SidevarItem.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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 roles" class="items">
  20. <!-- 系统首页 -->
  21. <el-menu-item
  22. v-if="item.name == 'home'"
  23. :index="`/wanzai/${item.name}`"
  24. >
  25. <svg-icon
  26. v-if="activeIndex == '/wanzai/home'"
  27. iconName="home_s"
  28. class="iconClass"
  29. ></svg-icon>
  30. <svg-icon v-else iconName="home" class="iconClass"></svg-icon>
  31. <span>{{ item.meta.title }}</span>
  32. </el-menu-item>
  33. <!-- 用户管理 -->
  34. <el-menu-item
  35. :index="`/wanzai/${item.name}`"
  36. v-if="item.name == 'user'"
  37. >
  38. <svg-icon
  39. v-if="activeIndex == '/wanzai/user'"
  40. iconName="user_s"
  41. class="iconClass"
  42. ></svg-icon>
  43. <svg-icon v-else iconName="user" class="iconClass"></svg-icon>
  44. <span>{{ item.meta.title }}</span>
  45. </el-menu-item>
  46. <!-- 身份管理 -->
  47. <el-menu-item
  48. v-if="item.name == 'identity'"
  49. :index="`/wanzai/${item.name}`"
  50. >
  51. <svg-icon
  52. v-if="activeIndex == '/wanzai/identity'"
  53. iconName="identity_s"
  54. class="iconClass"
  55. ></svg-icon>
  56. <svg-icon v-else iconName="identity" class="iconClass"></svg-icon>
  57. <span>{{ item.meta.title }}</span>
  58. </el-menu-item>
  59. <!-- 年级管理 -->
  60. <el-sub-menu :index="item.name" v-if="item.name == 'classGrade'">
  61. <template #title>
  62. <svg-icon
  63. v-if="
  64. activeIndex == '/wanzai/class' ||
  65. activeIndex == '/wanzai/grades' ||
  66. activeIndex == '/wanzai/post' ||
  67. activeIndex == '/wanzai/subject' ||
  68. activeIndex == '/wanzai/semester'
  69. "
  70. iconName="classGrade_s"
  71. class="iconClass"
  72. ></svg-icon>
  73. <svg-icon v-else iconName="classGrade" class="iconClass"></svg-icon>
  74. <span>{{ item.meta.title }}</span>
  75. </template>
  76. <el-menu-item v-for="i in item.children" :index="`/wanzai/${i.name}`">
  77. <template #title>
  78. <span>{{ i.meta.title }}</span>
  79. </template>
  80. </el-menu-item>
  81. </el-sub-menu>
  82. <!-- 应用管理 -->
  83. <el-menu-item
  84. :index="`/wanzai/${item.name}`"
  85. v-if="item.name == 'apply'"
  86. >
  87. <svg-icon
  88. v-if="activeIndex == '/wanzai/apply'"
  89. iconName="apply_s"
  90. class="iconClass"
  91. ></svg-icon>
  92. <svg-icon v-else iconName="apply" class="iconClass"></svg-icon>
  93. <span>{{ item.meta.title }}</span>
  94. </el-menu-item>
  95. <!-- 能耗管理 -->
  96. <el-menu-item
  97. v-if="item.name == 'energy'"
  98. :index="`/wanzai/${item.name}`"
  99. >
  100. <svg-icon
  101. v-if="activeIndex == '/wanzai/energy'"
  102. iconName="energy_s"
  103. class="iconClass"
  104. ></svg-icon>
  105. <svg-icon v-else iconName="energy" class="iconClass"></svg-icon>
  106. <span>{{ item.meta.title }}</span>
  107. </el-menu-item>
  108. <!-- 校园安全 -->
  109. <el-menu-item
  110. :index="`/wanzai/${item.name}`"
  111. v-if="item.name == 'safety'"
  112. >
  113. <svg-icon
  114. v-if="activeIndex == '/wanzai/safety'"
  115. iconName="safety_s"
  116. class="iconClass"
  117. ></svg-icon>
  118. <svg-icon v-else iconName="safety" class="iconClass"></svg-icon>
  119. <span>{{ item.meta.title }}</span>
  120. </el-menu-item>
  121. <!-- 请假管理 -->
  122. <el-menu-item
  123. :index="`/wanzai/${item.name}`"
  124. v-if="item.name == 'leave'"
  125. >
  126. <svg-icon
  127. v-if="activeIndex == '/wanzai/leave'"
  128. iconName="leave_s"
  129. class="iconClass"
  130. ></svg-icon>
  131. <svg-icon v-else iconName="leave" class="iconClass"></svg-icon>
  132. <span>{{ item.meta.title }}</span>
  133. </el-menu-item>
  134. <!-- 访客预约 -->
  135. <el-menu-item
  136. :index="`/wanzai/${item.name}`"
  137. v-if="item.name == 'caller'"
  138. >
  139. <svg-icon
  140. v-if="activeIndex == '/wanzai/caller'"
  141. iconName="caller_s"
  142. class="iconClass"
  143. ></svg-icon>
  144. <svg-icon v-else iconName="caller" class="iconClass"></svg-icon>
  145. <span>{{ item.meta.title }}</span>
  146. </el-menu-item>
  147. <!-- 轨迹管理 -->
  148. <el-sub-menu :index="item.name" v-if="item.name == 'track'">
  149. <template #title>
  150. <svg-icon
  151. v-if="
  152. activeIndex == '/wanzai/trackSearch' ||
  153. activeIndex == '/wanzai/trafficRecord' ||
  154. activeIndex == '/wanzai/attendanceRecord' ||
  155. activeIndex == '/wanzai/faceRecord'
  156. "
  157. iconName="track_s"
  158. class="iconClass"
  159. ></svg-icon>
  160. <svg-icon v-else iconName="track" class="iconClass"></svg-icon>
  161. <span>{{ item.meta.title }}</span>
  162. </template>
  163. <el-menu-item v-for="i in item.children" :index="`/wanzai/${i.name}`">
  164. <template #title>
  165. <span>{{ i.meta.title }}</span>
  166. </template>
  167. </el-menu-item>
  168. </el-sub-menu>
  169. <!-- 综合素质评价 -->
  170. <el-sub-menu :index="item.name" v-if="item.name == 'evaluate'">
  171. <template #title>
  172. <svg-icon
  173. v-if="
  174. activeIndex == '/wanzai/teacher' ||
  175. activeIndex == '/wanzai/student'
  176. "
  177. iconName="evaluate_s"
  178. class="iconClass"
  179. ></svg-icon>
  180. <svg-icon v-else iconName="evaluate" class="iconClass"></svg-icon>
  181. <span>{{ item.meta.title }}</span>
  182. </template>
  183. <el-menu-item v-for="i in item.children" :index="`/wanzai/${i.name}`">
  184. <template #title>
  185. <span>{{ i.meta.title }}</span>
  186. </template>
  187. </el-menu-item>
  188. </el-sub-menu>
  189. <!-- 数据交换 -->
  190. <el-sub-menu :index="item.name" v-if="item.name == 'dataExchange'">
  191. <template #title>
  192. <svg-icon
  193. v-if="
  194. activeIndex == '/wanzai/source' ||
  195. activeIndex == '/wanzai/task' ||
  196. activeIndex == '/wanzai/log'
  197. "
  198. iconName="data_s"
  199. class="iconClass"
  200. ></svg-icon>
  201. <svg-icon v-else iconName="data" class="iconClass"></svg-icon>
  202. <span>{{ item.meta.title }}</span>
  203. </template>
  204. <el-menu-item v-for="i in item.children" :index="`/wanzai/${i.name}`">
  205. <template #title>
  206. <span>{{ i.meta.title }}</span>
  207. </template>
  208. </el-menu-item>
  209. </el-sub-menu>
  210. <!-- 系统通知 -->
  211. <el-sub-menu :index="item.name" v-if="item.name == 'system'">
  212. <template #title>
  213. <svg-icon
  214. v-if="
  215. activeIndex == '/wanzai/info' ||
  216. activeIndex == '/wanzai/screenShot' ||
  217. activeIndex == '/wanzai/roles'
  218. "
  219. iconName="system_s"
  220. class="iconClass"
  221. ></svg-icon>
  222. <svg-icon v-else iconName="system" class="iconClass"></svg-icon>
  223. <span>{{ item.meta.title }}</span>
  224. </template>
  225. <el-menu-item v-for="i in item.children" :index="`/wanzai/${i.name}`">
  226. <template #title>
  227. <span>{{ i.meta.title }}</span>
  228. </template>
  229. </el-menu-item>
  230. </el-sub-menu>
  231. </div>
  232. </el-menu>
  233. </div>
  234. </template>
  235. <script setup>
  236. import {
  237. ref,
  238. onBeforeMount,
  239. onMounted,
  240. onUnmounted,
  241. watch,
  242. reactive,
  243. nextTick,
  244. } from "vue";
  245. import { useStore } from "vuex";
  246. import { ElMessage, ElMessageBox } from "element-plus";
  247. import { useRouter } from "vue-router";
  248. import axios from "axios";
  249. const store = useStore();
  250. const router = useRouter();
  251. const api = ref();
  252. const menuClose = ref(false);
  253. const activeIndex = ref(1);
  254. const acitveItems = reactive({ list: [] });
  255. const roles = ref();
  256. const roleList = ref();
  257. watch(
  258. () => store.state.user.collapse,
  259. (newValue, oldValue) => {
  260. menuClose.value = newValue;
  261. }
  262. );
  263. // watch(
  264. // () => store.state.user.activeIndex,
  265. // (newValue, oldValue) => {
  266. // console.log(newValue);
  267. // activeIndex.value = newValue;
  268. // }
  269. // );
  270. watch(
  271. () => router.currentRoute.value.fullPath,
  272. (newValue, oldValue) => {
  273. console.log(newValue);
  274. store.commit("indexUp", newValue);
  275. activeIndex.value = newValue;
  276. }
  277. );
  278. const handleSelect = (key, keyPath) => {
  279. // store.commit("indexUp", key);
  280. // activeIndex.value = key;
  281. // sessionStorage.setItem("sidevarItem", key);
  282. // console.log(key, keyPath);
  283. router.push({
  284. path: `${key}`,
  285. });
  286. activeIndex.value = key;
  287. store.commit("indexUp", key);
  288. sessionStorage.setItem("sidevarItem", key);
  289. // if (activeIndex.value == 1) {
  290. // router.push({
  291. // path: `/seniorCelebrity/order`,
  292. // });
  293. // }
  294. };
  295. const roleListData = async () => {};
  296. const roleListChange = async () => {
  297. const formDatas = new FormData();
  298. nextTick(async () => {
  299. formDatas.append("userId", "");
  300. let resData = await axios({
  301. method: "post",
  302. url: api.value + "/wanzai/api/smartAuthorGroup/queryUserAuthor",
  303. headers: {
  304. token: sessionStorage.getItem("token"),
  305. user_head: sessionStorage.getItem("userhead"),
  306. },
  307. data: formDatas,
  308. });
  309. // console.log(resData, "查看当前用户权限");
  310. if (resData.data.code == 200) {
  311. let roleList = resData.data.data[0].treAuthor;
  312. roleList.value = resData.data.data[0].treAuthor;
  313. roleList.forEach((item) => {
  314. let list = item.route.split("/");
  315. item.routeName = list[2];
  316. });
  317. let flag = roleList.some((item) => {
  318. return item.route == "/wanzai/home";
  319. });
  320. let address = roleList[0].route;
  321. console.log(flag, address);
  322. sessionStorage.setItem("roleList", JSON.stringify(roleList));
  323. store.commit("ROLELIST", "");
  324. console.log("能监听到", roleList.value);
  325. {
  326. let classArr = [];
  327. let trackArr = [];
  328. let evaluateArr = [];
  329. let dataExchangeArr = [];
  330. let systemArr = [];
  331. let arr = [];
  332. roleList.value.forEach((item) => {
  333. if (
  334. item.routeName == "class" ||
  335. item.routeName == "grades" ||
  336. item.routeName == "post" ||
  337. item.routeName == "subject" ||
  338. item.routeName == "semester" ||
  339. item.routeName == "exam"
  340. ) {
  341. classArr.push({
  342. name: item.routeName,
  343. meta: { isAuth: true, title: item.name },
  344. });
  345. }else if (
  346. item.routeName == "trackSearch" ||
  347. item.routeName == "trafficRecord" ||
  348. item.routeName == "attendanceRecord" ||
  349. item.routeName == "faceRecord"
  350. ) {
  351. trackArr.push({
  352. name: item.routeName,
  353. meta: { isAuth: true, title: item.name },
  354. });
  355. }
  356. else if (
  357. item.routeName == "teacher" ||
  358. item.routeName == "student" ||
  359. item.routeName == "grade"
  360. ) {
  361. evaluateArr.push({
  362. name: item.routeName,
  363. meta: { isAuth: true, title: item.name },
  364. });
  365. } else if (
  366. item.routeName == "source" ||
  367. item.routeName == "task" ||
  368. item.routeName == "log"
  369. ) {
  370. dataExchangeArr.push({
  371. name: item.routeName,
  372. meta: { isAuth: true, title: item.name },
  373. });
  374. } else if (
  375. item.routeName == "info" ||
  376. item.routeName == "screenShot" ||
  377. item.routeName == "roles"
  378. ) {
  379. systemArr.push({
  380. name: item.routeName,
  381. meta: { isAuth: true, title: item.name },
  382. });
  383. } else {
  384. arr.push({
  385. name: item.routeName,
  386. meta: { isAuth: true, title: item.name },
  387. });
  388. }
  389. });
  390. // console.log(classArr, "年级管理");
  391. // console.log(evaluateArr, "综合素质评价");
  392. // console.log(dataExchangeArr, "数据交换");
  393. // console.log(systemArr, "系统设置");
  394. if (classArr.length != 0) {
  395. arr.splice(3, 0, {
  396. name: "classGrade",
  397. meta: { isAuth: true, title: "年级管理" },
  398. children: classArr,
  399. });
  400. }
  401. if (trackArr.length != 0) {
  402. arr.splice(9, 0, {
  403. name: "track",
  404. meta: { isAuth: true, title: "轨迹管理" },
  405. children: trackArr,
  406. });
  407. }
  408. if (evaluateArr.length != 0) {
  409. arr.push({
  410. name: "evaluate",
  411. meta: { isAuth: true, title: "综合素质评价" },
  412. children: evaluateArr,
  413. });
  414. }
  415. if (dataExchangeArr.length != 0) {
  416. arr.push({
  417. name: "dataExchange",
  418. meta: { isAuth: true, title: "数据交换" },
  419. children: dataExchangeArr,
  420. });
  421. }
  422. if (systemArr.length != 0) {
  423. arr.push({
  424. name: "system",
  425. meta: { isAuth: true, title: "系统设置" },
  426. children: systemArr,
  427. });
  428. }
  429. roles.value = arr;
  430. // roles.value = store.state.user.roles;
  431. // console.log(roles.value, "1111111111111111111111111111111");
  432. }
  433. } else {
  434. ElMessage({
  435. type: "error",
  436. showClose: true,
  437. message: resData.data.message,
  438. center: true,
  439. });
  440. }
  441. });
  442. };
  443. onBeforeMount(() => {
  444. activeIndex.value = sessionStorage.getItem("sidevarItem");
  445. api.value = store.state.user.api;
  446. roleListChange();
  447. });
  448. onMounted(() => {
  449. window.addEventListener("storage", roleListChange);
  450. });
  451. onUnmounted(() => {
  452. window.removeEventListener("storage", roleListChange);
  453. });
  454. </script>
  455. <style lang="scss" scoped>
  456. .iconClass {
  457. width: 1.5em;
  458. height: 1.5em;
  459. margin: 0 20px !important;
  460. }
  461. .el-menu-vertical-demo:not(.el-menu--collapse) {
  462. // width: 220px;
  463. // min-height: 400px;
  464. }
  465. .box-item {
  466. width: 220px !important;
  467. height: calc(100vh);
  468. }
  469. .el-menu {
  470. width: 220px;
  471. height: 100%;
  472. background: rgba(24, 51, 82, 1);
  473. box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.16);
  474. // background: rgba(24, 51, 82, 1);
  475. overflow: auto;
  476. .logo {
  477. height: 65px;
  478. color: rgb(255, 255, 255);
  479. cursor: default;
  480. display: flex;
  481. justify-content: space-around;
  482. align-items: center;
  483. }
  484. .logo:hover {
  485. background-color: transparent !important;
  486. }
  487. .el-sub-menu {
  488. .el-menu-item {
  489. // background-color: rgba(255, 255, 255, 1);
  490. color: rgba(88, 109, 133, 1);
  491. padding: 0 20px 0 78px;
  492. }
  493. :deep(.el-tooltip__trigger) {
  494. padding: 0 20px;
  495. }
  496. :deep(.el-sub-menu__title):hover {
  497. color: rgba(18, 38, 61, 1);
  498. background-color: rgba(18, 38, 61, 1);
  499. span {
  500. color: #fff;
  501. }
  502. }
  503. .el-menu--inline {
  504. background-color: rgba(9, 101, 98, 1);
  505. }
  506. }
  507. .el-menu {
  508. .el-menu-item {
  509. background-color: rgba(24, 51, 82, 1);
  510. // padding-left: 30px;
  511. }
  512. .el-menu-item:hover {
  513. color: #fff;
  514. background-color: rgba(18, 38, 61, 1);
  515. }
  516. }
  517. .el-sub-menu:hover {
  518. color: #fff;
  519. }
  520. .el-menu-item:hover {
  521. background-color: rgba(18, 38, 61, 1);
  522. color: #fff;
  523. }
  524. .el-menu-item.is-active {
  525. background-color: rgba(18, 38, 61, 1);
  526. color: #fff;
  527. }
  528. }
  529. // .el-menu-item.is-active {
  530. // box-sizing: border-box;
  531. // // background-color: #fff;
  532. // background-color: rgba(111, 182, 184, 1);
  533. // color: #fff;
  534. // }
  535. .el-sub-menu.is-active {
  536. :deep(.el-sub-menu__title) {
  537. // border: 1px solid red;
  538. color: #fff !important;
  539. background-color: rgba(18, 38, 61, 1);
  540. }
  541. }
  542. </style>