SidevarItem.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <div class="box-item">
  3. <el-menu
  4. class="el-menu-vertical-demo"
  5. text-color="#fff"
  6. :default-active="activeIndex"
  7. :collapse="menuClose"
  8. @select="handleSelect"
  9. :router="true"
  10. >
  11. <!-- :default-openeds="[34]" -->
  12. <div class="logo el-menu-item">
  13. <el-icon :size="20"
  14. ><img
  15. src="@/assets/images/logo.png"
  16. style="width: 40px; height: 40px"
  17. /></el-icon>
  18. </div>
  19. <el-menu-item
  20. :index="`/process/${item.name}`"
  21. v-for="item in roleList"
  22. :key="item.name"
  23. >
  24. <div class="itemSon">
  25. <SvgIcon :icon="item.meta.icon" :size="22" />
  26. <span>{{ item.meta.title }}</span>
  27. </div>
  28. </el-menu-item>
  29. </el-menu>
  30. </div>
  31. </template>
  32. <script setup>
  33. import { ref, onBeforeMount, onMounted, watch, reactive, nextTick } from "vue";
  34. import axios from "axios";
  35. import { useStore } from "vuex";
  36. import { useRouter } from "vue-router";
  37. import { genFileId, ElMessage, ElMessageBox } from "element-plus";
  38. const store = useStore();
  39. const router = useRouter();
  40. const roleList = ref();// 菜单权限
  41. const btnList=ref() //按钮权限
  42. const menuClose = ref(false);
  43. const activeIndex = ref("");
  44. const acitveItems = reactive({ list: [] });
  45. const api = ref();
  46. watch(
  47. () => store.state.user.collapse,
  48. (newValue, oldValue) => {
  49. menuClose.value = newValue;
  50. }
  51. );
  52. watch(
  53. () => router.currentRoute.value.fullPath,
  54. (newValue, oldValue) => {
  55. console.log(newValue);
  56. store.commit("indexUp", newValue);
  57. activeIndex.value = newValue;
  58. }
  59. );
  60. const handleSelect = (key, keyPath) => {
  61. // store.commit("indexUp", key);
  62. // activeIndex.value = key;
  63. // sessionStorage.setItem("sidevarItem", key);
  64. console.log(key, keyPath);
  65. router.push({
  66. path: `${key}`,
  67. });
  68. activeIndex.value = key;
  69. store.commit("indexUp", key);
  70. sessionStorage.setItem("sidevarItem", key);
  71. // if (activeIndex.value == 1) {
  72. // router.push({
  73. // path: `/jianguanCloud/order`,
  74. // });
  75. // }
  76. };
  77. const roleChange = async () => {
  78. nextTick(async () => {
  79. let res = await axios({
  80. method: "post",
  81. url: api.value + "/api/sysUser/queryOwn",
  82. headers: {
  83. tokenP: sessionStorage.getItem("tokenP"),
  84. user_head: sessionStorage.getItem("userhead"),
  85. },
  86. });
  87. console.log(res, "获取个人信息");
  88. if (res.data.code == 200) {
  89. sessionStorage.setItem('id',res.data.data.id)
  90. sessionStorage.setItem('userName',res.data.data.userName)
  91. let data = new FormData();
  92. data.append("roleId", res.data.data.roleId);
  93. let role = await axios({
  94. method: "post",
  95. url: api.value + "/api/sysRole/queryMenuByRole",
  96. headers: {
  97. tokenP: sessionStorage.getItem("tokenP"),
  98. user_head: sessionStorage.getItem("userhead"),
  99. },
  100. data: data,
  101. });
  102. console.log(role, "查询角色菜单权限");
  103. if (role.data.code == 200) {
  104. roleList.value = [];// 菜单权限
  105. btnList.value=[]
  106. let resdata=role.data.data
  107. resdata=resdata.filter(i=>{
  108. return i.state==1
  109. })
  110. resdata.forEach((item) => {
  111. // let modules = import.meta.glob("../views/**/*.vue");
  112. if (item.state == 1) {
  113. let arr = {
  114. path: item.url,
  115. name: item.url,
  116. meta: { title: item.menuName, icon: item.url },
  117. component: () =>
  118. import(`../../views/${item.url}/${item.url}.vue`),
  119. };
  120. // state[0].roleList.children.push(arr);
  121. roleList.value.push(arr);
  122. }
  123. if(item.menuLists){
  124. item.menuLists.forEach(i=>{
  125. if(i.state==1){
  126. btnList.value.push(i.url)
  127. }
  128. })
  129. }
  130. });
  131. sessionStorage.setItem("roleList", JSON.stringify(resdata));
  132. sessionStorage.setItem("btnList", JSON.stringify(btnList.value));
  133. let roles = JSON.parse(sessionStorage.getItem("roleList"));
  134. if (roles) {
  135. store.commit("ROLELIST", "");
  136. }
  137. } else {
  138. ElMessage({
  139. type: "error",
  140. showClose: true,
  141. message: role.data.message,
  142. center: true,
  143. });
  144. }
  145. } else {
  146. ElMessage({
  147. type: "error",
  148. showClose: true,
  149. message: res.data.message,
  150. center: true,
  151. });
  152. }
  153. });
  154. };
  155. onBeforeMount(() => {
  156. api.value = store.state.user.api;
  157. roleChange();
  158. activeIndex.value = sessionStorage.getItem("sidevarItem");
  159. // roleList.value = sessionStorage.getItem("roleList");
  160. // roleList.value = store.state.user.roleList;
  161. });
  162. </script>
  163. <style lang="scss" scoped>
  164. .el-menu-vertical-demo:not(.el-menu--collapse) {
  165. width: 220px;
  166. // min-height: 400px;
  167. }
  168. .box-item {
  169. width: 220px;
  170. height: calc(100vh);
  171. }
  172. .el-menu {
  173. width: 220px;
  174. height: 100%;
  175. overflow: auto;
  176. // background: rgba(55, 105, 173, 1);
  177. background: rgba(46, 64, 89, 1);
  178. box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.16);
  179. border: none;
  180. .logo {
  181. height: 64px;
  182. color: rgb(255, 255, 255);
  183. cursor: default;
  184. display: flex;
  185. justify-content: space-around;
  186. align-items: center;
  187. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  188. }
  189. .logo:hover {
  190. background-color: transparent !important;
  191. }
  192. .itemSon {
  193. width: 180px;
  194. height: 40px;
  195. border-radius: 10px;
  196. display: flex;
  197. // justify-content: space-around;
  198. align-items: center;
  199. // background: linear-gradient(
  200. // 90deg,
  201. // rgba(38, 151, 255, 1) 0%,
  202. // rgba(102, 182, 255, 1) 100%
  203. // );
  204. .svg-icon {
  205. margin: 0 15px;
  206. }
  207. }
  208. .el-sub-menu {
  209. padding: 8px 0;
  210. .el-menu-item {
  211. padding: 0;
  212. background: rgba(46, 64, 89, 1);
  213. color: #fff;
  214. display: flex;
  215. justify-content: center;
  216. .img {
  217. width: 18px;
  218. margin: 0 20px;
  219. }
  220. .itemSon:hover {
  221. background: rgba(55, 105, 173, 1);
  222. color: rgba(99, 180, 255, 1);
  223. }
  224. }
  225. .el-menu-item:hover {
  226. background: rgba(46, 64, 89, 1);
  227. color: #fff;
  228. .itemSon {
  229. background: rgba(55, 105, 173, 1);
  230. color: rgba(99, 180, 255, 1);
  231. }
  232. }
  233. .el-menu-item.is-active {
  234. .itemSon {
  235. background: rgba(55, 105, 173, 1);
  236. color: rgba(99, 180, 255, 1);
  237. }
  238. }
  239. // 系统设置栏样式
  240. :deep(.el-sub-menu__title) {
  241. padding: 0;
  242. margin: 0 auto;
  243. width: 180px;
  244. height: 40px;
  245. border-radius: 10px;
  246. display: flex;
  247. align-items: center;
  248. background: rgba(55, 105, 173, 1);
  249. color: #fff;
  250. .el-icon {
  251. width: 18px;
  252. }
  253. }
  254. }
  255. .el-sub-menu.is-active {
  256. :deep(.el-sub-menu__title) {
  257. background: linear-gradient(
  258. 90deg,
  259. rgba(38, 151, 255, 1) 0%,
  260. rgba(102, 182, 255, 1) 100%
  261. );
  262. color: fff;
  263. }
  264. }
  265. // 单个菜单项样式
  266. .el-menu-item {
  267. padding: 10px 0 !important;
  268. display: flex;
  269. justify-content: center;
  270. }
  271. .el-menu-item:hover {
  272. background: rgba(46, 64, 89, 1);
  273. .itemSon {
  274. background: rgba(55, 105, 173, 1);
  275. color: rgba(99, 180, 255, 1);
  276. }
  277. }
  278. .el-menu-item.is-active {
  279. .itemSon {
  280. background: linear-gradient(
  281. 90deg,
  282. rgba(38, 151, 255, 1) 0%,
  283. rgba(102, 182, 255, 1) 100%
  284. );
  285. color: #fff;
  286. }
  287. }
  288. }
  289. </style>