瀏覽代碼

修改bug

Alex 10 月之前
父節點
當前提交
58a94bdad4

+ 52 - 34
App.vue

@@ -1,39 +1,57 @@
 <script setup>
-	import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
-	import {
-		store
-	} from '@/store/index.js'
-	onLaunch(() => {
-		console.log('App Launch')
-		// 尝试去获取本地的 token 和用户信息,填充到 store 中
-		if(!store.token) {
-			let token = uni.getStorageSync('token')
-			if(token) {
-				store.setToken(token)
-				let userInfo = uni.getStorageSync('userInfo')
-				if(userInfo) {
-					if(userInfo.userId) {
-						store.setUserInfo(userInfo)
-					}
-				}
-			}
-		}
-	})
-	onShow(() => {
-		console.log('App Show');
-	})
-	onHide(() => {
-		console.log('App Hide');
-	})
+import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
+import {
+    store
+} from '@/store/index.js'
+import { useGlobalEventRemove, useInit } from '@/utils/useBarcodeModule.js'
+import { useRouteMonitor } from '@/utils/useRouteMonitor.js'
+
+onLaunch(() => {
+    console.log('App Launch')
+    // 尝试去获取本地的 token 和用户信息,填充到 store 中
+    if (!store.token) {
+        let token = uni.getStorageSync('token')
+        if (token) {
+            store.setToken(token)
+            let userInfo = uni.getStorageSync('userInfo')
+            if (userInfo) {
+                if (userInfo.userId) {
+                    store.setUserInfo(userInfo)
+                }
+            }
+        }
+    }
+    // #ifdef APP-PLUS
+    // 初始化扫码模块
+    useInit()
+    // #endif
+})
+onShow(() => {
+    console.log('App Show');
+    // #ifdef APP-PLUS
+    // 页面显示时重新添加全局监听
+    useRouteMonitor((url, from) => {
+        console.log('onShow', url, from)
+        // #ifdef APP-PLUS
+        // 页面隐藏时移除全局监听
+        useGlobalEventRemove()
+        // #endif
+    })
+    // #endif
+})
+onHide(() => {
+    console.log('App Hide');
+})
 </script>
 
 <style lang="scss">
-	@import "@/uni_modules/uview-plus/index.scss";
-	@import "@/static/css/mystyle.css";
-	@import '@/static/css/common.scss';
-	/*每个页面公共css */
-	page{
-		background: #F5F6FA;
-		height: 100%;
-	}
+@import "@/uni_modules/uview-plus/index.scss";
+@import "@/static/css/mystyle.css";
+@import '@/static/css/common.scss';
+
+/*每个页面公共css */
+page {
+    background: #F5F6FA;
+    height: 100%;
+}
 </style>

+ 12 - 6
pages/index/index.vue

