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-02-08 07:21:00 +00:00
|
|
|
import { WebSocketClient } from '@/utils/websocket'
|
2025-02-11 03:34:24 +00:00
|
|
|
import {logSendlog} from "~/api/goods/index.js";
|
|
|
|
import CryptoJS from "crypto-js";
|
2025-01-23 11:29:29 +00:00
|
|
|
|
2025-01-15 08:10:28 +00:00
|
|
|
export const liveStore = createGlobalState(() => {
|
2025-02-11 03:34:24 +00:00
|
|
|
const {auctionDetail} = goodStore();
|
2025-02-08 07:21:00 +00:00
|
|
|
const { token } = authStore()
|
2025-02-11 07:27:31 +00:00
|
|
|
const fullLive = ref(false)
|
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-02-08 07:21:00 +00:00
|
|
|
const show1=ref(false)
|
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 07:21:00 +00:00
|
|
|
const socket=ref(null)
|
|
|
|
const config = useRuntimeConfig()
|
2025-02-11 03:34:24 +00:00
|
|
|
const pullLink=ref('')
|
2025-02-11 06:55:25 +00:00
|
|
|
const isMinWindow = ref(false)
|
|
|
|
const lastSnapshot = ref('')
|
|
|
|
const liveInfo = ref(null)
|
|
|
|
|
|
|
|
// 设置最小化状态
|
|
|
|
const setMinWindow = (status) => {
|
|
|
|
isMinWindow.value = status
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置截图
|
|
|
|
const setSnapshot = (snapshot) => {
|
|
|
|
lastSnapshot.value = snapshot
|
|
|
|
}
|
|
|
|
|
|
|
|
// 设置直播信息
|
|
|
|
const setLiveInfo = (info) => {
|
|
|
|
liveInfo.value = info
|
|
|
|
}
|
|
|
|
|
|
|
|
// 重置状态
|
|
|
|
const reset = () => {
|
|
|
|
isMinWindow.value = false
|
|
|
|
lastSnapshot.value = ''
|
|
|
|
liveInfo.value = null
|
|
|
|
}
|
2025-02-11 03:34:24 +00:00
|
|
|
// 解密工具函数
|
|
|
|
const decryptUtils = {
|
|
|
|
// 解密配置
|
|
|
|
cryptConfig: {
|
|
|
|
password: 'live-skkoql-1239-key',
|
|
|
|
salt: 'aldk100128ls',
|
|
|
|
iterations: 10000,
|
|
|
|
keySize: 32
|
|
|
|
},
|
|
|
|
|
|
|
|
// 生成密钥
|
|
|
|
generateKey(password, salt, iterations, keySize) {
|
|
|
|
return CryptoJS.PBKDF2(password, salt, {
|
|
|
|
keySize: keySize / 4,
|
|
|
|
iterations: iterations,
|
|
|
|
hasher: CryptoJS.algo.SHA1
|
|
|
|
}).toString(CryptoJS.enc.Hex)
|
|
|
|
},
|
|
|
|
|
|
|
|
// AES解密
|
|
|
|
decrypt(ciphertextBase64, key) {
|
|
|
|
const combined = CryptoJS.enc.Base64.parse(ciphertextBase64)
|
|
|
|
const iv = CryptoJS.lib.WordArray.create(combined.words.slice(0, 4))
|
|
|
|
const ciphertext = CryptoJS.lib.WordArray.create(combined.words.slice(4))
|
|
|
|
|
|
|
|
const decrypted = CryptoJS.AES.decrypt(
|
|
|
|
{ciphertext: ciphertext},
|
|
|
|
CryptoJS.enc.Hex.parse(key),
|
|
|
|
{
|
|
|
|
iv: iv,
|
|
|
|
mode: CryptoJS.mode.CBC,
|
|
|
|
padding: CryptoJS.pad.Pkcs7
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return decrypted.toString(CryptoJS.enc.Utf8)
|
|
|
|
},
|
|
|
|
|
|
|
|
// 解密数据的主函数
|
|
|
|
decryptData(encryptedData) {
|
|
|
|
const keyDerived = this.generateKey(
|
|
|
|
this.cryptConfig.password,
|
|
|
|
this.cryptConfig.salt,
|
|
|
|
this.cryptConfig.iterations,
|
|
|
|
this.cryptConfig.keySize
|
|
|
|
)
|
|
|
|
return this.decrypt(encryptedData, keyDerived)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const getLiveLink = () => {
|
|
|
|
return new Promise(async(resolve, reject) => {
|
|
|
|
const res = await logSendlog({
|
|
|
|
uuid: auctionDetail.value.uuid
|
|
|
|
})
|
|
|
|
if (res.status===0){
|
|
|
|
pullLink.value=decryptUtils.decryptData(res.data.code)
|
|
|
|
resolve(decryptUtils.decryptData(res.data.code))
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-02-08 02:06:21 +00:00
|
|
|
const getSocketData = async () => {
|
2025-02-08 07:21:00 +00:00
|
|
|
const wsClient = new WebSocketClient(
|
|
|
|
config.public.NUXT_PUBLIC_SOCKET_URL,
|
|
|
|
token.value
|
|
|
|
)
|
|
|
|
const ws = wsClient.connect('/api/v1/m/auction/live', {
|
2025-02-08 02:06:21 +00:00
|
|
|
auctionUuid: auctionDetail.value.uuid,
|
2025-02-08 07:21:00 +00:00
|
|
|
})
|
2025-01-23 11:29:29 +00:00
|
|
|
|
2025-02-08 07:21:00 +00:00
|
|
|
ws.onOpen(() => {
|
|
|
|
console.log('WebSocket connected')
|
2025-02-08 02:06:21 +00:00
|
|
|
})
|
2025-02-08 07:21:00 +00:00
|
|
|
|
|
|
|
ws.onMessage((data) => {
|
2025-02-06 07:43:23 +00:00
|
|
|
auctionData.value = data.data
|
2025-02-08 07:21:00 +00:00
|
|
|
if (data.data?.wsType === 'tip' ) {
|
|
|
|
if (data.data?.tip?.tipType === 'falling'){
|
2025-02-08 02:06:21 +00:00
|
|
|
message.warning({
|
|
|
|
title: {
|
|
|
|
text: '即将落槌',
|
|
|
|
color: '#F09F1F',
|
|
|
|
align: 'center',
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
width: '151px',
|
2025-02-08 08:34:03 +00:00
|
|
|
bottom: '230px',
|
2025-02-08 02:06:21 +00:00
|
|
|
},
|
2025-02-08 09:40:54 +00:00
|
|
|
})
|
2025-02-08 07:21:00 +00:00
|
|
|
}else if (data.data?.tip?.tipType === 'othersBid'){
|
|
|
|
message.error({
|
|
|
|
title: {
|
|
|
|
text: '已有人出价',
|
|
|
|
color: '#CF3050',
|
|
|
|
align: 'center',
|
|
|
|
},
|
|
|
|
icon:false,
|
|
|
|
subTitle:{
|
|
|
|
text:'更新后再出价',
|
|
|
|
color: '#939393',
|
|
|
|
align: 'center',
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
width: '151px',
|
|
|
|
bottom: '230px'
|
|
|
|
},
|
2025-02-08 09:40:54 +00:00
|
|
|
})
|
2025-02-08 07:21:00 +00:00
|
|
|
}else if (data.data?.tip?.tipType === 'successBid'){
|
|
|
|
message.success({
|
|
|
|
title: {
|
|
|
|
text: '恭喜您,竞拍成功',
|
|
|
|
color: '#18A058',
|
|
|
|
align: 'center',
|
|
|
|
},
|
|
|
|
icon:false,
|
|
|
|
subTitle:{
|
|
|
|
text:'请缴款',
|
|
|
|
color: '#939393',
|
|
|
|
align: 'center',
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
width: '151px',
|
|
|
|
bottom: '230px'
|
|
|
|
},
|
2025-02-08 09:40:54 +00:00
|
|
|
})
|
2025-02-08 07:21:00 +00:00
|
|
|
}else if (data.data?.tip?.tipType === 'artworkOver'){
|
|
|
|
message.success({
|
|
|
|
title: {
|
|
|
|
text: '本拍品已结束',
|
|
|
|
color: '#575757',
|
|
|
|
align: 'center',
|
2025-02-10 07:47:26 +00:00
|
|
|
|
2025-02-08 07:21:00 +00:00
|
|
|
},
|
|
|
|
icon:false,
|
|
|
|
subTitle:{
|
|
|
|
text:'请期待下个拍品',
|
|
|
|
color: '#939393',
|
|
|
|
align: 'center',
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
width: '151px',
|
2025-02-10 07:47:26 +00:00
|
|
|
bottom: '230px',
|
|
|
|
backgroundColor: '#fff',
|
|
|
|
borderColor:'#fff'
|
2025-02-08 07:21:00 +00:00
|
|
|
},
|
|
|
|
})
|
2025-02-10 02:56:38 +00:00
|
|
|
}else if (data.data?.tip?.tipType === 'failBid'){
|
|
|
|
message.error({
|
|
|
|
title: {
|
|
|
|
text: '很遗憾,竞拍失败',
|
|
|
|
color: '#CF3050',
|
|
|
|
align: 'center',
|
|
|
|
},
|
|
|
|
icon:false,
|
|
|
|
subTitle:{
|
|
|
|
text:'竞拍结束',
|
|
|
|
color: '#939393',
|
|
|
|
align: 'center',
|
|
|
|
},
|
|
|
|
style: {
|
|
|
|
width: '186px',
|
|
|
|
bottom: '230px'
|
|
|
|
},
|
|
|
|
})
|
2025-02-08 02:06:21 +00:00
|
|
|
}
|
2025-02-08 07:21:00 +00:00
|
|
|
|
|
|
|
}else if (data.data?.wsType==='stopArtwor'){
|
|
|
|
quoteStatus.value=false
|
2025-02-10 02:56:38 +00:00
|
|
|
}else if (data.data?.wsType==='over'){
|
|
|
|
message.success({
|
|
|
|
title: {
|
|
|
|
text: '竞拍结束,谢谢参与',
|
|
|
|
color: '#575757',
|
|
|
|
align: 'center',
|
2025-02-10 07:47:26 +00:00
|
|
|
|
2025-02-10 02:56:38 +00:00
|
|
|
},
|
|
|
|
icon:false,
|
|
|
|
style: {
|
|
|
|
width: '195px',
|
2025-02-10 07:47:26 +00:00
|
|
|
bottom: '230px',
|
|
|
|
backgroundColor: '#fff',
|
|
|
|
borderColor:'#fff'
|
2025-02-10 02:56:38 +00:00
|
|
|
},
|
|
|
|
})
|
2025-02-08 02:06:21 +00:00
|
|
|
}
|
2025-02-08 07:21:00 +00:00
|
|
|
|
|
|
|
console.log('onmessage', data)
|
|
|
|
})
|
|
|
|
|
|
|
|
ws.onClose(() => {
|
|
|
|
console.log('WebSocket disconnected')
|
|
|
|
})
|
|
|
|
|
|
|
|
ws.onError((error) => {
|
|
|
|
console.error('WebSocket error:', error)
|
2025-01-23 11:29:29 +00:00
|
|
|
})
|
|
|
|
}
|
2025-01-15 08:10:28 +00:00
|
|
|
const changeStatus = () => {
|
2025-02-10 09:02:58 +00:00
|
|
|
if (auctionData.value.artwork.isSelling&&!auctionData.value.artwork.isSoled){
|
|
|
|
quoteStatus.value = true
|
2025-02-08 02:06:21 +00:00
|
|
|
}else {
|
|
|
|
if (quoteStatus.value){
|
|
|
|
quoteStatus.value = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-15 08:10:28 +00:00
|
|
|
}
|
|
|
|
return{
|
2025-02-11 07:27:31 +00:00
|
|
|
fullLive,
|
2025-02-11 06:55:25 +00:00
|
|
|
isMinWindow,
|
|
|
|
lastSnapshot,
|
|
|
|
liveInfo,
|
|
|
|
setMinWindow,
|
|
|
|
setSnapshot,
|
|
|
|
setLiveInfo,
|
|
|
|
reset,
|
2025-02-11 03:34:24 +00:00
|
|
|
pullLink,
|
|
|
|
getLiveLink,
|
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
|
|
|
|
}
|
|
|
|
})
|