liu
2026-09-02 fec6a89b4ed2dfc988c1ab308188306d536d8ccd
src/views/basicData/mdm/index.vue
@@ -8,26 +8,33 @@
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' });
const [FormModal, formModalApi] = useVbenModal({
  connectedComponent: Form,
  destroyOnClose: true,
});
const [ImportModal, importModalApi] = useVbenModal({
  connectedComponent: ImportForm,
  destroyOnClose: true,
});
@@ -74,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();
}
/** 编辑物料 */
@@ -135,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 删除该物料及关联配置(BOM/SOP/SIP/批次配置),确认继续?');
  }
  syncingId.value = row.id!;
  try {
    await updateItemSync(row.id!, checked);
    message.success(checked ? '已同步到 MES' : '已取消同步');
    handleRefresh();
  } finally {
    syncingId.value = null;
  }
}
@@ -193,6 +222,7 @@
<template>
  <Page auto-content-height>
    <FormModal @success="handleRefresh" />
    <ImportModal @success="handleRefresh" />
    <Grid table-title="物料列表">
      <template #toolbar-tools>
        <TableAction
@@ -204,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',
@@ -232,8 +269,13 @@
        <Tag v-else>否</Tag>
      </template>
      <template #syncedMes="{ row }">
        <Tag v-if="row.syncedMes" color="success">已同步</Tag>
        <Tag v-else color="default">未同步</Tag>
        <Switch
          :checked="row.syncedMes"
          :loading="syncingId === row.id"
          checkedChildren="已同步"
          unCheckedChildren="未同步"
          @change="handleSyncChange(row, $event)"
        />
      </template>
      <template #actions="{ row }">
        <TableAction