transferConfigKafka.vue
5.02 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
<template>
<div class="transfer-config-mode">
<BasicForm :showSubmitButton="false" @register="register">
<template #addValue="{ field }">
<span style="display: none">{{ field }}</span>
<div>
<div>
<div v-if="keyAndValueArr.length > 0">
<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>
<div>
<a-button type="primary" class="mr-4" @click="addKeyAndValueFunc">添加</a-button>
<a-button color="error" @click="removeKeyAndValueFunc">删除</a-button>
</div>
</div>
</div>
</template>
</BasicForm>
</div>
</template>
<script lang="ts">
import { defineComponent, ref, reactive, nextTick } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { modeKafkaForm, modeKafkaInseretKeyAndValueForm } from '../config';
import { Alert, Divider, Descriptions } from 'ant-design-vue';
interface IKeyAndValue {
key: string;
value: string;
}
export default defineComponent({
components: {
BasicForm,
[Alert.name]: Alert,
[Divider.name]: Divider,
[Descriptions.name]: Descriptions,
[Descriptions.Item.name]: Descriptions.Item,
},
emits: ['next', 'prev', 'register'],
setup(_, { emit }) {
const temp = ref({});
let tempObj = ref({});
const keyAndValueArr = ref<[]>([]);
const keyAndValueArrTemp = ref<[]>([]);
const vType = ref('');
const keyAndValueObj = reactive<IKeyAndValue>({
key: '',
value: '',
});
const sonValues = reactive({
configuration: {},
});
const otherPropertiesValues = reactive({
otherProperties: {},
});
const clearName = ref('');
const [register, { validate, setFieldsValue, resetFields: defineClearFunc, clearValidate }] =
useForm({
labelWidth: 80,
schemas: modeKafkaForm,
actionColOptions: {
span: 14,
},
resetButtonOptions: {
text: '上一步',
type: 'primary',
},
resetFunc: customResetFunc,
});
const [
registerKeyAndValue,
{ validate: validateKeyAndValue, resetFields: defineClearKeyAndValueFunc },
] = useForm({
labelWidth: 80,
schemas: modeKafkaInseretKeyAndValueForm,
actionColOptions: {
span: 14,
},
});
const clearValidateFunc = async () => {
await clearValidate(['name']);
};
const setStepTwoFieldsValueFunc = async (v, v1) => {
clearName.value = v1;
setFieldsValue(v);
vType.value = v1;
setFieldsValue({
name: v1,
});
};
const customClearStepTwoValueFunc = async () => {
nextTick(() => {
defineClearFunc();
defineClearKeyAndValueFunc();
});
};
async function customResetFunc() {
emit('prev');
}
const tempGetKeyAndVal = async () => {
temp.value = await validateKeyAndValue();
};
// const defaultAddKeyAndValueFunc = () => {
// if (keyAndValueArr.value.length == 0) {
// keyAndValueArr.value.push(keyAndValueObj as never);
// }
// };
// defaultAddKeyAndValueFunc();
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 getSonValueFunc = async () => {
try {
sonValues.configuration = await validate();
if (keyAndValueArrTemp.value.length != 0) {
await getDefaultValue();
}
const kong = {};
let kongTemp = {};
keyAndValueArrTemp.value.map((item: any) => {
kong[item.key] = item.value;
});
kongTemp = JSON.parse(JSON.stringify(kong));
otherPropertiesValues.otherProperties = kongTemp;
Object.assign(sonValues.configuration, otherPropertiesValues);
return sonValues;
} catch (e) {
return e;
}
};
return {
clearValidateFunc,
getSonValueFunc,
keyAndValueArr,
register,
setStepTwoFieldsValueFunc,
customClearStepTwoValueFunc,
addKeyAndValueFunc,
registerKeyAndValue,
removeKeyAndValueFunc,
customResetFunc,
};
},
});
</script>