From 3922c16601266e78ee3b90936ba49305c6c8b09a Mon Sep 17 00:00:00 2001
From: ahao <liuhaoai545@gmail.com>
Date: 星期三, 27 十二月 2023 12:12:51 +0800
Subject: [PATCH] fix 修复 vue 类型识别问题

---
 src/layout/components/TagsView/index.vue |   51 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/src/layout/components/TagsView/index.vue b/src/layout/components/TagsView/index.vue
index 0e23caa..1e12ca4 100644
--- a/src/layout/components/TagsView/index.vue
+++ b/src/layout/components/TagsView/index.vue
@@ -32,24 +32,24 @@
 <script setup lang="ts">
 import ScrollPane from './ScrollPane.vue';
 import { getNormalPath } from '@/utils/ruoyi';
-import useTagsViewStore from '@/store/modules/tagsView';
 import useSettingsStore from '@/store/modules/settings';
 import usePermissionStore from '@/store/modules/permission';
-import { RouteRecordRaw, TagView } from 'vue-router';
+import useTagsViewStore from '@/store/modules/tagsView';
+import { RouteRecordRaw, RouteLocationNormalized } from 'vue-router';
 
 const visible = ref(false);
 const top = ref(0);
 const left = ref(0);
-const selectedTag = ref<TagView>({});
-const affixTags = ref<TagView[]>([]);
+const selectedTag = ref<RouteLocationNormalized>();
+const affixTags = ref<RouteLocationNormalized[]>([]);
 const scrollPaneRef = ref<InstanceType<typeof ScrollPane>>();
 
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 const route = useRoute();
 const router = useRouter();
 
-const visitedViews = computed(() => useTagsViewStore().visitedViews);
-const routes = computed(() => usePermissionStore().routes);
+const visitedViews = computed(() => useTagsViewStore().getVisitedViews());
+const routes = computed(() => usePermissionStore().getRoutes());
 const theme = computed(() => useSettingsStore().theme);
 
 watch(route, () => {
@@ -64,18 +64,18 @@
   }
 });
 
-const isActive = (r: TagView): boolean => {
+const isActive = (r: RouteLocationNormalized): boolean => {
   return r.path === route.path;
 };
-const activeStyle = (tag: TagView) => {
+const activeStyle = (tag: RouteLocationNormalized) => {
   if (!isActive(tag)) return {};
   return {
     'background-color': theme.value,
     'border-color': theme.value
   };
 };
-const isAffix = (tag: TagView) => {
-  return tag.meta && tag.meta.affix;
+const isAffix = (tag: RouteLocationNormalized) => {
+  return tag?.meta && tag?.meta?.affix;
 };
 const isFirstView = () => {
   try {
@@ -92,12 +92,17 @@
   }
 };
 const filterAffixTags = (routes: RouteRecordRaw[], basePath = '') => {
-  let tags: TagView[] = [];
+  let tags: RouteLocationNormalized[] = [];
 
   routes.forEach((route) => {
     if (route.meta && route.meta.affix) {
       const tagPath = getNormalPath(basePath + '/' + route.path);
       tags.push({
+        hash: '',
+        matched: [],
+        params: undefined,
+        query: undefined,
+        redirectedFrom: undefined,
         fullPath: tagPath,
         path: tagPath,
         name: route.name as string,
@@ -114,7 +119,7 @@
   return tags;
 };
 const initTags = () => {
-  const res = filterAffixTags(routes.value as any);
+  const res = filterAffixTags(routes.value);
   affixTags.value = res;
   for (const tag of res) {
     // Must have tag name
@@ -143,19 +148,19 @@
         scrollPaneRef.value?.moveToTarget(r);
         // when query is different then update
         if (r.fullPath !== route.fullPath) {
-          useTagsViewStore().updateVisitedView(route as any);
+          useTagsViewStore().updateVisitedView(route);
         }
       }
     }
   });
 };
-const refreshSelectedTag = (view: TagView) => {
+const refreshSelectedTag = (view: RouteLocationNormalized) => {
   proxy?.$tab.refreshPage(view);
   if (route.meta.link) {
-    useTagsViewStore().delIframeView(route as any);
+    useTagsViewStore().delIframeView(route);
   }
 };
-const closeSelectedTag = (view: TagView) => {
+const closeSelectedTag = (view: RouteLocationNormalized) => {
   proxy?.$tab.closePage(view).then(({ visitedViews }: any) => {
     if (isActive(view)) {
       toLastView(visitedViews, view);
@@ -163,15 +168,15 @@
   });
 };
 const closeRightTags = () => {
-  proxy?.$tab.closeRightPage(selectedTag.value).then((visitedViews: TagView[]) => {
-    if (!visitedViews.find((i: TagView) => i.fullPath === route.fullPath)) {
+  proxy?.$tab.closeRightPage(selectedTag.value).then((visitedViews: RouteLocationNormalized[]) => {
+    if (!visitedViews.find((i: RouteLocationNormalized) => i.fullPath === route.fullPath)) {
       toLastView(visitedViews);
     }
   });
 };
 const closeLeftTags = () => {
-  proxy?.$tab.closeLeftPage(selectedTag.value).then((visitedViews: TagView[]) => {
-    if (!visitedViews.find((i: TagView) => i.fullPath === route.fullPath)) {
+  proxy?.$tab.closeLeftPage(selectedTag.value).then((visitedViews: RouteLocationNormalized[]) => {
+    if (!visitedViews.find((i: RouteLocationNormalized) => i.fullPath === route.fullPath)) {
       toLastView(visitedViews);
     }
   });
@@ -182,7 +187,7 @@
     moveToCurrentTag();
   });
 };
-const closeAllTags = (view: TagView) => {
+const closeAllTags = (view: RouteLocationNormalized) => {
   proxy?.$tab.closeAllPage().then(({ visitedViews }) => {
     if (affixTags.value.some((tag) => tag.path === route.path)) {
       return;
@@ -190,7 +195,7 @@
     toLastView(visitedViews, view);
   });
 };
-const toLastView = (visitedViews: TagView[], view?: TagView) => {
+const toLastView = (visitedViews: RouteLocationNormalized[], view?: RouteLocationNormalized) => {
   const latestView = visitedViews.slice(-1)[0];
   if (latestView) {
     router.push(latestView.fullPath as string);
@@ -205,7 +210,7 @@
     }
   }
 };
-const openMenu = (tag: TagView, e: MouseEvent) => {
+const openMenu = (tag: RouteLocationNormalized, e: MouseEvent) => {
   const menuMinWidth = 105;
   const offsetLeft = proxy?.$el.getBoundingClientRect().left; // container margin left
   const offsetWidth = proxy?.$el.offsetWidth; // container width

--
Gitblit v1.9.3