From aca7aa9ce32acc4c8795342f945b027d3bc9f62a Mon Sep 17 00:00:00 2001 From: 曹睿 <360930172@qq.com> Date: 星期二, 10 六月 2025 17:37:34 +0800 Subject: [PATCH] feat: 添加时效报工,修复扫码内存泄漏 --- src/pages/production/index.vue | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 43 insertions(+), 1 deletions(-) diff --git a/src/pages/production/index.vue b/src/pages/production/index.vue index a55a50a..017062f 100644 --- a/src/pages/production/index.vue +++ b/src/pages/production/index.vue @@ -5,7 +5,7 @@ <wd-search placeholder-left hide-cancel></wd-search> </wd-col> <wd-col :span="3"> - <view class="scan_box"> + <view class="scan_box" @click="openScan"> <wd-icon name="scan" size="24px" color="#0D867F"></wd-icon> </view> </wd-col> @@ -28,6 +28,8 @@ /> </wd-tab> </wd-tabs> + <Scan ref="scanRef" emitName="scan" /> + <wd-toast /> </view> </template> @@ -35,6 +37,15 @@ import ManageApi from "@/api/product/manage"; import { ref } from "vue"; import ProductList from "./list/index.vue"; +import Scan from "@/components/scan/index.vue"; +import { useUserStore } from "@/store/modules/user"; +import reportApi from "@/api/work/report"; +import { useToast } from "wot-design-uni"; + +const scanRef = ref(); +const userStore = useUserStore(); +const userInfo: any = computed(() => userStore.userInfo); +const toast = useToast(); const waitRef = ref(); const alreadyRef = ref(); @@ -51,6 +62,37 @@ const changeAlready = (num: number) => { total.already = num; }; + +const openScan = () => { + scanRef.value.triggerScan(); +}; + +const getScanCode = async () => { + console.log("鐢熶骇绠$悊鎵爜鍥炶皟"); + const { code } = await reportApi.sendWorkTime({ + userName: userInfo.value.userName, + }); + if (code == 200) { + toast.success("鎵爜鎴愬姛"); + } +}; + +// 纭繚鍏堢Щ闄ゅ啀娣诲姞鐩戝惉 +const setupScanListener = () => { + uni.$off("scan", getScanCode); // 鍏堢Щ闄ゆ棫鐨� + uni.$on("scan", getScanCode); // 鍐嶆坊鍔犳柊鐨� +}; + +onMounted(() => { + // 寮�鍚箍鎾洃鍚簨浠� + setupScanListener(); + console.log("鏄剧ず1"); +}); +onUnmounted(() => { + // 寮�鍚箍鎾洃鍚簨浠� + uni.$off("scan", getScanCode); + console.log("绂诲紑1"); +}); </script> <style lang="scss" scoped> -- Gitblit v1.9.3