重置函数修复
parent
42614f46b1
commit
895ffda288
|
|
@ -5,7 +5,7 @@ import Utils from '@/common/utils'
|
||||||
import { SpecialPage } from '@/common/router/constants.ts'
|
import { SpecialPage } from '@/common/router/constants.ts'
|
||||||
|
|
||||||
export const useAppPageStore = defineStore('AppPage', () => {
|
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>({
|
const currentPage = Utils.resetAble(reactive<AppTypes.PageContext>({
|
||||||
insId: '',
|
insId: '',
|
||||||
|
|
@ -16,7 +16,7 @@ export const useAppPageStore = defineStore('AppPage', () => {
|
||||||
menuId: '',
|
menuId: '',
|
||||||
icon: '',
|
icon: '',
|
||||||
breadcrumb: [],
|
breadcrumb: [],
|
||||||
}))/* as Reactive<AppTypes.PageContext> */
|
}))
|
||||||
|
|
||||||
const keepAliveInclude = computed(() => {
|
const keepAliveInclude = computed(() => {
|
||||||
return pages.filter(it => it.keepAlive).map(it => Strings.pascalCase(it.routeName))
|
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'>
|
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) {
|
function checkRoute(option: string | Option) {
|
||||||
let opt: Option
|
let opt: Option
|
||||||
if (typeof option === 'string') {
|
if (typeof option === 'string') {
|
||||||
|
|
@ -188,6 +51,11 @@ function jump(ctx: AppTypes.PageContext) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开页面并添加标签
|
||||||
|
*
|
||||||
|
* @param option
|
||||||
|
*/
|
||||||
function open(option: string | Option) {
|
function open(option: string | Option) {
|
||||||
return checkRoute(option)
|
return checkRoute(option)
|
||||||
.then(({option, menu}) => {
|
.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)
|
.filter((it) => it.name !== SpecialPage.Main && it.name !== SpecialPage.Login && it.name !== SpecialPage.NotFound && it.name !== SpecialPage.Home)
|
||||||
.map((it) => it.name as string)
|
.map((it) => it.name as string)
|
||||||
removeRoutes(routes)
|
removeRoutes(routes)
|
||||||
router.push({replace: true, name: SpecialPage.Login}).then(() => {
|
router.push({replace: true, name: SpecialPage.Login})
|
||||||
// console.log(r)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
open,
|
open,
|
||||||
close,
|
close,
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ function resetAble<T>(target: T): ResetAble<T> {
|
||||||
resetAbleTarget.$reset = (val?: PartialForObject<T>) => {
|
resetAbleTarget.$reset = (val?: PartialForObject<T>) => {
|
||||||
const resetValue = val ?? (initialData as 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 arr = target as unknown as Array<unknown>
|
||||||
const initialArr = resetValue as unknown as Array<unknown>
|
const initialArr = resetValue as unknown as Array<unknown>
|
||||||
arr.splice(0, arr.length, ...initialArr)
|
arr.splice(0, arr.length, ...initialArr)
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,6 @@ watch(
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
function reopen(insId: string) {
|
|
||||||
appPageStore.reopen(insId)
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleCommand(command: 'closeCurrent' | 'closeOther' | 'closeAll') {
|
function handleCommand(command: 'closeCurrent' | 'closeOther' | 'closeAll') {
|
||||||
Nav[command]()
|
Nav[command]()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue