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.

284 lines
8.2 KiB

3 years ago
10 months ago
3 years ago
1 year ago
3 years ago
1 year ago
3 years ago
1 year ago
3 years ago
1 year ago
3 years ago
1 year ago
3 years ago
1 year ago
3 years ago
10 months ago
3 years ago
10 months ago
3 years ago
  1. <template>
  2. <aside class="site-sidebar" :class="'site-sidebar--' + sidebarLayoutSkin">
  3. <div class="site-sidebar__inner">
  4. <el-menu
  5. :default-active="menuActiveName || 'home'"
  6. :collapse="sidebarFold"
  7. :collapseTransition="false"
  8. class="site-sidebar__menu">
  9. <el-menu-item style=" padding-left: -5px;" :class="$store.state.common.sidebarLayoutSkin === 'light'?'menu-light':'menu-dark'">
  10. <span slot="title">
  11. <el-input v-model="search" placeholder="搜索" class="custom-input" @keyup.enter.native="searchMenu1" style="margin-left: -2px"></el-input></span>
  12. <i type="primary" class="el-icon-search" style="font-size: small" @click="searchMenu1()"></i>
  13. </el-menu-item>
  14. <el-menu-item index="home" @click="$router.push({ name: 'home' })">
  15. <icon-svg name="shouye" class="site-sidebar__menu-icon"></icon-svg>
  16. <span slot="title">{{ pageLanguage.homePage }}</span>
  17. </el-menu-item>
  18. <sub-menu
  19. v-for="menu in menuList"
  20. :key="menu.menuId"
  21. :menu="menu"
  22. :dynamicMenuRoutes="dynamicMenuRoutes">
  23. </sub-menu>
  24. <sub-menu
  25. v-for="menu in this.favoriteList"
  26. :key="menu.menuId"
  27. :menu="menu"
  28. :dynamicMenuRoutes="dynamicMenuRoutes">
  29. </sub-menu>
  30. </el-menu>
  31. </div>
  32. </aside>
  33. </template>
  34. <script>
  35. import SubMenu from './main-sidebar-sub-menu'
  36. import {isURL} from '@/utils/validate'
  37. import {userFavoriteList} from '@/api/userFavorite.js'
  38. import {treeDataTranslate} from '@/utils'
  39. import {
  40. searchFunctionButtonList,
  41. } from "@/api/sysLanguage.js"
  42. import {EventBus} from "../main";
  43. export default {
  44. data() {
  45. return {
  46. dynamicMenuRoutes: [],
  47. search: '',
  48. categoryList: [],
  49. uFavoriteList: [],
  50. favoriteList: [],
  51. newMenuList: [],
  52. list: [],
  53. pageLanguage: {
  54. homePage: '首页'
  55. }
  56. }
  57. },
  58. components: {
  59. SubMenu
  60. },
  61. computed: {
  62. sidebarLayoutSkin: {
  63. get() {
  64. return this.$store.state.common.sidebarLayoutSkin
  65. }
  66. },
  67. sidebarFold: {
  68. get() {
  69. return this.$store.state.common.sidebarFold
  70. }
  71. },
  72. menuList:
  73. {
  74. get() {
  75. return this.$store.state.common.menuList
  76. },
  77. set(val) {
  78. this.$store.commit('common/updateMenuList', val)
  79. }
  80. },
  81. menuActiveName: {
  82. get() {
  83. return this.$store.state.common.menuActiveName
  84. },
  85. set(val) {
  86. this.$store.commit('common/updateMenuActiveName', val)
  87. }
  88. },
  89. mainTabs: {
  90. get() {
  91. return this.$store.state.common.mainTabs
  92. },
  93. set(val) {
  94. this.$store.commit('common/updateMainTabs', val)
  95. }
  96. },
  97. mainTabsActiveName: {
  98. get() {
  99. return this.$store.state.common.mainTabsActiveName
  100. },
  101. set(val) {
  102. this.$store.commit('common/updateMainTabsActiveName', val)
  103. }
  104. }
  105. },
  106. watch: {
  107. $route: 'routeHandle'
  108. },
  109. created() {
  110. EventBus.$on('updateFavoriteList', this.updateFavoriteList);
  111. this.menuList = JSON.parse(sessionStorage.getItem('menuList') || '[]').filter(item => item.menuId != 999)
  112. this.favoriteList = JSON.parse(sessionStorage.getItem('menuList') || '[]').filter(item => item.menuId == 999)
  113. this.userFavorites()
  114. this.dynamicMenuRoutes = JSON.parse(sessionStorage.getItem('dynamicMenuRoutes') || '[]')
  115. this.routeHandle(this.$route)
  116. this.getFunctionButtonList()
  117. this.changeStyle()
  118. },
  119. destroyed() {
  120. EventBus.$off('updateFavoriteList', this.updateFavoriteList);
  121. },
  122. methods: {
  123. changeStyle(){
  124. let data= JSON.parse(sessionStorage.getItem('userConfig') || '{}')
  125. this.$store.commit('common/updateNavbarLayoutType', data.navbarLayoutType)
  126. this.$store.commit('common/updateSidebarLayoutSkin', data.sidebarLayoutSkin)
  127. },
  128. // 获取 首页菜单
  129. // 获取页面多语言数据
  130. getFunctionButtonList() {
  131. let queryButton = {
  132. functionId: 'systemInformation',
  133. tableId: 'systemInformation',
  134. languageCode: this.$i18n.locale,
  135. objectId: 'homePage'
  136. }
  137. searchFunctionButtonList(queryButton).then(({data}) => {
  138. if (data.code == 0 ) {
  139. this.pageLanguage = data.data
  140. }
  141. })
  142. },
  143. // 用户收藏夹
  144. userFavorites() {
  145. let query = {
  146. userId: this.$store.state.user.id,
  147. languageCode: this.$i18n.locale
  148. }
  149. userFavoriteList(query).then(({data}) => {
  150. if (data.list.length > 0) {
  151. this.favoriteList[0].list = data.list
  152. }
  153. })
  154. },
  155. updateFavoriteList(){
  156. this.userFavorites()
  157. },
  158. // 更具 当前节点id 获取上级节点
  159. getParent(val, sum) {
  160. if (val == 0) {
  161. return;
  162. }
  163. let parent = this.list.filter(item => item.menuId == val)
  164. if (parent.length > 0) {
  165. parent[0].list.length = 0
  166. sum.push(parent[0])
  167. this.getParent(parent[0].parentId, sum)
  168. }
  169. },
  170. // 搜索菜单方式1 start
  171. searchMenu1() {
  172. if (this.search == "") {
  173. this.menuList = JSON.parse(sessionStorage.getItem('menuList') || '[]').filter(item => item.menuId != 999)
  174. } else {
  175. let menuPlus = []
  176. this.menuList = JSON.parse(sessionStorage.getItem('menuList') || '[]').filter(item => item.menuId != 999)
  177. // this.menuList = this.treeFindPath(this.menuList).filter(this.search)
  178. // 转换成list
  179. this.list = this.treeFindPath(this.menuList)
  180. let list = this.treeFindPath(this.menuList)
  181. list = this.distinct(list, list);
  182. // list中获取菜单
  183. this.menuList = list.filter(item => item.name.indexOf(this.search) != -1)
  184. let menuSum = []
  185. for (let data of this.menuList) {
  186. menuSum.push(data)
  187. this.getParent(data.parentId, menuSum)
  188. }
  189. menuSum = Array.from(new Set([...menuSum]))
  190. if (menuSum.length > 0) {
  191. let menuList = menuSum.filter(item => item.parentId == 0);
  192. this.menuList = menuList
  193. this.treeList(menuList, menuSum)
  194. }
  195. }
  196. },
  197. // 封装树形结构
  198. treeList(menuList, menuSum) {
  199. for (let m1 of menuList) {
  200. for (let m2 of menuSum) {
  201. if (m1.menuId == m2.parentId) {
  202. m1.list.push(m2)
  203. this.treeList(m1.list, menuSum)
  204. }
  205. }
  206. }
  207. },
  208. // 搜索菜单方式1 树结构菜单转换list
  209. treeFindPath(tree, path = []) {
  210. if (!tree) return []
  211. for (const data of tree) {
  212. path.push(data)
  213. // if (data.list != null) {
  214. // path.push(...data.list)
  215. // delete data.list
  216. // }
  217. this.treeFindPath(data.list, path)
  218. }
  219. return path
  220. },
  221. // 搜索菜单方式1 去重
  222. distinct(a, b) {
  223. return Array.from(new Set([...a, ...b]))
  224. },
  225. // 路由操作
  226. routeHandle(route) {
  227. if (route.meta.isTab) {
  228. // tab选中, 不存在先添加
  229. var tab = this.mainTabs.filter(item => item.name === route.name)[0]
  230. if (!tab) {
  231. if (route.meta.isDynamic) {
  232. route = this.dynamicMenuRoutes.filter(item => item.name === route.name)[0]
  233. if (!route) {
  234. return console.error('未能找到可用标签页!')
  235. }
  236. }
  237. tab = {
  238. menuId: route.meta.menuId || route.name,
  239. name: route.name,
  240. title: route.meta.title,
  241. type: isURL(route.meta.iframeUrl) ? 'iframe' : 'module',
  242. iframeUrl: route.meta.iframeUrl || '',
  243. params: route.params,
  244. query: route.query
  245. }
  246. this.mainTabs = this.mainTabs.concat(tab)
  247. }
  248. this.menuActiveName = tab.menuId + ''
  249. this.mainTabsActiveName = tab.name
  250. }
  251. }
  252. }
  253. }
  254. </script>
  255. <style>
  256. .menu-dark .el-input__inner {
  257. background: transparent;
  258. width: 195px;
  259. font-size: 12px;
  260. color: #FFFFFF;
  261. border: #0BB2D4;
  262. }
  263. .menu-light .el-input__inner {
  264. background: transparent;
  265. width: 195px;
  266. font-size: 12px;
  267. color: #000;
  268. border: #0BB2D4;
  269. }
  270. .custom-input .el-input__inner::placeholder {
  271. font-size: 15px; /* 更改此处为您需要的字体大小 */
  272. color: #999; /* 更改此处为您所需的颜色 */
  273. }
  274. </style>