excuteTest.vue
2.22 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
<template>
<div class="mt-8">
<div>
<Button disabled @click="handleExcute" type="primary"> 执行测试请求 </Button>
</div>
<!-- <div class="mt-8">
<a-row type="flex" justify="center">
<a-col :span="3"> 测试结果 </a-col>
<a-col :span="21">
<a-textarea
allow-clear
show-count
v-model:value="testResult"
placeholder="测试结果为:"
:rows="8"
/>
</a-col>
</a-row>
</div> -->
</div>
</template>
<script lang="ts" setup name="testRequest">
import { nextTick } from 'vue';
import { Button } from 'ant-design-vue';
// import { otherHttp } from '/@/utils/http/axios';
const emits = defineEmits(['emitExcute']);
const props = defineProps({
data: {
type: Object,
},
});
//格式化替换像"http:xxxx/api/xx/{xx}/{xx}/{xx}这种格式"
String.prototype.restfulFormat = function (replacements) {
var formatString = function (str, replacements) {
replacements =
typeof replacements === 'object' ? replacements : Array.prototype.slice.call(arguments, 1);
return str.replace(/\{\{|\}\}|\{(\w+)\}/g, function (m, n) {
if (m == '{{') {
return '{';
}
if (m == '}}') {
return '}';
}
return replacements[n];
});
};
replacements =
typeof replacements === 'object' ? replacements : Array.prototype.slice.call(arguments, 0);
return formatString(this, replacements);
};
// const testResult = ref('');
//执行测试接口
const handleExcute = () => {
emits('emitExcute');
getValue();
};
const getValue = async () => {
await nextTick();
console.log(props.data);
};
// //TODO: 待优化 项目自带第三方请求
// const otherHttpRequest = async (apiType, params = {}, api, joinPrefix = false) => {
// switch (apiType) {
// case 'GET':
// return await otherHttp.get(
// { url: api, params },
// {
// apiUrl: '',
// joinPrefix,
// }
// );
// }
// };
</script>
<style scoped lang="less"></style>