index.vue
4.84 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
<template>
<div>
<Tabs @change="handleChange" v-model:activeKey="activeKey">
<TabPane class="tab-pane" forceRender key="Params" tab="Params">
<EditCellTable ref="editCellTableRef" :method="method" />
<TestRequest
@testInterface="handleTestInterface"
ref="testParRequestRef"
:method="method"
:requestOriginUrl="requestOriginUrl"
:requestUrl="requestUrl"
:data="dataMap.mapObj"
/>
</TabPane>
<TabPane
v-if="method !== '2' && paramsType !== 'GET'"
class="tab-pane"
forceRender
key="Body"
tab="Body"
>
<Body ref="bodyRef" :method="method" :paramsType="paramsType" :data="dataMap.mapObj" />
<TestRequest
@testInterface="handleTestInterface"
ref="testBodyRequestRef"
:method="method"
:requestOriginUrl="requestOriginUrl"
:requestUrl="requestUrl"
:data="dataMap.mapObj"
/>
</TabPane>
<TabPane v-if="method !== '2'" class="tab-pane" forceRender key="Header" tab="Header">
<EditCellTable ref="editHeaderCellTableRef" :method="method" />
<TestRequest
@testInterface="handleTestInterface"
ref="testHeaderRequestRef"
:method="method"
:requestOriginUrl="requestOriginUrl"
:requestUrl="requestUrl"
:data="dataMap.mapObj"
/>
</TabPane>
</Tabs>
</div>
</template>
<script lang="ts" setup name="simpleRequest">
import { ref, nextTick, reactive } from 'vue';
import { Tabs, TabPane } from 'ant-design-vue';
import { EditCellTable } from '../EditCellTable';
import Body from './body.vue';
import { TestRequest } from '../TestRequest/index';
const props = defineProps({
method: {
type: String,
},
paramsType: {
type: String,
},
requestOriginUrl: {
type: String,
},
requestUrl: {
type: String,
},
});
const emits = defineEmits(['activeKey']);
const activeKey = ref('Params');
const editCellTableRef = ref<InstanceType<typeof EditCellTable>>();
const editHeaderCellTableRef = ref<InstanceType<typeof EditCellTable>>();
const testParRequestRef = ref<InstanceType<typeof TestRequest>>();
const testBodyRequestRef = ref<InstanceType<typeof TestRequest>>();
const testHeaderRequestRef = ref<InstanceType<typeof TestRequest>>();
const dataMap: any = reactive({
mapObj: {},
});
const bodyRef = ref<InstanceType<typeof Body>>();
const handleChange = () => {
testParRequestRef.value?.setValue();
testHeaderRequestRef.value?.setValue();
testBodyRequestRef.value?.setValue();
};
const handleTestInterface = () => {
let value = getValue(false);
const type = value?.requestParamsBodyType;
if (type === 'none') value = [];
if (type === 'form-data') value = value['form-data'];
if (type === 'x-www-form-urlencoded') value = value['x-www-form-urlencoded'];
nextTick(
() =>
(dataMap.mapObj = {
list: value,
requestOriginUrl: props.requestOriginUrl,
requestUrl: props.requestUrl,
paramsType: props.paramsType,
})
);
};
//获取数据
const getValue = (status) => {
const type = activeKey.value;
const Body = bodyRef.value?.getValue();
const Params = editCellTableRef.value?.getValue();
const Header = editHeaderCellTableRef.value?.getValue();
status ? emits('activeKey', type) : null;
return type === 'Params' ? Params : type === 'Body' ? Body : Header;
};
//设置数据
const setValue = (data) => {
const Objects = JSON.parse(data?.requestParams);
nextTick(() => {
if (!Objects) return;
activeKey.value = Objects?.type;
if (activeKey.value === 'Params') {
editCellTableRef.value?.setValue(Objects?.Params);
testParRequestRef.value?.setValue();
} else if (activeKey.value === 'Body') {
bodyRef.value?.setValue(Objects?.Body);
testBodyRequestRef.value?.setValue();
} else if (activeKey.value === 'Header') {
editHeaderCellTableRef.value?.setValue(Objects?.Header);
testHeaderRequestRef.value?.setValue();
} else {
}
});
};
//重置数据
const resetValue = () => {
activeKey.value = 'Params';
nextTick(() => {
editCellTableRef.value?.resetValue();
editHeaderCellTableRef.value?.resetValue();
bodyRef.value?.resetValue();
handleChange();
});
};
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>