index.vue
5.77 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
<template>
<div>
<!--TODO: 待优化三者共存下的测试和是否能复用表格 -->
<Tabs @change="handleTabsChange" v-model:activeKey="activeKey">
<TabPane class="tab-pane" forceRender key="Params" tab="Params">
<ParamsTable ref="paramsCellTableRef" :method="method" />
<ParamsTest
@testParamsInterface="handleTestParamsInterface"
ref="testParamsRequestRef"
:data="dataMap.mapParamsObj"
/>
</TabPane>
<TabPane
v-if="method !== '2' && requestTypeAndUrl?.requestHttpType !== 'GET'"
class="tab-pane"
forceRender
key="Body"
tab="Body"
>
<Body ref="bodyRef" />
<ParamsTest
@testInterface="handleTestBodyInterface"
ref="testBodyRequestRef"
:data="dataMap.mapBodyObj"
/>
</TabPane>
<TabPane v-if="method !== '2'" class="tab-pane" forceRender key="Header" tab="Header">
<HeaderTable ref="editHeaderCellTableRef" :method="method" />
<HeaderTest
@testHeaderInterface="handleTestHeaderInterface"
ref="testHeaderRequestRef"
:data="dataMap.mapHeaderObj"
/>
</TabPane>
</Tabs>
<ExcuteTest ref="excuteTestRef" @emitExcute="handleEmitExcute" :data="excuteData" />
</div>
</template>
<script lang="ts" setup name="simpleRequest">
import { ref, nextTick, reactive } from 'vue';
import { Tabs, TabPane } from 'ant-design-vue';
import Body from './components/body.vue';
import { ParamsTest, HeaderTest } from '../TestInterface/index';
import HeaderTable from './components/headerTable.vue';
import ParamsTable from './components/paramsTable.vue';
import { isEmpty } from '/@/utils/is';
import { useUtils } from '../../hooks/useUtils';
import ExcuteTest from '../TestInterface/components/excuteTest.vue';
const props = defineProps({
method: {
type: String,
},
requestTypeAndUrl: {
type: Object,
},
requestOriginUrl: {
type: String,
},
});
const emits = defineEmits(['activeKey']);
const { pushObj } = useUtils();
const activeKey = ref('Params');
const excuteData = ref({});
const paramsCellTableRef = ref<InstanceType<typeof ParamsTable>>();
const editHeaderCellTableRef = ref<InstanceType<typeof ParamsTable>>();
const excuteTestRef = ref<InstanceType<typeof ExcuteTest>>();
const bodyRef = ref<InstanceType<typeof Body>>();
const testParamsRequestRef = ref<InstanceType<typeof ParamsTest>>();
const testBodyRequestRef = ref<InstanceType<typeof ParamsTest>>();
const testHeaderRequestRef = ref<InstanceType<typeof HeaderTest>>();
const dataMap: any = reactive({
mapParamsObj: {},
mapBodyObj: {},
mapHeaderObj: {},
});
const handleTabsChange = () => {
// testParamsRequestRef.value?.setValue();
// testBodyRequestRef.value?.setValue();
// testHeaderRequestRef.value?.setValue();
};
//if-else-if-else分支优化
const dataForTypeMap = [
[(type) => type === 'Params', (data) => paramsCellTableRef.value?.setValue(data)],
[(type) => type === 'Body', (data) => bodyRef.value?.setValue(data)],
[(type) => type === 'Header', (data) => editHeaderCellTableRef.value?.setValue(data)],
];
const handleEmitExcute = () => {
excuteData.value = {
Params: testParamsRequestRef.value?.getTestValue(),
Header: testHeaderRequestRef.value?.getTestValue(),
};
};
//TODO: 待优化这里测试接口
const handleTestParamsInterface = () => {
let value = getValue(false) as any;
dataMap.mapParamsObj = {
list: value?.Params,
requestOriginUrl: props.requestOriginUrl,
requestTypeAndUrl: props.requestTypeAndUrl,
method: props.method,
activeKey: activeKey.value,
};
};
const handleTestBodyInterface = () => {
let value = getValue(false) as any;
dataMap.mapBodyObj = {
list: value?.Body,
requestOriginUrl: props.requestOriginUrl,
requestTypeAndUrl: props.requestTypeAndUrl,
method: props.method,
activeKey: activeKey.value,
};
};
const handleTestHeaderInterface = () => {
let value = getValue(false) as any;
dataMap.mapHeaderObj = {
list: value?.Header,
requestOriginUrl: props.requestOriginUrl,
requestTypeAndUrl: props.requestTypeAndUrl,
method: props.method,
activeKey: activeKey.value,
};
};
//获取数据
const getValue = (status) => {
const type = activeKey.value;
status ? emits('activeKey', type) : null;
const Body = bodyRef.value?.getValue();
const Params = paramsCellTableRef.value?.getValue();
const Header = editHeaderCellTableRef.value?.getValue();
return {
Params,
Header,
Body,
};
};
//设置数据
const setValue = (data) => {
nextTick(() => {
const Objects = JSON.parse(data?.requestParams);
if (!Objects) return;
dataForTypeMap[0][1](isEmpty(Objects?.Params) ? [pushObj] : Objects?.Params);
dataForTypeMap[1][1](isEmpty(Objects?.Body) ? {} : Objects?.Body);
dataForTypeMap[2][1](isEmpty(Objects?.Header) ? [pushObj] : Objects?.Header);
});
};
//重置数据
const resetValue = () => {
activeKey.value = 'Params';
nextTick(() => {
paramsCellTableRef.value?.resetValue();
editHeaderCellTableRef.value?.resetValue();
bodyRef.value?.resetValue();
handleTabsChange();
});
};
defineExpose({
getValue,
setValue,
resetValue,
});
</script>
<style lang="less" scoped>
.tab-pane {
display: flex;
justify-content: flex-start;
flex-direction: column;
align-items: flex-start;
}
</style>