HcTopMenu.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { isPathUrl } from '~uti/tools'
  2. import { getToken } from '~src/api/util/auth'
  3. import { getStoreValue } from '~uti/storage'
  4. import { getTenantDetail } from '~api/other'
  5. import { getArrValue, getObjValue, newWindow } from 'js-fast-way'
  6. export default class HcTopMenu {
  7. // 基础菜单
  8. static baseMenu = [
  9. 'home', 'home-index', 'home-index-static', 'home-config', 'order-service', 'user-index', '403', '404', '500',
  10. ]
  11. static initMenu({ routes, menu, load, change }) {
  12. const topName = routes.matched[0]?.name
  13. if (this.baseMenu.includes(topName)) {
  14. load(topName)
  15. return false
  16. }
  17. for (let i = 0; i < menu.length; i++) {
  18. if (menu[i].code === topName) {
  19. change(topName, menu[i])
  20. }
  21. }
  22. }
  23. static async setMenuItem(item) {
  24. if (isPathUrl(item?.path)) {
  25. let token = getToken(), domain = item?.path
  26. const tenantId = getStoreValue('tenantId') ?? ''
  27. const projectId = getStoreValue('projectId') ?? ''
  28. const contractId = getStoreValue('contractId') ?? ''
  29. if (item?.code === 'to-archives-url' || item?.code === 'to-measure-url') {
  30. if (tenantId === '000000' || !tenantId) {
  31. domain = item?.path
  32. } else {
  33. const { error, code, data } = await getTenantDetail(tenantId)
  34. if (!error && code === 200) {
  35. const url = getObjValue(data).domainUrl
  36. domain = url ? url : item?.path
  37. }
  38. }
  39. }
  40. //跳转到新页面
  41. newWindow(`${domain}/#/auth?token=${token}&tid=${tenantId}&pid=${projectId}&cid=${contractId}`)
  42. } else {
  43. return getArrValue(item?.children)
  44. }
  45. }
  46. }