From 077d36ebdf699961b9e66dd21e13b509240f8f79 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期五, 23 十月 2026 15:43:31 +0800
Subject: [PATCH] feat: 完善设备数采与标签打印功能

---
 src/views/wls/barcode/components/printer-label.vue     |  200 +++++++++++++++++++++++++++++++++++++++-
 src/views/wls/itemreceipt/modules/line-list.vue        |    1 
 src/packages/constants/src/biz-mes-enum.ts             |    2 
 company.config.ts                                      |    2 
 src/views/mes/process-design/template/modules/form.vue |    2 
 vite.config.ts                                         |    7 +
 src/views/mes/process-design/template/data.ts          |   35 ++++++-
 src/views/wls/returnissue/modules/line-list.vue        |    1 
 src/views/wls/returnsales/modules/line-list.vue        |    1 
 .env.production                                        |   10 +-
 src/views/mes/dv/telemetry/index.vue                   |    8 
 src/views/wls/outsourcereceipt/modules/line-list.vue   |    1 
 src/views/wls/productreceipt/modules/line-list.vue     |    1 
 src/views/wls/returnvendor/modules/line-list.vue       |    1 
 src/views/wls/transfer/modules/line-list.vue           |    1 
 15 files changed, 251 insertions(+), 22 deletions(-)

diff --git a/.env.production b/.env.production
index f486acb..40a94ef 100644
--- a/.env.production
+++ b/.env.production
@@ -2,10 +2,10 @@
 
 VITE_BASE=/
 
-# 璇锋眰璺緞
-VITE_BASE_URL=http://1.95.78.124:9006
-# 鎺ュ彛鍦板潃
-VITE_GLOB_API_URL=http://1.95.78.124:9006/admin-api
+# 璇锋眰璺緞锛堢暀绌鸿〃绀哄悓婧愶紝鐢卞墠绔寜褰撳墠璁块棶鍩熷悕绔彛鎷兼帴锛�
+VITE_BASE_URL=
+# 鎺ュ彛鍦板潃锛堢浉瀵硅矾寰勶紝璺熼殢褰撳墠璁块棶鍩熷悕绔彛锛岀粡 nginx 鍙嶄唬鍒板悗绔級
+VITE_GLOB_API_URL=/admin-api
 # 鏂囦欢涓婁紶绫诲瀷锛歴erver - 鍚庣涓婁紶锛� client - 鍓嶇鐩磋繛涓婁紶锛屼粎鏀寔S3鏈嶅姟
 VITE_UPLOAD_TYPE=server
 
@@ -25,4 +25,4 @@
 VITE_ARCHIVER=true
 
 # 楠岃瘉鐮佺殑寮�鍏�
-VITE_APP_CAPTCHA_ENABLE=true
\ No newline at end of file
+VITE_APP_CAPTCHA_ENABLE=true
diff --git a/company.config.ts b/company.config.ts
index 7be98c4..6856429 100644
--- a/company.config.ts
+++ b/company.config.ts
@@ -21,7 +21,7 @@
     name: '鏂伴珮鏁板瓧宸ュ巶鎺у埗涓績',
     logo: '/logos/xgdl.svg',
     favicon: '/logos/xgdl.svg',
-    apiUrl: 'http://1.95.78.124:9006/admin-api',
+    apiUrl: '/admin-api',
   },
   JHHG: {
     name: '瀹佸涔濇硴鍖栧伐',
diff --git a/src/packages/constants/src/biz-mes-enum.ts b/src/packages/constants/src/biz-mes-enum.ts
index 87bc8e9..2bd6591 100644
--- a/src/packages/constants/src/biz-mes-enum.ts
+++ b/src/packages/constants/src/biz-mes-enum.ts
@@ -154,6 +154,8 @@
   MD_WORKSTATION_CODE: 'MD_WORKSTATION_CODE',
   MD_WORKSHOP_CODE: 'MD_WORKSHOP_CODE',
   PD_PROJECT_CODE: 'PD_PROJECT_CODE',
+  PD_PROCESS_PARAM_CODE: 'PD_PROCESS_PARAM_CODE',
+  PD_PROCESS_PARAM_TEMPLATE_CODE: 'PD_PROCESS_PARAM_TEMPLATE_CODE',
   PD_TASK_CODE: 'PD_TASK_CODE',
   PD_VERSION_CODE: 'PD_VERSION_CODE',
   PD_DOCUMENT_AUDIT_CODE: 'PD_DOCUMENT_AUDIT_CODE',
diff --git a/src/views/mes/dv/telemetry/index.vue b/src/views/mes/dv/telemetry/index.vue
index 27b8ef1..69564b5 100644
--- a/src/views/mes/dv/telemetry/index.vue
+++ b/src/views/mes/dv/telemetry/index.vue
@@ -104,14 +104,14 @@
     }
   }
 
