Ver Fonte

编辑电签页返回留在当前页

duy há 5 dias atrás
pai
commit
8d5a1e325a
2 ficheiros alterados com 94 adições e 25 exclusões
  1. 67 16
      src/views/certificate/list.vue
  2. 27 9
      src/views/certificate/lists/addList.vue

+ 67 - 16
src/views/certificate/list.vue

@@ -102,7 +102,7 @@
       :total="total"
       @size-change="handleSizeChange"
       @current-change="handleCurrentChange"
-      :current-page.sync="pageindex"
+      :current-page="pageindex"
       :page-size="pagesize"
     >
     </el-pagination>
@@ -130,6 +130,34 @@ export default {
       certificateTypeValue: null, //证书类型
     };
   },
+  watch: {
+    // 监听路由变化,当从其他页面返回时更新状态
+    '$route.query': {
+      immediate: true,
+      handler(newQuery) {
+        if (newQuery.pageindex) {
+          this.pageindex = Number(newQuery.pageindex);
+        }
+        if (newQuery.value) {
+          this.value = newQuery.value;
+        }
+    
+        if (newQuery.pagesize) {
+          this.pagesize = Number(newQuery.pagesize);
+        }
+      }
+    },
+    searchinput: {
+      immediate: true,
+      handler(newQuery) {
+        if (newQuery) {
+          this.pageindex = 1;
+          this.pagesize=20
+
+        }
+      }
+    }
+  },
   methods: {
     //#region 页码
     handleSizeChange(val) {
@@ -141,25 +169,38 @@ export default {
       this.listpage();
     },
     typeChange() {
+      this.pageindex = 1;
+      this.pagesize = 20;
       this.listpage();
     },
     //#endregion
 
     //#region 头接口
+   // 修改pushRouter方法,传递完整的查询状态
     pushRouter(id) {
       this.$router.push({
         path: "/certificate/list/addList",
         query: {
           id,
+          // 传递项目ID
           value: this.value,
-        },
+          // 传递证书类型
+          certificateTypeValue: this.certificateTypeValue,
+          // 传递搜索关键词
+          searchinput: this.searchinput,
+          // 传递当前页码
+          pageindex: this.pageindex,
+          // 传递每页条数
+          pagesize: this.pagesize
+        }
       });
-      console.log(this.value, "value");
     },
     //#endregion
 
     //#region 列表接口
     projectChange() {
+           this.pageindex = 1;
+      this.pagesize = 20;
       //下拉框change事件
       this.listpage();
     },
@@ -196,19 +237,29 @@ export default {
         this.listpage();
       }
     },
-    async queryProjectList() {
-      //获取所有项目
-      const { data: res } = await queryProjectList();
-      if (res.code == 200) {
-        this.options = res.data;
-        if (this.$route.query.value) {
-          this.value = this.$route.query.value;
-        } else {
-          this.value = this.value = this.options[0].id;
-        }
-        this.listpage();
-      }
-    },
+   async queryProjectList() {
+  const { data: res } = await queryProjectList();
+  if (res.code == 200) {
+    this.options = res.data;
+    // 处理路由参数
+    if (this.$route.query.value) {
+      this.value = this.$route.query.value;
+      // 确保页码是数字类型
+      this.pageindex = Number(this.$route.query.pageindex) || 1;
+      this.pagesize = Number(this.$route.query.pagesize) || 20;
+      this.certificateTypeValue = this.$route.query.certificateTypeValue 
+        ? Number(this.$route.query.certificateTypeValue) 
+        : null;
+      this.searchinput = this.$route.query.searchinput || '';
+    } else {
+      this.value = this.options[0].id || '';
+    }
+    this.$nextTick(() => {
+      this.listpage();
+    });
+  }
+},
+
     async listpage() {
       //分页获取证书列表数据
       const { data: res } = await listpage({

+ 27 - 9
src/views/certificate/lists/addList.vue

@@ -360,9 +360,19 @@ export default {
 
     },
     //#region
-    cancel () {//取消按钮
-      this.$router.push('/certificate/list')
-    },
+   cancel() {
+    const { value, certificateTypeValue, searchinput, pageindex, pagesize } = this.$route.query;
+    this.$router.push({
+      path: '/certificate/list',
+      query: {
+        value,
+        certificateTypeValue,
+        searchinput,
+        pageindex,
+        pagesize
+      }
+    });
+  },
     savess () {//保存按钮
       this.$refs.form.validate(async valid => {
         if (valid) {
@@ -544,12 +554,16 @@ export default {
           message: '新增电签成功!'
         })
         // this.$router.push('/certificate/list')
-        this.$router.push({
+       this.$router.push({
           path: '/certificate/list',
           query: {
-            value:this.$route.query.value
+            value: this.$route.query.value,
+            certificateTypeValue: this.$route.query.certificateTypeValue,
+            searchinput: this.$route.query.searchinput,
+            pageindex: this.$route.query.pageindex,
+            pagesize: this.$route.query.pagesize
           }
-        })
+        });
       }
     },
     async findUserByName () { //关联用户
@@ -606,12 +620,16 @@ export default {
           message: '修改电签成功!'
         })
         // this.$router.push('/certificate/list')
-        this.$router.push({
+         this.$router.push({
           path: '/certificate/list',
           query: {
-            value:this.$route.query.value
+            value: this.$route.query.value,
+            certificateTypeValue: this.$route.query.certificateTypeValue,
+            searchinput: this.$route.query.searchinput,
+            pageindex: this.$route.query.pageindex,
+            pagesize: this.$route.query.pagesize
           }
-        })
+        });
       }
     },
     //#endregion