Commit 3d7ab5e9d5f05e822139ca707f839b56f6e07e15

Authored by ww
1 parent 2d795708

fix(preview): 修复预览模式下未轮训请求

1 import { ref, toRefs, toRaw, watch } from 'vue' 1 import { ref, toRefs, toRaw, watch } from 'vue'
2 import type VChart from 'vue-echarts' 2 import type VChart from 'vue-echarts'
3 -import { customizeHttp } from '@/api/http'  
4 import { useChartDataPondFetch } from '@/hooks/' 3 import { useChartDataPondFetch } from '@/hooks/'
5 import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d' 4 import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d'
6 import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore' 5 import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
7 -import { RequestDataTypeEnum } from '@/enums/httpEnum'  
8 -import { isPreview, newFunctionHandle, intervalUnitHandle } from '@/utils' 6 +import { isPreview, intervalUnitHandle } from '@/utils'
9 import { setOption } from '@/packages/public/chart' 7 import { setOption } from '@/packages/public/chart'
  8 +import { useChartDataSocket } from './useChartDataSocket'
  9 +import { customRequest } from '@/api/external/customRequest'
  10 +import { useFilterFn } from './useFilterFn'
10 11
11 // 获取类型 12 // 获取类型
12 type ChartEditStoreType = typeof useChartEditStore 13 type ChartEditStoreType = typeof useChartEditStore
@@ -52,18 +53,13 @@ export const useChartDataFetch = ( @@ -52,18 +53,13 @@ export const useChartDataFetch = (
52 53
53 // 目标组件 54 // 目标组件
54 const { 55 const {
55 - requestDataType,  
56 requestUrl, 56 requestUrl,
57 requestIntervalUnit: targetUnit, 57 requestIntervalUnit: targetUnit,
58 requestInterval: targetInterval 58 requestInterval: targetInterval
59 } = toRefs(targetComponent.request) 59 } = toRefs(targetComponent.request)
60 60
61 - // 非请求类型  
62 - if (requestDataType.value !== RequestDataTypeEnum.AJAX) return  
63 -  
64 try { 61 try {
65 - // 处理地址  
66 - // @ts-ignore 62 + // 处理地址
67 if (requestUrl?.value) { 63 if (requestUrl?.value) {
68 // requestOriginUrl 允许为空 64 // requestOriginUrl 允许为空
69 const completePath = requestOriginUrl && requestOriginUrl.value + requestUrl.value 65 const completePath = requestOriginUrl && requestOriginUrl.value + requestUrl.value
@@ -72,14 +68,15 @@ export const useChartDataFetch = ( @@ -72,14 +68,15 @@ export const useChartDataFetch = (
72 clearInterval(fetchInterval) 68 clearInterval(fetchInterval)
73 69
74 const fetchFn = async () => { 70 const fetchFn = async () => {
75 - const res = await customizeHttp(toRaw(targetComponent.request), toRaw(chartEditStore.getRequestGlobalConfig)) 71 + const res = await customRequest(toRaw(targetComponent.request))
76 if (res) { 72 if (res) {
77 try { 73 try {
78 const filter = targetComponent.filter 74 const filter = targetComponent.filter
79 - echartsUpdateHandle(newFunctionHandle(res?.data, res, filter)) 75 + const { value } = useFilterFn(filter, res)
  76 + echartsUpdateHandle(value)
80 // 更新回调函数 77 // 更新回调函数
81 if (updateCallback) { 78 if (updateCallback) {
82 - updateCallback(newFunctionHandle(res?.data, res, filter)) 79 + updateCallback(value)
83 } 80 }
84 } catch (error) { 81 } catch (error) {
85 console.error(error) 82 console.error(error)
@@ -113,10 +110,9 @@ export const useChartDataFetch = ( @@ -113,10 +110,9 @@ export const useChartDataFetch = (
113 } 110 }
114 111
115 if (isPreview()) { 112 if (isPreview()) {
116 - // 判断是否是数据池类型  
117 - targetComponent.request.requestDataType === RequestDataTypeEnum.Pond  
118 - ? addGlobalDataInterface(targetComponent, useChartEditStore, updateCallback || echartsUpdateHandle)  
119 - : requestIntervalFn() 113 + requestIntervalFn()
  114 + const { initial } = useChartDataSocket()
  115 + initial(targetComponent, useChartEditStore, updateCallback)
120 } 116 }
121 return { vChartRef } 117 return { vChartRef }
122 } 118 }
@@ -7,18 +7,21 @@ import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore @@ -7,18 +7,21 @@ import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore
7 import { RequestDataTypeEnum } from '@/enums/httpEnum' 7 import { RequestDataTypeEnum } from '@/enums/httpEnum'
8 import { isPreview, newFunctionHandle, intervalUnitHandle } from '@/utils' 8 import { isPreview, newFunctionHandle, intervalUnitHandle } from '@/utils'
9 import { setOption } from '@/packages/public/chart' 9 import { setOption } from '@/packages/public/chart'
10 -import { useChartDataSocket } from './external/useChartDataSocket' 10 +
  11 +// THINGS_KIT 重写默认方法
  12 +export { useChartDataFetch } from './external/useChartDataFetch.hook'
11 13
12 // 获取类型 14 // 获取类型
13 type ChartEditStoreType = typeof useChartEditStore 15 type ChartEditStoreType = typeof useChartEditStore
14 16
  17 +// THINGS_KIT 重命名默认方法
15 /** 18 /**
16 * setdata 数据监听与更改 19 * setdata 数据监听与更改
17 * @param targetComponent 20 * @param targetComponent
18 * @param useChartEditStore 若直接引会报错,只能动态传递 21 * @param useChartEditStore 若直接引会报错,只能动态传递
19 * @param updateCallback 自定义更新函数 22 * @param updateCallback 自定义更新函数
20 */ 23 */
21 -export const useChartDataFetch = ( 24 +export const originUseChartDataFetch = (
22 targetComponent: CreateComponentType, 25 targetComponent: CreateComponentType,
23 useChartEditStore: ChartEditStoreType, 26 useChartEditStore: ChartEditStoreType,
24 updateCallback?: (...args: any) => any 27 updateCallback?: (...args: any) => any
@@ -119,9 +122,5 @@ export const useChartDataFetch = ( @@ -119,9 +122,5 @@ export const useChartDataFetch = (
119 ? addGlobalDataInterface(targetComponent, useChartEditStore, updateCallback || echartsUpdateHandle) 122 ? addGlobalDataInterface(targetComponent, useChartEditStore, updateCallback || echartsUpdateHandle)
120 : requestIntervalFn() 123 : requestIntervalFn()
121 } 124 }
122 -  
123 - // THINGS_KIT 添加socket支持  
124 - const { initial } = useChartDataSocket()  
125 - initial(targetComponent, useChartEditStore, updateCallback)  
126 return { vChartRef } 125 return { vChartRef }
127 } 126 }
@@ -37,7 +37,6 @@ export function createPermissionGuard(router: Router) { @@ -37,7 +37,6 @@ export function createPermissionGuard(router: Router) {
37 } 37 }
38 38
39 const token = userStore.getJwtToken 39 const token = userStore.getJwtToken
40 - console.log(token)  
41 40
42 if (to.matched.find(item => whitePathList.includes(item.path))) { 41 if (to.matched.find(item => whitePathList.includes(item.path))) {
43 if (to.path === PageEnum.BASE_LOGIN && token) { 42 if (to.path === PageEnum.BASE_LOGIN && token) {
@@ -54,7 +54,7 @@ const handleFilter = (query: string, option: SelectOption) => { @@ -54,7 +54,7 @@ const handleFilter = (query: string, option: SelectOption) => {
54 54
55 const requestHttpTypeRef = ref<RequestHttpEnum>() 55 const requestHttpTypeRef = ref<RequestHttpEnum>()
56 56
57 -const requestIntervalValueRef = ref<number>(30) 57 +const requestIntervalValueRef = ref<undefined | number>(30)
58 58
59 const requestIntervalUnitRef = ref<RequestHttpIntervalEnum>(RequestHttpIntervalEnum.SECOND) 59 const requestIntervalUnitRef = ref<RequestHttpIntervalEnum>(RequestHttpIntervalEnum.SECOND)
60 60
@@ -112,12 +112,14 @@ const getConfigurationData = () => { @@ -112,12 +112,14 @@ const getConfigurationData = () => {
112 record.requestParams[RequestParamsTypeEnum.PARAMS] = getDynamicFormValue() 112 record.requestParams[RequestParamsTypeEnum.PARAMS] = getDynamicFormValue()
113 record.requestParams[RequestParamsTypeEnum.HEADER] = unref(headerRef) 113 record.requestParams[RequestParamsTypeEnum.HEADER] = unref(headerRef)
114 record.requestParams[RequestParamsTypeEnum.BODY] = bodyValue 114 record.requestParams[RequestParamsTypeEnum.BODY] = bodyValue
  115 + record.requestInterval = unref(requestIntervalValueRef)
  116 + record.requestIntervalUnit = unref(requestIntervalUnitRef)
115 return record 117 return record
116 } 118 }
117 119
118 const setConfigurationData = async (request: ExtraRequestConfigType) => { 120 const setConfigurationData = async (request: ExtraRequestConfigType) => {
119 await getPublicInterfaceList() 121 await getPublicInterfaceList()
120 - const { requestDataPondId, requestParams, requestParamsBodyType, requestContentType, requestHttpType } = request 122 + const { requestDataPondId, requestParams, requestParamsBodyType, requestContentType, requestHttpType, requestIntervalUnit, requestInterval } = request
121 const { Header } = requestParams 123 const { Header } = requestParams
122 selectedPublicInterface.value = requestDataPondId 124 selectedPublicInterface.value = requestDataPondId
123 requestContentTypeRef.value = requestContentType 125 requestContentTypeRef.value = requestContentType
@@ -125,6 +127,8 @@ const setConfigurationData = async (request: ExtraRequestConfigType) => { @@ -125,6 +127,8 @@ const setConfigurationData = async (request: ExtraRequestConfigType) => {
125 headerRef.value = Header 127 headerRef.value = Header
126 requestParamsBodyTypeRef.value = requestParamsBodyType 128 requestParamsBodyTypeRef.value = requestParamsBodyType
127 requestBodyRef.value = requestParams 129 requestBodyRef.value = requestParams
  130 + requestIntervalUnitRef.value = requestIntervalUnit
  131 + requestIntervalValueRef.value = requestInterval
128 await nextTick() 132 await nextTick()
129 setDynamicFormValue(request) 133 setDynamicFormValue(request)
130 } 134 }