You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

253 lines
7.3 KiB

1 month ago
1 month ago
1 month ago
3 weeks ago
1 month ago
  1. <script setup>
  2. // 导航栏在这
  3. import {ref} from 'vue'
  4. import {useRouter} from 'vue-router'
  5. import {ElMessage} from 'element-plus'
  6. import dmmn from '../assets/link.png'
  7. import ChangePassword from '@/components/changePassword.vue'
  8. import {useAdminStore} from '@/store'
  9. import {storeToRefs} from 'pinia'
  10. import {filterMenu, getRoutePath} from "@/utils/menuUtils.js";
  11. // 存储接口返回的菜单数据
  12. const menuList = ref([])
  13. // 获取仓库实例
  14. const adminStore = useAdminStore()
  15. // 解构状态(保持响应式) 获得 adminData(用户信息) 和 menuTree(菜单树)
  16. const {adminData, menuTree} = storeToRefs(adminStore)
  17. // 筛选权限菜单 ,menuTree 是组件通信拿的
  18. menuList.value = filterMenu(menuTree.value)
  19. console.log("menuList", menuList.value)
  20. const router = useRouter()
  21. const imgrule1 = dmmn
  22. const messageVisible = ref(false)
  23. // 查看个人信息弹出框
  24. const openMessage = function () {
  25. messageVisible.value = true
  26. }
  27. // 关闭个人信息
  28. const closeMessage = function () {
  29. messageVisible.value = false
  30. }
  31. const message = function () {
  32. openMessage()
  33. }
  34. // 显示修改密码弹窗
  35. const showPasswordDialog = ref(false)
  36. //打开修改密码弹窗
  37. const openChangePassword = () => {
  38. showPasswordDialog.value = true
  39. }
  40. function logout() {
  41. const machineId = localStorage.getItem('machineId')
  42. localStorage.removeItem('token')
  43. adminStore.clearState()
  44. router.push('/login?machineId=' + machineId)
  45. ElMessage.success('退出成功')
  46. }
  47. </script>
  48. <template>
  49. <div class="common-layout">
  50. <el-container>
  51. <el-aside style="
  52. width: 15%;
  53. min-width: 180px;
  54. position: fixed; /* 固定位置 */
  55. top: 0;
  56. left: 0;
  57. height: 100vh; /* 高度占满视口 */
  58. z-index: 100; /* 确保侧边栏在其他元素之上 */
  59. ">
  60. <div class="logo">
  61. <img src="../assets/新logo.png" alt="logo" style="width: 80px; height: 80px"/>
  62. <!-- <div style="font-size: 16px; font-weight: bold; color: black; text-align: center;" ><h1>海外金币管理系统</h1></div> -->
  63. </div>
  64. <el-card style="min-height: 90%;">
  65. <el-menu
  66. :router="true"
  67. class="el-menu-vertical-demo"
  68. :default-active="$route.path"
  69. >
  70. <!-- 递归渲染菜单层级 -->
  71. <template v-for="menu in menuList" :key="menu.id">
  72. <!-- 有子菜单的父级菜单menuType=2 且存在children -->
  73. <el-sub-menu
  74. v-if="menu.children && menu.children.length > 0"
  75. :index="menu.id.toString()"
  76. >
  77. <template #title>
  78. <el-icon>
  79. <Folder/>
  80. </el-icon>
  81. <span>{{ menu.menuName }}</span>
  82. </template>
  83. <!-- 子菜单 -->
  84. <template v-for="child in menu.children" :key="child.id">
  85. <!-- 子菜单为叶子节点无children -->
  86. <el-menu-item
  87. v-if="!child.children || child.children.length === 0"
  88. :index="getRoutePath(child)"
  89. >
  90. <span>{{ child.menuName }}</span>
  91. </el-menu-item>
  92. <!-- 子菜单有下级 -->
  93. <el-sub-menu
  94. v-else
  95. :index="child.id.toString()"
  96. >
  97. <template #title>
  98. <span>{{ child.menuName }}</span>
  99. </template>
  100. <!-- 递归 下一级-->
  101. <template v-for="grandChild in child.children" :key="grandChild.id">
  102. <el-menu-item :index="getRoutePath(grandChild)">
  103. <span>{{ grandChild.menuName }}</span>
  104. </el-menu-item>
  105. </template>
  106. </el-sub-menu>
  107. </template>
  108. </el-sub-menu>
  109. <!-- 无子菜单的一级菜单 -->
  110. <el-menu-item
  111. v-else
  112. :index="getRoutePath(menu)"
  113. >
  114. <el-icon>
  115. <Folder/>
  116. </el-icon>
  117. <span>{{ menu.menuName }}</span>
  118. </el-menu-item>
  119. </template>
  120. </el-menu>
  121. </el-card>
  122. </el-aside>
  123. <el-container style="margin-left: 15%; min-width: 180px">
  124. <!-- 修改 el-header 样式 -->
  125. <el-header style="
  126. position: fixed;
  127. top: 0;
  128. left: 15%;
  129. right: 0;
  130. z-index: 80;
  131. background: white;
  132. ">
  133. <el-menu class="el-menu-demo" mode="horizontal" :ellipsis="false">
  134. <el-sub-menu index="1" class="admin">
  135. <template #title>
  136. <el-image :src="imgrule1" alt="错误" style="width: 50px; height: 50px"/>
  137. <span style="margin-left: 10px">{{ adminData.name }}</span>
  138. </template>
  139. <el-menu-item @click="message()">查看个人信息</el-menu-item>
  140. <el-menu-item @click="openChangePassword">修改密码</el-menu-item>
  141. <el-menu-item @click="logout">退出登录</el-menu-item>
  142. </el-sub-menu>
  143. </el-menu>
  144. </el-header>
  145. <el-main style="margin-top: 60px">
  146. <!-- 60px el-header 的大致高度可根据实际情况调整 -->
  147. <router-view></router-view>
  148. </el-main>
  149. </el-container>
  150. </el-container>
  151. <!-- 查看个人信息 -->
  152. <el-dialog v-model="messageVisible" title="查看个人信息" width="500px">
  153. <el-form :model="adminData">
  154. <el-form-item label="用户姓名" label-width="100px" label-position="left">
  155. <span class="message-font">{{ adminData.adminName }}</span>
  156. </el-form-item>
  157. <el-form-item label="精网号" label-width="100px" label-position="left">
  158. <span class="message-font">{{ adminData.account }}</span>
  159. </el-form-item>
  160. <el-form-item label="地区" label-width="100px" label-position="left">
  161. <span class="message-font">{{ adminData.markets }}</span>
  162. </el-form-item>
  163. <el-form-item label="注册时间" label-width="100px" label-position="left">
  164. <span class="message-font">{{ adminData.createTime }}</span>
  165. </el-form-item>
  166. </el-form>
  167. <template #footer>
  168. <div class="dialog-footer">
  169. <el-button text @click="closeMessage()">关闭</el-button>
  170. </div>
  171. </template>
  172. </el-dialog>
  173. <!-- 自定义密码修改弹窗组件 -->
  174. <el-dialog
  175. v-model="showPasswordDialog"
  176. :center="true"
  177. width="470px"
  178. >
  179. <ChangePassword @confirm="showPasswordDialog = false"/>
  180. </el-dialog>
  181. </div>
  182. </template>
  183. <style scoped>
  184. .message-font {
  185. font-size: 16px;
  186. font-weight: bold;
  187. }
  188. .item {
  189. margin-top: 20px;
  190. margin-right: 40px;
  191. }
  192. .admin {
  193. margin-left: auto;
  194. }
  195. .el-aside {
  196. min-height: 100vh;
  197. width: 200px;
  198. }
  199. /* background-color: #BFD8D2; */
  200. .logo {
  201. margin: 20px 0px 20px 20px;
  202. display: flex;
  203. }
  204. .el-menu-demo {
  205. border: none;
  206. /* 去除边框 */
  207. padding: 0;
  208. /* 去除内边距 */
  209. float: right;
  210. /* 将菜单向右浮动 */
  211. }
  212. .el-menu-vertical-demo:not(.el-menu--collapse) {
  213. width: 240px;
  214. min-height: 400px;
  215. border: none;
  216. /* 去除边框 */
  217. }
  218. </style>