From 6a6f43983826ac5f86087e7a056d6e81512bcaf0 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期五, 06 十一月 2026 09:19:53 +0800
Subject: [PATCH] feat(mes): 新增MES质量巡检模块及前后端功能

---
 src/views/mes/qc/components/qc-attachments.vue |   56 ++++++++++++++++++
 src/views/mes/qc/patrol/index.vue              |  120 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 176 insertions(+), 0 deletions(-)

diff --git a/src/views/mes/qc/components/qc-attachments.vue b/src/views/mes/qc/components/qc-attachments.vue
new file mode 100644
index 0000000..cfee81e
--- /dev/null
+++ b/src/views/mes/qc/components/qc-attachments.vue
@@ -0,0 +1,56 @@
+<script setup lang="ts">
+import type { SystemStorageApi } from '#/api/system/storage';
+
+import { onMounted, ref } from 'vue';
+import { Button, message, Popconfirm, Upload } from 'ant-design-vue';
+import { bindAttachments, deleteAttachments, listAttachments, uploadFile } from '#/api/system/storage';
+
+const props = defineProps<{ qcType: 'patrol'; qcId: number }>();
+const files = ref<SystemStorageApi.StorageBlob[]>([]);
+const loading = ref(false);
+const params = () => ({ recordType: `mes_qc_${props.qcType}`, recordId: props.qcId, application: 'file' });
+
+async function load() {
+  files.value = await listAttachments(params());
+}
+
+async function upload(file: File) {
+  if (files.value.length >= 50) {
+    message.warning('鏈�澶氫笂浼� 50 浠介檮浠�');
+    return Upload.LIST_IGNORE;
+  }
+  loading.value = true;
+  try {
+    const result = await uploadFile([file]);
+    const blob = result?.[0];
+    if (!blob?.id) throw new Error('涓婁紶缁撴灉缂哄皯鏂囦欢缂栧彿');
+    await bindAttachments({ ...params(), blobItems: [...files.value.map(item => ({ blobId: item.id })), { blobId: blob.id }] });
+    await load();
+    message.success('闄勪欢宸蹭笂浼�');
+  } finally {
+    loading.value = false;
+  }
+  return Upload.LIST_IGNORE;
+}
+
+async function remove(file: SystemStorageApi.StorageBlob) {
+  if (!file.storageAttachmentId) return;
+  await deleteAttachments([file.storageAttachmentId]);
+  await load();
+}
+
+onMounted(load);
+</script>
+
+<template>
+  <Upload :show-upload-list="false" :before-upload="upload" :disabled="loading">
+    <Button :loading="loading">涓婁紶宸℃闄勪欢</Button>
+  </Upload>
+  <div v-for="file in files" :key="file.id" class="flex items-center gap-2">
+    <a v-if="file.downloadURL || file.url" :href="file.downloadURL || file.url" target="_blank" rel="noopener noreferrer">{{ file.originalFilename || file.name || file.id }}</a>
+    <span v-else>{{ file.originalFilename || file.name || file.id }}</span>
+    <Popconfirm title="纭鍒犻櫎姝ら檮浠讹紵" @confirm="remove(file)">
+      <Button type="link" danger>鍒犻櫎</Button>
+    </Popconfirm>
+  </div>
+</template>
diff --git a/src/views/mes/qc/patrol/index.vue b/src/views/mes/qc/patrol/index.vue
new file mode 100644
index 0000000..515ebac
--- /dev/null
+++ b/src/views/mes/qc/patrol/index.vue
@@ -0,0 +1,120 @@
+<script setup lang="ts">
+import { onMounted, reactive, ref } from 'vue';
+import { useAccess } from '@vben/access';
+import { Page } from '@vben/common-ui';
+import { Button, DatePicker, Form, Input, InputNumber, message, Modal, Popconfirm, Select, Space, Table, Upload } from 'ant-design-vue';
+import dayjs from 'dayjs';
+import { requestClient } from '#/api/request';
+import { getSimpleUserList } from '#/api/system/user';
+import { getItem } from '#/api/mdm/item';
+import { bindAttachments, listAttachments, uploadFile } from '#/api/system/storage';
+import { MdmItemSelect } from '#/views/basicData/mdm/components';
+import QcAttachments from '../components/qc-attachments.vue';
+
+defineOptions({ name: 'MesQcPatrol' });
+interface Patrol { id?: number; code?: string; name?: string; itemId?: number; reelNo?: string; batchCode?: string; qualifiedQuantity?: number; unqualifiedQuantity?: number; inspectDate?: string; inspectorUserId?: number; remark?: string }
+const { hasAccessByCodes, hasAccessByRoles } = useAccess();
+const can = (action: string) => hasAccessByRoles(['super_admin']) || hasAccessByCodes([`mes:qc-patrol:${action}`]);
+const itemNames = ref<Record<number, string>>({});
+const rows = ref<Patrol[]>([]); const users = ref<any[]>([]); const loading = ref(false); const saving = ref(false); const open = ref(false);
+const query = reactive({ pageNo: 1, pageSize: 10, total: 0, code: '', reelNo: '' });
+const form = reactive<Patrol>({});
+const pendingFiles = ref<{ id: number; name: string }[]>([]);
+const uploading = ref(false);
+const attachmentVersion = ref(0);
+async function addPendingFile(file: File) {
+  if (uploading.value || pendingFiles.value.length >= 50) { if (pendingFiles.value.length >= 50) message.warning('鏈�澶氫笂浼� 50 浠介檮浠�'); return Upload.LIST_IGNORE; }
+  uploading.value = true;
+  try { const result = await uploadFile([file]); const blob = result?.[0]; if (!blob?.id) throw new Error('涓婁紶缁撴灉缂哄皯鏂囦欢缂栧彿'); pendingFiles.value.push({ id: blob.id, name: file.name }); message.success('闄勪欢宸蹭笂浼�'); } finally { uploading.value = false; }
+  return Upload.LIST_IGNORE;
+}
+async function bindPendingFiles() {
+  if (pendingFiles.value.length && form.id) {
+    const params = { recordType: 'mes_qc_patrol', recordId: form.id, application: 'file' };
+    const existing = await listAttachments(params);
+    await bindAttachments({ ...params, blobItems: [...existing.map(file => ({ blobId: file.id })), ...pendingFiles.value.map(file => ({ blobId: file.id }))] });
+    pendingFiles.value = [];
+  }
+  attachmentVersion.value++;
+}
+const columns = [ { title: '宸℃鍗曞彿', dataIndex: 'code' }, { title: '宸℃鍚嶇О', dataIndex: 'name' }, { title: '鐗╂枡鍚嶇О', dataIndex: 'itemId', key: 'itemId' }, { title: '鐩樺彿', dataIndex: 'reelNo' }, { title: '鎵规鍙�', dataIndex: 'batchCode' }, { title: '鍚堟牸鏁�', dataIndex: 'qualifiedQuantity' }, { title: '涓嶅悎鏍兼暟', dataIndex: 'unqualifiedQuantity' }, { title: '宸℃鏃ユ湡', dataIndex: 'inspectDate' }, { title: '鎿嶄綔', key: 'action', width: 145 } ];
+async function load() { loading.value=true; try { const res = await requestClient.get('/mes/qc/patrol/page', { params: { pageNo: query.pageNo, pageSize: query.pageSize, code: query.code || undefined, reelNo: query.reelNo || undefined } }); rows.value=res.list; query.total=res.total; await Promise.all([...new Set<number>(res.list.map((row: Patrol) => row.itemId).filter(Boolean))].map(async id => { if (!itemNames.value[id]) { const item = await getItem(id); itemNames.value[id] = item?.name || String(id); } })); } finally { loading.value=false; } }
+async function edit(row?: Patrol) { pendingFiles.value = []; Object.keys(form).forEach(k => delete (form as any)[k]); if (row?.id) { const data = await requestClient.get('/mes/qc/patrol/get', {params:{id:row.id}}); Object.assign(form, data, { inspectDate: dayjs(data.inspectDate).format('YYYY-MM-DDTHH:mm:ss') }); } else Object.assign(form, {qualifiedQuantity:0, unqualifiedQuantity:0, inspectDate:dayjs().format('YYYY-MM-DDTHH:mm:ss')}); open.value=true; }
+async function save() { if (!form.code?.trim() || !form.name?.trim() || !form.itemId || !form.inspectorUserId || !form.inspectDate || form.qualifiedQuantity == null || form.unqualifiedQuantity == null || form.qualifiedQuantity + form.unqualifiedQuantity <= 0) { message.warning('璇峰~鍐欏崟鍙枫�佸悕绉般�佺墿鏂欍�佸贰妫�浜哄憳銆佹棩鏈熷拰鏈夋晥鏁伴噺'); return; } saving.value=true; try { if(form.id) await requestClient.put('/mes/qc/patrol/update',form); else { form.id = await requestClient.post('/mes/qc/patrol/create',form); } await bindPendingFiles(); message.success('淇濆瓨鎴愬姛'); await load(); } finally { saving.value=false; } }
+async function remove(id: number) { await requestClient.delete('/mes/qc/patrol/delete',{params:{id}}); message.success('鍒犻櫎鎴愬姛'); await load(); }
+onMounted(async () => { await Promise.all([load(), getSimpleUserList().then(data => { users.value = data; })]); });
+</script>
+<template>
+  <Page auto-content-height>
+    <div class="patrol-page">
+      <section class="patrol-search" aria-label="宸℃鏌ヨ鏉′欢">
+        <div class="search-fields">
+          <label class="search-field"><span>宸℃鍗曞彿</span><Input v-model:value="query.code" placeholder="璇疯緭鍏ュ贰妫�鍗曞彿" allow-clear @press-enter="query.pageNo = 1; load()" /></label>
+          <label class="search-field"><span>鐩樺彿</span><Input v-model:value="query.reelNo" placeholder="璇疯緭鍏ョ洏鍙�" allow-clear @press-enter="query.pageNo = 1; load()" /></label>
+        </div>
+        <Space class="search-actions">
+          <Button @click="query.code = ''; query.reelNo = ''; query.pageNo = 1; load()">閲嶇疆</Button>
+          <Button type="primary" :loading="loading" @click="query.pageNo = 1; load()">鏌ヨ</Button>
+        </Space>
+      </section>
+
+      <section class="patrol-list" aria-label="宸℃璁板綍鍒楄〃">
+        <div class="list-heading">
+          <div><h2>宸℃璁板綍</h2><p>鍏� {{ query.total }} 鏉¤褰�</p></div>
+          <Space><Button :loading="loading" @click="load()">鍒锋柊</Button><Button v-if="can('create')" type="primary" @click="edit()">鏂板宸℃</Button></Space>
+        </div>
+        <Table row-key="id" :columns="columns" :data-source="rows" :loading="loading" :scroll="{ x: 1100 }" :pagination="{current:query.pageNo,pageSize:query.pageSize,total:query.total,showSizeChanger:true,showTotal:(total:number)=>`鍏� ${total} 鏉¤褰昤}" @change="(p:any) => {query.pageNo=p.current; query.pageSize=p.pageSize; load();}">
+          <template #bodyCell="{column,record}">
+            <template v-if="column.key==='itemId'">{{ itemNames[record.itemId] || record.itemId }}</template>
+            <template v-else-if="column.dataIndex==='inspectDate'">{{ record.inspectDate ? dayjs(record.inspectDate).format('YYYY-MM-DD HH:mm') : '鈥�' }}</template>
+            <template v-else-if="column.dataIndex==='reelNo' || column.dataIndex==='batchCode'">{{ record[column.dataIndex] || '鈥�' }}</template>
+            <template v-else-if="column.key==='action'"><Space :size="0"><Button v-if="can('update')" type="link" @click="edit(record)">淇敼</Button><Popconfirm v-if="can('delete')" title="纭鍒犻櫎姝ゅ贰妫�璁板綍锛�" @confirm="remove(record.id)"><Button type="link" danger>鍒犻櫎</Button></Popconfirm></Space></template>
+          </template>
+          <template #emptyText><div class="empty-state"><p>鏆傛棤宸℃璁板綍</p><span>鏂板宸℃鍚庯紝璁板綍浼氭樉绀哄湪杩欓噷</span><Button v-if="can('create')" type="link" @click="edit()">鏂板宸℃</Button></div></template>
+        </Table>
+      </section>
+    </div>
+    <Modal v-model:open="open" :title="form.id ? '淇敼宸℃璁板綍' : '鏂板宸℃璁板綍'" :width="850" :confirm-loading="saving" :closable="!uploading && !saving" :mask-closable="!uploading && !saving" :cancel-button-props="{ disabled: uploading || saving }" :ok-button-props="{ disabled: uploading }" ok-text="淇濆瓨" @ok="save">
+      <div class="patrol-modal">
+        <div class="form-heading"><h3>鍩烘湰淇℃伅</h3><p>濉啓宸℃瀵硅薄鍙婅褰曚俊鎭�</p></div>
+        <Form layout="vertical" class="patrol-form">
+          <Form.Item label="宸℃鍗曞彿" required><Input v-model:value="form.code" :maxlength="100" placeholder="璇疯緭鍏ュ贰妫�鍗曞彿" /></Form.Item>
+          <Form.Item label="宸℃鍚嶇О" required><Input v-model:value="form.name" :maxlength="255" placeholder="璇疯緭鍏ュ贰妫�鍚嶇О" /></Form.Item>
+          <Form.Item label="鐗╂枡" required><MdmItemSelect v-model="form.itemId" /></Form.Item>
+          <Form.Item label="鐩樺彿"><Input v-model:value="form.reelNo" :maxlength="128" placeholder="璇疯緭鍏ョ洏鍙�" /></Form.Item>
+          <Form.Item label="鎵规鍙�"><Input v-model:value="form.batchCode" :maxlength="128" placeholder="璇疯緭鍏ユ壒娆″彿" /></Form.Item>
+          <Form.Item label="宸℃浜哄憳" required><Select v-model:value="form.inspectorUserId" show-search option-filter-prop="label" placeholder="璇烽�夋嫨宸℃浜哄憳" :options="users.map(u=>({value:u.id,label:u.nickname}))" /></Form.Item>
+          <Form.Item label="鍚堟牸鏁伴噺" required><InputNumber v-model:value="form.qualifiedQuantity" :min="0" class="w-full" /></Form.Item>
+          <Form.Item label="涓嶅悎鏍兼暟閲�" required><InputNumber v-model:value="form.unqualifiedQuantity" :min="0" class="w-full" /></Form.Item>
+          <Form.Item label="宸℃鏃ユ湡" required><DatePicker v-model:value="form.inspectDate" show-time value-format="YYYY-MM-DDTHH:mm:ss" class="w-full" /></Form.Item>
+          <Form.Item label="澶囨敞"><Input v-model:value="form.remark" :maxlength="1000" placeholder="璇疯緭鍏ュ娉�" /></Form.Item>
+        </Form>
+        <div class="attachment-section"><div class="form-heading"><h3>宸℃闄勪欢</h3><p>涓婁紶宸℃鐩稿叧鏂囦欢</p></div><QcAttachments v-if="form.id" :key="attachmentVersion" qc-type="patrol" :qc-id="form.id" /><Upload v-else :show-upload-list="false" :before-upload="addPendingFile" :disabled="uploading"><Button :loading="uploading">涓婁紶宸℃闄勪欢</Button></Upload><div v-for="file in pendingFiles" :key="file.id" class="pending-file"><span>{{ file.name }}锛堢瓑寰呬繚瀛樺叧鑱旓級</span><Button type="link" danger @click="pendingFiles = pendingFiles.filter(item => item.id !== file.id)">绉婚櫎</Button></div></div>
+      </div>
+    </Modal>
+  </Page>
+</template>
+
+<style scoped>
+.patrol-page { display: flex; flex-direction: column; gap: 16px; min-height: 100%; }
+.patrol-search, .patrol-list { background: hsl(var(--card)); border-radius: 8px; padding: 20px 24px; }
+.patrol-search { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
+.search-fields { display: grid; grid-template-columns: repeat(2, minmax(180px, 280px)); gap: 24px; flex: 1; }
+.search-field { display: grid; gap: 8px; color: hsl(var(--foreground)); font-weight: 500; }
+.search-actions { flex-shrink: 0; }
+.patrol-list { flex: 1; min-width: 0; }
+.list-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
+.list-heading h2 { margin: 0; font-size: 16px; font-weight: 600; }
+.list-heading p, .form-heading p { margin: 4px 0 0; color: hsl(var(--muted-foreground)); font-size: 13px; }
+.empty-state { display: flex; min-height: 180px; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: hsl(var(--muted-foreground)); }
+.empty-state p { margin: 0; color: hsl(var(--foreground)); font-weight: 500; }
+.empty-state span { font-size: 13px; }
+.patrol-modal { max-height: 65vh; overflow-y: auto; padding: 8px 4px 0; }
+.form-heading { margin-bottom: 16px; }
+.form-heading h3 { margin: 0; font-size: 15px; font-weight: 600; }
+.patrol-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
+.attachment-section { border-top: 1px solid hsl(var(--border)); padding-top: 20px; margin-top: 4px; }
+.pending-file { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; }
+.pending-file span { overflow-wrap: anywhere; }
+@media (max-width: 768px) { .patrol-search { align-items: stretch; flex-direction: column; gap: 16px; } .search-fields { grid-template-columns: 1fr; gap: 12px; } .search-actions { align-self: end; } .patrol-search, .patrol-list { padding: 16px; } .patrol-form { grid-template-columns: 1fr; } }
+</style>

--
Gitblit v1.9.3