liveh5-nuxt/app/stores-collect-code/live/index.js
xingyy a791248752 refactor(app): 优化代码结构和功能
- 移除多处 console.log 语句,清理无用代码
- 在消息组件中添加 info 类型配置并实现 info 消息显示功能
- 优化 WebSocket 消息处理逻辑,提高代码可读性
2025-02-08 16:24:26 +08:00

43 lines
1.2 KiB
JavaScript

import { createGlobalState } from '@vueuse/core'
import {ref} from "vue";
import {goodStore} from "@/stores/goods/index.js";
import {authStore} from "@/stores/auth/index.js";
export const liveStore = createGlobalState(() => {
const {auctionDetail,getAuctionDetail} = goodStore();
const { token } = authStore()
const quoteStatus = ref(false)
const show = ref(false)
const show1=ref(true)
const playerId=ref('J_prismPlayer')
const auctionData=ref({})
const getSocketData=async ()=>{
if (!auctionDetail.value.uuid){
await getAuctionDetail()
}
const { ws, messages, onMessage } = useWebSocket()
// 连接
ws.connect('/api/v1/m/auction/live',{auctionUuid: auctionDetail.value.uuid,token:token.value})
/*// 发送消息
ws.send({ type: 'chat', content: 'Hello!' })*/
// 监听消息
onMessage((data) => {
auctionData.value = data
})
}
const changeStatus = () => {
quoteStatus.value = !quoteStatus.value
}
return{
auctionData,
getSocketData,
show1,
playerId,
show,
quoteStatus,
changeStatus
}
})