UNIVPLMDataIntegration/Web/src/views/system/menu/index.vue

202 lines
7.5 KiB
Vue
Raw Normal View History

2024-06-15 13:02:35 +08:00
<template>
2024-07-01 11:42:05 +08:00
<div class="sys-menu-container" v-loading="options.loading">
<el-card shadow="hover" :body-style="{ padding: '5px 5px 0 5px', display: 'flex', width: '100%', height: '100%', alignItems: 'start' }">
<el-form :model="state.queryParams" ref="queryForm" :show-message="false" :inlineMessage="true" label-width="auto" style="flex: 1 1 0%">
2024-07-01 11:42:05 +08:00
<el-row :gutter="10">
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
<el-form-item label="菜单名称" prop="title">
<el-input v-model="state.queryParams.title" placeholder="菜单名称" clearable @keyup.enter.native="handleQuery" />
</el-form-item>
</el-col>
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
<el-form-item label="类型" prop="type">
<el-select v-model="state.queryParams.type" placeholder="类型" clearable @clear="state.queryParams.type = undefined">
<el-option label="目录" :value="1" />
<el-option label="菜单" :value="2" />
<el-option label="按钮" :value="3" />
</el-select>
</el-form-item>
</el-col>
</el-row>
</el-form>
<el-divider style="height: calc(100% - 5px); margin: 0 10px" direction="vertical" />
<el-row>
<el-col>
2024-06-15 13:02:35 +08:00
<el-button-group>
2024-07-01 11:53:29 +08:00
<el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'sysMenu:list'" :loading="options.loading"> 查询 </el-button>
2024-07-01 11:42:05 +08:00
<el-button icon="ele-Refresh" @click="resetQuery" :loading="options.loading"> 重置 </el-button>
2024-06-15 13:02:35 +08:00
</el-button-group>
2024-07-01 11:42:05 +08:00
</el-col>
</el-row>
2024-06-15 13:02:35 +08:00
</el-card>
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
2024-07-09 09:47:33 +08:00
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" v-on="gridEvents">
2024-07-01 11:42:05 +08:00
<template #toolbar_buttons>
<el-button type="primary" icon="ele-Plus" @click="handleAdd" v-auth="'sysMenu:add'"> 新增 </el-button>
<el-button-group style="padding-left: 12px">
<el-button type="primary" icon="ele-Expand" @click="handleExpand"> 全部展开 </el-button>
<el-button type="primary" icon="ele-Fold" @click="handleFold"> 全部折叠 </el-button>
</el-button-group>
</template>
<template #toolbar_tools> </template>
<template #empty>
<el-empty :image-size="200" />
</template>
<template #row_title="{ row }">
<SvgIcon :name="row.icon" />
<span class="ml10">{{ $t(row.title) }}</span>
</template>
<template #row_type="{ row }">
<el-tag type="warning" v-if="row.type === 1">目录</el-tag>
<el-tag v-else-if="row.type === 2">菜单</el-tag>
<el-tag type="info" v-else>按钮</el-tag>
</template>
<template #row_status="{ row }">
<el-tag v-if="row.status === 1" type="success">启用</el-tag>
<el-tag v-else type="danger">禁用</el-tag>
</template>
2024-07-01 11:53:29 +08:00
<template #row_record="{ row }">
<ModifyRecord :data="row" />
</template>
2024-07-01 11:42:05 +08:00
<template #row_buttons="{ row }">
<el-tooltip content="编辑" placement="top">
<el-button icon="ele-Edit" text type="primary" v-auth="'sysMenu:update'" @click="handleEdit(row)"> </el-button>
</el-tooltip>
<el-tooltip content="删除" placement="top">
<el-button icon="ele-Delete" text type="danger" v-auth="'sysMenu:delete'" @click="handleDelete(row)"> </el-button>
</el-tooltip>
</template>
</vxe-grid>
2024-06-15 13:02:35 +08:00
</el-card>
2024-07-01 11:42:05 +08:00
<EditMenu ref="editMenuRef" :title="state.title" :menuData="state.menuData" @handleQuery="handleQuery" />
2024-06-15 13:02:35 +08:00
</div>
</template>
<script lang="ts" setup name="sysMenu">
2024-07-09 09:47:33 +08:00
import { reactive, ref } from 'vue';
2024-06-15 13:02:35 +08:00
import { ElMessageBox, ElMessage } from 'element-plus';
2024-07-10 12:59:32 +08:00
import { VxeGridInstance, VxeGridListeners } from 'vxe-table';
2024-07-09 09:47:33 +08:00
import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
2024-07-01 11:42:05 +08:00
import SvgIcon from '/@/components/svgIcon/index.vue';
2024-06-15 13:02:35 +08:00
import EditMenu from '/@/views/system/menu/component/editMenu.vue';
2024-07-01 11:53:29 +08:00
import ModifyRecord from '/@/components/table/modifyRecord.vue';
2024-06-15 13:02:35 +08:00
import { getAPI } from '/@/utils/axios-utils';
import { SysMenuApi } from '/@/api-services/api';
import { SysMenu } from '/@/api-services/models';
2024-07-01 11:42:05 +08:00
const xGrid = ref<VxeGridInstance>();
2024-06-15 13:02:35 +08:00
const editMenuRef = ref<InstanceType<typeof EditMenu>>();
const state = reactive({
menuData: [] as Array<SysMenu>,
queryParams: {
title: undefined,
type: undefined,
},
2024-07-01 11:42:05 +08:00
title: '',
2024-06-15 13:02:35 +08:00
});
2024-07-01 11:42:05 +08:00
// 表格参数配置
const options = useVxeTable<SysMenu>(
{
id: 'sysMenu',
name: '菜单信息',
columns: [
// { type: 'checkbox', width: 40, fixed: 'left' },
{ type: 'seq', title: '序号', width: 60, fixed: 'left' },
{ field: 'title', title: '菜单名称', minWidth: 180, showOverflow: 'tooltip', treeNode: true, slots: { default: 'row_title' } },
{ field: 'type', title: '菜单类型', minWidth: 100, showOverflow: 'tooltip', slots: { default: 'row_type' } },
{ field: 'path', title: '路由路径', minWidth: 150, showOverflow: 'tooltip' },
{ field: 'component', title: '组件路径', minWidth: 150, showOverflow: 'tooltip' },
{ field: 'permission', title: '权限标识', minWidth: 160, showOverflow: 'tooltip' },
2024-07-01 11:53:29 +08:00
{ field: 'orderNo', title: '排序', width: 80, showOverflow: 'tooltip' },
{ field: 'status', title: '状态', width: 100, showOverflow: 'tooltip', slots: { default: 'row_status' } },
{ field: '', title: '修改记录', width: 100, showOverflow: 'tooltip', slots: { default: 'row_record' } },
2024-07-01 11:42:05 +08:00
{ title: '操作', fixed: 'right', width: 100, showOverflow: true, slots: { default: 'row_buttons' } },
],
},
2024-07-09 09:47:33 +08:00
// vxeGrid配置参数(此处可覆写任何参数)参考vxe-table官方文档
{
stripe: false,
checkboxConfig: { range: false },
// 代理配置
proxyConfig: { autoLoad: true, ajax: { query: () => handleQueryApi() } },
// 分页配置
pagerConfig: { enabled: false },
// 工具栏配置
toolbarConfig: { export: false },
2024-07-10 12:59:32 +08:00
treeConfig: { expandAll: false },
2024-07-09 09:47:33 +08:00
}
2024-07-01 11:42:05 +08:00
);
2024-07-09 09:47:33 +08:00
// 查询api
const handleQueryApi = async () => {
const params = Object.assign(state.queryParams);
return getAPI(SysMenuApi).apiSysMenuListGet(params.title, params.type);
};
2024-06-15 13:02:35 +08:00
// 查询操作
const handleQuery = async () => {
2024-07-09 09:47:33 +08:00
// 调用vxe-grid的commitProxy(query)方法,触发表格重新加载数据
2024-07-10 12:59:32 +08:00
await xGrid.value?.commitProxy('query');
2024-06-15 13:02:35 +08:00
};
// 重置操作
2024-07-09 09:47:33 +08:00
const resetQuery = async () => {
2024-06-15 13:02:35 +08:00
state.queryParams.title = undefined;
state.queryParams.type = undefined;
2024-07-09 09:47:33 +08:00
// 调用vxe-grid的commitProxy(reload)方法,触发表格重新加载数据
2024-07-10 12:59:32 +08:00
await xGrid.value?.commitProxy('reload');
2024-07-09 09:47:33 +08:00
};
2024-06-15 13:02:35 +08:00
// 打开新增页面
2024-07-01 11:42:05 +08:00
const handleAdd = () => {
state.title = '添加菜单';
2024-06-15 13:02:35 +08:00
editMenuRef.value?.openDialog({ type: 2, isHide: false, isKeepAlive: true, isAffix: false, isIframe: false, status: 1, orderNo: 100 });
};
// 打开编辑页面
2024-07-01 11:42:05 +08:00
const handleEdit = (row: any) => {
state.title = '编辑菜单';
2024-06-15 13:02:35 +08:00
editMenuRef.value?.openDialog(row);
};
// 删除当前行
2024-07-01 11:42:05 +08:00
const handleDelete = (row: any) => {
2024-06-15 13:02:35 +08:00
ElMessageBox.confirm(`确定删除菜单:【${row.title}】?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(async () => {
await getAPI(SysMenuApi).apiSysMenuDeletePost({ id: row.id });
ElMessage.success('删除成功');
2024-07-01 11:42:05 +08:00
await handleQuery();
2024-06-15 13:02:35 +08:00
})
.catch(() => {});
};
2024-07-01 11:42:05 +08:00
2024-07-11 00:38:57 +08:00
// 表格事件
const gridEvents: VxeGridListeners<SysMenu> = {
// 只对 proxy-config.ajax.query 配置时有效,当手动点击查询时会触发该事件
async proxyQuery() {
state.menuData = xGrid.value?.getTableData().tableData ?? [];
},
};
2024-07-01 11:42:05 +08:00
// 全部展开
const handleExpand = () => {
xGrid.value?.setAllTreeExpand(true);
};
// 全部折叠
const handleFold = () => {
xGrid.value?.clearTreeExpand();
};
2024-06-15 13:02:35 +08:00
</script>