Kaynağa Gözat

fix: 获取字典值工具类加入零值判断

Tong 2 yıl önce
ebeveyn
işleme
7bd26f8324
1 değiştirilmiş dosya ile 15 ekleme ve 12 silme
  1. 15 12
      src/utils/index.ts

+ 15 - 12
src/utils/index.ts

@@ -5,7 +5,7 @@ import { unref } from 'vue';
 import { isObject } from '/@/utils/is';
 import { cloneDeep } from 'lodash-es';
 
-export const noop = () => { };
+export const noop = () => {};
 
 /**
  * @description:  Set ui mount node
@@ -74,10 +74,10 @@ export function getRawRoute(route: RouteLocationNormalized): RouteLocationNormal
     ...opt,
     matched: (matched
       ? matched.map((item: any) => ({
-        meta: item.meta,
-        name: item.name,
-        path: item.path,
-      }))
+          meta: item.meta,
+          name: item.name,
+          path: item.path,
+        }))
       : undefined) as RouteRecordNormalized[],
   };
 }
@@ -123,26 +123,29 @@ export function getAllParentKeys(treeData: Array<any>, key: string) {
 
 // 获取字典值
 export function formatDictValue(options: Array<any>, value: string) {
-  if (!value || !options) {
-    return '';
+  if (!value) {
+    if (value != '0' || !options) {
+      return '';
+    }
   }
   let matchItem = '';
-
   if (typeof value == 'boolean') {
     matchItem = value ? '是' : '否';
     return matchItem;
   }
-  matchItem = options.find(item => item['value'] === value);
+  matchItem = options.find(item => (item['value'] as string) == value);
   return matchItem && matchItem['label'] ? matchItem['label'] : '';
 }
 
 // 获取字典颜色
 export function formatDictColor(options: Array<any>, value: string) {
-  if (!value || !options) {
-    return '';
+  if (!value) {
+    if (value != '0' || !options) {
+      return '';
+    }
   }
   let matchItem = '';
-  matchItem = options.find(item => item['value'] === value);
+  matchItem = options.find(item => item['value'] == value);
   return matchItem && matchItem['color'] ? matchItem['color'] : '';
 }