Compare commits

...

2 Commits

Author SHA1 Message Date
Leo_Ding
abee5ef4a4 Merge branch 'master' of https://gitlab.guxuan.icu/Leo_Ding/GPU_Admin 2026-01-22 14:50:08 +08:00
Leo_Ding
a0b3e78cb2 字典使用 2026-01-22 14:49:55 +08:00

46
src/enums/dict.js Normal file
View 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()