zhangwei
4 天以前 91b116baef5c74909a59c7f13438dd4a0ad12bed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<template>
    <div class="sys-menu-container">
        <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
            <el-form :model="state.queryParams" ref="queryForm" :inline="true">
                <el-form-item label="租户" v-if="userStore.userInfos.accountType == 999">
                    <el-select v-model="state.queryParams.tenantId" placeholder="租户" style="width: 100%">
                        <el-option :value="item.value" :label="`${item.label} (${item.host})`" v-for="(item, index) in state.tenantList" :key="index" />
                    </el-select>
                </el-form-item>
                <el-form-item label="菜单名称">
                    <el-input v-model="state.queryParams.title" placeholder="菜单名称" clearable />
                </el-form-item>
                <el-form-item label="类型">
          <g-sys-dict v-model="state.queryParams.type" code="MenuTypeEnum" render-as="select" placeholder="类型" clearable />
                </el-form-item>
                <el-form-item>
                    <el-button-group>
                        <el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'sysMenu:list'"> 查询 </el-button>
                        <el-button icon="ele-Refresh" @click="resetQuery"> 重置 </el-button>
                    </el-button-group>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="ele-Plus" @click="openAddMenu" v-auth="'sysMenu:add'"> 新增 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
 
        <el-card class="full-table" shadow="hover" style="margin-top: 5px">
            <el-table :data="state.menuData" v-loading="state.loading" row-key="id" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" border>
                <el-table-column label="菜单名称" header-align="center" show-overflow-tooltip>
                    <template #default="scope">
                        <SvgIcon :name="scope.row.icon" />
                        <span class="ml10">{{ $t(scope.row.title) }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="类型" width="70" align="center" show-overflow-tooltip>
                    <template #default="scope">
            <g-sys-dict v-model="scope.row.type" code="MenuTypeEnum" />
                    </template>
                </el-table-column>
                <el-table-column prop="path" label="路由路径" header-align="center" show-overflow-tooltip />
                <el-table-column prop="component" label="组件路径" align="center" show-overflow-tooltip />
                <el-table-column prop="permission" label="权限标识" align="center" show-overflow-tooltip />
                <el-table-column prop="orderNo" label="排序" width="70" align="center" show-overflow-tooltip />
                <el-table-column label="状态" width="80" align="center" show-overflow-tooltip>
                    <template #default="scope">
            <g-sys-dict v-model="scope.row.status" code="StatusEnum" />
                    </template>
                </el-table-column>
                <el-table-column label="修改记录" width="100" align="center" show-overflow-tooltip>
                    <template #default="scope">
                        <ModifyRecord :data="scope.row" />
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="210" fixed="right" align="center" show-overflow-tooltip>
                    <template #default="scope">
                        <el-button icon="ele-Edit" text type="primary" @click="openEditMenu(scope.row)" v-auth="'sysMenu:update'"> 编辑 </el-button>
                        <el-button icon="ele-Delete" text type="danger" @click="delMenu(scope.row)" v-auth="'sysMenu:delete'"> 删除 </el-button>
                        <el-button icon="ele-CopyDocument" text type="primary" @click="openCopyMenu(scope.row)" v-auth="'sysMenu:add'"> 复制 </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-card>
 
        <EditMenu ref="editMenuRef" :title="state.editMenuTitle" :menuData="state.allMenuData" @handleQuery="handleQuery" />
    </div>
</template>
 
<script lang="ts" setup name="sysMenu">
import { onMounted, reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import EditMenu from '/@/views/system/menu/component/editMenu.vue';
import ModifyRecord from '/@/components/table/modifyRecord.vue';
 
import { getAPI } from '/@/utils/axios-utils';
import {SysMenuApi, SysTenantApi} from '/@/api-services/api';
import { SysMenu, UpdateMenuInput } from '/@/api-services/models';
import {useUserInfo} from "/@/stores/userInfo";
 
const userStore = useUserInfo();
const editMenuRef = ref<InstanceType<typeof EditMenu>>();
const state = reactive({
    loading: false,
    tenantList: [] as Array<any>,
    menuData: [] as Array<SysMenu>,
    allMenuData: [] as Array<SysMenu>,
    queryParams: {
        tenantId: undefined,
        title: undefined,
        type: undefined,
    },
    editMenuTitle: '',
});
 
onMounted(async () => {
    if (userStore.userInfos.accountType == 999) {
        state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
        state.queryParams.tenantId = state.tenantList[0].value;
    }
    handleQuery();
});
 
// 查询操作
const handleQuery = async () => {
    state.loading = true;
    const res = await getAPI(SysMenuApi).apiSysMenuListGet(state.queryParams.title, state.queryParams.type, state.queryParams.tenantId);
    state.menuData = res.data.result ?? [];
    state.loading = false;
};
 
// 重置操作
const resetQuery = () => {
    state.queryParams.title = undefined;
    state.queryParams.type = undefined;
    handleQuery();
};
 
// 获取菜单树数据
const getMenuTreeData = async () => {
    const res = await getAPI(SysMenuApi).apiSysMenuListGet(undefined, undefined, state.queryParams.tenantId);
    state.allMenuData = res.data.result ?? [];
    return state.menuData;
}
 
// 打开新增页面
const openAddMenu = () => {
    getMenuTreeData();
    const data = { type: 2, isHide: false, isKeepAlive: true, isAffix: false, isIframe: false, tenantId: undefined, status: 1, orderNo: 100 };
    data.tenantId = state.queryParams.tenantId;
    state.editMenuTitle = '添加菜单';
    editMenuRef.value?.openDialog(data);
};
 
// 打开编辑页面
const openEditMenu = (row: any) => {
    getMenuTreeData();
    state.editMenuTitle = '编辑菜单';
    editMenuRef.value?.openDialog(row);
};
 
// 打开复制页面
const openCopyMenu = (row: any) => {
    state.editMenuTitle = '复制菜单';
    var copyRow = JSON.parse(JSON.stringify(row)) as UpdateMenuInput;
    copyRow.id = 0;
    copyRow.title = '';
    editMenuRef.value?.openDialog(copyRow);
};
 
// 删除当前行
const delMenu = (row: any) => {
    ElMessageBox.confirm(`确定删除菜单:【${row.title}】?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
    })
        .then(async () => {
            await getAPI(SysMenuApi).apiSysMenuDeletePost({ id: row.id });
            handleQuery();
            ElMessage.success('删除成功');
        })
        .catch(() => {});
};
</script>