From e0eadec8ab4a1da79517f923f595ae19328a3703 Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@tuqin.cn>
Date: 星期一, 02 十一月 2026 10:17:52 +0800
Subject: [PATCH] feat(mes): 新增安全生产模块 - 应急处置预案(一期)
---
src/views/mes/pro/emergencyplan/index.vue | 218 ++++++++++++++
src/views/mes/pro/emergencyplan/modules/form.vue | 91 ++++++
src/components/import-modal/import-modal.vue | 317 +++++++++++++++++++++
src/views/mes/pro/emergencyplan/data.ts | 187 ++++++++++++
src/components/import-modal/index.ts | 1
src/packages/constants/src/dict-enum.ts | 1
src/api/mes/pro/emergencyplan/index.ts | 66 ++++
7 files changed, 881 insertions(+), 0 deletions(-)
diff --git a/src/api/mes/pro/emergencyplan/index.ts b/src/api/mes/pro/emergencyplan/index.ts
new file mode 100644
index 0000000..c099932
--- /dev/null
+++ b/src/api/mes/pro/emergencyplan/index.ts
@@ -0,0 +1,66 @@
+import type { PageParam, PageResult } from '@vben/request';
+
+import { requestClient } from '#/api/request';
+
+export namespace MesProEmergencyPlanApi {
+ /** 搴旀�ュ缃妗� */
+ export interface EmergencyPlan {
+ id?: number;
+ code?: string; // 棰勬缂栫爜
+ name?: string; // 棰勬鍚嶇О
+ planType?: number; // 棰勬绫诲瀷锛�1鍋滅數 2璁惧鏁呴殰 3鐏伨 4鑷劧鐏惧 5鍏朵粬
+ content?: string; // 澶勭疆鍐呭
+ orgUnit?: string; // 璐d换鍗曚綅
+ status?: number; // 鐘舵�侊細0鑽夌 10宸插彂甯�
+ remark?: string; // 澶囨敞
+ createTime?: string;
+ }
+}
+
+/** 鍒涘缓搴旀�ュ缃妗� */
+export function createPlan(data: MesProEmergencyPlanApi.EmergencyPlan) {
+ return requestClient.post('/mes/pro/emergency-plan/create', data);
+}
+
+/** 鏇存柊搴旀�ュ缃妗� */
+export function updatePlan(data: MesProEmergencyPlanApi.EmergencyPlan) {
+ return requestClient.put('/mes/pro/emergency-plan/update', data);
+}
+
+/** 鍒犻櫎搴旀�ュ缃妗� */
+export function deletePlan(ids: number[]) {
+ return requestClient.delete('/mes/pro/emergency-plan/delete', { params: { ids: ids.join(',') } });
+}
+
+/** 鑾峰彇搴旀�ュ缃妗� */
+export function getPlan(id: number) {
+ return requestClient.get<MesProEmergencyPlanApi.EmergencyPlan>(
+ `/mes/pro/emergency-plan/get?id=${id}`,
+ );
+}
+
+/** 鑾峰彇搴旀�ュ缃妗堝垎椤� */
+export function getPlanPage(params: PageParam) {
+ return requestClient.get<PageResult<MesProEmergencyPlanApi.EmergencyPlan>>(
+ '/mes/pro/emergency-plan/page',
+ { params },
+ );
+}
+
+/** 鍙戝竷搴旀�ュ缃妗� */
+export function publishPlan(id: number) {
+ return requestClient.put(`/mes/pro/emergency-plan/publish?id=${id}`);
+}
+
+/** 涓嬭浇搴旀�ュ缃妗堝鍏ユā鏉� */
+export function importPlanTemplate() {
+ return requestClient.download('/mes/pro/emergency-plan/get-import-template');
+}
+
+/** 瀵煎叆搴旀�ュ缃妗� */
+export function importPlan(file: File, updateSupport: boolean) {
+ return requestClient.upload(
+ `/mes/pro/emergency-plan/import?updateSupport=${updateSupport}`,
+ { file },
+ );
+}
diff --git a/src/components/import-modal/import-modal.vue b/src/components/import-modal/import-modal.vue
new file mode 100644
index 0000000..4ce97e0
--- /dev/null
+++ b/src/components/import-modal/import-modal.vue
@@ -0,0 +1,317 @@
+<script lang="ts" setup>
+import type { FileType } from 'ant-design-vue/es/upload/interface';
+
+import { h, ref } from 'vue';
+
+import { useVbenModal } from '@vben/common-ui';
+import { downloadFileFromBlobPart } from '@vben/utils';
+
+import { Button, message, Modal as AntModal, Upload } from 'ant-design-vue';
+
+import { useVbenForm, z } from '#/adapter/form';
+import { $t } from '#/locales';
+
+/**
+ * 瀵煎叆鎺ュ彛杩斿洖缁撴瀯銆�
+ *
+ * 鍚庣鍚勬ā鍧楃殑瀵煎叆杩斿洖鍊间笉缁熶竴锛岃繖閲屾弿杩板彲灞曠ず缁撴灉涓害瀹氭槑纭殑瀛楁锛�
+ * create* / update* / failure* 绛変笟鍔′笓鐢ㄥ瓧娈典細鍦ㄨ繍琛屾椂缁熶竴璇嗗埆銆�
+ */
+export interface ImportResultLike {
+ /** 琚烦杩囩殑琛岋細key 涓� Excel 琛屽彿锛寁alue 涓哄師鍥� */
+ skippedRows?: Record<string, string>;
+ /** 琚烦杩囩殑琛屾暟 */
+ skippedCount?: number;
+ /** Excel 涓疄闄呮湁鏁版嵁鐨勮鏁� */
+ totalRows?: number;
+ /** 鎴愬姛瀵煎叆鐨勮鏁� */
+ successRows?: number;
+ /** 鎴愬姛瀵煎叆鐨勬暟閲� */
+ successCount?: number;
+ /** 瀵煎叆澶辫触鐨勬暟閲� */
+ failureCount?: number;
+ /** 鍏跺畠妯″潡鐨勯�氱敤瀛楁锛氬け璐ュ垪琛� */
+ failureList?: Record<string, string> | string[];
+ /** 鍏跺畠妯″潡鐨勯�氱敤瀛楁锛氬け璐ュ師鍥� */
+ failureMessages?: Record<string, string> | string[];
+ [key: string]: unknown;
+}
+
+export interface ImportModalProps {
+ /** 寮圭獥鏍囬锛屽銆屽鍏ョ敤鎴枫�� */
+ title: string;
+ /** 涓嬭浇鐨勬ā鏉挎枃浠跺悕锛屽銆岀敤鎴峰鍏ユā鏉�.xls銆� */
+ fileName: string;
+ /** 鎵ц瀵煎叆鐨勬帴鍙e嚱鏁� (file, updateSupport) => Promise */
+ importFn: (file: File, updateSupport: boolean) => Promise<unknown>;
+ /** 涓嬭浇妯℃澘鐨勬帴鍙e嚱鏁� () => Promise(blob) */
+ templateFn: () => Promise<BlobPart>;
+}
+
+const emit = defineEmits(['success']);
+
+const config = ref<ImportModalProps>({
+ title: '',
+ fileName: '',
+ importFn: async () => {},
+ templateFn: () => Promise.resolve(new Blob()),
+});
+
+const [Form, formApi] = useVbenForm({
+ commonConfig: {
+ formItemClass: 'col-span-2',
+ labelWidth: 120,
+ },
+ layout: 'horizontal',
+ schema: [
+ {
+ fieldName: 'file',
+ label: '鏁版嵁鏂囦欢',
+ component: 'Upload',
+ rules: 'required',
+ help: '浠呭厑璁稿鍏� xls銆亁lsx 鏍煎紡鏂囦欢',
+ },
+ {
+ fieldName: 'updateSupport',
+ label: '鏄惁瑕嗙洊',
+ component: 'Switch',
+ componentProps: {
+ checkedChildren: '鏄�',
+ unCheckedChildren: '鍚�',
+ },
+ rules: z.boolean().default(false),
+ help: '鏄惁鏇存柊宸茬粡瀛樺湪鐨勬暟鎹�',
+ },
+ ],
+ showDefaultActions: false,
+});
+
+/**
+ * 浠庡鍏ユ帴鍙g殑杩斿洖鍊奸噷鎻愬彇鍙睍绀虹殑缁撴灉銆�
+ *
+ * 鍏抽敭鐐癸細涓嶈兘鍙湅鎺ュ彛鏈夋病鏈夋姤閿欏氨鎻愮ず銆屾搷浣滄垚鍔熴�嶁�斺�斿悗绔彲鑳借烦杩囦簡閮ㄥ垎琛岋紝
+ * 杩欎簺琛屼笉浼氭姏寮傚父锛屽繀椤绘妸璺宠繃/澶辫触鐨勬暟閲忓拰琛屽彿鏄庣‘鍛婅瘔鐢ㄦ埛锛屽惁鍒欐暟鎹棤澹颁涪澶便��
+ */
+function summarizeImportResult(raw: unknown) {
+ const result = unwrapImportResult(raw);
+
+ // 鍚勬ā鍧楀垎鍒繑鍥� createCodes銆乧reateContractNames銆乽pdateNames 绛夊瓧娈碉紝
+ // 涓嶈兘鎶婇�氱敤缁勪欢缁戝畾鍒版煇涓�涓笟鍔$殑瀛楁鍚嶃��
+ const successRows = firstNumber(result.successRows, result.successCount)
+ ?? countArrayFields(result, /^(?:create|update|success)(?!Count$)/i);
+
+ const failureEntries = collectEntries(result, /^failure(?!Count$)/i);
+ const skippedEntries = toEntries(result.skippedRows);
+ const failureRows = firstNumber(result.failureCount) ?? failureEntries.length;
+ const skippedRows = firstNumber(result.skippedCount) ?? skippedEntries.length;
+ const totalRows = firstNumber(result.totalRows);
+ const recognized = hasOutcomeFields(result);
+
+ if (failureRows > 0 && failureEntries.length === 0) {
+ failureEntries.push([`澶辫触 ${failureRows} 鏉, '鍚庣鏈繑鍥炲け璐ユ槑缁�']);
+ }
+ if (skippedRows > 0 && skippedEntries.length === 0) {
+ skippedEntries.push([`璺宠繃 ${skippedRows} 鏉, '鍚庣鏈繑鍥炶烦杩囨槑缁�']);
+ }
+
+ return {
+ successRows,
+ failureRows,
+ skippedRows,
+ failureEntries,
+ skippedEntries,
+ totalRows,
+ recognized,
+ hasIssue: failureRows > 0 || skippedRows > 0,
+ };
+}
+
+const OUTCOME_KEY_PATTERN = /^(?:create|update|success|failure|skipped|totalRows)/i;
+
+function hasOutcomeFields(result: ImportResultLike) {
+ return Object.keys(result).some((key) => OUTCOME_KEY_PATTERN.test(key));
+}
+
+/** requestClient 榛樿浼氳В鍖� data锛屽悓鏃跺吋瀹� Axios / CommonResult 鐨勫祵濂� data銆� */
+function unwrapImportResult(raw: unknown): ImportResultLike {
+ let current = raw;
+ for (let depth = 0; depth < 3; depth++) {
+ if (!current || typeof current !== 'object' || Array.isArray(current)) {
+ return {};
+ }
+ const result = current as ImportResultLike;
+ if (hasOutcomeFields(result)) {
+ return result;
+ }
+ current = result.data;
+ }
+ return {};
+}
+
+function firstNumber(...values: unknown[]): number | undefined {
+ return values.find((value): value is number => typeof value === 'number');
+}
+
+/** 姹囨�� create* / update* / success* 鏁扮粍鐨勯暱搴︺�� */
+function countArrayFields(result: ImportResultLike, keyPattern: RegExp) {
+ return Object.entries(result).reduce(
+ (total, [key, value]) =>
+ total + (keyPattern.test(key) && Array.isArray(value) ? value.length : 0),
+ 0,
+ );
+}
+
+/** 鍚堝苟 failure* 绛夌粨鏋滃瓧娈碉紝淇濈暀涓氬姟鍗曞彿鍙婂け璐ュ師鍥犮�� */
+function collectEntries(result: ImportResultLike, keyPattern: RegExp) {
+ return Object.entries(result).flatMap(([key, value]) =>
+ keyPattern.test(key) ? toEntries(value) : [],
+ );
+}
+
+/** 鎶� Record / string[] / undefined 缁熶竴鎴� [label, reason][] */
+function toEntries(input: unknown): Array<[string, string]> {
+ if (!input) {
+ return [];
+ }
+ if (Array.isArray(input)) {
+ return input.map((item) => [String(item), '']);
+ }
+ if (typeof input === 'object') {
+ return Object.entries(input as Record<string, string>).map(([k, v]) => [
+ k,
+ String(v ?? ''),
+ ]);
+ }
+ return [];
+}
+
+/** 鎶婄粨鏋滄嫾鎴愮敤鎴疯兘鐪嬫噦鐨勪竴娈佃瘽 */
+function buildResultMessage(summary: ReturnType<typeof summarizeImportResult>) {
+ const parts: string[] = [];
+ if (summary.successRows > 0) {
+ parts.push(`鎴愬姛 ${summary.successRows} 鏉);
+ }
+ if (summary.skippedRows > 0) {
+ parts.push(`璺宠繃 ${summary.skippedRows} 鏉);
+ }
+ if (summary.failureRows > 0) {
+ parts.push(`澶辫触 ${summary.failureRows} 鏉);
+ }
+ if (parts.length === 0) {
+ return summary.recognized
+ ? '瀵煎叆瀹屾垚锛屼絾娌℃湁鍙鐞嗙殑鏁版嵁'
+ : '瀵煎叆璇锋眰宸插畬鎴愶紝璇峰埛鏂板垪琛ㄧ‘璁ょ粨鏋�';
+ }
+ const total = summary.totalRows === undefined ? '' : `锛堣〃鏍煎叡 ${summary.totalRows} 琛岋級`;
+ return `瀵煎叆瀹屾垚锛�${parts.join('锛�')}${total}`;
+}
+
+const [Modal, modalApi] = useVbenModal({
+ async onOpenChange(isOpen: boolean) {
+ if (isOpen) {
+ config.value = modalApi.getData<ImportModalProps>() ?? config.value;
+ await formApi.resetForm();
+ }
+ },
+ async onConfirm() {
+ const { valid } = await formApi.validate();
+ if (!valid) {
+ return;
+ }
+ modalApi.lock();
+ // 鎻愪氦琛ㄥ崟
+ const data = await formApi.getValues();
+ try {
+ // 缁熶竴鍏滃簳锛氬悗绔悇妯″潡鍘嗗彶瀹炵幇瀵� updateSupport 鐨勬潵婧愪笉涓�鑷达紙鏈夌殑浠� query 璇汇��
+ // 鏈夌殑浠庤〃鍗曡锛夛紝婕忎紶浼氳 @NotNull 鎷︿笅骞跺脊鍑虹敤鎴锋牴鏈湅涓嶅埌瀵瑰簲瀛楁鐨�
+ // "鏄惁鏀寔鏇存柊涓嶈兘涓虹┖"銆傝繖閲屽己鍒舵樉寮忎紶甯冨皵鍊硷紝閬垮厤浠讳綍椤甸潰鍥犳湭鍒濆鍖栬俯鍧戙��
+ const updateSupport = data.updateSupport === true;
+ const raw = await config.value.importFn(data.file, updateSupport);
+ const summary = summarizeImportResult(raw);
+ const text = buildResultMessage(summary);
+
+ if (summary.hasIssue) {
+ // 鏈夎烦杩囨垨澶辫触鐨勮锛氫繚鎸佸脊绐楁墦寮�锛屾妸鏄庣粏灞曠ず缁欑敤鎴凤紝閬垮厤鏁版嵁鏃犲0涓㈠け
+ message.warning({
+ content: text,
+ duration: 8,
+ });
+ showDetail(summary);
+ emit('success');
+ return;
+ }
+
+ await modalApi.close();
+ emit('success');
+ message.success(text);
+ } finally {
+ modalApi.unlock();
+ }
+ },
+});
+
+/** 鐢� Modal.info 灞曠ず璺宠繃/澶辫触鏄庣粏锛屾瘮 toast 鏇磋�愯 */
+function showDetail(summary: ReturnType<typeof summarizeImportResult>) {
+ const sections: Array<{ title: string; rows: Array<[string, string]> }> = [];
+ if (summary.skippedEntries.length > 0) {
+ sections.push({ title: '琚烦杩囩殑琛岋紙鏈鍏ワ級', rows: summary.skippedEntries });
+ }
+ if (summary.failureEntries.length > 0) {
+ sections.push({ title: '瀵煎叆澶辫触', rows: summary.failureEntries });
+ }
+ AntModal.info({
+ title: '瀵煎叆缁撴灉鏄庣粏',
+ width: 560,
+ content: h(
+ 'div',
+ { style: 'max-height: 360px; overflow-y: auto;' },
+ sections.map((section) =>
+ h('div', { style: 'margin-bottom: 12px;' }, [
+ h('div', { style: 'font-weight: 600; margin-bottom: 4px;' }, section.title),
+ ...section.rows.map(([label, reason]) =>
+ h('div', { style: 'font-size: 13px; line-height: 20px;' }, [
+ h('span', { style: 'color: #cf1322;' }, `${label}`),
+ h('span', {}, `锛�${reason || '鏈鏄庡師鍥�'}`),
+ ]),
+ ),
+ ]),
+ ),
+ ),
+ });
+}
+
+/** 涓婁紶鍓� */
+function beforeUpload(file: FileType) {
+ formApi.setFieldValue('file', file);
+ return false;
+}
+
+/** 涓嬭浇妯$増 */
+async function handleDownload() {
+ const data = await config.value.templateFn();
+ downloadFileFromBlobPart({ fileName: config.value.fileName, source: data });
+}
+</script>
+
+<template>
+ <Modal :title="config.title" class="w-1/3">
+ <Form class="mx-4">
+ <template #file>
+ <div class="w-full">
+ <Upload
+ :max-count="1"
+ accept=".xls,.xlsx"
+ :before-upload="beforeUpload"
+ >
+ <Button type="primary"> 閫夋嫨 Excel 鏂囦欢 </Button>
+ </Upload>
+ </div>
+ </template>
+ </Form>
+ <template #prepend-footer>
+ <div class="flex flex-auto items-center">
+ <Button @click="handleDownload"> 涓嬭浇瀵煎叆妯℃澘 </Button>
+ </div>
+ </template>
+ </Modal>
+</template>
diff --git a/src/components/import-modal/index.ts b/src/components/import-modal/index.ts
new file mode 100644
index 0000000..d2bfb9c
--- /dev/null
+++ b/src/components/import-modal/index.ts
@@ -0,0 +1 @@
+export { default } from './import-modal.vue';
diff --git a/src/packages/constants/src/dict-enum.ts b/src/packages/constants/src/dict-enum.ts
index 1faab5f..082d48f 100644
--- a/src/packages/constants/src/dict-enum.ts
+++ b/src/packages/constants/src/dict-enum.ts
@@ -304,6 +304,7 @@
MES_EM_ALERT_TYPE: 'mes_em_alert_type', // MES 鑳借�楅璀︾被鍨�
MES_EM_ALERT_LEVEL: 'mes_em_alert_level', // MES 鑳借�楅璀︾骇鍒�
MES_EM_ALERT_STATUS: 'mes_em_alert_status', // MES 鑳借�楅璀﹀鐞嗙姸鎬�
+ MES_PRO_EMERGENCY_PLAN_TYPE: 'mes_pro_emergency_plan_type', // MES 搴旀�ュ缃妗堢被鍨�
} as const;
/** ========== WMS - 浠撳偍绠$悊妯″潡 ========== */
diff --git a/src/views/mes/pro/emergencyplan/data.ts b/src/views/mes/pro/emergencyplan/data.ts
new file mode 100644
index 0000000..04e599c
--- /dev/null
+++ b/src/views/mes/pro/emergencyplan/data.ts
@@ -0,0 +1,187 @@
+import type { VbenFormSchema } from '#/adapter/form';
+import type { VxeTableGridOptions } from '#/adapter/vxe-table';
+
+import { DICT_TYPE } from '@vben/constants';
+import { getDictOptions } from '@vben/hooks';
+
+/** 琛ㄥ崟绫诲瀷 */
+export type FormType = 'create' | 'detail' | 'edit';
+
+/** 鐘舵�佸父閲� */
+export const PLAN_STATUS = {
+ DRAFT: 0,
+ PUBLISHED: 10,
+};
+
+/** 琛ㄥ崟鐨勯厤缃」 */
+export function useFormSchema(formType: FormType): VbenFormSchema[] {
+ const isReadonly = formType === 'detail';
+ return [
+ {
+ fieldName: 'id',
+ component: 'Input',
+ dependencies: {
+ triggerFields: [''],
+ show: () => false,
+ },
+ },
+ {
+ fieldName: 'code',
+ label: '棰勬缂栫爜',
+ component: 'Input',
+ componentProps: {
+ placeholder: '绯荤粺鑷姩鐢熸垚',
+ disabled: true,
+ },
+ },
+ {
+ fieldName: 'name',
+ label: '棰勬鍚嶇О',
+ component: 'Input',
+ componentProps: {
+ placeholder: '璇疯緭鍏ラ妗堝悕绉�',
+ disabled: isReadonly,
+ },
+ rules: 'required',
+ },
+ {
+ fieldName: 'planType',
+ label: '棰勬绫诲瀷',
+ component: 'Select',
+ componentProps: {
+ options: getDictOptions(DICT_TYPE.MES_PRO_EMERGENCY_PLAN_TYPE, 'number'),
+ placeholder: '璇烽�夋嫨棰勬绫诲瀷',
+ disabled: isReadonly,
+ },
+ rules: 'selectRequired',
+ },
+ {
+ fieldName: 'orgUnit',
+ label: '璐d换鍗曚綅',
+ component: 'Input',
+ componentProps: {
+ placeholder: '璇疯緭鍏ヨ矗浠诲崟浣�/閮ㄩ棬',
+ disabled: isReadonly,
+ },
+ },
+ {
+ fieldName: 'content',
+ label: '澶勭疆鍐呭',
+ component: 'Textarea',
+ componentProps: {
+ placeholder: '璇疯緭鍏ュ簲鎬ュ缃唴瀹�',
+ rows: 4,
+ disabled: isReadonly,
+ },
+ formItemClass: 'col-span-3',
+ },
+ {
+ fieldName: 'remark',
+ label: '澶囨敞',
+ component: 'Textarea',
+ componentProps: {
+ placeholder: '璇疯緭鍏ュ娉�',
+ autoSize: { minRows: 1, maxRows: 1 },
+ disabled: isReadonly,
+ },
+ formItemClass: 'col-span-3',
+ },
+ ];
+}
+
+/** 鍒楄〃鐨勬悳绱㈣〃鍗� */
+export function useGridFormSchema(): VbenFormSchema[] {
+ return [
+ {
+ fieldName: 'code',
+ label: '棰勬缂栫爜',
+ component: 'Input',
+ componentProps: {
+ placeholder: '璇疯緭鍏ラ妗堢紪鐮�',
+ },
+ },
+ {
+ fieldName: 'name',
+ label: '棰勬鍚嶇О',
+ component: 'Input',
+ componentProps: {
+ placeholder: '璇疯緭鍏ラ妗堝悕绉�',
+ },
+ },
+ {
+ fieldName: 'planType',
+ label: '棰勬绫诲瀷',
+ component: 'Select',
+ componentProps: {
+ allowClear: true,
+ options: getDictOptions(DICT_TYPE.MES_PRO_EMERGENCY_PLAN_TYPE, 'number'),
+ placeholder: '璇烽�夋嫨棰勬绫诲瀷',
+ },
+ },
+ {
+ fieldName: 'status',
+ label: '鐘舵��',
+ component: 'Select',
+ componentProps: {
+ allowClear: true,
+ options: [
+ { label: '鑽夌', value: PLAN_STATUS.DRAFT },
+ { label: '宸插彂甯�', value: PLAN_STATUS.PUBLISHED },
+ ],
+ placeholder: '璇烽�夋嫨鐘舵��',
+ },
+ },
+ ];
+}
+
+/** 鍒楄〃鐨勮〃鏍煎垪 */
+export function useGridColumns(): VxeTableGridOptions['columns'] {
+ return [
+ { type: 'checkbox', width: 50 },
+ { type: 'seq', title: '搴忓彿', width: 60 },
+ {
+ field: 'code',
+ title: '棰勬缂栫爜',
+ minWidth: 150,
+ slots: { default: 'code' },
+ },
+ {
+ field: 'name',
+ title: '棰勬鍚嶇О',
+ minWidth: 200,
+ },
+ {
+ field: 'planType',
+ title: '棰勬绫诲瀷',
+ width: 110,
+ cellRender: {
+ name: 'CellDict',
+ props: { type: DICT_TYPE.MES_PRO_EMERGENCY_PLAN_TYPE },
+ },
+ },
+ {
+ field: 'orgUnit',
+ title: '璐d换鍗曚綅',
+ minWidth: 140,
+ },
+ {
+ field: 'status',
+ title: '鐘舵��',
+ width: 100,
+ slots: { default: 'status' },
+ },
+ {
+ field: 'createTime',
+ title: '鍒涘缓鏃堕棿',
+ width: 170,
+ formatter: 'formatDateTime',
+ },
+ {
+ field: 'action',
+ title: '鎿嶄綔',
+ width: 260,
+ fixed: 'right',
+ slots: { default: 'actions' },
+ },
+ ];
+}
diff --git a/src/views/mes/pro/emergencyplan/index.vue b/src/views/mes/pro/emergencyplan/index.vue
new file mode 100644
index 0000000..59e0944
--- /dev/null
+++ b/src/views/mes/pro/emergencyplan/index.vue
@@ -0,0 +1,218 @@
+<script lang="ts" setup>
+import type { VxeTableGridOptions } from '#/adapter/vxe-table';
+import type { MesProEmergencyPlanApi } from '#/api/mes/pro/emergencyplan';
+
+import { ref } from 'vue';
+
+import { Page, useVbenModal } from '@vben/common-ui';
+import { isEmpty } from '@vben/utils';
+
+import { message, Tag } from 'ant-design-vue';
+
+import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
+import {
+ deletePlan,
+ getPlanPage,
+ importPlan,
+ importPlanTemplate,
+ publishPlan,
+} from '#/api/mes/pro/emergencyplan';
+import ImportModalComponent from '#/components/import-modal';
+import { $t } from '#/locales';
+
+import { PLAN_STATUS, useGridColumns, useGridFormSchema } from './data';
+import Form from './modules/form.vue';
+
+/** MES 搴旀�ュ缃妗堝垪琛� */
+defineOptions({ name: 'MesProEmergencyPlan' });
+
+const [FormModal, formModalApi] = useVbenModal({
+ connectedComponent: Form,
+ destroyOnClose: true,
+});
+
+const [ImportModal, importModalApi] = useVbenModal({
+ connectedComponent: ImportModalComponent,
+ destroyOnClose: true,
+});
+
+function handleRefresh() {
+ gridApi.query();
+}
+
+function handleCreate() {
+ formModalApi.setData({ formType: 'create' }).open();
+}
+
+function handleEdit(row: MesProEmergencyPlanApi.EmergencyPlan) {
+ formModalApi.setData({ formType: 'edit', id: row.id }).open();
+}
+
+function handleDetail(row: MesProEmergencyPlanApi.EmergencyPlan) {
+ formModalApi.setData({ formType: 'detail', id: row.id }).open();
+}
+
+async function handleDelete(ids: number[]) {
+ const hideLoading = message.loading({
+ content: $t('ui.actionMessage.deleting'),
+ duration: 0,
+ });
+ try {
+ await deletePlan(ids);
+ message.success($t('ui.actionMessage.deleteSuccess'));
+ handleRefresh();
+ } finally {
+ hideLoading();
+ }
+}
+
+async function handlePublish(row: MesProEmergencyPlanApi.EmergencyPlan) {
+ await publishPlan(row.id!);
+ message.success('宸插彂甯�');
+ handleRefresh();
+}
+
+/** 瀵煎叆搴旀�ュ缃妗� */
+function handleImport() {
+ importModalApi
+ .setData({
+ title: $t('ui.actionTitle.import', ['搴旀�ュ缃妗�']),
+ fileName: '搴旀�ュ缃妗堝鍏ユā鏉�.xls',
+ importFn: importPlan,
+ templateFn: importPlanTemplate,
+ })
+ .open();
+}
+
+const checkedIds = ref<number[]>([]);
+function handleRowCheckboxChange({
+ records,
+}: {
+ records: MesProEmergencyPlanApi.EmergencyPlan[];
+}) {
+ checkedIds.value = records.map((item) => item.id!);
+}
+
+const [Grid, gridApi] = useVbenVxeGrid({
+ formOptions: {
+ schema: useGridFormSchema(),
+ },
+ gridOptions: {
+ columns: useGridColumns(),
+ height: 'auto',
+ keepSource: true,
+ proxyConfig: {
+ ajax: {
+ query: async ({ page }, formValues) => {
+ return await getPlanPage({
+ pageNo: page.currentPage,
+ pageSize: page.pageSize,
+ ...formValues,
+ });
+ },
+ },
+ },
+ rowConfig: {
+ keyField: 'id',
+ isHover: true,
+ },
+ toolbarConfig: {
+ refresh: true,
+ search: true,
+ },
+ } as VxeTableGridOptions<MesProEmergencyPlanApi.EmergencyPlan>,
+ gridEvents: {
+ checkboxAll: handleRowCheckboxChange,
+ checkboxChange: handleRowCheckboxChange,
+ },
+});
+</script>
+
+<template>
+ <Page auto-content-height>
+ <FormModal @success="handleRefresh" />
+ <ImportModal @success="handleRefresh" />
+ <Grid table-title="搴旀�ュ缃妗堝垪琛�">
+ <template #toolbar-tools>
+ <TableAction
+ :actions="[
+ {
+ label: $t('ui.actionTitle.create', ['搴旀�ュ缃妗�']),
+ type: 'primary',
+ icon: ACTION_ICON.ADD,
+ auth: ['mes:pro-emergency-plan:create'],
+ onClick: handleCreate,
+ },
+ {
+ label: $t('ui.actionTitle.import', ['搴旀�ュ缃妗�']),
+ icon: ACTION_ICON.UPLOAD,
+ auth: ['mes:pro-emergency-plan:import'],
+ onClick: handleImport,
+ },
+ {
+ label: '鎵归噺鍒犻櫎',
+ type: 'primary',
+ danger: true,
+ disabled: isEmpty(checkedIds),
+ icon: ACTION_ICON.DELETE,
+ auth: ['mes:pro-emergency-plan:delete'],
+ popConfirm: {
+ title: `鏄惁鍒犻櫎鎵�閫変腑鏁版嵁锛焋,
+ confirm: handleDelete.bind(null, checkedIds),
+ },
+ },
+ ]"
+ />
+ </template>
+ <template #code="{ row }">
+ <a class="link" @click="handleDetail(row)">{{ row.code }}</a>
+ </template>
+ <template #status="{ row }">
+ <Tag v-if="row.status === PLAN_STATUS.DRAFT" color="default">鑽夌</Tag>
+ <Tag v-else-if="row.status === PLAN_STATUS.PUBLISHED" color="success">宸插彂甯�</Tag>
+ </template>
+ <template #actions="{ row }">
+ <TableAction
+ :actions="[
+ {
+ label: $t('common.detail'),
+ type: 'link',
+ icon: ACTION_ICON.VIEW,
+ onClick: handleDetail.bind(null, row),
+ },
+ {
+ label: $t('common.edit'),
+ type: 'link',
+ icon: ACTION_ICON.EDIT,
+ auth: ['mes:pro-emergency-plan:update'],
+ ifShow: row.status === PLAN_STATUS.DRAFT,
+ onClick: handleEdit.bind(null, row),
+ },
+ {
+ label: '鍙戝竷',
+ type: 'link',
+ auth: ['mes:pro-emergency-plan:update'],
+ ifShow: row.status === PLAN_STATUS.DRAFT,
+ popConfirm: {
+ title: '纭鍙戝竷璇ラ妗堬紵',
+ confirm: handlePublish.bind(null, row),
+ },
+ },
+ {
+ label: $t('common.delete'),
+ type: 'link',
+ danger: true,
+ icon: ACTION_ICON.DELETE,
+ auth: ['mes:pro-emergency-plan:delete'],
+ ifShow: row.status === PLAN_STATUS.DRAFT,
+ popConfirm: {
+ title: $t('ui.actionMessage.deleteConfirm', [row.code]),
+ confirm: handleDelete.bind(null, [row.id!]),
+ },
+ },
+ ]"
+ />
+ </template>
+ </Grid>
+ </Page>
+</template>
diff --git a/src/views/mes/pro/emergencyplan/modules/form.vue b/src/views/mes/pro/emergencyplan/modules/form.vue
new file mode 100644
index 0000000..12a80ff
--- /dev/null
+++ b/src/views/mes/pro/emergencyplan/modules/form.vue
@@ -0,0 +1,91 @@
+<script lang="ts" setup>
+import type { MesProEmergencyPlanApi } from '#/api/mes/pro/emergencyplan';
+
+import { computed, ref } from 'vue';
+
+import { useVbenModal } from '@vben/common-ui';
+
+import { message } from 'ant-design-vue';
+
+import { useVbenForm } from '#/adapter/form';
+import { createPlan, getPlan, updatePlan } from '#/api/mes/pro/emergencyplan';
+import { $t } from '#/locales';
+
+import type { FormType } from '../data';
+import { useFormSchema } from '../data';
+
+const emit = defineEmits(['success']);
+const formData = ref<MesProEmergencyPlanApi.EmergencyPlan>();
+const formType = ref<FormType>('create');
+
+const getTitle = computed(() => {
+ if (formType.value === 'create') {
+ return $t('ui.actionTitle.create', ['搴旀�ュ缃妗�']);
+ } else if (formType.value === 'edit') {
+ return $t('ui.actionTitle.edit', ['搴旀�ュ缃妗�']);
+ } else {
+ return '搴旀�ュ缃妗堣鎯�';
+ }
+});
+
+const [Form, formApi] = useVbenForm({
+ commonConfig: {
+ componentProps: {
+ class: 'w-full',
+ },
+ labelWidth: 120,
+ },
+ wrapperClass: 'grid-cols-3',
+ layout: 'vertical',
+ schema: useFormSchema(formType.value),
+ showDefaultActions: false,
+});
+
+const [Modal, modalApi] = useVbenModal({
+ async onConfirm() {
+ const { valid } = await formApi.validate();
+ if (!valid) {
+ return;
+ }
+ modalApi.lock();
+ const data =
+ (await formApi.getValues()) as MesProEmergencyPlanApi.EmergencyPlan;
+ try {
+ await (formType.value === 'create'
+ ? createPlan(data)
+ : updatePlan(data));
+ await modalApi.close();
+ emit('success');
+ message.success($t('ui.actionMessage.operationSuccess'));
+ } finally {
+ modalApi.unlock();
+ }
+ },
+ async onOpenChange(isOpen: boolean) {
+ if (!isOpen) {
+ formData.value = undefined;
+ return;
+ }
+ const data = modalApi.getData<{ formType: FormType; id?: number }>();
+ formType.value = data.formType;
+ formApi.setDisabled(formType.value === 'detail');
+ formApi.updateSchema(useFormSchema(formType.value));
+ if (!data || !data.id) {
+ return;
+ }
+ modalApi.lock();
+ try {
+ formData.value = await getPlan(data.id);
+ await formApi.setValues(formData.value);
+ } finally {
+ modalApi.unlock();
+ }
+ },
+});
+</script>
+
+<template>
+ <Modal :title="getTitle" class="w-2/3" :show-confirm-button="formType !== 'detail'">
+ <Form class="mx-3" />
+ </Modal>
+</template>
--
Gitblit v1.9.3