xiaochan пре 2 година
родитељ
комит
764b60c925

+ 1 - 1
src/components/zhu-yuan-yi-sheng/shou-shu-shen-qing/DaYingShouShuShengQingDan.vue

@@ -109,7 +109,7 @@ import {cptSex} from "@/utils/computed";
 import {getLodop, initLodop} from "@/utils/c-lodop";
 import {ElMessage} from "element-plus";
 import XEUtils from "xe-utils";
-import findValueByListCode from "@/utils/findValueByListCode";
+import findValueByListCode from "@/utils/find-name-by-list-code";
 import {surgicalSituation} from "@/data/operation";
 
 const props = defineProps({

+ 13 - 2
src/utils/findValueByListCode.ts → src/utils/find-name-by-list-code.ts

@@ -1,25 +1,36 @@
 import XEUtils from "xe-utils";
 
 interface Option {
+    // 数组中的 code
     listCode: string,
+    // 数组中的 name
     listValue: string
 }
 
 const defaultValue: Option = {listCode: 'code', listValue: 'name'}
 
-const findValueByListCode = (arr: any[], code: string | number, option: Option = defaultValue): string => {
+/**
+ *
+ * @param arr 数组
+ * @param code 需要寻找的值
+ * @param option  配置
+ */
+const findValueByListCode = (arr: any[] | object, code: string | number, option: Option = defaultValue): string => {
     const {listCode, listValue} = option
     if (XEUtils.isEmpty(arr)) {
         return '';
     }
+
     if (!XEUtils.isArray(arr)) {
         return '';
     }
+
+
     if (typeof code === 'undefined' || code === null) {
         return '';
     }
 
-    for (let i = 0, len = arr.length; i < len; i++) {
+    for (let i: number = 0, len: number = arr.length; i < len; i++) {
         if (arr[i][listCode] === code) {
             return arr[i][listValue];
         }

+ 5 - 7
src/views/settings/Test.vue

@@ -5,14 +5,12 @@
 <script setup lang="ts">
 import EmrTestV2 from "@/components/zhu-yuan-yi-sheng/emr/auxiliary-tools/EmrTestV2.vue";
 import {onMounted} from "vue";
-import findValueByListCode from "@/utils/findValueByListCode";
+import findValueByListCode from "@/utils/find-name-by-list-code";
 
-const testData = [
-  {code: 1, name: 'asd'},
-  {code: 2, name: 'asd1'},
-  {code: 3, name: '3'},
-  {code: 4, name: '4'},
-]
+const testData = {
+  1: 'asd',
+  2: '123'
+}
 
 onMounted(() => {
   console.log(findValueByListCode(testData, 1));