迁移离婚弹窗组件脚本
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -371,6 +371,165 @@ export function marriageDivorcedModal() {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建发起离婚确认弹窗 Alpine 数据,展示协议/强制离婚的惩罚结果。
|
||||
*
|
||||
* @returns {Record<string, any>}
|
||||
*/
|
||||
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<string, any>}
|
||||
*/
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user