lrf402788946 vor 5 Jahren
Ursprung
Commit
50c2b70521
2 geänderte Dateien mit 14 neuen und 3 gelöschten Zeilen
  1. 10 1
      components/data-table.vue
  2. 4 2
      components/table.md

+ 10 - 1
components/data-table.vue

@@ -35,6 +35,7 @@ export default {
     fields: { type: Array, required: true },
     data: { type: Array, required: true },
     opera: { type: Array, default: () => [] },
+    toFormat: null,
   },
   components: {},
   data: () => ({}),
@@ -46,7 +47,15 @@ export default {
       if (this_fields.length > 0) {
         let format = _.get(this_fields[0], `format`, false);
         if (format) {
-          let res = format(cellValue);
+          let res;
+          if (_.isFunction(format)) {
+            res = format(cellValue);
+          } else {
+            res = this.toFormat({
+              model: this_fields[0].prop,
+              value: cellValue,
+            });
+          }
           return res;
         } else return cellValue;
       }

+ 4 - 2
components/table.md

@@ -6,6 +6,7 @@
 |fields|Array|`-`|是|字段列表(下文会说明如何使用)|
 |data|Array|`-`|是|数据列表|
 |opera|Array|[ ]|否|操作列的列表(下文会说明如何使用)|
+|toFormat|Function|`-`|否|如果fields中的format不是function类型,则会走toFormat的方法,需要自己写过滤规则,多个的情况需要区分|
 
 >fields
 >>
@@ -13,7 +14,7 @@
 |:-:|:-:|:-:|:-:|:-:|
 |label|String|`-`|是|列名称|
 |prop|String|`-`|是|字段名称|
-|format|Function|`-`|否|数据需要过滤则将过滤方法写在这,尽量不要太复杂,如果太复杂则在查询方法处理(推荐)|
+|format|Function/String|`-`|否|Function类型:数据需要过滤则将过滤方法写在这;String类型:走toFormat方法,参数位(model=>字段名,value=>值)|
 
 >opera
 >>
@@ -23,4 +24,5 @@
 |icon|String|`-`|否|图标|
 |method|String|`-`|是|此按钮连接的父级方法($emit)|
 |confirm|Boolean|`-`|否|是否需要确认提示|
-|methodZh|String|`-`|否|确认提示的操作文字|
+|methodZh|String|`-`|否|确认提示的操作文字|
+|display|Function|`-`|否|控制按钮是否显示(目前为简单版,只是根据此条数据中的内容判断,以后要是有需求会修改成toFormat的形式)|