| | |
| | | import {ListAllData} from "@/api/system/dict/data" |
| | | |
| | | const useDictStore = defineStore( |
| | | 'dict', |
| | | { |
| | | state: () => ({ |
| | | dict: new Array() |
| | | dict: [] |
| | | }), |
| | | actions: { |
| | | async initDict() { |
| | | const response = await ListAllData() |
| | | this.dict = response.data |
| | | }, |
| | | |
| | | // 根据字典类型获取字典 |
| | | getDictTypeList(_type) { |
| | | if (_type == null || _type === "") { |
| | | return null; |
| | | } |
| | | return this.dict.filter(item => item.type === _type); |
| | | }, |
| | | |
| | | getDictDataByTypeAndValue(_type,_value){ |
| | | if (_type == null || _value == null) { |
| | | return { |
| | | type:"", |
| | | value:"", |
| | | label:"" |
| | | }; |
| | | } |
| | | return this.dict.find(item => item.type == _type && item.value == _value ) || null; |
| | | |
| | | }, |
| | | |
| | | // 获取字典 |
| | | getDict(_key) { |
| | | if (_key == null && _key == "") { |
| | | return null |
| | | } |
| | | // console.log(this.dict) |
| | | try { |
| | | for (let i = 0; i < this.dict.length; i++) { |
| | | if (this.dict[i].key == _key) { |
| | |
| | | cleanDict() { |
| | | this.dict = new Array() |
| | | }, |
| | | // 初始字典 |
| | | initDict() { |
| | | } |
| | | |
| | | } |
| | | }) |
| | | |