CMVR-IOT-UI/src/store/modules/dict.js

58 lines
1.2 KiB
JavaScript
Raw Normal View History

2025-08-21 14:11:58 +08:00
const useDictStore = defineStore(
'dict',
{
state: () => ({
dict: new Array()
}),
actions: {
// 获取字典
getDict(_key) {
if (_key == null && _key == "") {
2026-07-28 16:26:07 +08:00
return null
2025-08-21 14:11:58 +08:00
}
try {
for (let i = 0; i < this.dict.length; i++) {
if (this.dict[i].key == _key) {
2026-07-28 16:26:07 +08:00
return this.dict[i].value
2025-08-21 14:11:58 +08:00
}
}
} catch (e) {
2026-07-28 16:26:07 +08:00
return null
2025-08-21 14:11:58 +08:00
}
},
// 设置字典
setDict(_key, value) {
if (_key !== null && _key !== "") {
this.dict.push({
key: _key,
value: value
2026-07-28 16:26:07 +08:00
})
2025-08-21 14:11:58 +08:00
}
},
// 删除字典
removeDict(_key) {
2026-07-28 16:26:07 +08:00
var bln = false
2025-08-21 14:11:58 +08:00
try {
for (let i = 0; i < this.dict.length; i++) {
if (this.dict[i].key == _key) {
2026-07-28 16:26:07 +08:00
this.dict.splice(i, 1)
return true
2025-08-21 14:11:58 +08:00
}
}
} catch (e) {
2026-07-28 16:26:07 +08:00
bln = false
2025-08-21 14:11:58 +08:00
}
2026-07-28 16:26:07 +08:00
return bln
2025-08-21 14:11:58 +08:00
},
// 清空字典
cleanDict() {
2026-07-28 16:26:07 +08:00
this.dict = new Array()
2025-08-21 14:11:58 +08:00
},
// 初始字典
initDict() {
}
}
})
export default useDictStore