// 回显数据字典 全局引入import {
selectDictLabel,
selectDictLabels,
} from '@/utils/ruoyi'
// 挂载Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
//
import { selectListLabel, loadingControl, getPublicTypePath } from './utils/platform'
export function selectDictLabel(datas, value) {
var actions = []
Object.keys(datas).some((key) => {
if (datas[key].value == '' + value) {
actions.push(datas[key].label)
return true
}
})
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) => {
Object.keys(datas).some((key) => {
if (datas[key].value == '' + temp[val]) {
actions.push(datas[key].label + currentSeparator)
}
})
})
return actions.join('').substring(0, actions.join('').length - 1)
}
使用方法
// 预约状态
statusSel: [
{
value: 0,
label: '待支付'
},
{
value: 1,
label: '待使用'
},
{
value: 2,
label: '待评价'
},
{
value: 3,
label: '已评价'
},
{
value: 4,
label: '退款审核中'
},
{
value: 5,
label: '已退订'
},
{
value: 6,
label: '已驳回'
},
{
value: 7,
label: '已取消'
},
{
value: 8,
label: '退款中'
}
],
return this.selectDictLabel(this.statusSel, 传入的数字('1')) =>待使用
return this.selectDictLabels(this.statusSel,‘1,2,3’ )
console.log(this.selectDictLabels(this.statusSel,‘1,2,3’ )) => 待使用,待评价,已评价