王智慧 3 лет назад
Родитель
Сommit
1db44da2ee

+ 1 - 0
src/components/ShipInfo.vue

@@ -421,6 +421,7 @@ async function submit() {
     ...props.shipInfos[currentIndex.value],
     shipOwnerId: props.shipOwnerId,
   });
+  store.commit("removeAlive", "shipOwnerList");
   router.replace("/shipOwnerManage/shipOwnerList");
 }
 

+ 2 - 1
src/layout/AppMain.vue

@@ -1,12 +1,13 @@
 <template>
   <router-view v-slot="{ Component, route }">
-    <keep-alive :include="['shipList', 'shipOwnerList']">
+    <keep-alive :include="store.state.keepAliveList">
       <component :is="Component" :key="route.path" />
     </keep-alive>
   </router-view>
 </template>
 <script setup>
 import { useRoute } from "vue-router";
+import store from "../store/index";
 const route = useRoute();
 </script>
 

+ 1 - 0
src/layout/Aside.vue

@@ -31,6 +31,7 @@ import store from "../store";
 
 let defaultActive = ref();
 function changeIndex(path) {
+  store.commit("clearAlive");
   defaultActive.value = path;
 }
 let menu = [

+ 16 - 0
src/store/index.js

@@ -17,6 +17,7 @@ const store = createStore({
     addCertsUrl,
     updateCertsUrl,
     versions: [],
+    keepAliveList: ["shipList", "shipOwnerList"],
   },
   mutations: {
     changefirstTitle(state, text) {
@@ -34,6 +35,21 @@ const store = createStore({
     setVersions(state, data) {
       state.versions = data;
     },
+    addAlive(state, data) {
+      let arr = state.keepAliveList;
+      arr.push(data);
+      state.keepAliveList = [...new Set(arr)];
+    },
+    removeAlive(state, data) {
+      console.log(data);
+      let arr = state.keepAliveList.filter((item) => {
+        return item != data;
+      });
+      state.keepAliveList = arr;
+    },
+    clearAlive(state, data) {
+      state.keepAliveList = [];
+    },
   },
 });
 

+ 1 - 0
src/views/shipManage/shipList.vue

@@ -149,6 +149,7 @@ async function getShipList(page) {
 }
 
 async function shipDetail(shipCode) {
+  store.commit("addAlive", "shipList");
   router.push({
     path: "/shipManage/shipDetail",
     query: {

+ 1 - 0
src/views/shipOwnerManage/shipOwnerDetail.vue

@@ -261,6 +261,7 @@ async function addShipOwner() {
         addShip();
       })
       .catch(() => {
+        store.commit("removeAlive", "shipOwnerList");
         router.push("/shipOwnerManage/shipOwnerList");
       });
   }

+ 1 - 0
src/views/shipOwnerManage/shipOwnerList.vue

@@ -202,6 +202,7 @@ async function getShipOwnerList(page) {
 }
 
 async function shipOwnerDetail(shipOwnerId) {
+  store.commit("addAlive", "shipOwnerList");
   router.push({
     path: "/shipOwnerManage/shipOwnerDetail",
     query: {