index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. <template>
  2. <el-menu :default-active="activeMenu" mode="horizontal">
  3. <template v-for="(item, index) in menuList">
  4. <template v-if="!item.hidden">
  5. <el-popover :key="item.path" trigger="hover" :visible-arrow="false" popper-class="zero-padding-popover">
  6. <div slot="reference" style="display: inline-block; line-height: 50px !important">
  7. <el-menu-item
  8. :style="{ '--theme': theme }"
  9. @click="handleClick(item)"
  10. :index="item.path"
  11. :key="item.path"
  12. v-if="index < visibleNumber && item.path && item.meta.title"
  13. >
  14. <svg-icon :icon-class="item.meta.icon"/>
  15. {{ item.meta.title }}
  16. </el-menu-item>
  17. <el-menu-item
  18. v-if="!(menuList.length > visibleNumber) && !three && user && false"
  19. @click="handleOpen('http://8.134.76.179/index.php?m=login&token='+user.code)"
  20. index="http://8.134.76.179/index"
  21. style="color: #999093"
  22. >
  23. <svg-icon icon-class="guide"/>
  24. 学习园地
  25. </el-menu-item>
  26. </div>
  27. </el-popover>
  28. </template>
  29. </template>
  30. <template></template>
  31. <!-- <template v-if="!(menuList.length > visibleNumber)">-->
  32. <!-- <el-button v-if="firstNav" style="margin-top:10px;margin-left:10px" size="small" @click.stop="backFirstMenu()" round>返回</el-button>-->
  33. <!-- </template>-->
  34. <!-- 顶部菜单超出数量折叠 -->
  35. <el-submenu index="more" v-if="menuList.length > visibleNumber">
  36. <template slot="title">更多菜单</template>
  37. <template v-for="(item, index) in menuList">
  38. <template v-if="!item.hidden">
  39. <el-menu-item :index="item.path" :key="index" v-if="index >= visibleNumber && item.path && item.meta.title"
  40. @click="handleClick(item)">
  41. <svg-icon :icon-class="item.meta.icon"/>
  42. {{ item.meta.title }}
  43. </el-menu-item>
  44. </template>
  45. </template>
  46. <el-menu-item
  47. v-if=" !three && user && false"
  48. @click="handleOpen('http://8.134.76.179/index.php?m=login&token='+user.code)"
  49. index="http://8.134.76.179/index"
  50. >
  51. <svg-icon icon-class="guide"/>
  52. 学习园地
  53. </el-menu-item>
  54. </el-submenu>
  55. <!-- <el-button v-if="three" style="margin-top:10px;margin-left:10px" size="small" @click.stop="backMenu()" round>-->
  56. <!-- 返回-->
  57. <!-- </el-button>-->
  58. <!-- <el-button v-if="firstNav" style="margin-top:10px;margin-left:10px" size="small" @click.stop="backFirstMenu()" round>返回首页</el-button> -->
  59. </el-menu>
  60. </template>
  61. <script>
  62. import { constantRoutes } from '@/router'
  63. import path from 'path'
  64. import auth from '@/utils/auth'
  65. import Cookies from 'js-cookie'
  66. import { mapGetters } from 'vuex'
  67. import RouterHelpMixin from '@/router/router-help-mixin'
  68. export default {
  69. mixins: [RouterHelpMixin],
  70. data() {
  71. return {
  72. // 顶部栏初始数
  73. visibleNumber: 10,
  74. // 是否为首次加载
  75. isFrist: false,
  76. // 当前激活菜单的 index
  77. currentIndex: undefined,
  78. menuList: [],
  79. three: false,
  80. firstNav: true,
  81. activeMenu: '',
  82. time: null,
  83. list1: [
  84. { name: '生涯测评', id: 'CareerEva' },
  85. { name: '院校库', id: 'UniversitiesColleges' },
  86. { name: '专业库', id: 'ProfessLib' },
  87. { name: '职业库', id: 'Vocation' },
  88. { name: '选科查询', id: 'Subject' },
  89. { name: '选科报名', id: 'SubjectSign' },
  90. { name: '生涯课程', id: '7' }
  91. ],
  92. list2: [
  93. { name: '高考政策', id: 'gkzc' },
  94. { name: '特殊类招生', id: 'tslzs' },
  95. { name: '强基计划', id: 'qjjh' },
  96. { name: '填报技巧', id: 'tbjq' }
  97. ],
  98. list3: [
  99. { name: '关注的院校', id: '0' },
  100. { name: '关注的专业', id: '1' },
  101. { name: '生涯测评报告', id: '2' },
  102. { name: '我的志愿表', id: '3' }
  103. ],
  104. list4: [
  105. { name: '模拟志愿', id: 'SimulatedVolunteer' },
  106. { name: '批次控制线', id: 'batch' },
  107. { name: '一分一段', id: 'yfyd' },
  108. { name: '投档线', id: 'ShiftLine' },
  109. { name: '高考名词', id: 'gkmc' }
  110. ],
  111. listActive: ''
  112. }
  113. },
  114. computed: {
  115. ...mapGetters(['currentUser']),
  116. user() {
  117. return this.currentUser
  118. },
  119. theme() {
  120. return this.$store.state.settings.theme
  121. },
  122. // 所有的路由信息
  123. routers() {
  124. return this.$store.state.permission.topbarRouters
  125. }
  126. },
  127. beforeMount() {
  128. window.addEventListener('resize', this.setVisibleNumber)
  129. },
  130. beforeDestroy() {
  131. window.removeEventListener('resize', this.setVisibleNumber)
  132. },
  133. mounted() {
  134. console.log(new Date().getTime())
  135. this.setVisibleNumber()
  136. this.menuList = this.topMenus()
  137. let menuList = []
  138. let routes = []
  139. menuList = auth.getMenuTab()
  140. routes = auth.getMenuList()
  141. console.log(menuList, routes)
  142. if (menuList && menuList.length > 0) {
  143. this.menuList = menuList
  144. this.$store.commit('SET_SIDEBAR_ROUTERS', routes)
  145. if (menuList[0].level == 2) {
  146. this.three = true
  147. }
  148. this.activeMenu = auth.getActiveMenu()
  149. } else {
  150. this.$store.commit('SET_SIDEBAR_ROUTERS', routes)
  151. this.gouTo()
  152. }
  153. console.log(new Date().getTime())
  154. if (menuList && menuList[0] && menuList[0].level == 2) {
  155. this.firstNav = false
  156. }
  157. console.log(menuList)
  158. },
  159. watch: {
  160. activeMenu: function(value) {
  161. console.log(value)
  162. if (value) {
  163. auth.setActiveMenu(value)
  164. }
  165. },
  166. $route: function() {
  167. this.menuList = auth.getMenuTab()
  168. this.activeMenu = auth.getActiveMenu()
  169. }
  170. },
  171. methods: {
  172. toSecondary(data, item) {
  173. auth.setActiveMenu(item.path)
  174. this.$router.push({ path: item.path, query: data })
  175. },
  176. clickEv(data, item) {
  177. this.listActive = data.id
  178. auth.setActiveMenu(item.path)
  179. // this.$router.push({ path: `/career/plan/${data.id}` }).catch(() => { })
  180. switch (data.id) {
  181. case 'CareerEva':
  182. auth.setActiveMenu(item.path)
  183. this.$router.push({ path: '/career/plan/CareerEva' }).catch(() => {
  184. })
  185. break
  186. case 'UniversitiesColleges':
  187. auth.setActiveMenu(item.path)
  188. this.$router
  189. .push({ path: '/career/plan/UniversitiesColleges' })
  190. .catch(() => {
  191. })
  192. break
  193. case 'ProfessLib':
  194. auth.setActiveMenu(item.path)
  195. this.$router
  196. .push({ path: '/career/plan/MajorLib' })
  197. .catch(() => {
  198. })
  199. break
  200. case 'Subject':
  201. this.$router.push({ path: '/career/subject/index' }).catch(() => {
  202. })
  203. break
  204. case 'SubjectSign':
  205. this.$router
  206. .push({ path: '/career/subjectSign/index' })
  207. .catch(() => {
  208. })
  209. break
  210. case 'Vocation':
  211. this.$router.push({ path: '/career/vocation/index' }).catch(() => {
  212. })
  213. break
  214. case 'batch':
  215. this.$router.push({ path: '/career/batch' }).catch(() => {
  216. })
  217. break
  218. case 'yfyd':
  219. this.$router.push({ path: '/career/yfyd' }).catch(() => {
  220. })
  221. break
  222. case 'gkmc':
  223. this.$router.push({ path: '/career/gkmc/index' }).catch(() => {
  224. })
  225. break
  226. case 'ShiftLine':
  227. this.$router.push({ path: '/career/ShiftLine' }).catch(() => {
  228. })
  229. break
  230. case 'SimulatedVolunteer':
  231. this.$router
  232. .push({ path: '/career/SimulatedVolunteer' })
  233. .catch(() => {
  234. })
  235. break
  236. default:
  237. this.toSecondary(data, item)
  238. break
  239. }
  240. },
  241. gouTo() {
  242. let menuList = this.topMenus()
  243. let actionMenu = ''
  244. menuList.forEach((item, index) => {
  245. if (this.$route.query.type == item.path) {
  246. this.handleClick(this.menuList[index] || {})
  247. if (item.children && item.children.length > 0) {
  248. actionMenu = item.path + '/' + item.children[0].path
  249. } else {
  250. actionMenu = item.path
  251. }
  252. }
  253. })
  254. console.log('actionMenu==', actionMenu)
  255. let routes = auth.getMenuList()
  256. if (routes.length == 0) {
  257. this.$router.push({ path: actionMenu })
  258. auth.setMenuListAction(actionMenu)
  259. } else {
  260. console.log('routes', routes)
  261. let path = this.findLeafDescendantPath(routes)
  262. if (path) {
  263. this.$router.push({ path: path })
  264. auth.setMenuListAction(path)
  265. console.log(new Date().getTime())
  266. }
  267. }
  268. },
  269. gouAction(data) {
  270. // 22.6.7 hht 作废此方法,只处理了有限级跳转
  271. if (data && data.length > 0) {
  272. if (data[0].children && data[0].children.length > 0) {
  273. if (
  274. data[0].children[0].children &&
  275. data[0].children[0].children.length > 0
  276. ) {
  277. return data[0].children[0].children.path
  278. } else {
  279. return data[0].path + '/' + data[0].children[0].path
  280. }
  281. } else {
  282. return data[0].path
  283. }
  284. } else {
  285. return ''
  286. }
  287. },
  288. backFirstMenu() {
  289. this.$router.push('/login')
  290. },
  291. backMenu() {
  292. this.menuList = this.topMenus()
  293. auth.setMenuTab(this.menuList)
  294. this.firstNav = true
  295. this.three = false
  296. },
  297. handleOpen(url) {
  298. window.open(url)
  299. },
  300. handleClick(data) {
  301. this.listActive = ''
  302. let item = JSON.parse(JSON.stringify(data))
  303. let routes = [] //三级菜单
  304. let second = [] //二级
  305. if (item.level == 1) {
  306. debugger
  307. //点击一级菜单
  308. if (item.children) {
  309. //有二级菜单
  310. item.children.forEach((item2) => {
  311. if (item2.children) {
  312. item2.children.forEach((item3) => {
  313. item3.path = item.path + '/' + item2.path + '/' + item3.path
  314. })
  315. if (routes.length == 0 && item2.children.length) {
  316. //一级菜单下面第一个有3个菜单的二级菜单
  317. routes = item2.children
  318. this.activeMenu = item.path + '/' + item2.path //默认值高亮
  319. }
  320. }
  321. item2.path = item.path + '/' + item2.path
  322. item2.level = 2
  323. second.push(item2)
  324. })
  325. this.menuList = second
  326. auth.setMenuTab(second)
  327. this.three = true
  328. this.$store.commit('SET_SIDEBAR_ROUTERS', routes)
  329. } else {
  330. //没有二级菜单
  331. this.$store.commit('SET_SIDEBAR_ROUTERS', [])
  332. this.$router.push({ path: item.path })
  333. }
  334. } else {
  335. auth.setActiveMenu(item.path)
  336. if (item.children) {
  337. //有三级菜单
  338. routes = item.children
  339. this.$store.commit('SET_SIDEBAR_ROUTERS', routes)
  340. let path = this.toPath(routes, '', '')
  341. auth.setMenuListAction(path)
  342. this.$router.push({ path: path })
  343. } else {
  344. routes = []
  345. this.$store.commit('SET_SIDEBAR_ROUTERS', [])
  346. this.$router.push({ path: item.path })
  347. }
  348. }
  349. auth.setMenuList(routes)
  350. this.firstNav = false
  351. this.$forceUpdate()
  352. },
  353. toPath(data, path, url) {
  354. data.forEach((item) => {
  355. if (!path && item.children && item.children.length > 0) {
  356. let ac = url ? url + '/' : ''
  357. path = this.toPath(item.children, path, ac + item.path)
  358. } else if (!path) {
  359. let ac = url ? url + '/' : ''
  360. path = ac + item.path
  361. }
  362. })
  363. return path
  364. },
  365. // 顶部显示菜单
  366. topMenus() {
  367. let topMenus = []
  368. this.routers.map((menu) => {
  369. menu.level = 1
  370. if (menu.hidden !== true) {
  371. // 兼容顶部栏一级菜单内部跳转
  372. if (menu.path === '/') {
  373. if (menu.children) {
  374. topMenus.push(menu.children[0])
  375. }
  376. } else {
  377. topMenus.push(menu)
  378. }
  379. }
  380. })
  381. return topMenus
  382. },
  383. // 根据宽度计算设置显示栏数
  384. setVisibleNumber() {
  385. const width = document.body.getBoundingClientRect().width / 2
  386. this.visibleNumber = parseInt(width / 85)
  387. },
  388. ishttp(url) {
  389. return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1
  390. }
  391. }
  392. }
  393. </script>
  394. <style lang="scss" scoped>
  395. // .el-menu--horizontal > .el-menu-item {
  396. // float: left;
  397. // height: 50px;
  398. // line-height: 50px;
  399. // margin: 0;
  400. // border-bottom: 3px solid transparent;
  401. // color: #999093;
  402. // padding: 0 5px;
  403. // margin: 0 10px;
  404. // }
  405. // .el-menu--horizontal >.el-popover__reference-wrapper > .el-menu-item.is-active {
  406. // border-bottom: 3px solid #{'var(--theme)'};
  407. // color: #303133;
  408. // }
  409. .navbar {
  410. .el-menu {
  411. .el-menu-item {
  412. float: left;
  413. height: 50px;
  414. line-height: 50px;
  415. margin: 0;
  416. border-bottom: 3px solid transparent;
  417. color: #999093;
  418. padding: 0 5px;
  419. margin: 0 10px;
  420. }
  421. span {
  422. .el-popover__reference-wrapper {
  423. .el-popover__reference {
  424. .el-menu-item.is-active {
  425. border-bottom: 3px solid #{"var(--theme)"} !important;
  426. // border:1px solid red;
  427. color: #303133 !important;
  428. }
  429. }
  430. }
  431. }
  432. }
  433. }
  434. .dataList {
  435. cursor: pointer;
  436. line-height: 36px;
  437. padding-left: 20px;
  438. &:hover {
  439. background-color: #d9ffee;
  440. }
  441. }
  442. /* submenu item */
  443. .el-menu--horizontal > .el-submenu .el-submenu__title {
  444. height: 50px !important;
  445. line-height: 50px !important;
  446. }
  447. </style>
  448. <style>
  449. .zero-padding-popover.el-popover {
  450. padding: 0px !important;
  451. }
  452. </style>