From 2625ec709848eb16fee565f2bb55cc1ce86cb03f Mon Sep 17 00:00:00 2001
From: zhangwencui <1064582902@qq.com>
Date: 星期四, 23 七月 2026 10:50:16 +0800
Subject: [PATCH] 工作台增加上工下工功能关联工作记录

---
 src/views/mes/workbench/index.vue |   51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/src/views/mes/workbench/index.vue b/src/views/mes/workbench/index.vue
index 3640291..15c283a 100644
--- a/src/views/mes/workbench/index.vue
+++ b/src/views/mes/workbench/index.vue
@@ -2,12 +2,19 @@
 import type { MesMdWorkstationApi } from '#/api/mes/md/workstation';
 import type { PendingTask, WorkbenchTabItem, WorkbenchTabKey } from './types';
 
-import { computed, ref, watch } from 'vue';
+import { computed, onMounted, ref, watch } from 'vue';
 
+import { confirm } from '@vben/common-ui';
+import { MesProWorkRecordTypeEnum } from '@vben/constants';
 import { IconifyIcon } from '@vben/icons';
 
-import { Button } from 'ant-design-vue';
+import { Button, message } from 'ant-design-vue';
 
+import {
+  clockInWorkRecord,
+  clockOutWorkRecord,
+  getMyWorkRecord,
+} from '#/api/mes/pro/workrecord';
 import { getPendingFeedbackPage } from '#/api/mes/pro/task';
 import { router } from '#/router';
 
@@ -51,6 +58,43 @@
 function handleWorkstationSelect(ws: MesMdWorkstationApi.Workstation) {
   workstation.value = ws;
 }
+
+// --- 涓婂伐/涓嬪伐 ---
+const isClockIn = ref(false);
+
+async function loadClockStatus() {
+  const record = await getMyWorkRecord();
+  isClockIn.value = record?.type === MesProWorkRecordTypeEnum.CLOCK_IN;
+}
+
+/** 涓婂伐锛氶粯璁や娇鐢ㄥ綋鍓嶉�変腑鐨勫伐浣滅珯锛屽脊绐楃‘璁� */
+async function handleClockIn() {
+  if (!workstationId.value) return;
+  try {
+    await confirm(
+      `纭涓婂伐鍒板綋鍓嶅伐浣滅珯銆�${workstation.value?.code} - ${workstation.value?.name}銆嶏紵`,
+    );
+  } catch {
+    return;
+  }
+  await clockInWorkRecord(workstationId.value);
+  message.success('涓婂伐鎴愬姛');
+  isClockIn.value = true;
+}
+
+/** 涓嬪伐 */
+async function handleClockOut() {
+  try {
+    await confirm('纭涓嬪伐褰撳墠宸ヤ綔绔欙紵');
+  } catch {
+    return;
+  }
+  await clockOutWorkRecord();
+  message.success('涓嬪伐鎴愬姛');
+  isClockIn.value = false;
+}
+
+onMounted(loadClockStatus);
 
 // --- 浠诲姟鍒楄〃 ---
 const taskList = ref<PendingTask[]>([]);
@@ -159,7 +203,10 @@
         <!-- 宸ヤ綔绔欓�夋嫨闈㈡澘 -->
         <WorkstationPanel
           :workstation="workstation"
+          :is-clock-in="isClockIn"
           @change="openWorkstationSelect"
+          @clock-in="handleClockIn"
+          @clock-out="handleClockOut"
         />
 
         <!-- 宸ュ崟鍒楄〃 -->

--
Gitblit v1.9.3