自定义数据字典

// 回显数据字典 全局引入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’ )) => 待使用,待评价,已评价

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值