功能:婚姻系统第12步(前端交互)
chat.js: - 监听婚姻全局广播(MarriageAccepted/Divorced/WeddingCelebration) - initMarriagePrivateChannel() 监听私人频道 (求婚/拒绝/过期/离婚申请/红包领取) frame.blade.php: - chatContext.marriage 注入所有婚姻 API URL - 引入 marriage-modals.blade.php 弹窗组件 marriage-modals.blade.php(新建): - 求婚弹窗(选戒指→求婚) - 收到求婚弹窗(接受/拒绝) - 结婚成功公告弹窗(可跳转婚礼设置) - 婚礼设置弹窗(档位/支付方式/立即OR定时) - 婚礼红包领取弹窗 - 所有 WebSocket 事件处理 user-actions.blade.php: - 名片加「💍 求婚」按钮(对方未婚时) - 名片加「💑 已婚状态」标签(对方已婚时) - fetchUser 同步拉取对方婚姻状态 MarriageController: - targetStatus 返回增加 status/partner_name/marriage_id - myRings 返回增加 status/intimacy_bonus/charm_bonus
This commit is contained in:
@@ -75,8 +75,75 @@ export function initChat(roomId) {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("chat:appointment-announced", { detail: e }),
|
||||
);
|
||||
})
|
||||
// ─── 婚姻系统:全局事件(广播给整个房间) ────────────────
|
||||
.listen("MarriageAccepted", (e) => {
|
||||
console.log("结婚公告:", e);
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("chat:marriage-accepted", { detail: e }),
|
||||
);
|
||||
})
|
||||
.listen("MarriageDivorced", (e) => {
|
||||
console.log("离婚公告:", e);
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("chat:marriage-divorced", { detail: e }),
|
||||
);
|
||||
})
|
||||
.listen("WeddingCelebration", (e) => {
|
||||
console.log("婚礼庆典:", e);
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("chat:wedding-celebration", { detail: e }),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化婚姻私人频道监听(求婚通知 / 拒绝通知 / 红包领取通知)
|
||||
* 在用户登录成功后调用,监听 user.{id} 私人频道的婚姻事件。
|
||||
*
|
||||
* @param {number} userId 当前登录用户 ID
|
||||
*/
|
||||
export function initMarriagePrivateChannel(userId) {
|
||||
if (!userId || !window.Echo) return;
|
||||
|
||||
window.Echo.private(`user.${userId}`)
|
||||
// 收到求婚通知(目标方)
|
||||
.listen(".marriage.proposed", (e) => {
|
||||
console.log("收到求婚:", e);
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("chat:marriage-proposed", { detail: e }),
|
||||
);
|
||||
})
|
||||
// 求婚被拒绝(发起方)
|
||||
.listen(".marriage.rejected", (e) => {
|
||||
console.log("求婚被拒:", e);
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("chat:marriage-rejected", { detail: e }),
|
||||
);
|
||||
})
|
||||
// 求婚过期(发起方)
|
||||
.listen(".marriage.expired", (e) => {
|
||||
console.log("求婚超时:", e);
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("chat:marriage-expired", { detail: e }),
|
||||
);
|
||||
})
|
||||
// 协议离婚申请通知(对方)
|
||||
.listen(".marriage.divorce-requested", (e) => {
|
||||
console.log("离婚申请:", e);
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("chat:divorce-requested", { detail: e }),
|
||||
);
|
||||
})
|
||||
// 红包领取成功通知
|
||||
.listen(".envelope.claimed", (e) => {
|
||||
console.log("红包到账:", e);
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("chat:envelope-claimed", { detail: e }),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// 供全局调用
|
||||
window.initChat = initChat;
|
||||
window.initMarriagePrivateChannel = initMarriagePrivateChannel;
|
||||
|
||||
Reference in New Issue
Block a user