From a7dc7b230fcc6abc6ee5a7bfadb90789b03d2ca8 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期一, 07 九月 2026 16:45:37 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_pro2.0' into dev_pro2.0

---
 src/views/basicData/mdm/index.vue |  110 +++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 90 insertions(+), 20 deletions(-)

diff --git a/src/views/basicData/mdm/index.vue b/src/views/basicData/mdm/index.vue
index 7f87556..af385ba 100644
--- a/src/views/basicData/mdm/index.vue
+++ b/src/views/basicData/mdm/index.vue
@@ -3,26 +3,28 @@
 import type { MdmItemApi } from '#/api/mdm/item';
 import type { MesMdItemTypeApi } from '#/api/mes/md/item/type';
 
-import { ref } from 'vue';
+import { computed, ref } from 'vue';
 
 import { confirm, Page, useVbenModal } from '#/packages/effects/common-ui/src';
 import { downloadFileFromBlobPart, isEmpty } from '#/packages/utils/src';
 
-import { message, Tag } from 'ant-design-vue';
+import { message, Switch, Tag } from 'ant-design-vue';
 
 import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
 import {
   deleteItem,
   deleteItemList,
-  // exportItem,
+  exportItem,
   getItemPage,
   updateItemStatus,
+  updateItemSync,
 } from '#/api/mdm/item';
 import { getItemTypeSimpleList } from '#/api/mes/md/item/type';
 import { $t } from '#/locales';
 
 import { useGridColumns, useGridFormSchema } from './data';
 import Form from './modules/form.vue';
+import ImportForm from './modules/import-form.vue';
 
 defineOptions({ name: 'MdmItem' });
 
@@ -31,8 +33,41 @@
   destroyOnClose: true,
 });
 
+const [ImportModal, importModalApi] = useVbenModal({
+  connectedComponent: ImportForm,
+  destroyOnClose: true,
+});
+
 // 鍒嗙被鍒楄〃缂撳瓨
 const categoryList = ref<MesMdItemTypeApi.ItemType[]>([]);
+
+const TAG_COLORS = [
+  'green',
+  'orange',
+  'blue',
+  'purple',
+  'cyan',
+  'magenta',
+  'geekblue',
+  'volcano',
+  'gold',
+  'lime',
+] as const;
+
+/** 鍒嗙被ID 鈫� 棰滆壊鏄犲皠锛堝熀浜庡垎绫诲湪鍒楄〃涓殑绱㈠紩寰幆鍒嗛厤锛� */
+const categoryColorMap = computed(() => {
+  const map = new Map<number, string>();
+  categoryList.value.forEach((item, index) => {
+    map.set(item.id!, TAG_COLORS[index % TAG_COLORS.length]!);
+  });
+  return map;
+});
+
+/** 鑾峰彇鍒嗙被Tag棰滆壊 */
+function getCategoryColor(categoryId?: number): string {
+  if (!categoryId) return '';
+  return categoryColorMap.value.get(categoryId) || '';
+}
 
 /** 鑾峰彇鍒嗙被鍚嶇О */
 function getCategoryName(categoryId?: number) {
@@ -46,15 +81,20 @@
   gridApi.query();
 }
 
-/** 瀵煎嚭琛ㄦ牸 */
-// async function handleExport() {
-//   const data = await exportItem(await gridApi.formApi.getValues());
-//   downloadFileFromBlobPart({ fileName: '鐗╂枡.xls', source: data });
-// }
+/** 瀵煎嚭琛ㄦ牸锛堟寜褰撳墠鍒楄〃鏌ヨ鏉′欢瀵煎嚭鍏ㄩ儴鍛戒腑鏁版嵁锛� */
+async function handleExport() {
+  const data = await exportItem(await gridApi.formApi.getValues());
+  downloadFileFromBlobPart({ fileName: '鐗╂枡鏁版嵁.xls', source: data });
+}
 
 /** 鍒涘缓鐗╂枡 */
 function handleCreate() {
   formModalApi.setData(null).open();
+}
+
+/** 瀵煎叆鐗╂枡 */
+function handleImport() {
+  importModalApi.open();
 }
 
 /** 缂栬緫鐗╂枡 */
