gaoluyang
3 天以前 92230c9a97dc9ce9df3313d11d26999c04bb6b26
src/store/modules/dict.ts
对比新文件
@@ -0,0 +1,55 @@
import { defineStore } from "pinia";
const useDictStore = defineStore("dict", {
  state: () => ({
    dict: new Array(),
  }),
  actions: {
    // 鑾峰彇瀛楀吀
    getDict(_key: string) {
      if (_key == null && _key == "") {
        return null;
      }
      try {
        for (let i = 0; i < this.dict.length; i++) {
          if (this.dict[i].key == _key) {
            return this.dict[i].value;
          }
        }
      } catch (e) {
        return null;
      }
    },
    // 璁剧疆瀛楀吀
    setDict(_key: string, value: any) {
      if (_key !== null && _key !== "") {
        this.dict.push({
          key: _key,
          value: value,
        });
      }
    },
    // 鍒犻櫎瀛楀吀
    removeDict(_key: string) {
      var bln = false;
      try {
        for (let i = 0; i < this.dict.length; i++) {
          if (this.dict[i].key == _key) {
            this.dict.splice(i, 1);
            return true;
          }
        }
      } catch (e) {
        bln = false;
      }
      return bln;
    },
    // 娓呯┖瀛楀吀
    cleanDict() {
      this.dict = new Array();
    },
    // 鍒濆瀛楀吀
    initDict() {},
  },
});
export default useDictStore;