迁移离婚弹窗组件脚本
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;
|
||||
|
||||
@@ -683,150 +683,6 @@
|
||||
|
||||
{{-- ═══════════ Alpine.js 组件脚本 ═══════════ --}}
|
||||
<script>
|
||||
/**
|
||||
* 发起离婚确认弹窗(发起方专用:展示双方结果 + 实时惩罚值)
|
||||
*/
|
||||
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 res = 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 res.json();
|
||||
this.close();
|
||||
if (data.ok) {
|
||||
window.chatDialog?.alert(data.message, '申请已发出 📩', '#6b7280');
|
||||
} else {
|
||||
window.chatDialog?.alert(data.message || '操作失败', '错误', '#dc2626');
|
||||
}
|
||||
} catch (e) {
|
||||
this.error = '网络请求失败,请重试。';
|
||||
} finally {
|
||||
this.acting = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 离婚申请通知弹窗(被申请方专用:三选 + 真实惩罚值)
|
||||
*/
|
||||
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;
|
||||
},
|
||||
|
||||
/** 同意:协议离婚,双方各扣 mutualPenalty 魅力 */
|
||||
async doAgree() {
|
||||
if (this.acting) return;
|
||||
this.acting = true;
|
||||
this.error = '';
|
||||
try {
|
||||
const res = 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 res.json();
|
||||
this.close();
|
||||
window.chatDialog?.alert(data.message, data.ok ? '操作完成' : '失败', data.ok ? '#6b7280' :
|
||||
'#cc4444');
|
||||
} catch (e) {
|
||||
this.error = '网络请求失败,请重试。';
|
||||
} finally {
|
||||
this.acting = false;
|
||||
}
|
||||
},
|
||||
|
||||
/** 不同意:视为强制离婚,申请方扣魅力 + 赔一半金币 */
|
||||
async doReject() {
|
||||
if (this.acting) return;
|
||||
this.acting = true;
|
||||
this.error = '';
|
||||
try {
|
||||
const res = 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 res.json();
|
||||
this.close();
|
||||
window.chatDialog?.alert(data.message, data.ok ? '已处理' : '失败', data.ok ? '#d97706' : '#cc4444');
|
||||
} catch (e) {
|
||||
this.error = '网络请求失败,请重试。';
|
||||
} finally {
|
||||
this.acting = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function weddingSetupModal() {
|
||||
return {
|
||||
show: false,
|
||||
|
||||
Reference in New Issue
Block a user