2025-01-15 08:10:28 +00:00
|
|
|
import { createGlobalState } from '@vueuse/core'
|
|
|
|
import {ref} from "vue";
|
2025-01-23 11:29:29 +00:00
|
|
|
import {goodStore} from "@/stores/goods/index.js";
|
|
|
|
import {authStore} from "@/stores/auth/index.js";
|
|
|
|
|
2025-01-15 08:10:28 +00:00
|
|
|
export const liveStore = createGlobalState(() => {
|
2025-01-23 11:29:29 +00:00
|
|
|
const {auctionDetail,getAuctionDetail} = goodStore();
|
|
|
|
const { token } = authStore()
|
2025-01-15 08:10:28 +00:00
|
|
|
const quoteStatus = ref(false)
|
2025-01-16 03:23:46 +00:00
|
|
|
const show = ref(false)
|
2025-01-16 03:07:38 +00:00
|
|
|
const show1=ref(false)
|
|
|
|
const playerId=ref('J_prismPlayer')
|
2025-01-23 11:29:29 +00:00
|
|
|
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
|
|
|
|
})
|
|
|
|
}
|
2025-01-15 08:10:28 +00:00
|
|
|
const changeStatus = () => {
|
|
|
|
quoteStatus.value = !quoteStatus.value
|
|
|
|
}
|
|
|
|
return{
|
2025-01-23 11:29:29 +00:00
|
|
|
auctionData,
|
|
|
|
getSocketData,
|
2025-01-16 03:07:38 +00:00
|
|
|
show1,
|
|
|
|
playerId,
|
2025-01-15 08:10:28 +00:00
|
|
|
show,
|
|
|
|
quoteStatus,
|
|
|
|
changeStatus
|
|
|
|
}
|
|
|
|
})
|