|
@@ -38,7 +38,7 @@ |
|
@@ -38,7 +38,7 @@ |
38
|
import { ref, nextTick } from 'vue';
|
38
|
import { ref, nextTick } from 'vue';
|
39
|
import { Button } from 'ant-design-vue';
|
39
|
import { Button } from 'ant-design-vue';
|
40
|
import { TestEditCellTable } from '../TestEditCellTable/index';
|
40
|
import { TestEditCellTable } from '../TestEditCellTable/index';
|
41
|
- // import { otherHttp } from '/@/utils/http/axios';
|
41
|
+ import { otherHttp } from '/@/utils/http/axios';
|
42
|
|
42
|
|
43
|
const emits = defineEmits(['testInterface']);
|
43
|
const emits = defineEmits(['testInterface']);
|
44
|
|
44
|
|
|
@@ -81,6 +81,53 @@ |
|
@@ -81,6 +81,53 @@ |
81
|
return temps;
|
81
|
return temps;
|
82
|
};
|
82
|
};
|
83
|
|
83
|
|
|
|
84
|
+ //获取测试表格的key value 数组对象形式
|
|
|
85
|
+ const getTestTableKeyValue = () => {
|
|
|
86
|
+ return testEditCellTableRef.value?.getValue().map((it) => {
|
|
|
87
|
+ const value = it.key === 'scope' ? it.keyValue : it.value;
|
|
|
88
|
+ const key = it.key === 'scope' ? it.value : it.key;
|
|
|
89
|
+ return {
|
|
|
90
|
+ key,
|
|
|
91
|
+ value,
|
|
|
92
|
+ };
|
|
|
93
|
+ });
|
|
|
94
|
+ };
|
|
|
95
|
+
|
|
|
96
|
+ //格式化"http:xxxx/api/xx/{xx}/{xx}/{xx}这种格式"
|
|
|
97
|
+ String.prototype.restfulFormat = function (replacements) {
|
|
|
98
|
+ var formatString = function (str, replacements) {
|
|
|
99
|
+ replacements =
|
|
|
100
|
+ typeof replacements === 'object' ? replacements : Array.prototype.slice.call(arguments, 1);
|
|
|
101
|
+ return str.replace(/\{\{|\}\}|\{(\w+)\}/g, function (m, n) {
|
|
|
102
|
+ if (m == '{{') {
|
|
|
103
|
+ return '{';
|
|
|
104
|
+ }
|
|
|
105
|
+ if (m == '}}') {
|
|
|
106
|
+ return '}';
|
|
|
107
|
+ }
|
|
|
108
|
+ return replacements[n];
|
|
|
109
|
+ });
|
|
|
110
|
+ };
|
|
|
111
|
+ replacements =
|
|
|
112
|
+ typeof replacements === 'object' ? replacements : Array.prototype.slice.call(arguments, 0);
|
|
|
113
|
+ return formatString(this, replacements);
|
|
|
114
|
+ };
|
|
|
115
|
+
|
|
|
116
|
+ //项目自带第三方请求
|
|
|
117
|
+ const otherHttpRequest = async (apiType, params = {}, api, joinPrefix = false) => {
|
|
|
118
|
+ console.log(params);
|
|
|
119
|
+ switch (apiType) {
|
|
|
120
|
+ case 'get':
|
|
|
121
|
+ return await otherHttp.get(
|
|
|
122
|
+ { url: api },
|
|
|
123
|
+ {
|
|
|
124
|
+ apiUrl: '',
|
|
|
125
|
+ joinPrefix,
|
|
|
126
|
+ }
|
|
|
127
|
+ );
|
|
|
128
|
+ }
|
|
|
129
|
+ };
|
|
|
130
|
+
|
84
|
const getValue = async () => {
|
131
|
const getValue = async () => {
|
85
|
await nextTick();
|
132
|
await nextTick();
|
86
|
await nextTick(() => {
|
133
|
await nextTick(() => {
|
|
@@ -97,39 +144,15 @@ |
|
@@ -97,39 +144,15 @@ |
97
|
const handleExcute = async () => {
|
144
|
const handleExcute = async () => {
|
98
|
await nextTick();
|
145
|
await nextTick();
|
99
|
await nextTick(async () => {
|
146
|
await nextTick(async () => {
|
100
|
- const getTable = testEditCellTableRef.value?.getValue().map((it) => {
|
|
|
101
|
- const value = it.key === 'scope' ? it.keyValue : it.value;
|
|
|
102
|
- const key = it.key === 'scope' ? it.value : it.key;
|
|
|
103
|
- return {
|
|
|
104
|
- key,
|
|
|
105
|
- value,
|
|
|
106
|
- };
|
|
|
107
|
- });
|
147
|
+ const getTable = getTestTableKeyValue();
|
108
|
const apiGetUrl = `${props.data?.requestOriginUrl}${props.data?.requestUrl}`;
|
148
|
const apiGetUrl = `${props.data?.requestOriginUrl}${props.data?.requestUrl}`;
|
109
|
const apiType = props.data?.paramsType.toLowerCase();
|
149
|
const apiType = props.data?.paramsType.toLowerCase();
|
110
|
- console.log(apiType);
|
|
|
111
|
-
|
|
|
112
|
- const formatStr = (str, args) => {
|
|
|
113
|
- if (str.length == 0) return str;
|
|
|
114
|
- let formatStr = '';
|
|
|
115
|
- args?.forEach((it) => {
|
|
|
116
|
- formatStr = str.replace(RegExp('\\{' + it.key + '\\}'), it.value);
|
|
|
117
|
- });
|
|
|
118
|
- return formatStr;
|
|
|
119
|
- };
|
|
|
120
|
-
|
|
|
121
|
- const api = formatStr(apiGetUrl, getTable);
|
|
|
122
|
- console.log(api);
|
|
|
123
|
- // const rest = await otherHttp.get(
|
|
|
124
|
- // {
|
|
|
125
|
- // // url: api,
|
|
|
126
|
- // },
|
|
|
127
|
- // {
|
|
|
128
|
- // apiUrl: api,
|
|
|
129
|
- // joinPrefix: false,
|
|
|
130
|
- // }
|
|
|
131
|
- // );
|
|
|
132
|
- // console.log(rest);
|
150
|
+ const getKeyValues = {};
|
|
|
151
|
+ getTable?.map((it) => (getKeyValues[it.key!] = it.value!));
|
|
|
152
|
+ const formatApi = apiGetUrl.restfulFormat(getKeyValues);
|
|
|
153
|
+ const rest = await otherHttpRequest(apiType, {}, formatApi, false);
|
|
|
154
|
+ if (!rest) return;
|
|
|
155
|
+ testResult.value = rest;
|
133
|
});
|
156
|
});
|
134
|
};
|
157
|
};
|
135
|
|
158
|
|