瀏覽代碼

优化带条件的订单查询数据渲染一直loading的问题

cgp 1 天之前
父節點
當前提交
26fc9727a6
共有 1 個文件被更改,包括 39 次插入30 次删除
  1. 39 30
      src/views/his/storeOrder/order1.vue

+ 39 - 30
src/views/his/storeOrder/order1.vue

@@ -1367,38 +1367,47 @@ export default {
       }
       
       console.log('查询参数:', this.queryParams);
-      
-      listOrder(this.queryParams).then(response => {
-        this.orderList = response.rows;
-        this.total = response.total;
-        if(this.total>0){
-          this.payPriceTotal = response.payPriceTotal;
-          this.payMoneyTotal = response.payMoneyTotal;
-          this.payRemainTotal = response.payRemainTotal;
-          this.productInfo = response.productInfo;
-        } else {
-          this.payPriceTotal = "0"
-          this.payMoneyTotal = "0"
-          this.payRemainTotal = "0"
-          this.productInfo = response.productInfo;
-        }
 
-        this.SFDFopen = false;
+      listOrder(this.queryParams).then(
+        response => {
+          // 将数据处理放入 try-catch,防止因数据格式异常导致 .then 抛出错误
+          try {
+            // 安全赋值,确保即使字段缺失也有默认值
+            this.orderList = response.rows || [];
+            this.total = response.total || 0;
+            this.payPriceTotal = response.payPriceTotal || '0';
+            this.payMoneyTotal = response.payMoneyTotal || '0';
+            this.payRemainTotal = response.payRemainTotal || '0';
+            this.productInfo = response.productInfo || '';
+            this.SFDFopen = false;
 
-        // 如果有排序,显示排序结果提示
-        if (this.currentSort.prop) {
-          const fieldLabel = this.getSortLabel(this.currentSort.prop);
-          const orderLabel = this.currentSort.order === 'ascending' ? '升序' : '降序';
-          console.log(`数据已按${fieldLabel}${orderLabel}加载`);
-        }
-      }).catch(error => {
-        console.error('查询失败:', error);
-        this.loading = false;
-        this.$message.error('查询数据失败');
-      }).finally(() => {
-        //无论如何都会执行,确保 loading 关闭
-        this.loading = false;
-      });
+            // 如果有排序,显示提示(保持原有逻辑)
+            if (this.currentSort.prop) {
+              const fieldLabel = this.getSortLabel(this.currentSort.prop);
+              const orderLabel = this.currentSort.order === 'ascending' ? '升序' : '降序';
+              console.log(`数据已按${fieldLabel}${orderLabel}加载`);
+            }
+          } catch (e) {
+            console.error('数据处理异常:', e);
+            this.$message.error('数据解析失败,请稍后重试');
+            // 清空表格数据避免渲染异常
+            this.orderList = [];
+            this.total = 0;
+          }
+        })
+        .catch(error => {
+          console.error('查询失败:', error);
+          this.$message.error('查询数据失败');
+          // 请求失败时也清空表格
+          this.orderList = [];
+          this.total = 0;
+        })
+        .finally(() => {
+          // 确保无论如何 loading 都会关闭
+          this.loading = false;
+          // 强制触发一次视图更新(可选)
+          this.$nextTick(() => {});
+        });
     },
     // 处理键盘按下事件
     handleKeyDown(event) {