transferConfigApi.vue
12 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<template>
<div class="transfer-config-mode">
<BasicForm :showSubmitButton="false" @register="register">
<template #uploadAdd1="{ field }">
<span style="display: none">{{ field }}</span>
<a-upload-dragger
v-model:fileList="fileList1"
name="file"
:multiple="false"
@change="handleChange('T', $event)"
:before-upload="() => false"
>
<p class="ant-upload-drag-icon">
<InboxOutlined />
</p>
<p class="ant-upload-text">点击或将文件拖拽到这里上传</p>
<p class="ant-upload-hint">
支持扩展名:.jpeg .png .jpg ...
<br />
文件大小:最大支持5M
</p>
</a-upload-dragger>
</template>
<template #showImg1="{ field }">
<span style="display: none">{{ field }}</span>
<img
v-if="showImg1"
:src="showImg1Pic"
alt="avatar"
style="width: 6.25rem; height: 6.25rem"
/>
</template>
<template #uploadAdd2="{ field }">
<span style="display: none">{{ field }}</span>
<a-upload-dragger
v-model:fileList="fileList2"
name="file"
:multiple="false"
@change="handleChange('F', $event)"
:before-upload="() => false"
>
<p class="ant-upload-drag-icon">
<InboxOutlined />
</p>
<p class="ant-upload-text">点击或将文件拖拽到这里上传</p>
<p class="ant-upload-hint">
支持扩展名:.jpeg .png .jpg ...
<br />
文件大小:最大支持5M
</p>
</a-upload-dragger>
</template>
<template #showImg2="{ field }">
<span style="display: none">{{ field }}</span>
<img
v-if="showImg2"
:src="showImg2Pic"
alt="avatar"
style="width: 6.25rem; height: 6.25rem"
/>
</template>
<template #uploadAdd3="{ field }">
<span style="display: none">{{ field }}</span>
<a-upload-dragger
v-model:fileList="fileList3"
name="file"
:multiple="false"
@change="handleChange('C', $event)"
:before-upload="() => false"
>
<p class="ant-upload-drag-icon">
<InboxOutlined />
</p>
<p class="ant-upload-text">点击或将文件拖拽到这里上传</p>
<p class="ant-upload-hint">
支持扩展名:.jpeg .png .jpg ...
<br />
文件大小:最大支持5M
</p>
</a-upload-dragger>
</template>
<template #showImg3="{ field }">
<span style="display: none">{{ field }}</span>
<img
v-if="showImg3"
:src="showImg3Pic"
alt="avatar"
style="width: 6.25rem; height: 6.25rem"
/>
</template>
</BasicForm>
</div>
</template>
<script lang="ts">
import { defineComponent, ref, reactive, nextTick } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { modeApiForm, CredentialsEnum } from '../config';
import { InboxOutlined } from '@ant-design/icons-vue';
import { Upload } from 'ant-design-vue';
import { useMessage } from '/@/hooks/web/useMessage';
import { uploadApi } from '/@/api/personal/index';
export default defineComponent({
components: {
BasicForm,
InboxOutlined,
[Upload.Dragger.name]: Upload.Dragger,
},
emits: ['next', 'prev', 'register'],
setup(_, { emit }) {
const showImg1 = ref(false);
const showImg1Pic = ref('');
const showImg2 = ref(false);
const showImg2Pic = ref('');
const showImg3 = ref(false);
const showImg3Pic = ref('');
const { createMessage } = useMessage();
let caCertFileName = ref('');
let privateKeyFileName = ref('');
let certFileName = ref('');
let fileList1: any = ref<[]>([]);
let fileList2: any = ref<[]>([]);
let fileList3: any = ref<[]>([]);
const credentialsV: any = reactive({
credentials: {
type: '',
},
});
const sonValues: any = reactive({
configuration: {},
});
const [register, { validate, setFieldsValue, resetFields: defineClearFunc }] = useForm({
labelWidth: 120,
schemas: modeApiForm,
actionColOptions: {
span: 14,
},
resetButtonOptions: {
text: '上一步',
},
resetFunc: customResetFunc,
submitFunc: customSubmitFunc,
});
const setStepTwoFieldsValueFunc = (v, v1, v2) => {
setFieldsValue(v);
setFieldsValue({
name: v1,
description: v2,
});
setFieldsValue({
password: v.credentials?.password,
username: v.credentials?.username,
type: v.credentials?.type,
});
fileList1.value = [{ name: v.credentials?.caCertFileName.slice(39), uid: '4' }];
fileList2.value = [{ name: v.credentials?.certFileName.slice(39), uid: '5' }];
fileList3.value = [{ name: v.credentials?.privateKeyFileName.slice(39), uid: '6' }];
caCertFileName.value = v.credentials?.caCertFileName;
certFileName.value = v.credentials?.certFileName;
privateKeyFileName.value = v.credentials?.privateKeyFileName;
const iscaCertFileNamePic = v.credentials?.caCertFileName.split('.').pop();
const iscertFileNamePic = v.credentials?.certFileName.split('.').pop();
const isprivateKeyFileNamePic = v.credentials?.privateKeyFileName.split('.').pop();
if (
iscaCertFileNamePic == 'jpg' ||
iscaCertFileNamePic == 'png' ||
iscaCertFileNamePic == 'jpeg' ||
iscaCertFileNamePic == 'gif'
) {
showImg1.value = true;
showImg1Pic.value = v.credentials?.caCertFileName;
} else {
showImg1.value = false;
}
if (
iscertFileNamePic == 'jpg' ||
iscertFileNamePic == 'png' ||
iscertFileNamePic == 'jpeg' ||
iscertFileNamePic == 'gif'
) {
showImg2.value = true;
showImg2Pic.value = v.credentials?.certFileName;
} else {
showImg2.value = false;
}
if (
isprivateKeyFileNamePic == 'jpg' ||
isprivateKeyFileNamePic == 'png' ||
isprivateKeyFileNamePic == 'jpeg' ||
isprivateKeyFileNamePic == 'gif'
) {
showImg3.value = true;
showImg3Pic.value = v.credentials?.privateKeyFileName;
} else {
showImg3.value = false;
}
};
const customClearStepTwoValueFunc = async () => {
nextTick(() => {
defineClearFunc();
fileList1.value = [];
fileList2.value = [];
fileList3.value = [];
caCertFileName.value = '';
privateKeyFileName.value = '';
certFileName.value = '';
showImg1.value = false;
showImg1Pic.value = '';
showImg2.value = false;
showImg2Pic.value = '';
showImg3.value = false;
showImg3Pic.value = '';
});
};
async function customResetFunc() {
emit('prev');
}
async function customSubmitFunc() {
try {
const values = await validate();
emit('next', values);
} catch (error) {
} finally {
}
}
/**
* 上传图片
*/
const handleChange = async (e, { file }) => {
if (file.status === 'removed') {
if (e == 'T') {
fileList1.value = [];
showImg1.value = false;
showImg1Pic.value = '';
caCertFileName.value = '';
} else if (e == 'F') {
fileList2.value = [];
showImg2.value = false;
showImg2Pic.value = '';
certFileName.value = '';
} else {
fileList3.value = [];
showImg3.value = false;
showImg3Pic.value = '';
privateKeyFileName.value = '';
}
} else {
const isLt5M = file.size / 1024 / 1024 < 5;
if (!isLt5M) {
createMessage.error('图片大小不能超过5MB!');
} else {
e == 'T'
? (fileList1.value = [file])
: e == 'F'
? (fileList2.value = [file])
: (fileList3.value = [file]);
const formData = new FormData();
formData.append('file', file);
const response = await uploadApi(formData);
if (response.fileStaticUri) {
if (e == 'T') {
caCertFileName.value = response.fileStaticUri;
const iscaCertFileNamePic = caCertFileName.value.split('.').pop();
if (
iscaCertFileNamePic == 'jpg' ||
iscaCertFileNamePic == 'png' ||
iscaCertFileNamePic == 'jpeg' ||
iscaCertFileNamePic == 'gif'
) {
showImg1.value = true;
showImg1Pic.value = response.fileStaticUri;
} else {
showImg1.value = false;
}
} else if (e == 'F') {
certFileName.value = response.fileStaticUri;
const iscertFileNamePic = certFileName.value.split('.').pop();
if (
iscertFileNamePic == 'jpg' ||
iscertFileNamePic == 'png' ||
iscertFileNamePic == 'jpeg' ||
iscertFileNamePic == 'gif'
) {
showImg2.value = true;
showImg2Pic.value = response.fileStaticUri;
} else {
showImg2.value = false;
}
} else {
privateKeyFileName.value = response.fileStaticUri;
const isprivateKeyFileNamePic = privateKeyFileName.value.split('.').pop();
if (
isprivateKeyFileNamePic == 'jpg' ||
isprivateKeyFileNamePic == 'png' ||
isprivateKeyFileNamePic == 'jpeg' ||
isprivateKeyFileNamePic == 'gif'
) {
showImg3.value = true;
showImg3Pic.value = response.fileStaticUri;
} else {
showImg3.value = false;
}
}
}
}
}
};
const getSonValueFunc = async () => {
sonValues.configuration = await validate();
credentialsV.credentials.type = sonValues.configuration.type;
if (credentialsV.credentials.type == CredentialsEnum.IS_BASIC) {
credentialsV.credentials.username = sonValues.configuration.username;
credentialsV.credentials.password = sonValues.configuration.password;
sonValues.configuration.username = undefined;
sonValues.configuration.password = undefined;
} else if (credentialsV.credentials.type == CredentialsEnum.IS_PEM) {
credentialsV.credentials.caCertFileName = caCertFileName.value;
credentialsV.credentials.certFileName = certFileName.value;
credentialsV.credentials.privateKeyFileName = privateKeyFileName.value;
credentialsV.credentials.password = sonValues.configuration.password;
}
Object.assign(sonValues.configuration, credentialsV);
return sonValues;
};
return {
register,
setStepTwoFieldsValueFunc,
customClearStepTwoValueFunc,
getSonValueFunc,
handleChange,
fileList1,
fileList2,
fileList3,
caCertFileName,
privateKeyFileName,
certFileName,
showImg1,
showImg1Pic,
showImg2,
showImg2Pic,
showImg3,
showImg3Pic,
};
},
});
</script>
<style lang="less" scoped>
:deep(.ant-col-24) {
margin-bottom: 20px !important;
}
:deep(.ant-btn-default) {
color: white;
background: #377dff;
}
</style>