156 lines
3.7 KiB
Vue
156 lines
3.7 KiB
Vue
<script lang="ts" setup>
|
|
import type {
|
|
OnActionClickParams,
|
|
VxeTableGridOptions,
|
|
} from '#/adapter/vxe-table';
|
|
import type { SystemMenuApi } from '#/api/system/menu';
|
|
|
|
import { ref } from 'vue';
|
|
import { $t } from '#/locales';
|
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
|
import { getMenuList, deleteMenu } from '#/api/system/menu';
|
|
import { SystemMenuTypeEnum } from '#/utils/constants';
|
|
|
|
import { Page, useVbenModal } from '@vben/common-ui';
|
|
import { Button, message } from 'ant-design-vue';
|
|
import { IconifyIcon, Plus } from '@vben/icons';
|
|
|
|
import { useGridColumns } from './data';
|
|
import Form from './modules/form.vue';
|
|
|
|
const [FormModal, formModalApi] = useVbenModal({
|
|
connectedComponent: Form,
|
|
destroyOnClose: true,
|
|
});
|
|
|
|
/** 编辑菜单 */
|
|
function onEdit(row: SystemMenuApi.SystemMenu) {
|
|
formModalApi.setData(row).open();
|
|
}
|
|
|
|
/** 添加下级菜单 */
|
|
function onAppend(row: SystemMenuApi.SystemMenu) {
|
|
formModalApi.setData({ pid: row.id }).open();
|
|
}
|
|
|
|
/** 创建菜单 */
|
|
function onCreate() {
|
|
formModalApi.setData({}).open();
|
|
}
|
|
|
|
/** 删除菜单 */
|
|
async function onDelete(row: SystemMenuApi.SystemMenu) {
|
|
const hideLoading = message.loading({
|
|
content: $t('ui.actionMessage.deleting', [row.name]),
|
|
duration: 0,
|
|
key: 'action_process_msg',
|
|
});
|
|
try {
|
|
await deleteMenu(row.id as number);
|
|
message.success({
|
|
content: $t('ui.actionMessage.deleteSuccess', [row.name]),
|
|
key: 'action_process_msg',
|
|
});
|
|
onRefresh();
|
|
} catch (error) {
|
|
hideLoading();
|
|
}
|
|
}
|
|
|
|
/** 表格操作按钮的回调函数 */
|
|
function onActionClick({
|
|
code,
|
|
row,
|
|
}: OnActionClickParams<SystemMenuApi.SystemMenu>) {
|
|
switch (code) {
|
|
case 'append': {
|
|
onAppend(row);
|
|
break;
|
|
}
|
|
case 'delete': {
|
|
onDelete(row);
|
|
break;
|
|
}
|
|
case 'edit': {
|
|
onEdit(row);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
const [Grid, gridApi] = useVbenVxeGrid({
|
|
gridOptions: {
|
|
columns: useGridColumns(onActionClick),
|
|
height: 'auto',
|
|
keepSource: true,
|
|
pagerConfig: {
|
|
enabled: false,
|
|
},
|
|
proxyConfig: {
|
|
ajax: {
|
|
query: async (_params) => {
|
|
return await getMenuList();
|
|
},
|
|
},
|
|
},
|
|
rowConfig: {
|
|
keyField: 'id',
|
|
},
|
|
toolbarConfig: {
|
|
refresh: { code: 'query' },
|
|
},
|
|
treeConfig: {
|
|
parentField: 'parentId',
|
|
rowField: 'id',
|
|
transform: true,
|
|
reserve: true,
|
|
},
|
|
} as VxeTableGridOptions,
|
|
});
|
|
|
|
/** 刷新表格 */
|
|
function onRefresh() {
|
|
gridApi.query();
|
|
}
|
|
|
|
/** 切换树形展开/收缩状态 */
|
|
const isExpanded = ref(false);
|
|
function toggleExpand() {
|
|
isExpanded.value = !isExpanded.value;
|
|
gridApi.grid.setAllTreeExpand(isExpanded.value);
|
|
}
|
|
</script>
|
|
<template>
|
|
<Page auto-content-height>
|
|
<FormModal @success="onRefresh" />
|
|
<Grid>
|
|
<template #toolbar-tools>
|
|
<Button type="primary" @click="onCreate">
|
|
<Plus class="size-5" />
|
|
{{ $t('ui.actionTitle.create', ['菜单']) }}
|
|
</Button>
|
|
<Button class="ml-2" @click="toggleExpand">
|
|
{{ isExpanded ? '收缩' : '展开' }}
|
|
</Button>
|
|
</template>
|
|
<template #title="{ row }">
|
|
<div class="flex w-full items-center gap-1">
|
|
<div class="size-5 flex-shrink-0">
|
|
<IconifyIcon
|
|
v-if="row.type === SystemMenuTypeEnum.BUTTON"
|
|
icon="carbon:square-outline"
|
|
class="size-full"
|
|
/>
|
|
<IconifyIcon
|
|
v-else-if="row.icon"
|
|
:icon="row.icon || 'carbon:circle-dash'"
|
|
class="size-full"
|
|
/>
|
|
</div>
|
|
<span class="flex-auto">{{ $t(row.name) }}</span>
|
|
<div class="items-center justify-end"></div>
|
|
</div>
|
|
</template>
|
|
</Grid>
|
|
</Page>
|
|
</template> |