merge: 合并 soy 1.3.8

This commit is contained in:
xlsea
2024-11-04 11:33:21 +08:00
39 changed files with 1634 additions and 1267 deletions

View File

@ -46,6 +46,10 @@ export const useAppStore = defineStore(SetupStoreId.App, () => {
});
setReloadFlag(true);
if (themeStore.resetCacheStrategy === 'refresh') {
routeStore.resetRouteCache();
}
}
const locale = ref<App.I18n.LangType>(localStg.get('lang') || 'zh-CN');

View File

@ -1,4 +1,4 @@
import { computed, ref, shallowRef } from 'vue';
import { computed, nextTick, ref, shallowRef } from 'vue';
import type { RouteRecordRaw } from 'vue-router';
import { defineStore } from 'pinia';
import { useBoolean } from '@sa/hooks';
@ -10,7 +10,6 @@ import { ROOT_ROUTE } from '@/router/routes/builtin';
import { getRouteName, getRoutePath } from '@/router/elegant/transform';
import { fetchGetRoutes } from '@/service/api';
import { humpToLine } from '@/utils/common';
import { useAppStore } from '../app';
import { useAuthStore } from '../auth';
import { useTabStore } from '../tab';
import {
@ -26,7 +25,6 @@ import {
} from './shared';
export const useRouteStore = defineStore(SetupStoreId.Route, () => {
const appStore = useAppStore();
const authStore = useAuthStore();
const tabStore = useTabStore();
const { bool: isInitConstantRoute, setBool: setIsInitConstantRoute } = useBoolean();
@ -166,8 +164,12 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
/** Cache routes */
const cacheRoutes = ref<RouteKey[]>([]);
/** All cache routes */
const allCacheRoutes = shallowRef<RouteKey[]>([]);
/**
* Exclude cache routes
*
* for reset route cache
*/
const excludeCacheRoutes = ref<RouteKey[]>([]);
/**
* Get cache routes
@ -175,69 +177,23 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
* @param routes Vue routes
*/
function getCacheRoutes(routes: RouteRecordRaw[]) {
const alls = getCacheRouteNames(routes);
cacheRoutes.value = alls;
allCacheRoutes.value = [...alls];
cacheRoutes.value = getCacheRouteNames(routes);
}
/**
* Add cache routes
* Reset route cache
*
* @default router.currentRoute.value.name current route name
* @param routeKey
*/
function addCacheRoutes(routeKey: RouteKey) {
if (cacheRoutes.value.includes(routeKey)) return;
async function resetRouteCache(routeKey?: RouteKey) {
const routeName = routeKey || (router.currentRoute.value.name as RouteKey);
cacheRoutes.value.push(routeKey);
}
excludeCacheRoutes.value.push(routeName);
/**
* Remove cache routes
*
* @param routeKey
*/
function removeCacheRoutes(routeKey: RouteKey) {
const index = cacheRoutes.value.findIndex(item => item === routeKey);
await nextTick();
if (index === -1) return;
cacheRoutes.value.splice(index, 1);
}
/**
* Is cached route
*
* @param routeKey
*/
function isCachedRoute(routeKey: RouteKey) {
return allCacheRoutes.value.includes(routeKey);
}
/**
* Re cache routes by route key
*
* @param routeKey
*/
async function reCacheRoutesByKey(routeKey: RouteKey) {
if (!isCachedRoute(routeKey)) return;
removeCacheRoutes(routeKey);
await appStore.reloadPage();
addCacheRoutes(routeKey);
}
/**
* Re cache routes by route keys
*
* @param routeKeys
*/
async function reCacheRoutesByKeys(routeKeys: RouteKey[]) {
for await (const key of routeKeys) {
await reCacheRoutesByKey(key);
}
excludeCacheRoutes.value = [];
}
/** Global breadcrumbs */
@ -415,8 +371,8 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => {
searchMenus,
updateGlobalMenusByLocale,
cacheRoutes,
reCacheRoutesByKey,
reCacheRoutesByKeys,
excludeCacheRoutes,
resetRouteCache,
breadcrumbs,
initConstantRoute,
isInitConstantRoute,