import { getAction } from '@/api/flowable/manage'; import store from '@/store'; export function formatDictText(dicts, values) { if (!(Array.isArray(dicts) && dicts.length > 0)) { return values; } if (!values) { return ''; } let valueArr = values.split(','); let contentArr = []; dicts.forEach((dict) => { for (let i = 0; i < valueArr.length; i++) { if (valueArr[i] === dict.value) { contentArr.push(dict.content); break; } } }); return contentArr.toString(); } export function randomString(len) { len = len || 32; const $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /** **默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/ const maxPos = $chars.length; let pwd = ''; for (let i = 0; i < len; i++) { pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); } return pwd; } // 深度拷贝 export function copyObj(obj) { //变量先置空 let newobj = null; //判断是否需要继续进行递归 if (typeof obj == 'object' && obj !== null) { newobj = obj instanceof Array ? [] : {}; //进行下一层递归克隆 for (const i in obj) { newobj[i] = copyObj(obj[i]); } //如果不是对象直接赋值 } else { newobj = obj; } return newobj; } export function getRecords(records) { const result = {}; records.forEach((record) => { const res = record.deliveryTime.split('-'); const yearMonth = res.slice(0, 2).join('-'); const day = 'date' + res.slice(-1); const quantity = record.quantity; if (!result[day]) { result[day] = []; } const existingEntry = result[day].find((entry) => entry.day === yearMonth); if (existingEntry) { existingEntry.num += quantity; } else { result[day].push({ day: yearMonth, num: quantity }); } }); return result; } export function groupByProperty(arr, property) { return arr.reduce((acc, item) => { const key = item[property]; // 若对象中不存在该键,则初始化一个空数组 if (!acc[key]) { acc[key] = []; } // 将当前元素添加到对应的数组中 acc[key].push(item); return acc; }, {}); } export function getMaxArrayLength(obj) { let maxLength = 0; // 遍历对象的所有属性 for (const key in obj) { if (Array.isArray(obj[key])) { // 比较当前数组长度与最大长度 maxLength = Math.max(maxLength, obj[key].length); } } return maxLength; } export function getMaxSameProcessIdCount(arr) { const countMap = {}; // 遍历数组,统计每个 processId 出现的次数 arr.forEach((item) => { const processId = item.processId; if (countMap[processId]) { countMap[processId]++; } else { countMap[processId] = 1; } }); let maxCount = 0; // 遍历计数对象,找出最大的计数 for (const key in countMap) { maxCount = Math.max(maxCount, countMap[key]); } return maxCount; } //合计费用 export function getSummaries(param, key, unit) { const { columns, data } = param; const sums = []; columns.forEach((column, index) => { if (index === 0) { sums[index] = '合计'; return; } if (key.includes(column.property)) { const values = data.map((item) => Number(item[column.property])); console.log(values); if (!values.every((value) => isNaN(value))) { sums[index] = values.reduce((prev, curr) => { const value = Number(curr); if (!isNaN(value)) { return prev + curr; } else { return prev; } }, 0); sums[index] = parseFloat(sums[index]) .toFixed(3) .replace(/\.?0+$/, ''); sums[index] += ' ' + unit + ''; } else { sums[index] = ''; } } else { sums[index] = ''; } }); return sums; }