Commit b1f9f93ed04313970e8a5f09b03f98f71e0d9e21
1 parent
712968b5
fix(src/store/external): 修复ws绑定单个文本组件,然后有多个,并且进行分组,显示的信息为原始信息,而非过滤函数返回的信息
Showing
1 changed file
with
36 additions
and
12 deletions
| 1 | import { defineStore } from "pinia"; | 1 | import { defineStore } from "pinia"; |
| 2 | import { KeyBoundComponentList, SocketComponentRecord, SocketReceiveMessageType, SocketSendMessageItemType, SocketSendMessageType, SocketStoreType, UnsubscribePoolType } from '@/store/external/modules/socketStore.d' | 2 | import { KeyBoundComponentList, SocketComponentRecord, SocketReceiveMessageType, SocketSendMessageItemType, SocketSendMessageType, SocketStoreType, UnsubscribePoolType } from '@/store/external/modules/socketStore.d' |
| 3 | -import { CreateComponentType } from "@/packages/index.d"; | 3 | +import { CreateComponentGroupType, CreateComponentType } from "@/packages/index.d"; |
| 4 | import { RequestContentTypeEnum } from "@/enums/external/httpEnum"; | 4 | import { RequestContentTypeEnum } from "@/enums/external/httpEnum"; |
| 5 | import { useChartEditStore } from "@/store/modules/chartEditStore/chartEditStore"; | 5 | import { useChartEditStore } from "@/store/modules/chartEditStore/chartEditStore"; |
| 6 | import { pinia } from '@/store' | 6 | import { pinia } from '@/store' |
| @@ -241,17 +241,41 @@ export const useSocketStore = defineStore({ | @@ -241,17 +241,41 @@ export const useSocketStore = defineStore({ | ||
| 241 | * @param value | 241 | * @param value |
| 242 | */ | 242 | */ |
| 243 | updateComponentById(id: string, value: SocketReceiveMessageType) { | 243 | updateComponentById(id: string, value: SocketReceiveMessageType) { |
| 244 | - const targetComponent = this.getSocketComponentsRecord.find(item => item.componentId === id) | ||
| 245 | - const targetComponentIndex = chartEditStore.fetchTargetIndex(targetComponent?.componentId) | ||
| 246 | - const target = chartEditStore.componentList[targetComponentIndex] as CreateComponentType | ||
| 247 | - const _target = cloneDeep(target) | ||
| 248 | - const { filter } = _target | ||
| 249 | - const _value = this.getComponentValueByKeys(target, value) | ||
| 250 | - const { value: filterValue, reason, flag } = useFilterFn(filter, _value) | ||
| 251 | - _target.option.dataset = flag ? filterValue : reason | ||
| 252 | - // TODO 存在重复更新未变化的值 | ||
| 253 | - // console.log({ _target }) | ||
| 254 | - chartEditStore.updateComponentList(targetComponentIndex, _target) | 244 | + /** |
| 245 | + * 原来的代码 | ||
| 246 | + // const targetComponent = this.getSocketComponentsRecord.find(item => item.componentId === id) | ||
| 247 | + // const targetComponentIndex = chartEditStore.fetchTargetIndex(targetComponent?.componentId) | ||
| 248 | + // const target = chartEditStore.componentList[targetComponentIndex] as CreateComponentType | ||
| 249 | + // const _target = cloneDeep(target) | ||
| 250 | + // const { filter } = _target | ||
| 251 | + // const _value = this.getComponentValueByKeys(target, value) | ||
| 252 | + // const { value: filterValue, reason, flag } = useFilterFn(filter, _value) | ||
| 253 | + // _target.option.dataset = flag ? filterValue : reason | ||
| 254 | + // // TODO 存在重复更新未变化的值 | ||
| 255 | + // // console.log({ _target }) | ||
| 256 | + // chartEditStore.updateComponentList(targetComponentIndex, _target) | ||
| 257 | + */ | ||
| 258 | + | ||
| 259 | + /** | ||
| 260 | + * 修改后的代码 | ||
| 261 | + * 修改ws绑定单个文本组件,然后有多个,并且进行分组,显示的信息为原始信息,而非过滤函数返回的信息 | ||
| 262 | + */ | ||
| 263 | + const target = chartEditStore.getComponentList?.reduce((prev: Array<CreateComponentType | CreateComponentGroupType>, acc) => { | ||
| 264 | + acc?.isGroup ? (prev = [...(acc?.groupList as CreateComponentGroupType[])]) : prev?.push(acc) | ||
| 265 | + return prev | ||
| 266 | + }, []) | ||
| 267 | + ?.filter( | ||
| 268 | + item => (item?.request?.requestContentType as RequestContentTypeEnum) === RequestContentTypeEnum.WEB_SOCKET | ||
| 269 | + ) | ||
| 270 | + target.forEach(item => { | ||
| 271 | + if (item.id === id) { | ||
| 272 | + const _value = this.getComponentValueByKeys(item, value) | ||
| 273 | + const { filter } = item | ||
| 274 | + const { value: filterValue, reason, flag } = useFilterFn(filter, _value) | ||
| 275 | + item.option.dataset = flag ? filterValue : reason | ||
| 276 | + } | ||
| 277 | + }) | ||
| 278 | + // | ||
| 255 | }, | 279 | }, |
| 256 | 280 | ||
| 257 | /** | 281 | /** |