1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- import { isPathUrl } from '~uti/tools'
- import { getToken } from '~src/api/util/auth'
- import { getStoreValue } from '~uti/storage'
- import { getTenantDetail } from '~api/other'
- import { getArrValue, getObjValue, newWindow } from 'js-fast-way'
- export default class HcTopMenu {
- // 基础菜单
- static baseMenu = [
- 'home', 'home-index', 'home-index-static', 'home-config', 'order-service', 'user-index', '403', '404', '500',
- ]
- static initMenu({ routes, menu, load, change }) {
- const topName = routes.matched[0]?.name
- if (this.baseMenu.includes(topName)) {
- load(topName)
- return false
- }
- for (let i = 0; i < menu.length; i++) {
- if (menu[i].code === topName) {
- change(topName, menu[i])
- }
- }
- }
- static async setMenuItem(item) {
- if (isPathUrl(item?.path)) {
- let token = getToken(), domain = item?.path
- const tenantId = getStoreValue('tenantId') ?? ''
- const projectId = getStoreValue('projectId') ?? ''
- const contractId = getStoreValue('contractId') ?? ''
- if (item?.code === 'to-archives-url' || item?.code === 'to-measure-url') {
- if (tenantId === '000000' || !tenantId) {
- domain = item?.path
- } else {
- const { error, code, data } = await getTenantDetail(tenantId)
- if (!error && code === 200) {
- const url = getObjValue(data).domainUrl
- domain = url ? url : item?.path
- }
- }
- }
- //跳转到新页面
- newWindow(`${domain}/#/auth?token=${token}&tid=${tenantId}&pid=${projectId}&cid=${contractId}`)
- } else {
- return getArrValue(item?.children)
- }
- }
- }
|