@@ -107,6 +147,23 @@
     handleRefresh();
   } finally {
     hideLoading();
+  }
+}
+
+const syncingId = ref<number | null>(null);
+
+/** 鍒囨崲鍚屾鐘舵�侊細鍏抽棴寮�鍏充細浠� MES 鍒犻櫎鐗╂枡锛岄渶纭 */
+async function handleSyncChange(row: MdmItemApi.Item, checked: boolean) {
+  if (!checked) {
+    await confirm('鍏抽棴鍚屾灏嗕粠 MES 鍒犻櫎璇ョ墿鏂欏強鍏宠仈閰嶇疆锛圔OM/SOP/SIP/鎵规閰嶇疆锛夛紝纭缁х画锛�');
+  }
+  syncingId.value = row.id!;
+  try {
+    await updateItemSync(row.id!, checked);
+    message.success(checked ? '宸插悓姝ュ埌 MES' : '宸插彇娑堝悓姝�');
+    handleRefresh();
+  } finally {
+    syncingId.value = null;
   }
 }
 
@@ -165,6 +222,7 @@
 <template>
   <Page auto-content-height>
     <FormModal @success="handleRefresh" />
+    <ImportModal @success="handleRefresh" />
     <Grid table-title="鐗╂枡鍒楄〃">
       <template #toolbar-tools>
         <TableAction
@@ -176,13 +234,20 @@
               auth: ['mdm:item:create'],
               onClick: handleCreate,
             },
-            // {
-            //   label: $t('ui.actionTitle.export'),
-            //   type: 'primary',
-            //   icon: ACTION_ICON.DOWNLOAD,
-            //   auth: ['mdm:item:export'],
-            //   onClick: handleExport,
-            // },
+            {
+              label: $t('ui.actionTitle.import', ['鐗╂枡']),
+              type: 'primary',
+              icon: ACTION_ICON.UPLOAD,
+              auth: ['mdm:item:import'],
+              onClick: handleImport,
+            },
+            {
+              label: $t('ui.actionTitle.export'),
+              type: 'primary',
+              icon: ACTION_ICON.DOWNLOAD,
+              auth: ['mdm:item:export'],
+              onClick: handleExport,
+            },
             {
               label: $t('ui.actionTitle.deleteBatch'),
               type: 'primary',
@@ -196,17 +261,22 @@
         />
       </template>
       <template #categoryName="{ row }">
-        <Tag v-if="row.categoryId === 1" color="green">{{ getCategoryName(row.categoryId) }}</Tag>
-        <Tag v-else-if="row.categoryId === 2" color="orange">{{ getCategoryName(row.categoryId) }}</Tag>
-        <Tag v-else-if="row.categoryId === 3" color="blue">{{ getCategoryName(row.categoryId) }}</Tag>
-        <Tag v-else-if="row.categoryId === 4" color="purple">{{ getCategoryName(row.categoryId) }}</Tag>
-        <Tag v-else-if="row.categoryId === 5" color="cyan">{{ getCategoryName(row.categoryId) }}</Tag>
+        <Tag v-if="getCategoryColor(row.categoryId)" :color="getCategoryColor(row.categoryId)">{{ getCategoryName(row.categoryId) }}</Tag>
         <span v-else>{{ getCategoryName(row.categoryId) }}</span>
       </template>
       <template #isBatchManaged="{ row }">
         <Tag v-if="row.isBatchManaged" color="success">鏄�</Tag>
         <Tag v-else>鍚�</Tag>
       </template>
+      <template #syncedMes="{ row }">
+        <Switch
+          :checked="row.syncedMes"
+          :loading="syncingId === row.id"
+          checkedChildren="宸插悓姝�"
+          unCheckedChildren="鏈悓姝�"
+          @change="handleSyncChange(row, $event)"
+        />
+      </template>
       <template #actions="{ row }">
         <TableAction
           :actions="[

--
Gitblit v1.9.3