| | |
| | | import Cookies from 'js-cookie'
|
| | |
|
| | |
|
| | | const useAppStore = defineStore(
|
| | | 'app',
|
| | | {
|
对比新文件 |
| | |
| | | const useDictStore = defineStore(
|
| | | 'dict',
|
| | | {
|
| | | state: () => ({
|
| | | dict: new Array()
|
| | | }),
|
| | | actions: {
|
| | | // 鑾峰彇瀛楀吀
|
| | | getDict(_key) {
|
| | | 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, value) {
|
| | | if (_key !== null && _key !== "") {
|
| | | this.dict.push({
|
| | | key: _key,
|
| | | value: value
|
| | | });
|
| | | }
|
| | | },
|
| | | // 鍒犻櫎瀛楀吀
|
| | | removeDict(_key) {
|
| | | 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
|
| | |
| | | import useDictStore from '@/store/modules/dict'
|
| | | import { getDicts } from '@/api/system/dict/data'
|
| | |
|
| | | /**
|
| | |
| | | export function useDict(...args) {
|
| | | const res = ref({});
|
| | | return (() => {
|
| | | args.forEach((d, index) => {
|
| | | res.value[d] = [];
|
| | | getDicts(d).then(resp => {
|
| | | res.value[d] = resp.data.map(p => ({ label: p.dictLabel, value: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass }))
|
| | | })
|
| | | args.forEach((dictType, index) => {
|
| | | res.value[dictType] = [];
|
| | | const dicts = useDictStore().getDict(dictType);
|
| | | if (dicts) {
|
| | | res.value[dictType] = dicts;
|
| | | } else {
|
| | | getDicts(dictType).then(resp => {
|
| | | res.value[dictType] = resp.data.map(p => ({ label: p.dictLabel, value: p.dictValue, elTagType: p.listClass, elTagClass: p.cssClass }))
|
| | | useDictStore().setDict(dictType, res.value[dictType]);
|
| | | })
|
| | | }
|
| | | })
|
| | | return toRefs(res.value);
|
| | | })()
|
| | |
| | | </template>
|
| | |
|
| | | <script setup name="Data">
|
| | | import useDictStore from '@/store/modules/dict'
|
| | | import { optionselect as getDictOptionselect, getType } from "@/api/system/dict/type";
|
| | | import { listData, getData, delData, addData, updateData } from "@/api/system/dict/data";
|
| | |
|
| | |
| | | if (valid) {
|
| | | if (form.value.dictCode != undefined) {
|
| | | updateData(form.value).then(response => {
|
| | | useDictStore().removeDict(queryParams.value.dictType);
|
| | | proxy.$modal.msgSuccess("淇敼鎴愬姛");
|
| | | open.value = false;
|
| | | getList();
|
| | | });
|
| | | } else {
|
| | | addData(form.value).then(response => {
|
| | | useDictStore().removeDict(queryParams.value.dictType);
|
| | | proxy.$modal.msgSuccess("鏂板鎴愬姛");
|
| | | open.value = false;
|
| | | getList();
|
| | |
| | | }).then(() => {
|
| | | getList();
|
| | | proxy.$modal.msgSuccess("鍒犻櫎鎴愬姛");
|
| | | useDictStore().removeDict(queryParams.value.dictType);
|
| | | }).catch(() => {});
|
| | | }
|
| | | /** 瀵煎嚭鎸夐挳鎿嶄綔 */
|
| | |
| | | </template>
|
| | |
|
| | | <script setup name="Dict">
|
| | | import useDictStore from '@/store/modules/dict'
|
| | | import { listType, getType, delType, addType, updateType, refreshCache } from "@/api/system/dict/type";
|
| | |
|
| | | const { proxy } = getCurrentInstance();
|
| | |
| | | function handleRefreshCache() {
|
| | | refreshCache().then(() => {
|
| | | proxy.$modal.msgSuccess("鍒锋柊鎴愬姛");
|
| | | useDictStore().cleanDict();
|
| | | });
|
| | | }
|
| | |
|