SidevarItem1.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div class="box-item">
  3. <el-menu
  4. class="el-menu-vertical-demo"
  5. background-color="#293749"
  6. text-color="#fff"
  7. active-text-color="#fff"
  8. :default-active="sidevarItem"
  9. :collapse="isCollapse"
  10. @open="handleOpen"
  11. @close="handleClose"
  12. @select="handleSelect"
  13. >
  14. <div class="logo el-menu-item">
  15. <el-icon :size="20"
  16. ><img src="@/assets/img/logo.png" style="width: 40px; height: 40px"
  17. /></el-icon>
  18. </div>
  19. <div v-for="i in roles.list" :key="i.path">
  20. <el-sub-menu
  21. v-if="i.name == '房源管理' || i.name == '权限管理'"
  22. :index="i.index"
  23. popper-class="ceshi"
  24. :teleported="true"
  25. >
  26. <template #title>
  27. <SvgIcon :name="i.icon" color="#fff" size="22"></SvgIcon>
  28. <span>{{ i.name }}</span>
  29. </template>
  30. <el-menu-item
  31. v-for="item in i.children"
  32. :index="item.path"
  33. :key="item.paht"
  34. >
  35. <template #title>{{ item.name }}</template>
  36. </el-menu-item>
  37. </el-sub-menu>
  38. <el-menu-item v-else :index="i.path">
  39. <SvgIcon :name="i.icon" color="#fff" size="22"></SvgIcon>
  40. <template #title>{{ i.name }}</template>
  41. </el-menu-item>
  42. </div>
  43. <!-- <el-menu-item index="/dataOverview">
  44. <SvgIcon name="dataOverview" color="#fff" size="22"></SvgIcon>
  45. <template #title>数据总览</template>
  46. </el-menu-item>
  47. <el-menu-item index="/studentInfo">
  48. <SvgIcon name="studentInfo" color="#fff" size="22"></SvgIcon>
  49. <template #title>学生信息管理</template>
  50. </el-menu-item>
  51. <el-sub-menu index="1" popper-class="ceshi" :teleported="true">
  52. <template #title>
  53. <SvgIcon name="building" color="#fff" size="22"></SvgIcon>
  54. <span>房源管理</span>
  55. </template>
  56. <el-menu-item index="/building">
  57. <template #title>楼栋信息管理</template>
  58. </el-menu-item>
  59. <el-menu-item index="/dormitory">
  60. <template #title>寝室信息管理</template>
  61. </el-menu-item>
  62. <el-menu-item index="/bed">
  63. <template #title>床位信息管理</template>
  64. </el-menu-item>
  65. </el-sub-menu>
  66. <el-menu-item index="/student">
  67. <SvgIcon name="student" color="#fff" size="22"></SvgIcon>
  68. <template #title>学生住宿信息</template>
  69. </el-menu-item>
  70. <el-menu-item index="/quarterage">
  71. <SvgIcon name="quarterage" color="#fff" size="22"></SvgIcon>
  72. <template #title>住宿信息统计</template>
  73. </el-menu-item>
  74. <el-menu-item index="/caller">
  75. <SvgIcon name="caller" color="#fff" size="22"></SvgIcon>
  76. <template #title>访客信息管理</template>
  77. </el-menu-item>
  78. <el-sub-menu index="2" popper-class="ceshi" :teleported="true">
  79. <template #title>
  80. <SvgIcon name="role" color="#fff" size="22"></SvgIcon>
  81. <span>权限管理</span>
  82. </template>
  83. <el-menu-item index="/user">
  84. <template #title>用户管理</template>
  85. </el-menu-item>
  86. <el-menu-item index="/role">
  87. <template #title>角色管理</template>
  88. </el-menu-item>
  89. </el-sub-menu>
  90. <el-menu-item index="/system">
  91. <SvgIcon name="system" color="#fff" size="22"></SvgIcon>
  92. <template #title>系统设置</template>
  93. </el-menu-item> -->
  94. </el-menu>
  95. </div>
  96. </template>
  97. <script setup>
  98. import { ref, onBeforeMount, onMounted, watch, reactive } from "vue";
  99. import {
  100. Fold,
  101. Expand,
  102. Service,
  103. Position,
  104. View,
  105. Open,
  106. } from "@element-plus/icons-vue";
  107. import { useRouter } from "vue-router";
  108. import { storeToRefs } from "pinia";
  109. import { useCounterStore } from "@/stores/index";
  110. const store = useCounterStore();
  111. const { isCollapse, sidevarItem, roleList } = storeToRefs(store);
  112. const router = useRouter();
  113. const roles = reactive({
  114. list: [],
  115. });
  116. const acitveItems = reactive({ list: [] });
  117. const handleSelect = (key) => {
  118. console.log(key);
  119. store.setItem(key);
  120. router.push({
  121. path: `${key}`,
  122. });
  123. };
  124. const handleOpen = () => {};
  125. const handleClose = () => {};
  126. onMounted(() => {
  127. console.log(roleList.value);
  128. roleList.value.forEach((i) => {
  129. if (i.path == "/building" || i.path == "/dormitory" || i.path == "/bed") {
  130. const exists = roles.list.some((item) => item.name === "房源管理");
  131. if (exists) {
  132. roles.list.forEach((j) => {
  133. if (j.name == "房源管理") {
  134. j.children.push({
  135. name: i.name,
  136. path: i.path,
  137. icon: i.icon,
  138. });
  139. }
  140. });
  141. } else {
  142. roles.list.push({
  143. name: "房源管理",
  144. index: 1,
  145. icon: "building",
  146. children: [
  147. {
  148. name: i.name,
  149. path: i.path,
  150. icon: i.icon,
  151. },
  152. ],
  153. });
  154. }
  155. } else if (i.path == "/user" || i.path == "/role") {
  156. const exists = roles.list.some((item) => item.name === "权限管理");
  157. if (exists) {
  158. roles.list.forEach((j) => {
  159. if (j.name == "权限管理") {
  160. j.children.push({
  161. name: i.name,
  162. path: i.path,
  163. icon: i.icon,
  164. });
  165. }
  166. });
  167. } else {
  168. roles.list.push({
  169. name: "权限管理",
  170. index: 2,
  171. icon: "role",
  172. children: [
  173. {
  174. name: i.name,
  175. path: i.path,
  176. icon: i.icon,
  177. },
  178. ],
  179. });
  180. }
  181. } else {
  182. roles.list.push({
  183. name: i.name,
  184. path: i.path,
  185. icon: i.icon,
  186. });
  187. }
  188. });
  189. console.log(roles.list);
  190. });
  191. onBeforeMount(() => {
  192. // console.log("SidevarItem/onBeforeMount");
  193. });
  194. </script>
  195. <style lang="scss" scoped>
  196. .el-menu-vertical-demo:not(.el-menu--collapse) {
  197. width: 200px;
  198. // min-height: 400px;
  199. user-select: none;
  200. }
  201. .box-item {
  202. height: 100vh;
  203. }
  204. :deep(.el-menu--vertical) {
  205. height: 100%;
  206. overflow: auto;
  207. background-color: rgba(48, 65, 86, 1);
  208. box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.16);
  209. .logo {
  210. height: 65px;
  211. color: rgb(255, 255, 255);
  212. cursor: default;
  213. display: flex;
  214. justify-content: space-around;
  215. align-items: center;
  216. margin: 20px 0 !important;
  217. }
  218. .logo:hover {
  219. background-color: transparent !important;
  220. }
  221. .el-sub-menu {
  222. padding: 0 14px;
  223. margin-bottom:20px ;
  224. .el-sub-menu__title {
  225. height: 40px;
  226. // margin: 0 0 20px 0;
  227. margin: 0;
  228. border-radius: 10px;
  229. }
  230. .el-menu-item {
  231. height: 40px;
  232. margin: 20px 0 !important;
  233. border-radius: 10px;
  234. .el-menu-tooltip__trigger {
  235. display: flex;
  236. align-items: center;
  237. justify-content: center;
  238. }
  239. &:last-child {
  240. margin: 20px 0 0 0 !important;
  241. }
  242. &.is-active {
  243. background: linear-gradient(
  244. 90deg,
  245. rgba(38, 151, 255, 1) 0%,
  246. rgba(102, 182, 255, 1) 100%
  247. );
  248. }
  249. }
  250. .el-menu.el-menu--inline {
  251. box-shadow: none;
  252. background-color: rgba(48, 65, 86, 1);
  253. }
  254. &.is-active.is-opened {
  255. .el-sub-menu__title {
  256. background: linear-gradient(
  257. 90deg,
  258. rgba(38, 151, 255, 1) 0%,
  259. rgba(102, 182, 255, 1) 100%
  260. );
  261. }
  262. }
  263. }
  264. .el-menu-item {
  265. height: 40px;
  266. margin: 20px 14px;
  267. border-radius: 10px;
  268. .el-menu-tooltip__trigger {
  269. display: flex;
  270. align-items: center;
  271. justify-content: center;
  272. }
  273. &.is-active {
  274. background: linear-gradient(
  275. 90deg,
  276. rgba(38, 151, 255, 1) 0%,
  277. rgba(102, 182, 255, 1) 100%
  278. );
  279. }
  280. }
  281. }
  282. :deep(.el-menu--collapse) {
  283. .el-sub-menu {
  284. padding: 0;
  285. margin: 20px 10px;
  286. .el-sub-menu__title {
  287. span {
  288. display: none;
  289. }
  290. .el-icon {
  291. margin-right: 0;
  292. }
  293. .el-sub-menu__icon-arrow {
  294. display: none;
  295. }
  296. }
  297. }
  298. .el-sub-menu.is-active {
  299. .el-sub-menu__title {
  300. background: linear-gradient(
  301. 90deg,
  302. rgba(38, 151, 255, 1) 0%,
  303. rgba(102, 182, 255, 1) 100%
  304. );
  305. span {
  306. display: none;
  307. }
  308. }
  309. }
  310. .el-sub-menu {
  311. padding: 0;
  312. margin: 0 10px 20px !important;
  313. .el-sub-menu__title {
  314. width: 40px;
  315. padding: 0 20px;
  316. // margin: 0 0 20px 0;
  317. display: flex;
  318. align-items: center;
  319. justify-content: center;
  320. }
  321. }
  322. .el-sub-menu {
  323. .el-menu-item {
  324. border: 1px solid red;
  325. }
  326. }
  327. .el-menu-item {
  328. width: 40px;
  329. margin: 20px 10px;
  330. .el-menu-tooltip__trigger {
  331. .el-icon {
  332. margin-right: 0;
  333. }
  334. }
  335. }
  336. }
  337. </style>
  338. <style lang="scss">
  339. .ceshi {
  340. &.is-light {
  341. border: none !important;
  342. }
  343. .el-menu-item.is-active {
  344. background: linear-gradient(
  345. 90deg,
  346. rgba(38, 151, 255, 1) 0%,
  347. rgba(102, 182, 255, 1) 100%
  348. );
  349. }
  350. }
  351. </style>