Commit 3c8f52ecd7fe4f404f8f82ecb783093098b139dc

Authored by xp.Huang
2 parents 8d73b7f6 33fd7a67

Merge branch 'perf/third-interface-05-7' into 'main_dev'

perf(src/views): 优化第三方接口

See merge request yunteng/thingskit-view!269
... ... @@ -147,6 +147,7 @@ export const customRequest = async (request: RequestConfigType) => {
147 147 pondRequestOriginUrl,
148 148 pondRequestGlobalTokenKey,
149 149 pondRequestGlobalTokenSuffix,
  150 + pondRequestGlobalIsToken
150 151 } = request as ExtraRequestConfigType
151 152 const chartEditStore = useChartEditStore()
152 153
... ... @@ -175,7 +176,7 @@ export const customRequest = async (request: RequestConfigType) => {
175 176 {
176 177 url:
177 178 requestHttpType === RequestHttpEnum.GET.toUpperCase() ? requestUrl : `${requestUrl}?${objConvertQuery(Params)}`,
178   - baseURL: requestVerificationToken ? pondRequestOriginUrl : globalRequestOriginUrl ? globalRequestOriginUrl : getOriginUrl(requestOriginUrl!),
  179 + baseURL: pondRequestGlobalIsToken ? requestVerificationToken ? pondRequestOriginUrl : globalRequestOriginUrl ? globalRequestOriginUrl : getOriginUrl(requestOriginUrl!): pondRequestOriginUrl,
179 180 method: requestHttpType,
180 181 params: requestHttpType === RequestHttpEnum.GET.toUpperCase() ? Params : null,
181 182 data: body,
... ...
... ... @@ -59,6 +59,13 @@ onMounted(() => {
59 59 watch(
60 60 () => props.modelValue,
61 61 (val: string) => {
  62 + if(props.language === 'json') {
  63 + try {
  64 + JSON.parse(val)
  65 + } catch (_) {
  66 + window.$message.error('JSON格式有误,请仔细检查!')
  67 + }
  68 + }
62 69 val !== getEditor()?.getValue() && updateMonacoVal(val)
63 70 }
64 71 )
... ...
... ... @@ -63,7 +63,8 @@ export const requestConfig: RequestConfigType = {
63 63 },
64 64 "Header": {},
65 65 "Params": {}
66   - }
  66 + },
  67 + pondRequestGlobalIsToken: true
67 68 }
68 69
69 70 // 单实例类
... ...
... ... @@ -223,7 +223,7 @@ export interface RequestConfigType extends RequestPublicConfigType {
223 223 sql: string
224 224 }
225 225
226   - // Token
  226 + // 三方Token相关
227 227 requestVerificationToken?: string
228 228 // 请求头里的Token键
229 229 requestTokenKey?: string
... ... @@ -250,6 +250,8 @@ export interface RequestConfigType extends RequestPublicConfigType {
250 250 thirdSelectCascaderLabel?: string
251 251 publicInterfaceSelectId?: string
252 252 thirdRequestDataPondId?: string
  253 + pondRequestGlobalIsToken?: boolean
  254 + //
253 255 }
254 256
255 257 // Store 类型
... ...
... ... @@ -59,15 +59,23 @@
59 59 <div class="editor-data-show">
60 60 <NSpace>
61 61 <NText depth="3">接口返回数据(res):</NText>
62   - <NScrollbar style="max-height: 300px;">
63   - <NCode :code="toString(isSocketRequest ? targetData.wsOriginalMessage : sourceData) || '暂无'" language="json" :word-wrap="true"></NCode>
64   - </NScrollbar>
  62 + <n-collapse :default-expanded-names="['1']">
  63 + <n-collapse-item title="res" name="1">
  64 + <NScrollbar style="max-height: 300px;">
  65 + <NCode :code="toString(isSocketRequest ? targetData.wsOriginalMessage : sourceData) || '暂无'" language="json" :word-wrap="true"></NCode>
  66 + </NScrollbar>
  67 + </n-collapse-item>
  68 + </n-collapse>
65 69 </NSpace>
66 70 </div>
67 71 <div class="editor-data-show">
68 72 <NSpace>
69 73 <NText depth="3">过滤器结果:</NText>
70   - <NCode :code="filterRes || '暂无'" language="json" :word-wrap="true"></NCode>
  74 + <n-collapse>
  75 + <n-collapse-item title="结果" name="2">
  76 + <NCode :code="filterRes || '暂无'" language="json" :word-wrap="true"></NCode>
  77 + </n-collapse-item>
  78 + </n-collapse>
71 79 </NSpace>
72 80 </div>
73 81 </NSpace>
... ...
... ... @@ -52,7 +52,7 @@ import { ChartDataDisplay } from '../ChartDataDisplay'
52 52 import { requestConfig } from '@/packages/public/publicConfig'
53 53 import { useTargetData } from '@/views/chart/ContentConfigurations/components/hooks/useTargetData.hook'
54 54 import { RequestDataPondItemType } from '@/store/modules/chartEditStore/chartEditStore.d'
55   -import { RequestBodyEnum, RequestContentTypeEnum, RequestDataTypeEnum, RequestHttpEnum } from '@/enums/httpEnum'
  55 +import { RequestDataTypeEnum } from '@/enums/httpEnum'
56 56 import { icon } from '@/plugins'
57 57 import { getUUID, goDialog } from '@/utils'
58 58 import { cloneDeep } from 'lodash'
... ... @@ -108,57 +108,10 @@ watch(
108 108 const openPond = (isEditFlag = false) => {
109 109 isEdit.value = !!isEditFlag
110 110 requestShow.value = true
111   - editData.value = cacheEditData.value || {
112   - dataPondId: getUUID(),
113   - dataPondName: getUUID(),
114   - dataPondRequestConfig: {
115   - requestDataPondId: '',
116   - requestInterval: 0,
117   - requestDataType: RequestDataTypeEnum.AJAX,
118   - requestHttpType: RequestHttpEnum.GET,
119   - requestUrl: '',
120   - requestContentType: RequestContentTypeEnum.DEFAULT,
121   - requestParamsBodyType: RequestBodyEnum.NONE,
122   - requestSQLContent: {
123   - sql: ''
124   - },
125   - requestVerificationToken: '',
126   - requestTokenKey: '',
127   - requestTokenSuffix: '',
128   - requestParams: {
129   - "Body": {
130   - "form-data": {},
131   - "x-www-form-urlencoded": {},
132   - "json": "",
133   - "xml": ""
134   - },
135   - "Header": {},
136   - "Params": {}
137   - },
138   - pondRequestOriginUrl: '',
139   - pondRequestInterval: 0,
140   - pondRequestIntervalUnit: '',
141   - pondRequestGlobalTokenSuffix: '',
142   - pondRequestGlobalTokenKey: '',
143   - pondRequestHttpType:'',
144   - pondRequestUrl:'',
145   - pondRequestContentType:RequestContentTypeEnum.DEFAULT,
146   - pondRequestSQLContent: {
147   - sql: ''
148   - },
149   - pondRequestParamsBodyType: RequestBodyEnum.NONE,
150   - pondRequestParams: {
151   - "Body": {
152   - "form-data": {},
153   - "x-www-form-urlencoded": {},
154   - "json": "",
155   - "xml": ""
156   - },
157   - "Header": {},
158   - "Params": {}
159   - }
160   - }
161   - } as unknown as RequestDataPondItemType
  111 + if (isEditFlag) {
  112 + editData.value = cacheEditData.value
  113 + targetData.value.request.pondRequestGlobalIsToken = editData.value?.dataPondRequestConfig.pondRequestGlobalIsToken
  114 + }
162 115 }
163 116
164 117 // 创建
... ... @@ -167,9 +120,9 @@ const createPond = () => {
167 120 editData.value = {
168 121 dataPondId: id,
169 122 dataPondName: id,
170   - dataPondRequestConfig: cloneDeep({ ...requestConfig, requestDataType: RequestDataTypeEnum.Pond })
  123 + dataPondRequestConfig: cloneDeep({ ...requestConfig, requestDataType: RequestDataTypeEnum.AJAX })
171 124 }
172   - cacheEditData.value = editData.value
  125 + targetData.value.request.pondRequestGlobalIsToken = true
173 126 openPond()
174 127 }
175 128
... ... @@ -248,10 +201,10 @@ const deletePond = (targetData: RequestDataPondItemType) => {
248 201 const closeHandle = () => {
249 202 // 将所选内容赋值给对象
250 203 if (pondData.value) {
251   - targetData.value.request = {
252   - ...toRaw(pondData.value.dataPondRequestConfig),
253   - requestDataPondId: pondData.value.dataPondId
254   - }
  204 + // targetData.value.request = {
  205 + // ...toRaw(pondData.value.dataPondRequestConfig),
  206 + // requestDataPondId: pondData.value.dataPondId
  207 + // }
255 208 }
256 209 emit('update:modelShow', false)
257 210 }
... ...
... ... @@ -100,6 +100,7 @@ const deletePond = (target: Event, targetData: RequestDataPondItemType) => {
100 100 // 选中
101 101 const clickHandle = (item: RequestDataPondItemType) => {
102 102 targetData.value.request.requestDataPondId = item.dataPondId
  103 + targetData.value.request.pondRequestGlobalIsToken = item.dataPondRequestConfig.pondRequestGlobalIsToken
103 104 }
104 105 </script>
105 106
... ...
1 1 <script setup lang="ts">
2   -import { ref, computed, onBeforeUnmount, watchEffect, unref } from 'vue'
  2 +import { ref, computed, onBeforeUnmount, watchEffect, unref, watch } from 'vue'
3 3 import { icon } from '@/plugins'
4 4 import { useDesignStore } from '@/store/modules/designStore/designStore'
5 5 import { SettingItemBox } from '@/components/Pages/ChartItemSetting'
... ... @@ -99,6 +99,10 @@ const controlModel = ref(false)
99 99
100 100 const handleOpenChartDataPondModal = () => controlModel.value = true
101 101
  102 +watch(()=>targetData.value, (newValue) => {
  103 + selectedRequestType.value = newValue?.request?.requestDataType as unknown as any
  104 +})
  105 +
102 106 </script>
103 107
104 108 <template>
... ...
... ... @@ -18,14 +18,14 @@ import {
18 18 CascaderOption,
19 19 NCascader,
20 20 } from 'naive-ui'
21   -import { computed, onMounted, reactive, ref, unref, watch } from 'vue'
  21 +import { computed, onMounted, reactive, ref, unref } from 'vue'
22 22 import GlobalParamsConfiguration from './GlobalParamsConfiguration.vue'
23 23 import { ChevronDown, ChevronUp } from '@vicons/carbon'
24 24 import { useDesignStore } from '@/store/modules/designStore/designStore'
25 25 import { selectTimeOptions } from '../../../index.d'
26 26 import { useTargetData } from '../../../../hooks/useTargetData.hook'
27 27 import { RequestDataTypeEnum, RequestHttpIntervalEnum } from '@/enums/httpEnum'
28   -import { RequestDataPondItemType } from '@/store/modules/chartEditStore/chartEditStore.d'
  28 +import { RequestConfigType, RequestDataPondItemType } from '@/store/modules/chartEditStore/chartEditStore.d'
29 29 import { convertToCascadingData } from '@/utils/external/utils'
30 30 import { customThirdInterfaceRequest, thirdInterfaceRequest } from '@/api/external/customRequest'
31 31
... ... @@ -52,6 +52,8 @@ const themeColor = computed(() => {
52 52
53 53 const selectGlobalPondValue = ref('')
54 54
  55 +const selectGlobalPondIsToken = ref(true)
  56 +
55 57 const cacheSelectOption = ref<Recordable>({
56 58 dataPondRequestConfig:{
57 59 pondRequestOriginUrl:'',
... ... @@ -104,6 +106,7 @@ const findCurrentPond = () => {
104 106 }
105 107
106 108 const handleSelectGlobalPond = (_:string, options:RequestDataPondItemType & {label: string, value: string}) => {
  109 + selectGlobalPondIsToken.value = options.dataPondRequestConfig.pondRequestGlobalIsToken!
107 110 cacheSelectOption.value = options
108 111 targetData.value.request = options.dataPondRequestConfig
109 112 targetData.value.request.requestDataPondId = options.dataPondId
... ... @@ -136,8 +139,12 @@ const handleExecuteRequest = async () => {
136 139 onMounted(()=>{
137 140 getTokenString.value = targetData.value?.request?.requestVerificationToken
138 141 selectGlobalPondValue.value = findCurrentPond()?.dataPondId as string
  142 + selectGlobalPondIsToken.value = findCurrentPond()?.dataPondRequestConfig.pondRequestGlobalIsToken as boolean
139 143 cacheSelectOption.value = findCurrentPond() as RequestDataPondItemType
140 144 resValue.value = targetData.value?.request?.thirdSelectCascaderLabel
  145 + targetData.value.request.pondRequestOriginUrl = findCurrentPond()?.dataPondRequestConfig?.pondRequestOriginUrl
  146 + targetData.value.request.pondRequestGlobalTokenKey = findCurrentPond()?.dataPondRequestConfig?.pondRequestGlobalTokenKey
  147 + targetData.value.request.pondRequestGlobalTokenSuffix = findCurrentPond()?.dataPondRequestConfig?.pondRequestGlobalTokenSuffix
141 148 handleExecuteRequest()
142 149 })
143 150 </script>
... ... @@ -245,7 +252,7 @@ onMounted(()=>{
245 252 </SettingItem>
246 253 </SettingItemBox>
247 254 <NDivider />
248   - <div style="margin:0 70px" v-if="selectGlobalPondValue">
  255 + <div style="margin:0 70px" v-if="selectGlobalPondValue && selectGlobalPondIsToken">
249 256 <n-space vertical>
250 257 <n-button type="primary" @click="handleExecuteRequest">执行请求</n-button>
251 258 <NCascader
... ...
... ... @@ -13,7 +13,6 @@
13 13 <div class="go-pr-3">
14 14 <n-space vertical>
15 15 <PondPublicConfiguration ref="pondPublicConfigurationRef" />
16   - <NDivider />
17 16 <PondRequestConfiguration ref="pondRequestConfigurationRef" />
18 17 </n-space>
19 18 </div>
... ... @@ -48,11 +47,10 @@
48 47
49 48 <script script lang="ts" setup>
50 49 import { PropType, ref, watch, onMounted, nextTick } from 'vue'
51   -import { RequestDataPondItemType } from '@/store/modules/chartEditStore/chartEditStore.d'
  50 +import { RequestConfigType, RequestDataPondItemType } from '@/store/modules/chartEditStore/chartEditStore.d'
52 51 import { goDialog } from '@/utils'
53 52 import PondPublicConfiguration from './PondPublicConfiguration.vue'
54 53 import PondRequestConfiguration from './PondRequestConfiguration.vue'
55   -import { merge } from 'lodash'
56 54 import { useTargetData } from '../../../../hooks/useTargetData.hook'
57 55
58 56 const props = defineProps({
... ... @@ -78,7 +76,7 @@ watch(
78 76 modelShowRef.value = newValue
79 77 if(newValue) {
80 78 nextTick(() => {
81   - pondPublicConfigurationRef?.value?.setConfigurationData(props.targetDataRequest?.dataPondRequestConfig as unknown as RequestDataPondItemType)
  79 + pondPublicConfigurationRef?.value?.setConfigurationData(props.targetDataRequest?.dataPondRequestConfig as unknown as RequestConfigType)
82 80 pondRequestConfigurationRef?.value?.setConfigurationData(props.targetDataRequest?.dataPondRequestConfig as unknown as RequestDataPondItemType)
83 81 })
84 82 }
... ... @@ -97,14 +95,15 @@ const closeAndSendHandle = () => {
97 95 }
98 96 const pondPublicData = pondPublicConfigurationRef?.value?.getConfigurationData()
99 97 const pondRequestData = pondRequestConfigurationRef?.value?.getConfigurationData()
100   - merge(props.targetDataRequest.dataPondRequestConfig, pondRequestData, pondPublicData)
  98 + const mergeTargetDataRequestData = Object.assign(props.targetDataRequest.dataPondRequestConfig, pondPublicData, pondRequestData)
  99 + props.targetDataRequest.dataPondRequestConfig = mergeTargetDataRequestData
101 100 goDialog({
102 101 message: '保存内容将同步修改所有使用此接口的组件, 是否继续?',
103 102 isMaskClosable: true,
104 103 transformOrigin: 'center',
105 104 onPositiveCallback: () => {
106 105 emit('update:modelShow', false)
107   - emit('editSaveHandle', props.targetDataRequest)
  106 + emit('editSaveHandle', props.targetDataRequest)
108 107 }
109 108 })
110 109 }
... ...
... ... @@ -21,11 +21,15 @@ import { ChevronDown, ChevronUp } from '@vicons/carbon'
21 21 import { useDesignStore } from '@/store/modules/designStore/designStore'
22 22 import { selectTimeOptions } from '../../../index.d'
23 23 import { RequestHttpIntervalEnum } from '@/enums/httpEnum'
  24 +import { RequestConfigType } from '@/store/modules/chartEditStore/chartEditStore.d'
  25 +import { useTargetData } from '../../../../hooks/useTargetData.hook'
24 26
25 27 const { PencilIcon } = icon.ionicons5
26 28
27 29 const designStore = useDesignStore()
28 30
  31 +const { targetData } = useTargetData()
  32 +
29 33 const editDisabled = ref(false)
30 34
31 35 const collapseHeaderTable = ref(false)
... ... @@ -40,6 +44,8 @@ const pondRequestGlobalTokenSuffixRef = ref('')
40 44
41 45 const pondRequestGlobalTokenKeyRef = ref('')
42 46
  47 +const pondRequestGlobalIsTokenRef = ref(true)
  48 +
43 49 const handleCollapse = () => {
44 50 collapseHeaderTable.value = !unref(collapseHeaderTable)
45 51 }
... ... @@ -49,23 +55,29 @@ const themeColor = computed(() => {
49 55 return designStore.getAppTheme
50 56 })
51 57
52   -const getConfigurationData = (): Recordable => {
  58 +const handleIsTokenSwitch = (value: boolean) => {
  59 + targetData.value.request.pondRequestGlobalIsToken = value
  60 +}
  61 +
  62 +const getConfigurationData = (): Partial<RequestConfigType> => {
53 63 return {
54 64 pondRequestOriginUrl: unref(pondRequestOriginUrlRef),
55 65 pondRequestInterval: unref(pondRequestIntervalRef),
56 66 pondRequestIntervalUnit: unref(pondRequestIntervalUnitRef),
57 67 pondRequestGlobalTokenSuffix: unref(pondRequestGlobalTokenSuffixRef),
58 68 pondRequestGlobalTokenKey: unref(pondRequestGlobalTokenKeyRef),
  69 + pondRequestGlobalIsToken: unref(pondRequestGlobalIsTokenRef),
59 70 }
60 71 }
61 72
62   -const setConfigurationData = (request: Recordable) => {
63   - const { pondRequestOriginUrl, pondRequestInterval, pondRequestIntervalUnit, pondRequestGlobalTokenSuffix, pondRequestGlobalTokenKey } = request
64   - pondRequestOriginUrlRef.value = pondRequestOriginUrl
  73 +const setConfigurationData = (request: Partial<RequestConfigType>) => {
  74 + const { pondRequestOriginUrl, pondRequestInterval, pondRequestIntervalUnit, pondRequestGlobalTokenSuffix, pondRequestGlobalTokenKey, pondRequestGlobalIsToken } = request
  75 + pondRequestOriginUrlRef.value = pondRequestOriginUrl!
65 76 pondRequestIntervalRef.value = pondRequestInterval
66   - pondRequestIntervalUnitRef.value = pondRequestIntervalUnit
67   - pondRequestGlobalTokenSuffixRef.value = pondRequestGlobalTokenSuffix
68   - pondRequestGlobalTokenKeyRef.value = pondRequestGlobalTokenKey
  77 + pondRequestIntervalUnitRef.value = pondRequestIntervalUnit!
  78 + pondRequestGlobalTokenSuffixRef.value = pondRequestGlobalTokenSuffix!
  79 + pondRequestGlobalTokenKeyRef.value = pondRequestGlobalTokenKey!
  80 + pondRequestGlobalIsTokenRef.value = pondRequestGlobalIsToken!
69 81 }
70 82
71 83 defineExpose({
... ... @@ -129,7 +141,12 @@ defineExpose({
129 141 </NButton>
130 142 </SettingItemBox>
131 143 <!-- 针对第三方接口 -->
132   - <SettingItemBox name="配置">
  144 + <SettingItemBox name="Token配置">
  145 + <SettingItem>
  146 + <n-switch @update:value="handleIsTokenSwitch" v-model:value="pondRequestGlobalIsTokenRef"/>
  147 + </SettingItem>
  148 + </SettingItemBox>
  149 + <SettingItemBox v-if="pondRequestGlobalIsTokenRef" name="配置">
133 150 <SettingItem name="请求标头">
134 151 <n-input v-model:value.trim="pondRequestGlobalTokenKeyRef" type="text" placeholder="默认值: X-Authorization " />
135 152 </SettingItem>
... ...
... ... @@ -12,6 +12,9 @@ import {
12 12 import { ref, unref } from 'vue'
13 13 import DefaultRequestContent from './DefaultRequestContent.vue'
14 14 import SqlConfiguration from './SqlConfiguration.vue'
  15 +import { useTargetData } from '../../../../hooks/useTargetData.hook'
  16 +
  17 +const { targetData } = useTargetData()
15 18
16 19 const pondRequestContentTypeRef = ref(RequestContentTypeEnum.DEFAULT)
17 20
... ... @@ -74,6 +77,8 @@ defineExpose({
74 77 </script>
75 78
76 79 <template>
  80 + <div v-if="targetData.request.pondRequestGlobalIsToken">
  81 + <NDivider />
77 82 <SettingItemBox
78 83 name="地址"
79 84 :itemRightStyle="{
... ... @@ -135,4 +140,5 @@ defineExpose({
135 140 v-if="pondRequestContentTypeRef === RequestContentTypeEnum.SQL"
136 141 />
137 142 </SettingItemBox>
  143 +</div>
138 144 </template>
... ...
... ... @@ -35,7 +35,6 @@ const openModal = async (flag = true, type: RequestDataTypeEnum) => {
35 35 requestDataType.value = type
36 36 showModal.value = flag
37 37 await nextTick()
38   - console.log(unref(selectTarget)!.request)
39 38 unref(componentConfigurationEl as any)?.setConfigurationData(unref(selectTarget)!.request || {})
40 39 unref(publicInterfaceFormEl as any)?.setConfigurationData(unref(selectTarget)!.request || {})
41 40 }
... ... @@ -98,6 +97,7 @@ const handleSaveAction = async () => {
98 97 value.thirdSelectCascaderLabel = targetData.value.request.thirdSelectCascaderLabel
99 98 value.requestDataType = targetData.value.request.requestDataType
100 99 value.publicInterfaceSelectId = targetData.value.request.publicInterfaceSelectId
  100 + value.pondRequestGlobalIsToken = targetData.value.request.pondRequestGlobalIsToken
101 101 if (unref(selectTarget)) {
102 102 chartEditStore.updateComponentList(chartEditStore.fetchTargetIndex(), {
103 103 ...unref(selectTarget)!,
... ...