Prechádzať zdrojové kódy

fix: 修复schedule页切换项目跳转问题

Jinyao 5 rokov pred
rodič
commit
b6ef5df5e8

+ 1 - 5
src/composable/useProject.ts

@@ -12,11 +12,7 @@ export const useProjectList = () => {
 
   const handleProjectChange = (projectId: number) => {
     WorkspaceDispatcher.changeProject(projectId);
-    if (router.currentRoute.value.path.includes('schedule')) {
-      setTimeout(() => router.go(0), 200);
-    } else {
-      router.push(`/project/${projectId}/schedule`);
-    }
+    router.push(`/project/${projectId}/schedule`);
   };
   return {
     projectList,

+ 23 - 7
src/views/Project/Schedule.vue

@@ -36,7 +36,13 @@
       <i class="el-icon-question"></i>
     </el-tooltip>
   </el-row>
-  <Tree :data="requirements" v-loading="loading" @change="handleTreeChange" @nodeClick="handleNodeClick" ref="tree"></Tree>
+  <Tree
+    :data="requirements"
+    v-loading="loading"
+    @change="handleTreeChange"
+    @nodeClick="handleNodeClick"
+    ref="tree"
+  ></Tree>
   <RequirementDrawer
     ref="drawer"
     v-bind="requirementInDrawer"
@@ -74,16 +80,26 @@ export default {
       projectMembers: [],
     };
   },
-  async mounted() {
-    this.projectMembers = this.$store.state.workspace.currentProjectMembers;
-    await this.getTreeData();
-    this.drawChart();
+  computed: {
+    projectId() {
+      return this.$route.params.projectId;
+    },
+  },
+  watch: {
+    $route: {
+      async handler() {
+        this.projectMembers = this.$store.state.workspace.currentProjectMembers;
+        await this.getTreeData();
+        this.drawChart();
+      },
+      immediate: true,
+    },
   },
   methods: {
     async getTreeData() {
       this.loading = true;
       try {
-        this.requirements = this.addChild2Node(await RequirementAPI.getTreeNodesByProjectId(this.$store.state.workspace.currentProjectId));
+        this.requirements = this.addChild2Node(await RequirementAPI.getTreeNodesByProjectId(this.projectId));
       } catch (e) {
         console.error(e);
       }
@@ -127,7 +143,7 @@ export default {
       this.requirementInDrawer = Array.prototype.find.call(this.requirements, (requirement) => requirement.id === id);
     },
     async drawChart() {
-      const bugList = await BugListAPI.getBugListByProjectId(this.$store.state.workspace.currentProjectId);
+      const bugList = await BugListAPI.getBugListByProjectId(this.projectId);
       const requirementsValuesMap = new Map();
       const requirementsValues = [];
       const bugListValuesMap = new Map();