mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat: 新增菜单管理页面
This commit is contained in:
@ -25,6 +25,13 @@ export function transformRecordToOption<T extends Record<string, string>>(record
|
||||
})) as CommonType.Option<keyof T>[];
|
||||
}
|
||||
|
||||
export function transformRecordToNumberOption<T extends Record<string, string>>(record: T) {
|
||||
return Object.entries(record).map(([value, label]) => ({
|
||||
value,
|
||||
label
|
||||
})) as CommonType.Option<keyof T>[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate options
|
||||
*
|
||||
@ -56,3 +63,20 @@ export function toggleHtmlClass(className: string) {
|
||||
remove
|
||||
};
|
||||
}
|
||||
|
||||
/* 驼峰转换下划线 */
|
||||
export function humpToLine(str: string, line: string = '-') {
|
||||
let temp = str.replace(/[A-Z]/g, match => {
|
||||
return `${line}${match.toLowerCase()}`;
|
||||
});
|
||||
// 如果首字母是大写,执行replace时会多一个_,这里需要去掉
|
||||
if (temp.slice(0, 1) === line) {
|
||||
temp = temp.slice(1);
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
/** 判断是否为空 */
|
||||
export function isNotNull(value: any) {
|
||||
return value !== undefined && value !== null && value !== '' && value !== 'undefined' && value !== 'null';
|
||||
}
|
||||
|
@ -7,3 +7,13 @@ export function getLocalIcons() {
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
export function getLocalMenuIcons() {
|
||||
const svgIcons = import.meta.glob('/src/assets/svg-icon/menu/*.svg');
|
||||
|
||||
const keys = Object.keys(svgIcons)
|
||||
.map(item => item.split('/').at(-1)?.replace('.svg', '') || '')
|
||||
.filter(Boolean);
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
67
src/utils/ruoyi.ts
Normal file
67
src/utils/ruoyi.ts
Normal file
@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 构造树型结构数据
|
||||
*
|
||||
* @param {any} data 数据源
|
||||
* @param {any} id id字段 默认 'id'
|
||||
* @param {any} parentId 父节点字段 默认 'parentId'
|
||||
* @param {any} children 孩子节点字段 默认 'children'
|
||||
*/
|
||||
export const handleMenuTree = (
|
||||
data: Api.System.MenuList,
|
||||
id: keyof Api.System.Menu,
|
||||
parentId?: keyof Api.System.Menu,
|
||||
children?: keyof Api.System.Menu
|
||||
// eslint-disable-next-line max-params
|
||||
): Api.System.MenuList => {
|
||||
const config: {
|
||||
id: keyof Api.System.Menu;
|
||||
parentId: keyof Api.System.Menu;
|
||||
childrenList: keyof Api.System.Menu;
|
||||
} = {
|
||||
id: id || 'id',
|
||||
parentId: parentId || 'parentId',
|
||||
childrenList: children || 'children'
|
||||
};
|
||||
|
||||
const childrenListMap: any = {};
|
||||
const nodeIds: any = {};
|
||||
const tree: Api.System.MenuList = [];
|
||||
|
||||
for (const d of data) {
|
||||
const pid = d[config.parentId];
|
||||
if (!childrenListMap[pid]) {
|
||||
childrenListMap[pid] = [];
|
||||
}
|
||||
nodeIds[d[config.id]] = d;
|
||||
if (d.menuType !== 'F') {
|
||||
childrenListMap[pid].push(d);
|
||||
}
|
||||
|
||||
if (childrenListMap[pid].length === 0) {
|
||||
childrenListMap[pid] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
for (const d of data) {
|
||||
const pid = d[config.parentId];
|
||||
if (!nodeIds[pid]) {
|
||||
tree.push(d);
|
||||
}
|
||||
}
|
||||
const adaptToChildrenList = (o: any) => {
|
||||
if (childrenListMap[o[config.id]] !== null) {
|
||||
o[config.childrenList] = childrenListMap[o[config.id]];
|
||||
}
|
||||
if (o[config.childrenList]) {
|
||||
for (const c of o[config.childrenList]) {
|
||||
adaptToChildrenList(c);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
for (const t of tree) {
|
||||
adaptToChildrenList(t);
|
||||
}
|
||||
|
||||
return tree;
|
||||
};
|
Reference in New Issue
Block a user