-  /** 鍒囨崲瀹炴椂鑷姩鍒锋柊锛堟瘡 30 绉掞級 */
+  /** 鍒囨崲鑷姩鍒锋柊锛堟瘡 30 鍒嗛挓锛� */
   function toggleAutoRefresh(checked: boolean | string | number) {
     if (checked) {
       refreshTimer = setInterval(() => {
         if (activeTab.value === 'latest') {
           latestGridApi.query();
         }
-      }, 30_000);
+      }, 1_800_000);
     } else if (refreshTimer) {
       clearInterval(refreshTimer);
       refreshTimer = undefined;
@@ -135,8 +135,8 @@
         </Button>
         <Switch
           v-model:checked="autoRefresh"
-          checked-children="瀹炴椂鑷姩鍒锋柊"
-          un-checked-children="瀹炴椂鑷姩鍒锋柊"
+          checked-children="鑷姩鍒锋柊锛�30鍒嗛挓锛�"
+          un-checked-children="鑷姩鍒锋柊锛�30鍒嗛挓锛�"
           @change="toggleAutoRefresh"
         />
         <span v-if="lastUpdateTime" class="text-sm text-gray-500">
diff --git a/src/views/mes/process-design/template/data.ts b/src/views/mes/process-design/template/data.ts
index e5dabf1..19d4906 100644
--- a/src/views/mes/process-design/template/data.ts
+++ b/src/views/mes/process-design/template/data.ts
@@ -1,17 +1,25 @@
-import type { VbenFormSchema } from "#/adapter/form";
+import type { VbenFormApi, VbenFormSchema } from "#/adapter/form";
 import type { VxeTableGridOptions } from "#/adapter/vxe-table";
 import type { MesPdTemplateApi } from "#/api/mes/pro/processdesign/template";
 
-import { DICT_TYPE } from "@vben/constants";
+import { h } from "vue";
+
+import { DICT_TYPE, MesAutoCodeRuleCode } from "@vben/constants";
 import { getDictOptions } from "@vben/hooks";
 
+import { Button } from "ant-design-vue";
+
 import { z } from "#/adapter/form";
+import { generateAutoCode } from "#/api/mes/md/autocode/record";
 
 /** 琛ㄥ崟绫诲瀷 */
 export type FormType = "create" | "detail" | "update";
 
 /** 鏂板/淇敼宸ヨ壓鍙傛暟妯℃澘鐨勮〃鍗� */
-export function useFormSchema(): VbenFormSchema[] {
+export function useFormSchema(
+  formType: FormType,
+  formApi?: VbenFormApi,
+): VbenFormSchema[] {
   return [
     {
       fieldName: "id",
@@ -27,9 +35,26 @@
       component: "Input",
       componentProps: {
         maxLength: 64,
-        placeholder: "妯℃澘缂栫爜鑷姩鐢熸垚",
-        disabled: true,
+        placeholder: "璇疯緭鍏ユā鏉跨紪鐮侊紝鐣欑┖灏嗚嚜鍔ㄧ敓鎴�",
       },
+      rules: z.string().max(64).optional(),
+      suffix:
+        formType === "detail"
+          ? undefined
+          : () =>
+              h(
+                Button,
+                {
+                  type: "default",
+                  onClick: async () => {
+                    const code = await generateAutoCode(
+                      MesAutoCodeRuleCode.PD_PROCESS_PARAM_TEMPLATE_CODE,
+                    );
+                    await formApi?.setFieldValue("templateCode", code);
+                  },
+                },
+                { default: () => "鑷姩鐢熸垚" },
+              ),
     },
     {
       fieldName: "templateName",
diff --git a/src/views/mes/process-design/template/modules/form.vue b/src/views/mes/process-design/template/modules/form.vue
index e5af337..0dd5563 100644
--- a/src/views/mes/process-design/template/modules/form.vue
+++ b/src/views/mes/process-design/template/modules/form.vue
@@ -118,9 +118,9 @@
         selectedDetails.value = [];
         return;
       }
-      formApi.setState({ schema: useFormSchema() });
       const data = modalApi.getData<{ formType: FormType; id?: number }>();
       formType.value = data.formType;
+      formApi.setState({ schema: useFormSchema(formType.value, formApi) });
       formApi.setDisabled(formType.value === "detail");
       modalApi.setState({ showConfirmButton: formType.value !== "detail" });
       if (!data?.id) {
diff --git a/src/views/wls/barcode/components/printer-label.vue b/src/views/wls/barcode/components/printer-label.vue
index 7fbeee5..84b4149 100644
--- a/src/views/wls/barcode/components/printer-label.vue
+++ b/src/views/wls/barcode/components/printer-label.vue
@@ -1,30 +1,220 @@
 <script lang="ts" setup>
+import type { MesWmBarcodeApi } from '#/api/mes/wm/barcode';
+
+import { ref } from 'vue';
+
+import { BarcodeBizTypeEnum } from '@vben/constants';
+
 import { Button, message } from 'ant-design-vue';
+
+import {
+  getBarcodeByBusiness,
+  renderBarcodeImage,
+} from '#/api/mes/wm/barcode';
 
 defineOptions({ name: 'WlsPrinterLabel' });
 
-withDefaults(
+const props = withDefaults(
   defineProps<{
     bizCode?: string;
     bizId?: number;
-    bizType?: string;
+    bizName?: string;
+    bizType?: number | string;
     labelText?: string;
   }>(),
   {
     bizCode: undefined,
     bizId: undefined,
+    bizName: undefined,
     bizType: undefined,
     labelText: '鏍囩鎵撳嵃',
   },
 );
 
-function handlePrint() {
-  message.warning('鏍囩鎵撳嵃鍔熻兘鏆傛湭瀹炵幇锛屾暚璇锋湡寰�');
+const printing = ref(false);
+
+function resolveBizType(value?: number | string) {
+  if (typeof value === 'number') {
+    return value;
+  }
+  const normalized = value?.trim().toUpperCase();
+  if (!normalized) {
+    return undefined;
+  }
+  // ITEM_BATCH 鏄儴鍒嗗叆搴撻〉闈㈡部鐢ㄧ殑鏃у埆鍚嶏紝瀹為檯浠嶅搴斺�滄壒娆♀�濄��
+  if (normalized === 'ITEM_BATCH') {
+    return BarcodeBizTypeEnum.BATCH;
+  }
+  const numericValue = Number(normalized);
+  if (Number.isInteger(numericValue)) {
+    return numericValue;
+  }
+  const enumValue =
+    BarcodeBizTypeEnum[
+      normalized as keyof typeof BarcodeBizTypeEnum
+    ];
+  return typeof enumValue === 'number' ? enumValue : undefined;
+}
+
+function getBizTypeLabel(bizType: number) {
+  const labels: Partial<Record<BarcodeBizTypeEnum, string>> = {
+    [BarcodeBizTypeEnum.AREA]: '搴撲綅',
+    [BarcodeBizTypeEnum.BATCH]: '鎵规',
+    [BarcodeBizTypeEnum.CLIENT]: '瀹㈡埛',
+    [BarcodeBizTypeEnum.ITEM]: '鐗╂枡',
+    [BarcodeBizTypeEnum.LOCATION]: '搴撳尯',
+    [BarcodeBizTypeEnum.MACHINERY]: '璁惧',
+    [BarcodeBizTypeEnum.PACKAGE]: '瑁呯鍗�',
+    [BarcodeBizTypeEnum.PROCARD]: '娴佽浆鍗�',
+    [BarcodeBizTypeEnum.SN]: 'SN 鐮�',
+    [BarcodeBizTypeEnum.STOCK]: '搴撳瓨',
+    [BarcodeBizTypeEnum.TOOL]: '宸ュ叿',
+    [BarcodeBizTypeEnum.USER]: '浜哄憳',
+    [BarcodeBizTypeEnum.VENDOR]: '渚涘簲鍟�',
+    [BarcodeBizTypeEnum.WAREHOUSE]: '浠撳簱',
+    [BarcodeBizTypeEnum.WORKORDER]: '宸ュ崟',
+    [BarcodeBizTypeEnum.WORKSHOP]: '杞﹂棿',
+    [BarcodeBizTypeEnum.WORKSTATION]: '宸ヤ綔绔�',
+  };
+  return labels[bizType as BarcodeBizTypeEnum] || '涓氬姟';
+}
+
+function escapeHtml(value?: null | string) {
+  return (value || '')
+    .replaceAll('&', '&amp;')
+    .replaceAll('<', '&lt;')
+    .replaceAll('>', '&gt;')
+    .replaceAll('"', '&quot;')
+    .replaceAll("'", '&#39;');
+}
+
+async function getBarcodeForPrint(bizType: number) {
+  const barcode = await getBarcodeByBusiness(bizType, props.bizId!);
+  if (barcode?.content) {
+    return barcode;
+  }
+  if (!props.bizCode) {
+    throw new Error('缂哄皯涓氬姟缂栫爜锛屾棤娉曟墦鍗版爣绛�');
+  }
+
+  // 鍘嗗彶鎵规鍙兘鏈厤缃潯鐮佽鍒欍�傛鏃朵娇鐢ㄤ笟鍔$紪鐮佸嵆鏃剁敓鎴� CODE128锛�
+  // 鍙敤浜庢湰娆℃墦鍗帮紝涓嶅啓鍏ユ潯鐮佽〃锛岄伩鍏嶁�滄潯鐮侀厤缃笉瀛樺湪鈥濋樆鏂笟鍔°��
+  return {
+    bizCode: props.bizCode,
+    bizId: props.bizId,
+    bizName: props.bizName || props.bizCode,
+    bizType,
+    content: props.bizCode,
+  } satisfies MesWmBarcodeApi.Barcode;
+}
+
+function writePrintDocument(
+  printWindow: Window,
+  barcode: MesWmBarcodeApi.Barcode,
+  imageBase64: string,
+  bizType: number,
+) {
+  const typeLabel = getBizTypeLabel(bizType);
+  const isQrCode = barcode.format === 1;
+  printWindow.document.open();
+  printWindow.document.write(`<!doctype html>
+<html lang="zh-CN">
+<head>
+  <meta charset="UTF-8" />
+  <title>${escapeHtml(typeLabel)}鏍囩</title>
+  <style>
+    @page { size: 80mm 55mm; margin: 0; }
+    * { box-sizing: border-box; }
+    html, body { width: 80mm; height: 55mm; margin: 0; color: #000; font-family: "Microsoft YaHei", Arial, sans-serif; }
+    .label { width: 80mm; height: 55mm; padding: 3mm; border: .35mm solid #000; display: grid; grid-template-columns: ${isQrCode ? '31mm 1fr' : '1fr'}; gap: 3mm; overflow: hidden; }
+    .barcode { display: flex; align-items: center; justify-content: center; min-width: 0; }
+    .barcode img { display: block; max-width: 100%; max-height: ${isQrCode ? '38mm' : '22mm'}; object-fit: contain; }
+    .info { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
+    .title { margin-bottom: 2mm; padding-bottom: 1.5mm; border-bottom: .3mm solid #000; font-size: 15pt; font-weight: 700; text-align: center; }
+    .row { margin: .8mm 0; font-size: 9.5pt; line-height: 1.35; overflow-wrap: anywhere; }
+    .key { font-weight: 700; }
+    .content { margin-top: 1mm; font-family: Consolas, monospace; font-size: 7.5pt; text-align: center; overflow-wrap: anywhere; }
+    ${isQrCode ? '' : '.label { grid-template-rows: auto 1fr; } .barcode { order: 2; } .info { order: 1; } .title { margin-bottom: 1mm; } .row { display: inline-block; margin-right: 4mm; }'}
+    @media screen { body { margin: 8px; } }
+  </style>
+</head>
+<body>
+  <main class="label">
+    <section class="barcode">
+      <img src="${imageBase64}" alt="${escapeHtml(typeLabel)}鏉$爜" />
+    </section>
+    <section class="info">
+      <div class="title">${escapeHtml(typeLabel)}鏍囩</div>
+      <div class="row"><span class="key">涓氬姟缂栫爜锛�</span>${escapeHtml(barcode.bizCode || props.bizCode)}</div>
+      <div class="row"><span class="key">涓氬姟鍚嶇О锛�</span>${escapeHtml(barcode.bizName || props.bizName || '-')}</div>
+      <div class="content">${escapeHtml(barcode.content)}</div>
+    </section>
+  </main>
+  <script>
+    window.addEventListener('load', function () {
+      window.focus();
+      window.onafterprint = function () { window.close(); };
+      setTimeout(function () { window.print(); }, 150);
+    });
+  <\/script>
+</body>
+</html>`);
+  printWindow.document.close();
+}
+
+async function handlePrint() {
+  if (printing.value) {
+    return;
+  }
+  const bizType = resolveBizType(props.bizType);
+  if (!props.bizId || !bizType) {
+    message.warning('缂哄皯涓氬姟绫诲瀷鎴栦笟鍔$紪鍙凤紝鏃犳硶鎵撳嵃鏍囩');
+    return;
+  }
+
+  // 鍦ㄧ敤鎴风偣鍑讳簨浠朵腑鍚屾鎵撳紑绐楀彛锛岄伩鍏嶅紓姝ヨ姹傜粨鏉熷悗琚祻瑙堝櫒鎷︽埅銆�
+  const printWindow = window.open('', '_blank', 'width=900,height=650');
+  if (!printWindow) {
+    message.error('鏃犳硶鎵撳紑鎵撳嵃绐楀彛锛岃鍏佽娴忚鍣ㄥ脊鍑虹獥鍙e悗閲嶈瘯');
+    return;
+  }
+  printWindow.opener = null;
+  printWindow.document.write(
+    '<!doctype html><html><head><meta charset="UTF-8"><title>鐢熸垚鏍囩</title></head><body style="font-family:Microsoft YaHei;padding:24px">姝e湪鐢熸垚鏍囩锛岃绋嶅�欌�︹��</body></html>',
+  );
+  printWindow.document.close();
+
+  printing.value = true;
+  try {
+    const barcode = await getBarcodeForPrint(bizType);
+    const isQrCode = barcode.format === 1;
+    const imageBase64 = await renderBarcodeImage(
+      barcode.content!,
+      barcode.format,
+      isQrCode ? 360 : 720,
+      isQrCode ? 360 : 220,
+    );
+    if (!imageBase64?.startsWith('data:image/png;base64,')) {
+      throw new Error('鏈嶅姟绔湭杩斿洖鏈夋晥鐨勬爣绛惧浘鐗�');
+    }
+    if (!printWindow.closed) {
+      writePrintDocument(printWindow, barcode, imageBase64, bizType);
+    }
+  } catch (error) {
+    if (!printWindow.closed) {
+      printWindow.close();
+    }
+    const errorMessage =
+      error instanceof Error ? error.message : '鏍囩鎵撳嵃澶辫触锛岃绋嶅悗閲嶈瘯';
+    message.error(errorMessage);
+  } finally {
+    printing.value = false;
+  }
 }
 </script>
 
 <template>
-  <Button type="link" @click="handlePrint">
+  <Button :loading="printing" type="link" @click="handlePrint">
     {{ labelText }}
   </Button>
 </template>
diff --git a/src/views/wls/itemreceipt/modules/line-list.vue b/src/views/wls/itemreceipt/modules/line-list.vue
index 2e5a09b..be46b35 100644
--- a/src/views/wls/itemreceipt/modules/line-list.vue
+++ b/src/views/wls/itemreceipt/modules/line-list.vue
@@ -232,6 +232,7 @@
             v-if="isStock"
             :biz-code="row.batchCode"
             :biz-id="row.batchId"
+            :biz-name="row.itemName"
             biz-type="ITEM_BATCH"
           />
         </div>
diff --git a/src/views/wls/outsourcereceipt/modules/line-list.vue b/src/views/wls/outsourcereceipt/modules/line-list.vue
index 1dcf161..e90785b 100644
--- a/src/views/wls/outsourcereceipt/modules/line-list.vue
+++ b/src/views/wls/outsourcereceipt/modules/line-list.vue
@@ -227,6 +227,7 @@
             v-if="isStock"
             :biz-code="row.batchCode"
             :biz-id="row.batchId"
+            :biz-name="row.itemName"
             biz-type="BATCH"
           />
         </div>
diff --git a/src/views/wls/productreceipt/modules/line-list.vue b/src/views/wls/productreceipt/modules/line-list.vue
index 26442fb..cc425f6 100644
--- a/src/views/wls/productreceipt/modules/line-list.vue
+++ b/src/views/wls/productreceipt/modules/line-list.vue
@@ -244,6 +244,7 @@
             v-if="isStock"
             :biz-code="row.batchCode"
             :biz-id="row.batchId"
+            :biz-name="row.itemName"
             biz-type="BATCH"
           />
         </div>
diff --git a/src/views/wls/returnissue/modules/line-list.vue b/src/views/wls/returnissue/modules/line-list.vue
index 98c6682..fd2ab69 100644
--- a/src/views/wls/returnissue/modules/line-list.vue
+++ b/src/views/wls/returnissue/modules/line-list.vue
@@ -240,6 +240,7 @@
             v-if="isStock"
             :biz-code="row.batchCode"
             :biz-id="row.batchId"
+            :biz-name="row.itemName"
             biz-type="BATCH"
           />
         </div>
diff --git a/src/views/wls/returnsales/modules/line-list.vue b/src/views/wls/returnsales/modules/line-list.vue
index 9c635e2..f9a05e2 100644
--- a/src/views/wls/returnsales/modules/line-list.vue
+++ b/src/views/wls/returnsales/modules/line-list.vue
@@ -242,6 +242,7 @@
             v-if="isStock"
             :biz-code="row.batchCode"
             :biz-id="row.batchId"
+            :biz-name="row.itemName"
             biz-type="BATCH"
           />
         </div>
diff --git a/src/views/wls/returnvendor/modules/line-list.vue b/src/views/wls/returnvendor/modules/line-list.vue
index 7f67f49..6b469ac 100644
--- a/src/views/wls/returnvendor/modules/line-list.vue
+++ b/src/views/wls/returnvendor/modules/line-list.vue
@@ -228,6 +228,7 @@
             v-if="isStock"
             :biz-code="row.batchCode"
             :biz-id="row.batchId"
+            :biz-name="row.itemName"
             biz-type="BATCH"
           />
         </div>
diff --git a/src/views/wls/transfer/modules/line-list.vue b/src/views/wls/transfer/modules/line-list.vue
index 05d8165..799d670 100644
--- a/src/views/wls/transfer/modules/line-list.vue
+++ b/src/views/wls/transfer/modules/line-list.vue
@@ -220,6 +220,7 @@
           v-if="isStock"
           :biz-code="row.batchCode"
           :biz-id="row.batchId"
+          :biz-name="row.itemName"
           biz-type="BATCH"
         />
       </template>
diff --git a/vite.config.ts b/vite.config.ts
index 58d7189..c4e00cc 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -20,7 +20,12 @@
   };
   if (!isDev && appApiUrl) {
     defineVars['import.meta.env.VITE_GLOB_API_URL'] = JSON.stringify(appApiUrl);
-    defineVars['import.meta.env.VITE_BASE_URL'] = JSON.stringify(new URL(appApiUrl).origin);
+    // 鏀寔鐩稿璺緞锛堝 /admin-api锛夛細鏃� origin 鏃剁暀绌猴紝鍓嶇鍚勫浠ュ悓婧愭柟寮忔嫾鎺�
+    try {
+      defineVars['import.meta.env.VITE_BASE_URL'] = JSON.stringify(new URL(appApiUrl).origin);
+    } catch {
+      defineVars['import.meta.env.VITE_BASE_URL'] = JSON.stringify('');
+    }
   }
 
   return {

--
Gitblit v1.9.3