This commit is contained in:
lcw
2026-03-29 19:46:50 +08:00
parent 60de16032f
commit af838854fa
49 changed files with 9947 additions and 1512 deletions

View File

@ -1,11 +1,11 @@
import { ref, toRefs, isRef } from 'vue';
import { getSysDictByCode, fzdict } from '@/api/sysDict' //引入封装数字字典接口
import { ref, toRefs, isRef } from "vue";
import { getSysDictByCode, fzdict } from "@/api/sysDict"; //引入封装数字字典接口
import { getLocalDic } from "@/utils/localDic/index.js"
import { getLocalDic } from "@/utils/localDic/index.js";
/**
* 获取字典数据
*/
let list = []
let list = [];
/** 是否取本地字典 (需要本地加载就加这里,不需要就删除) */
export function isLocalDict(dictCode) {
let localDicObj = {
@ -15,9 +15,9 @@ export function isLocalDict(dictCode) {
D_GS_SSYJ: true, // "岗哨系统四色预警"
D_BZ_SF: true, // "是否"
BD_BK_CLYJBQ: true, // "车辆预警标签"
D_YJXX_CZCSLX: true, //常控处置措施类型
}
return localDicObj[dictCode]
D_YJXX_CZCSLX: true //常控处置措施类型
};
return localDicObj[dictCode];
}
export function getDict(...args) {
const res = ref({});
@ -26,32 +26,32 @@ export function getDict(...args) {
res.value[d] = [];
// 本地字典拦截,如果本地字典存在,则使用本地字典,否则使用远程字典
if (isLocalDict(d) && getLocalDic(d)) {
res.value[d] = getLocalDic(d)
res.value[d] = getLocalDic(d);
} else {
getSysDictByCode({
dictCode: d
}).then(result => {
result = result || {}
result.itemList = Array.isArray(result.itemList) ? result.itemList : []
result.itemList.forEach(p => {
p.label = p.zdmc
p.value = p.dm
p.id = p.dm
p.elTagType = p.dictType
}).then((result) => {
result = result || {};
result.itemList = Array.isArray(result.itemList)
? result.itemList
: [];
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)
getChildren(p);
}
p.children = p.itemList
})
res.value[d] = result.itemList
p.children = p.itemList;
});
res.value[d] = result.itemList;
//
})
});
}
})
});
return toRefs(res.value);
})()
})();
}
export function getFzDict(...args) {
const res = ref({});
@ -64,7 +64,7 @@ export function getFzDict(...args) {
} else {
fzdict({
dictLabel: d
}).then(result => {
}).then((result) => {
result = result || {};
// result.itemList = Array.isArray(result.itemList) ? result.itemList : [];
// result.itemList.forEach(p => {
@ -79,26 +79,25 @@ export function getFzDict(...args) {
// });
// console.log(res.value);
res.value[d] = result
res.value[d] = result;
});
}
});
// 使用toRefs确保返回的是响应式对象
return toRefs(res.value);
})()
})();
}
export function getChildren(item) {
item.label = item.zdmc
item.value = item.dm
item.id = item.dm
item.label = item.zdmc;
item.value = item.dm;
item.id = item.dm;
if (item.itemList && item.itemList.length > 0) {
item.itemList.forEach(v => {
getChildren(v)
})
item.itemList.forEach((v) => {
getChildren(v);
});
}
item.children = item.itemList
item.children = item.itemList;
}
/**
* 设置级联选择器回显
@ -106,17 +105,17 @@ export function getChildren(item) {
* @param {*} array 级联数据树
* @param {*} childDeptList 子集变量
*/
export function setCascader(id, array, childDeptList = 'childDeptList', fun) {
export function setCascader(id, array, childDeptList = "childDeptList", fun) {
if (array) {
array.forEach(item => {
array.forEach((item) => {
if (item.childDeptList && item.id != id) {
setCascader(id, item.childDeptList, childDeptList, fun)
setCascader(id, item.childDeptList, childDeptList, fun);
} else if (item.childDeptList && item.id == id) {
fun(item)
fun(item);
} else if (!item.childDeptList && item.id == id) {
fun(item)
fun(item);
}
})
});
}
}
/**
@ -127,58 +126,64 @@ export function setCascader(id, array, childDeptList = 'childDeptList', fun) {
*/
export function IdCard(IdCard, type) {
let user = {
birthday: '',
sex: '',
age: ''
}
if (type === 1 || type == 'all') {
birthday: "",
sex: "",
age: ""
};
if (type === 1 || type == "all") {
//获取出生日期
let birthday = IdCard.substring(6, 10) + "-" + IdCard.substring(10, 12) + "-" + IdCard.substring(12, 14)
if (type == 'all') {
user.birthday = birthday
let birthday =
IdCard.substring(6, 10) +
"-" +
IdCard.substring(10, 12) +
"-" +
IdCard.substring(12, 14);
if (type == "all") {
user.birthday = birthday;
} else {
return birthday
return birthday;
}
}
if (type === 2 || type == 'all') {
if (type === 2 || type == "all") {
//获取性别
if (parseInt(IdCard.substr(16, 1)) % 2 === 1) {
if (type == 'all') {
user.sex = '男'
if (type == "all") {
user.sex = "男";
} else {
return "男"
return "男";
}
} else {
if (type == 'all') {
user.sex = '女'
if (type == "all") {
user.sex = "女";
} else {
return "女"
return "女";
}
}
}
if (type === 3 || type == 'all') {
if (type === 3 || type == "all") {
//获取年龄
var ageDate = new Date()
var month = ageDate.getMonth() + 1
var day = ageDate.getDate()
var age = ageDate.getFullYear() - IdCard.substring(6, 10) - 1
if (IdCard.substring(10, 12) < month || IdCard.substring(10, 12) === month && IdCard.substring(12, 14) <= day) {
age++
var ageDate = new Date();
var month = ageDate.getMonth() + 1;
var day = ageDate.getDate();
var age = ageDate.getFullYear() - IdCard.substring(6, 10) - 1;
if (
IdCard.substring(10, 12) < month ||
(IdCard.substring(10, 12) === month && IdCard.substring(12, 14) <= day)
) {
age++;
}
if (age <= 0) {
age = 1
age = 1;
}
if (type == 'all') {
user.age = age
if (type == "all") {
user.age = age;
} else {
return age
return age;
}
}
return user
return user;
}
/**
*翻译字典数据
* @export
@ -186,14 +191,14 @@ export function IdCard(IdCard, type) {
* @param {*} array
*/
export function getDictValue(dm, array) {
let item = array.value.find(item => {
let item = array.value.find((item) => {
if (item.value) {
return item.value == dm;
} else if (item.dm) {
return item.dm == dm;
}
})
return item ? item.label : ""
});
return item ? item.label : "";
}
/** 获取多个字典值(一个值也可以) 字典内容 value-label
@ -201,15 +206,15 @@ export function getDictValue(dm, array) {
* @param {Array} dict 字典内容
*/
export function getMultiDictVal(values, dict) {
if (typeof values === 'string' && values?.length) values = values.split(',')
if (!Array.isArray(values)) return ''
if (isRef(dict)) dict = dict.value
if (!Array.isArray(dict)) return ''
if (typeof values === "string" && values?.length) values = values.split(",");
if (!Array.isArray(values)) return "";
if (isRef(dict)) dict = dict.value;
if (!Array.isArray(dict)) return "";
return values.map(v => {
const item = dict.find(item => item.value === v);
return item ? item.label : v;
}).join(',');
return values
.map((v) => {
const item = dict.find((item) => item.value === v);
return item ? item.label : v;
})
.join(",");
}