@@ -263,24 +263,30 @@ const handleNavigation = (path) => {
     }
 
     .grid-container {
-        display: grid;
-        grid-template-columns: repeat(2, 1fr);
+        display: flex;
+        flex-wrap: wrap;
         gap: 20rpx;
         padding: 10rpx;
 
         .grid-item {
+            flex: 0 0 calc(50% - 10rpx);
             min-height: 148rpx;
             display: flex;
             align-items: center;
             justify-content: center;
-			text-align: center;
-			padding: 20rpx 30rpx;
-			line-height: 60rpx;
+            text-align: center;
+            padding: 20rpx 30rpx;
+            line-height: 60rpx;
             font-size: 50rpx;
             border-radius: 12rpx;
             color: #ffffff;
             transition: all 0.3s;
-			white-space: pre-wrap;
+            white-space: pre-wrap;
+            box-sizing: border-box;
+
+            &[style*="grid-column: span 2"] {
+                flex: 0 0 100%;
+            }
 
             &.primary {
                 background: linear-gradient(135deg, #4cd964, #3ac555);

+ 140 - 60
unpackage/dist/dev/app-plus/app-service.js

@@ -25822,53 +25822,54 @@ This will fail in production.`);
       const ttsModule2 = vue.ref(null);
       const searchText = vue.ref("");
       const locationInfo = vue.ref({
-        location: "K01-01-1A",
-        logisticsNo: "DPK20232154221",
-        orderNo: "7516531",
-        goodsCount: "10",
+        location: "",
+        logisticsNo: "",
+        orderNo: "",
+        goodsCount: "",
         remark: ""
       });
-      const badList = vue.ref([
-        {
-          image: "https://img20.360buyimg.com/da/jfs/t1/141592/25/8861/261559/5f68d8c1E33ed78ab/698ad655bfcfbaed.png",
-          title: "公文写作教程",
-          isbn: "978704051555",
-          price: 49.5,
-          discount: 0.85,
-          quantity: 5,
-          set: "不是",
-          estimate: 4.11,
-          review: 0,
-          good: 0,
-          average: 0,
-          bad: 1,
-          reason: "明显泛黄水印/发霉/明显异味"
-        },
-        {
-          image: "https://img20.360buyimg.com/da/jfs/t1/141592/25/8861/261559/5f68d8c1E33ed78ab/698ad655bfcfbaed.png",
-          title: "公文写作教程",
-          isbn: "978704051555",
-          price: 49.5,
-          discount: 0.85,
-          quantity: 5,
-          set: "不是",
-          estimate: 4.11,
-          review: 0,
-          good: 0,
-          average: 0,
-          bad: 1,
-          reason: "明显泛黄水印/发霉/明显异味"
+      const badList = vue.ref([]);
+      onLoad((options) => {
+        if (options.searchText) {
+          searchText.value = options.searchText;
+          onSearch();
         }
-      ]);
-      vue.onMounted(() => {
         ttsModule2.value = new VolumeTTS();
       });
-      const onSearch = () => {
+      const getSearchType = (text) => {
+        return /^[0-9]+$/.test(text) ? 1 : 2;
+      };
+      const onSearch = async () => {
+        if (!searchText.value)
+          return;
+        try {
+          const searchType = getSearchType(searchText.value);
+          const { data } = await uni.$u.http.post("/app/stock/findOrderOutStock", {
+            search: searchText.value,
+            searchType
+          });
+          if (data) {
+            locationInfo.value = {
+              location: data.location || "",
+              logisticsNo: data.logisticsNo || "",
+              orderNo: data.orderNo || "",
+              goodsCount: data.goodsCount || "",
+              remark: data.remark || ""
+            };
+            badList.value = data.badList || [];
+          }
+        } catch (error2) {
+          uni.showToast({
+            title: "获取数据失败",
+            icon: "none"
+          });
+        }
       };
       const openScan = () => {
         uni.scanCode({
           success: (res2) => {
             searchText.value = res2.result;
+            onSearch();
           },
           fail: (err) => {
             uni.showToast({
@@ -25882,13 +25883,34 @@ This will fail in production.`);
         uni.showModal({
           title: "确认提示",
           content: "是否确认出库?",
-          success: (res2) => {
+          success: async (res2) => {
             if (res2.confirm) {
-              uni.showToast({
-                title: "出库成功",
-                icon: "success"
-              });
-              ttsModule2.value.speak("出库成功");
+              try {
+                await uni.$u.http.post("/app/stock/outStock", {
+                  orderId: locationInfo.value.orderNo,
+                  positionCode: locationInfo.value.location,
+                  outputRemark: locationInfo.value.remark
+                });
+                uni.showToast({
+                  title: "出库成功",
+                  icon: "success"
+                });
+                ttsModule2.value.speak("出库成功");
+                searchText.value = "";
+                locationInfo.value = {
+                  location: "",
+                  logisticsNo: "",
+                  orderNo: "",
+                  goodsCount: "",
+                  remark: ""
+                };
+                badList.value = [];
+              } catch (error2) {
+                uni.showToast({
+                  title: "出库失败",
+                  icon: "none"
+                });
+              }
             }
           }
         });
@@ -25908,8 +25930,10 @@ This will fail in production.`);
         currentEditIndex.value = -1;
         currentRemark.value = "";
       };
-      const __returned__ = { ttsModule: ttsModule2, searchText, locationInfo, badList, onSearch, openScan, onConfirm, remarkVisible, currentRemark, currentEditIndex, openRemarkDialog, handleRemarkConfirm, ref: vue.ref, onMounted: vue.onMounted, BadOutCard, RemarkDialog, get VolumeTTS() {
+      const __returned__ = { ttsModule: ttsModule2, searchText, locationInfo, badList, getSearchType, onSearch, openScan, onConfirm, remarkVisible, currentRemark, currentEditIndex, openRemarkDialog, handleRemarkConfirm, ref: vue.ref, onMounted: vue.onMounted, BadOutCard, RemarkDialog, get VolumeTTS() {
         return VolumeTTS;
+      }, get onLoad() {
+        return onLoad;
       } };
       Object.defineProperty(__returned__, "__isScriptSetup", { enumerable: false, value: true });
       return __returned__;
@@ -30498,12 +30522,70 @@ This will fail in production.`);
   __definePage("pages/order/stat/pending-audit", PagesOrderStatPendingAudit);
   __definePage("pages/order/stat/pending-payment", PagesOrderStatPendingPayment);
   __definePage("pages/order/stat/receive-stat", PagesOrderStatReceiveStat);
+  function useInit() {
+    var barcodeModel = requireNativePlugin("iData-BarcodePlugin-BarcodeModule");
+    barcodeModel.initScan((ret) => {
+      formatAppLog("log", "at utils/useBarcodeModule.js:9", "初始化扫描", ret);
+    });
+  }
+  function useGlobalEvent(onChange) {
+    var globalEvent = requireNativePlugin("globalEvent");
+    globalEvent.addEventListener("iDataBarcodeEvent", function(e) {
+      onChange && onChange(e);
+    });
+  }
+  function useGlobalEventRemove() {
+    var globalEvent = requireNativePlugin("globalEvent");
+    globalEvent.removeEventListener("iDataBarcodeEvent");
+  }
+  function useRouteMonitor(onChange) {
+    uni.addInterceptor("navigateTo", {
+      invoke(e) {
+        var _a;
+        const pages2 = getCurrentPages();
+        const from = ((_a = pages2[pages2.length - 1]) == null ? void 0 : _a.route) || "";
+        onChange && onChange(e.url, from);
+        formatAppLog("log", "at utils/useRouteMonitor.js:18", "navigateTo", e.url, from);
+        return e;
+      }
+    });
+    uni.addInterceptor("redirectTo", {
+      invoke(e) {
+        var _a;
+        const pages2 = getCurrentPages();
+        const from = ((_a = pages2[pages2.length - 1]) == null ? void 0 : _a.route) || "";
+        onChange && onChange(e.url, from);
+        formatAppLog("log", "at utils/useRouteMonitor.js:28", "redirectTo", e.url, from);
+        return e;
+      }
+    });
+    uni.addInterceptor("reLaunch", {
+      invoke(e) {
+        var _a;
+        const pages2 = getCurrentPages();
+        const from = ((_a = pages2[pages2.length - 1]) == null ? void 0 : _a.route) || "";
+        onChange && onChange(e.url, from);
+        formatAppLog("log", "at utils/useRouteMonitor.js:38", "reLaunch", e.url, from);
+        return e;
+      }
+    });
+    uni.addInterceptor("switchTab", {
+      invoke(e) {
+        var _a;
+        const pages2 = getCurrentPages();
+        const from = ((_a = pages2[pages2.length - 1]) == null ? void 0 : _a.route) || "";
+        onChange && onChange(e.url, from);
+        formatAppLog("log", "at utils/useRouteMonitor.js:48", "switchTab", e.url, from);
+        return e;
+      }
+    });
+  }
   const _sfc_main = {
     __name: "App",
     setup(__props, { expose: __expose }) {
       __expose();
       onLaunch(() => {
-        formatAppLog("log", "at App.vue:7", "App Launch");
+        formatAppLog("log", "at App.vue:10", "App Launch");
         if (!store.token) {
           let token = uni.getStorageSync("token");
           if (token) {
@@ -30516,12 +30598,17 @@ This will fail in production.`);
             }
           }
         }
+        useInit();
       });
       onShow(() => {
-        formatAppLog("log", "at App.vue:23", "App Show");
+        formatAppLog("log", "at App.vue:30", "App Show");
+        useRouteMonitor((url2, from) => {
+          formatAppLog("log", "at App.vue:34", "onShow", url2, from);
+          useGlobalEventRemove();
+        });
       });
       onHide(() => {
-        formatAppLog("log", "at App.vue:26", "App Hide");
+        formatAppLog("log", "at App.vue:43", "App Hide");
       });
       const __returned__ = { get onLaunch() {
         return onLaunch;
@@ -30531,6 +30618,12 @@ This will fail in production.`);
         return onHide;
       }, get store() {
         return store;
+      }, get useGlobalEventRemove() {
+        return useGlobalEventRemove;
+      }, get useInit() {
+        return useInit;
+      }, get useRouteMonitor() {
+        return useRouteMonitor;
       } };
       Object.defineProperty(__returned__, "__isScriptSetup", { enumerable: false, value: true });
       return __returned__;
@@ -32143,19 +32236,6 @@ This will fail in production.`);
       };
     }
   };
-  requireNativePlugin("modal");
-  function useInit() {
-    var barcodeModel = requireNativePlugin("iData-BarcodePlugin-BarcodeModule");
-    barcodeModel.initScan((ret) => {
-      formatAppLog("log", "at utils/useBarcodeModule.js:10", "初始化扫描", ret);
-    });
-  }
-  function useGlobalEvent(onChange) {
-    var globalEvent = requireNativePlugin("globalEvent");
-    globalEvent.addEventListener("iDataBarcodeEvent", function(e) {
-      onChange && onChange(e);
-    });
-  }
   let ttsModule = new VolumeTTS();
   useInit();
   uni.$u.ttsModule = ttsModule;

+ 7 - 2
unpackage/dist/dev/app-plus/pages/index/index.css

@@ -44,12 +44,13 @@
   margin-bottom: 0.625rem;
 }
 .section .grid-container[data-v-1cf27b2a] {
-  display: grid;
-  grid-template-columns: repeat(2, 1fr);
+  display: flex;
+  flex-wrap: wrap;
   gap: 0.625rem;
   padding: 0.3125rem;
 }
 .section .grid-container .grid-item[data-v-1cf27b2a] {
+  flex: 0 0 calc(50% - 0.3125rem);
   min-height: 4.625rem;
   display: flex;
   align-items: center;
@@ -62,6 +63,10 @@
   color: #ffffff;
   transition: all 0.3s;
   white-space: pre-wrap;
+  box-sizing: border-box;
+}
+.section .grid-container .grid-item[style*="grid-column: span 2"][data-v-1cf27b2a] {
+  flex: 0 0 100%;
 }
 .section .grid-container .grid-item.primary[data-v-1cf27b2a] {
   background: linear-gradient(135deg, #4cd964, #3ac555);

+ 6 - 1
utils/useBarcodeModule.js

@@ -1,4 +1,3 @@
-const modal = uni.requireNativePlugin('modal');
 /**
  * 初始化idata扫描模块
  */
@@ -23,4 +22,10 @@ export function useGlobalEvent(onChange) {
 		onChange && onChange(e)
 		//条码结果示例:{"barcode","条码数据"}
 	});
+}
+
+//全局卸载监听事件
+export function useGlobalEventRemove() {
+	var globalEvent = uni.requireNativePlugin('globalEvent');
+	globalEvent.removeEventListener('iDataBarcodeEvent');
 }

+ 52 - 0
utils/useRouteMonitor.js

@@ -0,0 +1,52 @@
+/**
+ * 路由监听工具
+ */
+
+/**
+ * 监听路由变化
+ * @param {Function} onChange 路由变化回调函数,参数为 (to, from)
+ * @returns {void}
+ */
+export function useRouteMonitor(onChange) {
+    // 添加路由拦截器
+    uni.addInterceptor('navigateTo', {
+        invoke(e) {
+            // 获取当前页面路由
+            const pages = getCurrentPages()
+            const from = pages[pages.length - 1]?.route || ''
+            onChange && onChange(e.url, from)
+            console.log('navigateTo', e.url, from)
+            return e
+        }
+    })
+
+    uni.addInterceptor('redirectTo', {
+        invoke(e) {
+            const pages = getCurrentPages()
+            const from = pages[pages.length - 1]?.route || ''
+            onChange && onChange(e.url, from)
+            console.log('redirectTo', e.url, from)
+            return e
+        }
+    })
+
+    uni.addInterceptor('reLaunch', {
+        invoke(e) {
+            const pages = getCurrentPages()
+            const from = pages[pages.length - 1]?.route || ''
+            onChange && onChange(e.url, from)
+            console.log('reLaunch', e.url, from)
+            return e
+        }
+    })
+
+    uni.addInterceptor('switchTab', {
+        invoke(e) {
+            const pages = getCurrentPages()
+            const from = pages[pages.length - 1]?.route || ''
+            onChange && onChange(e.url, from)
+            console.log('switchTab', e.url, from)
+            return e
+        }
+    })
+}