SidevarItem copy.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <template>
  2. <div class="box-item">
  3. <el-menu
  4. class="el-menu-vertical-demo"
  5. text-color="rgba(88, 109, 133, 1)"
  6. active-color="#fff"
  7. :default-active="activeIndex"
  8. :collapse="menuClose"
  9. @select="handleSelect"
  10. :router="true"
  11. >
  12. <!-- :default-openeds="[34]" -->
  13. <div class="logo el-menu-item">
  14. <el-icon :size="20"
  15. ><img src="@/assets/logo.png" style="width: 30px; height: 24px"
  16. /></el-icon>
  17. </div>
  18. <!-- 菜单项 -->
  19. <div v-for="item in roleData" class="items">
  20. <!-- 房态管理 -->
  21. <el-menu-item
  22. v-if="item.name == 'roomStatus'"
  23. index="/hotel/roomStatus"
  24. >
  25. <img
  26. v-if="activeIndex == '/hotel/roomStatus'"
  27. src="@/assets/icons/roomStatusS.png"
  28. alt=""
  29. style="width: 22px; height: 22px; margin: 0 18px"
  30. />
  31. <img
  32. v-else
  33. src="@/assets/icons/roomStatus.png"
  34. alt=""
  35. style="width: 22px; height: 22px; margin: 0 18px"
  36. />
  37. <span>房态管理</span>
  38. </el-menu-item>
  39. <!-- 房型管理 -->
  40. <el-sub-menu index="roomTypes" v-if="item.name == 'roomTypes'">
  41. <template #title>
  42. <img
  43. v-if="
  44. activeIndex == '/hotel/roomType' ||
  45. activeIndex == '/hotel/roomPrice'
  46. "
  47. src="@/assets/icons/roomTypeS.png"
  48. style="width: 20px; height: 20px; margin: 0 20px 0 18px"
  49. alt=""
  50. />
  51. <img
  52. v-else
  53. src="@/assets/icons/roomType.png"
  54. style="width: 20px; height: 20px; margin: 0 20px 0 18px"
  55. alt=""
  56. />
  57. <span>{{ item.meta.title }}</span>
  58. </template>
  59. <el-menu-item v-for="i in item.children" :index="`/hotel/${i.name}`">
  60. <template #title>
  61. <span>{{ i.meta.title }}</span>
  62. </template>
  63. </el-menu-item>
  64. </el-sub-menu>
  65. <!-- 订单管理 -->
  66. <el-menu-item v-if="item.name == 'order'" index="/hotel/order">
  67. <img
  68. v-if="activeIndex == '/hotel/order'"
  69. src="@/assets/icons/orderS.png"
  70. alt=""
  71. style="width: 24px; height: 22px; margin: 0 18px"
  72. />
  73. <img
  74. v-else
  75. src="@/assets/icons/order.png"
  76. alt=""
  77. style="width: 22px; height: 22px; margin: 0 18px"
  78. />
  79. <span>订单管理</span>
  80. </el-menu-item>
  81. <!-- 授权管理 -->
  82. <el-sub-menu index="classs" v-if="item.name == 'classs'">
  83. <template #title>
  84. <img
  85. v-if="
  86. activeIndex == '/hotel/class' || activeIndex == '/hotel/process'
  87. "
  88. src="@/assets/icons/classS.png"
  89. style="width: 22px; height: 22px; margin: 0 18px 0 18px"
  90. alt=""
  91. />
  92. <img
  93. v-else
  94. src="@/assets/icons/class.png"
  95. style="width: 22px; height: 22px; margin: 0 18px 0 18px"
  96. alt=""
  97. />
  98. <span>{{ item.meta.title }}</span>
  99. </template>
  100. <el-menu-item v-for="i in item.children" :index="`/hotel/${i.name}`">
  101. <template #title>
  102. <span>{{ i.meta.title }}</span>
  103. </template>
  104. </el-menu-item>
  105. </el-sub-menu>
  106. <!-- 统计报表 -->
  107. <el-menu-item v-if="item.name == 'statement'" index="/hotel/statement">
  108. <img
  109. v-if="activeIndex == '/hotel/statement'"
  110. src="@/assets/icons/statementS.png"
  111. alt=""
  112. style="width: 24px; height: 22px; margin: 0 18px"
  113. />
  114. <img
  115. v-else
  116. src="@/assets/icons/statement.png"
  117. alt=""
  118. style="width: 22px; height: 22px; margin: 0 18px"
  119. />
  120. <span>统计报表</span>
  121. </el-menu-item>
  122. <!-- 设备管理 -->
  123. <el-sub-menu index="doorLocks" v-if="item.name == 'doorLocks'">
  124. <template #title>
  125. <img
  126. v-if="
  127. activeIndex == '/hotel/doorLock' ||
  128. activeIndex == '/hotel/meter'
  129. "
  130. src="@/assets/icons/doorLockS.png"
  131. style="width: 22px; height: 22px; margin: 0 18px 0 18px"
  132. alt=""
  133. />
  134. <img
  135. v-else
  136. src="@/assets/icons/doorLock.png"
  137. style="width: 22px; height: 22px; margin: 0 18px 0 18px"
  138. alt=""
  139. />
  140. <span>{{ item.meta.title }}</span>
  141. </template>
  142. <el-menu-item v-for="i in item.children" :index="`/hotel/${i.name}`">
  143. <template #title>
  144. <span>{{ i.meta.title }}</span>
  145. </template>
  146. </el-menu-item>
  147. </el-sub-menu>
  148. <!-- 组织架构 -->
  149. <el-sub-menu index="users" v-if="item.name == 'users'">
  150. <template #title>
  151. <img
  152. v-if="
  153. activeIndex == '/hotel/user' ||
  154. activeIndex == '/hotel/userRoles'
  155. "
  156. src="@/assets/icons/userS.png"
  157. style="width: 22px; height: 22px; margin: 0 18px 0 18px"
  158. alt=""
  159. />
  160. <img
  161. v-else
  162. src="@/assets/icons/user.png"
  163. style="width: 22px; height: 22px; margin: 0 18px 0 18px"
  164. alt=""
  165. />
  166. <span>{{ item.meta.title }}</span>
  167. </template>
  168. <el-menu-item v-for="i in item.children" :index="`/hotel/${i.name}`">
  169. <template #title>
  170. <span>{{ i.meta.title }}</span>
  171. </template>
  172. </el-menu-item>
  173. </el-sub-menu>
  174. <!-- 账号管理 -->
  175. <el-menu-item v-if="item.name == 'account'" index="/hotel/account">
  176. <img
  177. v-if="activeIndex == '/hotel/account'"
  178. src="@/assets/icons/accountS.png"
  179. alt=""
  180. style="width: 24px; height: 22px; margin: 0 18px"
  181. />
  182. <img
  183. v-else
  184. src="@/assets/icons/account.png"
  185. alt=""
  186. style="width: 22px; height: 22px; margin: 0 18px"
  187. />
  188. <span>账号管理</span>
  189. </el-menu-item>
  190. <!-- 系统通知 -->
  191. <el-menu-item v-if="item.name == 'system'" index="/hotel/system">
  192. <img
  193. v-if="activeIndex == '/hotel/system'"
  194. src="@/assets/icons/systemS.png"
  195. alt=""
  196. style="width: 24px; height: 22px; margin: 0 18px"
  197. />
  198. <img
  199. v-else
  200. src="@/assets/icons/system.png"
  201. alt=""
  202. style="width: 22px; height: 22px; margin: 0 18px"
  203. />
  204. <span>系统设置</span>
  205. </el-menu-item>
  206. </div>
  207. <!-- 民宿管理 -->
  208. <!-- <el-sub-menu :index="56">
  209. <template #title>
  210. <img v-if="activeIndex == '/seniorCelebrity/houseInfo' ||
  211. activeIndex == '/seniorCelebrity/houseType' ||
  212. activeIndex == '/seniorCelebrity/houseList'
  213. " src="@/assets/houseS.png" style="width: 22px; height: 22px; margin: 0 20px 0 18px" alt="" />
  214. <img v-else src="@/assets/house.png" style="width: 22px; height: 22px; margin: 0 20px 0 18px" alt="" />
  215. <span>民宿管理</span>
  216. </template>
  217. <el-menu-item index="/seniorCelebrity/houseInfo">
  218. <template #title>
  219. <span>民宿信息</span>
  220. </template>
  221. </el-menu-item>
  222. <el-menu-item index="/seniorCelebrity/houseType">
  223. <template #title>
  224. <span>房型管理</span>
  225. </template>
  226. </el-menu-item>
  227. <el-menu-item index="/seniorCelebrity/houseList">
  228. <template #title>
  229. <span>房源信息</span>
  230. </template>
  231. </el-menu-item>
  232. </el-sub-menu> -->
  233. </el-menu>
  234. </div>
  235. </template>
  236. <script setup>
  237. import { ref, onBeforeMount, onMounted, watch, reactive } from "vue";
  238. import { useStore } from "vuex";
  239. import { useRouter } from "vue-router";
  240. const store = useStore();
  241. const router = useRouter();
  242. const menuClose = ref(false);
  243. const activeIndex = ref();
  244. const roleData = ref();
  245. watch(
  246. () => store.state.user.collapse,
  247. (newValue, oldValue) => {
  248. menuClose.value = newValue;
  249. }
  250. );
  251. // watch(
  252. // () => store.state.user.activeIndex,
  253. // (newValue, oldValue) => {
  254. // console.log(newValue);
  255. // activeIndex.value = newValue;
  256. // }
  257. // );
  258. watch(
  259. () => router.currentRoute.value.fullPath,
  260. (newValue, oldValue) => {
  261. console.log(newValue);
  262. store.commit("indexUp", newValue);
  263. activeIndex.value = newValue;
  264. }
  265. );
  266. const handleSelect = (key, keyPath) => {
  267. // store.commit("indexUp", key);
  268. // activeIndex.value = key;
  269. // sessionStorage.setItem("activeItem", key);
  270. // console.log(key, keyPath);
  271. router.push({
  272. path: `${key}`,
  273. });
  274. // activeIndex.value = key;
  275. // console.log(key);
  276. // store.commit("indexUp", key);
  277. // sessionStorage.setItem("activeItem", key);
  278. // if (activeIndex.value == 1) {
  279. // router.push({
  280. // path: `/seniorCelebrity/order`,
  281. // });
  282. // }
  283. };
  284. onBeforeMount(() => {
  285. activeIndex.value = sessionStorage.getItem("sidevarItem");
  286. let arr = JSON.parse(sessionStorage.getItem("roleList"));
  287. let roles = [];
  288. arr.forEach((i) => {
  289. // 房态管理
  290. if (i.path == "roomStatus") {
  291. roles.push({
  292. name: "roomStatus",
  293. meta: { isAuth: true, title: "房态管理" },
  294. });
  295. }
  296. // 房型管理
  297. else if (i.path == "roomType" || i.path == "roomPrice") {
  298. let flag=roles.some(item=>{
  299. return item.name=='roomTypes'
  300. })
  301. if(!flag){
  302. roles.push({
  303. name: "roomTypes",
  304. meta: { isAuth: true, title: "房型管理", sign: "roomTypes" },
  305. children: [
  306. // {
  307. // name: "roomType",
  308. // meta: { isAuth: true, title: "房型管理" },
  309. // },
  310. // {
  311. // name: "roomPrice",
  312. // meta: { isAuth: true, title: "房价管理" },
  313. // },
  314. ],
  315. });
  316. }
  317. }
  318. // 订单管理
  319. else if (i.path == "order") {
  320. roles.push({
  321. name: "order",
  322. meta: { isAuth: true, title: "订单管理" },
  323. });
  324. }
  325. // 授权管理
  326. else if (i.path == "class" || i.path == "process") {
  327. let flag=roles.some(item=>{
  328. return item.name=='classs'
  329. })
  330. if(!flag){
  331. roles.push({
  332. name: "classs",
  333. meta: { isAuth: true, title: "授权管理", sign: "classs" },
  334. children: [
  335. // {
  336. // name: "class",
  337. // meta: { isAuth: true, title: "课表管理" },
  338. // },
  339. // {
  340. // name: "process",
  341. // meta: { isAuth: true, title: "流程管理" },
  342. // },
  343. ],
  344. });
  345. }
  346. }
  347. // 统计报表
  348. else if (i.path == "statement") {
  349. roles.push({
  350. name: "statement",
  351. meta: { isAuth: true, title: "统计报表" },
  352. });
  353. }
  354. // 设备管理
  355. else if (i.path == "doorLock" || i.path == "meter") {
  356. let flag=roles.some(item=>{
  357. return item.name=='doorLocks'
  358. })
  359. if(!flag){
  360. roles.push({
  361. name: "doorLocks",
  362. meta: { isAuth: true, title: "设备管理", sign: "doorLocks" },
  363. children: [
  364. // {
  365. // name: "doorLock",
  366. // meta: { isAuth: true, title: "门锁管理" },
  367. // },
  368. // {
  369. // name: "meter",
  370. // meta: { isAuth: true, title: "水电表管理" },
  371. // },
  372. ],
  373. });
  374. }
  375. }
  376. // 组织架构
  377. else if (i.path == "user" || i.path == "userRoles") {
  378. let flag=roles.some(item=>{
  379. return item.name=='users'
  380. })
  381. if(!flag){
  382. roles.push({
  383. name: "users",
  384. meta: { isAuth: true, title: "组织架构", sign: "roomTypes" },
  385. children: [
  386. // {
  387. // name: "user",
  388. // meta: { isAuth: true, title: "用户管理" },
  389. // },
  390. // {
  391. // name: "userRoles",
  392. // meta: { isAuth: true, title: "用户角色" },
  393. // },
  394. ],
  395. });
  396. }
  397. }
  398. // 账号管理
  399. else if (i.path == "account") {
  400. roles.push({
  401. name: "account",
  402. meta: { isAuth: true, title: "账号管理" },
  403. });
  404. }
  405. // 系统管理
  406. else if (i.path == "system") {
  407. roles.push({
  408. name: "system",
  409. meta: { isAuth: true, title: "系统管理" },
  410. });
  411. }
  412. });
  413. let roleArr=[]
  414. arr.forEach(i=>{
  415. //房型管理 房型管理
  416. if(i.path == "roomType"){
  417. roles.forEach(item=>{
  418. if(item.name=='roomTypes'){
  419. item.children.push( {
  420. name: "roomType",
  421. meta: { isAuth: true, title: "房型管理" },
  422. },)
  423. }
  424. })
  425. }
  426. //房型管理 房价管理
  427. else if(i.path == "roomPrice"){
  428. roles.forEach(item=>{
  429. if(item.name=='roomTypes'){
  430. item.children.push( {
  431. name: "roomPrice",
  432. meta: { isAuth: true, title: "房价管理" },
  433. },)
  434. }
  435. })
  436. }
  437. //授权管理 课表管理
  438. else if(i.path == "class"){
  439. roles.forEach(item=>{
  440. if(item.name=='classs'){
  441. item.children.push( {
  442. name: "class",
  443. meta: { isAuth: true, title: "课表管理" },
  444. },)
  445. }
  446. })
  447. }
  448. //授权管理 流程管理
  449. else if(i.path == "process"){
  450. roles.forEach(item=>{
  451. if(item.name=='classs'){
  452. item.children.push( {
  453. name: "process",
  454. meta: { isAuth: true, title: "流程管理" },
  455. },)
  456. }
  457. })
  458. }
  459. //设备管理 门锁管理
  460. else if(i.path == "doorLock"){
  461. roles.forEach(item=>{
  462. if(item.name=='doorLocks'){
  463. item.children.push( {
  464. name: "doorLock",
  465. meta: { isAuth: true, title: "门锁管理" },
  466. },)
  467. }
  468. })
  469. }
  470. //设备管理 水电表管理
  471. else if(i.path == "meter"){
  472. roles.forEach(item=>{
  473. if(item.name=='doorLocks'){
  474. item.children.push( {
  475. name: "meter",
  476. meta: { isAuth: true, title: "水电表管理" },
  477. },)
  478. }
  479. })
  480. }
  481. //组织架构 用户管理
  482. else if(i.path == "user"){
  483. roles.forEach(item=>{
  484. if(item.name=='users'){
  485. item.children.push( {
  486. name: "user",
  487. meta: { isAuth: true, title: "用户管理" },
  488. },)
  489. }
  490. })
  491. }
  492. //组织架构 用户角色
  493. else if(i.path == "userRoles"){
  494. roles.forEach(item=>{
  495. if(item.name=='users'){
  496. item.children.push( {
  497. name: "userRoles",
  498. meta: { isAuth: true, title: "用户角色" },
  499. },)
  500. }
  501. })
  502. }
  503. })
  504. roleData.value = roles;
  505. console.log(roleData.value,"整理后的路由");
  506. });
  507. </script>
  508. <style lang="scss" scoped>
  509. .el-menu-vertical-demo:not(.el-menu--collapse) {
  510. // width: 220px;
  511. // min-height: 400px;
  512. }
  513. .box-item {
  514. width: 220px;
  515. height: calc(100vh);
  516. }
  517. .el-menu {
  518. width: 220px;
  519. height: 100%;
  520. background: rgba(24, 51, 82, 1);
  521. box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.16);
  522. // background: rgba(24, 51, 82, 1);
  523. overflow: auto;
  524. .logo {
  525. height: 65px;
  526. color: rgb(255, 255, 255);
  527. cursor: default;
  528. display: flex;
  529. justify-content: space-around;
  530. align-items: center;
  531. }
  532. .logo:hover {
  533. background-color: transparent !important;
  534. }
  535. .el-sub-menu {
  536. .el-menu-item {
  537. // background-color: rgba(255, 255, 255, 1);
  538. color: rgba(88, 109, 133, 1);
  539. padding: 0 20px 0 78px;
  540. }
  541. :deep(.el-tooltip__trigger) {
  542. padding: 0 20px;
  543. }
  544. :deep(.el-sub-menu__title):hover {
  545. color: rgba(18, 38, 61, 1);
  546. background-color: rgba(18, 38, 61, 1);
  547. span {
  548. color: #fff;
  549. }
  550. }
  551. .el-menu--inline {
  552. background-color: rgba(9, 101, 98, 1);
  553. }
  554. }
  555. .el-menu {
  556. .el-menu-item {
  557. background-color: rgba(24, 51, 82, 1);
  558. // padding-left: 30px;
  559. }
  560. .el-menu-item:hover {
  561. color: #fff;
  562. background-color: rgba(18, 38, 61, 1);
  563. }
  564. }
  565. .el-sub-menu:hover {
  566. color: #fff;
  567. }
  568. .el-menu-item:hover {
  569. background-color: rgba(18, 38, 61, 1);
  570. color: #fff;
  571. }
  572. .el-menu-item.is-active {
  573. background-color: rgba(18, 38, 61, 1);
  574. color: #fff;
  575. }
  576. }
  577. // .el-menu-item.is-active {
  578. // box-sizing: border-box;
  579. // // background-color: #fff;
  580. // background-color: rgba(111, 182, 184, 1);
  581. // color: #fff;
  582. // }
  583. .el-sub-menu.is-active {
  584. :deep(.el-sub-menu__title) {
  585. // border: 1px solid red;
  586. color: #fff !important;
  587. background-color: rgba(18, 38, 61, 1);
  588. }
  589. }
  590. </style>