2024-09-28 22:28:46 +08:00
|
|
|
import { h, reactive } from 'vue';
|
|
|
|
import type { FormRules } from 'element-plus';
|
2024-10-18 13:51:03 +08:00
|
|
|
import { ElTag } from 'element-plus';
|
2024-09-28 22:28:46 +08:00
|
|
|
import { $t } from '@/plugins/i18n';
|
|
|
|
import { isAllEmpty } from '@pureadmin/utils';
|
2024-10-03 13:44:52 +08:00
|
|
|
import { useRenderIcon } from '@/components/CommonIcon/src/hooks';
|
2024-09-28 22:28:46 +08:00
|
|
|
|
2024-10-26 15:11:36 +08:00
|
|
|
/**
|
|
|
|
* 标签栏菜单类型匹配
|
|
|
|
* @param type
|
|
|
|
* @param text
|
|
|
|
*/
|
|
|
|
const getMenuType = (type: number, text: boolean = false): any => {
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
return text ? '菜单' : 'primary';
|
|
|
|
case 1:
|
|
|
|
return text ? 'iframe' : 'warning';
|
|
|
|
case 2:
|
|
|
|
return text ? '外链' : 'danger';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** 格式化菜单选项 */
|
|
|
|
export const formatHigherMenuOptions = (treeList: any) => {
|
|
|
|
if (!treeList || !treeList.length) return;
|
|
|
|
const newTreeList = [];
|
|
|
|
for (let i = 0; i < treeList.length; i++) {
|
|
|
|
treeList[i].title = $t(treeList[i].title);
|
|
|
|
formatHigherMenuOptions(treeList[i].children);
|
|
|
|
newTreeList.push(treeList[i]);
|
|
|
|
}
|
|
|
|
return newTreeList;
|
|
|
|
};
|
|
|
|
|
2024-09-28 22:28:46 +08:00
|
|
|
export const columns: TableColumnList = [
|
2024-10-26 15:11:36 +08:00
|
|
|
{ type: 'selection', align: 'left' },
|
2024-09-28 22:28:46 +08:00
|
|
|
{
|
|
|
|
label: '菜单名称',
|
|
|
|
prop: 'title',
|
|
|
|
align: 'left',
|
|
|
|
cellRenderer: ({ row }) => (
|
|
|
|
<>
|
|
|
|
<span class='inline-block mr-1'>
|
|
|
|
{h(useRenderIcon(row.icon), {
|
|
|
|
style: { paddingTop: '1px' },
|
|
|
|
})}
|
|
|
|
</span>
|
|
|
|
<span>{$t(row.title)}</span>
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '菜单类型',
|
|
|
|
prop: 'menuType',
|
|
|
|
width: 100,
|
|
|
|
cellRenderer: ({ row, props }) => (
|
2024-10-18 13:51:03 +08:00
|
|
|
<ElTag size={props.size} type={getMenuType(row.menuType)} effect='plain'>
|
2024-09-28 22:28:46 +08:00
|
|
|
{getMenuType(row.menuType, true)}
|
2024-10-18 13:51:03 +08:00
|
|
|
</ElTag>
|
2024-09-28 22:28:46 +08:00
|
|
|
),
|
|
|
|
},
|
|
|
|
{ label: '路由路径', prop: 'path' },
|
|
|
|
{
|
|
|
|
label: '组件路径',
|
|
|
|
prop: 'component',
|
|
|
|
formatter: ({ path, component }) => (isAllEmpty(component) ? path : component),
|
|
|
|
},
|
2024-10-18 13:51:03 +08:00
|
|
|
{ label: '排序', prop: 'rank', width: 80, slot: 'rank' },
|
2024-10-03 13:44:52 +08:00
|
|
|
{ label: '隐藏', prop: 'visible', slot: 'visible', width: 100 },
|
2024-10-03 18:41:26 +08:00
|
|
|
{ label: $t('table.updateTime'), prop: 'updateTime', sortable: true },
|
|
|
|
{ label: $t('table.createTime'), prop: 'createTime', sortable: true },
|
|
|
|
{ label: $t('table.createUser'), prop: 'createUser', slot: 'createUser', width: 90 },
|
|
|
|
{ label: $t('table.updateUser'), prop: 'updateUser', slot: 'updateUser', width: 90 },
|
2024-10-18 13:51:03 +08:00
|
|
|
{ label: $t('table.operation'), fixed: 'right', width: 230, slot: 'operation' },
|
2024-09-28 22:28:46 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
/** 自定义表单规则校验 */
|
|
|
|
export const formRules = reactive<FormRules>({
|
|
|
|
title: [{ required: true, message: '菜单名称为必填项', trigger: 'blur' }],
|
|
|
|
name: [{ required: true, message: '路由名称为必填项', trigger: 'blur' }],
|
|
|
|
path: [{ required: true, message: '路由路径为必填项', trigger: 'blur' }],
|
|
|
|
auths: [{ required: true, message: '权限标识为必填项', trigger: 'blur' }],
|
|
|
|
});
|