huangbin 4 年之前
父节点
当前提交
7d207a239b

+ 1 - 0
src/common/methods/table/interface.ts

@@ -13,6 +13,7 @@ export interface ColumnType {
     onFilter?: Function;
     sorter?: Function;
     render?: Function;
+    customRender?: Function;
 }
 export interface TableKey {
     table_pcweb_aggregate_profit_and_loss: "string; // 报表-汇总损益报表"

+ 29 - 4
src/common/setup/table/clolumn.ts

@@ -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
 }

+ 1 - 0
src/services/go/commonService/interface.ts

@@ -63,6 +63,7 @@ export interface Column {
     remark: string;//备注
     summarytype: number;//汇总类型 - 1:加总 2:最后一个
     tablekey: string;//列表Key
+    formatterstring: string;
 }
 
 export interface TableDefineRsp {

+ 1 - 2
src/views/report/setup.ts

@@ -103,7 +103,6 @@ export function queryTableList<T>(fn: Function) {
         queryResultLoadingAndInfo(fn, loading, param).then(res => {
             const result = res?.map((e: T, i: number) => {
                 for (const item in e) {
-                    console.log(e[item])
                     e[item] = getDecimalsNum(e[item])
                 }
                 return { ...e, key: String(i) };
@@ -120,7 +119,7 @@ function getDecimalsNum(val: any) {
         const str = val.toString();
         const num = str.indexOf('.') + 1;
         const count = str.length - num;
-        if (count > 4) {
+        if (count > 6) {
             result = val.toFixed(2)
         }
     }