wip: 字典 websocket 实时更新
This commit is contained in:
@@ -77,20 +77,44 @@ export function useWebSocketDict() {
|
||||
try {
|
||||
// 尝试解析消息
|
||||
const eventData = JSON.parse(message.body) as DictEvent;
|
||||
console.log(
|
||||
`[WebSocket] 接收到字典事件: ${eventData.type}, 字典编码: ${eventData.dictCode}`,
|
||||
eventData
|
||||
);
|
||||
|
||||
if (eventData.type === "DICT_UPDATED") {
|
||||
// 删除缓存,强制重新加载
|
||||
dictStore.removeDictItem(eventData.dictCode);
|
||||
console.log(`字典 ${eventData.dictCode} 已更新,缓存已清除`);
|
||||
console.log(`[WebSocket] 字典 ${eventData.dictCode} 已更新,缓存已清除`);
|
||||
ElMessage.success(`字典 ${eventData.dictCode} 已更新`);
|
||||
|
||||
// 派发自定义事件,通知组件刷新数据
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("dict-updated", {
|
||||
detail: {
|
||||
dictCode: eventData.dictCode,
|
||||
timestamp: eventData.timestamp,
|
||||
},
|
||||
})
|
||||
);
|
||||
} else if (eventData.type === "DICT_DELETED") {
|
||||
// 删除缓存
|
||||
dictStore.removeDictItem(eventData.dictCode);
|
||||
console.log(`字典 ${eventData.dictCode} 已删除,缓存已清除`);
|
||||
console.log(`[WebSocket] 字典 ${eventData.dictCode} 已删除,缓存已清除`);
|
||||
ElMessage.warning(`字典 ${eventData.dictCode} 已删除`);
|
||||
|
||||
// 派发自定义事件,通知组件刷新数据
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("dict-deleted", {
|
||||
detail: {
|
||||
dictCode: eventData.dictCode,
|
||||
timestamp: eventData.timestamp,
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("解析字典WebSocket消息失败:", error);
|
||||
console.error("[WebSocket] 解析字典WebSocket消息失败:", error, message.body);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user