优化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') component: () => import('@/views/admin/Authority.vue')
}, { }, {
path: `${BASE_PATH}/menus`, path: `${BASE_PATH}/menus`,
name: 'Menus', name: 'MenusBase',
children: [{ children: [{
path: '', path: '',
name: 'menus-index', name: 'Menus',
component: () => import('@/views/admin/Menus.vue') component: () => import('@/views/admin/Menus.vue')
}, { }, {
path: 'edit/:id', path: 'edit/:id',
name: 'menus-edit', name: 'MenuEdit',
component: () => import('@/views/admin/MenuEdit.vue'), component: () => import('@/views/admin/MenuEdit.vue'),
meta: { meta: {
replaceTabHistory: 'menus-index', replaceTabHistory: 'Menus',
labelKey: 'menu.label.menuEdit', labelKey: 'menu.label.menuEdit',
icon: 'Edit' icon: 'Edit'
} }

View File

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

View File

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