transferConfigApi.vue
9.7 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
<template>
<div class="transfer-config-mode">
<BasicForm :showSubmitButton="false" @register="register">
<template #addKeyAndValue="{ field }">
<span style="display: none">{{ field }}</span>
<div>
<div>
<template v-for="(item, index) in keyAndValueArr" :key="index">
<span style="display: none">{{ item + index }}</span>
<BasicForm
:showResetButton="false"
:showSubmitButton="false"
@register="registerKeyAndValue"
/>
</template>
<div>
<a-button type="primary" class="mr-4" @click="addKeyAndValueFunc">添加</a-button>
<a-button color="error" @click="removeKeyAndValueFunc">删除</a-button>
</div>
</div>
</div>
</template>
<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 #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 #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>
</BasicForm>
</div>
</template>
<script lang="ts">
import { defineComponent, ref, reactive, nextTick } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { modeApiForm, modeApiInseretKeyAndValueForm, 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';
interface IKeyAndValue {
key: string;
value: string;
}
export default defineComponent({
components: {
BasicForm,
InboxOutlined,
[Upload.Dragger.name]: Upload.Dragger,
},
emits: ['next', 'prev', 'register'],
setup(_, { emit }) {
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 keyAndValueArr = ref<[]>([]);
const temp = ref({});
let tempObj = ref({});
const otherPropertiesValues = reactive({
headers: {},
});
const credentialsV: any = reactive({
credentials: {
type: '',
},
});
const keyAndValueArrTemp = ref<[]>([]);
const keyAndValueObj = reactive<IKeyAndValue>({
key: '',
value: '',
});
const sonValues: any = reactive({
configuration: {},
});
const [register, { validate, setFieldsValue, resetFields: defineClearFunc }] = useForm({
labelWidth: 80,
schemas: modeApiForm,
actionColOptions: {
span: 14,
},
resetButtonOptions: {
text: '上一步',
},
resetFunc: customResetFunc,
submitFunc: customSubmitFunc,
});
const [
registerKeyAndValue,
{ validate: validateKeyAndValue, resetFields: defineClearKeyAndValueFunc },
] = useForm({
labelWidth: 80,
schemas: modeApiInseretKeyAndValueForm,
actionColOptions: {
span: 14,
},
});
const setStepTwoFieldsValueFunc = (v, v1) => {
setFieldsValue(v);
setFieldsValue({
name: v1,
});
setFieldsValue({
password: v.credentials?.password,
username: v.credentials?.username,
type: v.credentials?.type,
});
fileList1.value = [{ name: v.credentials?.caCertFileName.slice(39) }];
fileList2.value = [{ name: v.credentials?.certFileName.slice(39) }];
fileList3.value = [{ name: v.credentials?.privateKeyFileName.slice(39) }];
};
const customClearStepTwoValueFunc = async () => {
nextTick(() => {
defineClearFunc();
defineClearKeyAndValueFunc();
fileList1.value = [];
fileList2.value = [];
fileList3.value = [];
caCertFileName.value = '';
privateKeyFileName.value = '';
certFileName.value = '';
});
};
async function customResetFunc() {
emit('prev');
}
async function customSubmitFunc() {
try {
const values = await validate();
emit('next', values);
} catch (error) {
} finally {
}
}
const tempGetKeyAndVal = async () => {
temp.value = await validateKeyAndValue();
};
const getDefaultValue = async () => {
await tempGetKeyAndVal();
keyAndValueArrTemp.value.push(temp.value as never);
};
const addKeyAndValueFunc = async () => {
keyAndValueArr.value.push(keyAndValueObj as never);
await tempGetKeyAndVal();
tempObj.value = temp.value;
keyAndValueArrTemp.value.push(tempObj.value as never);
};
const removeKeyAndValueFunc = () => {
keyAndValueArr.value.splice(0, 1);
};
/**
* 上传图片
*/
const handleChange = async (e, { file }) => {
if (file.status === 'removed') {
e == 'T'
? (fileList1.value = [])
: e == 'F'
? (fileList2.value = [])
: (fileList3.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) {
e == 'T'
? (caCertFileName.value = response.fileStaticUri)
: e == 'F'
? (certFileName.value = response.fileStaticUri)
: (privateKeyFileName.value = response.fileStaticUri);
}
}
}
};
const getSonValueFunc = async () => {
sonValues.configuration = await validate();
if (keyAndValueArrTemp.value.length != 0) {
await getDefaultValue();
}
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;
}
const kong = {};
let kongTemp = {};
keyAndValueArrTemp.value.map((item: any) => {
kong[item.key] = item.value;
});
kongTemp = JSON.parse(JSON.stringify(kong));
otherPropertiesValues.headers = kongTemp;
Object.assign(sonValues.configuration, otherPropertiesValues, credentialsV);
return sonValues;
};
return {
register,
setStepTwoFieldsValueFunc,
customClearStepTwoValueFunc,
addKeyAndValueFunc,
removeKeyAndValueFunc,
getSonValueFunc,
keyAndValueArr,
registerKeyAndValue,
handleChange,
fileList1,
fileList2,
fileList3,
caCertFileName,
privateKeyFileName,
certFileName,
};
},
});
</script>
<style lang="less" scoped>
:deep(.ant-col-24) {
margin-bottom: 20px !important;
}
</style>