diff --git a/src/utils/dict.js b/src/utils/dict.js index 4668f7f..b3a89d6 100644 --- a/src/utils/dict.js +++ b/src/utils/dict.js @@ -1,29 +1,52 @@ import { ref, toRefs } from 'vue'; import { getSysDictByCode } from '@/api/sysDict' //引入封装数字字典接口 + +import { getLocalDic } from "@/utils/localDic/index.js" /** * 获取字典数据 */ let list = [] +/** 是否取本地字典 (需要本地加载就加这里,不需要就删除) */ +export function isLocalDict(dictCode) { + let localDicObj = { + D_GS_ZDR_YJDJ: true, // "岗哨系统重点人员预警等级" + D_BZ_XB: true, // 性别 + D_GS_BQ_DJ: true, // "岗哨系统标签管理标签等级" + D_GS_SSYJ: true, // "岗哨系统四色预警" + D_BZ_SF: true, // "是否" + BD_BK_CLYJBQ: true, // "车辆预警标签" + D_YJXX_CZCSLX:true, //常控处置措施类型 + } + return localDicObj[dictCode] +} export function getDict(...args) { const res = ref({}); return (() => { args.forEach((d, index) => { res.value[d] = []; - getSysDictByCode({ - dictCode: d - }).then(result => { - result.itemList.forEach(p => { - p.label = p.zdmc - p.value = p.dm - p.id = p.dm - p.elTagType = p.dictType - if ( p.itemList && p.itemList.length > 0) { - getChildren(p) - } - p.children = p.itemList + + // 本地字典拦截,如果本地字典存在,则使用本地字典,否则使用远程字典 + if (isLocalDict(d) && getLocalDic(d)) { + res.value[d] = getLocalDic(d) + } else { + getSysDictByCode({ + dictCode: d + }).then(result => { + result.itemList.forEach(p => { + p.label = p.zdmc + p.value = p.dm + p.id = p.dm + p.elTagType = p.dictType + if (p.itemList && p.itemList.length > 0) { + getChildren(p) + } + p.children = p.itemList + }) + res.value[d] = result.itemList + // console.log(`${d} - ${result.zdmc} :`, result.itemList); }) - res.value[d] = result.itemList - }) + } + }) return toRefs(res.value); })() @@ -61,9 +84,9 @@ export function setCascader(id, array, childDeptList = 'childDeptList', fun) { } /** * 当type=1时获取出生日期,type=2时获取性别,type=3时获取年龄 all - * @param {*} IdCard - * @param {*} type - * @returns + * @param {*} IdCard + * @param {*} type + * @returns */ export function IdCard(IdCard, type) { let user = { diff --git a/src/utils/localDic/index.js b/src/utils/localDic/index.js index 8eafd2c..e54462d 100644 --- a/src/utils/localDic/index.js +++ b/src/utils/localDic/index.js @@ -1,3 +1,7 @@ +/** 获取本地字典 + * @param {string} key 字典key + * @returns {Array} 字典数组 + */ export function getLocalDic(key) { let dicobj = { /** "岗哨系统重点人员预警等级" */ @@ -171,9 +175,126 @@ export function getLocalDic(key) { } ], /** 车辆预警标签 */ - BD_BK_CLYJBQ: true, + BD_BK_CLYJBQ: [ + { + "itemList": null, + "id": "DQCL", + "zdId": 59589198, + "zdbh": "BD_BK_CLYJBQ", + "zdmc": "盗抢车辆", + "dm": "DQCL", + "py": "DQCL", + "px": 1, + "bz": "", + "label": "盗抢车辆", + "value": "DQCL", + "children": null + }, + { + "itemList": null, + "id": "LKCL", + "zdId": 59589198, + "zdbh": "BD_BK_CLYJBQ", + "zdmc": "临控车辆", + "dm": "LKCL", + "py": "LKCL", + "px": 1, + "bz": "", + "label": "临控车辆", + "value": "LKCL", + "children": null + } + ], /** 是否 */ - D_BZ_SF: true, + D_BZ_SF: [ + { + "itemList": null, + "id": "0", + "zdId": 59587921, + "zdbh": "D_BZ_SF", + "zdmc": "否", + "dm": "0", + "py": "F", + "px": 1, + "bz": "", + "label": "否", + "value": "0", + "children": null + }, + { + "itemList": null, + "id": "1", + "zdId": 59587921, + "zdbh": "D_BZ_SF", + "zdmc": "是", + "dm": "1", + "py": "S", + "px": 2, + "bz": "", + "label": "是", + "value": "1", + "children": null + } + ], + /** 常控处置措施类型 */ + D_YJXX_CZCSLX: [ + { + "itemList": null, + "id": "01", + "zdId": 59589206, + "zdbh": "D_YJXX_CZCSLX", + "zdmc": "抓捕", + "dm": "01", + "py": "ZP", + "px": 1, + "bz": "", + "label": "抓捕", + "value": "01", + "children": null + }, + { + "itemList": null, + "id": "02", + "zdId": 59589206, + "zdbh": "D_YJXX_CZCSLX", + "zdmc": "管控", + "dm": "02", + "py": "GK", + "px": 2, + "bz": "", + "label": "管控", + "value": "02", + "children": null + }, + { + "itemList": null, + "id": "03", + "zdId": 59589206, + "zdbh": "D_YJXX_CZCSLX", + "zdmc": "经营", + "dm": "03", + "py": "JY", + "px": 3, + "bz": "", + "label": "经营", + "value": "03", + "children": null + }, + { + "itemList": null, + "id": "04", + "zdId": 59589206, + "zdbh": "D_YJXX_CZCSLX", + "zdmc": "关注", + "dm": "04", + "py": "GZ", + "px": 4, + "bz": "", + "label": "关注", + "value": "04", + "children": null + } + ], } return dicobj[key] }