rax-medical/src/views/permissions-manage/menu-manage.vue

171 lines
5.0 KiB
Vue
Raw Normal View History

2023-12-17 16:05:38 +08:00
<template>
2024-05-17 12:06:29 +08:00
<div class="table-page">
<div class="search-part" v-show="isSearch">
<div class="search-cell">
<span class="label">菜单名称</span>
<el-input v-model="queryParams" placeholder="请输入菜单名称"></el-input>
</div>
<el-button type="primary" icon="Search" @click="searchList">查询</el-button>
<el-button icon="Refresh" @click="resetSearch">重置</el-button>
</div>
<div class="button-part" style="justify-content: space-between;">
<div>
<el-button type="primary" icon="FirstAidKit" @click="addData()">新增</el-button>
<el-button @click="expandTable">展开/折叠</el-button>
</div>
<TableAbility :isDownload="false" @searchBtn="isSearch = !isSearch" @refreshBtn="initData()"></TableAbility>
</div>
<div class="table-part">
<el-table ref="tableRef" :data="tableData" row-key="id" height="100%" border show-overflow-tooltip
@row-click="tableRowClick">
<el-table-column property="name" label="菜单名称" width="180" align="center"/>
<el-table-column label="图标" width="80" align="center">
<template #default="scope"><i class="main-color f20" :class="scope.row.meta.icon"></i></template>
</el-table-column>
<el-table-column property="path" label="路由" width="260" align="center"/>
<el-table-column label="类型" width="180" align="center">
<template #default="scope">
<span>{{ scope.row.menuType == 0 ? "菜单" : "按钮" }}</span>
</template>
</el-table-column>
<el-table-column property="sortOrder" label="排序" width="80" align="center"/>
<el-table-column label="操作" align="center">
<template #default="scope">
<div @click.stop>
<el-button link icon="EditPen" v-if="scope.row.menuType == 0" @click="addData(scope.row)">
新建下级
</el-button>
<el-button link icon="EditPen" @click="editData(scope.row)">修改</el-button>
<el-button link icon="Delete" @click="removeData(scope.row)">删除</el-button>
</div>
</template>
</el-table-column>
</el-table>
</div>
</div>
<el-dialog v-model="isFormDialog" :title="formDialogTitle" width="30%">
<MenuForm ref="menuFormRef" :type="formDialogTitle === '添加' ? 'add' : 'edit'"
@save-or-update-event="formSaveUpdateEvent" @close="isFormDialog = false"/>
</el-dialog>
2023-12-17 16:05:38 +08:00
</template>
<script lang='ts' setup>
2024-04-24 19:35:24 +08:00
import {onMounted, ref} from 'vue'
2023-12-18 18:30:33 +08:00
import MenuForm from './form/menu-form.vue'
2024-04-24 19:35:24 +08:00
import * as menuApi from "@/api/menu";
import {ElMessage, ElMessageBox} from "element-plus";
2023-12-17 16:05:38 +08:00
2023-12-18 18:30:33 +08:00
let isExpand = false // 表格展开状态
const tableRef = ref()
2024-04-24 19:35:24 +08:00
const menuFormRef = ref()
2023-12-27 16:49:37 +08:00
const isSearch = ref(true)
const loading = ref(true)
2023-12-18 18:30:33 +08:00
const isFormDialog = ref(false)
const formDialogTitle = ref('')
2024-04-24 19:35:24 +08:00
const queryParams = ref('')
2023-12-18 18:30:33 +08:00
const tableData = ref([] as any)
const tableMap: any = {};
2023-12-18 18:30:33 +08:00
2024-04-24 19:35:24 +08:00
onMounted(() => {
2024-05-17 12:06:29 +08:00
initData();
2024-04-24 19:35:24 +08:00
})
2023-12-27 16:49:37 +08:00
function initData() {
2024-05-17 12:06:29 +08:00
loading.value = true;
tableData.value = [];
getMenuTree();
2024-04-24 19:35:24 +08:00
}
function searchList() {
2024-05-17 12:06:29 +08:00
loading.value = true;
tableData.value = [];
getMenuTree(queryParams.value)
2024-04-24 19:35:24 +08:00
}
function resetSearch() {
2024-05-17 12:06:29 +08:00
queryParams.value = '';
initData();
2024-04-24 19:35:24 +08:00
}
function getMenuTree(name?: string) {
2024-05-17 12:06:29 +08:00
menuApi.getMenuTree(name).then((res: any) => {
tableData.value = res.data ? res.data : [];
initTableMap(tableData.value);
})
2024-04-24 19:35:24 +08:00
}
function initTableMap(data: any) {
2024-05-17 12:06:29 +08:00
data.forEach((row: any, i: number) => {
handleInitTree(row, i, []);
});
2023-12-18 18:30:33 +08:00
}
function handleInitTree(row: any, i: number, pArr: any) {
2024-05-17 12:06:29 +08:00
// 当前序列
const cArr: any = [].concat(pArr);
cArr.push(i);
tableMap[row.id] = cArr;
row.indexArr = cArr;
if (row.children) {
row.children.forEach((row: any, i: number) => {
handleInitTree(row, i, cArr);
})
}
2023-12-18 18:30:33 +08:00
}
2024-04-24 19:35:24 +08:00
const addData = (menu?: any) => {
2024-05-17 12:06:29 +08:00
isFormDialog.value = true
formDialogTitle.value = '添加'
setTimeout(() => {
menuFormRef.value.resetData(menu)
}, 0)
2023-12-18 18:30:33 +08:00
}
const expandTable = () => {
2024-05-17 12:06:29 +08:00
isExpand = !isExpand
tableData.value.forEach((row: any) => {
tableRef.value.toggleRowExpansion(row, isExpand)
})
2023-12-18 18:30:33 +08:00
}
const removeData = (e?: any) => {
2024-05-17 12:06:29 +08:00
ElMessageBox.confirm(
'是否删除?',
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
draggable: true
}
).then(() => {
menuApi.deleteById(e.id).then((res: any) => {
if (res.code == 0) {
ElMessage.success("删除成功");
initData();
} else {
ElMessage.error(res.msg ? res.msg : "删除失败");
}
})
}).catch(() => {
})
2023-12-18 18:30:33 +08:00
}
const editData = (e: any) => {
2024-05-17 12:06:29 +08:00
isFormDialog.value = true
formDialogTitle.value = '修改'
setTimeout(() => {
menuFormRef.value.resetData(null, JSON.parse(JSON.stringify(e)))
}, 0)
2023-12-18 18:30:33 +08:00
}
const tableRowClick = (row: any) => {
2024-05-17 12:06:29 +08:00
tableRef.value.toggleRowExpansion(row)
2023-12-18 18:30:33 +08:00
}
2024-04-24 19:35:24 +08:00
function formSaveUpdateEvent() {
2024-05-17 12:06:29 +08:00
isFormDialog.value = false;
initData();
2023-12-18 18:30:33 +08:00
}
2024-04-24 19:35:24 +08:00
2023-12-17 16:05:38 +08:00
</script>
2023-12-27 16:49:37 +08:00
<style lang='scss' scoped></style>