字典问题修复
This commit is contained in:
parent
66d19f4b86
commit
ddca0e977a
52
src/api/system/dict/data.js
Normal file
52
src/api/system/dict/data.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 查询字典数据列表
|
||||||
|
export function listData(query) {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/data/list',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询字典数据详细
|
||||||
|
export function getData(dictCode) {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/data/' + dictCode,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据字典类型查询字典数据信息
|
||||||
|
export function getDicts(dictType) {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/data/type/' + dictType,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增字典数据
|
||||||
|
export function addData(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/data',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改字典数据
|
||||||
|
export function updateData(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/data',
|
||||||
|
method: 'put',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除字典数据
|
||||||
|
export function delData(dictCode) {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/data/' + dictCode,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
60
src/api/system/dict/type.js
Normal file
60
src/api/system/dict/type.js
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 查询字典类型列表
|
||||||
|
export function listType(query) {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/type/list',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询字典类型详细
|
||||||
|
export function getType(dictId) {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/type/' + dictId,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增字典类型
|
||||||
|
export function addType(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/type',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改字典类型
|
||||||
|
export function updateType(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/type',
|
||||||
|
method: 'put',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除字典类型
|
||||||
|
export function delType(dictId) {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/type/' + dictId,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 刷新字典缓存
|
||||||
|
export function refreshCache() {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/type/refreshCache',
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取字典选择框列表
|
||||||
|
export function optionselect() {
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/type/optionselect',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
16
src/main.js
16
src/main.js
@ -4,10 +4,26 @@ import uviewPlus from 'uview-plus'
|
|||||||
|
|
||||||
|
|
||||||
import { createSSRApp } from 'vue'
|
import { createSSRApp } from 'vue'
|
||||||
|
|
||||||
|
import { useDict } from '@/utils/dict'
|
||||||
|
import { parseTime, resetForm, addDateRange, handleTree, selectDictLabel, selectDictLabels } from '@/utils/ruoyi'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function createApp() {
|
export function createApp() {
|
||||||
const app = createSSRApp(App)
|
const app = createSSRApp(App)
|
||||||
app.use(uviewPlus)
|
app.use(uviewPlus)
|
||||||
app.use(plugins)
|
app.use(plugins)
|
||||||
|
|
||||||
|
// 全局方法挂载
|
||||||
|
app.config.globalProperties.useDict = useDict
|
||||||
|
app.config.globalProperties.parseTime = parseTime
|
||||||
|
app.config.globalProperties.resetForm = resetForm
|
||||||
|
app.config.globalProperties.handleTree = handleTree
|
||||||
|
app.config.globalProperties.addDateRange = addDateRange
|
||||||
|
app.config.globalProperties.selectDictLabel = selectDictLabel
|
||||||
|
app.config.globalProperties.selectDictLabels = selectDictLabels
|
||||||
|
|
||||||
return {
|
return {
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
import user from '@/store/modules/user'
|
import user from '@/store/modules/user'
|
||||||
|
import dict from '@/store/modules/dict'
|
||||||
import getters from './getters'
|
import getters from './getters'
|
||||||
import { createStore } from "vuex";
|
import { createStore } from "vuex";
|
||||||
const store = createStore({
|
const store = createStore<any>({
|
||||||
modules: {
|
modules: {
|
||||||
user,
|
user,
|
||||||
|
dict
|
||||||
},
|
},
|
||||||
getters
|
getters
|
||||||
});
|
});
|
||||||
|
|||||||
64
src/store/modules/dict.ts
Normal file
64
src/store/modules/dict.ts
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import config from "@/config";
|
||||||
|
import storage from "@/utils/storage";
|
||||||
|
import constant from "@/utils/constant";
|
||||||
|
import { login, logout, getInfo } from "@/api/login";
|
||||||
|
import { getToken, setToken, removeToken } from "@/utils/auth";
|
||||||
|
import { dictStateType, dictType } from "@/types/store";
|
||||||
|
import { Module } from "vuex";
|
||||||
|
|
||||||
|
const baseUrl = config.baseUrl;
|
||||||
|
|
||||||
|
const dict: Module<dictStateType, dictStateType> = {
|
||||||
|
state: {
|
||||||
|
dict: new Array(),
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
// 获取字典
|
||||||
|
getDict({ state }, _key) {
|
||||||
|
if (_key == null && _key == "") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
for (let i = 0; i < state.dict.length; i++) {
|
||||||
|
if (state.dict[i].key == _key) {
|
||||||
|
return state.dict[i].value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 设置字典
|
||||||
|
setDict({ state }, dict: dictType) {
|
||||||
|
if (dict.key !== null && dict.key !== "") {
|
||||||
|
state.dict.push({
|
||||||
|
key: dict.key,
|
||||||
|
value: dict.value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 删除字典
|
||||||
|
removeDict({ state }, _key) {
|
||||||
|
var bln = false;
|
||||||
|
try {
|
||||||
|
for (let i = 0; i < state.dict.length; i++) {
|
||||||
|
if (state.dict[i].key == _key) {
|
||||||
|
state.dict.splice(i, 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
bln = false;
|
||||||
|
}
|
||||||
|
return bln;
|
||||||
|
},
|
||||||
|
// 清空字典
|
||||||
|
cleanDict({ state }) {
|
||||||
|
state.dict = new Array();
|
||||||
|
},
|
||||||
|
// 初始字典
|
||||||
|
initDict() {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default dict;
|
||||||
@ -14,4 +14,6 @@ export interface UserForm {
|
|||||||
uuid: string
|
uuid: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type dictType = { key: string; value: string };
|
||||||
|
export type dictStateType = { dict: Array<dictType> };
|
||||||
|
|
||||||
|
|||||||
33
src/utils/dict.ts
Normal file
33
src/utils/dict.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import store from "@/store";
|
||||||
|
import { getDicts } from "@/api/system/dict/data";
|
||||||
|
import { Ref, ref, toRefs } from "vue";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字典数据
|
||||||
|
*/
|
||||||
|
export function useDict(...args: any[]) {
|
||||||
|
const res: Ref<any> = ref({});
|
||||||
|
return (() => {
|
||||||
|
args.forEach(async (dictType: string, index) => {
|
||||||
|
res.value[dictType] = [];
|
||||||
|
const dicts = await store.dispatch("getDict", dictType);
|
||||||
|
if (dicts) {
|
||||||
|
res.value[dictType] = dicts;
|
||||||
|
} else {
|
||||||
|
getDicts(dictType).then((resp) => {
|
||||||
|
res.value[dictType] = resp.data.map((p: any) => ({
|
||||||
|
label: p.dictLabel,
|
||||||
|
value: p.dictValue,
|
||||||
|
elTagType: p.listClass,
|
||||||
|
elTagClass: p.cssClass,
|
||||||
|
}));
|
||||||
|
store.dispatch("setDict", {
|
||||||
|
key: dictType,
|
||||||
|
value: res.value[dictType],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return toRefs(res.value);
|
||||||
|
})();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user