7 Commits
Author SHA1 Message Date
zhangyi 4bd7599cc0 update:新增ota 2026-09-21 14:56:43 +08:00
zhangyi b060d8f987 update:提交我的设备改版 2026-09-17 18:23:41 +08:00
zhangyi 46cbd37102 Merge branch 'test' into feat-shebei 2026-09-15 18:15:12 +08:00
zhangyi d4d690cb8e update:更新protocol 2026-09-15 18:12:39 +08:00
zhangyi b51813dd33 update:优化设备页 2026-09-15 17:56:36 +08:00
zhangyi a11e7f7532 Merge branch 'fix-audio' into feat-shebei 2026-09-15 15:49:26 +08:00
zhangyi 03fa2f4d48 update:代码备份 2026-09-15 15:39:46 +08:00
81 changed files with 3378 additions and 1167 deletions
+22 -10
View File
@@ -8,9 +8,6 @@
} from "@dcloudio/uni-app"; } from "@dcloudio/uni-app";
import websocket from "@/websocket"; import websocket from "@/websocket";
import matchWebsocket from "@/matchWebsocket"; import matchWebsocket from "@/matchWebsocket";
import {
getDeviceBatteryAPI
} from "@/apis";
import { import {
MESSAGETYPES MESSAGETYPES
} from "@/constants"; } from "@/constants";
@@ -27,7 +24,9 @@
} = storeToRefs(store); } = storeToRefs(store);
const { const {
updateUser, updateUser,
updateOnline, updateDeviceStatus,
setDeviceOnline,
clearDeviceStatus,
showDeviceChargingDialog, showDeviceChargingDialog,
clearSessionState, clearSessionState,
clearDevice clearDevice
@@ -69,13 +68,19 @@
}); });
} }
async function emitUpdateOnline() { function emitUpdateOnline(nextOnline) {
const data = await getDeviceBatteryAPI();
const wasOnline = Boolean(online.value); const wasOnline = Boolean(online.value);
const nextOnline = Boolean(data.online); setDeviceOnline(nextOnline === true);
updateOnline(nextOnline); if (!device.value.deviceId || wasOnline === (nextOnline === true)) return;
if (!device.value.deviceId || wasOnline === nextOnline) return; audioManager.play(nextOnline === true ? "设备已连接" : "设备连接已断开");
audioManager.play(nextOnline ? "设备已连接" : "设备连接已断开"); }
function onDeviceStatusPush(status) {
updateDeviceStatus(status);
}
function onShootSocketDisconnected() {
clearDeviceStatus();
} }
function onDeviceBindInvalid() { function onDeviceBindInvalid() {
@@ -111,6 +116,10 @@
} }
function onShootWsMsg(content) { function onShootWsMsg(content) {
if (content?.event === "/addons/shoot/battery") {
onDeviceStatusPush(content.data);
return;
}
if(content.type === 'shoot-trigger'){ if(content.type === 'shoot-trigger'){
onDeviceShoot() onDeviceShoot()
} }
@@ -122,6 +131,7 @@
void audioManager.warmButton(); void audioManager.warmButton();
uni.$on("update-user", emitUpdateUser); uni.$on("update-user", emitUpdateUser);
uni.$on("update-online", emitUpdateOnline); uni.$on("update-online", emitUpdateOnline);
uni.$on("shoot-socket-disconnected", onShootSocketDisconnected);
uni.$on("session-kicked-out", onSessionKickedOut); uni.$on("session-kicked-out", onSessionKickedOut);
uni.$on("device-bind-invalid", onDeviceBindInvalid); uni.$on("device-bind-invalid", onDeviceBindInvalid);
uni.$on("device-charging", onDeviceCharging); uni.$on("device-charging", onDeviceCharging);
@@ -148,6 +158,7 @@
onHide(() => { onHide(() => {
uni.$off("update-user", emitUpdateUser); uni.$off("update-user", emitUpdateUser);
uni.$off("update-online", emitUpdateOnline); uni.$off("update-online", emitUpdateOnline);
uni.$off("shoot-socket-disconnected", onShootSocketDisconnected);
uni.$off("session-kicked-out", onSessionKickedOut); uni.$off("session-kicked-out", onSessionKickedOut);
uni.$off("device-bind-invalid", onDeviceBindInvalid); uni.$off("device-bind-invalid", onDeviceBindInvalid);
uni.$off("device-charging", onDeviceCharging); uni.$off("device-charging", onDeviceCharging);
@@ -157,6 +168,7 @@
matchWebsocket.closeMatchWebSocket({ matchWebsocket.closeMatchWebSocket({
reason: "app-hide" reason: "app-hide"
}); });
clearDeviceStatus();
websocket.closeWebSocket(); websocket.closeWebSocket();
}); });
</script> </script>
+30 -13
View File
@@ -28,7 +28,8 @@ try {
const ADDONS_BASE_URL = BASE_URL.replace(/\/api\/shoot$/, "/api/shoot"); const ADDONS_BASE_URL = BASE_URL.replace(/\/api\/shoot$/, "/api/shoot");
const API_ROOT_URL = BASE_URL.replace(/\/api\/shoot$/, ""); const API_ROOT_URL = BASE_URL.replace(/\/api\/shoot$/, "");
// 统一处理业务接口请求,包含登录态、业务错误和特定接口空响应兼容。 // 统一处理业务接口请求,包含登录态、业务错误和特定接口空响应兼容。
function request(method, url, data = {}, baseUrl = BASE_URL, successCodes = [0]) { function request(method, url, data = {}, baseUrl = BASE_URL, successCodes = [0], options = {}) {
const {timeout = 10000, showErrorToast = true} = options;
const token = uni.getStorageSync( const token = uni.getStorageSync(
`${uni.getAccountInfoSync().miniProgram.envVersion}_token` `${uni.getAccountInfoSync().miniProgram.envVersion}_token`
); );
@@ -40,8 +41,16 @@ function request(method, url, data = {}, baseUrl = BASE_URL, successCodes = [0])
method, method,
header, header,
data, data,
timeout: 10000, timeout,
success: (res) => { success: (res) => {
if (
url === "/user/hardwareBox/connectWifi" &&
res.statusCode === 200 &&
typeof res.data?.success === "boolean"
) {
resolve(res.data);
return;
}
const acceptsEmptyResponse = [ const acceptsEmptyResponse = [
"/user/hardwareBox/connectWifi", "/user/hardwareBox/connectWifi",
"/user/device/unbindByQrcodeId", "/user/device/unbindByQrcodeId",
@@ -111,10 +120,12 @@ function request(method, url, data = {}, baseUrl = BASE_URL, successCodes = [0])
icon: "none", icon: "none",
}); });
} }
if (showErrorToast) {
uni.showToast({ uni.showToast({
title: message, title: message,
icon: "none", icon: "none",
}); });
}
reject(error); reject(error);
return; return;
} }
@@ -122,7 +133,7 @@ function request(method, url, data = {}, baseUrl = BASE_URL, successCodes = [0])
} }
}, },
fail: (err) => { fail: (err) => {
handleRequestError(err, url); if (showErrorToast) handleRequestError(err, url);
reject(err); reject(err);
}, },
}); });
@@ -281,6 +292,14 @@ export const getMyDevicesAPI = () => {
return request("GET", "/user/device/getBindings"); return request("GET", "/user/device/getBindings");
}; };
export const getDeviceDetailAPI = (deviceId) => {
return request("GET", `/user/device/getDetail?deviceId=${encodeURIComponent(deviceId)}`);
};
export const updateDeviceAliasAPI = (deviceId, alias) => {
return request("POST", "/user/device/updateAlias", {deviceId, alias});
};
export const createPractiseAPI = (arrows, time, target) => { export const createPractiseAPI = (arrows, time, target) => {
return request("POST", "/user/practice/create", { return request("POST", "/user/practice/create", {
shootNumber: arrows, shootNumber: arrows,
@@ -561,13 +580,16 @@ export const laserCloseAPI = async () => {
return request("POST", "/user/device/closeAim"); return request("POST", "/user/device/closeAim");
}; };
export const getDeviceBatteryAPI = async () => {
return request("GET", "/user/device/battery");
};
// 设备连接指定 WiFi,只下发 WiFi 凭证,不触发 OTA 升级。 // 设备连接指定 WiFi,只下发 WiFi 凭证,不触发 OTA 升级。
export const connectDeviceWifiAPI = async (ssid, password) => { export const connectDeviceWifiAPI = async (ssid, password) => {
return request("POST", "/user/hardwareBox/connectWifi", {ssid, password}); return request(
"POST",
"/user/hardwareBox/connectWifi",
{ssid, password},
BASE_URL,
[0],
{timeout: 20000, showErrorToast: false}
);
}; };
// 获取硬件盒子版本信息,用于判断当前设备是否需要 OTA 升级。 // 获取硬件盒子版本信息,用于判断当前设备是否需要 OTA 升级。
@@ -580,11 +602,6 @@ export const sendHardwareBoxUpdateAPI = async (data) => {
return request("POST", "/user/hardwareBox/sendUpdate", data); return request("POST", "/user/hardwareBox/sendUpdate", data);
}; };
// 根据任务 ID 获取硬件盒子 OTA 更新状态。
export const getHardwareBoxTaskStatusAPI = async (taskId) => {
return request("GET", `/user/hardwareBox/taskStatus?taskId=${taskId}`);
};
export const addNoteAPI = async (id, remark) => { export const addNoteAPI = async (id, remark) => {
return request("POST", "/user/score/sheet/remark", {id, remark}); return request("POST", "/user/score/sheet/remark", {id, remark});
}; };
+3 -3
View File
@@ -2,7 +2,7 @@ export const AUDIO_INTERRUPTION_BEGIN_EVENT = "audio-interruption-begin";
export const AUDIO_INTERRUPTION_END_EVENT = "audio-interruption-end"; export const AUDIO_INTERRUPTION_END_EVENT = "audio-interruption-end";
export const RHYTHM_SHOOT_WINDOW_AUDIO_KEY = "请射箭"; export const RHYTHM_SHOOT_WINDOW_AUDIO_KEY = "请射箭";
export const STABILITY_START_AUDIO_KEY = export const STABILITY_START_AUDIO_KEY =
"请在计时结束前能量条达到百分百"; "请在计时结束时能量条达到标记区域";
export const STABILITY_ENERGY_50_AUDIO_KEY = "加油!到达50%啦"; export const STABILITY_ENERGY_50_AUDIO_KEY = "加油!到达50%啦";
export const STABILITY_ENERGY_70_AUDIO_KEY = export const STABILITY_ENERGY_70_AUDIO_KEY =
"70%啦!还差一点,胜利就在眼前"; "70%啦!还差一点,胜利就在眼前";
@@ -12,7 +12,7 @@ const TRAINING_START_AUDIO_KEY_MAP = Object.freeze({
endurance: "请于计时前完成累计环数和箭量", endurance: "请于计时前完成累计环数和箭量",
precision: "请射箭命中高亮区域", precision: "请射箭命中高亮区域",
rhythm: "请在读条推进到标记区间内射箭", rhythm: "请在读条推进到标记区间内射箭",
stability: "请在计时结束前能量条达到百分百", stability: STABILITY_START_AUDIO_KEY,
}); });
export const getTrainingStartAudioKey = (trainingType, fallback = "") => export const getTrainingStartAudioKey = (trainingType, fallback = "") =>
@@ -176,7 +176,7 @@ export const audioFils = {
练习开始: 练习开始:
"https://static.shelingxingqiu.com/attachment/2025-11-14/de88w0lmmt43nnfmoi.mp3", "https://static.shelingxingqiu.com/attachment/2025-11-14/de88w0lmmt43nnfmoi.mp3",
[STABILITY_START_AUDIO_KEY]: [STABILITY_START_AUDIO_KEY]:
"https://static.shelingxingqiu.com/shootaudio/%E8%AF%B7%E5%9C%A8%E8%AE%A1%E6%97%B6%E7%BB%93%E6%9D%9F%E5%89%8D%E8%83%BD%E9%87%8F%E6%9D%A1%E8%BE%BE%E5%88%B0%E7%99%BE%E5%88%86%E7%99%BE.MP3", "https://static.shelingxingqiu.com/shootmini/static/audio0820/%E8%AF%B7%E5%9C%A8%E8%AE%A1%E6%97%B6%E7%BB%93%E6%9D%9F%E6%97%B6%E8%83%BD%E9%87%8F%E6%9D%A1%E8%BE%BE%E5%88%B0%E6%A0%87%E8%AE%B0%E5%8C%BA%E5%9F%9F.MP3",
[STABILITY_ENERGY_50_AUDIO_KEY]: [STABILITY_ENERGY_50_AUDIO_KEY]:
"https://static.shelingxingqiu.com/shootmini/static/audio0820/%E5%8A%A0%E6%B2%B9%EF%BC%81%E5%88%B0%E8%BE%BE50%25%E5%95%A6.MP3", "https://static.shelingxingqiu.com/shootmini/static/audio0820/%E5%8A%A0%E6%B2%B9%EF%BC%81%E5%88%B0%E8%BE%BE50%25%E5%95%A6.MP3",
[STABILITY_ENERGY_70_AUDIO_KEY]: [STABILITY_ENERGY_70_AUDIO_KEY]:
+7
View File
@@ -81,6 +81,13 @@ const props = defineProps({
src="https://static.shelingxingqiu.com/shootmini/static/app-bg9.png" src="https://static.shelingxingqiu.com/shootmini/static/app-bg9.png"
mode="widthFix" mode="widthFix"
/> />
<!-- 我的设备未绑定/绑定成功页面背景 -->
<image
class="bg-image"
v-if="type === 12"
src="../static/device-assets/my-device-unbound-background.png"
mode="widthFix"
/>
<image <image
class="bg-image" class="bg-image"
v-if="type === 10" v-if="type === 10"
+1 -1
View File
@@ -18,7 +18,7 @@ function handleTabClick(index) {
} }
if (index === 2) { if (index === 2) {
uni.navigateTo({ uni.navigateTo({
url: "/pages/device-intro", url: "/pages/device/device-intro",
}); });
} }
} }
+5 -34
View File
@@ -1,44 +1,15 @@
<script setup> <script setup>
import { ref, onMounted, onBeforeUnmount } from "vue"; import useStore from "@/store";
import { getDeviceBatteryAPI } from "@/apis"; import { storeToRefs } from "pinia";
const power = ref(0); const store = useStore();
const timer = ref(null); const { deviceBattery: power } = storeToRefs(store);
let disposed = false;
let requestInFlight = false;
const refreshPower = async () => {
if (disposed || requestInFlight) return;
requestInFlight = true;
try {
const data = await getDeviceBatteryAPI();
if (!disposed) power.value = data.battery;
} catch (_) {
// 电量轮询失败时等待下一轮,避免产生未处理的 Promise 拒绝。
} finally {
requestInFlight = false;
}
};
onMounted(async () => {
await refreshPower();
if (disposed) return;
timer.value = setInterval(() => {
void refreshPower();
}, 1000 * 10);
});
onBeforeUnmount(() => {
disposed = true;
clearInterval(timer.value);
timer.value = null;
});
</script> </script>
<template> <template>
<view class="container"> <view class="container">
<image src="../static/b-power.png" mode="widthFix" /> <image src="../static/b-power.png" mode="widthFix" />
<view>电量{{ power || 1 }}%</view> <view>{{ power === null ? "电量--" : `电量${power}%` }}</view>
</view> </view>
</template> </template>
+1 -1
View File
@@ -124,7 +124,7 @@ const cancelMatching = async () => {
const goCalibration = async () => { const goCalibration = async () => {
await laserAimAPI(); await laserAimAPI();
uni.navigateTo({ uni.navigateTo({
url: "/pages/calibration", url: "/pages/device/calibration",
}); });
}; };
</script> </script>
+37
View File
@@ -1,4 +1,6 @@
<script setup> <script setup>
import IconButton from "./IconButton.vue";
const props = defineProps({ const props = defineProps({
show: { show: {
type: Boolean, type: Boolean,
@@ -28,6 +30,14 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: true, default: true,
}, },
confirmDisabled: {
type: Boolean,
default: false,
},
showClose: {
type: Boolean,
default: false,
},
onCancel: { onCancel: {
type: Function, type: Function,
default: null, default: null,
@@ -36,6 +46,10 @@ const props = defineProps({
type: Function, type: Function,
default: null, default: null,
}, },
onClose: {
type: Function,
default: null,
},
}); });
const handleCancel = () => { const handleCancel = () => {
@@ -43,8 +57,13 @@ const handleCancel = () => {
}; };
const handleConfirm = () => { const handleConfirm = () => {
if (props.confirmDisabled) return;
props.onConfirm?.(); props.onConfirm?.();
}; };
const handleClose = () => {
props.onClose?.();
};
</script> </script>
<template> <template>
@@ -89,6 +108,7 @@ const handleConfirm = () => {
<view <view
v-if="showConfirm" v-if="showConfirm"
class="dialog-button confirm" class="dialog-button confirm"
:class="{ disabled: confirmDisabled }"
@click="handleConfirm" @click="handleConfirm"
> >
<text>{{ confirmText }}</text> <text>{{ confirmText }}</text>
@@ -96,6 +116,13 @@ const handleConfirm = () => {
</view> </view>
</view> </view>
<view v-if="showClose" class="dialog-close">
<IconButton
src="../static/close-gold-outline.png"
:width="30"
:onClick="handleClose"
/>
</view>
</view> </view>
</view> </view>
</template> </template>
@@ -108,6 +135,7 @@ const handleConfirm = () => {
top: 0; top: 0;
left: 0; left: 0;
background-color: rgba(0, 0, 0, 0.62); background-color: rgba(0, 0, 0, 0.62);
flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
z-index: 999; z-index: 999;
@@ -116,6 +144,7 @@ const handleConfirm = () => {
.modal-wrap { .modal-wrap {
position: relative; position: relative;
display: flex; display: flex;
flex-direction: column;
width: 549rpx; width: 549rpx;
min-height: 318rpx;; min-height: 318rpx;;
padding-top: 168rpx; padding-top: 168rpx;
@@ -222,6 +251,14 @@ const handleConfirm = () => {
background-color: #ffda3f; background-color: #ffda3f;
} }
.dialog-button.confirm.disabled {
opacity: 0.62;
}
.dialog-close {
margin-top: 28rpx;
}
@keyframes rotateLight { @keyframes rotateLight {
from { from {
transform: translateX(-50%) rotate(0deg); transform: translateX(-50%) rotate(0deg);
+43 -23
View File
@@ -1,10 +1,11 @@
<script setup> <script setup>
import { computed } from "vue"; import { computed } from "vue";
import { getDeviceBatteryAPI } from "@/apis"; import useStore from "@/store";
import { storeToRefs } from "pinia";
const OTA_MIN_BATTERY = 50;
const OTA_LOW_BATTERY_TEXT = "电量不足 50%,暂不支持 OTA 升级";
const OTA_OFFLINE_TEXT = "请先开启智能弓"; const OTA_OFFLINE_TEXT = "请先开启智能弓";
const store = useStore();
const { deviceStatus } = storeToRefs(store);
const props = defineProps({ const props = defineProps({
visible: { visible: {
@@ -23,6 +24,10 @@ const props = defineProps({
type: Number, type: Number,
default: 40, default: 40,
}, },
phase: {
type: String,
default: "",
},
// 副标题:如“新版本将优化智能弓体验” // 副标题:如“新版本将优化智能弓体验”
description: { description: {
type: String, type: String,
@@ -47,30 +52,24 @@ const isSuccess = computed(() => props.state === "update_success");
const isFailure = computed(() => props.state === "update_failure"); const isFailure = computed(() => props.state === "update_failure");
// Clamp progress to keep the progress bar width within its container. // Clamp progress to keep the progress bar width within its container.
const progressValue = computed(() => Math.min(100, Math.max(0, Number(props.progress) || 0))); const progressValue = computed(() => Math.min(100, Math.max(0, Number(props.progress) || 0)));
const progressPhaseText = computed(() => {
const phaseText = {
started: "正在准备固件更新",
downloading: "正在下载固件",
installing: "正在安装固件",
};
return phaseText[props.phase] || "正在进行固件更新";
});
// 点击立即更新前先校验设备在线状态,再校验设备电量。 // 点击立即更新前先校验设备在线状态。
const handleUpdateClick = async () => { const handleUpdateClick = () => {
try { if (deviceStatus.value?.online !== true) {
const deviceStatus = await getDeviceBatteryAPI();
if (deviceStatus?.online !== true) {
uni.showToast({ uni.showToast({
title: OTA_OFFLINE_TEXT, title: OTA_OFFLINE_TEXT,
icon: "none", icon: "none",
}); });
return; return;
} }
if (Number(deviceStatus?.battery) <= OTA_MIN_BATTERY) {
uni.showToast({
title: OTA_LOW_BATTERY_TEXT,
icon: "none",
});
return;
}
} catch (err) {
emit("update");
return;
}
emit("update"); emit("update");
}; };
</script> </script>
@@ -140,10 +139,10 @@ const handleUpdateClick = async () => {
<!-- 更新成功:图片左边距 34rpx,文案左边距 44rpx,按钮浮动底部居中 --> <!-- 更新成功:图片左边距 34rpx,文案左边距 44rpx,按钮浮动底部居中 -->
<block v-else-if="isSuccess"> <block v-else-if="isSuccess">
<image src="https://static.shelingxingqiu.com/shootmini/static/ota/update-ok.png" mode="aspectFit" class="result-title-img" style="width: 220rpx; height: 62rpx;" /> <image src="https://static.shelingxingqiu.com/shootmini/static/ota/update-ok.png" mode="aspectFit" class="result-title-img" style="width: 220rpx; height: 62rpx;" />
<text class="dialog-desc">请关机并重启智能弓</text> <text class="dialog-desc">固件更新已完成</text>
<view class="btn-group-result"> <view class="btn-group-result">
<view class="primary-btn" @click="emit('done')"> <view class="primary-btn" @click="emit('done')">
<text class="primary-btn-text">完成</text> <text class="primary-btn-text">关闭</text>
</view> </view>
</view> </view>
</block> </block>
@@ -152,6 +151,10 @@ const handleUpdateClick = async () => {
<block v-else-if="isProgress"> <block v-else-if="isProgress">
<image src="https://static.shelingxingqiu.com/shootmini/static/ota/update_progress.png" mode="aspectFit" class="result-title-img" style="width: 220rpx; height: 62rpx;" /> <image src="https://static.shelingxingqiu.com/shootmini/static/ota/update_progress.png" mode="aspectFit" class="result-title-img" style="width: 220rpx; height: 62rpx;" />
<view class="progress-wrap"> <view class="progress-wrap">
<view class="progress-meta">
<text class="progress-phase">{{ progressPhaseText }}</text>
<text class="progress-value">{{ Math.floor(progressValue) }}%</text>
</view>
<view class="progress-track"> <view class="progress-track">
<view class="progress-fill" :style="{ width: `${progressValue}%` }"></view> <view class="progress-fill" :style="{ width: `${progressValue}%` }"></view>
</view> </view>
@@ -404,9 +407,26 @@ const handleUpdateClick = async () => {
} }
.progress-wrap { .progress-wrap {
width: 394rpx; width: 394rpx;
margin-top: 40rpx; margin-top: 28rpx;
margin-left: 44rpx; margin-left: 44rpx;
} }
.progress-meta {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16rpx;
color: #ffffff;
font-size: 24rpx;
line-height: 34rpx;
}
.progress-phase {
flex: 1;
}
.progress-value {
flex-shrink: 0;
margin-left: 16rpx;
color: #fed847;
}
.progress-track { .progress-track {
width: 100%; width: 100%;
height: 18rpx; height: 18rpx;
+1 -4
View File
@@ -12,12 +12,11 @@ import {
getHomeData, getHomeData,
getPhoneNumberAPI, getPhoneNumberAPI,
getPhoneNumberAPIv2, getPhoneNumberAPIv2,
getDeviceBatteryAPI,
} from "@/apis"; } from "@/apis";
import useStore from "@/store"; import useStore from "@/store";
const store = useStore(); const store = useStore();
const { updateUser, updateDevice, updateOnline, clearDevice } = store; const { updateUser, updateDevice, clearDevice } = store;
const props = defineProps({ const props = defineProps({
show: { show: {
@@ -125,8 +124,6 @@ async function doLogin() {
devices.bindings[0].deviceId, devices.bindings[0].deviceId,
devices.bindings[0].deviceName devices.bindings[0].deviceName
); );
const data = await getDeviceBatteryAPI();
updateOnline(data.online);
} else { } else {
clearDevice(); clearDevice();
} }
+24 -15
View File
@@ -21,9 +21,6 @@
{ {
"path": "pages/audio-test" "path": "pages/audio-test"
}, },
{
"path": "pages/calibration"
},
{ {
"path": "pages/about-us" "path": "pages/about-us"
}, },
@@ -60,12 +57,6 @@
{ {
"path": "pages/match-page" "path": "pages/match-page"
}, },
{
"path": "pages/my-device"
},
{
"path": "pages/device-intro"
},
{ {
"path": "pages/user" "path": "pages/user"
}, },
@@ -107,12 +98,6 @@
}, },
{ {
"path": "pages/mine-bow-data" "path": "pages/mine-bow-data"
},
{
"path": "pages/ota-wifi",
"style": {
"navigationStyle": "custom"
}
} }
], ],
"globalStyle": { "globalStyle": {
@@ -159,6 +144,30 @@
{ {
"root": "pages/device", "root": "pages/device",
"pages": [ "pages": [
{
"path": "my-device"
},
{
"path": "device-qrcode"
},
{
"path": "device-bind-success"
},
{
"path": "device-bind-failure"
},
{
"path": "device-intro"
},
{
"path": "ota-wifi",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "calibration"
},
{ {
"path": "unbind-device" "path": "unbind-device"
} }
@@ -0,0 +1,86 @@
import { bindDeviceAPIV2 } from "@/apis";
export function useDeviceBinding({
token,
confirmBindTip,
binding,
updateDevice,
deviceDetails,
}) {
const showBindFailurePage = () => {
uni.hideToast();
uni.navigateTo({
url: "/pages/device/device-bind-failure",
fail: (error) => {
console.error("打开绑定失败页失败", error);
uni.showToast({ title: "二维码不正确,请重新扫码", icon: "none" });
},
});
};
const handleScan = () => {
uni.scanCode({
onlyFromCamera: true,
scanType: ["qrCode"],
success: (result) => {
if (!result?.result) {
showBindFailurePage();
return;
}
token.value = result.result;
confirmBindTip.value = true;
},
fail: (error) => {
const message = String(error?.errMsg || error?.message || "");
if (/cancel|取消/i.test(message)) return;
showBindFailurePage();
},
});
};
const confirmBind = async () => {
if (!token.value || binding.value) return;
binding.value = true;
try {
const result = await bindDeviceAPIV2(token.value);
confirmBindTip.value = false;
if (result?.binded) {
uni.showToast({
title: "设备已绑定其他账号,请解绑后再绑定",
icon: "none",
});
return;
}
const deviceId = String(result?.deviceId || "").trim();
const deviceName = String(result?.name || result?.deviceName || "").trim();
if (!deviceId || !deviceName) {
confirmBindTip.value = false;
token.value = "";
showBindFailurePage();
return;
}
const applyBoundDevice = () => {
updateDevice(deviceId, deviceName);
deviceDetails.value = result || {};
};
uni.navigateTo({
url: `/pages/device/device-bind-success?deviceId=${encodeURIComponent(deviceId)}`,
success: applyBoundDevice,
fail: (navigationError) => {
applyBoundDevice();
console.error("打开绑定成功页失败", navigationError);
uni.showToast({ title: "绑定成功,请返回查看设备", icon: "none" });
},
});
} catch (error) {
console.error("绑定设备失败", error);
confirmBindTip.value = false;
token.value = "";
showBindFailurePage();
} finally {
binding.value = false;
}
};
return { confirmBind, handleScan, showBindFailurePage };
}
@@ -0,0 +1,207 @@
import { computed, ref } from "vue";
import {
getDeviceDetailAPI,
getMyDevicesAPI,
unbindDeviceAPI,
} from "@/apis";
export const DEVICE_NAME_STORAGE_KEY = "device_name_overrides";
export function useDeviceStatus({
user,
device,
deviceStatus,
online,
updateDevice,
clearDevice,
unbindDialogVisible,
}) {
const deviceDetails = ref({});
let deviceDetailRequestVersion = 0;
const isDeviceOnline = computed(
() => deviceStatus.value.online === true || online.value === true
);
const isDeviceCharging = computed(
() => isDeviceOnline.value && deviceStatus.value.charging === true
);
const statusText = computed(() => {
if (!isDeviceOnline.value) return "未连接";
return isDeviceCharging.value ? "已连接(充电中)" : "已连接";
});
const statusClass = computed(() =>
isDeviceOnline.value ? "device-status--online" : "device-status--offline"
);
const battery = computed(() => {
const rawValue = deviceStatus.value.battery ?? deviceStatus.value.power;
if (rawValue === null || rawValue === undefined || rawValue === "") return null;
const value = Number(rawValue);
return Number.isFinite(value) ? Math.min(100, Math.max(0, value)) : null;
});
const batteryText = computed(() =>
battery.value === null ? "暂无数据" : `${battery.value}%`
);
const onlineDurationText = computed(() => {
const rawDuration = deviceStatus.value.onlineDuration;
if (rawDuration == null || String(rawDuration).trim() === "") return "--";
const seconds = Number(rawDuration);
if (!Number.isFinite(seconds) || seconds < 0) return "--";
// WS 推送秒数,页面按完整分钟展示累计使用时间。
const totalMinutes = Math.floor(seconds / 60);
const hours = Math.floor(totalMinutes / 60);
const minutes = totalMinutes % 60;
return hours > 0 ? `${hours}小时${minutes}分钟` : `${minutes}分钟`;
});
const networkType = computed(() =>
String(deviceStatus.value.netType ?? "").trim().toLowerCase()
);
const networkText = computed(() => {
const netType = networkType.value;
if (netType === "wifi") return "WiFi";
if (netType === "4g") return "4G";
return isDeviceOnline.value ? "在线" : "未连接";
});
const maskedDeviceId = computed(() => {
const id = String(device.value.deviceId || "");
if (!id) return "暂无设备编号";
if (id.length <= 3) return id;
return `${"*".repeat(Math.min(5, id.length - 3))}${id.slice(-3)}`;
});
const deviceRows = computed(() => [
{ label: "设备型号", value: deviceDetails.value.model || "射灵智能弓" },
{ label: "当前电量", value: batteryText.value },
{ label: "连接方式", value: networkText.value },
{ label: "设备编号", value: maskedDeviceId.value },
]);
const getDeviceNameOverrides = () => {
const value = uni.getStorageSync(DEVICE_NAME_STORAGE_KEY);
return value && typeof value === "object" ? value : {};
};
const refreshDeviceDetails = async () => {
const deviceId = device.value.deviceId;
if (!deviceId) return;
const requestVersion = ++deviceDetailRequestVersion;
try {
const detailResponse = await getDeviceDetailAPI(deviceId);
const detail = detailResponse?.detail || detailResponse?.data?.detail;
if (
!detail ||
typeof detail !== "object" ||
requestVersion !== deviceDetailRequestVersion ||
device.value.deviceId !== deviceId
) {
return;
}
deviceDetails.value = {
...deviceDetails.value,
...detail,
deviceModelName: detail.deviceModelName ?? "",
bindTime: String(
detail.bindTime ?? deviceDetails.value.bindTime ?? ""
).trim(),
qrCodeUrl: String(
detail.qrCodeUrl ?? deviceDetails.value.qrCodeUrl ?? ""
).trim(),
};
} catch (error) {
// 实时刷新失败时保留当前页面数据,等待下次通知或页面重新显示。
console.log("刷新设备详情失败", error);
}
};
const syncDeviceBinding = async () => {
if (!user.value.id) return;
try {
const devices = await getMyDevicesAPI();
if (Array.isArray(devices?.bindings) && devices.bindings.length > 0) {
const currentDevice = devices.bindings[0];
const nameOverrides = getDeviceNameOverrides();
// 二维码和绑定时间仅取详情接口,绑定列表不能作为这两项的回退数据。
let latestDevice = {
...currentDevice,
deviceModelName: "",
bindTime: "",
qrCodeUrl: "",
};
try {
const detailResponse = await getDeviceDetailAPI(currentDevice.deviceId);
const detail = detailResponse?.detail || detailResponse?.data?.detail;
if (detail && typeof detail === "object") {
latestDevice = {
...currentDevice,
...detail,
deviceModelName: detail.deviceModelName ?? "",
bindTime: String(detail.bindTime ?? "").trim(),
qrCodeUrl: String(detail.qrCodeUrl ?? "").trim(),
deviceName:
detail.deviceAlias || detail.deviceName || currentDevice.deviceName,
};
}
} catch (error) {
// 详情接口失败时保留绑定关系,二维码和绑定时间仍保持为空。
console.log("获取设备详情失败", error);
}
deviceDetails.value = latestDevice;
updateDevice(
latestDevice.deviceId,
nameOverrides[latestDevice.deviceId] ||
latestDevice.deviceAlias ||
latestDevice.deviceName ||
latestDevice.name ||
"我的智能弓"
);
return;
}
clearDevice();
deviceDetailRequestVersion += 1;
deviceDetails.value = {};
} catch (error) {
console.log("同步设备绑定失败", error);
}
};
const unbindDevice = async () => {
if (!device.value.deviceId) return;
try {
await unbindDeviceAPI(device.value.deviceId);
uni.setStorageSync("calibration", false);
clearDevice();
deviceDetailRequestVersion += 1;
deviceDetails.value = {};
unbindDialogVisible.value = false;
uni.showToast({ title: "解绑成功", icon: "success" });
} catch (error) {
console.error("解绑设备失败", error);
if (error?.type === "DEVICE_BIND_INVALID") {
clearDevice();
unbindDialogVisible.value = false;
}
}
};
return {
batteryText,
deviceDetails,
deviceRows,
getDeviceNameOverrides,
isDeviceCharging,
isDeviceOnline,
maskedDeviceId,
networkText,
networkType,
onlineDurationText,
refreshDeviceDetails,
statusClass,
statusText,
syncDeviceBinding,
unbindDevice,
};
}
@@ -0,0 +1,188 @@
import { computed, onUnmounted, ref } from "vue";
import { sendHardwareBoxUpdateAPI } from "@/apis";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const OTA_PROGRESS_EVENT = "/addons/shoot/otaProgress";
const OTA_RESULT_EVENT = "/addons/shoot/otaResult";
const UPDATE_TIMEOUT = 10 * 60 * 1000;
const phaseTextMap = {
started: "正在准备固件更新",
downloading: "正在下载固件",
installing: "正在安装固件",
};
export const useOtaUpdate = () => {
const store = useStore();
const { device } = storeToRefs(store);
const updating = ref(false);
const progress = ref(0);
const phase = ref("started");
const resultVisible = ref(false);
const resultStatus = ref("");
const resultReason = ref("");
let updateRunId = 0;
let targetVersion = "";
let timeoutTimer = null;
let successCallback = null;
let socketListening = false;
const phaseText = computed(
() => phaseTextMap[phase.value] || "正在进行固件更新"
);
const resultTitle = computed(() =>
resultStatus.value === "success" ? "固件更新完成" : "固件更新失败"
);
const resultContent = computed(() => {
if (resultStatus.value === "success") return "固件更新已完成";
return resultReason.value || "更新失败,请检查设备及网络后重试";
});
const clearTimers = () => {
clearTimeout(timeoutTimer);
timeoutTimer = null;
};
const stopSocketListening = () => {
if (!socketListening) return;
uni.$off("socket-inbox", handleSocketMessage);
socketListening = false;
};
const resetActiveUpdate = () => {
clearTimers();
stopSocketListening();
successCallback = null;
};
const finishUpdate = (status, reason = "", runId = updateRunId) => {
if (runId !== updateRunId || !updating.value) return;
const onSuccess = successCallback;
resetActiveUpdate();
updating.value = false;
resultStatus.value = status;
resultReason.value = reason;
if (status === "success") {
progress.value = 100;
phase.value = "installing";
onSuccess?.();
}
resultVisible.value = true;
};
const isCurrentUpdateMessage = (data) => {
const messageDeviceId = String(data?.deviceId || "");
const currentDeviceId = String(device.value?.deviceId || "");
if (messageDeviceId && currentDeviceId && messageDeviceId !== currentDeviceId) {
return false;
}
const messageVersion = String(data?.versionNumber || "");
return !messageVersion || !targetVersion || messageVersion === targetVersion;
};
function handleSocketMessage(message) {
if (!updating.value || Number(message?.code ?? 0) !== 0) return;
if (![OTA_PROGRESS_EVENT, OTA_RESULT_EVENT].includes(message?.event)) return;
if (!isCurrentUpdateMessage(message.data)) return;
if (message.event === OTA_PROGRESS_EVENT) {
const nextProgress = Math.min(
100,
Math.max(0, Number(message.data?.progress) || 0)
);
progress.value = Math.max(progress.value, nextProgress);
if (phaseTextMap[message.data?.phase]) {
phase.value = message.data.phase;
}
return;
}
if (message.data?.status === "success") {
finishUpdate("success");
return;
}
if (message.data?.status === "failed") {
finishUpdate("failed", message.data?.reason || "");
}
}
const startSocketListening = () => {
if (socketListening) return;
uni.$on("socket-inbox", handleSocketMessage);
socketListening = true;
};
const startUpdate = async ({
versionNumber,
resourceUrl,
wifiSsid = "",
wifiPassword = "",
onSuccess,
}) => {
if (updating.value) return false;
updateRunId += 1;
const runId = updateRunId;
targetVersion = String(versionNumber || "");
successCallback = onSuccess || null;
resultVisible.value = false;
resultStatus.value = "";
resultReason.value = "";
progress.value = 0;
phase.value = "started";
updating.value = true;
startSocketListening();
timeoutTimer = setTimeout(() => {
finishUpdate("failed", "固件更新超时,请稍后重试", runId);
}, UPDATE_TIMEOUT);
try {
const updateResult = await sendHardwareBoxUpdateAPI({
versionNumber: targetVersion,
wifiSsid,
wifiPassword,
resourceUrl,
});
if (runId !== updateRunId || !updating.value) return false;
if (!updateResult?.taskId) {
finishUpdate("failed", "固件更新任务创建失败,请稍后重试", runId);
return false;
}
return true;
} catch (error) {
if (runId === updateRunId) {
finishUpdate(
"failed",
error?.message || "固件更新请求失败,请稍后重试",
runId
);
}
return false;
}
};
const closeResult = () => {
resultVisible.value = false;
};
onUnmounted(() => {
updateRunId += 1;
resetActiveUpdate();
});
return {
updating,
progress,
phase,
phaseText,
resultVisible,
resultStatus,
resultTitle,
resultContent,
startUpdate,
closeResult,
};
};
+156
View File
@@ -0,0 +1,156 @@
<script setup>
import Container from "@/components/Container.vue";
// 失败页由设备页进入,返回时优先回到上一页;页面栈异常时兜底回到设备页。
const goBackToDevicePage = () => {
const pages = getCurrentPages();
if (pages.length > 1) {
uni.navigateBack({ delta: 1 });
return;
}
uni.redirectTo({ url: "/pages/device/my-device" });
};
// 返回设备页后沿用原有扫码绑定流程,不在结果页重复处理二维码数据。
const retryScan = () => {
const pages = getCurrentPages();
if (pages.length > 1) {
uni.navigateBack({
delta: 1,
success: () => uni.$emit("device-bind-retry-scan"),
});
return;
}
uni.redirectTo({ url: "/pages/device/my-device?retryScan=1" });
};
</script>
<template>
<view class="device-bind-failure-page">
<Container
:bgType="12"
bgColor="transparent"
:onBack="goBackToDevicePage"
headerClass="bind-failure-header"
:scroll="false"
:usePageScroll="true"
>
<view class="bind-failure-page">
<view class="bind-failure-scene">
<view class="bind-failure-hero-wrap">
<view class="bind-failure-hero-shadow"></view>
<image
class="bind-failure-hero"
src="../../static/device-assets/device-bind-failure-hero.png"
mode="aspectFit"
/>
</view>
<view class="bind-failure-message">
<text>二维码不正确,</text>
<text>仅支持扫描射灵智能弓箭的设备二维码。</text>
</view>
<view class="bind-failure-retry" @click="$clickSound(retryScan)">
<text>重新扫码</text>
</view>
</view>
</view>
</Container>
</view>
</template>
<style scoped lang="scss">
.device-bind-failure-page {
position: relative;
min-height: 100vh;
background: transparent;
}
.bind-failure-header {
position: relative;
z-index: 20;
pointer-events: auto;
}
/* 与绑定成功页共用固定画布,页面内的视觉尺寸全部按 375 宽设计稿换算为 rpx。 */
.bind-failure-page {
position: fixed;
top: 0;
left: 0;
z-index: 1;
width: 100%;
height: 100vh;
overflow: hidden;
pointer-events: none;
}
.bind-failure-scene {
position: relative;
width: 100%;
height: 100%;
}
.bind-failure-hero-wrap,
.bind-failure-message,
.bind-failure-retry {
position: absolute;
}
.bind-failure-hero-wrap {
top: 568rpx;
left: 244rpx;
width: 260rpx;
height: 222rpx;
}
.bind-failure-hero-shadow {
position: absolute;
left: 22rpx;
bottom: 0;
width: 238rpx;
height: 40rpx;
border-radius: 50%;
background: rgba(0, 0, 0, 0.3);
}
.bind-failure-hero {
position: absolute;
top: 0;
left: 0;
width: 260rpx;
height: 222rpx;
}
.bind-failure-message {
top: 824rpx;
left: 122rpx;
display: flex;
width: 504rpx;
min-height: 80rpx;
flex-direction: column;
align-items: center;
color: #ffffff;
font-family: PingFang SC-Regular;
font-size: 28rpx;
font-weight: normal;
line-height: 40rpx;
text-align: center;
white-space: nowrap;
}
.bind-failure-retry {
top: 960rpx;
left: 195rpx;
display: flex;
width: 360rpx;
height: 70rpx;
box-sizing: border-box;
align-items: center;
justify-content: center;
border: 2rpx solid #ffd947;
border-radius: 78rpx;
color: #ffd947;
font-size: 26rpx;
line-height: 26rpx;
pointer-events: auto;
}
</style>
+248
View File
@@ -0,0 +1,248 @@
<script setup>
import { computed, ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import { getDeviceDetailAPI, getHomeData } from "@/apis";
const bindResult = ref({
isFirstBind: false,
expireDate: "",
});
const bindSuccessHero = computed(() =>
bindResult.value.isFirstBind
? "../../static/device-assets/device-bind-success-hero-first.png"
: "../../static/device-assets/device-bind-success-hero-nonfirst.png"
);
const bindRewardExpireDate = computed(() => bindResult.value.expireDate);
// 与会员页使用相同的到期时间格式,设备详情接口本身不提供会员有效期。
const formatVipDate = (value) => {
if (!value) return "";
const numericValue = Number(value);
const timestamp = Number.isNaN(numericValue)
? new Date(value).getTime()
: numericValue < 1000000000000
? numericValue * 1000
: numericValue;
const date = new Date(timestamp);
if (Number.isNaN(date.getTime())) return "";
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
};
const loadBindResult = async (deviceId) => {
if (!deviceId) return;
try {
const data = await getDeviceDetailAPI(deviceId);
if (data?.detail?.isFirstBind !== true) return;
bindResult.value.isFirstBind = true;
try {
const homeData = await getHomeData();
bindResult.value.expireDate = formatVipDate(
homeData?.user?.normalVipExpiredAt
);
} catch (error) {
console.error("获取赠送会员有效期失败", error);
}
} catch (error) {
console.error("获取设备详情失败", error);
}
};
const toFirstTryPage = () => {
uni.navigateTo({ url: "/pages/first-try" });
};
// 成功页由设备页 navigateTo 进入,优先返回上一页;页面栈异常时兜底回到设备页。
const goBackToDevicePage = () => {
const pages = getCurrentPages();
if (pages.length > 1) {
uni.navigateBack({ delta: 1 });
return;
}
uni.redirectTo({ url: "/pages/device/my-device" });
};
onLoad((options = {}) => {
bindResult.value = {
isFirstBind: false,
expireDate: "",
};
void loadBindResult(options.deviceId);
});
</script>
<template>
<view class="device-bind-success-page">
<Container
:bgType="12"
bgColor="transparent"
:onBack="goBackToDevicePage"
headerClass="bind-success-header"
:scroll="false"
:usePageScroll="true"
>
<view class="bind-success-page">
<view
class="bind-success-scene"
:class="{ 'bind-success-scene--first': bindResult.isFirstBind }"
>
<image
class="bind-success-confetti"
src="../../static/device-assets/device-bind-success-confetti.png"
mode="aspectFit"
/>
<image class="bind-success-hero" :src="bindSuccessHero" mode="aspectFit" />
<image
class="bind-success-title-image"
src="../../static/device-assets/device-bind-success-title.png"
mode="aspectFit"
/>
<view v-if="bindResult.isFirstBind" class="bind-reward-card">
<image
class="bind-reward-gift"
src="../../static/device-assets/device-bind-success-reward-gift.png"
mode="aspectFit"
/>
<text class="bind-reward-text">
新设备首次绑定礼包:
<text class="bind-reward-highlight">6个月射灵会员</text>
已自动发放至本账号<text v-if="bindRewardExpireDate">,有效期{{ bindRewardExpireDate }}</text>。
</text>
</view>
<view class="bind-success-tutorial" @click="$clickSound(toFirstTryPage)">
<text>立即查看新手教程</text>
</view>
</view>
</view>
</Container>
</view>
</template>
<style scoped lang="scss">
.device-bind-success-page {
position: relative;
min-height: 100vh;
background: transparent;
}
.bind-success-header {
position: relative;
z-index: 20;
pointer-events: auto;
}
/* 绑定结果页使用固定画布,背景和前景素材按蓝湖 375 x 812 画布定位。 */
.bind-success-page {
position: fixed;
top: 0;
left: 0;
z-index: 1;
width: 100%;
height: 100vh;
overflow: hidden;
pointer-events: none;
}
.bind-success-scene {
position: relative;
width: 100%;
height: 100%;
}
.bind-success-confetti,
.bind-success-hero,
.bind-success-title-image,
.bind-reward-card,
.bind-success-tutorial {
position: absolute;
}
.bind-success-confetti {
top: 488rpx;
left: 78rpx;
width: 588rpx;
height: 508rpx;
}
.bind-success-hero {
top: 568rpx;
left: 244rpx;
width: 260rpx;
height: 222rpx;
}
.bind-success-scene--first .bind-success-confetti {
top: 314rpx;
}
.bind-success-scene--first .bind-success-hero {
top: 400rpx;
}
.bind-success-title-image {
top: 828rpx;
left: 216rpx;
width: 316rpx;
height: 70rpx;
}
.bind-success-scene--first .bind-success-title-image {
top: 660rpx;
}
.bind-reward-card {
top: 768rpx;
left: 170rpx;
width: 508rpx;
height: 152rpx;
box-sizing: border-box;
padding: 16rpx 16rpx 16rpx 90rpx;
border-radius: 16rpx 64rpx 16rpx 64rpx;
background: rgba(0, 0, 0, 0.6);
}
.bind-reward-gift {
position: absolute;
top: -18rpx;
left: -100rpx;
width: 178rpx;
height: 176rpx;
}
.bind-reward-text {
display: block;
width: 380rpx;
height: 120rpx;
color: #ffffff;
font-family: PingFang SC-Regular;
font-size: 28rpx;
font-weight: normal;
line-height: 40rpx;
}
.bind-reward-highlight {
color: #ffd947;
}
.bind-success-tutorial {
top: 960rpx;
left: 195rpx;
display: flex;
width: 360rpx;
height: 70rpx;
box-sizing: border-box;
align-items: center;
justify-content: center;
border: 2rpx solid #ffd947;
border-radius: 78rpx;
color: #ffd947;
font-size: 26rpx;
line-height: 26rpx;
pointer-events: auto;
}
</style>
@@ -38,7 +38,7 @@ const onScrollView = (e) => {
mode="widthFix" mode="widthFix"
/> />
<navigator open-type="navigateBack"> <navigator open-type="navigateBack">
<image class="header-back" src="../static/back.png" mode="widthFix" /> <image class="header-back" src="../../static/back.png" mode="widthFix" />
</navigator> </navigator>
<text <text
:style="{ opacity: addBg ? 1 : 0, color: '#fff', fontWeight: 'bold' }" :style="{ opacity: addBg ? 1 : 0, color: '#fff', fontWeight: 'bold' }"
+192
View File
@@ -0,0 +1,192 @@
<script setup>
import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import { getDeviceDetailAPI } from "@/apis";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { device } = storeToRefs(store);
const deviceId = ref("");
const qrImageUrl = ref("");
const qrSaved = ref(false);
const loading = ref(true);
const loadQrCode = async () => {
if (!deviceId.value) {
loading.value = false;
return;
}
try {
const response = await getDeviceDetailAPI(deviceId.value);
const detail = response?.detail || response?.data?.detail;
qrImageUrl.value = String(detail?.qrCodeUrl ?? "").trim();
} catch (error) {
console.error("获取设备二维码失败", error);
qrImageUrl.value = "";
} finally {
loading.value = false;
}
};
const saveQrCode = async () => {
if (!qrImageUrl.value) return;
let filePath = qrImageUrl.value;
try {
if (/^https?:\/\//.test(filePath)) {
filePath = await new Promise((resolve, reject) => {
uni.downloadFile({
url: filePath,
success: (result) =>
result.statusCode === 200
? resolve(result.tempFilePath)
: reject(new Error("二维码下载失败")),
fail: reject,
});
});
}
await new Promise((resolve, reject) => {
uni.saveImageToPhotosAlbum({ success: resolve, fail: reject, filePath });
});
qrSaved.value = true;
uni.showToast({ title: "已保存至相册", icon: "success" });
} catch (error) {
uni.showToast({ title: "请长按二维码保存", icon: "none" });
}
};
onLoad((options = {}) => {
try {
deviceId.value = decodeURIComponent(options.deviceId || "") || device.value.deviceId || "";
} catch (error) {
deviceId.value = device.value.deviceId || "";
}
void loadQrCode();
});
</script>
<template>
<Container :bgType="12" :scroll="false">
<view class="qr-page">
<view class="qr-corner qr-corner--top"></view>
<view class="qr-corner qr-corner--bottom"></view>
<view class="qr-canvas">
<text v-if="loading" class="qr-empty">二维码加载中...</text>
<template v-else-if="qrImageUrl">
<image class="qr-image" :src="qrImageUrl" mode="aspectFit" show-menu-by-longpress />
<text v-if="qrSaved" class="qr-device-id">设备ID:{{ deviceId }}</text>
<view v-else class="qr-save-button" @click="saveQrCode">
<text>保存至相册</text>
</view>
<text class="qr-description">
该二维码为当前绑定弓箭的二维码,你可以截图保存到相册,以便当二维码丢失或不在身边时,可以扫描二维码进行设备绑定。
</text>
<text class="qr-note">注:解除绑定后将无法查看该二维码。</text>
</template>
<text v-else class="qr-empty">暂无设备二维码</text>
</view>
</view>
</Container>
</template>
<style scoped>
.qr-page {
position: relative;
width: 100%;
height: 100%;
min-height: 0;
box-sizing: border-box;
overflow: hidden;
background: transparent;
}
.qr-corner {
position: absolute;
width: 300rpx;
height: 300rpx;
background: #ffeb00;
}
.qr-corner--top {
top: -220rpx;
right: -170rpx;
transform: rotate(42deg);
}
.qr-corner--bottom {
bottom: -220rpx;
left: -170rpx;
transform: rotate(42deg);
}
.qr-canvas {
position: relative;
z-index: 1;
display: flex;
width: 100%;
height: 100%;
min-height: 0;
box-sizing: border-box;
flex-direction: column;
align-items: center;
padding: 260rpx 62rpx 70rpx;
}
.qr-image {
width: 432rpx;
height: 432rpx;
box-sizing: border-box;
background: #ffffff;
}
.qr-save-button {
display: flex;
width: 360rpx;
height: 72rpx;
align-items: center;
justify-content: center;
margin-top: 34rpx;
border: 1rpx solid #e8c840;
border-radius: 36rpx;
color: #ffe846;
font-size: 26rpx;
}
.qr-device-id,
.qr-empty {
color: rgba(255, 255, 255, 0.72);
font-size: 26rpx;
line-height: 40rpx;
text-align: center;
}
.qr-device-id {
margin-top: 24rpx;
}
.qr-empty {
margin-top: 140rpx;
}
.qr-description,
.qr-note {
width: 100%;
color: rgba(255, 255, 255, 0.6);
font-size: 22rpx;
line-height: 36rpx;
text-align: center;
}
.qr-description {
margin-top: 42rpx;
}
.qr-note {
margin-top: 12rpx;
color: rgba(255, 232, 70, 0.7);
}
</style>
File diff suppressed because it is too large Load Diff
@@ -1,24 +1,21 @@
<script setup> <script setup>
import { ref, computed, onMounted, onUnmounted } from "vue"; import { ref, computed, onMounted, onUnmounted } from "vue";
import { onLoad, onShow } from "@dcloudio/uni-app"; import { onLoad, onShow } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue"; import Container from "@/components/Container.vue";
import ScreenHint from "@/components/ScreenHint.vue"; import ScreenHint from "@/components/ScreenHint.vue";
import ModalDialog from "@/components/ModalDialog.vue";
import OtaModal from "@/components/OtaModal.vue";
import { import {
connectDeviceWifiAPI, connectDeviceWifiAPI,
getDeviceBatteryAPI,
getHardwareBoxTaskStatusAPI,
getHardwareBoxVersionAPI, getHardwareBoxVersionAPI,
sendHardwareBoxUpdateAPI,
} from "@/apis"; } from "@/apis";
import { useOtaUpdate } from "./composables/useOtaUpdate";
const STATES = { const STATES = {
SCANNING: "SCANNING", SCANNING: "SCANNING",
LIST: "LIST", LIST: "LIST",
CONNECTING: "CONNECTING", CONNECTING: "CONNECTING",
CONNECTED: "CONNECTED", CONNECTED: "CONNECTED",
UPDATING: "UPDATING",
DONE: "DONE",
FAILED: "FAILED",
}; };
const isIOS = uni.getDeviceInfo().osName === "ios"; const isIOS = uni.getDeviceInfo().osName === "ios";
@@ -38,27 +35,37 @@ const keyboardHeight = ref(0);
const showPassword = ref(false); const showPassword = ref(false);
// 刷新防抖标志:扫描进行中为 true,禁止重复点击;扫描结束(成功/失败)后重置为 false。 // 刷新防抖标志:扫描进行中为 true,禁止重复点击;扫描结束(成功/失败)后重置为 false。
const isRefreshing = ref(false); const isRefreshing = ref(false);
const isStartingUpdate = ref(false); const fromFirmwareUpdate = ref(false);
const routeOtaInfo = ref({ const routeOtaInfo = ref({
versionNumber: "", versionNumber: "",
resourceUrl: "", resourceUrl: "",
}); });
const countdownVisible = ref(false);
const progress = ref(0); const countdownSeconds = ref(3);
let progressTimer = null; const firmwareMessageVisible = ref(false);
let timeoutTimer = null; const firmwareMessage = ref("");
let statusTimer = null; let countdownTimer = null;
let wifiConnectTimer = null;
let wifiConnectRequestId = 0; let wifiConnectRequestId = 0;
let wifiConnectPollCount = 0;
const WIFI_CONNECT_POLL_INTERVAL = 2000;
const WIFI_CONNECT_MAX_POLL_COUNT = 30;
const WIFI_CONNECT_FAILED_TEXT = "连接失败,请检查WiFi密码或WiFi状态"; const WIFI_CONNECT_FAILED_TEXT = "连接失败,请检查WiFi密码或WiFi状态";
const OTA_MIN_BATTERY = 50;
const OTA_LOW_BATTERY_TEXT = "电量不足 50%,暂不支持 OTA 升级";
// 控制授权拒绝弹窗显示/隐藏 // 控制授权拒绝弹窗显示/隐藏
const wifiAuthDeniedVisible = ref(false); const wifiAuthDeniedVisible = ref(false);
const {
updating: otaUpdating,
progress: otaProgress,
phase: otaPhase,
resultVisible: otaResultVisible,
resultStatus: otaResultStatus,
resultTitle: otaResultTitle,
resultContent: otaResultContent,
startUpdate: startOtaUpdate,
closeResult: closeOtaResult,
} = useOtaUpdate();
const countdownButtonText = computed(
() => `${Math.max(1, countdownSeconds.value)}秒后开始`
);
// 判断 WiFi 列表失败是否由用户拒绝授权引起(兼容 errno:103 及各平台 errMsg 变体)。 // 判断 WiFi 列表失败是否由用户拒绝授权引起(兼容 errno:103 及各平台 errMsg 变体)。
const isWifiPermissionDenied = (err) => { const isWifiPermissionDenied = (err) => {
if (err?.errno === 103) return true; if (err?.errno === 103) return true;
@@ -207,7 +214,7 @@ const startScanning = () => {
// 选择列表中的 WiFi,并打开密码输入弹窗。 // 选择列表中的 WiFi,并打开密码输入弹窗。
const selectWifi = (wifi) => { const selectWifi = (wifi) => {
cancelWifiConnectPolling(); cancelWifiConnectWaiting();
connectingWifi.value = wifi; connectingWifi.value = wifi;
connectInput.value = { ssid: wifi.SSID, password: "" }; connectInput.value = { ssid: wifi.SSID, password: "" };
connectMode.value = wifi.secure ? "secure" : "open"; connectMode.value = wifi.secure ? "secure" : "open";
@@ -217,7 +224,7 @@ const selectWifi = (wifi) => {
// 选择手动输入 WiFi,并打开手动输入弹窗。 // 选择手动输入 WiFi,并打开手动输入弹窗。
const selectOther = () => { const selectOther = () => {
cancelWifiConnectPolling(); cancelWifiConnectWaiting();
connectingWifi.value = null; connectingWifi.value = null;
connectInput.value = { ssid: "", password: "" }; connectInput.value = { ssid: "", password: "" };
connectMode.value = "manual"; connectMode.value = "manual";
@@ -225,9 +232,9 @@ const selectOther = () => {
currentState.value = STATES.CONNECTING; currentState.value = STATES.CONNECTING;
}; };
// 关闭连接弹窗,并停止当前 WiFi 连接轮询。 // 关闭连接弹窗,并停止等待当前 WiFi 连接结果。
const closeConnectSheet = () => { const closeConnectSheet = () => {
cancelWifiConnectPolling(); cancelWifiConnectWaiting();
connectError.value = ""; connectError.value = "";
currentState.value = connectedWifi.value ? STATES.CONNECTED : STATES.LIST; currentState.value = connectedWifi.value ? STATES.CONNECTED : STATES.LIST;
}; };
@@ -257,89 +264,30 @@ const wifiListScrollHeight = computed(() => {
return `${Math.min(itemCount * 92, maxHeight)}rpx`; return `${Math.min(itemCount * 92, maxHeight)}rpx`;
}); });
// 清理 WiFi 连接轮询定时器。 // 取消当前 WiFi 连接请求的页面等待状态,并忽略可能迟到的响应。
const clearWifiConnectTimer = () => { const cancelWifiConnectWaiting = () => {
clearTimeout(wifiConnectTimer);
wifiConnectTimer = null;
wifiConnectPollCount = 0;
};
// 取消当前 WiFi 连接轮询,并恢复弹窗提交状态。
const cancelWifiConnectPolling = () => {
wifiConnectRequestId += 1; wifiConnectRequestId += 1;
clearWifiConnectTimer();
connectStatusText.value = ""; connectStatusText.value = "";
isSubmittingWifi.value = false; isSubmittingWifi.value = false;
uni.hideLoading(); uni.hideLoading();
}; };
// 判断设备电量接口返回的 online/netType 字段,确定设备是否已通过 WiFi 在线。 // 把接口失败和传输异常转换为连接弹窗内的用户提示。
// 返回值含义:true → WiFi 在线成功;"net_fail" → 设备走 4g 失败;false → 未就绪,需继续轮询。 const getWifiConnectErrorText = (error) => {
const isDeviceConnectedByWifi = (deviceStatus) => { const message = error?.message || "";
// online 不为 true → 设备不在线,需继续轮询 if (message.includes("请先开启智能弓")) return "请先开启智能弓";
if (deviceStatus?.online !== true) return false; if (message.includes("超时") || error?.errMsg?.includes("timeout")) {
const netType = String(deviceStatus?.netType || "").toLowerCase(); return "等待设备响应超时,请重试";
// online:true + netType:4g → 设备已切 4g,WiFi 连接失败 }
if (netType === "4g") return "net_fail"; if (error?.errMsg) return "网络异常,请检查网络后重试";
// online:true + netType:wifi → WiFi 连接成功 return message || WIFI_CONNECT_FAILED_TEXT;
// online:true + netType:"" → 设备在线但 netType 暂未上报,继续轮询等待
return netType === "wifi";
}; };
// 轮询设备电量接口,等待设备切到 WiFi 在线;netType:4g 快速失败,超时 30 次后放弃。 // 提交 WiFi 配置,并以接口返回的设备最终连接结果更新页面。
const waitForDeviceWifiConnected = (requestId) => {
return new Promise((resolve) => {
const poll = async () => {
if (requestId !== wifiConnectRequestId) {
resolve(false);
return;
}
wifiConnectPollCount += 1;
try {
const deviceStatus = await getDeviceBatteryAPI();
if (requestId !== wifiConnectRequestId) {
resolve(false);
return;
}
const connResult = isDeviceConnectedByWifi(deviceStatus);
// online:true + netType:wifi → 成功
if (connResult === true) {
resolve(true);
return;
}
// online:true + netType:4g → 立即失败(设备已切 4g,WiFi 连不上)
if (connResult === "net_fail") {
resolve(false);
return;
}
// online:false + netType:"" → 继续轮询
// online:true + netType:"" → 忽略,继续轮询(netType 暂未上报)
} catch (err) {
if (requestId !== wifiConnectRequestId) {
resolve(false);
return;
}
}
if (wifiConnectPollCount >= WIFI_CONNECT_MAX_POLL_COUNT) {
resolve(false);
return;
}
wifiConnectTimer = setTimeout(poll, WIFI_CONNECT_POLL_INTERVAL);
};
poll();
});
};
// 提交 WiFi 配置给游戏设备,并轮询确认设备真实连上 WiFi 后再展示成功。
const submitDeviceWifiConfig = async ({ ssid, password }) => { const submitDeviceWifiConfig = async ({ ssid, password }) => {
if (isSubmittingWifi.value) return; if (isSubmittingWifi.value) return;
wifiConnectRequestId += 1; wifiConnectRequestId += 1;
const requestId = wifiConnectRequestId; const requestId = wifiConnectRequestId;
clearWifiConnectTimer();
isSubmittingWifi.value = true; isSubmittingWifi.value = true;
connectStatusText.value = "WiFi连接中..."; connectStatusText.value = "WiFi连接中...";
uni.showLoading({ uni.showLoading({
@@ -347,10 +295,9 @@ const submitDeviceWifiConfig = async ({ ssid, password }) => {
mask: true, mask: true,
}); });
try { try {
await connectDeviceWifiAPI(ssid, password); const connectResult = await connectDeviceWifiAPI(ssid, password);
const isConnected = await waitForDeviceWifiConnected(requestId);
if (requestId !== wifiConnectRequestId) return; if (requestId !== wifiConnectRequestId) return;
if (!isConnected) { if (connectResult?.success !== true) {
connectError.value = WIFI_CONNECT_FAILED_TEXT; connectError.value = WIFI_CONNECT_FAILED_TEXT;
return; return;
} }
@@ -362,14 +309,15 @@ const submitDeviceWifiConfig = async ({ ssid, password }) => {
}; };
connectError.value = ""; connectError.value = "";
currentState.value = STATES.CONNECTED; currentState.value = STATES.CONNECTED;
if (fromFirmwareUpdate.value) {
openFirmwareCountdown();
}
} catch (err) { } catch (err) {
if (requestId === wifiConnectRequestId) { if (requestId === wifiConnectRequestId) {
connectError.value = connectError.value = getWifiConnectErrorText(err);
err?.code === -1 && err?.message ? err.message : WIFI_CONNECT_FAILED_TEXT;
} }
} finally { } finally {
if (requestId === wifiConnectRequestId) { if (requestId === wifiConnectRequestId) {
clearWifiConnectTimer();
connectStatusText.value = ""; connectStatusText.value = "";
isSubmittingWifi.value = false; isSubmittingWifi.value = false;
uni.hideLoading(); uni.hideLoading();
@@ -387,81 +335,7 @@ const joinNetwork = () => {
submitDeviceWifiConfig({ ssid, password }); submitDeviceWifiConfig({ ssid, password });
}; };
// 清理 OTA 更新相关定时器,避免页面退出或状态结束后继续执行。 // 获取 OTA 更新版本信息,正常使用入口传参,缺失时再请求后端兜底。
const clearUpdateTimers = () => {
clearInterval(progressTimer);
clearTimeout(timeoutTimer);
clearTimeout(statusTimer);
progressTimer = null;
timeoutTimer = null;
statusTimer = null;
};
// 启动本地进度条动画,真实完成状态以后端任务轮询结果为准。
const startProgressAnimation = () => {
clearInterval(progressTimer);
progressTimer = setInterval(() => {
if (progress.value >= 90) {
clearInterval(progressTimer);
return;
}
const increment = Math.max(0.5, 2 - progress.value / 60);
progress.value = Math.min(90, progress.value + increment);
}, 500);
};
// 将 OTA 更新流程标记为失败并切换到失败页面。
const failUpdate = () => {
clearUpdateTimers();
isStartingUpdate.value = false;
currentState.value = STATES.FAILED;
};
// 将 OTA 更新流程标记为成功,进度补到 100% 后进入完成页面。
const completeUpdate = () => {
clearUpdateTimers();
isStartingUpdate.value = false;
progress.value = 100;
setTimeout(() => {
currentState.value = STATES.DONE;
}, 300);
};
// 轮询 OTA 更新任务状态,状态为处理中则继续轮询,成功或失败则结束流程。
const pollUpdateTaskStatus = (taskId) => {
clearTimeout(statusTimer);
statusTimer = setTimeout(async () => {
try {
const taskStatus = await getHardwareBoxTaskStatusAPI(taskId);
const status = Number(taskStatus?.status);
if (status === 2) {
completeUpdate();
return;
}
if (status === 3) {
failUpdate();
return;
}
if (status === 0 || status === 1) {
pollUpdateTaskStatus(taskId);
return;
}
failUpdate();
} catch (err) {
failUpdate();
}
}, 3000);
};
// 判断设备是否满足 OTA 更新条件,不满足时返回精确提示文案。
const getUpdateDisabledReason = (deviceStatus) => {
if (deviceStatus?.online !== true) return "请先开启智能弓";
if (Number(deviceStatus?.battery) <= OTA_MIN_BATTERY) return OTA_LOW_BATTERY_TEXT;
if (String(deviceStatus?.netType || "").toLowerCase() !== "wifi") return "设备当前未连接 WiFi,请先连接 WiFi 后再更新";
return "";
};
// 获取 OTA 更新版本信息,优先使用首页跳转传入的数据,没有传参时再请求后端版本接口。
const getOtaVersionInfo = async () => { const getOtaVersionInfo = async () => {
if (routeOtaInfo.value.versionNumber && routeOtaInfo.value.resourceUrl) { if (routeOtaInfo.value.versionNumber && routeOtaInfo.value.resourceUrl) {
return { return {
@@ -473,101 +347,43 @@ const getOtaVersionInfo = async () => {
return getHardwareBoxVersionAPI(); return getHardwareBoxVersionAPI();
}; };
// 点击开始更新时先判断设备状态和版本信息,满足条件才发送 OTA 指令并开始轮询任务状态。 const startFirmwareUpdate = async () => {
const startUpdate = async () => { if (!fromFirmwareUpdate.value || !connectedWifi.value || otaUpdating.value) return;
if (isStartingUpdate.value) return;
if (!connectedWifi.value) return;
isStartingUpdate.value = true;
try { try {
const deviceStatus = await getDeviceBatteryAPI(); const versionInfo = await getOtaVersionInfo();
const disabledReason = getUpdateDisabledReason(deviceStatus);
if (disabledReason) {
isStartingUpdate.value = false;
uni.showToast({
title: disabledReason,
icon: "none",
});
return;
}
let versionInfo;
try {
versionInfo = await getOtaVersionInfo();
} catch (err) {
isStartingUpdate.value = false;
uni.showToast({
title: "获取更新版本失败,请重试",
icon: "none",
});
return;
}
if (!versionInfo?.needUpdate) { if (!versionInfo?.needUpdate) {
isStartingUpdate.value = false; firmwareMessage.value = "当前已是最新版本";
uni.showToast({ firmwareMessageVisible.value = true;
title: "当前已是最新版本",
icon: "none",
});
return; return;
} }
await startOtaUpdate({
currentState.value = STATES.UPDATING;
progress.value = 0;
startProgressAnimation();
timeoutTimer = setTimeout(() => {
if (currentState.value === STATES.UPDATING) {
failUpdate();
}
}, 5 * 60 * 1000);
const updateResult = await sendHardwareBoxUpdateAPI({
versionNumber: versionInfo.versionNumber, versionNumber: versionInfo.versionNumber,
wifiSsid: connectedWifi.value.SSID, wifiSsid: connectedWifi.value.SSID,
wifiPassword: connectedWifi.value.password || "", wifiPassword: connectedWifi.value.password || "",
resourceUrl: versionInfo.resourceUrl, resourceUrl: versionInfo.resourceUrl,
}); });
if (!updateResult?.taskId) { } catch (error) {
failUpdate(); firmwareMessage.value = "获取更新版本失败,请重试";
return; firmwareMessageVisible.value = true;
}
pollUpdateTaskStatus(updateResult.taskId);
} catch (err) {
failUpdate();
} }
}; };
// WebSocket 成功回调保留兜底能力,触发后直接按更新完成处理。 const clearFirmwareCountdown = () => {
const handleWsDone = () => { clearInterval(countdownTimer);
completeUpdate(); countdownTimer = null;
}; };
// WebSocket 失败回调保留兜底能力,触发后直接按更新失败处理。 const openFirmwareCountdown = () => {
const handleWsFail = () => { clearFirmwareCountdown();
failUpdate(); countdownSeconds.value = 3;
}; countdownVisible.value = true;
countdownTimer = setInterval(() => {
// 处理更新完成返回,兼容首页 OTA 弹窗入口和设备页普通入口。 countdownSeconds.value -= 1;
const handleDone = () => { if (countdownSeconds.value > 0) return;
const pages = getCurrentPages(); clearFirmwareCountdown();
const prevPage = pages[pages.length - 2]; countdownVisible.value = false;
const prevVm = prevPage?.$vm; void startFirmwareUpdate();
}, 1000);
if (prevVm && "otaState" in prevVm && "otaVisible" in prevVm) {
prevVm.otaState = "update_success";
prevVm.otaVisible = true;
}
uni.navigateBack({ delta: 1 });
};
const handleRetry = () => {
if (connectedWifi.value) {
currentState.value = STATES.CONNECTED;
} else {
startScanning();
}
}; };
// 监听系统输入法高度,用于让底部弹窗避开键盘遮挡。 // 监听系统输入法高度,用于让底部弹窗避开键盘遮挡。
@@ -585,8 +401,9 @@ const togglePasswordVisibility = () => {
}); });
}; };
// 页面加载时接收首页传入的 OTA 版本号和固件地址。 // 页面加载时识别普通 WiFi 入口和固件更新入口。
onLoad((options = {}) => { onLoad((options = {}) => {
fromFirmwareUpdate.value = options.source === "firmware-update";
routeOtaInfo.value = { routeOtaInfo.value = {
versionNumber: decodeURIComponent(options.versionNumber || ""), versionNumber: decodeURIComponent(options.versionNumber || ""),
resourceUrl: decodeURIComponent(options.resourceUrl || ""), resourceUrl: decodeURIComponent(options.resourceUrl || ""),
@@ -612,8 +429,8 @@ onUnmounted(() => {
if (typeof uni.offKeyboardHeightChange === "function") { if (typeof uni.offKeyboardHeightChange === "function") {
uni.offKeyboardHeightChange(handleKeyboardHeightChange); uni.offKeyboardHeightChange(handleKeyboardHeightChange);
} }
cancelWifiConnectPolling(); cancelWifiConnectWaiting();
clearUpdateTimers(); clearFirmwareCountdown();
wx.offGetWifiList && wx.offGetWifiList(); wx.offGetWifiList && wx.offGetWifiList();
}); });
</script> </script>
@@ -650,16 +467,16 @@ onUnmounted(() => {
</view> </view>
<view v-if="currentState === 'CONNECTED'" class="wifi-list-card connected-wifi-card"> <view v-if="currentState === 'CONNECTED'" class="wifi-list-card connected-wifi-card">
<view class="wifi-item connected-wifi-item"> <view class="wifi-item connected-wifi-item">
<image class="check-icon" src="../static/sicon/check.png" mode="aspectFit" /> <image class="check-icon" src="../../static/sicon/check.png" mode="aspectFit" />
<text class="wifi-ssid connected-wifi-ssid">{{ connectedWifi?.SSID }}</text> <text class="wifi-ssid connected-wifi-ssid">{{ connectedWifi?.SSID }}</text>
<view class="wifi-icons connected-wifi-icons"> <view class="wifi-icons connected-wifi-icons">
<image <image
v-if="connectedWifi?.secure" v-if="connectedWifi?.secure"
class="security-icon" class="security-icon"
src="../static/sicon/pwd.png" src="../../static/sicon/pwd.png"
mode="aspectFit" mode="aspectFit"
/> />
<image class="signal-icon" src="../static/sicon/wifi.png" mode="aspectFit" /> <image class="signal-icon" src="../../static/sicon/wifi.png" mode="aspectFit" />
</view> </view>
</view> </view>
</view> </view>
@@ -668,7 +485,7 @@ onUnmounted(() => {
<view class="section-label-row"> <view class="section-label-row">
<text class="section-label">网络</text> <text class="section-label">网络</text>
<image <image
src="../static/sicon/refresh.png" src="../../static/sicon/refresh.png"
mode="aspectFit" mode="aspectFit"
:style="{ width: '34rpx', height: '34rpx', marginLeft: '8rpx', opacity: isRefreshing ? 0.3 : 0.7 }" :style="{ width: '34rpx', height: '34rpx', marginLeft: '8rpx', opacity: isRefreshing ? 0.3 : 0.7 }"
@click="startScanning" @click="startScanning"
@@ -699,10 +516,10 @@ onUnmounted(() => {
<image <image
v-if="wifi.secure" v-if="wifi.secure"
class="security-icon" class="security-icon"
src="../static/sicon/pwd.png" src="../../static/sicon/pwd.png"
mode="aspectFit" mode="aspectFit"
/> />
<image class="signal-icon" src="../static/sicon/wifi.png" mode="aspectFit" /> <image class="signal-icon" src="../../static/sicon/wifi.png" mode="aspectFit" />
</view> </view>
</view> </view>
<view class="wifi-item" @click="selectOther"> <view class="wifi-item" @click="selectOther">
@@ -711,46 +528,6 @@ onUnmounted(() => {
</block> </block>
</scroll-view> </scroll-view>
<!-- CONNECTED:开始更新按钮 -->
<view v-if="currentState === 'CONNECTED'" class="bottom-btn-area connected-bottom-btn-area">
<view class="primary-btn update-btn" @click="startUpdate">
<text class="primary-btn-text">开始更新</text>
</view>
</view>
</view>
<!-- UPDATING -->
<view v-else-if="currentState === 'UPDATING'" class="center-page">
<image src="https://static.shelingxingqiu.com/shootmini/static/ota/target-char.png" mode="aspectFit" style="width: 194rpx; height: 164rpx;" />
<text class="page-title" style="margin-top: 24rpx;">更新中,请稍等片刻...</text>
<view class="progress-wrap">
<view class="progress-track">
<view class="progress-fill" :style="{ width: progress + '%' }"></view>
</view>
<text class="progress-pct">{{ Math.floor(progress) }}%</text>
</view>
</view>
<!-- DONE -->
<view v-else-if="currentState === 'DONE'" class="center-page">
<image src="https://static.shelingxingqiu.com/shootmini/static/ota/check-char.png" mode="aspectFit" style="width: 194rpx; height: 166rpx;" />
<text class="page-title" style="margin-top: 24rpx;">更新完成</text>
<text class="page-desc-white">请关机并重启智能弓</text>
<view class="primary-btn done-btn" style="margin-top:20px" @click="handleDone">
<text class="primary-btn-text">完成</text>
</view>
</view>
<!-- FAILED -->
<view v-else-if="currentState === 'FAILED'" class="center-page">
<image src="https://static.shelingxingqiu.com/shootmini/static/ota/close-char.png" mode="aspectFit" style="width: 194rpx; height: 164rpx;" />
<text class="page-title fail-title" style="margin-top: 24rpx;">更新失败</text>
<text class="page-desc-white">请确保:</text>
<text class="page-desc-white">1、智能弓已开启</text>
<text class="page-desc-white">2、网路连接稳定</text>
<view class="primary-btn done-btn" style="margin-top: 40rpx;" @click="handleRetry">
<text class="primary-btn-text">重试</text>
</view>
</view> </view>
<!-- CONNECTING 底部弹窗 --> <!-- CONNECTING 底部弹窗 -->
@@ -763,7 +540,7 @@ onUnmounted(() => {
<block v-if="connectMode === 'secure'"> <block v-if="connectMode === 'secure'">
<view class="sheet-header"> <view class="sheet-header">
<view class="sheet-nav-btn" @click="closeConnectSheet"> <view class="sheet-nav-btn" @click="closeConnectSheet">
<image src="../static/sicon/arrow-left.png" mode="aspectFit" style="width: 40rpx; height: 40rpx;" /> <image src="../../static/sicon/arrow-left.png" mode="aspectFit" style="width: 40rpx; height: 40rpx;" />
</view> </view>
<text class="sheet-title">加入"{{ connectInput.ssid }}"</text> <text class="sheet-title">加入"{{ connectInput.ssid }}"</text>
<view <view
@@ -771,7 +548,7 @@ onUnmounted(() => {
:class="{ 'nav-disabled': joinDisabled }" :class="{ 'nav-disabled': joinDisabled }"
@click="joinNetwork" @click="joinNetwork"
> >
<image src="../static/sicon/check.png" mode="aspectFit" style="width: 28rpx; height: 24rpx;" /> <image src="../../static/sicon/check.png" mode="aspectFit" style="width: 28rpx; height: 24rpx;" />
</view> </view>
</view> </view>
<view class="input-row-card"> <view class="input-row-card">
@@ -789,7 +566,7 @@ onUnmounted(() => {
<!-- 密码显示/隐藏切换按钮 --> <!-- 密码显示/隐藏切换按钮 -->
<view class="pwd-eye-btn" @click="togglePasswordVisibility"> <view class="pwd-eye-btn" @click="togglePasswordVisibility">
<image <image
:src="showPassword ? '../static/sicon/eye-on.png' : '../static/sicon/eye-off.png'" :src="showPassword ? '../../static/sicon/eye-on.png' : '../../static/sicon/eye-off.png'"
mode="aspectFit" mode="aspectFit"
style="width: 40rpx; height: 40rpx;" style="width: 40rpx; height: 40rpx;"
/> />
@@ -803,11 +580,11 @@ onUnmounted(() => {
<block v-else-if="connectMode === 'open'"> <block v-else-if="connectMode === 'open'">
<view class="sheet-header"> <view class="sheet-header">
<view class="sheet-nav-btn" @click="closeConnectSheet"> <view class="sheet-nav-btn" @click="closeConnectSheet">
<image src="../static/sicon/arrow-left.png" mode="aspectFit" style="width: 40rpx; height: 40rpx;" /> <image src="../../static/sicon/arrow-left.png" mode="aspectFit" style="width: 40rpx; height: 40rpx;" />
</view> </view>
<text class="sheet-title">加入"{{ connectInput.ssid }}"</text> <text class="sheet-title">加入"{{ connectInput.ssid }}"</text>
<view class="sheet-nav-btn" @click="joinNetwork"> <view class="sheet-nav-btn" @click="joinNetwork">
<image src="../static/sicon/check.png" mode="aspectFit" style="width: 28rpx; height: 24rpx;" /> <image src="../../static/sicon/check.png" mode="aspectFit" style="width: 28rpx; height: 24rpx;" />
</view> </view>
</view> </view>
<text v-if="connectStatusText" class="connect-status">{{ connectStatusText }}</text> <text v-if="connectStatusText" class="connect-status">{{ connectStatusText }}</text>
@@ -819,7 +596,7 @@ onUnmounted(() => {
<block v-else-if="connectMode === 'manual'"> <block v-else-if="connectMode === 'manual'">
<view class="sheet-header"> <view class="sheet-header">
<view class="sheet-nav-btn" @click="closeConnectSheet"> <view class="sheet-nav-btn" @click="closeConnectSheet">
<image src="../static/sicon/arrow-left.png" mode="aspectFit" style="width: 40rpx; height: 40rpx;" /> <image src="../../static/sicon/arrow-left.png" mode="aspectFit" style="width: 40rpx; height: 40rpx;" />
</view> </view>
<text class="sheet-title">加入无线网络</text> <text class="sheet-title">加入无线网络</text>
<view <view
@@ -827,7 +604,7 @@ onUnmounted(() => {
:class="{ 'nav-disabled': joinDisabled }" :class="{ 'nav-disabled': joinDisabled }"
@click="joinNetwork" @click="joinNetwork"
> >
<image src="../static/sicon/check.png" mode="aspectFit" style="width: 28rpx; height: 24rpx;" /> <image src="../../static/sicon/check.png" mode="aspectFit" style="width: 28rpx; height: 24rpx;" />
</view> </view>
</view> </view>
<view class="input-row-card"> <view class="input-row-card">
@@ -854,7 +631,7 @@ onUnmounted(() => {
<!-- 密码显示/隐藏切换按钮 --> <!-- 密码显示/隐藏切换按钮 -->
<view class="pwd-eye-btn" @click="togglePasswordVisibility"> <view class="pwd-eye-btn" @click="togglePasswordVisibility">
<image <image
:src="showPassword ? '../static/sicon/eye-on.png' : '../static/sicon/eye-off.png'" :src="showPassword ? '../../static/sicon/eye-on.png' : '../../static/sicon/eye-off.png'"
mode="aspectFit" mode="aspectFit"
style="width: 40rpx; height: 40rpx;" style="width: 40rpx; height: 40rpx;"
/> />
@@ -883,6 +660,46 @@ onUnmounted(() => {
</view> </view>
</view> </view>
</ScreenHint> </ScreenHint>
<ModalDialog
:show="countdownVisible"
title="WiFi连接成功"
content="3秒后将自动开始更新"
:confirmText="countdownButtonText"
:showCancel="false"
:confirmDisabled="true"
></ModalDialog>
<OtaModal
:visible="otaUpdating"
state="update_progress"
:progress="otaProgress"
:phase="otaPhase"
/>
<OtaModal
:visible="otaResultVisible && otaResultStatus === 'success'"
state="update_success"
@done="closeOtaResult"
/>
<ModalDialog
:show="otaResultVisible && otaResultStatus === 'failed'"
:title="otaResultTitle"
:content="otaResultContent"
confirmText="关闭"
:showCancel="false"
:onConfirm="closeOtaResult"
></ModalDialog>
<ModalDialog
:show="firmwareMessageVisible"
title="固件更新"
:content="firmwareMessage"
confirmText="关闭"
:showCancel="false"
:onConfirm="() => (firmwareMessageVisible = false)"
></ModalDialog>
</Container> </Container>
</template> </template>
+429 -158
View File
@@ -1,18 +1,17 @@
<script setup> <script setup>
import {onMounted, onUnmounted, ref, watch} from "vue"; import {computed, onMounted, onUnmounted, ref, watch} from "vue";
import {onShareAppMessage, onShareTimeline, onShow} from "@dcloudio/uni-app"; import {onShareAppMessage, onShareTimeline, onShow} from "@dcloudio/uni-app";
import Container from "@/components/Container.vue"; import Container from "@/components/Container.vue";
import AppFooter from "@/components/AppFooter.vue"; import AppFooter from "@/components/AppFooter.vue";
import UserHeader from "@/components/UserHeader.vue"; import UserHeader from "@/components/UserHeader.vue";
import Signin from "@/components/Signin.vue"; import Signin from "@/components/Signin.vue";
import BubbleTip from "@/components/BubbleTip.vue"; import BubbleTip from "@/components/BubbleTip.vue";
import ModalDialog from "@/components/ModalDialog.vue";
import OtaModal from "@/components/OtaModal.vue"; import OtaModal from "@/components/OtaModal.vue";
import { import {
checkUserBindAPI, checkUserBindAPI,
getAppConfig, getAppConfig,
getDeviceBatteryAPI,
getHardwareBoxTaskStatusAPI,
getHardwareBoxVersionAPI, getHardwareBoxVersionAPI,
getHomeData, getHomeData,
getMyDevicesAPI, getMyDevicesAPI,
@@ -33,52 +32,70 @@ const {
clearDevice, clearDevice,
getLvlName, getLvlName,
getLvlNameByScore, getLvlNameByScore,
updateOnline,
} = store; } = store;
const {user, device, online, game} = storeToRefs(store); const {user, device, deviceStatus, online, deviceBattery, game} = storeToRefs(store);
const showModal = ref(false); const showModal = ref(false);
const showGuide = ref(false); const showGuide = ref(false);
const scoreRankList = ref([]); const scoreRankList = ref([]);
const DEVICE_STATUS_STALE_TIME = 6000;
// 首页设备卡片按“未绑定 / 已绑定未连接 / 已绑定已连接”三态展示。
const deviceCardState = computed(() => {
// 未登录时始终展示绑定入口,避免本地残留设备状态误显示为已绑定。
if (!user.value?.id || !device.value?.deviceId) return "unbound";
return online.value === true ? "online" : "offline";
});
const deviceCardAssets = {
unbound: {
bow: "../static/home-device/device-bow--unbound.png",
background: "../static/home-device/device-card-bg--unbound.png",
actionBackground: "../static/home-device/device-action-bg--bind.png",
},
offline: {
bow: "../static/home-device/device-bow--offline.png",
background: "../static/home-device/device-card-bg--bound.png",
actionBackground: "../static/home-device/device-action-bg--device.png",
},
online: {
bow: "../static/home-device/device-bow--online.png",
background: "../static/home-device/device-card-bg--bound.png",
actionBackground: "../static/home-device/device-action-bg--device.png",
},
};
const deviceCardAsset = computed(() => deviceCardAssets[deviceCardState.value]);
// OTA 相关 // OTA 相关
const otaVisible = ref(false); const otaVisible = ref(false);
const wifiRequiredVisible = ref(false);
const otaState = ref("new_version"); const otaState = ref("new_version");
const otaProgress = ref(0); const otaProgress = ref(0);
const otaPhase = ref("started");
const otaInfo = ref({ const otaInfo = ref({
versionNumber: "", versionNumber: "",
versionInfo: "", versionInfo: "",
resourceUrl: "", resourceUrl: "",
forceUpdate: false, forceUpdate: false,
needUpdate: false,
}); });
const isStartingOta = ref(false); const isStartingOta = ref(false);
let isCheckingOta = false; let isCheckingOta = false;
let otaCheckQueuedForOnline = false; let otaCheckQueuedForOnline = false;
let otaProgressTimer = null;
let otaStatusTimer = null;
let otaTimeoutTimer = null; let otaTimeoutTimer = null;
let otaResultTimer = null;
let otaStatusPollCount = 0;
let otaUpdateRunId = 0; let otaUpdateRunId = 0;
// 首页 OTA 轮询采用请求次数和总时长双重兜底,避免更新中状态长期卡住。 const OTA_UPDATE_TIMEOUT = 10 * 60 * 1000;
const OTA_TASK_STATUS_POLL_INTERVAL = 2000; const OTA_PROGRESS_EVENT = "/addons/shoot/otaProgress";
const OTA_TASK_STATUS_MAX_POLL_COUNT = 15; const OTA_RESULT_EVENT = "/addons/shoot/otaResult";
const OTA_TASK_STATUS_TIMEOUT = 30000;
// 清理首页 OTA 更新定时器,避免弹窗关闭或页面卸载后继续轮询。 // 清理首页 OTA 更新超时计时器。
const clearOtaUpdateTimers = () => { const clearOtaUpdateTimers = () => {
clearInterval(otaProgressTimer);
clearTimeout(otaStatusTimer);
clearTimeout(otaTimeoutTimer); clearTimeout(otaTimeoutTimer);
clearTimeout(otaResultTimer);
otaProgressTimer = null;
otaStatusTimer = null;
otaTimeoutTimer = null; otaTimeoutTimer = null;
otaResultTimer = null;
otaStatusPollCount = 0;
}; };
// 使当前 OTA 运行失效,确保旧请求返回后不会继续轮询或覆盖新状态。 // 使当前 OTA 运行失效,确保旧请求返回后不会覆盖新状态。
const invalidateOtaUpdateRun = () => { const invalidateOtaUpdateRun = () => {
otaUpdateRunId += 1; otaUpdateRunId += 1;
clearOtaUpdateTimers(); clearOtaUpdateTimers();
@@ -87,19 +104,6 @@ const invalidateOtaUpdateRun = () => {
const isOtaUpdateRunActive = (runId) => const isOtaUpdateRunActive = (runId) =>
runId === otaUpdateRunId && otaState.value === "update_progress"; runId === otaUpdateRunId && otaState.value === "update_progress";
// 启动首页 OTA 本地进度动画,最终成功失败以后端任务状态为准。
const startOtaProgressAnimation = () => {
clearInterval(otaProgressTimer);
otaProgressTimer = setInterval(() => {
if (otaProgress.value >= 90) {
clearInterval(otaProgressTimer);
return;
}
const increment = Math.max(0.5, 2 - otaProgress.value / 60);
otaProgress.value = Math.min(90, otaProgress.value + increment);
}, 500);
};
// 获取并保存后端返回的 OTA 版本信息,供弹窗展示和更新接口使用。 // 获取并保存后端返回的 OTA 版本信息,供弹窗展示和更新接口使用。
const applyOtaVersionInfo = (versionInfo) => { const applyOtaVersionInfo = (versionInfo) => {
otaInfo.value = { otaInfo.value = {
@@ -107,6 +111,8 @@ const applyOtaVersionInfo = (versionInfo) => {
versionInfo: versionInfo?.versionInfo || "", versionInfo: versionInfo?.versionInfo || "",
resourceUrl: versionInfo?.resourceUrl || "", resourceUrl: versionInfo?.resourceUrl || "",
forceUpdate: Number(versionInfo?.forceUpdate) === 1, forceUpdate: Number(versionInfo?.forceUpdate) === 1,
needUpdate:
versionInfo?.needUpdate === true || Number(versionInfo?.needUpdate) === 1,
}; };
}; };
@@ -116,13 +122,7 @@ const checkOtaUpdate = async () => {
isCheckingOta = true; isCheckingOta = true;
try { try {
let deviceStatus; if (online.value !== true || otaVisible.value) return;
try {
deviceStatus = await getDeviceBatteryAPI();
} catch (err) {
return;
}
if (deviceStatus?.online !== true || otaVisible.value) return;
let versionInfo; let versionInfo;
try { try {
@@ -130,8 +130,9 @@ const checkOtaUpdate = async () => {
} catch (err) { } catch (err) {
return; return;
} }
if (!versionInfo?.needUpdate || otaVisible.value) return; if (otaVisible.value) return;
applyOtaVersionInfo(versionInfo); applyOtaVersionInfo(versionInfo);
if (!otaInfo.value.needUpdate) return;
const dismissedAt = uni.getStorageSync("ota_dismissed_at"); const dismissedAt = uni.getStorageSync("ota_dismissed_at");
const now = Date.now(); const now = Date.now();
@@ -162,10 +163,11 @@ watch(online, (nextOnline, previousOnline) => {
const getOtaWifiUrl = () => { const getOtaWifiUrl = () => {
const { versionNumber, resourceUrl } = otaInfo.value; const { versionNumber, resourceUrl } = otaInfo.value;
const query = [ const query = [
"source=firmware-update",
`versionNumber=${encodeURIComponent(versionNumber)}`, `versionNumber=${encodeURIComponent(versionNumber)}`,
`resourceUrl=${encodeURIComponent(resourceUrl)}`, `resourceUrl=${encodeURIComponent(resourceUrl)}`,
].join("&"); ].join("&");
return `/pages/ota-wifi?${query}`; return `/pages/device/ota-wifi?${query}`;
}; };
// 处理 OTA 弹窗暂不更新,强制更新时不允许关闭。 // 处理 OTA 弹窗暂不更新,强制更新时不允许关闭。
@@ -189,49 +191,42 @@ const completeHomeOtaUpdate = (runId) => {
if (!isOtaUpdateRunActive(runId)) return; if (!isOtaUpdateRunActive(runId)) return;
invalidateOtaUpdateRun(); invalidateOtaUpdateRun();
isStartingOta.value = false; isStartingOta.value = false;
otaInfo.value = {...otaInfo.value, needUpdate: false};
otaProgress.value = 100; otaProgress.value = 100;
const completedRunId = otaUpdateRunId; otaPhase.value = "installing";
otaResultTimer = setTimeout(() => {
otaResultTimer = null;
if (completedRunId !== otaUpdateRunId) return;
otaState.value = "update_success"; otaState.value = "update_success";
otaVisible.value = true; otaVisible.value = true;
}, 300);
}; };
// 轮询首页直接发起的 OTA 更新任务状态。 // 首页只处理当前设备、当前目标版本的 OTA WebSocket 消息。
const pollHomeOtaTaskStatus = async (taskId, runId) => { const handleHomeOtaSocketMessage = (message) => {
if (!isOtaUpdateRunActive(runId)) return; const runId = otaUpdateRunId;
if (!isOtaUpdateRunActive(runId) || Number(message?.code ?? 0) !== 0) return;
if (![OTA_PROGRESS_EVENT, OTA_RESULT_EVENT].includes(message?.event)) return;
otaStatusPollCount += 1; const messageDeviceId = String(message.data?.deviceId || "");
try { const currentDeviceId = String(device.value?.deviceId || "");
const taskStatus = await getHardwareBoxTaskStatusAPI(taskId); if (messageDeviceId && currentDeviceId && messageDeviceId !== currentDeviceId) return;
if (!isOtaUpdateRunActive(runId)) return;
const status = Number(taskStatus?.status); const messageVersion = String(message.data?.versionNumber || "");
if (status === 2) { const currentVersion = String(otaInfo.value.versionNumber || "");
if (messageVersion && currentVersion && messageVersion !== currentVersion) return;
if (message.event === OTA_PROGRESS_EVENT) {
const nextProgress = Math.min(
100,
Math.max(0, Number(message.data?.progress) || 0)
);
otaProgress.value = Math.max(otaProgress.value, nextProgress);
if (["started", "downloading", "installing"].includes(message.data?.phase)) {
otaPhase.value = message.data.phase;
}
return;
}
if (message.data?.status === "success") {
completeHomeOtaUpdate(runId); completeHomeOtaUpdate(runId);
return; } else if (message.data?.status === "failed") {
}
if (status === 3) {
failHomeOtaUpdate(runId);
return;
}
if (status === 0 || status === 1) {
if (otaStatusPollCount >= OTA_TASK_STATUS_MAX_POLL_COUNT) {
failHomeOtaUpdate(runId);
return;
}
otaStatusTimer = setTimeout(() => {
otaStatusTimer = null;
if (!isOtaUpdateRunActive(runId)) return;
void pollHomeOtaTaskStatus(taskId, runId);
}, OTA_TASK_STATUS_POLL_INTERVAL);
return;
}
failHomeOtaUpdate(runId);
} catch (err) {
if (!isOtaUpdateRunActive(runId)) return;
failHomeOtaUpdate(runId); failHomeOtaUpdate(runId);
} }
}; };
@@ -243,11 +238,11 @@ const startHomeOtaUpdate = async () => {
otaState.value = "update_progress"; otaState.value = "update_progress";
otaVisible.value = true; otaVisible.value = true;
otaProgress.value = 0; otaProgress.value = 0;
startOtaProgressAnimation(); otaPhase.value = "started";
otaTimeoutTimer = setTimeout(() => { otaTimeoutTimer = setTimeout(() => {
if (!isOtaUpdateRunActive(runId)) return; if (!isOtaUpdateRunActive(runId)) return;
failHomeOtaUpdate(runId); failHomeOtaUpdate(runId);
}, OTA_TASK_STATUS_TIMEOUT); }, OTA_UPDATE_TIMEOUT);
try { try {
const updateResult = await sendHardwareBoxUpdateAPI({ const updateResult = await sendHardwareBoxUpdateAPI({
@@ -261,30 +256,19 @@ const startHomeOtaUpdate = async () => {
failHomeOtaUpdate(runId); failHomeOtaUpdate(runId);
return; return;
} }
void pollHomeOtaTaskStatus(updateResult.taskId, runId);
} catch (err) { } catch (err) {
if (!isOtaUpdateRunActive(runId)) return; if (!isOtaUpdateRunActive(runId)) return;
failHomeOtaUpdate(runId); failHomeOtaUpdate(runId);
} }
}; };
// 点击立即更新时先判断设备是否在线并已通过 WiFi 联网,已联网则首页直接更新,否则跳转 WiFi 页面。 // 点击立即更新时先判断设备是否在线并已通过 WiFi 联网,未联网时先展示连接引导。
const handleOtaUpdate = async () => { const handleOtaUpdate = async () => {
if (isStartingOta.value) return; if (isStartingOta.value) return;
isStartingOta.value = true; isStartingOta.value = true;
let deviceStatus; const currentDeviceStatus = deviceStatus.value;
try {
deviceStatus = await getDeviceBatteryAPI();
} catch (err) {
isStartingOta.value = false;
uni.showToast({
title: "获取设备状态失败,请重试",
icon: "none",
});
return;
}
if (deviceStatus?.online !== true) { if (currentDeviceStatus?.online !== true) {
isStartingOta.value = false; isStartingOta.value = false;
uni.showToast({ uni.showToast({
title: "请先开启智能弓", title: "请先开启智能弓",
@@ -293,13 +277,31 @@ const handleOtaUpdate = async () => {
return; return;
} }
if (String(deviceStatus?.netType || "").toLowerCase() === "wifi") { if (
Date.now() - Number(currentDeviceStatus?.receivedAt || 0) >
DEVICE_STATUS_STALE_TIME
) {
isStartingOta.value = false;
uni.showToast({
title: "设备状态同步中,请稍后重试",
icon: "none",
});
return;
}
if (String(currentDeviceStatus?.netType || "").toLowerCase() === "wifi") {
startHomeOtaUpdate(); startHomeOtaUpdate();
return; return;
} }
isStartingOta.value = false; isStartingOta.value = false;
otaVisible.value = false; otaVisible.value = false;
wifiRequiredVisible.value = true;
};
// 从首页固件更新提示进入 WiFi 配置页,并继续沿用当前版本信息。
const goWifiForOtaUpdate = () => {
wifiRequiredVisible.value = false;
uni.navigateTo({ url: getOtaWifiUrl() }); uni.navigateTo({ url: getOtaWifiUrl() });
}; };
@@ -336,6 +338,51 @@ const toRankListPage = () => {
}); });
}; };
// 清理首页设备相关状态;clearDevice 会同步清空 deviceId 和在线状态。
const clearHomeDeviceState = () => {
clearDevice();
uni.setStorageSync("calibration", false);
};
// 从后端同步首页设备绑定关系和连接状态,绑定关系与在线状态共同决定卡片三态。
const syncHomeDevice = async () => {
let devices;
try {
devices = await getMyDevicesAPI();
} catch (error) {
// 绑定接口失败时保留当前设备,避免网络抖动被误判为未绑定。
console.log("同步首页设备绑定失败", error);
return;
}
const bindings = devices?.bindings;
// 服务端用 null 或空数组表示当前账号没有绑定设备。
if (bindings === null || (Array.isArray(bindings) && bindings.length === 0)) {
clearHomeDeviceState();
return;
}
// bindings 缺失或类型错误才属于异常响应,保留已有设备状态。
if (!Array.isArray(bindings)) {
console.log("首页设备绑定响应格式异常", devices);
return;
}
const currentDevice = bindings.find((item) => item?.deviceId);
if (!currentDevice) {
clearHomeDeviceState();
return;
}
const deviceId = String(currentDevice.deviceId || "");
updateDevice(
deviceId,
currentDevice.deviceName || currentDevice.name || ""
);
};
onShow(async (options) => { onShow(async (options) => {
const env = uni.getAccountInfoSync().miniProgram.envVersion; const env = uni.getAccountInfoSync().miniProgram.envVersion;
const token = uni.getStorageSync(`${env}_token`); const token = uni.getStorageSync(`${env}_token`);
@@ -343,6 +390,9 @@ onShow(async (options) => {
// 检查是否从 OTA 更新页面返回 // 检查是否从 OTA 更新页面返回
if (options && options.updateResult) { if (options && options.updateResult) {
otaState.value = options.updateResult; otaState.value = options.updateResult;
if (options.updateResult === "update_success") {
otaInfo.value = {...otaInfo.value, needUpdate: false};
}
otaVisible.value = true; otaVisible.value = true;
} else if (token || user.value.id) { } else if (token || user.value.id) {
await checkOtaUpdate(); await checkOtaUpdate();
@@ -363,8 +413,6 @@ onShow(async (options) => {
// devices.bindings[0].deviceId, // devices.bindings[0].deviceId,
// devices.bindings[0].deviceName // devices.bindings[0].deviceName
// ); // );
// const data = await getDeviceBatteryAPI();
// updateOnline(data.online);
// } // }
// } else { // } else {
// showModal.value = true; // showModal.value = true;
@@ -400,28 +448,21 @@ onShow(async (options) => {
showGuide.value = false; showGuide.value = false;
}, 3000); }, 3000);
} }
const devices = await getMyDevicesAPI(); await syncHomeDevice();
if (devices.bindings && devices.bindings.length) {
updateDevice(
devices.bindings[0].deviceId,
devices.bindings[0].deviceName
);
const data = await getDeviceBatteryAPI();
updateOnline(data.online);
} else {
clearDevice();
}
} }
} }
}); });
onMounted(async () => { onMounted(async () => {
uni.$on("socket-inbox", handleHomeOtaSocketMessage);
const config = await getAppConfig(); const config = await getAppConfig();
updateConfig(config); updateConfig(config);
console.log("全局配置:", config); console.log("全局配置:", config);
}); });
onUnmounted(() => { onUnmounted(() => {
uni.$off("socket-inbox", handleHomeOtaSocketMessage);
invalidateOtaUpdateRun(); invalidateOtaUpdateRun();
}); });
@@ -451,6 +492,7 @@ onShareTimeline(() => {
:state="otaState" :state="otaState"
:version="otaInfo.versionNumber" :version="otaInfo.versionNumber"
:progress="otaProgress" :progress="otaProgress"
:phase="otaPhase"
:description="''" :description="''"
:changelog="otaInfo.versionInfo" :changelog="otaInfo.versionInfo"
:forceUpdate="otaInfo.forceUpdate" :forceUpdate="otaInfo.forceUpdate"
@@ -460,6 +502,14 @@ onShareTimeline(() => {
@done="handleOtaDone" @done="handleOtaDone"
@retry="handleOtaRetry" @retry="handleOtaRetry"
/> />
<ModalDialog
:show="wifiRequiredVisible"
title="固件更新"
content="请在WiFi网络下更新"
confirmText="连接WiFi"
:showCancel="false"
:onConfirm="goWifiForOtaUpdate"
/>
<view class="container"> <view class="container">
<view class="top-theme"> <view class="top-theme">
<!-- <image <!-- <image
@@ -468,30 +518,91 @@ onShareTimeline(() => {
/> --> /> -->
</view> </view>
<UserHeader showRank :onSignin="() => (showModal = true)"/> <UserHeader showRank :onSignin="() => (showModal = true)"/>
<view :style="{ padding: '12px 10px' }"> <view :style="{ padding: '24rpx 20rpx' }">
<view class="feature-grid"> <view class="feature-grid">
<view class="bow-card"> <view class="bow-card">
<view
class="device-visual"
@click="$clickSound(() => toPage('/pages/device/my-device'))"
>
<image <image
v-if="online" class="device-visual-background"
src="https://static.shelingxingqiu.com/attachment/2025-08-07/dbvt1o6dvhr2rop3kn.webp" :src="deviceCardAsset.background"
mode="widthFix" mode="scaleToFill"
@click="() => toPage('/pages/my-device')"
/> />
<image <image
v-else class="device-visual-bow"
src="https://static.shelingxingqiu.com/attachment/2026-01-04/dffohwtk1gwh0xfa6h.png" :class="{ 'device-visual-bow--floating': deviceCardState === 'online' }"
mode="widthFix" :src="deviceCardAsset.bow"
@click="$clickSound(() => toPage('/pages/my-device'))" mode="scaleToFill"
/> />
<block v-if="user.id"> <view
<text v-if="!device.deviceId">绑定我的智能弓</text> v-if="user.id && deviceCardState === 'offline'"
<text v-else-if="!online">设备离线</text> class="device-status-badge device-status-badge--offline"
<text v-else-if="online">设备在线</text> @click.stop="$clickSound(() => toPage('/pages/device/my-device'))"
</block> >
<image <image
class="device-status-icon"
src="../static/home-device/device-state-dot--offline.png"
mode="scaleToFill"
/>
<text>未连接</text>
</view>
<view
v-if="user.id && deviceCardState === 'online'"
class="device-status-badge device-status-badge--online"
@click.stop="$clickSound(() => toPage('/pages/device/my-device'))"
>
<image
v-if="otaInfo.needUpdate"
class="device-status-refresh"
src="../static/home-device/device-state-refresh.png"
mode="scaleToFill"
/>
<view class="device-battery-value">
<image
class="device-battery-frame"
src="../static/home-device/device-state-battery.png"
mode="scaleToFill"
/>
<text class="device-battery-text">{{ deviceBattery === null ? "--" : deviceBattery }}</text>
</view>
<image
class="device-status-icon device-status-icon--online"
src="../static/home-device/device-state-dot--online.png"
mode="scaleToFill"
/>
</view>
<view
class="device-action-badge"
:class="`device-action-badge--${deviceCardState}`"
@click.stop="$clickSound(() => toPage('/pages/device/my-device'))"
>
<image
class="device-action-background"
:src="deviceCardAsset.actionBackground"
mode="scaleToFill"
/>
<image
v-if="deviceCardState === 'unbound'"
class="device-action-bind-icon"
src="../static/home-device/device-action-bind-icon.png"
mode="scaleToFill"
/>
<text
:class="{
'device-action-text--bound': deviceCardState !== 'unbound'
}"
>
{{ deviceCardState === "unbound" ? "绑定智能弓箭" : "我的设备" }}
</text>
</view>
</view>
<image
class="device-tutorial"
src="https://static.shelingxingqiu.com/shootmini/static/first-try.png" src="https://static.shelingxingqiu.com/shootmini/static/first-try.png"
mode="widthFix" mode="scaleToFill"
@click="() => toPage('/pages/first-try')" @click="$clickSound(() => toPage('/pages/first-try'))"
/> />
<BubbleTip v-if="showGuide" :location="{ top: '60%', left: '47%' }"> <BubbleTip v-if="showGuide" :location="{ top: '60%', left: '47%' }">
<text>新人必刷!</text> <text>新人必刷!</text>
@@ -599,7 +710,7 @@ onShareTimeline(() => {
.feature-grid { .feature-grid {
width: 100%; width: 100%;
display: flex; display: flex;
margin-bottom: 5px; margin-bottom: 10rpx;
} }
.feature-grid > view { .feature-grid > view {
@@ -614,22 +725,182 @@ onShareTimeline(() => {
overflow: hidden; overflow: hidden;
} }
.feature-grid > view > image { .device-visual {
position: relative;
width: 100%; width: 100%;
height: 390rpx;
overflow: hidden;
background: #16161e;
} }
.bow-card > text { .device-visual-background,
.device-visual-bow {
display: flex;
position: absolute; position: absolute;
top: 66%; pointer-events: none;
left: 50%;
transform: translate(-50%, -50%);
white-space: nowrap;
font-size: 13px;
color: #b3b3b3;
} }
.bow-card > image:nth-child(3) { .device-visual-background {
transform: translateY(-1px); top: 0;
left: 0;
width: 100%;
height: 100%;
}
.device-visual-bow {
top: 0;
left: 0;
width: 100%;
height: 388rpx;
}
.device-visual-bow--floating {
animation: device-bow-float 3s ease-in-out infinite;
}
@keyframes device-bow-float {
0%,
100% {
transform: translateY(0) rotate(-0.5deg);
}
50% {
transform: translateY(-10rpx) rotate(0.5deg);
}
}
.device-status-badge,
.device-action-badge {
display: flex;
align-items: center;
}
.device-status-badge {
position: absolute;
top: 10rpx;
right: 14rpx;
z-index: 2;
height: 34rpx;
color: #ffffff;
font-family: Inter-Regular, sans-serif;
font-size: 18rpx;
line-height: 18rpx;
}
.device-status-badge--online {
top: 9rpx;
right: 10rpx;
height: 36rpx;
}
.device-status-badge--offline .device-status-icon {
margin-right: 6rpx;
}
.device-status-badge--online .device-status-icon--online {
margin-left: 12rpx;
}
.device-status-icon {
width: 36rpx;
height: 36rpx;
}
.device-status-icon--online {
width: 36rpx;
height: 36rpx;
}
.device-status-refresh {
width: 36rpx;
height: 36rpx;
}
/* 三个状态项使用等大的方形槽位,电池框在槽位内垂直居中。 */
.device-battery-value {
position: relative;
width: 36rpx;
height: 36rpx;
margin-left: 12rpx;
}
.device-battery-frame {
position: absolute;
top: 0;
left: 0;
width: 38rpx;
height: 36rpx;
}
/* 文字容器只覆盖电池主体(60rpx),避开右侧凸起,使数字在框内水平垂直居中。 */
.device-battery-text {
position: absolute;
top: 9rpx;
left: 0x;
display: flex;
align-items: center;
justify-content: center;
width: 36rpx;
height: 20rpx;
font-size: 14rpx;
font-weight: 700;
line-height: 1;
}
.device-action-badge {
position: absolute;
bottom: 28rpx;
left: 50%;
z-index: 2;
width: 218rpx;
height: 56rpx;
justify-content: center;
transform: translateX(-50%);
color: #ffffff;
font-size: 22rpx;
font-weight: 700;
white-space: nowrap;
}
.device-action-badge--offline,
.device-action-badge--online {
width: 166rpx;
height: 44rpx;
font-size: 24rpx;
}
.device-action-background {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
}
.device-action-badge > text,
.device-action-bind-icon {
position: relative;
z-index: 1;
}
.device-action-text--bound {
background: linear-gradient(90deg, #fcfeef 0%, #fdeaa1 100%);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
.device-action-bind-icon {
width: 32rpx;
height: 32rpx;
margin-right: 8rpx;
}
.device-tutorial {
display: block;
width: 100%;
height: 114rpx;
} }
.play-card { .play-card {
@@ -642,8 +913,8 @@ onShareTimeline(() => {
} }
.ranking-section { .ranking-section {
border-radius: 15px; border-radius: 30rpx;
padding: 15px; padding: 30rpx;
position: relative; position: relative;
} }
@@ -657,23 +928,23 @@ onShareTimeline(() => {
.into-btn { .into-btn {
position: absolute; position: absolute;
top: 40px; top: 80rpx;
left: calc(50% - 100px); left: calc(50% - 200rpx);
width: 200px; width: 400rpx;
height: 100px; height: 200rpx;
} }
.ranking-players { .ranking-players {
display: flex; display: flex;
align-items: center; align-items: center;
padding-bottom: 20px; padding-bottom: 40rpx;
margin-top: 42%; margin-top: 42%;
border-bottom: 1rpx solid rgba(255, 255, 255, 0.2); border-bottom: 1rpx solid rgba(255, 255, 255, 0.2);
} }
.ranking-players > image:first-child { .ranking-players > image:first-child {
width: 28%; width: 28%;
transform: translateX(-10px) translateY(-8px); transform: translateX(-20rpx) translateY(-16rpx);
} }
.player-avatars { .player-avatars {
@@ -682,10 +953,10 @@ onShareTimeline(() => {
} }
.divide-line { .divide-line {
width: 1px; width: 2rpx;
height: 35px; height: 70rpx;
background-color: #80808033; background-color: #80808033;
margin-right: 8px; margin-right: 16rpx;
} }
.player-avatar, .player-avatar,
@@ -712,10 +983,10 @@ onShareTimeline(() => {
border-radius: 50%; border-radius: 50%;
background: #777777; background: #777777;
text-align: center; text-align: center;
font-size: 10px; font-size: 20rpx;
line-height: 18px; line-height: 36rpx;
width: 18px; width: 36rpx;
height: 18px; height: 36rpx;
color: #fff; color: #fff;
} }
@@ -727,20 +998,20 @@ onShareTimeline(() => {
.more-players { .more-players {
background: #3c445a; background: #3c445a;
font-size: 9px; font-size: 18rpx;
line-height: 80rpx; line-height: 80rpx;
text-align: center; text-align: center;
z-index: 1; z-index: 1;
} }
.more-players > text { .more-players > text {
margin-left: 2px; margin-left: 4rpx;
color: #fff; color: #fff;
} }
.my-data { .my-data {
display: flex; display: flex;
margin-top: 20px; margin-top: 40rpx;
justify-content: space-between; justify-content: space-between;
} }
@@ -750,7 +1021,7 @@ onShareTimeline(() => {
.my-data > view:first-child > image { .my-data > view:first-child > image {
width: 100%; width: 100%;
transform: translateX(-8px); transform: translateX(-16rpx);
} }
.my-data > view:nth-child(2) { .my-data > view:nth-child(2) {
@@ -767,7 +1038,7 @@ onShareTimeline(() => {
.my-data > view:nth-child(2) > view { .my-data > view:nth-child(2) > view {
width: 28%; width: 28%;
border-radius: 10px; border-radius: 20rpx;
background: linear-gradient(180deg, #303b4c 30%, #2c384a 100%); background: linear-gradient(180deg, #303b4c 30%, #2c384a 100%);
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -777,7 +1048,7 @@ onShareTimeline(() => {
.my-data > view:nth-child(2) > view > text:last-child { .my-data > view:nth-child(2) > view > text:last-child {
color: #fff; color: #fff;
line-height: 25px; line-height: 50rpx;
font-weight: 500; font-weight: 500;
} }
@@ -787,7 +1058,7 @@ onShareTimeline(() => {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
width: 100%; width: 100%;
height: 60px; height: 120rpx;
z-index: -1; z-index: -1;
} }
-526
View File
@@ -1,526 +0,0 @@
<script setup>
import { computed, ref } from "vue";
import { onShow } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import ScreenHint from "@/components/ScreenHint.vue";
import SButton from "@/components/SButton.vue";
import {
bindDeviceAPI,
getMyDevicesAPI,
unbindDeviceAPI,
laserAimAPI, bindDeviceAPIV2,
} from "@/apis";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const showTip = ref(false);
const confirmBindTip = ref(false);
const addDevice = ref();
const store = useStore();
const { updateDevice, clearDevice } = store;
const { user, device } = storeToRefs(store);
const justBind = ref(false);
const calibration = ref(false);
const token = ref(null);
const isSVip = computed(() => user.value.sVip === true);
const isVip = computed(() => user.value.vip === true && !isSVip.value);
// 扫描二维码方法
const handleScan = () => {
// 调用扫码API
uni.scanCode({
// 只支持扫码二维码
onlyFromCamera: true,
scanType: ["qrCode"],
success: async (res) => {
try {
// const base64Decode = (str) => {
// // 将 base64 转换为 utf8 字符串
// const bytes = wx.base64ToArrayBuffer(str);
// return String.fromCharCode.apply(null, new Uint8Array(bytes));
// };
//
// addDevice.value = JSON.parse(base64Decode(res.result));
token.value = res.result;
confirmBindTip.value = true;
} catch (err) {
uni.showToast({
title: "无效二维码",
icon: "none",
duration: 2000,
});
}
},
fail: (err) => {
console.error("扫码失败:", err);
uni.showToast({
title: "扫码失败",
icon: "error",
});
},
});
};
const confirmBind = async () => {
if (!justBind.value && token.value) {
const result = await bindDeviceAPIV2(token.value);
confirmBindTip.value = false;
if (result.binded) {
return uni.showToast({
title: "设备已绑定其他账号,请解绑后再绑定",
icon: "none",
});
}
updateDevice(result.deviceId, result.name);
justBind.value = true;
uni.showToast({
title: "绑定成功",
icon: "success",
});
}
};
const toFristTryPage = () => {
uni.navigateTo({
url: "/pages/first-try",
});
};
const unbindDevice = async () => {
try {
await unbindDeviceAPI(device.value.deviceId);
} catch (error) {
if (error?.type === "DEVICE_BIND_INVALID") {
uni.setStorageSync("calibration", false);
clearDevice();
}
return;
}
uni.setStorageSync("calibration", false);
uni.showToast({
title: "解绑成功",
icon: "success",
});
clearDevice();
};
/** 连接wifi跳转到wifi列表页面 */
const joinWifi = () => {
uni.navigateTo({ url: "/pages/ota-wifi" });
};
const toDeviceIntroPage = () => {
uni.navigateTo({
url: "/pages/device-intro",
});
};
const backToHome = () => {
uni.navigateBack();
};
const copyEmail = () => {
uni.setClipboardData({
data: "shelingxingqiu@163.com",
success: () => {
uni.showToast({
title: "邮箱已复制",
icon: "success",
});
},
});
};
const goCalibration = async () => {
await laserAimAPI();
uni.navigateTo({
url: "/pages/calibration",
});
};
const syncDeviceBinding = async () => {
if (!user.value.id) return;
try {
const devices = await getMyDevicesAPI();
if (devices.bindings && devices.bindings.length) {
updateDevice(devices.bindings[0].deviceId, devices.bindings[0].deviceName);
} else {
clearDevice();
}
} catch (error) {
console.log("sync device binding error", error);
}
};
onShow(async () => {
calibration.value = uni.getStorageSync("calibration");
await syncDeviceBinding();
});
</script>
<template>
<Container title="弓箭绑定">
<view v-if="!device.deviceId" class="scan-code">
<button hover-class="none" @click="$clickSound(handleScan)">
<image src="https://static.shelingxingqiu.com/shootmini/static/scan.png" mode="widthFix" />
</button>
<button hover-class="none" @click="showTip = true">
<text>扫</text>
<text :style="{ color: '#fed847' }">射灵弓箭</text>
<text>上的二维码</text>
<image src="../static/s-question-mark-white.png" mode="widthFix" />
</button>
<text>射灵智能弓箭,三模传感系统与独创靶环算法,</text>
<text>毫秒级在线实时对战,让你拥有全球约战的乐趣!</text>
<button hover-class="none" @click="toDeviceIntroPage">
<image src="https://static.shelingxingqiu.com/shootmini/static/have-no-device.png" mode="widthFix" />
</button>
<ScreenHint
mode="square"
:show="showTip"
:onClose="() => (showTip = false)"
>
<view class="scan-tips">
<text>扫码绑定设灵弓箭</text>
<image
src="https://static.shelingxingqiu.com/attachment/2025-08-05/dbuacrelri7jr3axiy.png"
mode="widthFix"
/>
<text>【注】已被绑定的弓箭无法再次绑定。</text>
<view>
<text>如有任何疑问,请随时联系:</text>
<button hover-class="none" @click="copyEmail">
shelingxingqiu@163.com
</button>
</view>
</view>
</ScreenHint>
<ScreenHint
:show="confirmBindTip"
:onClose="() => (confirmBindTip = false)"
>
<view class="confirm-bind">
<text
>智能弓箭和系统账号需一一对应,你确定要将<text
:style="{ color: '#fed847' }"
>当前登录用户账号</text
>绑定<text :style="{ color: '#fed847' }">这把弓箭</text>吗?
绑定后不可随意更换。</text
>
<view>
<view @click="confirmBind">确认绑定</view>
<view @click="() => (confirmBindTip = false)">取消</view>
</view>
</view>
</ScreenHint>
</view>
<view v-if="justBind" class="just-bind">
<view
class="device-binded"
:style="{ marginBottom: calibration ? '250rpx' : '100rpx' }"
>
<view>
<image src="https://static.shelingxingqiu.com/shootmini/static/device-icon.png" mode="widthFix" />
<text>{{ device.deviceName }}</text>
<view class="calibration" v-if="calibration">
<button hover-class="none" @click="goCalibration">
<text>重新校准</text>
<image src="../static/enter-arrow-blue.png" mode="widthFix" />
</button>
<view>
<image src="../static/calibration-tip.png" mode="widthFix" />
<text>如有场地/距离变化,需重新校准以保证智能弓射箭精准度</text>
</view>
</view>
</view>
<image src="../static/bind-success.png" mode="widthFix" />
<view>
<image
:src="user.avatar || '../static/user-icon.png'"
mode="widthFix"
:style="{ borderRadius: '50%' }"
/>
<view
:class="[
'member-nickname',
isVip ? 'member-nickname--vip' : '',
isSVip ? 'member-nickname--svip' : '',
]"
>
<text class="member-nickname__text">{{ user.nickName }}</text>
<text v-if="isSVip" class="member-nickname__shine">{{
user.nickName
}}</text>
</view>
</view>
</view>
<!-- <block v-if="calibration"> -->
<view>
<text>恭喜,你的弓箭和账号已成功绑定!</text>
<text :style="{ color: '#fed847' }">已赠送6个月射灵世界会员</text>
</view>
<!-- <SButton :onClick="goCalibration" width="60vw" :rounded="40">
开启智能弓进行校准
</SButton>
<text :style="{ marginTop: '20rpx', fontSize: '24rpx', color: '#fff9' }"
>校准时弓箭激光将开启,请勿直视激光</text
> -->
<view>
<SButton
:onClick="backToHome"
backgroundColor="#fff3"
color="#fff"
width="60vw"
:rounded="40"
>返回首页</SButton
>
</view>
<view :style="{ marginTop: '15px' }">
<SButton :onClick="toFristTryPage" width="60vw" :rounded="40">进入新手试炼</SButton>
</view>
<!-- </block> -->
<!-- <block v-else>
</block> -->
</view>
<view v-if="device.deviceId && !justBind" class="has-device">
<view class="device-binded">
<view>
<image src="https://static.shelingxingqiu.com/shootmini/static/device-icon.png" mode="widthFix" />
<text>{{ device.deviceName }}</text>
<view class="calibration">
<button hover-class="none" @click="goCalibration">
<text>去校准</text>
<image src="../static/enter-arrow-blue.png" mode="widthFix" />
</button>
<view>
<image src="../static/calibration-tip.png" mode="widthFix" />
<text
>首次绑定智能弓或场地/距离变化时,应进行校准以确保射箭精度</text
>
</view>
</view>
</view>
<image src="../static/bind.png" mode="widthFix" />
<view>
<image
:src="user.avatar || '../static/user-icon.png'"
mode="widthFix"
:style="{ borderRadius: '50%' }"
/>
<view
:class="[
'member-nickname',
isVip ? 'member-nickname--vip' : '',
isSVip ? 'member-nickname--svip' : '',
]"
>
<text class="member-nickname__text">{{ user.nickName }}</text>
<text v-if="isSVip" class="member-nickname__shine">{{
user.nickName
}}</text>
</view>
</view>
</view>
<view :style="{ marginTop: '240rpx' }">
<SButton :onClick="() => $clickSound(unbindDevice)" width="80vw" :rounded="40"
>解绑</SButton
>
</view>
<view :style="{ marginTop: '20rpx' }">
<SButton :onClick="() => $clickSound(joinWifi)" width="80vw" :rounded="40"
>设备连接WIFI</SButton
>
</view>
</view>
</Container>
</template>
<style scoped>
.scan-code,
.just-bind,
.has-device {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
width: 100%;
height: 100%;
}
.scan-code {
justify-content: flex-start;
}
.scan-code > button:first-child {
margin-top: 22%;
}
.scan-code > button:first-child > image {
width: 300rpx;
}
.scan-code > button:nth-child(2) {
display: flex;
align-items: center;
justify-content: center;
font-size: 26rpx;
color: #ffffff;
margin: 50rpx;
}
.scan-code > button:nth-child(2) > image {
width: 28rpx;
margin-left: 10rpx;
}
.scan-code > text {
font-size: 24rpx;
color: #fff9;
}
.scan-code > button:nth-child(5) {
margin-top: 25%;
}
.scan-code > button:nth-child(5) > image {
width: 380rpx;
}
.scan-tips {
display: flex;
flex-direction: column;
font-size: 14px;
width: 90%;
margin-top: 20%;
}
.scan-tips > text {
margin-bottom: 2px;
color: #fff;
font-size: 24rpx;
}
.scan-tips > text:first-child {
color: #fed847;
margin-bottom: 10px;
font-size: 32rpx;
}
.scan-tips > view {
display: flex;
flex-direction: column;
align-items: flex-start;
}
.scan-tips > view:last-child {
margin-top: 5px;
font-size: 26rpx;
}
.scan-tips > view:last-child > button {
font-size: 30rpx;
color: #39a8ff;
}
.scan-tips > image {
width: 100%;
margin-bottom: 10px;
}
.confirm-bind {
color: #fff9;
font-size: 14px;
}
.confirm-bind > view:last-child {
display: flex;
justify-content: space-between;
margin-top: 10px;
}
.confirm-bind > view:last-child > view {
width: 48%;
border-radius: 20px;
background-color: #fed847;
color: #000;
line-height: 40px;
text-align: center;
}
.confirm-bind > view:last-child > view:nth-child(2) {
color: #fff;
background-color: #fff3;
}
.device-binded {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
font-size: 14px;
margin-top: 200rpx;
}
.device-binded > view {
display: flex;
flex-direction: column;
align-items: center;
position: relative;
font-size: 26rpx;
}
.device-binded > view > image {
width: 140rpx;
height: 140rpx;
margin-bottom: 5px;
border-radius: 12px;
}
.device-binded > view > text {
width: 120px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: center;
}
.device-binded .member-nickname {
justify-content: center;
width: 120px;
}
.device-binded .member-nickname__text,
.device-binded .member-nickname__shine {
font-size: 26rpx;
text-align: center;
}
.device-binded > image {
width: 100rpx;
margin: 0 20px;
}
.has-device,
.just-bind {
justify-content: flex-start;
}
.has-device > view:nth-child(2),
.just-bind > view:nth-child(2) {
color: #fff9;
display: flex;
flex-direction: column;
align-items: center;
font-size: 28rpx;
margin-bottom: 100rpx;
}
.has-device > view:nth-child(2) > text,
.just-bind > view:nth-child(2) > text {
margin: 5px;
}
.calibration {
position: absolute;
bottom: -145rpx;
left: 20rpx;
}
.calibration > button {
font-size: 26rpx;
color: #287fff;
display: flex;
align-items: center;
padding-bottom: 15rpx;
padding-left: 50rpx;
}
.calibration > button > image {
width: 28rpx;
height: 28rpx;
}
.calibration > view {
position: relative;
font-size: 22rpx;
color: #fff9;
padding-top: 34rpx;
padding-left: 35rpx;
width: 322rpx;
}
.calibration > view > image {
position: absolute;
top: 0;
left: 0;
width: 370rpx;
}
</style>
+5 -34
View File
@@ -1,44 +1,15 @@
<script setup> <script setup>
import { ref, onMounted, onBeforeUnmount } from "vue"; import useStore from "@/store";
import { getDeviceBatteryAPI } from "@/apis"; import { storeToRefs } from "pinia";
const power = ref(0); const store = useStore();
const timer = ref(null); const { deviceBattery: power } = storeToRefs(store);
let disposed = false;
let requestInFlight = false;
const refreshPower = async () => {
if (disposed || requestInFlight) return;
requestInFlight = true;
try {
const data = await getDeviceBatteryAPI();
if (!disposed) power.value = data.battery;
} catch (_) {
// 电量轮询失败时等待下一轮,避免产生未处理的 Promise 拒绝。
} finally {
requestInFlight = false;
}
};
onMounted(async () => {
await refreshPower();
if (disposed) return;
timer.value = setInterval(() => {
void refreshPower();
}, 1000 * 10);
});
onBeforeUnmount(() => {
disposed = true;
clearInterval(timer.value);
timer.value = null;
});
</script> </script>
<template> <template>
<view class="container"> <view class="container">
<image src="../../../static/b-power.png" mode="widthFix" /> <image src="../../../static/b-power.png" mode="widthFix" />
<view>电量{{ power || 1 }}%</view> <view>{{ power === null ? "电量--" : `电量${power}%` }}</view>
</view> </view>
</template> </template>
@@ -111,7 +111,7 @@ const cancelMatching = async () => {
const goCalibration = async () => { const goCalibration = async () => {
await laserAimAPI(); await laserAimAPI();
uni.navigateTo({ uni.navigateTo({
url: "/pages/calibration", url: "/pages/device/calibration",
}); });
}; };
</script> </script>
@@ -89,7 +89,7 @@ const previewLines = computed(() => {
} }
.difficulty-preview__copy { .difficulty-preview__copy {
width: 80%; width: 84%;
margin: 0 auto; margin: 0 auto;
display: block; display: block;
color: #ffffff; color: #ffffff;
Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 944 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 850 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 371 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 294 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 687 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 413 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 841 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 B

+69 -1
View File
@@ -17,6 +17,16 @@ const getDefaultDevice = () => ({
deviceName: "", deviceName: "",
}); });
const getDefaultDeviceStatus = () => ({
battery: null,
charging: false,
version: "",
online: false,
netType: "",
onlineDuration: null,
receivedAt: 0,
});
const getDefaultGame = () => ({ const getDefaultGame = () => ({
roomID: "", roomID: "",
inBattle: false, inBattle: false,
@@ -100,6 +110,10 @@ export default defineStore("store", {
ringRank: [], ringRank: [],
}, },
online: false, online: false,
// 设备电量属于运行时状态,null 表示当前没有有效数据。
deviceBattery: null,
// WebSocket 实时推送的设备状态,不参与持久化。
deviceStatus: getDefaultDeviceStatus(),
game: { game: {
roomID: "", roomID: "",
inBattle: false, inBattle: false,
@@ -134,7 +148,56 @@ export default defineStore("store", {
this.rankData = { ...(data || {}) }; this.rankData = { ...(data || {}) };
}, },
updateOnline(online) { updateOnline(online) {
this.setDeviceOnline(online);
},
updateDeviceBattery(value) {
if (value === null || value === undefined || value === "") {
this.deviceBattery = null;
return;
}
const battery = Number(value);
this.deviceBattery = Number.isFinite(battery)
? Math.min(100, Math.max(0, battery))
: null;
},
updateDeviceStatus(status = {}) {
const battery = Number(status.battery ?? status.power);
const onlineDuration = Number(status.onlineDuration);
const online = status.online === true;
const nextStatus = {
battery: Number.isFinite(battery)
? Math.min(100, Math.max(0, battery))
: null,
charging: status.charging === true,
version: String(status.version ?? "").trim(),
online,
netType: String(status.netType ?? "").trim().toLowerCase(),
onlineDuration:
Number.isFinite(onlineDuration) && onlineDuration >= 0
? onlineDuration
: null,
receivedAt: Date.now(),
};
this.deviceStatus = nextStatus;
this.online = online; this.online = online;
this.deviceBattery = online ? nextStatus.battery : null;
},
setDeviceOnline(online) {
const nextOnline = online === true;
this.online = nextOnline;
if (nextOnline) {
this.deviceStatus = { ...this.deviceStatus, online: true };
return;
}
this.deviceBattery = null;
this.deviceStatus = getDefaultDeviceStatus();
},
clearDeviceStatus() {
this.online = false;
this.deviceBattery = null;
this.deviceStatus = getDefaultDeviceStatus();
}, },
async updateUser(user = {}) { async updateUser(user = {}) {
this.user = { ...getDefaultUser(), ...user }; this.user = { ...getDefaultUser(), ...user };
@@ -145,12 +208,15 @@ export default defineStore("store", {
); );
}, },
updateDevice(deviceId, deviceName) { updateDevice(deviceId, deviceName) {
if (String(this.device.deviceId || "") !== String(deviceId || "")) {
this.clearDeviceStatus();
}
this.device.deviceId = deviceId; this.device.deviceId = deviceId;
this.device.deviceName = deviceName; this.device.deviceName = deviceName;
}, },
clearDevice() { clearDevice() {
this.device = getDefaultDevice(); this.device = getDefaultDevice();
this.online = false; this.clearDeviceStatus();
}, },
async updateConfig(config) { async updateConfig(config) {
this.config = config; this.config = config;
@@ -199,6 +265,8 @@ export default defineStore("store", {
user: getDefaultUser(), user: getDefaultUser(),
device: getDefaultDevice(), device: getDefaultDevice(),
online: false, online: false,
deviceBattery: null,
deviceStatus: getDefaultDeviceStatus(),
game: getDefaultGame(), game: getDefaultGame(),
dailyCount: getDefaultDailyCount(), dailyCount: getDefaultDailyCount(),
deviceChargingDialogVisible: false, deviceChargingDialogVisible: false,
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -7,7 +7,7 @@ const { Reader, Writer } = protobuf;
// 所以这里使用 minimal Reader/Writer 做静态字段解码和客户端消息编码。 // 所以这里使用 minimal Reader/Writer 做静态字段解码和客户端消息编码。
// <match-schema-generated> // <match-schema-generated>
// 此区块由 scripts/generate-match-schema.mjs 自动生成,请勿手动修改。 // 此区块由 scripts/generate-match-schema.mjs 自动生成,请勿手动修改。
// 来源:src/utils/match.min.js(sha256: bece92f31bde3072) // 来源:src/utils/match.min.js(sha256: ec0371baeba9a9bf)
// 协议命名空间:rpc;消息数:12;字段数:163 // 协议命名空间:rpc;消息数:12;字段数:163
export const ServerMessageType = { export const ServerMessageType = {
@@ -188,7 +188,7 @@ const SCHEMAS = {
43: { name: "calories", kind: "double" }, 43: { name: "calories", kind: "double" },
44: { name: "score_slot", kind: "int32" }, 44: { name: "score_slot", kind: "int32" },
45: { name: "current_energy", kind: "int32" }, 45: { name: "current_energy", kind: "int32" },
46: { name: "energy_cost_per_sec", kind: "int32" }, 46: { name: "energy_cost_per_sec", kind: "float" },
47: { name: "energy_per_hit", kind: "int32" }, 47: { name: "energy_per_hit", kind: "int32" },
48: { name: "energy_req_percent", kind: "int32" }, 48: { name: "energy_req_percent", kind: "int32" },
49: { name: "delta_current_energy", kind: "int32" }, 49: { name: "delta_current_energy", kind: "int32" },
+28 -6
View File
@@ -77,17 +77,38 @@ function createWebSocket(token, onMessage) {
socketTask.onMessage((res) => { socketTask.onMessage((res) => {
if (socket !== socketTask) return; if (socket !== socketTask) return;
const { data, event } = JSON.parse(res.data); let response;
try {
response = JSON.parse(res.data);
} catch (err) {
console.error("WebSocket 消息解析失败", err);
return;
}
const { data, event, code, timestamp } = response || {};
if (event === "pong") return; if (event === "pong") return;
if (data.type) { const passthroughEvents = [
"/addons/shoot/battery",
"/addons/shoot/otaProgress",
"/addons/shoot/otaResult",
];
if (passthroughEvents.includes(event)) {
if ((code == null || Number(code) === 0) && onMessage && data && typeof data === "object") {
onMessage({ event, data, code, timestamp });
}
return;
}
if (data?.type) {
if (ENABLE_REALTIME_MESSAGE_LOG) { if (ENABLE_REALTIME_MESSAGE_LOG) {
console.log("收到 WebSocket 消息", getMessageTypeName(data.type)); console.log("收到 WebSocket 消息", getMessageTypeName(data.type));
} }
if (onMessage) onMessage({ ...(data.data || {}), type: data.type }); if (onMessage) onMessage({ ...(data.data || {}), type: data.type });
return; return;
} }
if (onMessage && data.updates) onMessage(data.updates); const updates = Array.isArray(data?.updates) ? data.updates : [];
const msg = data.updates[0]; if (!updates.length) return;
if (onMessage) onMessage(updates);
const msg = updates[0];
if (msg) { if (msg) {
if (ENABLE_REALTIME_MESSAGE_LOG) { if (ENABLE_REALTIME_MESSAGE_LOG) {
console.log( console.log(
@@ -101,9 +122,9 @@ function createWebSocket(token, onMessage) {
} else if (msg.constructor === MESSAGETYPES.LvlUpdate) { } else if (msg.constructor === MESSAGETYPES.LvlUpdate) {
uni.setStorageSync("latestLvl", msg.lvl); uni.setStorageSync("latestLvl", msg.lvl);
} else if (msg.constructor === MESSAGETYPES.DeviceOnline) { } else if (msg.constructor === MESSAGETYPES.DeviceOnline) {
uni.$emit("update-online"); uni.$emit("update-online", true);
} else if (msg.constructor === MESSAGETYPES.DeviceOffline) { } else if (msg.constructor === MESSAGETYPES.DeviceOffline) {
uni.$emit("update-online"); uni.$emit("update-online", false);
} else if (msg.constructor === MESSAGETYPES.DeviceCharging) { } else if (msg.constructor === MESSAGETYPES.DeviceCharging) {
uni.$emit("device-charging"); uni.$emit("device-charging");
} }
@@ -121,6 +142,7 @@ function createWebSocket(token, onMessage) {
stopHeartbeat(); stopHeartbeat();
socket = null; socket = null;
isConnecting = false; isConnecting = false;
uni.$emit("shoot-socket-disconnected");
if (manualClose || kickedOut) return; if (manualClose || kickedOut) return;
await handleUnexpectedClose(onMessage); await handleUnexpectedClose(onMessage);