1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
| <script lang="ts" setup>
| import type { MesPdDocumentApi } from '#/api/mes/pd/document';
|
| import { ref } from 'vue';
|
| import { useVbenModal } from '#/packages/effects/common-ui/src';
| import { MesPdDocumentTypeEnum } from '#/packages/constants/src';
|
| import { message } from 'ant-design-vue';
|
| import { useVbenForm } from '#/adapter/form';
| import {
| createPdDocument,
| getPdDocument,
| updatePdDocument,
| } from '#/api/mes/pd/document';
| import { $t } from '#/locales';
|
| import { getPdDocumentTypeOptions } from '../data';
|
| const emit = defineEmits(['success']);
|
| const isUpdate = ref(false);
|
| const [Form, formApi] = useVbenForm({
| commonConfig: {
| componentProps: { class: 'w-full' },
| labelWidth: 100,
| },
| layout: 'horizontal',
| schema: [
| {
| fieldName: 'id',
| component: 'Input',
| dependencies: { triggerFields: [''], show: () => false },
| },
| {
| fieldName: 'projectId',
| component: 'Input',
| dependencies: { triggerFields: [''], show: () => false },
| },
| {
| fieldName: 'documentType',
| label: '资料类型',
| component: 'Select',
| componentProps: {
| options: getPdDocumentTypeOptions(),
| placeholder: '请选择资料类型',
| },
| rules: 'selectRequired',
| },
| {
| fieldName: 'name',
| label: '资料名称',
| component: 'Input',
| componentProps: { placeholder: '请输入资料名称' },
| rules: 'required',
| },
| {
| fieldName: 'version',
| label: '版本号',
| component: 'Input',
| componentProps: { placeholder: '如 V1.0' },
| rules: 'required',
| },
| {
| fieldName: 'fileUrl',
| label: '文件地址',
| component: 'Input',
| componentProps: { placeholder: '请输入文件 URL 或上传后填入' },
| },
| {
| fieldName: 'fileName',
| label: '文件名',
| component: 'Input',
| componentProps: { placeholder: '如 bom-list.xlsx' },
| },
| {
| fieldName: 'remark',
| label: '备注',
| component: 'Textarea',
| componentProps: { placeholder: '请输入备注', rows: 3 },
| },
| ],
| showDefaultActions: false,
| });
|
| const [Modal, modalApi] = useVbenModal({
| async onConfirm() {
| const { valid } = await formApi.validate();
| if (!valid) {
| return;
| }
| modalApi.lock();
| const data = (await formApi.getValues()) as MesPdDocumentApi.Document;
| try {
| if (isUpdate.value) {
| await updatePdDocument(data);
| } else {
| await createPdDocument(data);
| }
| emit('success');
| message.success($t('ui.actionMessage.operationSuccess'));
| await modalApi.close();
| } finally {
| modalApi.unlock();
| }
| },
| async onOpenChange(isOpen: boolean) {
| if (!isOpen) {
| return;
| }
| const data = modalApi.getData<{
| id?: number;
| projectId: number;
| documentType?: number;
| }>();
| isUpdate.value = !!data.id;
| modalApi.setState({ title: isUpdate.value ? '编辑附件' : '上传附件' });
| if (data.id) {
| modalApi.lock();
| try {
| const detail = await getPdDocument(data.id);
| await formApi.setValues(detail);
| } finally {
| modalApi.unlock();
| }
| return;
| }
| await formApi.setValues({
| projectId: data.projectId,
| documentType: data.documentType ?? MesPdDocumentTypeEnum.SCHEME,
| });
| },
| });
| </script>
|
| <template>
| <Modal class="w-[560px]">
| <Form class="mx-4" />
| </Modal>
| </template>
|
|