|
|
@@ -30,9 +30,7 @@ export function getTableColumns() {
|
|
|
const filtered = filteredInfo.value || {};
|
|
|
columns.value.length = 0;
|
|
|
list.forEach((e, i) => {
|
|
|
- const { columnfield, columntitle, columnwidth, aligntype } = e;
|
|
|
- console.log();
|
|
|
-
|
|
|
+ const { columnfield, columntitle, columnwidth, aligntype, formatterstring } = e;
|
|
|
const item: ColumnType = {
|
|
|
key: String(i),
|
|
|
dataIndex: columnfield, // 表格数据对应的key
|
|
|
@@ -41,13 +39,20 @@ export function getTableColumns() {
|
|
|
slots: { customRender: columnfield },
|
|
|
};
|
|
|
if (columntitle === '序号') {
|
|
|
- item.render = (text: any, record: any, index: number) => `${index + 1}`
|
|
|
+ item.customRender = (obj: any) => `${obj.index + 1}`
|
|
|
}
|
|
|
if (columnwidth && columnwidth !== '0') {
|
|
|
item.width = +columnwidth
|
|
|
} else {
|
|
|
item.width = 120 // 默认120
|
|
|
}
|
|
|
+
|
|
|
+ if (formatterstring) {
|
|
|
+ const fn = getFromatterFn(formatterstring)
|
|
|
+ if (fn) {
|
|
|
+ item.customRender = fn
|
|
|
+ }
|
|
|
+ }
|
|
|
// 以下添加过滤数据对应的方法
|
|
|
filterKeyList.forEach(el => {
|
|
|
if (e.columnfield === el) {
|
|
|
@@ -68,4 +73,24 @@ export function getTableColumns() {
|
|
|
registerColumn(cacheTableKey, cacheFilterKeyList, cacheColumnCB)
|
|
|
}
|
|
|
return { columns, registerColumn, updateColumn, filteredInfo }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取对应的格式化函数
|
|
|
+ * @param val
|
|
|
+ * @returns 格式化函数
|
|
|
+ */
|
|
|
+function getFromatterFn(val: string) {
|
|
|
+ const arr = val.split(',');
|
|
|
+ const first = arr[0]
|
|
|
+ let result: Function | null = null
|
|
|
+ switch (first) {
|
|
|
+ case 'FormatterUnit': // 处理单位
|
|
|
+ result = (obj: any) => arr[1] ? obj.text + obj.record[arr[1]] : obj.text
|
|
|
+ break;
|
|
|
+ case 'FromatterPercent': // 数值百分比
|
|
|
+ result = (obj: any) => (Number(obj.text) * 100).toFixed(2) + '%'
|
|
|
+ break
|
|
|
+ }
|
|
|
+ return result
|
|
|
}
|