mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-12 06:57:13 +08:00
新增:新增公共查询枚举字典 API,优化前端获取枚举数据的方式
This commit is contained in:
@@ -5,11 +5,7 @@ import { MenuParam } from '@/api/system/menu';
|
||||
import { RoleParam } from '@/api/system/role';
|
||||
import { PostParam } from '@/api/system/post';
|
||||
import { TreeNodeData } from '@arco-design/web-vue';
|
||||
|
||||
export interface LabelValueRecord {
|
||||
label: string;
|
||||
value: any;
|
||||
}
|
||||
import { LabelValueState } from '@/store/modules/dict/types';
|
||||
|
||||
export function listDeptTree(params: DeptParam) {
|
||||
return axios.get<TreeNodeData[]>('/common/tree/dept', {
|
||||
@@ -30,7 +26,7 @@ export function listMenuTree(params: MenuParam) {
|
||||
}
|
||||
|
||||
export function listRoleDict(params: RoleParam) {
|
||||
return axios.get<LabelValueRecord[]>('/common/dict/role', {
|
||||
return axios.get<LabelValueState[]>('/common/dict/role', {
|
||||
params,
|
||||
paramsSerializer: (obj) => {
|
||||
return qs.stringify(obj);
|
||||
@@ -39,10 +35,14 @@ export function listRoleDict(params: RoleParam) {
|
||||
}
|
||||
|
||||
export function listPostDict(params: PostParam) {
|
||||
return axios.get<LabelValueRecord[]>('/common/dict/post', {
|
||||
return axios.get<LabelValueState[]>('/common/dict/post', {
|
||||
params,
|
||||
paramsSerializer: (obj) => {
|
||||
return qs.stringify(obj);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function listEnumDict(enumTypeName: string) {
|
||||
return axios.get<LabelValueState[]>(`/common/dict/enum/${enumTypeName}`);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import ArcoVueIcon from '@arco-design/web-vue/es/icon';
|
||||
// eslint-disable-next-line import/no-unresolved
|
||||
import 'virtual:svg-icons-register';
|
||||
import globalComponents from '@/components';
|
||||
import useDict from '@/utils/dict';
|
||||
import router from './router';
|
||||
import store from './store';
|
||||
import i18n from './locale';
|
||||
@@ -16,6 +17,9 @@ import '@/utils/request';
|
||||
|
||||
const app = createApp(App);
|
||||
|
||||
// 全局方法挂载
|
||||
app.config.globalProperties.useDict = useDict;
|
||||
|
||||
app.use(ArcoVue, {});
|
||||
app.use(ArcoVueIcon);
|
||||
|
||||
|
@@ -1,9 +1,10 @@
|
||||
import { createPinia } from 'pinia';
|
||||
import useAppStore from './modules/app';
|
||||
import useLoginStore from './modules/login';
|
||||
import useDictStore from './modules/dict';
|
||||
import useTabBarStore from './modules/tab-bar';
|
||||
|
||||
const pinia = createPinia();
|
||||
|
||||
export { useAppStore, useLoginStore, useTabBarStore };
|
||||
export { useAppStore, useLoginStore, useDictStore, useTabBarStore };
|
||||
export default pinia;
|
||||
|
54
continew-admin-ui/src/store/modules/dict/index.ts
Normal file
54
continew-admin-ui/src/store/modules/dict/index.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { DictState, LabelValueState } from '@/store/modules/dict/types';
|
||||
|
||||
const useDictStore = defineStore('dict', {
|
||||
state: () => ({ dict: [] as Array<DictState> }),
|
||||
actions: {
|
||||
// 获取字典
|
||||
getDict(_name: string) {
|
||||
if (_name === null && _name === '') {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
for (let i = 0; i < this.dict.length; i += 1) {
|
||||
if (this.dict[i].name === _name) {
|
||||
return this.dict[i].detail;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
// 设置字典
|
||||
setDict(_name: string, detail: Array<LabelValueState>) {
|
||||
if (_name !== null && _name !== '') {
|
||||
this.dict.push({
|
||||
name: _name,
|
||||
detail,
|
||||
});
|
||||
}
|
||||
},
|
||||
// 删除字典
|
||||
deleteDict(_name: string) {
|
||||
let bln = false;
|
||||
try {
|
||||
for (let i = 0; i < this.dict.length; i += 1) {
|
||||
if (this.dict[i].name === _name) {
|
||||
this.dict.splice(i, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
bln = false;
|
||||
}
|
||||
return bln;
|
||||
},
|
||||
// 清空字典
|
||||
cleanDict() {
|
||||
this.dict = [];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default useDictStore;
|
9
continew-admin-ui/src/store/modules/dict/types.ts
Normal file
9
continew-admin-ui/src/store/modules/dict/types.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface LabelValueState {
|
||||
label: string;
|
||||
value: any;
|
||||
}
|
||||
|
||||
export interface DictState {
|
||||
name: string;
|
||||
detail: Array<LabelValueState>;
|
||||
}
|
27
continew-admin-ui/src/utils/dict.ts
Normal file
27
continew-admin-ui/src/utils/dict.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { ref, toRefs } from 'vue';
|
||||
import { listEnumDict } from '@/api/common';
|
||||
import { useDictStore } from '@/store';
|
||||
|
||||
/**
|
||||
* 获取字典数据
|
||||
*
|
||||
* @param names 字典名列表
|
||||
*/
|
||||
export default function useDict(...names: Array<string>) {
|
||||
const res = ref<any>({});
|
||||
return (() => {
|
||||
names.forEach((name: string) => {
|
||||
res.value[name] = [];
|
||||
const dict = useDictStore().getDict(name);
|
||||
if (dict) {
|
||||
res.value[name] = dict;
|
||||
} else {
|
||||
listEnumDict(name).then((resp) => {
|
||||
res.value[name] = resp.data;
|
||||
useDictStore().setDict(name, res.value[name]);
|
||||
});
|
||||
}
|
||||
});
|
||||
return toRefs(res.value);
|
||||
})();
|
||||
}
|
@@ -10,10 +10,10 @@
|
||||
<a-form-item field="status" hide-label>
|
||||
<a-select
|
||||
v-model="queryParams.status"
|
||||
:options="statusOptions"
|
||||
:options="SuccessFailureStatusEnum"
|
||||
placeholder="登录状态搜索"
|
||||
allow-clear
|
||||
style="width: 150px;"
|
||||
style="width: 150px"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item field="createTime" hide-label>
|
||||
@@ -81,7 +81,6 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { getCurrentInstance, ref, toRefs, reactive } from 'vue';
|
||||
import { SelectOptionData } from '@arco-design/web-vue';
|
||||
import {
|
||||
LoginLogParam,
|
||||
LoginLogRecord,
|
||||
@@ -89,14 +88,11 @@
|
||||
} from '@/api/monitor/log';
|
||||
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const { SuccessFailureStatusEnum } = proxy.useDict('SuccessFailureStatusEnum');
|
||||
|
||||
const loginLogList = ref<LoginLogRecord[]>([]);
|
||||
const total = ref(0);
|
||||
const loading = ref(false);
|
||||
const statusOptions = ref<SelectOptionData[]>([
|
||||
{ label: '成功', value: 1 },
|
||||
{ label: '失败', value: 2 },
|
||||
]);
|
||||
|
||||
const data = reactive({
|
||||
// 查询参数
|
||||
|
@@ -19,7 +19,7 @@
|
||||
<a-form-item field="status" hide-label>
|
||||
<a-select
|
||||
v-model="queryParams.status"
|
||||
:options="statusOptions"
|
||||
:options="SuccessFailureStatusEnum"
|
||||
placeholder="操作状态搜索"
|
||||
allow-clear
|
||||
style="width: 150px"
|
||||
@@ -91,7 +91,6 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { getCurrentInstance, ref, toRefs, reactive } from 'vue';
|
||||
import { SelectOptionData } from '@arco-design/web-vue';
|
||||
import {
|
||||
OperationLogParam,
|
||||
OperationLogRecord,
|
||||
@@ -99,14 +98,11 @@
|
||||
} from '@/api/monitor/log';
|
||||
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const { SuccessFailureStatusEnum } = proxy.useDict('SuccessFailureStatusEnum');
|
||||
|
||||
const operationLogList = ref<OperationLogRecord[]>([]);
|
||||
const total = ref(0);
|
||||
const loading = ref(false);
|
||||
const statusOptions = ref<SelectOptionData[]>([
|
||||
{ label: '成功', value: 1 },
|
||||
{ label: '失败', value: 2 },
|
||||
]);
|
||||
|
||||
const data = reactive({
|
||||
// 查询参数
|
||||
|
@@ -19,7 +19,7 @@
|
||||
<a-form-item field="status" hide-label>
|
||||
<a-select
|
||||
v-model="queryParams.status"
|
||||
:options="statusOptions"
|
||||
:options="DisEnableStatusEnum"
|
||||
placeholder="状态搜索"
|
||||
allow-clear
|
||||
style="width: 150px"
|
||||
@@ -282,11 +282,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { getCurrentInstance, ref, toRefs, reactive } from 'vue';
|
||||
import {
|
||||
SelectOptionData,
|
||||
TreeNodeData,
|
||||
TableData,
|
||||
} from '@arco-design/web-vue';
|
||||
import { TreeNodeData, TableData } from '@arco-design/web-vue';
|
||||
import {
|
||||
DeptRecord,
|
||||
DeptParam,
|
||||
@@ -299,6 +295,7 @@
|
||||
import { listDeptTree } from '@/api/common';
|
||||
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const { DisEnableStatusEnum } = proxy.useDict('DisEnableStatusEnum');
|
||||
|
||||
const deptList = ref<DeptRecord[]>([]);
|
||||
const dept = ref<DeptRecord>({
|
||||
@@ -322,10 +319,6 @@
|
||||
const exportLoading = ref(false);
|
||||
const visible = ref(false);
|
||||
const detailVisible = ref(false);
|
||||
const statusOptions = ref<SelectOptionData[]>([
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 2 },
|
||||
]);
|
||||
const treeData = ref<TreeNodeData[]>();
|
||||
|
||||
const data = reactive({
|
||||
|
@@ -19,7 +19,7 @@
|
||||
<a-form-item field="status" hide-label>
|
||||
<a-select
|
||||
v-model="queryParams.status"
|
||||
:options="statusOptions"
|
||||
:options="DisEnableStatusEnum"
|
||||
placeholder="状态搜索"
|
||||
allow-clear
|
||||
style="width: 150px"
|
||||
@@ -335,11 +335,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { getCurrentInstance, ref, toRefs, reactive } from 'vue';
|
||||
import {
|
||||
SelectOptionData,
|
||||
TreeNodeData,
|
||||
TableData,
|
||||
} from '@arco-design/web-vue';
|
||||
import { TreeNodeData, TableData } from '@arco-design/web-vue';
|
||||
import {
|
||||
MenuRecord,
|
||||
MenuParam,
|
||||
@@ -352,6 +348,7 @@
|
||||
import { listMenuTree } from '@/api/common';
|
||||
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const { DisEnableStatusEnum } = proxy.useDict('DisEnableStatusEnum');
|
||||
|
||||
const menuList = ref<MenuRecord[]>([]);
|
||||
const ids = ref<Array<number>>([]);
|
||||
@@ -364,10 +361,6 @@
|
||||
const expandAll = ref(false);
|
||||
const visible = ref(false);
|
||||
const showChooseIcon = ref(false);
|
||||
const statusOptions = ref<SelectOptionData[]>([
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 2 },
|
||||
]);
|
||||
const treeData = ref<TreeNodeData[]>();
|
||||
|
||||
const data = reactive({
|
||||
|
@@ -19,7 +19,7 @@
|
||||
<a-form-item field="status" hide-label>
|
||||
<a-select
|
||||
v-model="queryParams.status"
|
||||
:options="statusOptions"
|
||||
:options="DisEnableStatusEnum"
|
||||
placeholder="状态搜索"
|
||||
allow-clear
|
||||
style="width: 150px"
|
||||
@@ -267,7 +267,6 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { getCurrentInstance, ref, toRefs, reactive } from 'vue';
|
||||
import { SelectOptionData } from '@arco-design/web-vue';
|
||||
import {
|
||||
PostRecord,
|
||||
PostParam,
|
||||
@@ -279,6 +278,7 @@
|
||||
} from '@/api/system/post';
|
||||
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const { DisEnableStatusEnum } = proxy.useDict('DisEnableStatusEnum');
|
||||
|
||||
const postList = ref<PostRecord[]>([]);
|
||||
const post = ref<PostRecord>({
|
||||
@@ -301,10 +301,6 @@
|
||||
const exportLoading = ref(false);
|
||||
const visible = ref(false);
|
||||
const detailVisible = ref(false);
|
||||
const statusOptions = ref<SelectOptionData[]>([
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 2 },
|
||||
]);
|
||||
|
||||
const data = reactive({
|
||||
// 查询参数
|
||||
|
@@ -19,7 +19,7 @@
|
||||
<a-form-item field="status" hide-label>
|
||||
<a-select
|
||||
v-model="queryParams.status"
|
||||
:options="statusOptions"
|
||||
:options="DisEnableStatusEnum"
|
||||
placeholder="状态搜索"
|
||||
allow-clear
|
||||
style="width: 150px"
|
||||
@@ -244,7 +244,7 @@
|
||||
<a-form-item label="数据权限" field="dataScope">
|
||||
<a-select
|
||||
v-model="form.dataScope"
|
||||
:options="dataScopeOptions"
|
||||
:options="DataScopeEnum"
|
||||
placeholder="请选择数据权限"
|
||||
/>
|
||||
</a-form-item>
|
||||
@@ -378,7 +378,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { getCurrentInstance, ref, toRefs, reactive } from 'vue';
|
||||
import { SelectOptionData, TreeNodeData } from '@arco-design/web-vue';
|
||||
import { TreeNodeData } from '@arco-design/web-vue';
|
||||
import {
|
||||
RoleRecord,
|
||||
RoleParam,
|
||||
@@ -391,6 +391,7 @@
|
||||
import { listMenuTree, listDeptTree } from '@/api/common';
|
||||
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const { DataScopeEnum, DisEnableStatusEnum } = proxy.useDict('DataScopeEnum', 'DisEnableStatusEnum');
|
||||
|
||||
const roleList = ref<RoleRecord[]>([]);
|
||||
const role = ref<RoleRecord>({
|
||||
@@ -417,17 +418,6 @@
|
||||
const exportLoading = ref(false);
|
||||
const visible = ref(false);
|
||||
const detailVisible = ref(false);
|
||||
const statusOptions = ref<SelectOptionData[]>([
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 2 },
|
||||
]);
|
||||
const dataScopeOptions = ref<SelectOptionData[]>([
|
||||
{ label: '全部数据权限', value: 1 },
|
||||
{ label: '本部门及以下数据权限', value: 2 },
|
||||
{ label: '本部门数据权限', value: 3 },
|
||||
{ label: '仅本人数据权限', value: 4 },
|
||||
{ label: '自定义数据权限', value: 5 },
|
||||
]);
|
||||
const menuLoading = ref(false);
|
||||
const deptLoading = ref(false);
|
||||
const menuOptions = ref<TreeNodeData[]>([]);
|
||||
|
@@ -36,7 +36,7 @@
|
||||
<a-form-item field="status" hide-label>
|
||||
<a-select
|
||||
v-model="queryParams.status"
|
||||
:options="statusOptions"
|
||||
:options="DisEnableStatusEnum"
|
||||
placeholder="状态搜索"
|
||||
allow-clear
|
||||
style="width: 150px"
|
||||
@@ -484,7 +484,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { getCurrentInstance, ref, toRefs, reactive, watch } from 'vue';
|
||||
import { SelectOptionData, TreeNodeData } from '@arco-design/web-vue';
|
||||
import { TreeNodeData } from '@arco-design/web-vue';
|
||||
import {
|
||||
UserRecord,
|
||||
UserParam,
|
||||
@@ -496,15 +496,12 @@
|
||||
resetPassword,
|
||||
updateUserRole,
|
||||
} from '@/api/system/user';
|
||||
import {
|
||||
LabelValueRecord,
|
||||
listDeptTree,
|
||||
listPostDict,
|
||||
listRoleDict,
|
||||
} from '@/api/common';
|
||||
import { listDeptTree, listPostDict, listRoleDict } from '@/api/common';
|
||||
import { LabelValueState } from '@/store/modules/dict/types';
|
||||
import getAvatar from '@/utils/avatar';
|
||||
|
||||
const { proxy } = getCurrentInstance() as any;
|
||||
const { DisEnableStatusEnum } = proxy.useDict('DisEnableStatusEnum');
|
||||
|
||||
const userList = ref<UserRecord[]>([]);
|
||||
const user = ref<UserRecord>({
|
||||
@@ -535,16 +532,12 @@
|
||||
const visible = ref(false);
|
||||
const userRoleVisible = ref(false);
|
||||
const detailVisible = ref(false);
|
||||
const statusOptions = ref<SelectOptionData[]>([
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 2 },
|
||||
]);
|
||||
const deptLoading = ref(false);
|
||||
const postLoading = ref(false);
|
||||
const roleLoading = ref(false);
|
||||
const deptOptions = ref<TreeNodeData[]>([]);
|
||||
const postOptions = ref<LabelValueRecord[]>([]);
|
||||
const roleOptions = ref<LabelValueRecord[]>([]);
|
||||
const postOptions = ref<LabelValueState[]>([]);
|
||||
const roleOptions = ref<LabelValueState[]>([]);
|
||||
const deptTree = ref<TreeNodeData[]>([]);
|
||||
const deptName = ref('');
|
||||
|
||||
|
Reference in New Issue
Block a user