|
@@ -17,7 +17,8 @@ export const useSocketStore = defineStore({ |
|
@@ -17,7 +17,8 @@ export const useSocketStore = defineStore({ |
17
|
subscribePool: [],
|
17
|
subscribePool: [],
|
18
|
cacheMessage: {},
|
18
|
cacheMessage: {},
|
19
|
currentSubscribeId: 0,
|
19
|
currentSubscribeId: 0,
|
20
|
- unsubscribePool: []
|
20
|
+ unsubscribePool: [],
|
|
|
21
|
+ componentUpdateFnPool: {}
|
21
|
}),
|
22
|
}),
|
22
|
getters: {
|
23
|
getters: {
|
23
|
/**
|
24
|
/**
|
|
@@ -74,8 +75,8 @@ export const useSocketStore = defineStore({ |
|
@@ -74,8 +75,8 @@ export const useSocketStore = defineStore({ |
74
|
* 源代码 keys.forEach
|
75
|
* 源代码 keys.forEach
|
75
|
* 修改代码 const overrideKeys = typeof keys==="string"?[keys]: keys overrideKeys.forEach
|
76
|
* 修改代码 const overrideKeys = typeof keys==="string"?[keys]: keys overrideKeys.forEach
|
76
|
*/
|
77
|
*/
|
77
|
- const overrideKeys = typeof keys==="string"?[keys]: keys
|
|
|
78
|
-
|
78
|
+ const overrideKeys = typeof keys === "string" ? [keys] : keys
|
|
|
79
|
+
|
79
|
overrideKeys.forEach(key => {
|
80
|
overrideKeys.forEach(key => {
|
80
|
Reflect.set(keysRecord, key, [{ componentId }])
|
81
|
Reflect.set(keysRecord, key, [{ componentId }])
|
81
|
})
|
82
|
})
|
|
@@ -151,12 +152,13 @@ export const useSocketStore = defineStore({ |
|
@@ -151,12 +152,13 @@ export const useSocketStore = defineStore({ |
151
|
* @description 订阅
|
152
|
* @description 订阅
|
152
|
* @param targetComponent
|
153
|
* @param targetComponent
|
153
|
*/
|
154
|
*/
|
154
|
- subscribe(targetComponent: CreateComponentType) {
|
155
|
+ subscribe(targetComponent: CreateComponentType, updateCallback?: Fn) {
|
155
|
const { id: componentId, request } = targetComponent
|
156
|
const { id: componentId, request } = targetComponent
|
156
|
const { requestContentType, requestParams } = request
|
157
|
const { requestContentType, requestParams } = request
|
157
|
if ((requestContentType as RequestContentTypeEnum) === RequestContentTypeEnum.WEB_SOCKET) {
|
158
|
if ((requestContentType as RequestContentTypeEnum) === RequestContentTypeEnum.WEB_SOCKET) {
|
158
|
const { Params } = requestParams
|
159
|
const { Params } = requestParams
|
159
|
const { entityId = '', keys = [] } = Params
|
160
|
const { entityId = '', keys = [] } = Params
|
|
|
161
|
+ updateCallback && (this.componentUpdateFnPool[componentId] = updateCallback)
|
160
|
return this.updateConnectionPool(entityId, keys as string[], componentId)
|
162
|
return this.updateConnectionPool(entityId, keys as string[], componentId)
|
161
|
}
|
163
|
}
|
162
|
},
|
164
|
},
|
|
@@ -184,17 +186,17 @@ export const useSocketStore = defineStore({ |
|
@@ -184,17 +186,17 @@ export const useSocketStore = defineStore({ |
184
|
*/
|
186
|
*/
|
185
|
getNeedUpdateComponentsIdBySubscribeId(subscribeId: number, keys: string[]) {
|
187
|
getNeedUpdateComponentsIdBySubscribeId(subscribeId: number, keys: string[]) {
|
186
|
const entityId = this.subscribePool.find(item => item.subscribeId === subscribeId)?.entityId
|
188
|
const entityId = this.subscribePool.find(item => item.subscribeId === subscribeId)?.entityId
|
187
|
- /**这里修改自定义tab切换传的单个属性问题
|
|
|
188
|
- * ft
|
|
|
189
|
- * 源代码 keys.map(key => keysRecord[key])
|
|
|
190
|
- * 修改代码 const overrideKeys = typeof keys==="string"?[keys]: keys overrideKeys.map(key => keysRecord[key])
|
|
|
191
|
- */
|
|
|
192
|
- const overrideKeys = typeof keys==="string"?[keys]: keys
|
189
|
+ /**这里修改自定义tab切换传的单个属性问题
|
|
|
190
|
+ * ft
|
|
|
191
|
+ * 源代码 keys.map(key => keysRecord[key])
|
|
|
192
|
+ * 修改代码 const overrideKeys = typeof keys==="string"?[keys]: keys overrideKeys.map(key => keysRecord[key])
|
|
|
193
|
+ */
|
|
|
194
|
+ const overrideKeys = typeof keys === "string" ? [keys] : keys
|
193
|
|
195
|
|
194
|
if (entityId) {
|
196
|
if (entityId) {
|
195
|
const keysRecord = Reflect.get(this.connectionPool, entityId)
|
197
|
const keysRecord = Reflect.get(this.connectionPool, entityId)
|
196
|
const needUpdateComponents = overrideKeys.map(key => keysRecord[key])
|
198
|
const needUpdateComponents = overrideKeys.map(key => keysRecord[key])
|
197
|
- const ids = needUpdateComponents
|
199
|
+ const ids: string[] = needUpdateComponents
|
198
|
.reduce((prev, next) => [...prev, ...next], [])
|
200
|
.reduce((prev, next) => [...prev, ...next], [])
|
199
|
.map((item: KeyBoundComponentList) => item.componentId)
|
201
|
.map((item: KeyBoundComponentList) => item.componentId)
|
200
|
return [...new Set(ids)]
|
202
|
return [...new Set(ids)]
|
|
@@ -217,7 +219,7 @@ export const useSocketStore = defineStore({ |
|
@@ -217,7 +219,7 @@ export const useSocketStore = defineStore({ |
217
|
* 源代码 keys as unknown as string[]
|
219
|
* 源代码 keys as unknown as string[]
|
218
|
* 修改代码 const overrideKeys = typeof keys==="string"?[keys]: keys overrideKeys as unknown as string[]
|
220
|
* 修改代码 const overrideKeys = typeof keys==="string"?[keys]: keys overrideKeys as unknown as string[]
|
219
|
*/
|
221
|
*/
|
220
|
- const overrideKeys = typeof keys==="string"?[keys]: keys
|
222
|
+ const overrideKeys = typeof keys === "string" ? [keys] : keys
|
221
|
|
223
|
|
222
|
const targetComponentBindKeys = overrideKeys as unknown as string[]
|
224
|
const targetComponentBindKeys = overrideKeys as unknown as string[]
|
223
|
//ft
|
225
|
//ft
|
|
@@ -261,6 +263,12 @@ export const useSocketStore = defineStore({ |
|
@@ -261,6 +263,12 @@ export const useSocketStore = defineStore({ |
261
|
const keys = Object.keys(data)
|
263
|
const keys = Object.keys(data)
|
262
|
const componentIds = this.getNeedUpdateComponentsIdBySubscribeId(subscriptionId, keys)
|
264
|
const componentIds = this.getNeedUpdateComponentsIdBySubscribeId(subscriptionId, keys)
|
263
|
componentIds?.forEach((targetComponentId) => {
|
265
|
componentIds?.forEach((targetComponentId) => {
|
|
|
266
|
+ const fn = this.componentUpdateFnPool[targetComponentId]
|
|
|
267
|
+ try {
|
|
|
268
|
+ fn?.(value)
|
|
|
269
|
+ } catch (error) {
|
|
|
270
|
+ throw `componentIds: ${componentIds} call update function happend error!`
|
|
|
271
|
+ }
|
264
|
this.updateComponentById(targetComponentId as string, value)
|
272
|
this.updateComponentById(targetComponentId as string, value)
|
265
|
})
|
273
|
})
|
266
|
},
|
274
|
},
|