mirror of
https://gitee.com/dromara/go-view.git
synced 2025-04-06 03:58:04 +08:00
feat: 新增全局请求定时功能
This commit is contained in:
parent
e4aac1597f
commit
99cd66c835
@ -116,7 +116,6 @@ export const customizeHttp = (targetParams: RequestConfigType, globalParams: Req
|
|||||||
if (!targetParams || !globalParams) {
|
if (!targetParams || !globalParams) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全局
|
// 全局
|
||||||
const {
|
const {
|
||||||
// 全局请求源地址
|
// 全局请求源地址
|
||||||
|
@ -26,11 +26,10 @@ export const useChartDataFetch = (
|
|||||||
|
|
||||||
// 数据池
|
// 数据池
|
||||||
const { addGlobalDataInterface } = useChartDataPondFetch()
|
const { addGlobalDataInterface } = useChartDataPondFetch()
|
||||||
const { requestDataPondId } = toRefs(targetComponent.request)
|
|
||||||
|
|
||||||
// 组件类型
|
// 组件类型
|
||||||
const { chartFrame } = targetComponent.chartConfig
|
const { chartFrame } = targetComponent.chartConfig
|
||||||
|
|
||||||
// eCharts 组件配合 vChart 库更新方式
|
// eCharts 组件配合 vChart 库更新方式
|
||||||
const echartsUpdateHandle = (dataset: any) => {
|
const echartsUpdateHandle = (dataset: any) => {
|
||||||
if (chartFrame === ChartFrameEnum.ECHARTS) {
|
if (chartFrame === ChartFrameEnum.ECHARTS) {
|
||||||
@ -89,7 +88,6 @@ export const useChartDataFetch = (
|
|||||||
|
|
||||||
// 立即调用
|
// 立即调用
|
||||||
fetchFn()
|
fetchFn()
|
||||||
|
|
||||||
// 定时时间
|
// 定时时间
|
||||||
const time = targetInterval && targetInterval.value ? targetInterval.value : globalRequestInterval.value
|
const time = targetInterval && targetInterval.value ? targetInterval.value : globalRequestInterval.value
|
||||||
// 单位
|
// 单位
|
||||||
@ -104,8 +102,8 @@ export const useChartDataFetch = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isPreview()) {
|
if (isPreview()) {
|
||||||
// 判断是否有数据池对应 id
|
// 判断是否是数据池类型
|
||||||
requestDataPondId
|
targetComponent.request.requestDataType === RequestDataTypeEnum.Pond
|
||||||
? addGlobalDataInterface(targetComponent, useChartEditStore, updateCallback || echartsUpdateHandle)
|
? addGlobalDataInterface(targetComponent, useChartEditStore, updateCallback || echartsUpdateHandle)
|
||||||
: requestIntervalFn()
|
: requestIntervalFn()
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import { customizeHttp } from '@/api/http'
|
|||||||
import { CreateComponentType } from '@/packages/index.d'
|
import { CreateComponentType } from '@/packages/index.d'
|
||||||
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
|
||||||
import { RequestGlobalConfigType, RequestDataPondItemType } from '@/store/modules/chartEditStore/chartEditStore.d'
|
import { RequestGlobalConfigType, RequestDataPondItemType } from '@/store/modules/chartEditStore/chartEditStore.d'
|
||||||
import { newFunctionHandle } from '@/utils'
|
import { newFunctionHandle, intervalUnitHandle } from '@/utils'
|
||||||
|
|
||||||
// 获取类型
|
// 获取类型
|
||||||
type ChartEditStoreType = typeof useChartEditStore
|
type ChartEditStoreType = typeof useChartEditStore
|
||||||
@ -24,6 +24,9 @@ const newPondItemInterval = (
|
|||||||
dataPondMapItem?: DataPondMapType[]
|
dataPondMapItem?: DataPondMapType[]
|
||||||
) => {
|
) => {
|
||||||
if (!dataPondMapItem) return
|
if (!dataPondMapItem) return
|
||||||
|
let fetchInterval: any = 0
|
||||||
|
|
||||||
|
clearInterval(fetchInterval)
|
||||||
|
|
||||||
// 请求
|
// 请求
|
||||||
const fetchFn = async () => {
|
const fetchFn = async () => {
|
||||||
@ -48,6 +51,19 @@ const newPondItemInterval = (
|
|||||||
|
|
||||||
// 立即调用
|
// 立即调用
|
||||||
fetchFn()
|
fetchFn()
|
||||||
|
|
||||||
|
const targetInterval = requestDataPondItem.dataPondRequestConfig.requestInterval
|
||||||
|
const targetUnit = requestDataPondItem.dataPondRequestConfig.requestIntervalUnit
|
||||||
|
|
||||||
|
const globalRequestInterval = requestGlobalConfig.requestInterval
|
||||||
|
const globalUnit = requestGlobalConfig.requestIntervalUnit
|
||||||
|
|
||||||
|
// 定时时间
|
||||||
|
const time = targetInterval ? targetInterval : globalRequestInterval
|
||||||
|
// 单位
|
||||||
|
const unit = targetInterval ? targetUnit : globalUnit
|
||||||
|
// 开启轮询
|
||||||
|
if (time) fetchInterval = setInterval(fetchFn, intervalUnitHandle(time, unit))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,6 +90,11 @@ export const useChartDataPondFetch = () => {
|
|||||||
mittDataPondMap.set(requestDataPondId, mittPondIdArr)
|
mittDataPondMap.set(requestDataPondId, mittPondIdArr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清除旧数据
|
||||||
|
const clearMittDataPondMap = () => {
|
||||||
|
mittDataPondMap.clear()
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化数据池
|
// 初始化数据池
|
||||||
const initDataPond = (requestGlobalConfig: RequestGlobalConfigType) => {
|
const initDataPond = (requestGlobalConfig: RequestGlobalConfigType) => {
|
||||||
const { requestDataPond } = requestGlobalConfig
|
const { requestDataPond } = requestGlobalConfig
|
||||||
@ -88,6 +109,7 @@ export const useChartDataPondFetch = () => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
addGlobalDataInterface,
|
addGlobalDataInterface,
|
||||||
|
clearMittDataPondMap,
|
||||||
initDataPond
|
initDataPond
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ import { getSizeStyle, getComponentAttrStyle, getStatusStyle } from '../../utils
|
|||||||
import { useLifeHandler } from '@/hooks'
|
import { useLifeHandler } from '@/hooks'
|
||||||
|
|
||||||
// 初始化数据池
|
// 初始化数据池
|
||||||
const { initDataPond } = useChartDataPondFetch()
|
const { initDataPond, clearMittDataPondMap } = useChartDataPondFetch()
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
localStorageInfo: {
|
localStorageInfo: {
|
||||||
@ -69,6 +69,7 @@ const themeColor = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// 组件渲染结束初始化数据池
|
// 组件渲染结束初始化数据池
|
||||||
|
clearMittDataPondMap()
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
initDataPond(props.localStorageInfo.requestGlobalConfig)
|
initDataPond(props.localStorageInfo.requestGlobalConfig)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user