2024-03-21 10:57:53 +08:00
|
|
|
<script setup lang="tsx">
|
|
|
|
import { ref } from 'vue';
|
2024-03-26 11:47:11 +08:00
|
|
|
import type { Ref } from 'vue';
|
2024-03-21 10:57:53 +08:00
|
|
|
import { NButton, NPopconfirm, NTag } from 'naive-ui';
|
|
|
|
import { useBoolean } from '@sa/hooks';
|
2024-03-26 11:47:11 +08:00
|
|
|
import { fetchGetAllPages, fetchGetMenuList } from '@/service/api';
|
2024-03-21 10:57:53 +08:00
|
|
|
import { useAppStore } from '@/store/modules/app';
|
2024-03-26 11:47:11 +08:00
|
|
|
import { useTable, useTableOperate } from '@/hooks/common/table';
|
2024-03-21 10:57:53 +08:00
|
|
|
import { $t } from '@/locales';
|
|
|
|
import { yesOrNoRecord } from '@/constants/common';
|
|
|
|
import { enableStatusRecord, menuTypeRecord } from '@/constants/business';
|
|
|
|
import SvgIcon from '@/components/custom/svg-icon.vue';
|
|
|
|
import MenuOperateDrawer, { type OperateType } from './modules/menu-operate-drawer.vue';
|
|
|
|
|
|
|
|
const appStore = useAppStore();
|
2024-03-26 11:47:11 +08:00
|
|
|
|
|
|
|
const { bool: drawerVisible, setTrue: openDrawer, setFalse: _closeDrawer } = useBoolean();
|
2024-03-21 10:57:53 +08:00
|
|
|
|
|
|
|
const wrapperRef = ref<HTMLElement | null>(null);
|
|
|
|
|
2024-03-26 11:47:11 +08:00
|
|
|
const { columns, columnChecks, data, loading, pagination, getData } = useTable({
|
2024-03-21 10:57:53 +08:00
|
|
|
apiFn: fetchGetMenuList,
|
|
|
|
columns: () => [
|
|
|
|
{
|
|
|
|
type: 'selection',
|
|
|
|
align: 'center',
|
|
|
|
width: 48
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'id',
|
|
|
|
title: $t('page.manage.menu.id'),
|
|
|
|
align: 'center'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'menuType',
|
|
|
|
title: $t('page.manage.menu.menuType'),
|
|
|
|
align: 'center',
|
|
|
|
width: 80,
|
|
|
|
render: row => {
|
|
|
|
const tagMap: Record<Api.Common.EnableStatus, NaiveUI.ThemeColor> = {
|
|
|
|
1: 'default',
|
|
|
|
2: 'primary'
|
|
|
|
};
|
|
|
|
|
|
|
|
const label = $t(menuTypeRecord[row.menuType]);
|
|
|
|
|
|
|
|
return <NTag type={tagMap[row.menuType]}>{label}</NTag>;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'menuName',
|
|
|
|
title: $t('page.manage.menu.menuName'),
|
|
|
|
align: 'center',
|
|
|
|
minWidth: 120,
|
|
|
|
render: row => {
|
|
|
|
const { i18nKey, menuName } = row;
|
|
|
|
|
|
|
|
const label = i18nKey ? $t(i18nKey) : menuName;
|
|
|
|
|
|
|
|
return <span>{label}</span>;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'icon',
|
|
|
|
title: $t('page.manage.menu.icon'),
|
|
|
|
align: 'center',
|
|
|
|
width: 60,
|
|
|
|
render: row => {
|
|
|
|
const icon = row.iconType === '1' ? row.icon : undefined;
|
|
|
|
|
|
|
|
const localIcon = row.iconType === '2' ? row.icon : undefined;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div class="flex-center">
|
|
|
|
<SvgIcon icon={icon} localIcon={localIcon} class="text-icon" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'routeName',
|
|
|
|
title: $t('page.manage.menu.routeName'),
|
|
|
|
align: 'center',
|
|
|
|
minWidth: 120
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'routePath',
|
|
|
|
title: $t('page.manage.menu.routePath'),
|
|
|
|
align: 'center',
|
|
|
|
minWidth: 120
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'status',
|
|
|
|
title: $t('page.manage.menu.menuStatus'),
|
|
|
|
align: 'center',
|
|
|
|
width: 80,
|
|
|
|
render: row => {
|
|
|
|
if (row.status === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const tagMap: Record<Api.Common.EnableStatus, NaiveUI.ThemeColor> = {
|
|
|
|
1: 'success',
|
|
|
|
2: 'warning'
|
|
|
|
};
|
|
|
|
|
2024-03-30 17:07:04 +08:00
|
|
|
const label = $t(enableStatusRecord[row.status!]);
|
2024-03-21 10:57:53 +08:00
|
|
|
|
2024-03-30 17:07:04 +08:00
|
|
|
return <NTag type={tagMap[row.status!]}>{label}</NTag>;
|
2024-03-21 10:57:53 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'hideInMenu',
|
|
|
|
title: $t('page.manage.menu.hideInMenu'),
|
|
|
|
align: 'center',
|
|
|
|
width: 80,
|
|
|
|
render: row => {
|
|
|
|
const hide: CommonType.YesOrNo = row.hideInMenu ? 'Y' : 'N';
|
|
|
|
|
|
|
|
const tagMap: Record<CommonType.YesOrNo, NaiveUI.ThemeColor> = {
|
|
|
|
Y: 'error',
|
|
|
|
N: 'default'
|
|
|
|
};
|
|
|
|
|
|
|
|
const label = $t(yesOrNoRecord[hide]);
|
|
|
|
|
|
|
|
return <NTag type={tagMap[hide]}>{label}</NTag>;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'parentId',
|
|
|
|
title: $t('page.manage.menu.parentId'),
|
|
|
|
width: 90,
|
|
|
|
align: 'center'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'order',
|
|
|
|
title: $t('page.manage.menu.order'),
|
|
|
|
align: 'center',
|
|
|
|
width: 60
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'operate',
|
|
|
|
title: $t('common.operate'),
|
|
|
|
align: 'center',
|
|
|
|
width: 230,
|
|
|
|
render: row => (
|
|
|
|
<div class="flex-center justify-end gap-8px">
|
|
|
|
{row.menuType === '1' && (
|
2024-03-26 11:47:11 +08:00
|
|
|
<NButton type="primary" ghost size="small" onClick={() => handleAddChildMenu(row)}>
|
2024-03-21 10:57:53 +08:00
|
|
|
{$t('page.manage.menu.addChildMenu')}
|
|
|
|
</NButton>
|
|
|
|
)}
|
2024-03-26 11:47:11 +08:00
|
|
|
<NButton type="primary" ghost size="small" onClick={() => handleEdit(row)}>
|
2024-03-21 10:57:53 +08:00
|
|
|
{$t('common.edit')}
|
|
|
|
</NButton>
|
|
|
|
<NPopconfirm onPositiveClick={() => handleDelete(row.id)}>
|
|
|
|
{{
|
|
|
|
default: () => $t('common.confirmDelete'),
|
|
|
|
trigger: () => (
|
|
|
|
<NButton type="error" ghost size="small">
|
|
|
|
{$t('common.delete')}
|
|
|
|
</NButton>
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
</NPopconfirm>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2024-03-26 11:47:11 +08:00
|
|
|
const { checkedRowKeys, onBatchDeleted, onDeleted } = useTableOperate(data, getData);
|
|
|
|
|
2024-03-21 10:57:53 +08:00
|
|
|
const operateType = ref<OperateType>('add');
|
|
|
|
|
|
|
|
function handleAdd() {
|
|
|
|
operateType.value = 'add';
|
|
|
|
openDrawer();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleBatchDelete() {
|
|
|
|
// request
|
|
|
|
console.log(checkedRowKeys.value);
|
|
|
|
|
2024-03-26 11:47:11 +08:00
|
|
|
onBatchDeleted();
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleDelete(id: number) {
|
|
|
|
// request
|
|
|
|
console.log(id);
|
2024-03-21 10:57:53 +08:00
|
|
|
|
2024-03-26 11:47:11 +08:00
|
|
|
onDeleted();
|
2024-03-21 10:57:53 +08:00
|
|
|
}
|
|
|
|
|
2024-03-26 11:47:11 +08:00
|
|
|
/** the edit menu data or the parent menu data when adding a child menu */
|
|
|
|
const editingData: Ref<Api.SystemManage.Menu | null> = ref(null);
|
|
|
|
|
|
|
|
function handleEdit(item: Api.SystemManage.Menu) {
|
|
|
|
operateType.value = 'edit';
|
|
|
|
editingData.value = { ...item };
|
|
|
|
|
2024-03-21 10:57:53 +08:00
|
|
|
openDrawer();
|
|
|
|
}
|
|
|
|
|
2024-03-26 11:47:11 +08:00
|
|
|
function handleAddChildMenu(item: Api.SystemManage.Menu) {
|
|
|
|
operateType.value = 'addChild';
|
|
|
|
|
|
|
|
editingData.value = { ...item };
|
2024-03-21 10:57:53 +08:00
|
|
|
|
|
|
|
openDrawer();
|
|
|
|
}
|
|
|
|
|
2024-03-26 11:47:11 +08:00
|
|
|
const allPages = ref<string[]>([]);
|
2024-03-21 10:57:53 +08:00
|
|
|
|
2024-03-26 11:47:11 +08:00
|
|
|
async function getAllPages() {
|
|
|
|
const { data: pages } = await fetchGetAllPages();
|
|
|
|
allPages.value = pages || [];
|
2024-03-21 10:57:53 +08:00
|
|
|
}
|
|
|
|
|
2024-03-26 11:47:11 +08:00
|
|
|
function init() {
|
|
|
|
getAllPages();
|
2024-03-21 10:57:53 +08:00
|
|
|
}
|
2024-03-26 11:47:11 +08:00
|
|
|
|
|
|
|
// init
|
|
|
|
init();
|
2024-03-21 10:57:53 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2024-03-26 11:47:11 +08:00
|
|
|
<div ref="wrapperRef" class="flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
|
2024-03-21 10:57:53 +08:00
|
|
|
<NCard :title="$t('page.manage.menu.title')" :bordered="false" size="small" class="sm:flex-1-hidden card-wrapper">
|
|
|
|
<template #header-extra>
|
|
|
|
<TableHeaderOperation
|
2024-03-26 11:47:11 +08:00
|
|
|
v-model:columns="columnChecks"
|
2024-03-21 10:57:53 +08:00
|
|
|
:disabled-delete="checkedRowKeys.length === 0"
|
|
|
|
:loading="loading"
|
|
|
|
@add="handleAdd"
|
|
|
|
@delete="handleBatchDelete"
|
|
|
|
@refresh="getData"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<NDataTable
|
|
|
|
v-model:checked-row-keys="checkedRowKeys"
|
|
|
|
:columns="columns"
|
|
|
|
:data="data"
|
|
|
|
size="small"
|
|
|
|
:flex-height="!appStore.isMobile"
|
|
|
|
:scroll-x="1088"
|
|
|
|
:loading="loading"
|
2024-03-26 11:47:11 +08:00
|
|
|
:row-key="row => row.id"
|
2024-03-21 10:57:53 +08:00
|
|
|
remote
|
|
|
|
:pagination="pagination"
|
|
|
|
class="sm:h-full"
|
|
|
|
/>
|
|
|
|
<MenuOperateDrawer
|
|
|
|
v-model:visible="drawerVisible"
|
|
|
|
:operate-type="operateType"
|
|
|
|
:row-data="editingData"
|
2024-03-26 11:47:11 +08:00
|
|
|
:all-pages="allPages"
|
2024-03-21 10:57:53 +08:00
|
|
|
@submitted="getData"
|
|
|
|
/>
|
|
|
|
</NCard>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped></style>
|