|
@@ -0,0 +1,119 @@
|
|
|
+<template>
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24" class="aside">
|
|
|
+ <el-menu
|
|
|
+ :default-active="onRoutes"
|
|
|
+ unique-opened
|
|
|
+ router
|
|
|
+ :background-color="styleInfo.aside_bg_color"
|
|
|
+ :text-color="styleInfo.menus_txt_color"
|
|
|
+ :active-text-color="styleInfo.routerview_bg_color"
|
|
|
+ >
|
|
|
+ <template v-for="item in items">
|
|
|
+ <!-- 二级菜单 -->
|
|
|
+ <template v-if="item.type === '0'">
|
|
|
+ <el-sub-menu :index="item._id || item.index" :key="item._id">
|
|
|
+ <template v-slot:title>
|
|
|
+ <span>{{ item.name }}</span>
|
|
|
+ </template>
|
|
|
+ <template v-for="subItem in item.children">
|
|
|
+ <!-- 三级菜单 -->
|
|
|
+ <el-sub-menu v-if="subItem.children && subItem.children.length > 0" :index="subItem._id" :key="subItem._id">
|
|
|
+ <template v-slot:title>
|
|
|
+ <span>{{ subItem.name }}</span>
|
|
|
+ </template>
|
|
|
+ <el-menu-item v-for="(threeItem, i) in subItem.children" :key="i" :index="threeItem.path">
|
|
|
+ <template v-slot:title>
|
|
|
+ <span>{{ threeItem.name }}</span>
|
|
|
+ </template>
|
|
|
+ </el-menu-item>
|
|
|
+ </el-sub-menu>
|
|
|
+ <el-menu-item v-else :index="subItem.path" :key="subItem.path">
|
|
|
+ <template v-slot:title>
|
|
|
+ <span>{{ subItem.name }}</span>
|
|
|
+ </template>
|
|
|
+ </el-menu-item>
|
|
|
+ </template>
|
|
|
+ </el-sub-menu>
|
|
|
+ </template>
|
|
|
+ <!-- 一级菜单 -->
|
|
|
+ <template v-else>
|
|
|
+ <el-menu-item :index="item.path" :key="item.path">
|
|
|
+ <span>{{ item.name }}</span>
|
|
|
+ </el-menu-item>
|
|
|
+ </template>
|
|
|
+ </template>
|
|
|
+ </el-menu>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import { ref, onMounted, watch } from 'vue';
|
|
|
+import type { Ref } from 'vue';
|
|
|
+import { admin_style_Info } from '../../../layout/site';
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
+import { useRoute } from 'vue-router';
|
|
|
+// 接口
|
|
|
+import { ModuleStore } from '@common/src/stores/admin/module'; //模块
|
|
|
+import { RoleStore } from '@common/src/stores/admin/role'; //模块
|
|
|
+import type { IQueryResult } from '@/util/types.util'; //
|
|
|
+import store from '@/stores/counter';
|
|
|
+const module = ModuleStore();
|
|
|
+const role = RoleStore();
|
|
|
+let route = useRoute();
|
|
|
+let user = store.state.user as { _id: string; name: string; unit_name: string; nick_name: string; role_type: string };
|
|
|
+
|
|
|
+// 请求列表
|
|
|
+let items: Ref<any[]> = ref([]);
|
|
|
+let styleInfo = admin_style_Info as { aside_bg_color: string; routerview_bg_color: string; menus_txt_color: string };
|
|
|
+let onRoutes = route.path;
|
|
|
+const getMenu = async (e: any) => {
|
|
|
+ let name = import.meta.env.VITE_APP_ROUTER;
|
|
|
+ const res: IQueryResult = await module.query({ name: name, is_use: 'Y' });
|
|
|
+ if (res && res.errcode == '0') {
|
|
|
+ if (res.total > 0) {
|
|
|
+ let moduleInfo = res.data[0];
|
|
|
+ let roleInfo: IQueryResult = await role.um();
|
|
|
+ if (roleInfo.errcode == '0') {
|
|
|
+ if (roleInfo.data) {
|
|
|
+ let menus = roleInfo.data[moduleInfo._id];
|
|
|
+ if (menus && menus.length > 0) {
|
|
|
+ items.value = menus;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ElMessage({ message: `${res.errmsg}`, type: 'error' });
|
|
|
+ }
|
|
|
+};
|
|
|
+onMounted(async () => {
|
|
|
+ console.log(import.meta);
|
|
|
+
|
|
|
+ let name = import.meta.env.VITE_APP_ROUTER;
|
|
|
+ const res: IQueryResult = await module.query({ name: name, is_use: 'Y' });
|
|
|
+ if (res && res.errcode == '0') {
|
|
|
+ if (res.total > 0) {
|
|
|
+ let moduleInfo = res.data[0];
|
|
|
+ let roleInfo: IQueryResult = await role.um();
|
|
|
+ if (roleInfo.errcode == '0') {
|
|
|
+ if (roleInfo.data) {
|
|
|
+ let menus = roleInfo.data[moduleInfo._id];
|
|
|
+ if (menus && menus.length > 0) {
|
|
|
+ items.value = menus;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ElMessage({ message: `${res.errmsg}`, type: 'error' });
|
|
|
+ }
|
|
|
+});
|
|
|
+watch(user, (newVal: any) => {
|
|
|
+ if (newVal && newVal._id) getMenu(newVal);
|
|
|
+ else ElMessage({ message: `暂无用户信息,无法获取菜单信息`, type: 'error' });
|
|
|
+});
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped></style>
|