提交 8b340651 作者: 王定

合并分支

import { weatherHttp } from '/@/utils/http/axios'
import { otherHttp, weatherHttp } from '/@/utils/http/axios'
const API_KEY = '4fb5c9e814994516b6522419651f2e9e'
......@@ -22,3 +22,25 @@ export function alarm(location: string) {
url: `/weatheralert/v1/current/${location.replace(',', '/')}?key=${API_KEY}`,
})
}
// 格点天气预报-日值(降雨、大风用)
export function gridForecastDaily(location: string, day = 3) {
return weatherHttp.get({
url: `/v7/weather/${day}d?key=${API_KEY}&location=${location}`,
})
}
// 格点天气预报-小时值(温度用)
export function gridForecastHourly(location: string) {
return weatherHttp.get({
url: `/v7/weather/24h?key=${API_KEY}&location=${location}`,
})
}
// 强对流预报(自建接口)
export function severeForecast(lon: string, lat: string) {
return otherHttp.get({
url: '/weather/forecast',
params: { lon, lat },
}, { isTransformResponse: false })
}
......@@ -13,17 +13,17 @@ export default {
},
methods: {
loadLibs: loadEchartsLibs,
init() {
init(notMerge) {
// 如果已经初始化过了,就直接更新配置项
if (this.chart && this.chart.setOption) {
this.chart.setOption(this.option)
this.chart.setOption(this.option, { notMerge: notMerge || false })
return
}
// 初始化组件
const chart = window.echarts.init(document.getElementById(this.option.id))
// 设置图表配置项
chart.setOption(this.option)
chart.setOption(this.option, { notMerge: notMerge || false })
this.chart = chart
},
changeOption(option) {
......@@ -45,12 +45,20 @@ export default {
}
}
this.option = merge(this.option, option)
const notMerge = option.__notMerge
// 清除内部标记
delete option.__notMerge
if (notMerge) {
this.option = option
} else {
this.option = merge(this.option, option)
}
if (typeof window.echarts === 'object' && typeof window.echarts.init === 'function') {
this.init()
this.init(notMerge)
} else {
this.loadLibs().then(() => {
this.init()
this.init(notMerge)
})
}
},
......
......@@ -44,10 +44,10 @@ export function useEcharts<T extends EchartsInstance, P extends EChartsOption>(
return [
register,
{
setOption: (option: Partial<P>): Promise<void> => {
setOption: (option: Partial<P>, opts?: { notMerge?: boolean; lazyUpdate?: boolean }): Promise<void> => {
return new Promise((resolve) => {
tryOnMounted(() => {
getInstance()?.setOption(option)
getInstance()?.setOption(option, opts)
resolve()
})
})
......
......@@ -14,7 +14,7 @@
this.$emit('register', this)
},
methods: {
setOption(option) {
setOption(option, opts) {
// 处理tooltip formatter函数序列化
if (option.tooltip && typeof option.tooltip.formatter === 'function') {
// 将函数转换为字符串,在视图层重新构建
......@@ -25,6 +25,11 @@
id: this.id,
...option,
}
// 保存 opts 供 renderjs 层使用
if (opts?.notMerge !== undefined) {
this.option.__notMerge = opts.notMerge
}
},
},
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论