| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import { RouteNameRaw } from '@/router'
- import type { RoutesRef } from '@/router/info'
- import type { MenuRaw, MenuRelation } from '@/views/sys/menu/menu'
- import type { ComputedRef, Ref } from 'vue'
- import type { ModeFlag } from './sys'
- export type AuthName<T extends ModeFlag = any> =
- RouteNameRaw<T>[keyof RouteNameRaw<T>]
- export type RouteAuth = {
- name: AuthName
- open: boolean
- }
- export type RouteAuths = RouteAuth[]
- export type AppConfig = {
- routerRef: RoutesRef
- menu: ComputedRef<{
- list: MenuRaw
- allList?: MenuRaw
- relation: MenuRelation
- }>
- preset?: () => Promise<void>
- auth?: {
- list: Ref<RouteAuths>
- include: (name: AuthName | AuthName[] | string) => void
- exclude: (name: AuthName | AuthName[] | string) => void
- inExclude: (name: AuthName | AuthName[] | string) => boolean
- inInclude: (name: AuthName | AuthName[] | string) => boolean
- request: () => Promise<any>
- save: () => Promise<any>
- backups: () => void
- recovery: () => void
- }
- logo: string
- basePath?: string
- }
- export const getResources = uri => {
- if (
- !currentApp.basePath ||
- ~uri.indexOf('base64') ||
- ~uri.indexOf('bolb') ||
- ~uri.indexOf('//')
- )
- return uri
- const baseURL = new URL(currentApp.basePath)
- const url = new URL(uri, currentApp.basePath)
- const basePath =
- baseURL.pathname[baseURL.pathname.length - 1] === '/'
- ? baseURL.pathname.substring(0, baseURL.pathname.length - 1)
- : baseURL.pathname
- url.pathname = basePath + url.pathname
- return url.href
- }
- // 保存每个app的状态
- export let currentApp: AppConfig = {
- menu: null,
- routerRef: null,
- logo: null
- }
- export const setCurrentApp = (config: AppConfig) => {
- currentApp = config
- }
|