优化tabs以及缓存规则

This commit is contained in:
Gary Fu
2024-01-13 14:30:46 +08:00
parent 11f9f92fad
commit 859c075b75
3 changed files with 18 additions and 19 deletions

View File

@@ -22,17 +22,17 @@ export default [{
component: () => import('@/views/admin/Authority.vue')
}, {
path: `${BASE_PATH}/menus`,
name: 'Menus',
name: 'MenusBase',
children: [{
path: '',
name: 'menus-index',
name: 'Menus',
component: () => import('@/views/admin/Menus.vue')
}, {
path: 'edit/:id',
name: 'menus-edit',
name: 'MenuEdit',
component: () => import('@/views/admin/MenuEdit.vue'),
meta: {
replaceTabHistory: 'menus-index',
replaceTabHistory: 'Menus',
labelKey: 'menu.label.menuEdit',
icon: 'Edit'
}

View File

@@ -65,19 +65,14 @@ export const useTabsViewStore = defineStore('tabsView', () => {
if (idx < 0) {
const replaceIdx = historyTabs.value.findIndex(v => checkMataReplaceHistory(v, tab) ||
checkMataReplaceHistory(tab, v) || isSameReplaceHistory(v, tab))
let replaceTab = null
if (replaceIdx > -1) {
console.info(replaceIdx, historyTabs.value[replaceIdx])
if (replaceIdx !== undefined) {
replaceTab = historyTabs.value[replaceIdx]
historyTabs.value.splice(replaceIdx, 1, Object.assign({}, tab))
return
}
}
} else {
historyTabs.value.push(Object.assign({}, tab)) // 可能是Proxy需要解析出来
if (isCachedTabMode.value && tab.name) {
if (!cachedTabs.value.includes(tab.name)) {
cachedTabs.value.push(tab.name)
}
}
addCachedTab(tab, replaceTab)
}
}
}
@@ -116,8 +111,9 @@ export const useTabsViewStore = defineStore('tabsView', () => {
}
}
}
const addCachedTab = (tab) => {
if (isCachedTabMode.value && tab.name) {
const addCachedTab = (tab, replaceTab) => {
if (isCachedTabMode.value && tab.name && !tab.name.includes('-')) {
removeCachedTab(replaceTab)
if (!cachedTabs.value.includes(tab.name)) {
cachedTabs.value.push(tab.name)
}

View File

@@ -1,10 +1,12 @@
<script setup>
import { computed, onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { useRoute, useRouter } from 'vue-router'
import { loadAndParseMenus, loadMenuResult, useMenuFormOptions } from '@/services/menu/MenuService'
const route = useRoute()
const router = useRouter()
const backUrl = '/admin/menus'
const menuDto = ref({
id: route.params.id
})
@@ -35,6 +37,7 @@ const submitForm = form => {
form.validate(valid => {
if (valid) {
console.log('submit', menuDto.value)
router.push(backUrl)
}
})
}
@@ -47,7 +50,7 @@ const submitForm = form => {
:model="menuDto"
:options="menuFormOptions"
label-width="120px"
back-url="/admin/menus"
:back-url="backUrl"
@submit-form="submitForm"
/>
</el-container>