修复:confirmGift null错误(先保存item再关弹框);MessageSent改为ShouldBroadcastNow立即广播;修复route()引号冲突

This commit is contained in:
2026-02-27 16:26:16 +08:00
parent 6a8ba4fbc8
commit 157aee3812
3 changed files with 9 additions and 6 deletions

View File

@@ -12,11 +12,11 @@ namespace App\Events;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class MessageSent implements ShouldBroadcast
class MessageSent implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

View File

@@ -117,8 +117,8 @@ class ShopController extends Controller
: '';
$sysContent = "{$icon}{$user->username}】送出了一张 [{$item->name}],赠给 {$toStr}{$msgText}";
// 广播系统消息到公屏
broadcast(new MessageSent(
// 广播系统消息到公屏ShouldBroadcastNow 模式)
$sysMsgEvent = new MessageSent(
roomId: $roomId,
message: [
'id' => 0,
@@ -129,7 +129,8 @@ class ShopController extends Controller
'color' => '#cc6600',
'created_at' => now()->toDateTimeString(),
]
));
);
broadcast($sysMsgEvent);
}
}

View File

@@ -870,8 +870,10 @@
const recipient = document.getElementById('gift-recipient').value.trim();
const message = document.getElementById('gift-message').value.trim();
document.getElementById('gift-err').textContent = '';
// 先将商品数据保存到局部变量再关闭弹框closeGiftDialog 会把 _giftItem 设为 null
const item = _giftItem;
closeGiftDialog();
buyItem(_giftItem.id, _giftItem.name, _giftItem.price, recipient, message);
buyItem(item.id, item.name, item.price, recipient, message);
};
/** 购买商品(最终执行) */