重置函数修复
parent
42614f46b1
commit
895ffda288
|
|
@ -5,7 +5,7 @@ import Utils from '@/common/utils'
|
|||
import { SpecialPage } from '@/common/router/constants.ts'
|
||||
|
||||
export const useAppPageStore = defineStore('AppPage', () => {
|
||||
const pages = Utils.resetAble(reactive<AppTypes.PageContext[]>([]))/* as Reactive<AppTypes.PageContext[]> */
|
||||
const pages = Utils.resetAble(reactive<AppTypes.PageContext[]>([]))
|
||||
|
||||
const currentPage = Utils.resetAble(reactive<AppTypes.PageContext>({
|
||||
insId: '',
|
||||
|
|
@ -16,7 +16,7 @@ export const useAppPageStore = defineStore('AppPage', () => {
|
|||
menuId: '',
|
||||
icon: '',
|
||||
breadcrumb: [],
|
||||
}))/* as Reactive<AppTypes.PageContext> */
|
||||
}))
|
||||
|
||||
const keepAliveInclude = computed(() => {
|
||||
return pages.filter(it => it.keepAlive).map(it => Strings.pascalCase(it.routeName))
|
||||
|
|
|
|||
|
|
@ -12,143 +12,6 @@ import { SpecialPage } from '@/common/router/constants.ts'
|
|||
|
||||
type Option = Partial<Pick<AppTypes.PageContext, 'params' | 'insId' | 'title'>> & Pick<AppTypes.PageContext, 'routeName'>
|
||||
|
||||
/**
|
||||
* 打开页面并添加标签
|
||||
*
|
||||
* @param option
|
||||
*/
|
||||
|
||||
/* function open(option: string | Option) {
|
||||
let ctx: AppTypes.PageContext
|
||||
const appSettingStore = useAppSettingStore()
|
||||
if (typeof option === 'string') {
|
||||
const routeName = option
|
||||
if (!router.hasRoute(routeName)) {
|
||||
return reloadUserInfo()
|
||||
.then(reloadRouter)
|
||||
.then(() => {
|
||||
if (!router.hasRoute(routeName)) {
|
||||
ElMessage.error('页面不存在')
|
||||
return Promise.reject('页面不存在')
|
||||
}
|
||||
const menu = appSettingStore.menus.find(it => it.routeName === routeName)
|
||||
if (menu == null) {
|
||||
ElMessage.error('页面不存在')
|
||||
return Promise.reject('页面不存在')
|
||||
}
|
||||
ctx = {
|
||||
insId: routeName,
|
||||
title: menu.title,
|
||||
keepAlive: true,
|
||||
params: {},
|
||||
routeName,
|
||||
menuId: menu.id,
|
||||
icon: menu.icon,
|
||||
breadcrumb: menu.breadcrumb,
|
||||
}
|
||||
useAppPageStore().open(ctx)
|
||||
return router.push({name: ctx.routeName, params: ctx.params})
|
||||
.then(err => {
|
||||
if (err == null) {
|
||||
Evt.emit('openPage')
|
||||
return Promise.resolve(true)
|
||||
} else {
|
||||
return Promise.reject(err)
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
return Promise.reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
const menu = appSettingStore.menus.find(it => it.routeName === routeName)
|
||||
if (menu == null) {
|
||||
ElMessage.error('页面不存在')
|
||||
return Promise.reject('页面不存在')
|
||||
}
|
||||
ctx = {
|
||||
insId: routeName ,
|
||||
title: menu.title,
|
||||
keepAlive: true,
|
||||
params: {},
|
||||
routeName,
|
||||
menuId: menu.id,
|
||||
icon: menu.icon,
|
||||
breadcrumb: menu.breadcrumb,
|
||||
}
|
||||
} else {
|
||||
const routeName = option.routeName
|
||||
if (!router.hasRoute(routeName)) {
|
||||
return reloadUserInfo()
|
||||
.then(reloadRouter)
|
||||
.then(() => {
|
||||
if (!router.hasRoute(routeName)) {
|
||||
ElMessage.error('页面不存在')
|
||||
return Promise.reject('页面不存在')
|
||||
}
|
||||
const menu = appSettingStore.menus.find(it => it.routeName === routeName)
|
||||
if (menu == null) {
|
||||
ElMessage.error('页面不存在')
|
||||
return Promise.reject('页面不存在')
|
||||
}
|
||||
const option_ = option as Option
|
||||
ctx = {
|
||||
insId: option_.insId ?? routeName,
|
||||
title: option_.title ?? menu.title,
|
||||
routeName: routeName,
|
||||
keepAlive: true,
|
||||
params: option_.params ?? {},
|
||||
menuId: menu.id,
|
||||
icon: menu.icon,
|
||||
breadcrumb: menu.breadcrumb,
|
||||
}
|
||||
useAppPageStore().open(ctx)
|
||||
return router.push({name: ctx.routeName, params: ctx.params})
|
||||
.then(err => {
|
||||
if (err == null) {
|
||||
Evt.emit('openPage')
|
||||
return Promise.resolve(true)
|
||||
} else {
|
||||
return Promise.reject(err)
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
return Promise.reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
const menu = appSettingStore.menus.find(it => it.routeName === routeName)
|
||||
if (menu == null) {
|
||||
ElMessage.error('页面不存在')
|
||||
return Promise.reject('页面不存在')
|
||||
}
|
||||
|
||||
ctx = {
|
||||
insId: option.insId ?? routeName,
|
||||
title: option.title ?? menu.title,
|
||||
routeName: routeName,
|
||||
keepAlive: true,
|
||||
params: option.params ?? {},
|
||||
menuId: menu.id,
|
||||
icon: menu.icon,
|
||||
breadcrumb: menu.breadcrumb,
|
||||
}
|
||||
}
|
||||
useAppPageStore().open(ctx)
|
||||
return router.push({name: ctx.routeName, params: ctx.params})
|
||||
.then(err => {
|
||||
if (err == null) {
|
||||
Evt.emit('openPage')
|
||||
return Promise.resolve(true)
|
||||
} else {
|
||||
return Promise.reject(err)
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
return Promise.reject(err)
|
||||
})
|
||||
} */
|
||||
|
||||
function checkRoute(option: string | Option) {
|
||||
let opt: Option
|
||||
if (typeof option === 'string') {
|
||||
|
|
@ -188,6 +51,11 @@ function jump(ctx: AppTypes.PageContext) {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开页面并添加标签
|
||||
*
|
||||
* @param option
|
||||
*/
|
||||
function open(option: string | Option) {
|
||||
return checkRoute(option)
|
||||
.then(({option, menu}) => {
|
||||
|
|
@ -276,12 +144,11 @@ const install = (_: App): void => {
|
|||
.filter((it) => it.name !== SpecialPage.Main && it.name !== SpecialPage.Login && it.name !== SpecialPage.NotFound && it.name !== SpecialPage.Home)
|
||||
.map((it) => it.name as string)
|
||||
removeRoutes(routes)
|
||||
router.push({replace: true, name: SpecialPage.Login}).then(() => {
|
||||
// console.log(r)
|
||||
})
|
||||
router.push({replace: true, name: SpecialPage.Login})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
export default {
|
||||
open,
|
||||
close,
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ function resetAble<T>(target: T): ResetAble<T> {
|
|||
resetAbleTarget.$reset = (val?: PartialForObject<T>) => {
|
||||
const resetValue = val ?? (initialData as PartialForObject<T>)
|
||||
|
||||
if (Array.isArray(val)) {
|
||||
if (Array.isArray(resetValue)) {
|
||||
const arr = target as unknown as Array<unknown>
|
||||
const initialArr = resetValue as unknown as Array<unknown>
|
||||
arr.splice(0, arr.length, ...initialArr)
|
||||
|
|
|
|||
|
|
@ -54,10 +54,6 @@ watch(
|
|||
})
|
||||
})
|
||||
|
||||
function reopen(insId: string) {
|
||||
appPageStore.reopen(insId)
|
||||
}
|
||||
|
||||
function handleCommand(command: 'closeCurrent' | 'closeOther' | 'closeAll') {
|
||||
Nav[command]()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue