import { formatDate } from '@/utils/date.js' /** * 将后台取回来的数据, 转换成table所需要的二位数组 * @param obj 【数据源】 * @param arr 【所需要取的字段】 * @return {[[],[],[],[]]} 返回一个 二维数组 */ export function CtableClass(obj, arr) { if (obj.length < 1) { return [] } let _result = []; const han = /^[\u4e00-\u9fa5]+$/; obj.forEach((item, key) => { let _arr = [] for (let i = 0; i < arr.length; i++) { if (han.test(arr[i])) { _arr.push(arr[i]) } else if (arr[i] instanceof Array) { if (arr[i][0] === '时间戳') { let _time = formatDate(new Date(item[arr[i][1]]), 'yyyy-MM-dd hh:mm:ss') _arr.push([arr[i][0], _time]) } else if (arr[i][0] === '规格书') { _arr.push([arr[i][0], item[arr[i][1]]]) } else if (arr[i][0] === '地址') { let area = item[arr[i][2]].split(',').join(' ') let str = area + ' ' + item[arr[i][1]] _arr.push(str) } else { _arr.push([arr[i][0], Math.abs(item[arr[i][1]])]) } } else { _arr.push(item[arr[i]]) } } _result.push(_arr) }) return _result } export function WtableClass (obj, arr) { if (obj.length === 0) {return []} obj.forEach((item, key) => { item.isDisabled = false }) return obj } export function splitTableClass (obj, arr) { if (obj.length === 0) {return []} obj.forEach((item, keys) => { for (let i = 0; i < arr.attr.length; i++) { let _n = {} for (let j = 0; j < arr.thead.length; j++) { _n[arr.thead[j].id] = arr.attr[i].default } item[arr.attr[i].id] = _n } }) console.log(obj) return obj }