【新增】新增字典按需加载用dicts方式
This commit is contained in:
@@ -59,4 +59,11 @@ export default {
|
||||
params:data
|
||||
})
|
||||
},
|
||||
// 获取字典值
|
||||
getCode(data) {
|
||||
return request({
|
||||
url: '/api/sys/dictItem/'+data,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
// 正式
|
||||
|
||||
@@ -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 };
|
||||
|
||||
+2
-1
@@ -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 })
|
||||
|
||||
+15
-3
@@ -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()]
|
||||
})
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -73,16 +73,16 @@
|
||||
<div class="user-form">
|
||||
<el-form ref="addForm" :model="form" label-width="186px" :disabled="mode === 'view'"
|
||||
:rules="formRule">
|
||||
<el-form-item label="选项:" >
|
||||
<el-form-item label="选项:" required>
|
||||
<el-input v-model="form.itemName" maxlength="20" show-word-limit placeholder="请输入选项"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项值:" >
|
||||
<el-form-item label="选项值:" required>
|
||||
<el-input v-model="form.itemValue" maxlength="20" placeholder="请输入值" show-word-limit></el-input>
|
||||
</el-form-item>
|
||||
<!--<el-form-item label="确认密码:" :required="mode === 'add'" v-if="mode !== 'view'">-->
|
||||
<!--<el-input v-model="repassword" maxlength="20" type="password" placeholder="请确认密码"></el-input>-->
|
||||
<!--</el-form-item>-->
|
||||
<el-form-item label="排序:" >
|
||||
<el-form-item label="排序:" required>
|
||||
<el-input v-model="form.itemOrder"show-word-limit maxlength="10" placeholder="请输入排序"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注:" >
|
||||
|
||||
@@ -35,8 +35,8 @@
|
||||
<el-col :span="9" :offset="6">
|
||||
<el-form-item label="报告涉密等级:" prop="confidentialLevel">
|
||||
<el-select :disabled="formControl" v-model="form.confidentialLevel" placeholder="请选择报告涉密等级">
|
||||
<el-option v-for="item in confidentialLevelOptions" :key="item.value" :label="item.label"
|
||||
:value="item.value">
|
||||
<el-option v-for="item in dict['classified_level']" :key="item.itemValue" :label="item.itemName"
|
||||
:value="item.itemValue">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
@@ -67,7 +67,7 @@
|
||||
<el-col :span="9" :offset="6">
|
||||
<el-form-item label="报告隐私等级:" prop="privacyLevelOptions">
|
||||
<el-select :disabled="formControl" v-model="form.privacyLevelOptions" placeholder="请选择报告隐私等级">
|
||||
<el-option v-for="item in privacyLevelOptions" :key="item.value" :label="item.label" :value="item.value">
|
||||
<el-option v-for="item in dict['privacy_level']" :key="item.itemValue" :label="item.itemName" :value="item.itemValue">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
@@ -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
|
||||
|
||||
@@ -244,7 +244,6 @@ export default {
|
||||
twoApprove: ''
|
||||
}
|
||||
this.$nextTick(() => {
|
||||
this.$refs.applicationFormRef.clearValidate()
|
||||
this.$refs.assignFormRef.clearValidate()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user