diff --git a/src/api/modules/dictionary.js b/src/api/modules/dictionary.js index dca2c9d..8138474 100644 --- a/src/api/modules/dictionary.js +++ b/src/api/modules/dictionary.js @@ -59,4 +59,11 @@ export default { params:data }) }, + // 获取字典值 + getCode(data) { + return request({ + url: '/api/sys/dictItem/'+data, + method: 'get', + }) + } } diff --git a/src/components/Header.vue b/src/components/Header.vue index 501905a..616c108 100644 --- a/src/components/Header.vue +++ b/src/components/Header.vue @@ -86,6 +86,7 @@ export default { this.$store.commit('saveUserInfo', null) this.$store.commit('setHandleProcess', null) this.$store.commit('savePathUrl', null) + this.$store.commit('removeDicts', null) // var sevice = "http://"+window.location.host+"/"; // var serviceUrl = encodeURIComponent(sevice); // 正式 diff --git a/src/components/dict.js b/src/components/dict.js new file mode 100644 index 0000000..0da9263 --- /dev/null +++ b/src/components/dict.js @@ -0,0 +1,58 @@ +// 混入字典方法 做到按需加载 +import interfaces from "@/api/modules/dictionary"; +import store from "@/store"; +import Vue from "vue"; + +class Dict { + constructor(dict) { + this.dict = dict; + } + + async init(names) { + const ps = []; + names.forEach((name) => { + if (store.getters.dicts[name]) { + Vue.set(this.dict, name, store.getters.dicts[name]); + } else { + Vue.set(this.dict, name, []); + ps.push( + interfaces.getCode(name).then((res) => { + this.dict[name] = Object.freeze(res.data); + store.dispatch('setDicts_a', { + label: name, + value: Object.freeze(res.data), + }) + }) + ); + + } + }); + await Promise.all(ps); + } +} + +const install = function (Vue) { + Vue.mixin({ + data() { + if ( + this.$options.dicts instanceof Array && + this.$options.dicts.length > 0 + ) { + return { dict: {} }; + } else { + return {}; + } + }, + created() { + if ( + this.$options.dicts instanceof Array && + this.$options.dicts.length > 0 + ) { + new Dict(this.dict).init(this.$options.dicts); + } + }, + }); +}; + +export default { install }; + diff --git a/src/main.js b/src/main.js index 26b2d10..e6fffae 100644 --- a/src/main.js +++ b/src/main.js @@ -35,13 +35,14 @@ import VueQuillEditor from 'vue-quill-editor' import 'quill/dist/quill.core.css' import 'quill/dist/quill.snow.css' import 'quill/dist/quill.bubble.css' +import dict from '@/components/dict' VXETable.setup({ table: { resizable: true } }) - +Vue.use(dict); Vue.use(VXETable) Vue.use(VueQuillEditor) Vue.use(ElementUI, { size: 'mini', zIndex: 3000 }) diff --git a/src/store/index.js b/src/store/index.js index 56fb363..c57283a 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -14,7 +14,8 @@ export default new Vuex.Store({ menuName: '', activeTab: '', handleProcess: '', - marketpre:'' + marketpre:'', + dicts:{} }, getters: { marketpre: (state) => state.marketpre, @@ -22,9 +23,16 @@ export default new Vuex.Store({ menuName: (state) => state.menuName, userInfo: (state) => state.userInfo, activeTab: (state) =>state.activeTab, - handleProcess: (state) =>state.handleProcess + handleProcess: (state) =>state.handleProcess, + dicts: (state) =>state.dicts }, mutations: { + setDicts(state, obj) { + state.dicts[obj.label] = obj.value; + }, + removeDicts(state, obj) { + state.dicts = {} + }, setMarketpre(state, data){ state.marketpre = data }, @@ -53,7 +61,11 @@ export default new Vuex.Store({ state.menuName = data } }, - actions: {}, + actions: { + setDicts_a({ commit }, obj) { + commit('setDicts', obj) + }, + }, modules: {}, plugins: [createPersistedState()] }) diff --git a/src/utils/request.js b/src/utils/request.js index 2e411ef..fa68921 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -82,6 +82,7 @@ instance.interceptors.response.use(function (response) { if (error.response.data.status == 401) { store.commit('savePathUrl', null) store.commit('setHandleProcess', null) + store.commit('removeDicts', null) router.push('/login') Message.error('登录超时过期') // window.open(BASE_URL.BASE_CHANGAN + "/logout?service=" + BASE_URL.BASE_LOCAL + "/login?loginType=1", '_self'); @@ -95,6 +96,7 @@ instance.interceptors.response.use(function (response) { if (error.response.status === 500) { store.commit('savePathUrl', null) store.commit('setHandleProcess', null) + store.commit('removeDicts', null) router.push('/login') Message.error('登录超时过期') // window.open(BASE_URL.BASE_CHANGAN + "/logout?service=" + BASE_URL.BASE_LOCAL + "/login?loginType=1", '_self'); diff --git a/src/views/System/dictionaryDetail.vue b/src/views/System/dictionaryDetail.vue index 374ed4b..0c33145 100644 --- a/src/views/System/dictionaryDetail.vue +++ b/src/views/System/dictionaryDetail.vue @@ -73,16 +73,16 @@
- + - + - + diff --git a/src/views/reportProcess/components/reportForm.vue b/src/views/reportProcess/components/reportForm.vue index 6403ff5..10c9a49 100644 --- a/src/views/reportProcess/components/reportForm.vue +++ b/src/views/reportProcess/components/reportForm.vue @@ -35,8 +35,8 @@ - + @@ -67,7 +67,7 @@ - + @@ -148,6 +148,7 @@ import newTranslate from "../../../components/newTranslate"; import VueTagsInput from '@johmun/vue-tags-input'; export default { + dicts:['classified_level','privacy_level'], components: { VueTagsInput, newTranslate diff --git a/src/views/reportProcess/launch.vue b/src/views/reportProcess/launch.vue index 5e5c882..62c6db8 100644 --- a/src/views/reportProcess/launch.vue +++ b/src/views/reportProcess/launch.vue @@ -244,7 +244,6 @@ export default { twoApprove: '' } this.$nextTick(() => { - this.$refs.applicationFormRef.clearValidate() this.$refs.assignFormRef.clearValidate() })