快乐的昕的电脑
2025-11-19 f13213d0a2d44443790e648896303ed93dc1bacd
components/WorkOrderPrint.vue
@@ -238,9 +238,10 @@
            printNum: 1, reportingList: [], printLoading: false, customAmount: '',
            isGeneratingBarcode: false, lastGenerateTime: 0, generateRequestId: null,
            nowTimeTimer: null, nowTime: '',
            userSearch: '',
                userSearch: '',
                refreshTimer: null, // 新增:自动刷新定时器
            /* 新增:历史报工记录数组 */
            reportingHistory: []
                reportingHistory: []
         }
      },
      computed: {
@@ -278,10 +279,35 @@
         this.getXS0101();
         this.updateNowTime();
         // 秒级刷新;如不需动态跳秒可改为 60000
         this.nowTimeTimer = setInterval(this.updateNowTime, 1000);
            this.nowTimeTimer = setInterval(this.updateNowTime, 1000);
            // 新增:每分钟自动刷新数据(60000毫秒 = 1分钟)
            this.startAutoRefresh();
      },
      beforeDestroy() { if (this.nowTimeTimer) clearInterval(this.nowTimeTimer); },
      methods: {
        beforeDestroy() {
            if (this.nowTimeTimer) clearInterval(this.nowTimeTimer);
            // 新增:清理自动刷新定时器
            this.stopAutoRefresh();
        },
        methods: {
            // 新增:开始自动刷新
            startAutoRefresh() {
                // 先清除可能存在的旧定时器
                this.stopAutoRefresh();
                // 设置新的定时器,每分钟执行一次
                this.refreshTimer = setInterval(() => {
                    console.log('自动刷新数据...');
                    this.refresh();
                }, 60000); // 60000毫秒 = 1分钟
            },
            // 新增:停止自动刷新
            stopAutoRefresh() {
                if (this.refreshTimer) {
                    clearInterval(this.refreshTimer);
                    this.refreshTimer = null;
                }
            },
         formatUser(u) {
            if (!u) return '';
            const segs = u.split(':');
@@ -303,13 +329,24 @@
            this.isGeneratingBarcode = false; this.generateRequestId = null; this.lastGenerateTime = 0;
            this.$showMessage("已重置条码生成状态");
         },
         refresh() {
            this.$sendPostRequest({
               url: "http://192.168.0.94:9095/Numerical/RefreshDevBycl",
               data: { machineNo: this.order.machineNo },
               contentType: "application/json"
            }).then(r => { r.code == 200 ? this.fetchData(true) : this.$showMessage("同步失败"); });
         },
            // 修改:在手动刷新时也重置自动刷新计时器
            refresh() {
                this.$sendPostRequest({
                    url: "http://192.168.0.94:9095/Numerical/RefreshDevBycl",
                    data: { machineNo: this.order.machineNo },
                    contentType: "application/json"
                }).then(r => {
                    if (r.code == 200) {
                        this.fetchData(true);
                        this.$showMessage("数据刷新成功");
                    } else {
                        this.$showMessage("同步失败");
                    }
                }).catch(error => {
                    console.error('刷新失败:', error);
                    this.$showMessage("刷新失败,请检查网络连接");
                });
            },
         onDaa003Change(v) {
            let o = this.lineList[this.DAA003List.indexOf(v)];
            this.orderId = o.id; this.orderNo = o.daa001;