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
| ... | ... | @@ -205,23 +205,28 @@ watch( | 
| 205 | 205 | //fix 修复v-chart图表绑定联动组件视图不更新问题 | 
| 206 | 206 | const updateVChart = (newData: SocketReceiveMessageType) => { | 
| 207 | 207 | if (!newData) return | 
| 208 | - const { option } = props.chartConfig | |
| 208 | + const { option,request } = props.chartConfig | |
| 209 | + const {requestParams:{Params:{attrName}}} = request || {} | |
| 209 | 210 | const { dataset: overrideDataset } = option | 
| 210 | 211 | const { dimensions } = overrideDataset | 
| 211 | 212 | if (!Array.isArray(dimensions)) return | 
| 212 | 213 | const { data } = newData | 
| 213 | - const { keys, record } = useAssembleDataHooks(data,dimensions) | |
| 214 | + const { record } = useAssembleDataHooks(data,dimensions,(attrName as any)) | |
| 214 | 215 | if (unref(realTimeList).length >= chartMaxDataPoint.value) { | 
| 215 | 216 | unref(realTimeList).splice(0, 1) | 
| 216 | 217 | } | 
| 217 | 218 | realTimeList.value.push(record) | 
| 218 | - const dataset = { | |
| 219 | - dimensions: ['ts', ...keys], | |
| 219 | + const dataset = { | |
| 220 | + dimensions: ['ts', ...attrName], | |
| 220 | 221 | source: toRaw(unref(realTimeList)) | 
| 221 | 222 | } | 
| 223 | + option.series.forEach((item:any,index:number)=>{ | |
| 224 | + item.name = attrName?.[index] | |
| 225 | + }) | |
| 222 | 226 | vChartRef.value?.setOption({ | 
| 223 | - ...option.value, | |
| 224 | - dataset | |
| 227 | + ...option, | |
| 228 | + dataset, | |
| 229 | + legend:{data:attrName || []} | |
| 225 | 230 | }) | 
| 226 | 231 | } | 
| 227 | 232 | const { vChartRef } = useChartDataFetch(props.chartConfig, useChartEditStore, newData => { | ... | ... | 
| ... | ... | @@ -3,9 +3,10 @@ | 
| 3 | 3 | * @param data {'wendu':[[xxxxxx,xxxx]]} | 
| 4 | 4 | * @returns keys:[xx,xx,xx] record:{'x':'xx'} | 
| 5 | 5 | */ | 
| 6 | +import { isNullOrUnDef } from '@/utils/external/is' | |
| 6 | 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 | 10 | const formatValueToNumber = (value: string | number, defaultValue = 0) => | 
| 10 | 11 | isNaN(value as number) ? defaultValue : Number(value) | 
| 11 | 12 | const tempObj: Recordable = {} | 
| ... | ... | @@ -17,11 +18,12 @@ export const useAssembleDataHooks = (data: Record<string, string | [number, stri | 
| 17 | 18 | }) | 
| 18 | 19 | }) | 
| 19 | 20 | const keys = Object.keys(tempObj) | 
| 20 | - const record = keys.reduce((prev, next) => { | |
| 21 | + const record = keys.reduce((prev, next,index) => { | |
| 21 | 22 | const [latest] = data[next] || [] | 
| 23 | + if (isNullOrUnDef(latest)) return prev | |
| 22 | 24 | const [ts, value] = latest as unknown as string[] | 
| 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 | 29 | return { | ... | ... | 
| ... | ... | @@ -327,7 +327,8 @@ export const useSocketStore = defineStore({ | 
| 327 | 327 | try { | 
| 328 | 328 | fn?.(value) | 
| 329 | 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 | 333 | this.updateComponentById(targetComponentId as string, value) | 
| 333 | 334 | }) | ... | ... | 
| ... | ... | @@ -19,7 +19,8 @@ export enum BuiltInVariable { | 
| 19 | 19 | DEVICE_PROFILE_ID = 'deviceProfileId', | 
| 20 | 20 | DATE_FIXED = 'fixed_date', | 
| 21 | 21 | DATE_RANGE = 'date_range', | 
| 22 | - SELECT_TIME_AGGREGATION = 'selectTimeAggregation' | |
| 22 | + SELECT_TIME_AGGREGATION = 'selectTimeAggregation', | |
| 23 | + ATTR_NAME='attrName' | |
| 23 | 24 | } | 
| 24 | 25 | |
| 25 | 26 | export enum ComponentType { | 
| ... | ... | @@ -134,7 +135,6 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { | 
| 134 | 135 | |
| 135 | 136 | const getValue = computed(() => { | 
| 136 | 137 | const value = { ...unref(params) } | 
| 137 | - | |
| 138 | 138 | if (Reflect.has(value, BuiltInVariable.DATE_FIXED)) { | 
| 139 | 139 | const fieldMapping = unref(getParams).find(item => item.key === BuiltInVariable.DATE_FIXED) | 
| 140 | 140 | Reflect.set(value, fieldMapping?.value || '', value[BuiltInVariable.DATE_FIXED]) | 
| ... | ... | @@ -229,8 +229,12 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { | 
| 229 | 229 | labelField: 'name', | 
| 230 | 230 | valueField: 'identifier', | 
| 231 | 231 | multiple: true, | 
| 232 | - onUpdateValue(value) { | |
| 232 | + onUpdateValue(value:any) { | |
| 233 | 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 | }) | ... | ... |