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-02-08 02:06:21 +00:00
|
|
|
import {message} from "~/components/x-message/useMessage.js";
|
2025-01-23 11:29:29 +00:00
|
|
|
|
2025-01-15 08:10:28 +00:00
|
|
|
export const liveStore = createGlobalState(() => {
|
2025-01-23 11:29:29 +00:00
|
|
|
const {auctionDetail,getAuctionDetail} = goodStore();
|
2025-02-08 02:06:21 +00:00
|
|
|
|
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-02-08 02:06:21 +00:00
|
|
|
const cleanup = ref(null)
|
2025-01-23 12:02:20 +00:00
|
|
|
const show1=ref(true)
|
2025-01-16 03:07:38 +00:00
|
|
|
const playerId=ref('J_prismPlayer')
|
2025-01-23 11:29:29 +00:00
|
|
|
const auctionData=ref({})
|
2025-02-08 02:06:21 +00:00
|
|
|
const getSocketData = async () => {
|
|
|
|
if (!auctionDetail.value.uuid) {
|
2025-01-23 11:29:29 +00:00
|
|
|
await getAuctionDetail()
|
|
|
|
}
|
|
|
|
|
2025-02-08 02:06:21 +00:00
|
|
|
const { ws, onMessage } = useWebSocket()
|
|
|
|
// 建立新连接
|
|
|
|
ws.connect('/api/v1/m/auction/live', {
|
|
|
|
auctionUuid: auctionDetail.value.uuid,
|
2025-01-23 11:29:29 +00:00
|
|
|
|
2025-02-08 02:06:21 +00:00
|
|
|
})
|
|
|
|
// 保存清理函数
|
|
|
|
cleanup.value = onMessage((data) => {
|
2025-02-06 07:43:23 +00:00
|
|
|
auctionData.value = data.data
|
2025-02-08 02:06:21 +00:00
|
|
|
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)
|
2025-01-23 11:29:29 +00:00
|
|
|
})
|
|
|
|
}
|
2025-01-15 08:10:28 +00:00
|
|
|
const changeStatus = () => {
|
2025-02-08 02:06:21 +00:00
|
|
|
if (auctionData.value.artwork.isSelling){
|
|
|
|
quoteStatus.value = !quoteStatus.value
|
|
|
|
}else {
|
|
|
|
if (quoteStatus.value){
|
|
|
|
quoteStatus.value = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-15 08:10:28 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
})
|