Browse Source

fix: [数据源](数据源指标) 功能完善

main
betaqi 4 weeks ago
parent
commit
bc1daf868f
  1. 54
      src/hooks/useChartDataFetch.hook.ts
  2. 1
      src/store/modules/chartEditStore/chartEditStore.ts
  3. 2
      src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataRequest/components/RequestDataSourceConfig/index.vue
  4. 2
      src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataSource/components/data-source-model.vue

54
src/hooks/useChartDataFetch.hook.ts

@ -2,6 +2,10 @@ import { ref, toRefs, toRaw, watch } from 'vue' @@ -2,6 +2,10 @@ import { ref, toRefs, toRaw, watch } from 'vue'
import type VChart from 'vue-echarts'
import { customizeHttp } from '@/api/http'
import { useChartDataPondFetch } from '@/hooks/'
import {
RequestConfigType,
RequestDataSourceConfig
} from '@/store/modules/chartEditStore/chartEditStore.d'
import { CreateComponentType, ChartFrameEnum } from '@/packages/index.d'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
import { RequestAJAXTypes, RequestDataTypeEnum } from '@/enums/httpEnum'
@ -110,21 +114,7 @@ export const useChartDataFetch = ( @@ -110,21 +114,7 @@ export const useChartDataFetch = (
}
}
// 普通初始化与组件交互处理监听
// 定义一个防抖的函数
const debouncedFetch = debounce(() => {
clearInterval(fetchInterval)
// 定时时间
const time = targetInterval && !isNil(targetInterval.value) ? targetInterval.value : globalRequestInterval.value
// 单位
const unit = targetInterval && !isNil(targetInterval.value) ? targetUnit.value : globalUnit.value
// 开启轮询
if (time) {
fetchInterval = setInterval(fetchFn, intervalUnitHandle(time, unit))
}
fetchFn()
}, 500) // 500ms 后触发,可以按需调整
const debouncedFetch = createDebouncedFetch(fetchFn, targetComponent.requestSource)
watch(
() => targetComponent.request.requestParams,
() => {
@ -151,31 +141,51 @@ export const useChartDataFetch = ( @@ -151,31 +141,51 @@ export const useChartDataFetch = (
requestIntervalUnit: targetUnit,
requestInterval: targetInterval
} = toRefs(targetComponent.requestSource)
try {
function fetchFn() {
clearInterval(fetchInterval)
console.log(station, devices, points, targetUnit, targetInterval)
console.log(station.value)
}
const debouncedFetch = createDebouncedFetch(fetchFn, targetComponent.requestSource)
watch(
() => targetComponent.requestSource,
() => {
fetchFn()
debouncedFetch()
},
{
immediate: true,
deep: true
}
)
} catch (error) {
console.log('SourceRequestIntervalFn Error:', error)
}
}
function createDebouncedFetch(fetchFn: () => void, targetComponentRequest: RequestConfigType | RequestDataSourceConfig) {
const chartEditStore = useChartEditStore()
const {
requestIntervalUnit: targetUnit,
requestInterval: targetInterval
} = toRefs(targetComponentRequest)
// 全局数据
const {
requestOriginUrl,
requestIntervalUnit: globalUnit,
requestInterval: globalRequestInterval
} = toRefs(chartEditStore.getRequestGlobalConfig)
return debounce(() => {
const time = targetInterval && !isNil(targetInterval.value) ? targetInterval.value : globalRequestInterval.value
// // 单位
const unit = targetInterval && !isNil(targetInterval.value) ? targetUnit.value : globalUnit.value
// // 开启轮询
if (time) {
fetchInterval = setInterval(fetchFn, intervalUnitHandle(time, unit))
}
fetchFn()
}, 500)
}
if (isPreview()) {

1
src/store/modules/chartEditStore/chartEditStore.ts

@ -290,7 +290,6 @@ export const useChartEditStore = defineStore({ @@ -290,7 +290,6 @@ export const useChartEditStore = defineStore({
loadingFinish()
return -1
}
console.log(this)
const targetIndex = this.componentList.findIndex(e => e.id === targetId)
console.log("测试查找当前ID:",targetIndex)
console.log("componentList1:",this.getComponentList)

2
src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataRequest/components/RequestDataSourceConfig/index.vue

@ -57,7 +57,7 @@ @@ -57,7 +57,7 @@
点位:
</template>
<n-infinite-scroll style="height: 300px" :distance="10">
<n-infinite-scroll style="height: 500px" :distance="10">
<n-checkbox-group v-model:value="targetDataSourceRequest.points">
<n-grid :y-gap="8" :cols="3">
<n-gi v-for="point in pointsData">

2
src/views/chart/ContentConfigurations/components/ChartData/components/ChartDataSource/components/data-source-model.vue

@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
<n-scrollbar style="max-height: 718px">
<div class="go-pr-3">
<n-space vertical>
<request-global-config></request-global-config>
<!--<request-global-config></request-global-config>-->
<request-data-source-config
:target-data-source-request="targetData?.requestSource"></request-data-source-config>
</n-space>

Loading…
Cancel
Save