2025-04-10 11:11:46 +08:00
|
|
|
<script setup>
|
2025-06-22 02:39:03 +08:00
|
|
|
import { watch, onMounted, onUnmounted } from "vue";
|
|
|
|
|
import { onShow } from "@dcloudio/uni-app";
|
2025-06-05 21:32:15 +08:00
|
|
|
import websocket from "@/websocket";
|
|
|
|
|
import useStore from "@/store";
|
|
|
|
|
import { storeToRefs } from "pinia";
|
|
|
|
|
const store = useStore();
|
|
|
|
|
const { user } = storeToRefs(store);
|
2025-06-22 02:39:03 +08:00
|
|
|
const { updateConnect, updateUser } = store;
|
2025-04-10 11:11:46 +08:00
|
|
|
|
2025-06-05 21:32:15 +08:00
|
|
|
watch(
|
|
|
|
|
() => user.value.id,
|
|
|
|
|
(newVal) => {
|
|
|
|
|
const token = uni.getStorageSync("token");
|
|
|
|
|
if (newVal && token) {
|
2025-06-19 21:03:33 +08:00
|
|
|
websocket.createWebSocket(token, updateConnect, (content) => {
|
2025-06-05 21:32:15 +08:00
|
|
|
uni.$emit("socket-inbox", content);
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-06-22 02:39:03 +08:00
|
|
|
if (!newVal) {
|
|
|
|
|
updateConnect(false);
|
|
|
|
|
websocket.closeWebSocket();
|
|
|
|
|
}
|
2025-06-05 21:32:15 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
deep: false, // 如果 user 是一个对象或数组,建议开启
|
|
|
|
|
immediate: false, // 若想在初始化时立即执行一次回调,可开启。
|
|
|
|
|
}
|
|
|
|
|
);
|
2025-06-22 02:39:03 +08:00
|
|
|
|
|
|
|
|
onShow(() => {
|
|
|
|
|
const token = uni.getStorageSync("token");
|
|
|
|
|
if (user.value.id && token) {
|
|
|
|
|
// 检查 WebSocket 连接状态
|
|
|
|
|
uni.sendSocketMessage({
|
|
|
|
|
data: JSON.stringify({ event: "ping", data: {} }),
|
|
|
|
|
fail: () => {
|
|
|
|
|
// 如果发送失败,说明连接已断开,需要重新连接
|
|
|
|
|
websocket.createWebSocket(token, updateConnect, (content) => {
|
|
|
|
|
uni.$emit("socket-inbox", content);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-04-10 11:11:46 +08:00
|
|
|
</script>
|
|
|
|
|
|
2025-05-07 23:34:15 +08:00
|
|
|
<style>
|
2025-05-08 22:05:53 +08:00
|
|
|
page {
|
|
|
|
|
-webkit-touch-callout: none;
|
|
|
|
|
-webkit-user-select: none;
|
|
|
|
|
user-select: none;
|
2025-06-13 14:22:23 +08:00
|
|
|
background-color: #000;
|
2025-05-08 22:05:53 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-07 23:34:15 +08:00
|
|
|
button {
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
border: none;
|
|
|
|
|
background: none;
|
|
|
|
|
line-height: 1;
|
|
|
|
|
outline: none;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
button::after {
|
|
|
|
|
border: none;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-08 22:05:53 +08:00
|
|
|
.guide-tips {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
}
|
|
|
|
|
.guide-tips > text:first-child {
|
|
|
|
|
color: #fed847;
|
2025-05-07 23:34:15 +08:00
|
|
|
}
|
2025-05-10 16:57:36 +08:00
|
|
|
|
2025-06-08 12:52:49 +08:00
|
|
|
@keyframes fadeIn {
|
|
|
|
|
from {
|
|
|
|
|
transform: translateY(20px);
|
|
|
|
|
opacity: 0;
|
|
|
|
|
}
|
|
|
|
|
to {
|
|
|
|
|
transform: translateY(0);
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.fade-in {
|
|
|
|
|
animation: fadeIn 0.3s ease forwards;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@keyframes fadeOut {
|
|
|
|
|
from {
|
|
|
|
|
transform: translateY(0);
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
to {
|
|
|
|
|
transform: translateY(20px);
|
|
|
|
|
opacity: 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.fade-out {
|
|
|
|
|
animation: fadeOut 0.3s ease forwards;
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-10 16:57:36 +08:00
|
|
|
@keyframes scaleIn {
|
|
|
|
|
from {
|
|
|
|
|
transform: scale(0);
|
|
|
|
|
opacity: 0;
|
|
|
|
|
}
|
|
|
|
|
to {
|
|
|
|
|
transform: scale(1);
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.scale-in {
|
|
|
|
|
animation: scaleIn 0.3s ease-out forwards;
|
|
|
|
|
transform-origin: center center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@keyframes scaleOut {
|
|
|
|
|
from {
|
|
|
|
|
transform: scale(1);
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
to {
|
|
|
|
|
transform: scale(0);
|
|
|
|
|
opacity: 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.scale-out {
|
|
|
|
|
animation: scaleOut 0.3s ease-out forwards;
|
|
|
|
|
transform-origin: center center;
|
|
|
|
|
}
|
2025-06-19 01:55:40 +08:00
|
|
|
|
|
|
|
|
@keyframes rotate {
|
|
|
|
|
from {
|
|
|
|
|
transform: rotate(0deg);
|
|
|
|
|
}
|
|
|
|
|
to {
|
|
|
|
|
transform: rotate(360deg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@keyframes pumpIn {
|
|
|
|
|
from {
|
|
|
|
|
transform: scale(2);
|
|
|
|
|
}
|
|
|
|
|
to {
|
|
|
|
|
transform: scale(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.pump-in {
|
|
|
|
|
animation: pumpIn 0.3s ease-out forwards;
|
|
|
|
|
transform-origin: center center;
|
|
|
|
|
}
|
2025-06-21 21:40:31 +08:00
|
|
|
|
|
|
|
|
.share-canvas {
|
2025-06-21 22:28:42 +08:00
|
|
|
width: 300px;
|
|
|
|
|
height: 530px;
|
2025-06-21 21:40:31 +08:00
|
|
|
position: absolute;
|
|
|
|
|
top: -1000px;
|
|
|
|
|
left: 0;
|
|
|
|
|
}
|
2025-06-22 15:04:10 +08:00
|
|
|
.round-end-tip {
|
|
|
|
|
width: 100%;
|
|
|
|
|
color: #fff;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
.round-end-tip > view:nth-child(2) {
|
|
|
|
|
margin: 15px 0;
|
|
|
|
|
font-size: 24px;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
}
|
|
|
|
|
.round-end-tip > view:nth-child(2) > text:nth-child(2),
|
|
|
|
|
.round-end-tip > view:nth-child(2) > text:nth-child(4) {
|
|
|
|
|
color: #fed847;
|
|
|
|
|
width: 30px;
|
|
|
|
|
text-align: center;
|
|
|
|
|
font-size: 30px;
|
|
|
|
|
}
|
|
|
|
|
.round-end-tip > text:nth-child(3),
|
|
|
|
|
.round-end-tip > text:nth-child(4) {
|
|
|
|
|
color: #fff9;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
margin-bottom: 10px;
|
|
|
|
|
}
|
2025-05-07 23:34:15 +08:00
|
|
|
</style>
|