This commit is contained in:
孟帅
2024-04-22 23:08:40 +08:00
parent 82483bd7b9
commit e144b12580
445 changed files with 17457 additions and 6708 deletions

View File

@@ -1,8 +1,11 @@
import { ref } from 'vue';
import { cloneDeep } from 'lodash-es';
import { Option } from '@/utils/hotgo';
import { Dicts } from '@/api/dict/dict';
export interface State {
id: number;
pid: number;
pid?: number;
title: string;
name: string;
path: string;
@@ -12,7 +15,7 @@ export interface State {
redirect: string;
permissions: string;
permissionName: string;
component: string;
component?: string;
alwaysShow: number;
activeMenu: string;
isRoot: number;
@@ -23,9 +26,11 @@ export interface State {
affix: number;
status: number;
sort: number;
disabled: boolean;
children?: State[];
}
export const defaultState = {
export const defaultState: State = {
id: 0,
pid: 0,
title: '',
@@ -37,22 +42,70 @@ export const defaultState = {
redirect: '',
permissions: '',
permissionName: '',
component: '',
alwaysShow: 1,
component: null,
alwaysShow: 2,
activeMenu: '',
isRoot: 0,
isRoot: 2,
isFrame: 2,
frameSrc: '',
keepAlive: 0,
hidden: 0,
affix: 0,
keepAlive: 2,
hidden: 2,
affix: 2,
status: 1,
sort: 10,
disabled: false,
children: null,
};
export function newState(state: State | null): State {
if (state !== null) {
return cloneDeep(state);
return defaultValueCheck(cloneDeep(state));
}
return cloneDeep(defaultState);
return defaultValueCheck(cloneDeep(defaultState));
}
// 默认值校正,主要为了解决历史数据格式不规范问题
export function defaultValueCheck(state: State): State {
if (state.pid < 1) {
state.pid = null;
}
if (state.alwaysShow != 1) {
state.alwaysShow = 2;
}
if (state.isRoot != 1) {
state.isRoot = 2;
}
if (state.isFrame != 1) {
state.isFrame = 2;
}
if (state.keepAlive != 1) {
state.keepAlive = 2;
}
if (state.hidden != 1) {
state.hidden = 2;
}
if (state.affix != 1) {
state.affix = 2;
}
if (state.status != 1) {
state.status = 2;
}
return state;
}
// 字典数据选项
export const options = ref({
sys_menu_types: [] as Option[],
sys_menu_component: [] as Option[],
sys_normal_disable: [] as Option[],
sys_switch: [] as Option[],
});
// 加载字典数据选项
export function loadOptions() {
Dicts({
types: ['sys_menu_types', 'sys_menu_component', 'sys_normal_disable', 'sys_switch'],
}).then((res) => {
options.value = res;
});
}