Showing
13 changed files
with
547 additions
and
156 deletions
... | ... | @@ -3,17 +3,20 @@ import type { |
3 | 3 | queryPageParams, |
4 | 4 | BigScreenCenterParams, |
5 | 5 | ConfigurationCenterInfo, |
6 | - BigScreenCenterItemsModal, | |
6 | + BigScreenCenterItemsModel, | |
7 | + BigScreenInterfaceParams, | |
7 | 8 | } from './model/bigscreenCenterModel'; |
8 | 9 | import { getPageData } from '../../base'; |
9 | 10 | import { FileUploadResponse } from '../../oem/model'; |
10 | 11 | enum API { |
11 | 12 | basicUrl = '/data_view', |
12 | 13 | UPLOAD = '/oss/upload', |
14 | + //大屏公共接口 | |
15 | + DATA_VIEW_INTERFACE = '/data_view_interface', | |
13 | 16 | } |
14 | 17 | |
15 | 18 | export const getPage = (params: queryPageParams) => { |
16 | - return getPageData<BigScreenCenterItemsModal>(params, API.basicUrl); | |
19 | + return getPageData<BigScreenCenterItemsModel>(params, API.basicUrl); | |
17 | 20 | }; |
18 | 21 | |
19 | 22 | export const saveConfigurationCenter = (params: BigScreenCenterParams) => { |
... | ... | @@ -46,3 +49,46 @@ export const saveOrUpdateBigScreenCenter = (params: ConfigurationCenterInfo, isU |
46 | 49 | export const uploadThumbnail = (file: FormData) => { |
47 | 50 | return defHttp.post<FileUploadResponse>({ url: API.UPLOAD, params: file }); |
48 | 51 | }; |
52 | + | |
53 | +/** | |
54 | + * 大屏公共接口 | |
55 | + */ | |
56 | + | |
57 | +export const getDataViewInterfacePage = (params: queryPageParams) => { | |
58 | + return getPageData<BigScreenCenterItemsModel>(params, API.DATA_VIEW_INTERFACE); | |
59 | +}; | |
60 | + | |
61 | +export const saveDataViewInterface = (params: BigScreenInterfaceParams) => { | |
62 | + return defHttp.post({ | |
63 | + url: API.DATA_VIEW_INTERFACE, | |
64 | + data: params, | |
65 | + }); | |
66 | +}; | |
67 | + | |
68 | +export const updateDataViewInterface = (params: BigScreenInterfaceParams) => { | |
69 | + return defHttp.put({ | |
70 | + url: API.DATA_VIEW_INTERFACE, | |
71 | + data: params, | |
72 | + }); | |
73 | +}; | |
74 | + | |
75 | +export const deleteBigViewInterface = (ids: string[]) => { | |
76 | + return defHttp.delete({ | |
77 | + url: API.DATA_VIEW_INTERFACE, | |
78 | + data: { | |
79 | + ids: ids, | |
80 | + }, | |
81 | + }); | |
82 | +}; | |
83 | + | |
84 | +export function getPublish(id) { | |
85 | + return defHttp.get({ | |
86 | + url: API.DATA_VIEW_INTERFACE + '/publish/' + id, | |
87 | + }); | |
88 | +} | |
89 | + | |
90 | +export function getCancelPublish(id) { | |
91 | + return defHttp.get({ | |
92 | + url: API.DATA_VIEW_INTERFACE + '/cancel_publish/' + id, | |
93 | + }); | |
94 | +} | ... | ... |
... | ... | @@ -25,3 +25,32 @@ export interface BigScreenCenterParams { |
25 | 25 | defaultContent?: string; |
26 | 26 | } |
27 | 27 | export type ConfigurationCenterInfo = BigScreenCenterParams; |
28 | + | |
29 | +/** | |
30 | + * 大屏公共接口 | |
31 | + */ | |
32 | +export interface BigScreenInterfaceParams { | |
33 | + createTime: string; | |
34 | + creator: string; | |
35 | + defaultConfig: string; | |
36 | + description: string; | |
37 | + enabled: boolean; | |
38 | + icon: string; | |
39 | + id: string; | |
40 | + interfaceName: string; | |
41 | + name: string; | |
42 | + remark: string; | |
43 | + requestContentType: 0; | |
44 | + requestHttpType: string; | |
45 | + requestOriginUrl: string; | |
46 | + requestParams: string; | |
47 | + requestUrl: string; | |
48 | + roleIds: [string]; | |
49 | + state: number; | |
50 | + tenantExpireTime: string; | |
51 | + tenantId: string; | |
52 | + tenantProfileId: string; | |
53 | + tenantStatus: string; | |
54 | + updateTime: string; | |
55 | + updater: string; | |
56 | +} | ... | ... |
1 | 1 | <template> |
2 | 2 | <div class="table-content"> |
3 | - <table align="center" style="width: 100%" cellspacing="0"> | |
3 | + <!-- 采用的原生表格 --> | |
4 | + <table align="center"> | |
4 | 5 | <thead> |
5 | 6 | <tr> |
6 | 7 | <th></th> |
7 | 8 | <th>Key</th> |
8 | 9 | <th>Value</th> |
10 | + <th>是否必须</th> | |
9 | 11 | <th>操作</th> |
10 | 12 | </tr> |
11 | 13 | </thead> |
... | ... | @@ -18,10 +20,9 @@ |
18 | 20 | <Select |
19 | 21 | v-model:value="item.key" |
20 | 22 | placeholder="请选择" |
21 | - notFoundContent="请选择" | |
22 | 23 | style="width: 14rem" |
23 | 24 | :options="selectOptions" |
24 | - @change="handleChange" | |
25 | + @change="handleChange(item.key)" | |
25 | 26 | allowClear |
26 | 27 | /> |
27 | 28 | </td> |
... | ... | @@ -34,6 +35,9 @@ |
34 | 35 | /> |
35 | 36 | </td> |
36 | 37 | <td> |
38 | + <a-switch v-model:checked="item.required" /> | |
39 | + </td> | |
40 | + <td> | |
37 | 41 | <div> |
38 | 42 | <Button type="dashed" @click="add(item, index)"> |
39 | 43 | <template #icon><PlusOutlined /></template |
... | ... | @@ -49,11 +53,10 @@ |
49 | 53 | </div> |
50 | 54 | </template> |
51 | 55 | <script lang="ts" setup name="editCellTable"> |
52 | - import { reactive, ref, onMounted } from 'vue'; | |
56 | + import { reactive, ref, onMounted, nextTick } from 'vue'; | |
53 | 57 | import { Select, Button } from 'ant-design-vue'; |
54 | 58 | import { findDictItemByCode } from '/@/api/system/dict'; |
55 | 59 | import { PlusOutlined, MinusOutlined } from '@ant-design/icons-vue'; |
56 | - import { buildUUID } from '/@/utils/uuid'; | |
57 | 60 | |
58 | 61 | const props = defineProps({ |
59 | 62 | method: { |
... | ... | @@ -61,7 +64,11 @@ |
61 | 64 | }, |
62 | 65 | }); |
63 | 66 | |
64 | - onMounted(async () => { | |
67 | + onMounted(() => { | |
68 | + getSelectOptions(); | |
69 | + }); | |
70 | + | |
71 | + const getSelectOptions = async () => { | |
65 | 72 | const res = await findDictItemByCode({ dictCode: 'dataview_builtin_params' }); |
66 | 73 | selectOptions.value = res.map((m) => ({ label: m.itemText, value: m.itemValue })); |
67 | 74 | selectOptions.value.push({ |
... | ... | @@ -70,15 +77,15 @@ |
70 | 77 | }); |
71 | 78 | if (props.method === '2') |
72 | 79 | selectOptions.value = selectOptions.value.filter((f) => f.value !== 'scope'); |
73 | - }); | |
80 | + }; | |
74 | 81 | |
75 | 82 | const selectOptions = ref<{ label: string; value: string; disabled?: boolean }[]>([]); |
76 | 83 | |
77 | 84 | type defaultItem = { |
78 | - id: string; | |
79 | 85 | key: null | string; |
80 | 86 | value: string; |
81 | 87 | editDisabled: boolean; |
88 | + required: boolean; | |
82 | 89 | }; |
83 | 90 | |
84 | 91 | const tableArray = reactive<{ |
... | ... | @@ -86,10 +93,10 @@ |
86 | 93 | }>({ |
87 | 94 | content: [ |
88 | 95 | { |
89 | - id: buildUUID(), | |
90 | 96 | key: null, |
91 | 97 | value: '', |
92 | 98 | editDisabled: false, |
99 | + required: false, | |
93 | 100 | }, |
94 | 101 | ], |
95 | 102 | }); |
... | ... | @@ -97,10 +104,10 @@ |
97 | 104 | // 新增 |
98 | 105 | const add = (_, index: number) => { |
99 | 106 | tableArray.content.splice(index + 1, 0, { |
100 | - id: buildUUID(), | |
101 | 107 | key: null, |
102 | 108 | value: '', |
103 | 109 | editDisabled: false, |
110 | + required: false, | |
104 | 111 | }); |
105 | 112 | }; |
106 | 113 | |
... | ... | @@ -117,7 +124,8 @@ |
117 | 124 | }; |
118 | 125 | |
119 | 126 | //Select互斥 |
120 | - const handleChange = () => { | |
127 | + const handleChange = (value: string) => { | |
128 | + console.log(value); | |
121 | 129 | selectOptions.value.forEach((ele) => { |
122 | 130 | ele.disabled = false; |
123 | 131 | tableArray.content.forEach((element) => { |
... | ... | @@ -135,20 +143,40 @@ |
135 | 143 | |
136 | 144 | //获取数据 |
137 | 145 | const getValue = () => { |
138 | - const params = {}; | |
139 | - tableArray.content?.map((item: any) => { | |
140 | - if (item?.key !== 'scope') params[item?.key] = item.value; | |
141 | - params[`${(item?.key + item?.id).slice(0, 10)}`] = item.value; | |
142 | - }); | |
143 | - return params; | |
146 | + return tableArray.content; | |
144 | 147 | }; |
145 | 148 | |
146 | 149 | //设置数据 |
147 | - const setValue = (data) => (tableArray.content = data); | |
150 | + const setValue = (data) => { | |
151 | + nextTick(() => (tableArray.content = data)); | |
152 | + nextTick(() => | |
153 | + setTimeout(() => { | |
154 | + tableArray.content.forEach((it: any) => { | |
155 | + handleChange(it.key); | |
156 | + }); | |
157 | + }, 20) | |
158 | + ); | |
159 | + }; | |
148 | 160 | |
161 | + //重置数据 | |
162 | + const resetValue = () => { | |
163 | + tableArray.content = []; | |
164 | + tableArray.content.push({ | |
165 | + key: null, | |
166 | + value: '', | |
167 | + editDisabled: false, | |
168 | + required: false, | |
169 | + }); | |
170 | + nextTick(() => { | |
171 | + tableArray.content.forEach((it: any) => { | |
172 | + handleChange(it.key); | |
173 | + }); | |
174 | + }); | |
175 | + }; | |
149 | 176 | defineExpose({ |
150 | 177 | getValue, |
151 | 178 | setValue, |
179 | + resetValue, | |
152 | 180 | }); |
153 | 181 | </script> |
154 | 182 | |
... | ... | @@ -161,10 +189,11 @@ |
161 | 189 | } |
162 | 190 | |
163 | 191 | .table-content { |
164 | - margin-top: 20px; | |
165 | - margin-right: 20px; | |
192 | + overflow-x: auto; | |
166 | 193 | |
167 | 194 | table { |
195 | + border-collapse: collapse; | |
196 | + width: 100%; | |
168 | 197 | &:extend(.table-border-color); |
169 | 198 | } |
170 | 199 | ... | ... |
1 | 1 | <template> |
2 | 2 | <div> |
3 | - <a-radio-group v-model:value="getRequestBody.content.radioValue" @change="handleChange"> | |
3 | + <a-radio-group | |
4 | + v-model:value="getRequestBody.content.requestParamsBodyType" | |
5 | + @change="handleChange" | |
6 | + > | |
4 | 7 | <a-radio v-for="item in RequestBodyTypeEnum" :key="item" :value="item">{{ item }}</a-radio> |
5 | 8 | </a-radio-group> |
6 | 9 | <div class="mt-3"> |
7 | 10 | <a-textarea |
8 | - v-if="getRequestBody.content.radioValue === 'none'" | |
11 | + v-show="getRequestBody.content.requestParamsBodyType === 'none'" | |
9 | 12 | disabled |
10 | 13 | placeholder="该接口没有 Body 体" |
11 | 14 | :rows="2" |
12 | 15 | /> |
13 | 16 | <EditCellTable |
14 | - v-if=" | |
15 | - getRequestBody.content.radioValue === 'form-data' || | |
16 | - getRequestBody.content.radioValue === 'x-www-form-urlencoded' | |
17 | + ref="editCellTableRef" | |
18 | + v-show=" | |
19 | + getRequestBody.content.requestParamsBodyType === 'form-data' || | |
20 | + getRequestBody.content.requestParamsBodyType === 'x-www-form-urlencoded' | |
17 | 21 | " |
18 | 22 | /> |
19 | 23 | <a-textarea |
20 | 24 | v-model:value="getRequestBody.content.json" |
21 | - v-if="getRequestBody.content.radioValue === 'json'" | |
25 | + v-show="getRequestBody.content.requestParamsBodyType === 'json'" | |
22 | 26 | placeholder="请输入json" |
23 | 27 | :rows="6" |
24 | 28 | /> |
25 | 29 | <a-textarea |
26 | 30 | v-model:value="getRequestBody.content.xml" |
27 | - v-if="getRequestBody.content.radioValue === 'xml'" | |
31 | + v-show="getRequestBody.content.requestParamsBodyType === 'xml'" | |
28 | 32 | placeholder="请输入xml" |
29 | 33 | :rows="6" |
30 | 34 | /> |
... | ... | @@ -32,7 +36,7 @@ |
32 | 36 | </div> |
33 | 37 | </template> |
34 | 38 | <script lang="ts" setup name="body"> |
35 | - import { reactive } from 'vue'; | |
39 | + import { reactive, ref, nextTick } from 'vue'; | |
36 | 40 | import { RequestBodyTypeEnum } from '../../enum/index'; |
37 | 41 | import { EditCellTable } from '../EditCellTable/index'; |
38 | 42 | |
... | ... | @@ -43,25 +47,65 @@ |
43 | 47 | }); |
44 | 48 | |
45 | 49 | const getRequestBody = reactive({ |
46 | - content: { json: '', xml: '', radioValue: 'none' }, | |
50 | + content: { | |
51 | + requestParamsBodyType: 'none', | |
52 | + json: '', | |
53 | + xml: '', | |
54 | + 'form-data': {}, | |
55 | + 'x-www-form-urlencoded': {}, | |
56 | + }, | |
47 | 57 | }); |
48 | 58 | |
59 | + const editCellTableRef = ref<InstanceType<typeof EditCellTable>>(); | |
60 | + | |
49 | 61 | const handleChange = ({ target }) => { |
50 | 62 | const { value } = target; |
51 | - getRequestBody.content.radioValue = value; | |
63 | + getRequestBody.content.requestParamsBodyType = value; | |
52 | 64 | }; |
53 | 65 | |
54 | 66 | //获取数据 |
55 | 67 | const getValue = () => { |
68 | + const type = Reflect.get(getRequestBody.content, 'requestParamsBodyType'); | |
69 | + if (type === 'none') getRequestBody.content = {} as any; | |
70 | + const values = editCellTableRef.value?.getValue(); | |
71 | + if (type === 'form-data') getRequestBody.content['form-data'] = values as any; | |
72 | + if (type === 'x-www-form-urlencoded') | |
73 | + getRequestBody.content['x-www-form-urlencoded'] = values as any; | |
56 | 74 | return getRequestBody.content; |
57 | 75 | }; |
58 | 76 | |
59 | 77 | //设置数据 |
60 | 78 | const setValue = (data) => { |
61 | - getRequestBody.content = data; | |
79 | + nextTick(() => { | |
80 | + try { | |
81 | + if (!data) return; | |
82 | + const type = data?.requestParamsBodyType; | |
83 | + getRequestBody.content.requestParamsBodyType = type; | |
84 | + type === 'none' | |
85 | + ? null | |
86 | + : type === 'form-data' | |
87 | + ? editCellTableRef.value?.setValue(data['form-data']) | |
88 | + : type === 'x-www-form-urlencoded' | |
89 | + ? editCellTableRef.value?.setValue(data['x-www-form-urlencoded']) | |
90 | + : type === 'json' | |
91 | + ? (getRequestBody.content.json = data['json']) | |
92 | + : type === 'xml' | |
93 | + ? (getRequestBody.content.xml = data['xml']) | |
94 | + : ''; | |
95 | + } finally { | |
96 | + } | |
97 | + }); | |
98 | + }; | |
99 | + | |
100 | + //重置数据 | |
101 | + const resetValue = () => { | |
102 | + for (let i in getRequestBody.content) Reflect.set(getRequestBody.content, i, ''); | |
103 | + getRequestBody.content.requestParamsBodyType = 'none'; | |
104 | + nextTick(() => editCellTableRef?.value?.resetValue()); | |
62 | 105 | }; |
63 | 106 | defineExpose({ |
64 | 107 | getValue, |
65 | 108 | setValue, |
109 | + resetValue, | |
66 | 110 | }); |
67 | 111 | </script> | ... | ... |
src/views/dataview/publicApi/components/SimpleRequest/index.ts
deleted
100644 → 0
1 | 1 | <template> |
2 | 2 | <div> |
3 | - <div> | |
4 | - <Tabs type="card" v-model:activeKey="activeKey"> | |
5 | - <TabPane forceRender v-for="item in RequestParamsTypeEnum" :key="item" :tab="item" /> | |
6 | - </Tabs> | |
7 | - </div> | |
8 | - <div> | |
9 | - <div v-if="activeKey === RequestParamsTypeEnum.PARAMS"> | |
3 | + <Tabs @change="handleChange" v-model:activeKey="activeKey"> | |
4 | + <TabPane class="tab-pane" forceRender key="Params" tab="Params"> | |
10 | 5 | <EditCellTable ref="editCellTableRef" :method="method" /> |
11 | - <TestRequest :method="method" /> | |
12 | - </div> | |
13 | - <div v-if="activeKey === RequestParamsTypeEnum.BODY"> | |
14 | - <Body :method="method" /> | |
15 | - <TestRequest :method="method" /> | |
16 | - </div> | |
17 | - <div v-if="activeKey === RequestParamsTypeEnum.HEADER"> | |
18 | - <EditCellTable ref="editCellTableRef" :method="method" /> | |
19 | - <TestRequest :method="method" /> | |
20 | - </div> | |
21 | - </div> | |
6 | + <TestRequest ref="testParRequestRef" :method="method" :data="dataList" /> | |
7 | + </TabPane> | |
8 | + <TabPane v-if="method !== '2'" class="tab-pane" forceRender key="Body" tab="Body"> | |
9 | + <Body ref="bodyRef" :method="method" /> | |
10 | + <TestRequest ref="testBodyRequestRef" :method="method" :data="dataList" /> | |
11 | + </TabPane> | |
12 | + <TabPane v-if="method !== '2'" class="tab-pane" forceRender key="Header" tab="Header"> | |
13 | + <EditCellTable ref="editHeaderCellTableRef" :method="method" /> | |
14 | + <TestRequest ref="testHeaderRequestRef" :method="method" :data="dataList" /> | |
15 | + </TabPane> | |
16 | + </Tabs> | |
22 | 17 | </div> |
23 | 18 | </template> |
24 | 19 | <script lang="ts" setup name="simpleRequest"> |
25 | - import { ref } from 'vue'; | |
20 | + import { ref, nextTick } from 'vue'; | |
26 | 21 | import { Tabs, TabPane } from 'ant-design-vue'; |
27 | - import { RequestParamsTypeEnum } from '../../enum'; | |
28 | 22 | import { EditCellTable } from '../EditCellTable'; |
29 | 23 | import Body from './body.vue'; |
30 | 24 | import { TestRequest } from '../TestRequest/index'; |
31 | 25 | |
32 | - const props = defineProps({ | |
26 | + defineProps({ | |
33 | 27 | method: { |
34 | 28 | type: String, |
35 | 29 | }, |
36 | 30 | }); |
37 | 31 | |
38 | - if (props.method === '2') { | |
39 | - Reflect.deleteProperty(RequestParamsTypeEnum, 'BODY'); | |
40 | - Reflect.deleteProperty(RequestParamsTypeEnum, 'HEADER'); | |
41 | - } else { | |
42 | - Reflect.set(RequestParamsTypeEnum, 'BODY', 'Body'); | |
43 | - Reflect.set(RequestParamsTypeEnum, 'HEADER', 'Header'); | |
44 | - } | |
32 | + const emits = defineEmits(['activeKey']); | |
45 | 33 | |
46 | 34 | const activeKey = ref('Params'); |
47 | 35 | |
48 | 36 | const editCellTableRef = ref<InstanceType<typeof EditCellTable>>(); |
49 | 37 | |
38 | + const editHeaderCellTableRef = ref<InstanceType<typeof EditCellTable>>(); | |
39 | + | |
40 | + const testParRequestRef = ref<InstanceType<typeof TestRequest>>(); | |
41 | + | |
42 | + const testBodyRequestRef = ref<InstanceType<typeof TestRequest>>(); | |
43 | + | |
44 | + const testHeaderRequestRef = ref<InstanceType<typeof TestRequest>>(); | |
45 | + | |
46 | + const dataList = ref({}); | |
47 | + | |
48 | + const bodyRef = ref<InstanceType<typeof Body>>(); | |
49 | + | |
50 | + const handleChange = () => { | |
51 | + testParRequestRef.value?.setValue(); | |
52 | + testHeaderRequestRef.value?.setValue(); | |
53 | + testBodyRequestRef.value?.setValue(); | |
54 | + }; | |
55 | + | |
50 | 56 | //获取数据 |
51 | 57 | const getValue = () => { |
52 | - return editCellTableRef?.value?.getValue(); | |
58 | + const type = activeKey.value; | |
59 | + const Body = bodyRef.value?.getValue(); | |
60 | + const Params = editCellTableRef.value?.getValue(); | |
61 | + const Header = editHeaderCellTableRef.value?.getValue(); | |
62 | + emits('activeKey', type); | |
63 | + return type === 'Params' ? Params : type === 'Body' ? Body : Header; | |
53 | 64 | }; |
54 | 65 | |
55 | 66 | //设置数据 |
56 | 67 | const setValue = (data) => { |
57 | - editCellTableRef?.value?.setValue(data); | |
68 | + dataList.value = data; | |
69 | + const Objects = JSON.parse(data?.requestParams); | |
70 | + nextTick(() => { | |
71 | + if (!Objects) return; | |
72 | + activeKey.value = Objects?.type; | |
73 | + if (activeKey.value === 'Params') { | |
74 | + editCellTableRef.value?.setValue(Objects?.Params); | |
75 | + testParRequestRef.value?.setValue(); | |
76 | + } else if (activeKey.value === 'Body') { | |
77 | + bodyRef.value?.setValue(Objects?.Body); | |
78 | + testBodyRequestRef.value?.setValue(); | |
79 | + } else if (activeKey.value === 'Header') { | |
80 | + editHeaderCellTableRef.value?.setValue(Objects?.Header); | |
81 | + testHeaderRequestRef.value?.setValue(); | |
82 | + } else { | |
83 | + } | |
84 | + }); | |
85 | + }; | |
86 | + | |
87 | + //重置数据 | |
88 | + const resetValue = () => { | |
89 | + activeKey.value = 'Params'; | |
90 | + nextTick(() => { | |
91 | + editCellTableRef.value?.resetValue(); | |
92 | + editHeaderCellTableRef.value?.resetValue(); | |
93 | + bodyRef.value?.resetValue(); | |
94 | + }); | |
58 | 95 | }; |
59 | 96 | |
60 | 97 | defineExpose({ |
61 | 98 | getValue, |
62 | 99 | setValue, |
100 | + resetValue, | |
63 | 101 | }); |
64 | 102 | </script> |
103 | + | |
104 | +<style lang="less" scoped> | |
105 | + .tab-pane { | |
106 | + display: flex; | |
107 | + justify-content: flex-start; | |
108 | + flex-direction: column; | |
109 | + align-items: flex-start; | |
110 | + } | |
111 | +</style> | ... | ... |
... | ... | @@ -264,12 +264,7 @@ |
264 | 264 | |
265 | 265 | //获取数据 |
266 | 266 | const getValue = () => { |
267 | - const params = {}; | |
268 | - tableArray.content?.map((item: any) => { | |
269 | - if (item?.key !== 'scope') params[item?.key] = item.value; | |
270 | - params[`${(item?.key + item?.id).slice(0, 10)}`] = item.value; | |
271 | - }); | |
272 | - return params; | |
267 | + return tableArray.content; | |
273 | 268 | }; |
274 | 269 | defineExpose({ |
275 | 270 | getValue, | ... | ... |
1 | 1 | <template> |
2 | - <div class="mt-8"> | |
3 | - <div> | |
4 | - <Button @click="showTestEditCell = true" type="primary"> 测试一下 </Button> | |
2 | + <div> | |
3 | + <div class="mt-8"> | |
4 | + <div> | |
5 | + <Button @click="showTestEditCell = true" 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> | |
5 | 15 | </div> |
6 | 16 | <div v-if="showTestEditCell" class="mt-8"> |
7 | - <a-row type="flex" justify="center"> | |
8 | - <a-col :span="3"> 参数设置 </a-col> | |
9 | - <a-col :span="21"> | |
10 | - <TestEditCellTable ref="testEditCellTableRef" :method="method" /> | |
11 | - </a-col> | |
12 | - </a-row> | |
13 | - </div> | |
14 | - </div> | |
15 | - <div v-if="showTestEditCell" class="mt-8"> | |
16 | - <div> | |
17 | - <Button @click="handleExcute" type="primary"> 执行 </Button> | |
18 | - </div> | |
19 | - <div class="mt-8"> | |
20 | - <a-row type="flex" justify="center"> | |
21 | - <a-col :span="3"> 测试结果 </a-col> | |
22 | - <a-col :span="21"> | |
23 | - <a-textarea v-model:value="testResult" placeholder="测试结果为:" :rows="6" /> | |
24 | - </a-col> | |
25 | - </a-row> | |
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> | |
26 | 34 | </div> |
27 | 35 | </div> |
28 | 36 | </template> |
29 | -<script lang="ts" setup name="testSql"> | |
37 | +<script lang="ts" setup name="testRequest"> | |
30 | 38 | import { ref } from 'vue'; |
31 | 39 | import { Button } from 'ant-design-vue'; |
32 | 40 | import { TestEditCellTable } from '../TestEditCellTable/index'; |
41 | + import { getAllDeviceByOrg } from '/@/api/dataBoard'; | |
42 | + import { getDeviceAttributes } from '/@/api/dataBoard'; | |
33 | 43 | |
34 | 44 | defineProps({ |
35 | 45 | method: { |
36 | 46 | type: String, |
37 | 47 | }, |
48 | + data: { | |
49 | + type: Object, | |
50 | + }, | |
38 | 51 | }); |
39 | 52 | |
40 | 53 | const showTestEditCell = ref(false); |
... | ... | @@ -43,10 +56,34 @@ |
43 | 56 | |
44 | 57 | const testResult = ref(''); |
45 | 58 | |
59 | + // const testNeedKeys = ['organizationId', 'deviceProfileId', 'entityId', 'keys', 'date']; | |
60 | + | |
46 | 61 | const handleExcute = async () => { |
47 | 62 | const params = testEditCellTableRef.value?.getValue(); |
48 | - testResult.value = JSON.stringify(params); | |
63 | + const keys = params?.map((m) => ({ key: m.key, value: m.value })); | |
64 | + keys?.forEach(async (it: any) => { | |
65 | + console.log(it); | |
66 | + if (it.key === 'organizationId') { | |
67 | + //获取设备 | |
68 | + const data = await getAllDeviceByOrg(it.value!); | |
69 | + testResult.value = JSON.stringify(data); | |
70 | + } | |
71 | + if (it.key === 'deviceProfileId') { | |
72 | + //获取属性 | |
73 | + const data = await getDeviceAttributes({ deviceProfileId: it.value! }); | |
74 | + testResult.value = JSON.stringify(data); | |
75 | + } | |
76 | + }); | |
49 | 77 | }; |
78 | + | |
79 | + //设置数据 | |
80 | + const setValue = () => { | |
81 | + showTestEditCell.value = false; | |
82 | + testResult.value = ''; | |
83 | + }; | |
84 | + defineExpose({ | |
85 | + setValue, | |
86 | + }); | |
50 | 87 | </script> |
51 | 88 | |
52 | 89 | <style scoped lang="less"></style> | ... | ... |
1 | 1 | <template> |
2 | 2 | <div class="mt-8"> |
3 | 3 | <div> |
4 | - <Button @click="handleExcute" type="primary"> 测试一下 </Button> | |
4 | + <Button @click="handleExcute" type="primary"> 测试SQL </Button> | |
5 | 5 | </div> |
6 | 6 | </div> |
7 | 7 | <div class="mt-8"> |
... | ... | @@ -9,7 +9,13 @@ |
9 | 9 | <a-row type="flex" justify="center"> |
10 | 10 | <a-col :span="3"> 测试结果 </a-col> |
11 | 11 | <a-col :span="21"> |
12 | - <a-textarea v-model:value="testResult" placeholder="测试结果为:" :rows="6" /> | |
12 | + <a-textarea | |
13 | + allow-clear | |
14 | + show-count | |
15 | + v-model:value="testResult" | |
16 | + placeholder="测试结果为:" | |
17 | + :rows="8" | |
18 | + /> | |
13 | 19 | </a-col> |
14 | 20 | </a-row> |
15 | 21 | </div> |
... | ... | @@ -27,9 +33,15 @@ |
27 | 33 | |
28 | 34 | const testResult = ref(''); |
29 | 35 | |
30 | - const handleExcute = () => { | |
36 | + const handleExcute = async () => { | |
31 | 37 | testResult.value = '测试结果为:1234'; |
32 | 38 | }; |
39 | + | |
40 | + const resetValue = () => (testResult.value = ''); | |
41 | + | |
42 | + defineExpose({ | |
43 | + resetValue, | |
44 | + }); | |
33 | 45 | </script> |
34 | 46 | |
35 | 47 | <style scoped lang="less"></style> | ... | ... |
... | ... | @@ -8,53 +8,65 @@ export const columns: BasicColumn[] = [ |
8 | 8 | { |
9 | 9 | title: '接口名称', |
10 | 10 | dataIndex: 'interfaceName', |
11 | - width: 80, | |
11 | + width: 150, | |
12 | 12 | }, |
13 | 13 | { |
14 | 14 | title: '请求方式', |
15 | 15 | dataIndex: 'requestContentType', |
16 | - width: 120, | |
16 | + width: 90, | |
17 | 17 | format(text) { |
18 | - return text === '0' ? '普通请求' : text === '1' ? 'SQL请求' : 'websocket请求'; | |
18 | + return Number(text) === 0 ? '普通请求' : Number(text) === 1 ? 'SQL请求' : 'websocket请求'; | |
19 | 19 | }, |
20 | 20 | }, |
21 | 21 | { |
22 | 22 | title: '接口内容', |
23 | 23 | dataIndex: 'content', |
24 | - width: 120, | |
24 | + width: 80, | |
25 | + slots: { customRender: 'content' }, | |
25 | 26 | }, |
26 | 27 | { |
27 | 28 | title: '状态', |
28 | - dataIndex: 'status', | |
29 | - width: 120, | |
29 | + dataIndex: 'state', | |
30 | + width: 80, | |
30 | 31 | customRender: ({ record }) => { |
31 | - const status = record.status; | |
32 | - const color = status == 0 ? 'green' : 'red'; | |
33 | - const text = status == 0 ? '发布' : '未发布'; | |
32 | + const status = record.state; | |
33 | + const color = status == 1 ? 'green' : 'red'; | |
34 | + const text = status == 1 ? '发布' : '未发布'; | |
34 | 35 | return h(Tag, { color: color }, () => text); |
35 | 36 | }, |
36 | 37 | }, |
37 | 38 | ]; |
38 | 39 | |
39 | -//模拟数据 | |
40 | -export const list = [ | |
40 | +// 查询配置 | |
41 | +export const searchFormSchema: FormSchema[] = [ | |
41 | 42 | { |
42 | - interfaceName: '传感器趋势图', | |
43 | - requestContentType: '0', | |
44 | - content: '/api/sensor', | |
45 | - status: 0, | |
46 | - }, | |
47 | - { | |
48 | - interfaceName: '2co趋势图', | |
49 | - requestContentType: '2', | |
50 | - content: '/api/2co', | |
51 | - status: 1, | |
43 | + field: 'name', | |
44 | + label: '接口名称', | |
45 | + component: 'Input', | |
46 | + colProps: { span: 8 }, | |
47 | + componentProps: { | |
48 | + maxLength: 36, | |
49 | + placeholder: '请输入接口名称', | |
50 | + }, | |
52 | 51 | }, |
53 | 52 | { |
54 | - interfaceName: 'temp趋势图', | |
55 | - requestContentType: '1', | |
56 | - content: '/api/temp', | |
57 | - status: 1, | |
53 | + field: 'state', | |
54 | + label: '发布状态', | |
55 | + component: 'Select', | |
56 | + colProps: { span: 8 }, | |
57 | + componentProps: { | |
58 | + options: [ | |
59 | + { | |
60 | + label: '发布', | |
61 | + value: 1, | |
62 | + }, | |
63 | + { | |
64 | + label: '未发布', | |
65 | + value: 0, | |
66 | + }, | |
67 | + ], | |
68 | + placeholder: '请选择发布状态', | |
69 | + }, | |
58 | 70 | }, |
59 | 71 | ]; |
60 | 72 | |
... | ... | @@ -149,7 +161,7 @@ export const schemas: FormSchema[] = [ |
149 | 161 | values['requestContentType'] === '0' || values['requestContentType'] === '1', |
150 | 162 | }, |
151 | 163 | { |
152 | - field: 'sqlKey', | |
164 | + field: 'requestSQLKey', | |
153 | 165 | label: '键名', |
154 | 166 | colProps: { span: 12 }, |
155 | 167 | component: 'Input', |
... | ... | @@ -160,7 +172,7 @@ export const schemas: FormSchema[] = [ |
160 | 172 | ifShow: ({ values }) => values['requestContentType'] === '1', |
161 | 173 | }, |
162 | 174 | { |
163 | - field: 'sqlValue', | |
175 | + field: 'requestSQLContent', | |
164 | 176 | label: '键值', |
165 | 177 | colProps: { span: 24 }, |
166 | 178 | component: 'InputTextArea', | ... | ... |
... | ... | @@ -12,16 +12,19 @@ |
12 | 12 | <SimpleRequest |
13 | 13 | ref="simpleRequestRef" |
14 | 14 | v-if="model['requestContentType'] === '0'" |
15 | + @activeKey="handleActiveKey" | |
15 | 16 | :method="model['requestContentType']" |
16 | 17 | /> |
17 | 18 | <SimpleRequest |
18 | 19 | ref="simpleRequestRef" |
19 | - v-if="model['requestContentType'] === '2'" | |
20 | + @activeKey="handleActiveKey" | |
21 | + v-else-if="model['requestContentType'] === '2'" | |
20 | 22 | :method="model['requestContentType']" |
21 | 23 | /> |
22 | 24 | </template> |
23 | 25 | <template #testSql="{ model }"> |
24 | 26 | <TestSql |
27 | + ref="testSqlRef" | |
25 | 28 | v-if="model['requestContentType'] === '1'" |
26 | 29 | :method="model['requestContentType']" |
27 | 30 | /> |
... | ... | @@ -31,38 +34,110 @@ |
31 | 34 | </div> |
32 | 35 | </template> |
33 | 36 | <script lang="ts" setup name="publicApi"> |
34 | - import { ref } from 'vue'; | |
37 | + import { ref, nextTick } from 'vue'; | |
35 | 38 | import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'; |
36 | 39 | import { BasicForm, useForm } from '/@/components/Form'; |
37 | 40 | import { schemas } from './config'; |
38 | - import { SimpleRequest } from './components/SimpleRequest'; | |
41 | + import SimpleRequest from './components/SimpleRequest/index.vue'; | |
39 | 42 | import { TestSql } from './components/TestSql/index'; |
43 | + import { | |
44 | + saveDataViewInterface, | |
45 | + updateDataViewInterface, | |
46 | + } from '/@/api/bigscreen/center/bigscreenCenter'; | |
47 | + import { useMessage } from '/@/hooks/web/useMessage'; | |
48 | + | |
49 | + const emits = defineEmits(['success', 'register']); | |
50 | + | |
51 | + const { createMessage } = useMessage(); | |
52 | + | |
53 | + const isUpdate = ref(false); | |
54 | + | |
55 | + const putId = ref(''); | |
56 | + | |
57 | + const activeKey = ref(''); | |
40 | 58 | |
41 | 59 | const simpleRequestRef = ref<InstanceType<typeof SimpleRequest>>(); |
42 | 60 | |
43 | - const [registerForm, { resetFields, validate, setFieldsValue }] = useForm({ | |
61 | + const testSqlRef = ref<InstanceType<typeof TestSql>>(); | |
62 | + | |
63 | + const [registerForm, { resetFields, validate, setFieldsValue, updateSchema }] = useForm({ | |
44 | 64 | labelWidth: 120, |
45 | 65 | schemas, |
46 | 66 | showActionButtonGroup: false, |
47 | 67 | }); |
48 | 68 | |
49 | - const [registerDrawer, { setDrawerProps }] = useDrawerInner(async (data) => { | |
69 | + const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => { | |
70 | + setDrawerProps({ loading: true }); | |
71 | + await nextTick(); | |
50 | 72 | await resetFields(); |
73 | + nextTick(() => simpleRequestRef.value?.resetValue()); | |
74 | + nextTick(() => testSqlRef.value?.resetValue()); | |
51 | 75 | const title = `${!data.isUpdate ? '新增' : '修改'}公共接口`; |
52 | 76 | setDrawerProps({ title }); |
53 | - setFieldsValue({ ...data.record }); | |
77 | + isUpdate.value = data.isUpdate; | |
78 | + !isUpdate.value ? (putId.value = '') : (putId.value = data.record.id); | |
79 | + if (isUpdate.value) { | |
80 | + await setFieldsValue({ | |
81 | + ...data.record, | |
82 | + requestContentType: String(data.record?.requestContentType), | |
83 | + requestSQLContent: JSON.parse(data.record?.requestParams)?.requestSQLContent?.sql, | |
84 | + }); | |
85 | + await nextTick(() => | |
86 | + setTimeout(() => { | |
87 | + simpleRequestRef.value?.setValue(data.record); | |
88 | + }, 200) | |
89 | + ); | |
90 | + const opt = [ | |
91 | + { label: 'get', value: 'GET' }, | |
92 | + { label: 'post', value: 'POST' }, | |
93 | + { label: 'put', value: 'PUT' }, | |
94 | + ]; | |
95 | + if (data.record?.requestContentType === 1) { | |
96 | + updateSchema({ | |
97 | + field: 'requestHttpType', | |
98 | + componentProps: { | |
99 | + options: opt.slice(-2), | |
100 | + }, | |
101 | + }); | |
102 | + } else { | |
103 | + updateSchema({ | |
104 | + field: 'requestHttpType', | |
105 | + componentProps: { | |
106 | + options: opt, | |
107 | + }, | |
108 | + }); | |
109 | + } | |
110 | + } | |
111 | + setDrawerProps({ loading: false }); | |
54 | 112 | }); |
55 | 113 | |
114 | + const handleActiveKey = (v) => (activeKey.value = v); | |
115 | + | |
56 | 116 | const handleOnSubmit = async () => { |
57 | - const values = await validate(); | |
58 | - if (!values) return; | |
59 | - const params = simpleRequestRef?.value?.getValue(); | |
60 | - const data = { | |
61 | - ...values, | |
62 | - requestParams: { | |
63 | - params, | |
64 | - }, | |
65 | - }; | |
66 | - console.log('Get form values', data); | |
117 | + setDrawerProps({ loading: true }); | |
118 | + try { | |
119 | + const values = await validate(); | |
120 | + if (!values) return; | |
121 | + const Objects = simpleRequestRef.value?.getValue(); | |
122 | + const data = { | |
123 | + ...values, | |
124 | + id: !putId.value ? null : putId.value, | |
125 | + requestParams: JSON.stringify({ | |
126 | + requestSQLContent: { | |
127 | + sql: values?.requestSQLContent, | |
128 | + }, | |
129 | + type: activeKey.value, | |
130 | + Params: activeKey.value === 'Params' ? Objects : {}, | |
131 | + Body: activeKey.value === 'Body' ? Objects : {}, | |
132 | + Header: activeKey.value === 'Header' ? Objects : {}, | |
133 | + }), | |
134 | + }; | |
135 | + !putId.value ? await saveDataViewInterface(data) : await updateDataViewInterface(data); | |
136 | + emits('success'); | |
137 | + closeDrawer(); | |
138 | + createMessage.success(`${!isUpdate.value ? '新增' : '修改'}成功`); | |
139 | + } finally { | |
140 | + setDrawerProps({ loading: false }); | |
141 | + } | |
67 | 142 | }; |
68 | 143 | </script> | ... | ... |
1 | 1 | <template> |
2 | 2 | <div> |
3 | 3 | <BasicTable @register="registerTable"> |
4 | + <template #content="{ record }"> | |
5 | + <a-button type="link" class="ml-2" @click="handleRecordContent(record)"> 查看 </a-button> | |
6 | + </template> | |
4 | 7 | <template #toolbar> |
5 | 8 | <a-button type="primary" @click="handleCreateOrEdit(null)"> 新增公共接口 </a-button> |
9 | + <Popconfirm | |
10 | + title="您确定要批量删除数据" | |
11 | + ok-text="确定" | |
12 | + cancel-text="取消" | |
13 | + @confirm="handleDeleteOrBatchDelete(null)" | |
14 | + > | |
15 | + <a-button color="error" :disabled="hasBatchDelete"> 批量删除 </a-button> | |
16 | + </Popconfirm> | |
6 | 17 | </template> |
7 | 18 | <template #action="{ record }"> |
8 | 19 | <TableAction |
9 | 20 | :actions="[ |
10 | 21 | { |
11 | 22 | label: '发布', |
12 | - icon: 'clarity:note-edit-line', | |
13 | - onClick: handleCreateOrEdit.bind(null, record), | |
23 | + icon: 'ant-design:node-expand-outlined', | |
24 | + onClick: handlePublish.bind(null, record), | |
25 | + ifShow: () => { | |
26 | + return record.state === 0; | |
27 | + }, | |
14 | 28 | }, |
15 | 29 | { |
16 | 30 | label: '取消发布', |
17 | - icon: 'clarity:note-edit-line', | |
18 | - onClick: handleCreateOrEdit.bind(null, record), | |
31 | + icon: 'ant-design:node-collapse-outlined', | |
32 | + onClick: handleCancelPublish.bind(null, record), | |
33 | + ifShow: () => { | |
34 | + return record.state === 1; | |
35 | + }, | |
19 | 36 | }, |
20 | 37 | { |
21 | 38 | label: '修改', |
22 | 39 | icon: 'clarity:note-edit-line', |
23 | 40 | onClick: handleCreateOrEdit.bind(null, record), |
41 | + ifShow: () => { | |
42 | + return record.state === 0; | |
43 | + }, | |
24 | 44 | }, |
25 | 45 | { |
26 | 46 | label: '删除', |
27 | 47 | icon: 'ant-design:delete-outlined', |
28 | 48 | color: 'error', |
49 | + ifShow: () => { | |
50 | + return record.state === 0; | |
51 | + }, | |
29 | 52 | popConfirm: { |
30 | 53 | title: '是否确认删除', |
31 | 54 | confirm: handleDeleteOrBatchDelete.bind(null, record), |
... | ... | @@ -36,24 +59,39 @@ |
36 | 59 | </template> |
37 | 60 | </BasicTable> |
38 | 61 | </div> |
39 | - <PublicApiForm @register="registerDrawer" /> | |
62 | + <PublicApiForm @register="registerDrawer" @success="handleSuccess" /> | |
40 | 63 | </template> |
41 | 64 | <script lang="ts" setup name="list"> |
65 | + import { nextTick, h } from 'vue'; | |
42 | 66 | import { BasicTable, useTable, TableAction } from '/@/components/Table'; |
43 | 67 | import { useDrawer } from '/@/components/Drawer'; |
44 | - import { columns, list } from './config'; | |
68 | + import { columns, searchFormSchema } from './config'; | |
45 | 69 | import { PublicApiForm } from './index'; |
70 | + import { | |
71 | + getDataViewInterfacePage, | |
72 | + deleteBigViewInterface, | |
73 | + getPublish, | |
74 | + getCancelPublish, | |
75 | + } from '/@/api/bigscreen/center/bigscreenCenter'; | |
76 | + import { useBatchDelete } from '/@/hooks/web/useBatchDelete'; | |
77 | + import { Popconfirm, Modal } from 'ant-design-vue'; | |
78 | + import { JsonPreview } from '/@/components/CodeEditor'; | |
79 | + import { useMessage } from '/@/hooks/web/useMessage'; | |
46 | 80 | |
47 | - const [registerTable] = useTable({ | |
48 | - // api: exportPage, | |
49 | - dataSource: list, | |
81 | + const [registerTable, { reload, setProps }] = useTable({ | |
82 | + api: getDataViewInterfacePage, | |
50 | 83 | columns, |
51 | 84 | showIndexColumn: false, |
52 | 85 | clickToRowSelect: false, |
53 | 86 | showTableSetting: true, |
54 | 87 | bordered: true, |
88 | + formConfig: { | |
89 | + labelWidth: 120, | |
90 | + schemas: searchFormSchema, | |
91 | + }, | |
92 | + useSearchForm: true, | |
55 | 93 | actionColumn: { |
56 | - width: 200, | |
94 | + width: 150, | |
57 | 95 | title: '操作', |
58 | 96 | dataIndex: 'action', |
59 | 97 | slots: { customRender: 'action' }, |
... | ... | @@ -63,9 +101,19 @@ |
63 | 101 | |
64 | 102 | const [registerDrawer, { openDrawer }] = useDrawer(); |
65 | 103 | |
66 | - const handleDeleteOrBatchDelete = (record) => { | |
67 | - console.log(record); | |
68 | - }; | |
104 | + const { createMessage } = useMessage(); | |
105 | + | |
106 | + const handleSuccess = () => reload(); | |
107 | + | |
108 | + const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete( | |
109 | + deleteBigViewInterface, | |
110 | + handleSuccess, | |
111 | + setProps | |
112 | + ); | |
113 | + | |
114 | + nextTick(() => { | |
115 | + setProps(selectionOptions); | |
116 | + }); | |
69 | 117 | |
70 | 118 | const handleCreateOrEdit = (record) => { |
71 | 119 | const isUpdate = record === null ? false : true; |
... | ... | @@ -75,4 +123,24 @@ |
75 | 123 | record: recordContent, |
76 | 124 | }); |
77 | 125 | }; |
126 | + | |
127 | + const handleRecordContent = (record) => { | |
128 | + Modal.info({ | |
129 | + title: '接口内容', | |
130 | + width: 600, | |
131 | + content: h(JsonPreview, { data: JSON.parse(record.requestParams) }), | |
132 | + }); | |
133 | + }; | |
134 | + | |
135 | + const handlePublish = async (record) => { | |
136 | + await getPublish(record.id); | |
137 | + createMessage.success(`发布成功`); | |
138 | + handleSuccess(); | |
139 | + }; | |
140 | + | |
141 | + const handleCancelPublish = async (record) => { | |
142 | + await getCancelPublish(record.id); | |
143 | + createMessage.success(`取消发布成功`); | |
144 | + handleSuccess(); | |
145 | + }; | |
78 | 146 | </script> | ... | ... |