Explorar o código

优化加载更多

liuyanpeng hai 6 meses
pai
achega
f351993000

+ 1 - 1
public/index.html

@@ -4,7 +4,7 @@
         <meta charset="UTF-8" />
         <meta http-equiv="X-UA-Compatible" content="IE=edge" />
         <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-        <title>WMS仓库管理系统</title>
+        <title>无人线边库</title>
         <!-- 本地 Font Awesome -->
         <link rel="stylesheet" href="./font-awesome.min.css" />
         <!-- 本地 Pacifico 字体 -->

+ 18 - 4
src/finishProduct/FinishProductOut.vue

@@ -242,9 +242,13 @@ const checkAndLoadMore = async () => {
     }
 };
 
+// 是否正在执行初次加载(防止重复请求)
+let isInitialLoading = false;
+
 // 加载更多数据
 const loadMore = async () => {
-    if (loadingMore.value || noMoreData.value || loading.value) return;
+    // 增加 isInitialLoading 检查,防止初次加载时触发 loadMore
+    if (loadingMore.value || noMoreData.value || loading.value || isInitialLoading) return;
     
     loadingMore.value = true;
     
@@ -346,18 +350,21 @@ const confirmOutbound = () => {
     showConfirmModal.value = true;
 };
 
+// 提交中状态(与列表加载分开管理)
+const submitting = ref(false);
+
 // 执行出库
 const executeOutbound = async () => {
     showConfirmModal.value = false;
     if (selectedProducts.value.length === 0) return;
 
-    loading.value = true;
+    submitting.value = true;
     try {
         const res = await generateStockOut(selectedProducts.value);
         if (res.errorCode === 0) {
             showNotify({ type: 'success', message: '出库成功' });
             selectedProducts.value = [];
-            getList(); // 重新加载列表
+            await getList(); // 重新加载列表
         } else {
             showNotify({ type: 'danger', message: res.errorMessage });
         }
@@ -365,15 +372,21 @@ const executeOutbound = async () => {
         console.log(error);
         showNotify({ type: 'danger', message: '出库失败' });
     } finally {
-        loading.value = false;
+        submitting.value = false;
     }
 };
 
 // 初次加载成品列表
 const getList = async () => {
+    // 防止重复调用
+    if (isInitialLoading) return;
+    isInitialLoading = true;
+    
     loading.value = true;
     currentStart.value = 0;
     noMoreData.value = false;
+    // 立即清空列表,防止数据重复
+    finishProductList.value = [];
     
     const params = {
         ...searchForm.value,
@@ -412,6 +425,7 @@ const getList = async () => {
         showNotify({ type: 'danger', message: '获取成品列表失败' });
     } finally {
         loading.value = false;
+        isInitialLoading = false;
     }
 };
 

+ 8 - 4
src/login/UserHome.vue

@@ -183,9 +183,10 @@ let infoTimer = null;
 
 // 从 localStorage 获取用户名和isOut状态
 onMounted(() => {
-    const storedUser = localStorage.getItem('username');
-    if (storedUser) {
-        username.value = storedUser;
+    const loginInfo = localStorage.getItem('#LoginInfo');
+    if (loginInfo) {
+        const loginInfoObj = JSON.parse(loginInfo);
+        username.value = loginInfoObj.userName;
     }
 
     // 读取isOut状态
@@ -1118,6 +1119,8 @@ const getInfo = async () => {
 
   .title {
     left: 50%;
+    top: 44%;
+    font-size: 48px !important;
   }
 
   .user-badge {
@@ -1211,7 +1214,8 @@ const getInfo = async () => {
   }
 
   .title {
-    font-size: 42px;
+    top: 44%;
+    font-size: 50px;
     letter-spacing: 10px;
   }
 

+ 22 - 7
src/stock/RegularRequisition.vue

@@ -274,9 +274,13 @@ const checkAndLoadMore = async () => {
     }
 };
 
+// 是否正在执行初次加载(防止重复请求)
+let isInitialLoading = false;
+
 // 加载更多数据
 const loadMore = async () => {
-    if (loadingMore.value || noMoreData.value || loading.value) return;
+    // 增加 isInitialLoading 检查,防止初次加载时触发 loadMore
+    if (loadingMore.value || noMoreData.value || loading.value || isInitialLoading) return;
     
     loadingMore.value = true;
     
@@ -319,9 +323,15 @@ const loadMore = async () => {
 
 // 初次加载物料数据
 const getStockRequisitionList = async () => {
+    // 防止重复调用
+    if (isInitialLoading) return;
+    isInitialLoading = true;
+    
     loading.value = true;
     currentStart.value = 0;
     noMoreData.value = false;
+    // 立即清空列表,防止数据重复
+    stockRequisitionList.value = [];
     
     const params = {
         inventoryName: inventoryName.value,
@@ -359,6 +369,7 @@ const getStockRequisitionList = async () => {
         console.error('查询常用物料API失败', error);
     } finally {
         loading.value = false;
+        isInitialLoading = false;
     }
 };
 
@@ -397,21 +408,24 @@ const handleReset = () => {
 };
 
 // 查询(重新搜索时重置列表)
-const getDatas = () => {
+const getDatas = async () => {
     // 滚动到顶部
     if (cardGridWrapper.value) {
         cardGridWrapper.value.scrollTop = 0;
     }
-    getStockRequisitionList();
+    await getStockRequisitionList();
 };
 
+// 提交中状态(与列表加载分开管理)
+const submitting = ref(false);
+
 // 加入领料车
 const submitStock = async () => {
     if (selectedIds.value.length == 0) {
         showNotify({ type: 'danger', message: '请至少选择一个物料' });
         return;
     }
-    loading.value = true;
+    submitting.value = true;
     const params = {
         inventoryIds: selectedIds.value,
     };
@@ -420,15 +434,16 @@ const submitStock = async () => {
         const res = await createStockOutPrepareLine(params);
         if (res.errorCode == 0) {
             selectedIds.value = [];
-            getDatas();
-            queryPickingCarCount();
             showNotify({ type: 'success', message: '已添加到领料车' });
+            // 先等待提交完成,再刷新列表
+            await getDatas();
+            queryPickingCarCount();
         }
     } catch (error) {
         console.error('添加领料车失败:', error);
         showNotify({ type: 'danger', message: '添加到领料车失败' });
     } finally {
-        loading.value = false;
+        submitting.value = false;
     }
 };
 

+ 23 - 9
src/stock/StockPickingCar.vue

@@ -311,9 +311,13 @@ const checkAndLoadMore = async () => {
     }
 };
 
+// 是否正在执行初次加载(防止重复请求)
+let isInitialLoading = false;
+
 // 加载更多数据
 const loadMore = async () => {
-    if (loadingMore.value || noMoreData.value || loading.value) return;
+    // 增加 isInitialLoading 检查,防止初次加载时触发 loadMore
+    if (loadingMore.value || noMoreData.value || loading.value || isInitialLoading) return;
     
     loadingMore.value = true;
     
@@ -361,9 +365,15 @@ const loadMore = async () => {
 
 // 初次加载物料数据
 const getPickerCarList = async () => {
+    // 防止重复调用
+    if (isInitialLoading) return;
+    isInitialLoading = true;
+    
     loading.value = true;
     currentStart.value = 0;
     noMoreData.value = false;
+    // 立即清空列表,防止数据重复
+    carList.value = [];
     
     const loginInfo = localStorage.getItem('#LoginInfo');
     if (loginInfo) {
@@ -408,6 +418,7 @@ const getPickerCarList = async () => {
         showNotify({ type: 'danger', message: '获取领料车列表API调用失败' });
     } finally {
         loading.value = false;
+        isInitialLoading = false;
     }
 };
 
@@ -439,9 +450,12 @@ const deleteStock = () => {
     deleteModalVisible.value = true;
 };
 
+// 提交/删除中状态(与列表加载分开管理)
+const submitting = ref(false);
+
 //  删除接口
 const deleteStockCarApi = async () => {
-    loading.value = true;
+    submitting.value = true;
     const params = {
         pickingCarIds: selectedIds.value,
     };
@@ -450,7 +464,7 @@ const deleteStockCarApi = async () => {
         if (res.errorCode == 0) {
             showNotify({ type: 'success', message: '删除成功' });
             selectedIds.value = [];
-            getDatas();
+            await getDatas();
         } else {
             showNotify({ type: 'danger', message: res.errorMessage });
         }
@@ -458,7 +472,7 @@ const deleteStockCarApi = async () => {
         console.log('删除领料车API调用失败', error);
         showNotify({ type: 'danger', message: '删除领料车API调用失败' });
     } finally {
-        loading.value = false;
+        submitting.value = false;
     }
 };
 // 获取仓库列表
@@ -502,12 +516,12 @@ const handleDeleteCancel = () => {
 };
 
 // 查询(重新搜索时重置列表)
-const getDatas = () => {
+const getDatas = async () => {
     // 滚动到顶部
     if (cardGridWrapper.value) {
         cardGridWrapper.value.scrollTop = 0;
     }
-    getPickerCarList();
+    await getPickerCarList();
 };
 
 // 领料
@@ -516,7 +530,7 @@ const submitStock = async () => {
         showNotify({ type: 'danger', message: '请至少选择一个工装设备' });
         return;
     }
-    loading.value = true;
+    submitting.value = true;
     const params = {
         pickingCarIds: selectedIds.value,
     };
@@ -527,7 +541,7 @@ const submitStock = async () => {
             // 提交成功后清除选择项
             selectedIds.value = [];
             // 刷新列表数据
-            getDatas();
+            await getDatas();
             confirmModalVisible.value = true;
         } else {
             showNotify({ type: 'danger', message: res.errorMessage });
@@ -536,7 +550,7 @@ const submitStock = async () => {
         console.log('生成领料单API调用失败', error);
         showNotify({ type: 'danger', message: '生成领料单API调用失败' });
     } finally {
-        loading.value = false;
+        submitting.value = false;
     }
 };
 onMounted(() => {

+ 22 - 7
src/stock/StockRequisition.vue

@@ -307,9 +307,13 @@ const checkAndLoadMore = async () => {
     }
 };
 
+// 是否正在执行初次加载(防止重复请求)
+let isInitialLoading = false;
+
 // 加载更多数据
 const loadMore = async () => {
-    if (loadingMore.value || noMoreData.value || loading.value) return;
+    // 增加 isInitialLoading 检查,防止初次加载时触发 loadMore
+    if (loadingMore.value || noMoreData.value || loading.value || isInitialLoading) return;
     
     loadingMore.value = true;
     
@@ -352,9 +356,15 @@ const loadMore = async () => {
 
 // 初次加载物料数据
 const getStockRequisitionList = async () => {
+    // 防止重复调用
+    if (isInitialLoading) return;
+    isInitialLoading = true;
+    
     loading.value = true;
     currentStart.value = 0;
     noMoreData.value = false;
+    // 立即清空列表,防止数据重复
+    stockRequisitionList.value = [];
     
     const params = {
         inventoryName: inventoryName.value,
@@ -392,6 +402,7 @@ const getStockRequisitionList = async () => {
         showNotify({ type: 'danger', message: '获取库存数据失败' });
     } finally {
         loading.value = false;
+        isInitialLoading = false;
     }
 };
 
@@ -430,21 +441,24 @@ const handleReset = () => {
 };
 
 // 查询(重新搜索时重置列表)
-const getDatas = () => {
+const getDatas = async () => {
     // 滚动到顶部
     if (cardGridWrapper.value) {
         cardGridWrapper.value.scrollTop = 0;
     }
-    getStockRequisitionList();
+    await getStockRequisitionList();
 };
 
+// 提交中状态(与列表加载分开管理)
+const submitting = ref(false);
+
 // 加入领料车
 const submitStock = async () => {
     if (selectedIds.value.length == 0) {
         showNotify({ type: 'danger', message: '请至少选择一个物料' });
         return;
     }
-    loading.value = true;
+    submitting.value = true;
     const params = {
         inventoryIds: selectedIds.value,
     };
@@ -453,15 +467,16 @@ const submitStock = async () => {
         const res = await createStockOutPrepareLine(params);
         if (res.errorCode == 0) {
             selectedIds.value = [];
-            getDatas();
-            queryPickingCarCount();
             showNotify({ type: 'success', message: '已添加到领料车' });
+            // 先等待提交完成,再刷新列表
+            await getDatas();
+            queryPickingCarCount();
         }
     } catch (error) {
         console.error('添加领料车失败:', error);
         showNotify({ type: 'danger', message: '添加到领料车失败' });
     } finally {
-        loading.value = false;
+        submitting.value = false;
     }
 };