Showing
22 changed files
with
887 additions
and
396 deletions
@@ -6,6 +6,7 @@ export interface BigScreenCenterItemsModel { | @@ -6,6 +6,7 @@ export interface BigScreenCenterItemsModel { | ||
6 | createTime: string; | 6 | createTime: string; |
7 | creator: string; | 7 | creator: string; |
8 | remark: string; | 8 | remark: string; |
9 | + state: number; | ||
9 | } | 10 | } |
10 | export type queryPageParams = BasicPageParams & { | 11 | export type queryPageParams = BasicPageParams & { |
11 | name?: Nullable<string>; | 12 | name?: Nullable<string>; |
@@ -118,6 +118,7 @@ | @@ -118,6 +118,7 @@ | ||
118 | }; | 118 | }; |
119 | 119 | ||
120 | const handleDesign = (record: BigScreenCenterItemsModel) => { | 120 | const handleDesign = (record: BigScreenCenterItemsModel) => { |
121 | + if (record.state === 1) return; | ||
121 | window.open(`${largeDesignerPrefix}/#/chart/home/${record.id}`); | 122 | window.open(`${largeDesignerPrefix}/#/chart/home/${record.id}`); |
122 | }; | 123 | }; |
123 | 124 | ||
@@ -241,8 +242,9 @@ | @@ -241,8 +242,9 @@ | ||
241 | </Tooltip> | 242 | </Tooltip> |
242 | <Tooltip title="设计"> | 243 | <Tooltip title="设计"> |
243 | <AuthIcon | 244 | <AuthIcon |
244 | - v-if="item.state === 0" | ||
245 | - class="!text-lg" | 245 | + :class="`!text-lg ${ |
246 | + item.state === 1 ? '!cursor-not-allowed !text-gray-200' : '' | ||
247 | + }`" | ||
246 | icon="ant-design:edit-outlined" | 248 | icon="ant-design:edit-outlined" |
247 | @click="handleDesign(item)" | 249 | @click="handleDesign(item)" |
248 | /> | 250 | /> |
src/views/dataview/publicApi/components/EditCellTable/index.ts
deleted
100644 → 0
src/views/dataview/publicApi/components/SimpleRequest/components/body.vue
renamed from
src/views/dataview/publicApi/components/SimpleRequest/body.vue
@@ -13,18 +13,17 @@ | @@ -13,18 +13,17 @@ | ||
13 | placeholder="该接口没有 Body 体" | 13 | placeholder="该接口没有 Body 体" |
14 | :rows="2" | 14 | :rows="2" |
15 | /> | 15 | /> |
16 | - <EditCellTable | ||
17 | - ref="editCellTableRef" | ||
18 | - v-show=" | ||
19 | - getRequestBody.content.requestParamsBodyType === 'form-data' || | ||
20 | - getRequestBody.content.requestParamsBodyType === 'x-www-form-urlencoded' | ||
21 | - " | 16 | + <BodyTable |
17 | + ref="bodyCellFormDataTableRef" | ||
18 | + v-show="getRequestBody.content.requestParamsBodyType === 'form-data'" | ||
22 | /> | 19 | /> |
23 | - <a-textarea | ||
24 | - v-model:value="getRequestBody.content.json" | 20 | + <BodyTable |
21 | + ref="bodyCellXwwwTableRef" | ||
22 | + v-show="getRequestBody.content.requestParamsBodyType === 'x-www-form-urlencoded'" | ||
23 | + /> | ||
24 | + <JsonEditor | ||
25 | v-show="getRequestBody.content.requestParamsBodyType === 'json'" | 25 | v-show="getRequestBody.content.requestParamsBodyType === 'json'" |
26 | - placeholder="请输入json" | ||
27 | - :rows="6" | 26 | + ref="jsonEditorRef" |
28 | /> | 27 | /> |
29 | <a-textarea | 28 | <a-textarea |
30 | v-model:value="getRequestBody.content.xml" | 29 | v-model:value="getRequestBody.content.xml" |
@@ -37,20 +36,11 @@ | @@ -37,20 +36,11 @@ | ||
37 | </template> | 36 | </template> |
38 | <script lang="ts" setup name="body"> | 37 | <script lang="ts" setup name="body"> |
39 | import { reactive, ref, nextTick } from 'vue'; | 38 | import { reactive, ref, nextTick } from 'vue'; |
40 | - import { RequestBodyTypeEnum } from '../../enum/index'; | ||
41 | - import { EditCellTable } from '../EditCellTable/index'; | ||
42 | - | ||
43 | - defineProps({ | ||
44 | - method: { | ||
45 | - type: String, | ||
46 | - }, | ||
47 | - paramsType: { | ||
48 | - type: String, | ||
49 | - }, | ||
50 | - data: { | ||
51 | - type: Array || Object, | ||
52 | - }, | ||
53 | - }); | 39 | + import { RequestBodyTypeEnum } from '../../../enum/index'; |
40 | + import BodyTable from './bodyTable.vue'; | ||
41 | + import { isEmpty } from '/@/utils/is'; | ||
42 | + import { useUtils } from '../../../hooks/useUtils'; | ||
43 | + import JsonEditor from './jsonEditor.vue'; | ||
54 | 44 | ||
55 | const getRequestBody = reactive({ | 45 | const getRequestBody = reactive({ |
56 | content: { | 46 | content: { |
@@ -62,7 +52,13 @@ | @@ -62,7 +52,13 @@ | ||
62 | }, | 52 | }, |
63 | }); | 53 | }); |
64 | 54 | ||
65 | - const editCellTableRef = ref<InstanceType<typeof EditCellTable>>(); | 55 | + const { pushObj } = useUtils(); |
56 | + | ||
57 | + const bodyCellFormDataTableRef = ref<InstanceType<typeof BodyTable>>(); | ||
58 | + | ||
59 | + const jsonEditorRef = ref<InstanceType<typeof JsonEditor>>(); | ||
60 | + | ||
61 | + const bodyCellXwwwTableRef = ref<InstanceType<typeof BodyTable>>(); | ||
66 | 62 | ||
67 | const handleChange = ({ target }) => { | 63 | const handleChange = ({ target }) => { |
68 | const { value } = target; | 64 | const { value } = target; |
@@ -72,42 +68,39 @@ | @@ -72,42 +68,39 @@ | ||
72 | //获取数据 | 68 | //获取数据 |
73 | const getValue = () => { | 69 | const getValue = () => { |
74 | const type = Reflect.get(getRequestBody.content, 'requestParamsBodyType'); | 70 | const type = Reflect.get(getRequestBody.content, 'requestParamsBodyType'); |
71 | + const valuesFormData = bodyCellFormDataTableRef.value?.getValue(); | ||
72 | + const valuesXWww = bodyCellXwwwTableRef.value?.getValue(); | ||
73 | + const jsonEditorValue = jsonEditorRef.value?.getJsonValue(); | ||
74 | + getRequestBody.content['form-data'] = valuesFormData as any; | ||
75 | + getRequestBody.content['x-www-form-urlencoded'] = valuesXWww as any; | ||
76 | + getRequestBody.content['json'] = jsonEditorValue; | ||
75 | if (type === 'none') getRequestBody.content = {} as any; | 77 | if (type === 'none') getRequestBody.content = {} as any; |
76 | - const values = editCellTableRef.value?.getValue(); | ||
77 | - if (type === 'form-data') getRequestBody.content['form-data'] = values as any; | ||
78 | - if (type === 'x-www-form-urlencoded') | ||
79 | - getRequestBody.content['x-www-form-urlencoded'] = values as any; | ||
80 | return getRequestBody.content; | 78 | return getRequestBody.content; |
81 | }; | 79 | }; |
82 | 80 | ||
83 | //设置数据 | 81 | //设置数据 |
84 | - const setValue = (data) => { | ||
85 | - nextTick(() => { | ||
86 | - try { | ||
87 | - if (!data) return; | ||
88 | - const type = data?.requestParamsBodyType; | ||
89 | - getRequestBody.content.requestParamsBodyType = type; | ||
90 | - type === 'none' | ||
91 | - ? null | ||
92 | - : type === 'form-data' | ||
93 | - ? editCellTableRef.value?.setValue(data['form-data']) | ||
94 | - : type === 'x-www-form-urlencoded' | ||
95 | - ? editCellTableRef.value?.setValue(data['x-www-form-urlencoded']) | ||
96 | - : type === 'json' | ||
97 | - ? (getRequestBody.content.json = data['json']) | ||
98 | - : type === 'xml' | ||
99 | - ? (getRequestBody.content.xml = data['xml']) | ||
100 | - : ''; | ||
101 | - } finally { | ||
102 | - } | ||
103 | - }); | 82 | + const setValue = async (data) => { |
83 | + if (!data) return; | ||
84 | + const type = data?.requestParamsBodyType; | ||
85 | + getRequestBody.content.requestParamsBodyType = type; | ||
86 | + await nextTick(); | ||
87 | + await nextTick(); | ||
88 | + bodyCellFormDataTableRef.value?.setValue(isEmpty(data) ? [pushObj] : data['form-data']); | ||
89 | + bodyCellXwwwTableRef.value?.setValue(isEmpty(data) ? [pushObj] : data['x-www-form-urlencoded']); | ||
90 | + jsonEditorRef.value?.setJsonValue(data['json']); | ||
91 | + getRequestBody.content.xml = data['xml']; | ||
104 | }; | 92 | }; |
105 | 93 | ||
106 | //重置数据 | 94 | //重置数据 |
107 | const resetValue = () => { | 95 | const resetValue = () => { |
108 | for (let i in getRequestBody.content) Reflect.set(getRequestBody.content, i, ''); | 96 | for (let i in getRequestBody.content) Reflect.set(getRequestBody.content, i, ''); |
97 | + getRequestBody.content['form-data'] = {}; | ||
98 | + getRequestBody.content['x-www-form-urlencoded'] = {}; | ||
109 | getRequestBody.content.requestParamsBodyType = 'none'; | 99 | getRequestBody.content.requestParamsBodyType = 'none'; |
110 | - nextTick(() => editCellTableRef?.value?.resetValue()); | 100 | + nextTick(() => { |
101 | + bodyCellFormDataTableRef?.value?.resetValue(); | ||
102 | + bodyCellXwwwTableRef?.value?.resetValue(); | ||
103 | + }); | ||
111 | }; | 104 | }; |
112 | defineExpose({ | 105 | defineExpose({ |
113 | getValue, | 106 | getValue, |
src/views/dataview/publicApi/components/SimpleRequest/components/bodyTable.vue
renamed from
src/views/dataview/publicApi/components/EditCellTable/index.vue
@@ -58,8 +58,8 @@ | @@ -58,8 +58,8 @@ | ||
58 | import { Select, Button } from 'ant-design-vue'; | 58 | import { Select, Button } from 'ant-design-vue'; |
59 | import { findDictItemByCode } from '/@/api/system/dict'; | 59 | import { findDictItemByCode } from '/@/api/system/dict'; |
60 | import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue'; | 60 | import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue'; |
61 | - import { editCellTableTHeadConfig } from '../../config'; | ||
62 | - import { selectType, tableItems } from '../../types'; | 61 | + import { editCellTableTHeadConfig } from '../../../config'; |
62 | + import { selectType, tableItems } from '../../../types'; | ||
63 | 63 | ||
64 | defineProps({ | 64 | defineProps({ |
65 | method: { | 65 | method: { |
@@ -144,7 +144,7 @@ | @@ -144,7 +144,7 @@ | ||
144 | const assemblyData = tableArray.content.map((it) => { | 144 | const assemblyData = tableArray.content.map((it) => { |
145 | return { | 145 | return { |
146 | key: it.key, | 146 | key: it.key, |
147 | - value: it?.key === 'date_range' ? `${it.date1},${it.date2}` : it.value, | 147 | + value: it.key === 'date_range' ? `${it.date1},${it.date2}` : it.value, |
148 | editDisabled: it.editDisabled, | 148 | editDisabled: it.editDisabled, |
149 | required: it.required, | 149 | required: it.required, |
150 | }; | 150 | }; |
src/views/dataview/publicApi/components/SimpleRequest/components/headerTable.vue
renamed from
src/views/dataview/publicApi/components/SimpleRequest/header.vue
@@ -19,6 +19,9 @@ | @@ -19,6 +19,9 @@ | ||
19 | <a-input style="width: 12vw" placeholder="请输入" v-model:value="item.value" /> | 19 | <a-input style="width: 12vw" placeholder="请输入" v-model:value="item.value" /> |
20 | </td> | 20 | </td> |
21 | <td style="width: 4vw"> | 21 | <td style="width: 4vw"> |
22 | + <a-switch v-model:checked="item.required" /> | ||
23 | + </td> | ||
24 | + <td style="width: 4vw"> | ||
22 | <div> | 25 | <div> |
23 | <Button type="dashed" @click="add(item, index)"> | 26 | <Button type="dashed" @click="add(item, index)"> |
24 | <template #icon><PlusOutlined /></template | 27 | <template #icon><PlusOutlined /></template |
@@ -37,8 +40,8 @@ | @@ -37,8 +40,8 @@ | ||
37 | import { reactive, nextTick } from 'vue'; | 40 | import { reactive, nextTick } from 'vue'; |
38 | import { Button } from 'ant-design-vue'; | 41 | import { Button } from 'ant-design-vue'; |
39 | import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue'; | 42 | import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue'; |
40 | - import { editTestCellTableTHeaderConfig } from '../../config'; | ||
41 | - import { tableItems } from '../../types'; | 43 | + import { editTestCellTableTHeaderConfig } from '../../../config'; |
44 | + import { tableItems } from '../../../types'; | ||
42 | 45 | ||
43 | defineProps({ | 46 | defineProps({ |
44 | method: { | 47 | method: { |
@@ -53,6 +56,7 @@ | @@ -53,6 +56,7 @@ | ||
53 | { | 56 | { |
54 | key: '', | 57 | key: '', |
55 | value: '', | 58 | value: '', |
59 | + required: false, | ||
56 | }, | 60 | }, |
57 | ], | 61 | ], |
58 | }); | 62 | }); |
@@ -62,6 +66,7 @@ | @@ -62,6 +66,7 @@ | ||
62 | tableArray.content.splice(index + 1, 0, { | 66 | tableArray.content.splice(index + 1, 0, { |
63 | key: '', | 67 | key: '', |
64 | value: '', | 68 | value: '', |
69 | + required: false, | ||
65 | }); | 70 | }); |
66 | }; | 71 | }; |
67 | 72 | ||
@@ -89,8 +94,8 @@ | @@ -89,8 +94,8 @@ | ||
89 | tableArray.content.push({ | 94 | tableArray.content.push({ |
90 | key: '', | 95 | key: '', |
91 | value: '', | 96 | value: '', |
97 | + required: false, | ||
92 | }); | 98 | }); |
93 | - nextTick(() => {}); | ||
94 | }; | 99 | }; |
95 | defineExpose({ | 100 | defineExpose({ |
96 | getValue, | 101 | getValue, |
1 | +<template> | ||
2 | + <div ref="jsoneditorRef" style="height: 100%; width: 100%"></div> | ||
3 | +</template> | ||
4 | + | ||
5 | +<script lang="ts" setup> | ||
6 | + import { ref, onMounted, nextTick, unref } from 'vue'; | ||
7 | + import jsoneditor from 'jsoneditor'; | ||
8 | + import 'jsoneditor/dist/jsoneditor.min.css'; | ||
9 | + | ||
10 | + // json 以及初始化JSON | ||
11 | + const jsoneditorRef = ref(); | ||
12 | + | ||
13 | + const jsonValue = ref({}); | ||
14 | + | ||
15 | + const jsonInstance = ref(); | ||
16 | + | ||
17 | + onMounted(() => { | ||
18 | + nextTick(() => { | ||
19 | + let options = { | ||
20 | + mode: 'code', | ||
21 | + mainMenuBar: false, | ||
22 | + statusBar: false, | ||
23 | + }; | ||
24 | + let editor = new jsoneditor(jsoneditorRef.value, options); | ||
25 | + editor.set(jsonValue.value); | ||
26 | + jsonInstance.value = editor; | ||
27 | + }); | ||
28 | + }); | ||
29 | + | ||
30 | + const getJsonValue = () => unref(jsonInstance).get(); | ||
31 | + | ||
32 | + const setJsonValue = (Json) => { | ||
33 | + nextTick(() => { | ||
34 | + unref(jsonInstance).set(Json); | ||
35 | + }); | ||
36 | + }; | ||
37 | + | ||
38 | + defineExpose({ | ||
39 | + getJsonValue, | ||
40 | + setJsonValue, | ||
41 | + jsonInstance, | ||
42 | + }); | ||
43 | +</script> | ||
44 | + | ||
45 | +<style> | ||
46 | + .jsoneditor { | ||
47 | + border: none; | ||
48 | + } | ||
49 | +</style> |
1 | +<template> | ||
2 | + <div class="table-content"> | ||
3 | + <!-- 采用的原生表格 --> | ||
4 | + <table align="center"> | ||
5 | + <thead> | ||
6 | + <tr> | ||
7 | + <th v-for="item in editCellTableTHeadConfig" :key="item">{{ item }}</th> | ||
8 | + </tr> | ||
9 | + </thead> | ||
10 | + <tbody> | ||
11 | + <tr v-for="(item, index) in tableArray.content" :key="index"> | ||
12 | + <td> | ||
13 | + {{ index + 1 }} | ||
14 | + </td> | ||
15 | + <td style="width: 12vw"> | ||
16 | + <Select | ||
17 | + v-model:value="item.key" | ||
18 | + placeholder="请选择" | ||
19 | + :options="selectOptions" | ||
20 | + @change="handleChange" | ||
21 | + allowClear | ||
22 | + /> | ||
23 | + </td> | ||
24 | + <td style="width: 12vw"> | ||
25 | + <div v-if="item.key === 'date_range'"> | ||
26 | + <a-input style="width: 6vw" placeholder="请输入" v-model:value="item.date1" /> | ||
27 | + <span>~</span> | ||
28 | + <a-input style="width: 6vw" placeholder="请输入" v-model:value="item.date2" /> | ||
29 | + </div> | ||
30 | + <div v-else> | ||
31 | + <a-input | ||
32 | + :disabled="item.editDisabled" | ||
33 | + placeholder="请输入" | ||
34 | + v-model:value="item.value" | ||
35 | + /> | ||
36 | + </div> | ||
37 | + </td> | ||
38 | + <td style="width: 4vw"> | ||
39 | + <a-switch v-model:checked="item.required" /> | ||
40 | + </td> | ||
41 | + <td style="width: 4vw"> | ||
42 | + <div> | ||
43 | + <Button type="dashed" @click="add(item, index)"> | ||
44 | + <template #icon><PlusOutlined /></template | ||
45 | + ></Button> | ||
46 | + <Button type="dashed" style="margin-left: 5px" @click="remove(item, index)"> | ||
47 | + <template #icon> <MinusOutlined /></template> | ||
48 | + </Button> | ||
49 | + </div> | ||
50 | + </td> | ||
51 | + </tr> | ||
52 | + </tbody> | ||
53 | + </table> | ||
54 | + </div> | ||
55 | +</template> | ||
56 | +<script lang="ts" setup name="editCellTable"> | ||
57 | + import { reactive, ref, onMounted, nextTick } from 'vue'; | ||
58 | + import { Select, Button } from 'ant-design-vue'; | ||
59 | + import { findDictItemByCode } from '/@/api/system/dict'; | ||
60 | + import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue'; | ||
61 | + import { editCellTableTHeadConfig } from '../../../config'; | ||
62 | + import { selectType, tableItems } from '../../../types'; | ||
63 | + | ||
64 | + defineProps({ | ||
65 | + method: { | ||
66 | + type: String, | ||
67 | + }, | ||
68 | + }); | ||
69 | + | ||
70 | + const selectOptions = ref<selectType[]>([]); | ||
71 | + | ||
72 | + onMounted(() => { | ||
73 | + getSelectOptions(); | ||
74 | + }); | ||
75 | + | ||
76 | + const getSelectOptions = async () => { | ||
77 | + const res = await findDictItemByCode({ dictCode: 'dataview_builtin_params' }); | ||
78 | + selectOptions.value = res.map((m) => ({ label: m.itemText, value: m.itemValue })); | ||
79 | + selectOptions.value.push({ | ||
80 | + label: '自定义', | ||
81 | + value: 'scope', | ||
82 | + }); | ||
83 | + }; | ||
84 | + | ||
85 | + const tableArray = reactive<{ | ||
86 | + content: tableItems[]; | ||
87 | + }>({ | ||
88 | + content: [ | ||
89 | + { | ||
90 | + key: undefined, | ||
91 | + value: '', | ||
92 | + editDisabled: false, | ||
93 | + required: false, | ||
94 | + date1: '', | ||
95 | + date2: '', | ||
96 | + }, | ||
97 | + ], | ||
98 | + }); | ||
99 | + | ||
100 | + // 新增 | ||
101 | + const add = (_, index: number) => { | ||
102 | + tableArray.content.splice(index + 1, 0, { | ||
103 | + key: undefined, | ||
104 | + value: '', | ||
105 | + editDisabled: false, | ||
106 | + required: false, | ||
107 | + date1: '', | ||
108 | + date2: '', | ||
109 | + }); | ||
110 | + }; | ||
111 | + | ||
112 | + // 减少 | ||
113 | + const remove = (item, index: number) => { | ||
114 | + if (tableArray.content.length !== 1) { | ||
115 | + selectOptions.value.forEach((ele) => { | ||
116 | + if (ele.value == item.key) { | ||
117 | + ele.disabled = false; | ||
118 | + } | ||
119 | + }); | ||
120 | + tableArray.content.splice(index, 1); | ||
121 | + } | ||
122 | + }; | ||
123 | + | ||
124 | + //Select互斥 | ||
125 | + const handleChange = () => { | ||
126 | + selectOptions.value.forEach((ele) => { | ||
127 | + ele.disabled = false; | ||
128 | + tableArray.content.forEach((element) => { | ||
129 | + if (element.key === 'scope' || element.key === 'fixed_date') { | ||
130 | + element.editDisabled = false; | ||
131 | + } else { | ||
132 | + element.value = ''; | ||
133 | + element.editDisabled = true; | ||
134 | + } | ||
135 | + if (element.key === ele.value && element.key !== 'scope' && element.key !== 'fixed_date') { | ||
136 | + ele.disabled = true; | ||
137 | + } | ||
138 | + }); | ||
139 | + }); | ||
140 | + }; | ||
141 | + | ||
142 | + //获取数据 | ||
143 | + const getValue = () => { | ||
144 | + const assemblyData = tableArray.content.map((it) => { | ||
145 | + return { | ||
146 | + key: it.key, | ||
147 | + value: it.key === 'date_range' ? `${it.date1},${it.date2}` : it.value, | ||
148 | + editDisabled: it.editDisabled, | ||
149 | + required: it.required, | ||
150 | + }; | ||
151 | + }); | ||
152 | + return assemblyData; | ||
153 | + }; | ||
154 | + | ||
155 | + //设置数据 | ||
156 | + const setValue = async (data) => { | ||
157 | + await nextTick(); | ||
158 | + const assemblyData = data.map((it) => { | ||
159 | + return { | ||
160 | + key: it.key, | ||
161 | + value: it.value, | ||
162 | + editDisabled: it.editDisabled, | ||
163 | + required: it.required, | ||
164 | + date1: it.key === 'date_range' ? it.value?.split(',')?.at(-2) : '', | ||
165 | + date2: it.key === 'date_range' ? it.value?.split(',')?.at(-1) : '', | ||
166 | + }; | ||
167 | + }); | ||
168 | + tableArray.content = assemblyData; | ||
169 | + tableArray.content.forEach(() => { | ||
170 | + handleChange(); | ||
171 | + }); | ||
172 | + }; | ||
173 | + | ||
174 | + //重置数据 | ||
175 | + const resetValue = () => { | ||
176 | + tableArray.content = []; | ||
177 | + tableArray.content.push({ | ||
178 | + key: undefined, | ||
179 | + value: '', | ||
180 | + editDisabled: false, | ||
181 | + required: false, | ||
182 | + date1: '', | ||
183 | + date2: '', | ||
184 | + }); | ||
185 | + nextTick(() => { | ||
186 | + tableArray.content.forEach(() => { | ||
187 | + handleChange(); | ||
188 | + }); | ||
189 | + }); | ||
190 | + }; | ||
191 | + defineExpose({ | ||
192 | + getValue, | ||
193 | + setValue, | ||
194 | + resetValue, | ||
195 | + }); | ||
196 | +</script> | ||
197 | + | ||
198 | +<style scoped lang="less"> | ||
199 | + @table-color: #e5e7eb; | ||
200 | + | ||
201 | + .table-border-color { | ||
202 | + border: 1px solid #e5e7eb; | ||
203 | + text-align: center; | ||
204 | + } | ||
205 | + | ||
206 | + .table-content { | ||
207 | + overflow-x: auto; | ||
208 | + | ||
209 | + table { | ||
210 | + border-collapse: collapse; | ||
211 | + width: 35vw; | ||
212 | + &:extend(.table-border-color); | ||
213 | + } | ||
214 | + | ||
215 | + table thead { | ||
216 | + white-space: nowrap; | ||
217 | + } | ||
218 | + | ||
219 | + table td { | ||
220 | + padding: 5px; | ||
221 | + white-space: nowrap; | ||
222 | + &:extend(.table-border-color); | ||
223 | + } | ||
224 | + | ||
225 | + table th { | ||
226 | + padding: 5px; | ||
227 | + &:extend(.table-border-color); | ||
228 | + } | ||
229 | + } | ||
230 | +</style> |
1 | <template> | 1 | <template> |
2 | <div> | 2 | <div> |
3 | + <!--TODO: 待优化三者共存下的测试和是否能复用表格 --> | ||
3 | <Tabs @change="handleTabsChange" v-model:activeKey="activeKey"> | 4 | <Tabs @change="handleTabsChange" v-model:activeKey="activeKey"> |
4 | <TabPane class="tab-pane" forceRender key="Params" tab="Params"> | 5 | <TabPane class="tab-pane" forceRender key="Params" tab="Params"> |
5 | - <EditCellTable ref="editParamsCellTableRef" :method="method" /> | 6 | + <ParamsTable ref="paramsCellTableRef" :method="method" /> |
7 | + <ParamsTest | ||
8 | + @testParamsInterface="handleTestParamsInterface" | ||
9 | + ref="testParamsRequestRef" | ||
10 | + :data="dataMap.mapParamsObj" | ||
11 | + /> | ||
6 | </TabPane> | 12 | </TabPane> |
7 | <TabPane | 13 | <TabPane |
8 | v-if="method !== '2' && requestTypeAndUrl?.requestHttpType !== 'GET'" | 14 | v-if="method !== '2' && requestTypeAndUrl?.requestHttpType !== 'GET'" |
@@ -11,36 +17,35 @@ | @@ -11,36 +17,35 @@ | ||
11 | key="Body" | 17 | key="Body" |
12 | tab="Body" | 18 | tab="Body" |
13 | > | 19 | > |
14 | - <Body | ||
15 | - ref="bodyRef" | ||
16 | - :method="method" | ||
17 | - :paramsType="requestTypeAndUrl?.requestHttpType" | ||
18 | - :data="dataMap.mapObj" | 20 | + <Body ref="bodyRef" /> |
21 | + <ParamsTest | ||
22 | + @testInterface="handleTestBodyInterface" | ||
23 | + ref="testBodyRequestRef" | ||
24 | + :data="dataMap.mapBodyObj" | ||
19 | /> | 25 | /> |
20 | </TabPane> | 26 | </TabPane> |
21 | <TabPane v-if="method !== '2'" class="tab-pane" forceRender key="Header" tab="Header"> | 27 | <TabPane v-if="method !== '2'" class="tab-pane" forceRender key="Header" tab="Header"> |
22 | - <Header ref="editHeaderCellTableRef" :method="method" /> | 28 | + <HeaderTable ref="editHeaderCellTableRef" :method="method" /> |
29 | + <HeaderTest | ||
30 | + @testHeaderInterface="handleTestHeaderInterface" | ||
31 | + ref="testHeaderRequestRef" | ||
32 | + :data="dataMap.mapHeaderObj" | ||
33 | + /> | ||
23 | </TabPane> | 34 | </TabPane> |
24 | </Tabs> | 35 | </Tabs> |
25 | - <div class="tab-pane"> | ||
26 | - <TestRequest | ||
27 | - @testInterface="handleTestInterface" | ||
28 | - ref="testRequestRef" | ||
29 | - :method="method" | ||
30 | - :requestOriginUrl="requestOriginUrl" | ||
31 | - :requestUrl="requestTypeAndUrl?.requestUrl" | ||
32 | - :data="dataMap.mapObj" | ||
33 | - /> | ||
34 | - </div> | 36 | + <ExcuteTest ref="excuteTestRef" @emitExcute="handleEmitExcute" :data="excuteData" /> |
35 | </div> | 37 | </div> |
36 | </template> | 38 | </template> |
37 | <script lang="ts" setup name="simpleRequest"> | 39 | <script lang="ts" setup name="simpleRequest"> |
38 | import { ref, nextTick, reactive } from 'vue'; | 40 | import { ref, nextTick, reactive } from 'vue'; |
39 | import { Tabs, TabPane } from 'ant-design-vue'; | 41 | import { Tabs, TabPane } from 'ant-design-vue'; |
40 | - import { EditCellTable } from '../EditCellTable'; | ||
41 | - import Body from './body.vue'; | ||
42 | - import { TestRequest } from '../TestRequest/index'; | ||
43 | - import Header from './header.vue'; | 42 | + import Body from './components/body.vue'; |
43 | + import { ParamsTest, HeaderTest } from '../TestInterface/index'; | ||
44 | + import HeaderTable from './components/headerTable.vue'; | ||
45 | + import ParamsTable from './components/paramsTable.vue'; | ||
46 | + import { isEmpty } from '/@/utils/is'; | ||
47 | + import { useUtils } from '../../hooks/useUtils'; | ||
48 | + import ExcuteTest from '../TestInterface/components/excuteTest.vue'; | ||
44 | 49 | ||
45 | const props = defineProps({ | 50 | const props = defineProps({ |
46 | method: { | 51 | method: { |
@@ -56,45 +61,84 @@ | @@ -56,45 +61,84 @@ | ||
56 | 61 | ||
57 | const emits = defineEmits(['activeKey']); | 62 | const emits = defineEmits(['activeKey']); |
58 | 63 | ||
64 | + const { pushObj } = useUtils(); | ||
65 | + | ||
59 | const activeKey = ref('Params'); | 66 | const activeKey = ref('Params'); |
60 | 67 | ||
61 | - const editParamsCellTableRef = ref<InstanceType<typeof EditCellTable>>(); | 68 | + const excuteData = ref({}); |
69 | + | ||
70 | + const paramsCellTableRef = ref<InstanceType<typeof ParamsTable>>(); | ||
71 | + | ||
72 | + const editHeaderCellTableRef = ref<InstanceType<typeof ParamsTable>>(); | ||
62 | 73 | ||
63 | - const editHeaderCellTableRef = ref<InstanceType<typeof EditCellTable>>(); | 74 | + const excuteTestRef = ref<InstanceType<typeof ExcuteTest>>(); |
64 | 75 | ||
65 | const bodyRef = ref<InstanceType<typeof Body>>(); | 76 | const bodyRef = ref<InstanceType<typeof Body>>(); |
66 | 77 | ||
67 | - const testRequestRef = ref<InstanceType<typeof TestRequest>>(); | 78 | + const testParamsRequestRef = ref<InstanceType<typeof ParamsTest>>(); |
79 | + | ||
80 | + const testBodyRequestRef = ref<InstanceType<typeof ParamsTest>>(); | ||
81 | + | ||
82 | + const testHeaderRequestRef = ref<InstanceType<typeof HeaderTest>>(); | ||
68 | 83 | ||
69 | const dataMap: any = reactive({ | 84 | const dataMap: any = reactive({ |
70 | - mapObj: {}, | 85 | + mapParamsObj: {}, |
86 | + mapBodyObj: {}, | ||
87 | + mapHeaderObj: {}, | ||
71 | }); | 88 | }); |
72 | 89 | ||
73 | - const handleTabsChange = () => testRequestRef.value?.setValue(); | 90 | + const handleTabsChange = () => { |
91 | + // testParamsRequestRef.value?.setValue(); | ||
92 | + // testBodyRequestRef.value?.setValue(); | ||
93 | + // testHeaderRequestRef.value?.setValue(); | ||
94 | + }; | ||
74 | 95 | ||
75 | //if-else-if-else分支优化 | 96 | //if-else-if-else分支优化 |
76 | const dataForTypeMap = [ | 97 | const dataForTypeMap = [ |
77 | - [(type) => type === 'Params', (data) => editParamsCellTableRef.value?.setValue(data)], | 98 | + [(type) => type === 'Params', (data) => paramsCellTableRef.value?.setValue(data)], |
78 | [(type) => type === 'Body', (data) => bodyRef.value?.setValue(data)], | 99 | [(type) => type === 'Body', (data) => bodyRef.value?.setValue(data)], |
79 | [(type) => type === 'Header', (data) => editHeaderCellTableRef.value?.setValue(data)], | 100 | [(type) => type === 'Header', (data) => editHeaderCellTableRef.value?.setValue(data)], |
80 | ]; | 101 | ]; |
81 | 102 | ||
82 | - //测试接口 | ||
83 | - const handleTestInterface = () => { | 103 | + const handleEmitExcute = () => { |
104 | + excuteData.value = { | ||
105 | + Params: testParamsRequestRef.value?.getTestValue(), | ||
106 | + Header: testHeaderRequestRef.value?.getTestValue(), | ||
107 | + }; | ||
108 | + }; | ||
109 | + | ||
110 | + //TODO: 待优化这里测试接口 | ||
111 | + const handleTestParamsInterface = () => { | ||
112 | + let value = getValue(false) as any; | ||
113 | + dataMap.mapParamsObj = { | ||
114 | + list: value?.Params, | ||
115 | + requestOriginUrl: props.requestOriginUrl, | ||
116 | + requestTypeAndUrl: props.requestTypeAndUrl, | ||
117 | + method: props.method, | ||
118 | + activeKey: activeKey.value, | ||
119 | + }; | ||
120 | + }; | ||
121 | + | ||
122 | + const handleTestBodyInterface = () => { | ||
84 | let value = getValue(false) as any; | 123 | let value = getValue(false) as any; |
85 | - const type = value?.requestParamsBodyType; | ||
86 | - // if (type === 'none') value = []; | ||
87 | - // if (type === 'form-data') value = value['form-data']; | ||
88 | - // if (type === 'x-www-form-urlencoded') value = value['x-www-form-urlencoded']; | ||
89 | - nextTick( | ||
90 | - () => | ||
91 | - (dataMap.mapObj = { | ||
92 | - list: value?.Params || value?.Header, | ||
93 | - requestOriginUrl: props.requestOriginUrl, | ||
94 | - requestParamsBodyType: type, | ||
95 | - requestTypeAndUrl: props.requestTypeAndUrl, | ||
96 | - }) | ||
97 | - ); | 124 | + dataMap.mapBodyObj = { |
125 | + list: value?.Body, | ||
126 | + requestOriginUrl: props.requestOriginUrl, | ||
127 | + requestTypeAndUrl: props.requestTypeAndUrl, | ||
128 | + method: props.method, | ||
129 | + activeKey: activeKey.value, | ||
130 | + }; | ||
131 | + }; | ||
132 | + | ||
133 | + const handleTestHeaderInterface = () => { | ||
134 | + let value = getValue(false) as any; | ||
135 | + dataMap.mapHeaderObj = { | ||
136 | + list: value?.Header, | ||
137 | + requestOriginUrl: props.requestOriginUrl, | ||
138 | + requestTypeAndUrl: props.requestTypeAndUrl, | ||
139 | + method: props.method, | ||
140 | + activeKey: activeKey.value, | ||
141 | + }; | ||
98 | }; | 142 | }; |
99 | 143 | ||
100 | //获取数据 | 144 | //获取数据 |
@@ -102,7 +146,7 @@ | @@ -102,7 +146,7 @@ | ||
102 | const type = activeKey.value; | 146 | const type = activeKey.value; |
103 | status ? emits('activeKey', type) : null; | 147 | status ? emits('activeKey', type) : null; |
104 | const Body = bodyRef.value?.getValue(); | 148 | const Body = bodyRef.value?.getValue(); |
105 | - const Params = editParamsCellTableRef.value?.getValue(); | 149 | + const Params = paramsCellTableRef.value?.getValue(); |
106 | const Header = editHeaderCellTableRef.value?.getValue(); | 150 | const Header = editHeaderCellTableRef.value?.getValue(); |
107 | return { | 151 | return { |
108 | Params, | 152 | Params, |
@@ -116,9 +160,9 @@ | @@ -116,9 +160,9 @@ | ||
116 | nextTick(() => { | 160 | nextTick(() => { |
117 | const Objects = JSON.parse(data?.requestParams); | 161 | const Objects = JSON.parse(data?.requestParams); |
118 | if (!Objects) return; | 162 | if (!Objects) return; |
119 | - dataForTypeMap[0][1](Objects?.Params); | ||
120 | - dataForTypeMap[1][1](Objects?.Body); | ||
121 | - dataForTypeMap[2][1](Objects?.Header); | 163 | + dataForTypeMap[0][1](isEmpty(Objects?.Params) ? [pushObj] : Objects?.Params); |
164 | + dataForTypeMap[1][1](isEmpty(Objects?.Body) ? {} : Objects?.Body); | ||
165 | + dataForTypeMap[2][1](isEmpty(Objects?.Header) ? [pushObj] : Objects?.Header); | ||
122 | }); | 166 | }); |
123 | }; | 167 | }; |
124 | 168 | ||
@@ -126,7 +170,7 @@ | @@ -126,7 +170,7 @@ | ||
126 | const resetValue = () => { | 170 | const resetValue = () => { |
127 | activeKey.value = 'Params'; | 171 | activeKey.value = 'Params'; |
128 | nextTick(() => { | 172 | nextTick(() => { |
129 | - editParamsCellTableRef.value?.resetValue(); | 173 | + paramsCellTableRef.value?.resetValue(); |
130 | editHeaderCellTableRef.value?.resetValue(); | 174 | editHeaderCellTableRef.value?.resetValue(); |
131 | bodyRef.value?.resetValue(); | 175 | bodyRef.value?.resetValue(); |
132 | handleTabsChange(); | 176 | handleTabsChange(); |
src/views/dataview/publicApi/components/TestEditCellTable/index.ts
deleted
100644 → 0
1 | +<template> | ||
2 | + <div class="mt-8"> | ||
3 | + <div> | ||
4 | + <Button disabled @click="handleExcute" type="primary"> 执行测试请求 </Button> | ||
5 | + </div> | ||
6 | + <!-- <div class="mt-8"> | ||
7 | + <a-row type="flex" justify="center"> | ||
8 | + <a-col :span="3"> 测试结果 </a-col> | ||
9 | + <a-col :span="21"> | ||
10 | + <a-textarea | ||
11 | + allow-clear | ||
12 | + show-count | ||
13 | + v-model:value="testResult" | ||
14 | + placeholder="测试结果为:" | ||
15 | + :rows="8" | ||
16 | + /> | ||
17 | + </a-col> | ||
18 | + </a-row> | ||
19 | + </div> --> | ||
20 | + </div> | ||
21 | +</template> | ||
22 | +<script lang="ts" setup name="testRequest"> | ||
23 | + import { nextTick } from 'vue'; | ||
24 | + import { Button } from 'ant-design-vue'; | ||
25 | + // import { otherHttp } from '/@/utils/http/axios'; | ||
26 | + | ||
27 | + const emits = defineEmits(['emitExcute']); | ||
28 | + | ||
29 | + const props = defineProps({ | ||
30 | + data: { | ||
31 | + type: Object, | ||
32 | + }, | ||
33 | + }); | ||
34 | + | ||
35 | + //格式化替换像"http:xxxx/api/xx/{xx}/{xx}/{xx}这种格式" | ||
36 | + String.prototype.restfulFormat = function (replacements) { | ||
37 | + var formatString = function (str, replacements) { | ||
38 | + replacements = | ||
39 | + typeof replacements === 'object' ? replacements : Array.prototype.slice.call(arguments, 1); | ||
40 | + return str.replace(/\{\{|\}\}|\{(\w+)\}/g, function (m, n) { | ||
41 | + if (m == '{{') { | ||
42 | + return '{'; | ||
43 | + } | ||
44 | + if (m == '}}') { | ||
45 | + return '}'; | ||
46 | + } | ||
47 | + return replacements[n]; | ||
48 | + }); | ||
49 | + }; | ||
50 | + replacements = | ||
51 | + typeof replacements === 'object' ? replacements : Array.prototype.slice.call(arguments, 0); | ||
52 | + return formatString(this, replacements); | ||
53 | + }; | ||
54 | + | ||
55 | + // const testResult = ref(''); | ||
56 | + | ||
57 | + //执行测试接口 | ||
58 | + const handleExcute = () => { | ||
59 | + emits('emitExcute'); | ||
60 | + getValue(); | ||
61 | + }; | ||
62 | + | ||
63 | + const getValue = async () => { | ||
64 | + await nextTick(); | ||
65 | + console.log(props.data); | ||
66 | + }; | ||
67 | + | ||
68 | + // //TODO: 待优化 项目自带第三方请求 | ||
69 | + // const otherHttpRequest = async (apiType, params = {}, api, joinPrefix = false) => { | ||
70 | + // switch (apiType) { | ||
71 | + // case 'GET': | ||
72 | + // return await otherHttp.get( | ||
73 | + // { url: api, params }, | ||
74 | + // { | ||
75 | + // apiUrl: '', | ||
76 | + // joinPrefix, | ||
77 | + // } | ||
78 | + // ); | ||
79 | + // } | ||
80 | + // }; | ||
81 | +</script> | ||
82 | + | ||
83 | +<style scoped lang="less"></style> |
1 | +<template> | ||
2 | + <div> | ||
3 | + <div class="mt-8"> | ||
4 | + <div> | ||
5 | + <Button disabled @click="handleTest" type="primary"> 测试接口 </Button> | ||
6 | + </div> | ||
7 | + <div v-if="showTestEditCell" class="mt-8"> | ||
8 | + <a-row type="flex" justify="center"> | ||
9 | + <a-col :span="3"> 参数设置 </a-col> | ||
10 | + <a-col :span="21"> | ||
11 | + <TestHeaderEditCellTable ref="testEditCellTableRef" /> | ||
12 | + </a-col> | ||
13 | + </a-row> | ||
14 | + </div> | ||
15 | + </div> | ||
16 | + <div class="mt-8"> </div> | ||
17 | + </div> | ||
18 | +</template> | ||
19 | +<script lang="ts" setup name="testRequest"> | ||
20 | + import { ref, nextTick } from 'vue'; | ||
21 | + import { Button } from 'ant-design-vue'; | ||
22 | + import TestHeaderEditCellTable from './testEditHeaderCellTable.vue'; | ||
23 | + | ||
24 | + const emits = defineEmits(['testHeaderInterface']); | ||
25 | + | ||
26 | + const props = defineProps({ | ||
27 | + data: { | ||
28 | + type: Object, | ||
29 | + }, | ||
30 | + }); | ||
31 | + | ||
32 | + const showTestEditCell = ref(false); | ||
33 | + | ||
34 | + const excuteData = ref({}); | ||
35 | + | ||
36 | + const testEditCellTableRef = ref<InstanceType<typeof TestHeaderEditCellTable>>(); | ||
37 | + | ||
38 | + const testResult = ref(''); | ||
39 | + | ||
40 | + const handleTest = () => { | ||
41 | + showTestEditCell.value = true; | ||
42 | + emits('testHeaderInterface'); | ||
43 | + getValue(); | ||
44 | + }; | ||
45 | + | ||
46 | + const getValue = async () => { | ||
47 | + await nextTick(); | ||
48 | + await nextTick(() => { | ||
49 | + const getValue = props.data?.list; | ||
50 | + testEditCellTableRef.value?.setTableArray(getValue); | ||
51 | + }); | ||
52 | + }; | ||
53 | + | ||
54 | + //测试表格里的数据转化为 key value 数组对象形式 | ||
55 | + const getTestTableKeyValue = () => { | ||
56 | + return testEditCellTableRef.value?.getValue(); | ||
57 | + }; | ||
58 | + | ||
59 | + //获取数据 | ||
60 | + const getTestValue = () => { | ||
61 | + const getTable = getTestTableKeyValue(); | ||
62 | + //源地址 | ||
63 | + const apiGetUrl = `${props.data?.requestOriginUrl}${props.data?.requestTypeAndUrl?.requestUrl}`; | ||
64 | + //请求类型 | ||
65 | + const apiType = props.data?.requestTypeAndUrl?.requestHttpType; | ||
66 | + //替换key value | ||
67 | + const params: any = {}; | ||
68 | + getTable?.map((it: any) => (params[it.key!] = it.value!)); | ||
69 | + excuteData.value = { | ||
70 | + apiGetUrl, | ||
71 | + apiType, | ||
72 | + params, | ||
73 | + activeKey: props.data?.activeKey, | ||
74 | + }; | ||
75 | + return excuteData.value; | ||
76 | + }; | ||
77 | + | ||
78 | + //设置数据 | ||
79 | + const setValue = () => { | ||
80 | + showTestEditCell.value = false; | ||
81 | + testResult.value = ''; | ||
82 | + }; | ||
83 | + | ||
84 | + defineExpose({ | ||
85 | + setValue, | ||
86 | + handleTest, | ||
87 | + getTestValue, | ||
88 | + }); | ||
89 | +</script> | ||
90 | + | ||
91 | +<style scoped lang="less"></style> |
src/views/dataview/publicApi/components/TestInterface/headerTest/testEditHeaderCellTable.vue
0 → 100644
1 | +<!-- eslint-disable vue/valid-v-model --> | ||
2 | +<template> | ||
3 | + <div class="table-content"> | ||
4 | + <!-- TODO: 待优化测试表格 --> | ||
5 | + <table align="center"> | ||
6 | + <thead> | ||
7 | + <tr> | ||
8 | + <th v-for="item in editTestCellTableTHeadConfig.slice(1)" :key="item">{{ item }}</th> | ||
9 | + </tr> | ||
10 | + </thead> | ||
11 | + <tbody> | ||
12 | + <tr v-for="(item, index) in tableTestArray.content" :key="index"> | ||
13 | + <td style="width: 7.5vw"> | ||
14 | + <a-input disabled placeholder="请输入" v-model:value="item.key" /> | ||
15 | + </td> | ||
16 | + <td style="width: 6.5vw"> | ||
17 | + <a-input placeholder="请输入" v-model:value="item.value" /> | ||
18 | + </td> | ||
19 | + </tr> | ||
20 | + </tbody> | ||
21 | + </table> | ||
22 | + </div> | ||
23 | +</template> | ||
24 | +<script lang="ts" setup name="editCellTable"> | ||
25 | + import { reactive } from 'vue'; | ||
26 | + import { cloneDeep } from 'lodash-es'; | ||
27 | + import { tableItems } from '../../../types'; | ||
28 | + import { editTestCellTableTHeadConfig } from '../../../config'; | ||
29 | + | ||
30 | + defineProps({ | ||
31 | + method: { | ||
32 | + type: String, | ||
33 | + }, | ||
34 | + }); | ||
35 | + | ||
36 | + const tableTestArray = reactive<{ | ||
37 | + content: tableItems[]; | ||
38 | + }>({ | ||
39 | + content: [ | ||
40 | + { | ||
41 | + key: undefined, | ||
42 | + value: undefined, | ||
43 | + keyValue: null, | ||
44 | + editDisabled: false, | ||
45 | + dateValue: null, | ||
46 | + }, | ||
47 | + ], | ||
48 | + }); | ||
49 | + | ||
50 | + //设置数据 | ||
51 | + const setTableArray = (data) => { | ||
52 | + const list = cloneDeep(data); | ||
53 | + if (Array.isArray(list)) tableTestArray.content = list; | ||
54 | + }; | ||
55 | + | ||
56 | + //获取数据 | ||
57 | + const getValue = () => { | ||
58 | + return tableTestArray.content; | ||
59 | + }; | ||
60 | + defineExpose({ | ||
61 | + getValue, | ||
62 | + setTableArray, | ||
63 | + }); | ||
64 | +</script> | ||
65 | + | ||
66 | +<style scoped lang="less"> | ||
67 | + @table-color: #e5e7eb; | ||
68 | + | ||
69 | + .table-border-color { | ||
70 | + border: 1px solid #e5e7eb; | ||
71 | + text-align: center; | ||
72 | + } | ||
73 | + | ||
74 | + .table-content { | ||
75 | + table { | ||
76 | + width: 31vw; | ||
77 | + &:extend(.table-border-color); | ||
78 | + } | ||
79 | + | ||
80 | + table td { | ||
81 | + padding: 5px; | ||
82 | + white-space: nowrap; | ||
83 | + &:extend(.table-border-color); | ||
84 | + } | ||
85 | + | ||
86 | + table th { | ||
87 | + padding: 5px; | ||
88 | + &:extend(.table-border-color); | ||
89 | + } | ||
90 | + } | ||
91 | +</style> |
1 | +<template> | ||
2 | + <div> | ||
3 | + <div class="mt-8"> | ||
4 | + <div> | ||
5 | + <Button disabled @click="handleTest" type="primary"> 测试接口 </Button> | ||
6 | + </div> | ||
7 | + <div v-if="showTestEditCell" class="mt-8"> | ||
8 | + <a-row type="flex" justify="center"> | ||
9 | + <a-col :span="3"> 参数设置 </a-col> | ||
10 | + <a-col :span="21"> | ||
11 | + <TestParamsCellTable ref="testEditCellTableRef" /> | ||
12 | + </a-col> | ||
13 | + </a-row> | ||
14 | + </div> | ||
15 | + </div> | ||
16 | + <div class="mt-8"> </div> | ||
17 | + </div> | ||
18 | +</template> | ||
19 | +<script lang="ts" setup name="testRequest"> | ||
20 | + import { ref, nextTick } from 'vue'; | ||
21 | + import { Button } from 'ant-design-vue'; | ||
22 | + import TestParamsCellTable from './testEditParamsCellTable.vue'; | ||
23 | + import moment from 'moment'; | ||
24 | + import { useUtils } from '../../../hooks/useUtils'; | ||
25 | + | ||
26 | + const emits = defineEmits(['testParamsInterface']); | ||
27 | + | ||
28 | + const props = defineProps({ | ||
29 | + data: { | ||
30 | + type: Object, | ||
31 | + }, | ||
32 | + }); | ||
33 | + | ||
34 | + const showTestEditCell = ref(false); | ||
35 | + | ||
36 | + const excuteData = ref({}); | ||
37 | + | ||
38 | + const testEditCellTableRef = ref<InstanceType<typeof TestParamsCellTable>>(); | ||
39 | + | ||
40 | + const testResult = ref(''); | ||
41 | + | ||
42 | + const { getMultipleKeys } = useUtils(); | ||
43 | + | ||
44 | + const handleTest = () => { | ||
45 | + showTestEditCell.value = true; | ||
46 | + emits('testParamsInterface'); | ||
47 | + getValue(); | ||
48 | + }; | ||
49 | + | ||
50 | + const getValue = async () => { | ||
51 | + await nextTick(); | ||
52 | + await nextTick(() => { | ||
53 | + //拆分"xx,xx,xx"多个 | ||
54 | + const getSingleKey = props.data?.list; | ||
55 | + const getMuteKey = props.data?.list?.filter((it: any) => it.key.split(',').length > 1); | ||
56 | + const getMuteKeys = getMultipleKeys(getMuteKey); | ||
57 | + const mergeKeys = [...getSingleKey, ...getMuteKeys]?.filter( | ||
58 | + (it: any) => it.key.split(',').length === 1 | ||
59 | + ); | ||
60 | + testEditCellTableRef.value?.setTableArray(mergeKeys); | ||
61 | + }); | ||
62 | + }; | ||
63 | + | ||
64 | + //测试表格里的数据转化为 key value 数组对象形式 | ||
65 | + //TODO:待优化这里的TS类型 | ||
66 | + const getTestTableKeyValue = () => { | ||
67 | + //把日期拆分成多个 | ||
68 | + const keyValueList: any = []; | ||
69 | + testEditCellTableRef.value?.getValue()?.forEach((item: any) => { | ||
70 | + const splitDateKey = item?.key === 'date_range' ? item?.value?.split(',') : []; | ||
71 | + const splitDateValue = item?.key === 'date_range' ? item?.dateValue : []; | ||
72 | + for (let i in splitDateKey) { | ||
73 | + const obj = { | ||
74 | + key: splitDateKey[i], | ||
75 | + value: moment(splitDateValue[i]).valueOf(), | ||
76 | + }; | ||
77 | + keyValueList.push(obj); | ||
78 | + } | ||
79 | + }); | ||
80 | + return testEditCellTableRef.value | ||
81 | + ?.getValue() | ||
82 | + .concat(keyValueList) | ||
83 | + .filter((it) => it.key !== 'date_range') | ||
84 | + .map((it: any) => { | ||
85 | + const value = it?.key === 'scope' || it?.key === 'fixed_date' ? it?.keyValue : it?.value; | ||
86 | + const key = it?.key === 'scope' || it?.key === 'fixed_date' ? it?.value : it?.key; | ||
87 | + return { | ||
88 | + key, | ||
89 | + value, | ||
90 | + }; | ||
91 | + }); | ||
92 | + }; | ||
93 | + | ||
94 | + //获取数据 | ||
95 | + const getTestValue = () => { | ||
96 | + const getTable = getTestTableKeyValue(); | ||
97 | + //源地址 | ||
98 | + const apiGetUrl = `${props.data?.requestOriginUrl}${props.data?.requestTypeAndUrl?.requestUrl}`; | ||
99 | + //请求类型 | ||
100 | + const apiType = props.data?.requestTypeAndUrl?.requestHttpType; | ||
101 | + //替换key value | ||
102 | + const params: any = {}; | ||
103 | + getTable?.map((it) => (params[it.key!] = it.value!)); | ||
104 | + excuteData.value = { | ||
105 | + apiGetUrl, | ||
106 | + apiType, | ||
107 | + params, | ||
108 | + activeKey: props.data?.activeKey, | ||
109 | + }; | ||
110 | + return excuteData.value; | ||
111 | + }; | ||
112 | + | ||
113 | + //设置数据 | ||
114 | + const setValue = () => { | ||
115 | + showTestEditCell.value = false; | ||
116 | + testResult.value = ''; | ||
117 | + }; | ||
118 | + | ||
119 | + defineExpose({ | ||
120 | + setValue, | ||
121 | + handleTest, | ||
122 | + getTestValue, | ||
123 | + }); | ||
124 | +</script> | ||
125 | + | ||
126 | +<style scoped lang="less"></style> |
src/views/dataview/publicApi/components/TestInterface/paramsTest/testEditParamsCellTable.vue
renamed from
src/views/dataview/publicApi/components/TestEditCellTable/index.vue
1 | <!-- eslint-disable vue/valid-v-model --> | 1 | <!-- eslint-disable vue/valid-v-model --> |
2 | <template> | 2 | <template> |
3 | <div class="table-content"> | 3 | <div class="table-content"> |
4 | - <!-- TODO 待优化测试表格 --> | 4 | + <!-- TODO: 待优化测试表格 --> |
5 | <table align="center"> | 5 | <table align="center"> |
6 | <thead> | 6 | <thead> |
7 | <tr> | 7 | <tr> |
@@ -67,10 +67,18 @@ | @@ -67,10 +67,18 @@ | ||
67 | </td> | 67 | </td> |
68 | <td style="width: 6.5vw"> | 68 | <td style="width: 6.5vw"> |
69 | <a-input | 69 | <a-input |
70 | - v-if="item.key === 'scope' || item.key === 'fixed_date'" | 70 | + v-if="item.key === 'scope'" |
71 | placeholder="请输入" | 71 | placeholder="请输入" |
72 | v-model:value="item.keyValue" | 72 | v-model:value="item.keyValue" |
73 | /> | 73 | /> |
74 | + <a-date-picker | ||
75 | + v-else-if="item.key === 'fixed_date'" | ||
76 | + style="width: 6.5vw" | ||
77 | + v-model:value="item.keyValue" | ||
78 | + :show-time="{ format: 'HH:mm' }" | ||
79 | + format="YYYY-MM-DD HH:mm:ss" | ||
80 | + placeholder="日期时间" | ||
81 | + /> | ||
74 | <a-range-picker | 82 | <a-range-picker |
75 | v-else-if="item.key == 'date_range'" | 83 | v-else-if="item.key == 'date_range'" |
76 | style="width: 6.5vw" | 84 | style="width: 6.5vw" |
@@ -79,7 +87,7 @@ | @@ -79,7 +87,7 @@ | ||
79 | format="YYYY-MM-DD HH:mm" | 87 | format="YYYY-MM-DD HH:mm" |
80 | :placeholder="['开始', '结束']" | 88 | :placeholder="['开始', '结束']" |
81 | /> | 89 | /> |
82 | - <a-input v-else disabled="true" placeholder="请输入" v-model:value="item.keyValue" /> | 90 | + <a-input v-else disabled placeholder="请输入" v-model:value="item.keyValue" /> |
83 | </td> | 91 | </td> |
84 | </tr> | 92 | </tr> |
85 | </tbody> | 93 | </tbody> |
@@ -92,10 +100,10 @@ | @@ -92,10 +100,10 @@ | ||
92 | import { findDictItemByCode } from '/@/api/system/dict'; | 100 | import { findDictItemByCode } from '/@/api/system/dict'; |
93 | import { getAllDeviceByOrg } from '/@/api/dataBoard'; | 101 | import { getAllDeviceByOrg } from '/@/api/dataBoard'; |
94 | import { getDeviceAttributes } from '/@/api/dataBoard'; | 102 | import { getDeviceAttributes } from '/@/api/dataBoard'; |
95 | - import { useApi } from '../../hooks/useApi'; | 103 | + import { useApi } from '../../../hooks/useApi'; |
96 | import { cloneDeep } from 'lodash-es'; | 104 | import { cloneDeep } from 'lodash-es'; |
97 | - import { tableItems, selectType } from '../../types'; | ||
98 | - import { editTestCellTableTHeadConfig } from '../../config'; | 105 | + import { tableItems, selectType } from '../../../types'; |
106 | + import { editTestCellTableTHeadConfig } from '../../../config'; | ||
99 | 107 | ||
100 | const props = defineProps({ | 108 | const props = defineProps({ |
101 | method: { | 109 | method: { |
@@ -166,7 +174,7 @@ | @@ -166,7 +174,7 @@ | ||
166 | 174 | ||
167 | const handleOrgnationChange = async (e) => { | 175 | const handleOrgnationChange = async (e) => { |
168 | let deviceProfileId = ''; | 176 | let deviceProfileId = ''; |
169 | - tableTestArray.content.forEach((f) => { | 177 | + tableTestArray.content.forEach((f: any) => { |
170 | if (f.key === 'entityId') { | 178 | if (f.key === 'entityId') { |
171 | f.value = null; | 179 | f.value = null; |
172 | } | 180 | } |
@@ -192,7 +200,7 @@ | @@ -192,7 +200,7 @@ | ||
192 | const handleValueChange = (e) => { | 200 | const handleValueChange = (e) => { |
193 | let organizationId = ''; | 201 | let organizationId = ''; |
194 | if (e.key === 'deviceProfileId') { | 202 | if (e.key === 'deviceProfileId') { |
195 | - tableTestArray.content.forEach((f) => { | 203 | + tableTestArray.content.forEach((f: any) => { |
196 | if (f.key === 'keys') { | 204 | if (f.key === 'keys') { |
197 | f.value = null; | 205 | f.value = null; |
198 | } | 206 | } |
src/views/dataview/publicApi/components/TestRequest/index.ts
deleted
100644 → 0
src/views/dataview/publicApi/components/TestRequest/index.vue
deleted
100644 → 0
1 | -<template> | ||
2 | - <div> | ||
3 | - <div class="mt-8"> | ||
4 | - <div> | ||
5 | - <Button @click="handleTest" type="primary"> 测试接口 </Button> | ||
6 | - </div> | ||
7 | - <div v-if="showTestEditCell" class="mt-8"> | ||
8 | - <a-row type="flex" justify="center"> | ||
9 | - <a-col :span="3"> 参数设置 </a-col> | ||
10 | - <a-col :span="21"> | ||
11 | - <TestEditCellTable ref="testEditCellTableRef" :method="method" /> | ||
12 | - </a-col> | ||
13 | - </a-row> | ||
14 | - </div> | ||
15 | - </div> | ||
16 | - <div v-if="showTestEditCell" class="mt-8"> | ||
17 | - <div> | ||
18 | - <Button @click="handleExcute" type="primary"> 执行 </Button> | ||
19 | - </div> | ||
20 | - <div class="mt-8"> | ||
21 | - <a-row type="flex" justify="center"> | ||
22 | - <a-col :span="3"> 测试结果 </a-col> | ||
23 | - <a-col :span="21"> | ||
24 | - <a-textarea | ||
25 | - allow-clear | ||
26 | - show-count | ||
27 | - v-model:value="testResult" | ||
28 | - placeholder="测试结果为:" | ||
29 | - :rows="8" | ||
30 | - /> | ||
31 | - </a-col> | ||
32 | - </a-row> | ||
33 | - </div> | ||
34 | - </div> | ||
35 | - </div> | ||
36 | -</template> | ||
37 | -<script lang="ts" setup name="testRequest"> | ||
38 | - import { ref, nextTick, reactive } from 'vue'; | ||
39 | - import { Button } from 'ant-design-vue'; | ||
40 | - import { TestEditCellTable } from '../TestEditCellTable/index'; | ||
41 | - import { otherHttp } from '/@/utils/http/axios'; | ||
42 | - import moment from 'moment'; | ||
43 | - import { useWebSocket } from '@vueuse/core'; | ||
44 | - import { JWT_TOKEN_KEY } from '/@/enums/cacheEnum'; | ||
45 | - import { getAuthCache } from '/@/utils/auth'; | ||
46 | - import { useMessage } from '/@/hooks/web/useMessage'; | ||
47 | - import { useGlobSetting } from '/@/hooks/setting'; | ||
48 | - | ||
49 | - const emits = defineEmits(['testInterface']); | ||
50 | - | ||
51 | - const props = defineProps({ | ||
52 | - method: { | ||
53 | - type: String, | ||
54 | - }, | ||
55 | - data: { | ||
56 | - type: Object, | ||
57 | - }, | ||
58 | - }); | ||
59 | - | ||
60 | - const { createMessage } = useMessage(); | ||
61 | - | ||
62 | - const token = getAuthCache(JWT_TOKEN_KEY); | ||
63 | - | ||
64 | - const { socketUrl } = useGlobSetting(); | ||
65 | - | ||
66 | - const socketMessage = reactive({ | ||
67 | - server: `${socketUrl}${token}`, | ||
68 | - sendValue: { | ||
69 | - tsSubCmds: [], | ||
70 | - }, | ||
71 | - }); | ||
72 | - | ||
73 | - const showTestEditCell = ref(false); | ||
74 | - | ||
75 | - const testEditCellTableRef = ref<InstanceType<typeof TestEditCellTable>>(); | ||
76 | - | ||
77 | - const testResult = ref(''); | ||
78 | - | ||
79 | - // const testNeedKeys = ['organizationId', 'deviceProfileId', 'entityId', 'keys', 'date']; | ||
80 | - | ||
81 | - const handleTest = () => { | ||
82 | - showTestEditCell.value = true; | ||
83 | - emits('testInterface'); | ||
84 | - getValue(); | ||
85 | - }; | ||
86 | - | ||
87 | - //获取多个key | ||
88 | - const getMultipleKeys = (list) => { | ||
89 | - let temps = []; | ||
90 | - list?.forEach((it) => { | ||
91 | - const keys = it.key.split(','); | ||
92 | - const temp = keys.map((item) => { | ||
93 | - let obj: { key: string; value: string } = { key: '', value: '' }; | ||
94 | - obj.key = item; | ||
95 | - obj.value = item === 'scope' ? it.value : ''; | ||
96 | - return obj; | ||
97 | - }); | ||
98 | - temps = temp; | ||
99 | - }); | ||
100 | - return temps; | ||
101 | - }; | ||
102 | - | ||
103 | - //获取测试表格的key value 数组对象形式 | ||
104 | - const getTestTableKeyValue = () => { | ||
105 | - //把日期拆分成多个 | ||
106 | - const keyValueList = []; | ||
107 | - testEditCellTableRef.value?.getValue()?.forEach((item) => { | ||
108 | - const splitDateKey = item.key === 'date_range' ? item.value?.split(',') : []; | ||
109 | - const splitDateValue = item.key === 'date_range' ? item.dateValue : []; | ||
110 | - for (let i in splitDateKey) { | ||
111 | - const obj = { | ||
112 | - key: splitDateKey[i], | ||
113 | - value: moment(splitDateValue[i]).valueOf(), | ||
114 | - }; | ||
115 | - keyValueList.push(obj); | ||
116 | - } | ||
117 | - }); | ||
118 | - return testEditCellTableRef.value | ||
119 | - ?.getValue() | ||
120 | - .concat(keyValueList) | ||
121 | - .filter((it) => it.key !== 'date_range') | ||
122 | - .map((it) => { | ||
123 | - const value = it.key === 'scope' || it.key === 'fixed_date' ? it.keyValue : it.value; | ||
124 | - const key = it.key === 'scope' || it.key === 'fixed_date' ? it.value : it.key; | ||
125 | - return { | ||
126 | - key, | ||
127 | - value, | ||
128 | - }; | ||
129 | - }); | ||
130 | - }; | ||
131 | - | ||
132 | - //格式化"http:xxxx/api/xx/{xx}/{xx}/{xx}这种格式" | ||
133 | - String.prototype.restfulFormat = function (replacements) { | ||
134 | - var formatString = function (str, replacements) { | ||
135 | - replacements = | ||
136 | - typeof replacements === 'object' ? replacements : Array.prototype.slice.call(arguments, 1); | ||
137 | - return str.replace(/\{\{|\}\}|\{(\w+)\}/g, function (m, n) { | ||
138 | - if (m == '{{') { | ||
139 | - return '{'; | ||
140 | - } | ||
141 | - if (m == '}}') { | ||
142 | - return '}'; | ||
143 | - } | ||
144 | - return replacements[n]; | ||
145 | - }); | ||
146 | - }; | ||
147 | - replacements = | ||
148 | - typeof replacements === 'object' ? replacements : Array.prototype.slice.call(arguments, 0); | ||
149 | - return formatString(this, replacements); | ||
150 | - }; | ||
151 | - | ||
152 | - //TODO 待优化 项目自带第三方请求 | ||
153 | - const otherHttpRequest = async (apiType, params = {}, api, joinPrefix = false) => { | ||
154 | - switch (apiType) { | ||
155 | - case 'GET': | ||
156 | - Reflect.deleteProperty(params, 'deviceProfileId'); | ||
157 | - Reflect.deleteProperty(params, 'organizationId'); | ||
158 | - Reflect.deleteProperty(params, 'entityId'); | ||
159 | - Reflect.deleteProperty(params, 'entityType'); | ||
160 | - Reflect.deleteProperty(params, 'scope'); | ||
161 | - Reflect.deleteProperty(params, 'id'); | ||
162 | - Reflect.deleteProperty(params, 'type'); | ||
163 | - return await otherHttp.get( | ||
164 | - { url: api, params }, | ||
165 | - { | ||
166 | - apiUrl: '', | ||
167 | - joinPrefix, | ||
168 | - } | ||
169 | - ); | ||
170 | - case 'POST': | ||
171 | - return await otherHttp.post( | ||
172 | - { url: api, data: params }, | ||
173 | - { | ||
174 | - apiUrl: '', | ||
175 | - joinPrefix, | ||
176 | - } | ||
177 | - ); | ||
178 | - case 'PUT': | ||
179 | - return await otherHttp.put( | ||
180 | - { url: api, data: params }, | ||
181 | - { | ||
182 | - apiUrl: '', | ||
183 | - joinPrefix, | ||
184 | - } | ||
185 | - ); | ||
186 | - } | ||
187 | - }; | ||
188 | - | ||
189 | - const getValue = async () => { | ||
190 | - await nextTick(); | ||
191 | - await nextTick(() => { | ||
192 | - const getSingleKey = props.data?.list; | ||
193 | - const getMuteKey = props.data?.list?.filter((it: any) => it.key.split(',').length > 1); | ||
194 | - const getMuteKeys = getMultipleKeys(getMuteKey); | ||
195 | - const mergeKeys = [...getSingleKey, ...getMuteKeys]?.filter( | ||
196 | - (it: any) => it.key.split(',').length === 1 | ||
197 | - ); | ||
198 | - testEditCellTableRef.value?.setTableArray(mergeKeys); | ||
199 | - }); | ||
200 | - }; | ||
201 | - | ||
202 | - //执行测试接口 | ||
203 | - const handleExcute = async () => { | ||
204 | - await nextTick(); | ||
205 | - await nextTick(async () => { | ||
206 | - const getTable = getTestTableKeyValue(); | ||
207 | - const apiGetUrl = `${props.data?.requestOriginUrl}${props.data?.requestTypeAndUrl?.requestUrl}`; | ||
208 | - const apiType = props.data?.requestTypeAndUrl?.requestHttpType; | ||
209 | - const params: any = {}; | ||
210 | - getTable?.map((it) => (params[it.key!] = it.value!)); | ||
211 | - if (props.method === '0') { | ||
212 | - //普通请求 | ||
213 | - const formatApi = apiGetUrl.restfulFormat(params); | ||
214 | - const rest = await otherHttpRequest(apiType, params, formatApi.split('{?')[0], false); | ||
215 | - testResult.value = JSON.stringify(rest); | ||
216 | - } else if (props.method === '2') { | ||
217 | - //websocket请求 | ||
218 | - Reflect.deleteProperty(params, 'deviceProfileId'); | ||
219 | - Reflect.deleteProperty(params, 'organizationId'); | ||
220 | - Reflect.set(params, 'cmdId', Number(params?.cmdId)); | ||
221 | - socketMessage.sendValue.tsSubCmds.push(params); | ||
222 | - const { send, close } = useWebSocket(socketMessage.server, { | ||
223 | - onConnected() { | ||
224 | - send(JSON.stringify(socketMessage.sendValue)); | ||
225 | - console.log('建立连接了'); | ||
226 | - }, | ||
227 | - onMessage(_, e) { | ||
228 | - const { data } = JSON.parse(e.data); | ||
229 | - testResult.value = JSON.stringify(data); | ||
230 | - }, | ||
231 | - onDisconnected() { | ||
232 | - console.log('断开连接了'); | ||
233 | - close(); | ||
234 | - }, | ||
235 | - onError() { | ||
236 | - createMessage.error('webSocket连接超时,请联系管理员'); | ||
237 | - }, | ||
238 | - }); | ||
239 | - } | ||
240 | - }); | ||
241 | - }; | ||
242 | - | ||
243 | - //设置数据 | ||
244 | - const setValue = () => { | ||
245 | - showTestEditCell.value = false; | ||
246 | - testResult.value = ''; | ||
247 | - }; | ||
248 | - | ||
249 | - defineExpose({ | ||
250 | - setValue, | ||
251 | - handleTest, | ||
252 | - }); | ||
253 | -</script> | ||
254 | - | ||
255 | -<style scoped lang="less"></style> |
@@ -204,4 +204,4 @@ export const schemas: FormSchema[] = [ | @@ -204,4 +204,4 @@ export const schemas: FormSchema[] = [ | ||
204 | //表格表头配置 | 204 | //表格表头配置 |
205 | export const editCellTableTHeadConfig = ['序号', '内置参数', '参数名', '是否必须', '操作']; | 205 | export const editCellTableTHeadConfig = ['序号', '内置参数', '参数名', '是否必须', '操作']; |
206 | export const editTestCellTableTHeadConfig = ['内置参数', '参数名', '参数值']; | 206 | export const editTestCellTableTHeadConfig = ['内置参数', '参数名', '参数值']; |
207 | -export const editTestCellTableTHeaderConfig = ['序号', '参数名', '参数值']; | 207 | +export const editTestCellTableTHeaderConfig = ['序号', '参数名', '参数值', '是否必须', '操作']; |
@@ -12,7 +12,6 @@ | @@ -12,7 +12,6 @@ | ||
12 | <SimpleRequest | 12 | <SimpleRequest |
13 | ref="simpleRequestRef" | 13 | ref="simpleRequestRef" |
14 | v-if="model['requestContentType'] === '0' || model['requestContentType'] === '2'" | 14 | v-if="model['requestContentType'] === '0' || model['requestContentType'] === '2'" |
15 | - @activeKey="handleActiveKey" | ||
16 | :requestTypeAndUrl="model['requestHttpTypeAndUrl']" | 15 | :requestTypeAndUrl="model['requestHttpTypeAndUrl']" |
17 | :method="model['requestContentType']" | 16 | :method="model['requestContentType']" |
18 | :requestOriginUrl="model['requestOriginUrl']" | 17 | :requestOriginUrl="model['requestOriginUrl']" |
@@ -42,7 +41,11 @@ | @@ -42,7 +41,11 @@ | ||
42 | saveDataViewInterface, | 41 | saveDataViewInterface, |
43 | updateDataViewInterface, | 42 | updateDataViewInterface, |
44 | } from '/@/api/bigscreen/center/bigscreenCenter'; | 43 | } from '/@/api/bigscreen/center/bigscreenCenter'; |
44 | + | ||
45 | import { useMessage } from '/@/hooks/web/useMessage'; | 45 | import { useMessage } from '/@/hooks/web/useMessage'; |
46 | + import { useUtils } from './hooks/useUtils'; | ||
47 | + | ||
48 | + const { resetReqHttpType, resetUpdateSchema } = useUtils(); | ||
46 | 49 | ||
47 | const emits = defineEmits(['success', 'register']); | 50 | const emits = defineEmits(['success', 'register']); |
48 | 51 | ||
@@ -52,8 +55,6 @@ | @@ -52,8 +55,6 @@ | ||
52 | 55 | ||
53 | const putId = ref(''); | 56 | const putId = ref(''); |
54 | 57 | ||
55 | - const activeKey = ref(''); | ||
56 | - | ||
57 | const simpleRequestRef = ref<InstanceType<typeof SimpleRequest>>(); | 58 | const simpleRequestRef = ref<InstanceType<typeof SimpleRequest>>(); |
58 | 59 | ||
59 | const testSqlRef = ref<InstanceType<typeof TestSql>>(); | 60 | const testSqlRef = ref<InstanceType<typeof TestSql>>(); |
@@ -67,18 +68,8 @@ | @@ -67,18 +68,8 @@ | ||
67 | const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => { | 68 | const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => { |
68 | await resetFields(); | 69 | await resetFields(); |
69 | await nextTick(); | 70 | await nextTick(); |
70 | - updateSchema({ | ||
71 | - field: 'requestHttpTypeAndUrl', | ||
72 | - componentProps: { | ||
73 | - type: '0', | ||
74 | - }, | ||
75 | - }); | ||
76 | - setFieldsValue({ | ||
77 | - requestHttpTypeAndUrl: { | ||
78 | - requestHttpType: undefined, | ||
79 | - requestUrl: '', | ||
80 | - }, | ||
81 | - }); | 71 | + updateSchema(resetUpdateSchema); |
72 | + setFieldsValue(resetReqHttpType); | ||
82 | const title = `${!data.isUpdate ? '新增' : '修改'}公共接口`; | 73 | const title = `${!data.isUpdate ? '新增' : '修改'}公共接口`; |
83 | setDrawerProps({ title }); | 74 | setDrawerProps({ title }); |
84 | isUpdate.value = data.isUpdate; | 75 | isUpdate.value = data.isUpdate; |
@@ -104,12 +95,9 @@ | @@ -104,12 +95,9 @@ | ||
104 | type: String(data.record?.requestContentType), | 95 | type: String(data.record?.requestContentType), |
105 | }, | 96 | }, |
106 | }); | 97 | }); |
107 | - } else { | ||
108 | } | 98 | } |
109 | }); | 99 | }); |
110 | 100 | ||
111 | - const handleActiveKey = (v) => (activeKey.value = v); | ||
112 | - | ||
113 | const handleSubmit = async () => { | 101 | const handleSubmit = async () => { |
114 | setDrawerProps({ loading: true }); | 102 | setDrawerProps({ loading: true }); |
115 | try { | 103 | try { |
1 | +export const useUtils = () => { | ||
2 | + //获取多个key | ||
3 | + const getMultipleKeys = (list) => { | ||
4 | + let temps = []; | ||
5 | + list?.forEach((it) => { | ||
6 | + const keys = it.key.split(','); | ||
7 | + const temp = keys.map((item) => { | ||
8 | + const obj: { key: string; value: string } = { key: '', value: '' }; | ||
9 | + obj.key = item; | ||
10 | + obj.value = item === 'scope' ? it.value : ''; | ||
11 | + return obj; | ||
12 | + }); | ||
13 | + temps = temp; | ||
14 | + }); | ||
15 | + return temps; | ||
16 | + }; | ||
17 | + //默认push一个 | ||
18 | + const pushObj = { | ||
19 | + key: undefined, | ||
20 | + value: '', | ||
21 | + editDisabled: false, | ||
22 | + required: false, | ||
23 | + date1: '', | ||
24 | + date2: '', | ||
25 | + }; | ||
26 | + //新增时置空特定数据 | ||
27 | + const resetReqHttpType = { | ||
28 | + requestHttpTypeAndUrl: { | ||
29 | + requestHttpType: undefined, | ||
30 | + requestUrl: '', | ||
31 | + }, | ||
32 | + }; | ||
33 | + const resetUpdateSchema = { | ||
34 | + field: 'requestHttpTypeAndUrl', | ||
35 | + componentProps: { | ||
36 | + type: '0', | ||
37 | + }, | ||
38 | + }; | ||
39 | + return { getMultipleKeys, pushObj, resetReqHttpType, resetUpdateSchema }; | ||
40 | +}; |