import { getDicts } from '@/common/api/common'
export async function useDict(...args) {
let res = {};
for(let i = 0; i < args.length; i++){
let d = args[i];
res[d] = [];
await getDicts(d).then(resp => {
res[d] = resp.data.map(p => ({ label: p.dictLabel, value: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass }))
})
}
return res;
}
export function selectDictLabel(datas, value) {
if (value === undefined) {
return "";
}
var actions = [];
Object.keys(datas).some((key) => {
if (datas[key].value == ('' + value)) {
actions.push(datas[key].label);
return true;
}
})
if (actions.length === 0) {
actions.push(value);
}
return actions.join('');
}
import { useDict,selectDictLabel } from './dict'
Vue.prototype.useDict = useDict;
Vue.prototype.selectDictLabel = selectDictLabel;
async getDics(){
const {bus_tam_gzlx, bus_tam_clsx} = await this.useDict("bus_tam_gzlx","bus_tam_clsx");
this.bus_tam_gzlx=[bus_tam_gzlx]
this.bus_tam_clsx=[bus_tam_clsx]
}
this.form.gzlxName=this.selectDictLabel(this.bus_tam_gzlx,this.form.gzlx)
import { getDicts } from '@/api/system/dict/data'
export function useDict(...args) {
const res = ref({});
return (() => {
args.forEach((d, index) => {
res.value[d] = [];
getDicts(d).then(resp => {
res.value[d] = resp.data.map(p => ({ label: p.dictLabel, value: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass }))
})
})
return toRefs(res.value);
})()
}
export function selectDictLabel(datas, value, valueName = 'value', labelName = 'label') {
if (value === undefined) {
return "";
}
var actions = [];
Object.keys(datas).some((key) => {
if (datas[key][valueName] == ('' + value)) {
actions.push(datas[key][labelName]);
return true;
}
})
if (actions.length === 0) {
actions.push(value);
}
return actions.join('');
}
export function selectDictLabels(datas, value, separator) {
if (value === undefined) {
return "";
}
var actions = [];
var currentSeparator = undefined === separator ? "," : separator;
var temp = value.split(currentSeparator);
Object.keys(value.split(currentSeparator)).some((val) => {
var match = false;
Object.keys(datas).some((key) => {
if (datas[key].value == ('' + temp[val])) {
actions.push(datas[key].label + currentSeparator);
match = true;
}
})
if (!match) {
actions.push(temp[val] + currentSeparator);
}
})
return actions.join('').substring(0, actions.join('').length - 1);
}
import { useDict,selectDictLabel,selectDictLabels } from '@/utils/dict'
app.config.globalProperties.useDict = useDict
app.config.globalProperties.selectDictLabel = selectDictLabel
app.config.globalProperties.selectDictLabels = selectDictLabels
const { proxy } = getCurrentInstance();
const {bus_tam_gzlx,bus_tam_clsx} = proxy.useDict("bus_tam_gzlx","bus_tam_clsx");
<el-table-column prop="clsx" label="处理时长" align="center" min-width="70" >
<template #default="{row}">
{{selectDictLabel(bus_tam_clsx,row.clsx)}}
</template>
</el-table-column>