Commit 573a74843cb8830c7027d4d13f1470b037782a98
Merge branch 'perf/public-interfac-option' into 'main_dev'
perf: 优化公共接口下拉选项 See merge request yunteng/thingskit-view!93
Showing
3 changed files
with
59 additions
and
36 deletions
src/enums/external/interfaceEnum.ts
0 → 100644
1 | 1 | <script lang="ts" setup> |
2 | 2 | import { getAllPublicInterface } from '@/api/external/dynamicRequest' |
3 | -import { ParamsItemType, PublicInterfaceRecord, PublicInterfaceRequestParams, PublicInterfaceStateEnum } from '@/api/external/dynamicRequest/model'; | |
3 | +import { ParamsItemType, PublicInterfaceRecord, PublicInterfaceRequestParams } from '@/api/external/dynamicRequest/model'; | |
4 | 4 | import { SettingItem, SettingItemBox } from '@/components/Pages/ChartItemSetting'; |
5 | 5 | import { RequestContentTypeEnum, RequestContentTypeNameEnum, RequestEnum } from '@/enums/external/httpEnum'; |
6 | 6 | import { RequestBodyEnum, RequestHttpEnum, RequestHttpIntervalEnum, RequestParams, RequestParamsTypeEnum } from '@/enums/httpEnum'; |
7 | -import { NCard, NEllipsis, NEmpty, NInputGroup, NInputNumber, NScrollbar, NSelect, NSpace, NTabPane, NTabs, SelectOption } from 'naive-ui'; | |
7 | +import { NCard, NEmpty, NInputGroup, NInputNumber, NScrollbar, NSelect, NTabPane, NTabs, SelectOption } from 'naive-ui'; | |
8 | 8 | import { ref, computed, unref, nextTick, h } from 'vue' |
9 | 9 | import { selectTimeOptions, selectTypeOptions } from '../../../index.d'; |
10 | 10 | import ParamsTable from '../RequestModal/ParamsTable.vue'; |
... | ... | @@ -14,6 +14,7 @@ import { DynamicForm } from '../DynamicForm'; |
14 | 14 | import { extraPublicInterfaceInfo } from '../DynamicForm/utils'; |
15 | 15 | import { isArray } from '@/utils'; |
16 | 16 | import { useTargetData } from '../../../../hooks/useTargetData.hook'; |
17 | +import { InterfaceTypeEnum, InterfaceTypeNameEnum } from '@/enums/external/interfaceEnum'; | |
17 | 18 | |
18 | 19 | const publicInterfaceList = ref<PublicInterfaceRecord[]>([]) |
19 | 20 | |
... | ... | @@ -44,15 +45,20 @@ const getSelectedInterfaceParams = computed(() => { |
44 | 45 | |
45 | 46 | const getPublicInterfaceList = async () => { |
46 | 47 | if (unref(publicInterfaceList).length) return |
47 | - /** | |
48 | - * ft 更换接口 | |
49 | - * 修改后的代码在注释之间,并标注好源代码和修改后代码,方便回溯 | |
50 | - * 源代码 const result = await getAllPublicInterface({ state: PublicInterfaceStateEnum.PUBLISH }) | |
51 | - * 修改后代码 const result = await getAllPublicInterface() | |
52 | - */ | |
48 | + /** | |
49 | + * ft 更换接口 | |
50 | + * 修改后的代码在注释之间,并标注好源代码和修改后代码,方便回溯 | |
51 | + * 源代码 const result = await getAllPublicInterface({ state: PublicInterfaceStateEnum.PUBLISH }) | |
52 | + * 修改后代码 const result = await getAllPublicInterface() | |
53 | + */ | |
53 | 54 | const result = await getAllPublicInterface() |
54 | 55 | //ft |
55 | - publicInterfaceList.value = result | |
56 | + publicInterfaceList.value = result.map(item => { | |
57 | + return { | |
58 | + ...item, | |
59 | + class: 'interface-option' | |
60 | + } | |
61 | + }) | |
56 | 62 | } |
57 | 63 | |
58 | 64 | const handleFilter = (query: string, option: SelectOption) => { |
... | ... | @@ -116,14 +122,14 @@ const setDynamicFormValue = (request: ExtraRequestConfigType) => { |
116 | 122 | /** |
117 | 123 | * ft 优化动态表单包含有entityType,则自动回填DEVICE |
118 | 124 | */ |
119 | - if(typeof request.requestParams ==='string' && request.requestParams) { | |
120 | - const DEVICE='DEVICE' | |
121 | - const {Params:includeEntityTypeByParams}=JSON.parse(request.requestParams as unknown as string) | |
122 | - const findEntityType = includeEntityTypeByParams.find((item:Record<string,string>)=>item.key==='scope' && item.value==='entityType') | |
123 | - if(!findEntityType) return | |
124 | - if (unref(paramsDynamicFormEl)) unref(paramsDynamicFormEl)?.setConfigurationData({ | |
125 | - [findEntityType?.value]:DEVICE | |
126 | - }) | |
125 | + if (typeof request.requestParams === 'string' && request.requestParams) { | |
126 | + const DEVICE = 'DEVICE' | |
127 | + const { Params: includeEntityTypeByParams } = JSON.parse(request.requestParams as unknown as string) | |
128 | + const findEntityType = includeEntityTypeByParams.find((item: Record<string, string>) => item.key === 'scope' && item.value === 'entityType') | |
129 | + if (!findEntityType) return | |
130 | + if (unref(paramsDynamicFormEl)) unref(paramsDynamicFormEl)?.setConfigurationData({ | |
131 | + [findEntityType?.value]: DEVICE | |
132 | + }) | |
127 | 133 | } |
128 | 134 | //ft |
129 | 135 | } |
... | ... | @@ -156,7 +162,7 @@ const setConfigurationData = async (request: ExtraRequestConfigType) => { |
156 | 162 | * 源代码 selectedPublicInterface.value = requestDataPondId |
157 | 163 | * 修改后代码 selectedPublicInterface.value = publicInterfaceList.value.find(it=>it.id === requestDataPondId)?.id||'' |
158 | 164 | */ |
159 | - selectedPublicInterface.value = publicInterfaceList.value.find(it=>it.id === requestDataPondId)?.id||'' | |
165 | + selectedPublicInterface.value = publicInterfaceList.value.find(it => it.id === requestDataPondId)?.id || '' | |
160 | 166 | //ft |
161 | 167 | requestContentTypeRef.value = requestContentType |
162 | 168 | requestHttpTypeRef.value = requestHttpType |
... | ... | @@ -169,26 +175,27 @@ const setConfigurationData = async (request: ExtraRequestConfigType) => { |
169 | 175 | setDynamicFormValue(request) |
170 | 176 | } |
171 | 177 | |
172 | - /** | |
173 | - * ft 修改在公共接口下拉框里加上接口类型 | |
174 | - * 修改后的代码在注释之间,并标注好源代码和修改后代码,方便回溯 | |
175 | - * 源代码 属于新增代码,源代码无 | |
176 | - * 修改后代码在//ft之间 | |
177 | - */ | |
178 | +/** | |
179 | + * ft 修改在公共接口下拉框里加上接口类型 | |
180 | + * 修改后的代码在注释之间,并标注好源代码和修改后代码,方便回溯 | |
181 | + * 源代码 属于新增代码,源代码无 | |
182 | + * 修改后代码在//ft之间 | |
183 | + */ | |
178 | 184 | |
179 | -const getHttpType = (httpType:RequestEnum, contentType:number) => { | |
180 | - if(contentType===0){ | |
181 | - if (httpType === RequestEnum[httpType]) return RequestEnum[httpType] | |
185 | +const getHttpType = (httpType: RequestEnum, contentType: number) => { | |
186 | + if (contentType === 0) { | |
187 | + if (httpType === RequestEnum[httpType]) return RequestEnum[httpType] | |
182 | 188 | } |
183 | - else if (contentType===2) return 'WebSocket' | |
189 | + else if (contentType === 2) return 'WebSocket' | |
184 | 190 | } |
185 | 191 | |
186 | 192 | const renderOption = (option: SelectOption) => { |
187 | - const httpType = getHttpType(option?.requestHttpType as RequestEnum, option?.requestContentType as number) | |
188 | - const interfaceTypeName = option?.interfaceType === 'SYSTEM' ? '系统默认' :option?.interfaceType === 'CUSTOM'? '自定义':'' | |
189 | - return h(NSpace, { justify: 'space-between', wrap: false, style: 'padding: 0 15px; height: 28px; line-height: 28px; width:100%' }, () => [ | |
190 | - h(NEllipsis, null, () => `${!httpType?'':httpType+'/'}${interfaceTypeName}`), | |
191 | - h(NEllipsis, null, () => option.interfaceName), | |
193 | + const interfaceType = option?.interfaceType as InterfaceTypeEnum | |
194 | + const interfaceTypeName = interfaceType ? InterfaceTypeNameEnum[interfaceType] : '' | |
195 | + const interfaceName = option.interfaceName as string | |
196 | + return h('div', { style: 'display: flex; justify-content: space-between;' }, [ | |
197 | + h('div', { style: 'flex: 0 0 100px' }, interfaceTypeName), | |
198 | + h('div', { style: 'flex: 1 1 auto; text-align: right; text-overflow: ellipsis; overflow: hidden;' }, interfaceName) | |
192 | 199 | ]) |
193 | 200 | } |
194 | 201 | //ft |
... | ... | @@ -206,7 +213,7 @@ defineExpose({ |
206 | 213 | <SettingItemBox name="公共接口" :alone="true" :item-right-style="{ gridTemplateColumns: '5fr 2fr 1fr' }"> |
207 | 214 | <SettingItem name="请求方式 & URL地址"> |
208 | 215 | <NInputGroup> |
209 | - <!-- | |
216 | + <!-- | |
210 | 217 | /** |
211 | 218 | * ft 修改在公共接口下拉框里加上接口类型 |
212 | 219 | * 修改后的代码在注释之间,并标注好源代码和修改后代码,方便回溯 |
... | ... | @@ -269,7 +276,7 @@ defineExpose({ |
269 | 276 | :disabled="true" /> |
270 | 277 | |
271 | 278 | </SettingItemBox> |
272 | - <!-- | |
279 | + <!-- | |
273 | 280 | /** |
274 | 281 | * ft 修改 |
275 | 282 | * 修改后的代码在注释之间,并标注好源代码和修改后代码,方便回溯 |
... | ... | @@ -278,7 +285,8 @@ defineExpose({ |
278 | 285 | * 优化普通和websocket表格长度不一样样式问题 |
279 | 286 | */ |
280 | 287 | --> |
281 | - <SettingItemBox v-if="requestContentTypeRef === RequestContentTypeEnum.WEB_SOCKET" :item-right-style="{ gridTemplateColumns: '7fr 1fr' }"> | |
288 | + <SettingItemBox v-if="requestContentTypeRef === RequestContentTypeEnum.WEB_SOCKET" | |
289 | + :item-right-style="{ gridTemplateColumns: '7fr 1fr' }"> | |
282 | 290 | <NCard v-if="requestParamsTypeRef === RequestParamsTypeEnum.PARAMS" class="dynamic-form"> |
283 | 291 | <NScrollbar style="max-height: 400px; box-sizing: border-box;"> |
284 | 292 | <DynamicForm ref="socketDynamicFormEl" :paramsItemList="getSelectedInterfaceParams" /> |
... | ... | @@ -304,3 +312,9 @@ defineExpose({ |
304 | 312 | } |
305 | 313 | } |
306 | 314 | </style> |
315 | + | |
316 | +<style lang="scss"> | |
317 | +.interface-option> div { | |
318 | + width: 100%; | |
319 | +} | |
320 | +</style> | ... | ... |