Browse Source

feat: useChartDataFetch.hook.ts 数据源请求完善

main
betaqi 2 weeks ago
parent
commit
8bcafb450f
  1. 2
      package.json
  2. 27
      src/hooks/useChartDataFetch.hook.ts

2
package.json

@ -7,7 +7,7 @@
}, },
"scripts": { "scripts": {
"dev": "vite --host", "dev": "vite --host",
"build": "vue-tsc --noEmit && vite build", "build": "vite build",
"build:prod": "vite build --mode production", "build:prod": "vite build --mode production",
"preview": "vite preview", "preview": "vite preview",
"new": "plop --plopfile ./plop/plopfile.js", "new": "plop --plopfile ./plop/plopfile.js",

27
src/hooks/useChartDataFetch.hook.ts

@ -13,6 +13,7 @@ import { intervalUnitHandle, isPreview, newFunctionHandle } from '@/utils'
import { setOption } from '@/packages/public/chart' import { setOption } from '@/packages/public/chart'
import { isNil } from 'lodash' import { isNil } from 'lodash'
import dayjs from "dayjs"; import dayjs from "dayjs";
import { fetchDataByIot } from "@/api/path/dataSource";
// 获取类型 // 获取类型
type ChartEditStoreType = typeof useChartEditStore type ChartEditStoreType = typeof useChartEditStore
@ -120,17 +121,23 @@ export const useChartDataFetch = (
} }
function SourceRequestIntervalFn() { function SourceRequestIntervalFn() {
const chartEditStore = useChartEditStore()
const {
station,
device,
points,
requestIntervalUnit: targetUnit,
requestInterval: targetInterval
} = toRefs(targetComponent.requestSource)
try { try {
function fetchFn() { async function fetchFn() {
console.log(station.value) const res = await fetchDataByIot(targetComponent.requestSource)
if (res) {
try {
const filter = targetComponent.filter
const { data } = res
echartsUpdateHandle(newFunctionHandle(data, res, filter))
// 更新回调函数
if (updateCallback) {
updateCallback(newFunctionHandle(data, res, filter))
}
} catch (error) {
console.error(error)
}
}
} }
createFetchInterval(fetchFn, targetComponent.requestSource) createFetchInterval(fetchFn, targetComponent.requestSource)

Loading…
Cancel
Save