Commit f31d67db8aa13f15f88c56ffab891dcb7acfcd2b
Merge branch 'fix/line-real-time' into 'main_dev'
fix: 修改h实时数据折线图名称标识符改成名称 See merge request yunteng/thingskit-view!200
Showing
5 changed files
with
26 additions
and
14 deletions
| @@ -8,7 +8,7 @@ export const includes = ['legend', 'xAxis', 'yAxis', 'grid'] | @@ -8,7 +8,7 @@ export const includes = ['legend', 'xAxis', 'yAxis', 'grid'] | ||
| 8 | export const seriesItem = { | 8 | export const seriesItem = { |
| 9 | type: 'line', | 9 | type: 'line', |
| 10 | label: { | 10 | label: { |
| 11 | - show: true, | 11 | + show: false, |
| 12 | position: 'top', | 12 | position: 'top', |
| 13 | color: '#fff', | 13 | color: '#fff', |
| 14 | fontSize: 12 | 14 | fontSize: 12 |
| @@ -205,23 +205,28 @@ watch( | @@ -205,23 +205,28 @@ watch( | ||
| 205 | //fix 修复v-chart图表绑定联动组件视图不更新问题 | 205 | //fix 修复v-chart图表绑定联动组件视图不更新问题 |
| 206 | const updateVChart = (newData: SocketReceiveMessageType) => { | 206 | const updateVChart = (newData: SocketReceiveMessageType) => { |
| 207 | if (!newData) return | 207 | if (!newData) return |
| 208 | - const { option } = props.chartConfig | 208 | + const { option,request } = props.chartConfig |
| 209 | + const {requestParams:{Params:{attrName}}} = request || {} | ||
| 209 | const { dataset: overrideDataset } = option | 210 | const { dataset: overrideDataset } = option |
| 210 | const { dimensions } = overrideDataset | 211 | const { dimensions } = overrideDataset |
| 211 | if (!Array.isArray(dimensions)) return | 212 | if (!Array.isArray(dimensions)) return |
| 212 | const { data } = newData | 213 | const { data } = newData |
| 213 | - const { keys, record } = useAssembleDataHooks(data,dimensions) | 214 | + const { record } = useAssembleDataHooks(data,dimensions,(attrName as any)) |
| 214 | if (unref(realTimeList).length >= chartMaxDataPoint.value) { | 215 | if (unref(realTimeList).length >= chartMaxDataPoint.value) { |
| 215 | unref(realTimeList).splice(0, 1) | 216 | unref(realTimeList).splice(0, 1) |
| 216 | } | 217 | } |
| 217 | realTimeList.value.push(record) | 218 | realTimeList.value.push(record) |
| 218 | - const dataset = { | ||
| 219 | - dimensions: ['ts', ...keys], | 219 | + const dataset = { |
| 220 | + dimensions: ['ts', ...attrName], | ||
| 220 | source: toRaw(unref(realTimeList)) | 221 | source: toRaw(unref(realTimeList)) |
| 221 | } | 222 | } |
| 223 | + option.series.forEach((item:any,index:number)=>{ | ||
| 224 | + item.name = attrName?.[index] | ||
| 225 | + }) | ||
| 222 | vChartRef.value?.setOption({ | 226 | vChartRef.value?.setOption({ |
| 223 | - ...option.value, | ||
| 224 | - dataset | 227 | + ...option, |
| 228 | + dataset, | ||
| 229 | + legend:{data:attrName || []} | ||
| 225 | }) | 230 | }) |
| 226 | } | 231 | } |
| 227 | const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, newData => { | 232 | const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, newData => { |
| @@ -3,9 +3,10 @@ | @@ -3,9 +3,10 @@ | ||
| 3 | * @param data {'wendu':[[xxxxxx,xxxx]]} | 3 | * @param data {'wendu':[[xxxxxx,xxxx]]} |
| 4 | * @returns keys:[xx,xx,xx] record:{'x':'xx'} | 4 | * @returns keys:[xx,xx,xx] record:{'x':'xx'} |
| 5 | */ | 5 | */ |
| 6 | +import { isNullOrUnDef } from '@/utils/external/is' | ||
| 6 | import dayjs from 'dayjs' | 7 | import dayjs from 'dayjs' |
| 7 | 8 | ||
| 8 | -export const useAssembleDataHooks = (data: Record<string, string | [number, string]>, dimensions: string[]) => { | 9 | +export const useAssembleDataHooks = (data: Record<string, string | [number, string]>, dimensions: string[],attrName?:string[]) => { |
| 9 | const formatValueToNumber = (value: string | number, defaultValue = 0) => | 10 | const formatValueToNumber = (value: string | number, defaultValue = 0) => |
| 10 | isNaN(value as number) ? defaultValue : Number(value) | 11 | isNaN(value as number) ? defaultValue : Number(value) |
| 11 | const tempObj: Recordable = {} | 12 | const tempObj: Recordable = {} |
| @@ -17,11 +18,12 @@ export const useAssembleDataHooks = (data: Record<string, string | [number, stri | @@ -17,11 +18,12 @@ export const useAssembleDataHooks = (data: Record<string, string | [number, stri | ||
| 17 | }) | 18 | }) |
| 18 | }) | 19 | }) |
| 19 | const keys = Object.keys(tempObj) | 20 | const keys = Object.keys(tempObj) |
| 20 | - const record = keys.reduce((prev, next) => { | 21 | + const record = keys.reduce((prev, next,index) => { |
| 21 | const [latest] = data[next] || [] | 22 | const [latest] = data[next] || [] |
| 23 | + if (isNullOrUnDef(latest)) return prev | ||
| 22 | const [ts, value] = latest as unknown as string[] | 24 | const [ts, value] = latest as unknown as string[] |
| 23 | //把值转为number类型 wendu:"23" 转为 wendu:23 | 25 | //把值转为number类型 wendu:"23" 转为 wendu:23 |
| 24 | - return { ...prev, ts: dayjs(ts).format('YYYY-MM-DD HH:mm:ss'), [next]: formatValueToNumber(value) } | 26 | + return { ...prev, ts: dayjs(ts).format('YYYY-MM-DD HH:mm:ss'),[ attrName![index]]: formatValueToNumber(value) } |
| 25 | }, {}) | 27 | }, {}) |
| 26 | 28 | ||
| 27 | return { | 29 | return { |
| @@ -327,7 +327,8 @@ export const useSocketStore = defineStore({ | @@ -327,7 +327,8 @@ export const useSocketStore = defineStore({ | ||
| 327 | try { | 327 | try { |
| 328 | fn?.(value) | 328 | fn?.(value) |
| 329 | } catch (error) { | 329 | } catch (error) { |
| 330 | - throw `componentIds: ${componentIds} call update function happend error!` | 330 | + console.error(`componentIds: ${componentIds} call update function happend error!`) |
| 331 | + throw error | ||
| 331 | } | 332 | } |
| 332 | this.updateComponentById(targetComponentId as string, value) | 333 | this.updateComponentById(targetComponentId as string, value) |
| 333 | }) | 334 | }) |
| @@ -19,7 +19,8 @@ export enum BuiltInVariable { | @@ -19,7 +19,8 @@ export enum BuiltInVariable { | ||
| 19 | DEVICE_PROFILE_ID = 'deviceProfileId', | 19 | DEVICE_PROFILE_ID = 'deviceProfileId', |
| 20 | DATE_FIXED = 'fixed_date', | 20 | DATE_FIXED = 'fixed_date', |
| 21 | DATE_RANGE = 'date_range', | 21 | DATE_RANGE = 'date_range', |
| 22 | - SELECT_TIME_AGGREGATION = 'selectTimeAggregation' | 22 | + SELECT_TIME_AGGREGATION = 'selectTimeAggregation', |
| 23 | + ATTR_NAME='attrName' | ||
| 23 | } | 24 | } |
| 24 | 25 | ||
| 25 | export enum ComponentType { | 26 | export enum ComponentType { |
| @@ -134,7 +135,6 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { | @@ -134,7 +135,6 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { | ||
| 134 | 135 | ||
| 135 | const getValue = computed(() => { | 136 | const getValue = computed(() => { |
| 136 | const value = { ...unref(params) } | 137 | const value = { ...unref(params) } |
| 137 | - | ||
| 138 | if (Reflect.has(value, BuiltInVariable.DATE_FIXED)) { | 138 | if (Reflect.has(value, BuiltInVariable.DATE_FIXED)) { |
| 139 | const fieldMapping = unref(getParams).find(item => item.key === BuiltInVariable.DATE_FIXED) | 139 | const fieldMapping = unref(getParams).find(item => item.key === BuiltInVariable.DATE_FIXED) |
| 140 | Reflect.set(value, fieldMapping?.value || '', value[BuiltInVariable.DATE_FIXED]) | 140 | Reflect.set(value, fieldMapping?.value || '', value[BuiltInVariable.DATE_FIXED]) |
| @@ -229,8 +229,12 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { | @@ -229,8 +229,12 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { | ||
| 229 | labelField: 'name', | 229 | labelField: 'name', |
| 230 | valueField: 'identifier', | 230 | valueField: 'identifier', |
| 231 | multiple: true, | 231 | multiple: true, |
| 232 | - onUpdateValue(value) { | 232 | + onUpdateValue(value:any) { |
| 233 | params[BuiltInVariable.KEYS] = value | 233 | params[BuiltInVariable.KEYS] = value |
| 234 | + //保存物模型name | ||
| 235 | + const attrNameList = unref(optionsSet[BuiltInVariable.KEYS]) | ||
| 236 | + | ||
| 237 | + params[BuiltInVariable.ATTR_NAME] = value.map((item:any) => attrNameList.find((temp:any)=>temp.identifier==item).name) | ||
| 234 | } | 238 | } |
| 235 | } | 239 | } |
| 236 | }) | 240 | }) |