liveh5-nuxt/app/stores/live/index.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

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) => {
console.log('收到消息:', data)
auctionData.value = data
})
}
const changeStatus = () => {
quoteStatus.value = !quoteStatus.value
}
return{
auctionData,
getSocketData,
show1,
playerId,
show,
quoteStatus,
changeStatus
}
})