93 lines
2.7 KiB
JavaScript
93 lines
2.7 KiB
JavaScript
// 婚姻弹窗辅助入口,承接从 marriage-modals.blade.php 迁移出的全局函数。
|
|
|
|
/**
|
|
* 向聊天主窗口追加一条婚姻系统公告,允许传入受控 HTML 按钮。
|
|
*
|
|
* @param {string} html 系统模板生成的 HTML 内容
|
|
* @returns {void}
|
|
*/
|
|
export function appendSystemMessage(html) {
|
|
const container = document.getElementById("chat-messages-container");
|
|
|
|
if (!container) {
|
|
return;
|
|
}
|
|
|
|
const div = document.createElement("div");
|
|
div.style.cssText = "background:linear-gradient(135deg,#fdf4ff,#fce7f3); border-left:3px solid #ec4899; border-radius:6px; padding:5px 12px; margin:3px 0; font-size:13px; line-height:1.6;";
|
|
div.innerHTML = `<span style="color:#9d174d;">${html}</span>`;
|
|
container.appendChild(div);
|
|
container.scrollTop = container.scrollHeight;
|
|
}
|
|
|
|
/**
|
|
* 打开求婚弹窗入口,从用户名片按钮触发。
|
|
*
|
|
* @param {string} username 求婚对象用户名
|
|
* @returns {Promise<void>}
|
|
*/
|
|
export async function openProposeModal(username) {
|
|
let rings = [];
|
|
|
|
try {
|
|
const response = await fetch(window.chatContext.marriage.myRingsUrl, {
|
|
headers: {
|
|
Accept: "application/json",
|
|
},
|
|
});
|
|
const data = await response.json();
|
|
|
|
if (data.status === "success") {
|
|
rings = data.rings || [];
|
|
}
|
|
} catch {
|
|
// 网络异常时继续交给后端兜底,避免前端误拦截真实可用的求婚流程。
|
|
}
|
|
|
|
if (rings.length === 0) {
|
|
const goShop = await window.chatDialog?.confirm(
|
|
"求婚需要一枚💍结婚戒指,你的背包里还没有。\n\n要前往商店购买吗?",
|
|
"需要结婚戒指",
|
|
);
|
|
|
|
if (goShop && typeof window.openShopModal === "function") {
|
|
window.openShopModal();
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
const modal = document.getElementById("marriage-propose-modal");
|
|
const alpine = window.Alpine;
|
|
|
|
if (modal && alpine) {
|
|
alpine.$data(modal).openWithRings(username, rings);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 打开婚礼设置弹窗,供新婚公告和名片入口复用。
|
|
*
|
|
* @param {number|string} marriageId 婚姻记录 ID
|
|
* @returns {void}
|
|
*/
|
|
export function openWeddingSetupModal(marriageId) {
|
|
const modal = document.getElementById("wedding-setup-modal");
|
|
const alpine = window.Alpine;
|
|
|
|
if (modal && alpine) {
|
|
alpine.$data(modal).open(marriageId);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 暴露婚姻弹窗存量入口,兼容 Blade 内 onclick、Alpine 方法和广播回调。
|
|
*
|
|
* @returns {void}
|
|
*/
|
|
export function bindMarriageModalControls() {
|
|
window.appendSystemMessage = appendSystemMessage;
|
|
window.openProposeModal = openProposeModal;
|
|
window.openWeddingSetupModal = openWeddingSetupModal;
|
|
}
|