|
|
@@ -498,7 +498,21 @@ onLoad(async (options) => {
|
|
|
sseRequestTask = createSSEConnection(sseConfig.url, sseConfig);
|
|
|
sseRequestTask.onMessage((msg) => {
|
|
|
console.log('SSE 收到:', msg);
|
|
|
- // 可在此根据 msg.data / msg.event 更新页面
|
|
|
+ if (msg.event === 'cart_update' && msg.data) {
|
|
|
+ try {
|
|
|
+ const payload = typeof msg.data === 'string' ? JSON.parse(msg.data) : msg.data;
|
|
|
+ const items = payload?.items ?? [];
|
|
|
+ cartData.value = {
|
|
|
+ items: Array.isArray(items) ? items : [],
|
|
|
+ totalAmount: Number(payload?.totalAmount) || 0,
|
|
|
+ totalQuantity: Number(payload?.totalQuantity) || 0
|
|
|
+ };
|
|
|
+ pendingCartData = null;
|
|
|
+ mergeCartIntoFoodList();
|
|
|
+ } catch (e) {
|
|
|
+ console.error('SSE 购物车数据解析失败:', e);
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
sseRequestTask.onOpen(async () => {
|
|
|
console.log('SSE 连接已建立');
|