generated from Leo_Ding/web-template
字典使用
This commit is contained in:
parent
385efa8bf7
commit
a0b3e78cb2
46
src/enums/dict.js
Normal file
46
src/enums/dict.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
//获取值:payType.get(1)
|
||||||
|
//如果是下拉框需要获取列表:
|
||||||
|
export class BaseDict {
|
||||||
|
constructor(entries) {
|
||||||
|
this.map = new Map(entries)
|
||||||
|
}
|
||||||
|
//获取数组
|
||||||
|
get options() {
|
||||||
|
return Array.from(this.map, ([value, label]) => ({ value, label }))
|
||||||
|
}
|
||||||
|
//获取label
|
||||||
|
getLabel(value) {
|
||||||
|
return this.map.get(value)
|
||||||
|
}
|
||||||
|
//是否包含
|
||||||
|
has(value) {
|
||||||
|
return this.map.has(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//支付方式
|
||||||
|
class PayTypeDict extends BaseDict {
|
||||||
|
constructor() {
|
||||||
|
super([
|
||||||
|
[1, '微信支付'],
|
||||||
|
[2, '支付宝支付'],
|
||||||
|
[3, '银行卡支付'],
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//支付状态
|
||||||
|
class PayStatusDict extends BaseDict {
|
||||||
|
constructor() {
|
||||||
|
super([
|
||||||
|
['PaymentProcessing', '支付中'],
|
||||||
|
['PaymentSuccessful', '支付成功'],
|
||||||
|
['PaymentFailed', '支付失败'],
|
||||||
|
['PaymentCancelled','已取消']
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//如何使用:import {payTypeDict} from '@/enums/dict
|
||||||
|
//获取下拉框列表:payTypeDict.options
|
||||||
|
//获取label:payTypeDict.getLabel(1)
|
||||||
|
export const payTypeDict=new PayTypeDict()
|
||||||
|
export const payStatusDict=new PayStatusDict()
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user