From 2e8bfb61c27499e5a23341c6f2ecb4ef0ccbbc03 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 25 Apr 2026 19:20:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=A6=BB=E5=A9=9A=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E7=BB=84=E4=BB=B6=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/js/chat-room.js | 8 + resources/js/chat-room/marriage-modals.js | 161 ++++++++++++++++++ .../chat/partials/marriage-modals.blade.php | 144 ---------------- 3 files changed, 169 insertions(+), 144 deletions(-) diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index fa2056c..a20a407 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -97,6 +97,8 @@ export { export { appendSystemMessage, bindMarriageModalControls, + divorceConfirmModal, + divorceRequestModal, marriageAcceptedModal, marriageDivorcedModal, marriageIncomingModal, @@ -278,6 +280,8 @@ import { import { appendSystemMessage, bindMarriageModalControls, + divorceConfirmModal, + divorceRequestModal, marriageAcceptedModal, marriageDivorcedModal, marriageIncomingModal, @@ -549,6 +553,8 @@ if (typeof window !== "undefined") { bindMarriageStatusControls, appendSystemMessage, bindMarriageModalControls, + divorceConfirmModal, + divorceRequestModal, marriageAcceptedModal, marriageDivorcedModal, marriageIncomingModal, @@ -736,6 +742,8 @@ if (typeof window !== "undefined") { window.marriageAction = marriageAction; window.openMarriageStatusModal = openMarriageStatusModal; window.appendSystemMessage = appendSystemMessage; + window.divorceConfirmModal = divorceConfirmModal; + window.divorceRequestModal = divorceRequestModal; window.marriageAcceptedModal = marriageAcceptedModal; window.marriageDivorcedModal = marriageDivorcedModal; window.marriageIncomingModal = marriageIncomingModal; diff --git a/resources/js/chat-room/marriage-modals.js b/resources/js/chat-room/marriage-modals.js index 9af2665..6897e34 100644 --- a/resources/js/chat-room/marriage-modals.js +++ b/resources/js/chat-room/marriage-modals.js @@ -371,6 +371,165 @@ export function marriageDivorcedModal() { }; } +/** + * 创建发起离婚确认弹窗 Alpine 数据,展示协议/强制离婚的惩罚结果。 + * + * @returns {Record} + */ +export function divorceConfirmModal() { + return { + show: false, + marriageId: null, + mutualPenalty: 0, + forcedPenalty: 0, + mutualCooldown: 0, + forcedCooldown: 0, + acting: false, + error: "", + + open(marriageId, config) { + this.marriageId = marriageId; + this.mutualPenalty = config.mutual_charm_penalty ?? 0; + this.forcedPenalty = config.forced_charm_penalty ?? 0; + this.mutualCooldown = config.mutual_cooldown_days ?? 0; + this.forcedCooldown = config.forced_cooldown_days ?? 0; + this.acting = false; + this.error = ""; + this.show = true; + }, + + close() { + this.show = false; + }, + + async doConfirm() { + if (this.acting) { + return; + } + + this.acting = true; + this.error = ""; + + try { + const response = await fetch(window.chatContext.marriage.divorceUrl(this.marriageId), { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "X-CSRF-TOKEN": document.querySelector("meta[name=csrf-token]").content, + }, + }); + const data = await response.json(); + + this.close(); + + if (data.ok) { + window.chatDialog?.alert(data.message, "申请已发出 📩", "#6b7280"); + } else { + window.chatDialog?.alert(data.message || "操作失败", "错误", "#dc2626"); + } + } catch { + this.error = "网络请求失败,请重试。"; + } finally { + this.acting = false; + } + }, + }; +} + +/** + * 创建离婚申请通知弹窗 Alpine 数据,处理同意或拒绝离婚请求。 + * + * @returns {Record} + */ +export function divorceRequestModal() { + return { + show: false, + marriageId: null, + initiatorName: "", + mutualPenalty: 0, + forcedPenalty: 0, + acting: false, + error: "", + + open(detail) { + this.marriageId = detail.marriage_id; + this.initiatorName = detail.initiator_name ?? detail.divorcer_username ?? "对方"; + this.mutualPenalty = detail.mutual_charm_penalty ?? 0; + this.forcedPenalty = detail.forced_charm_penalty ?? 0; + this.acting = false; + this.error = ""; + this.show = true; + }, + + close() { + this.show = false; + }, + + async doAgree() { + if (this.acting) { + return; + } + + this.acting = true; + this.error = ""; + + try { + const response = await fetch(window.chatContext.marriage.confirmDivorceUrl(this.marriageId), { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "X-CSRF-TOKEN": document.querySelector("meta[name=csrf-token]").content, + }, + body: JSON.stringify({ + room_id: window.chatContext.roomId, + }), + }); + const data = await response.json(); + + this.close(); + window.chatDialog?.alert(data.message, data.ok ? "操作完成" : "失败", data.ok ? "#6b7280" : "#cc4444"); + } catch { + this.error = "网络请求失败,请重试。"; + } finally { + this.acting = false; + } + }, + + async doReject() { + if (this.acting) { + return; + } + + this.acting = true; + this.error = ""; + + try { + const response = await fetch(window.chatContext.marriage.rejectDivorceUrl(this.marriageId), { + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "X-CSRF-TOKEN": document.querySelector("meta[name=csrf-token]").content, + }, + body: JSON.stringify({ + room_id: window.chatContext.roomId, + }), + }); + const data = await response.json(); + + this.close(); + window.chatDialog?.alert(data.message, data.ok ? "已处理" : "失败", data.ok ? "#d97706" : "#cc4444"); + } catch { + this.error = "网络请求失败,请重试。"; + } finally { + this.acting = false; + } + }, + }; +} + /** * 读取 Alpine 组件数据,避免直接访问 Alpine 私有字段。 * @@ -571,6 +730,8 @@ function bindMarriageModalBootstrap() { */ export function bindMarriageModalControls() { window.appendSystemMessage = appendSystemMessage; + window.divorceConfirmModal = divorceConfirmModal; + window.divorceRequestModal = divorceRequestModal; window.marriageAcceptedModal = marriageAcceptedModal; window.marriageDivorcedModal = marriageDivorcedModal; window.marriageIncomingModal = marriageIncomingModal; diff --git a/resources/views/chat/partials/marriage-modals.blade.php b/resources/views/chat/partials/marriage-modals.blade.php index a8719a4..bf99c7c 100644 --- a/resources/views/chat/partials/marriage-modals.blade.php +++ b/resources/views/chat/partials/marriage-modals.blade.php @@ -683,150 +683,6 @@ {{-- ═══════════ Alpine.js 组件脚本 ═══════════ --}}