新增:在用户名片面板展现「协议离婚」按钮及相关的交互弹窗提示

This commit is contained in:
2026-03-01 18:02:47 +08:00
parent 52c252f525
commit 5bcbf74dfc
3 changed files with 52 additions and 3 deletions

View File

@@ -94,6 +94,7 @@ class MarriageController extends Controller
'status' => $marriage->status,
'marriage_id' => $marriage->id,
'partner_name' => $partner?->username,
'is_my_partner' => $partner?->id === $request->user()?->id,
'ring' => $marriage->ringItem?->only(['name', 'icon']),
'level_icon' => \App\Services\MarriageIntimacyService::levelIcon($marriage->level),
'level_name' => \App\Services\MarriageIntimacyService::levelName($marriage->level),

View File

@@ -27,7 +27,7 @@
{{-- 内容区 --}}
<div id="global-dialog-message"
style="padding:18px 18px 14px; font-size:13px; color:#374151;
style="padding:18px 18px 14px; font-size:13px; color:#374151; white-space:pre-wrap;
line-height:1.6; word-break:break-word;">
</div>

View File

@@ -167,6 +167,45 @@
this.friendLoading = false;
},
async handleConfirmDivorce(marriageId) {
// 等待后端接口实现,当前先略
return;
},
/** 发起协议离婚 */
async doDivorce(marriageId) {
if (!marriageId) return;
this.showUserModal = false;
const confirmed = await window.chatDialog?.confirm(
'提出离婚后,对方将在私人频道收到通知。\n\n如果对方在 24 小时内未作决定,此申请将自动升级为“强制离婚”,并扣除发起方一定的魅力值作为单方面解除契约的惩罚。\n\n您确定要继续发起离婚申请吗',
'发起离婚',
'#475569'
);
if (!confirmed) return;
window.chatDialog?.alert('请稍候…', '发送申请中', '#9ca3af');
try {
const res = await fetch(window.chatContext.marriage.divorceUrl(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();
if (data.ok) {
window.chatDialog?.alert(data.message, '已发出', '#6b7280');
} else {
window.chatDialog?.alert(data.message || '操作失败', '错误', '#dc2626');
}
} catch (e) {
window.chatDialog?.alert('网络请求失败', '错误', '#dc2626');
}
},
/** 获取用户资料 */
async fetchUser(username) {
try {
@@ -736,14 +775,23 @@
💍 请先设置性别
</div>
{{-- 对方已婚时显示提示 --}}
<div x-show="!marriageLoading && targetMarriage && targetMarriage.status === 'married'"
{{-- 对方已婚时显示提示(非伴侣) --}}
<div x-show="!marriageLoading && targetMarriage && targetMarriage.status === 'married' && !targetMarriage.is_my_partner"
style="flex:1; display:flex; align-items:center; justify-content:center;
padding:7px 10px; border-radius:5px; font-size:11px; background:#fff1f2;
border:1px solid #fecdd3; color:#f43f5e; font-weight:bold;">
💑 <span x-text="'与 ' + (targetMarriage?.partner_name || '—') + ' 已婚'"
style="margin-left:3px;"></span>
</div>
{{-- 如果对方是自己的伴侣,显示离婚按钮 --}}
<button
x-show="!marriageLoading && targetMarriage && targetMarriage.status === 'married' && targetMarriage.is_my_partner"
style="flex:1; padding: 7px 10px; border-radius: 5px; font-size: 12px; font-weight: bold; cursor: pointer;
background: #64748b; color:#fff; border:none;"
x-on:click="doDivorce(targetMarriage.marriage_id)">
💔 协议离婚
</button>
</div>
{{-- 内联礼物面板 --}}