import { createGlobalState } from '@vueuse/core' import {ref} from "vue"; import {goodStore} from "@/stores/goods/index.js"; import {authStore} from "@/stores/auth/index.js"; import {message} from "~/components/x-message/useMessage.js"; export const liveStore = createGlobalState(() => { const {auctionDetail,getAuctionDetail} = goodStore(); const quoteStatus = ref(false) const show = ref(false) const cleanup = ref(null) const show1=ref(true) const playerId=ref('J_prismPlayer') const auctionData=ref({}) const getSocketData = async () => { if (!auctionDetail.value.uuid) { await getAuctionDetail() } const { ws, onMessage } = useWebSocket() // 建立新连接 ws.connect('/api/v1/m/auction/live', { auctionUuid: auctionDetail.value.uuid, }) // 保存清理函数 cleanup.value = onMessage((data) => { auctionData.value = data.data if (auctionData.value.wsType === 'tip') { if (auctionData.value.tip?.tipType === 'falling') { message.warning({ title: { text: '即将落槌', color: '#F09F1F', align: 'center', }, style: { width: '151px', bottom: '230px' }, }, 500000) } } console.log('auctionData.value', auctionData.value) }) } const changeStatus = () => { if (auctionData.value.artwork.isSelling){ quoteStatus.value = !quoteStatus.value }else { if (quoteStatus.value){ quoteStatus.value = false } } } return{ auctionData, getSocketData, show1, playerId, show, quoteStatus, changeStatus } })