From 5cf243d187369e7909036bedfe449dd25cd37389 Mon Sep 17 00:00:00 2001 From: zhangyi <690096405@qq.com> Date: Thu, 11 Jun 2026 18:10:59 +0800 Subject: [PATCH] =?UTF-8?q?update:=E4=BC=98=E5=8C=96=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 10 +++++++++- src/apis.js | 9 +++++++++ src/components/Signin.vue | 4 +++- src/pages/index.vue | 3 +++ src/pages/my-device.vue | 31 +++++++++++++++++++++++++++---- src/store.js | 4 ++++ 6 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/App.vue b/src/App.vue index c852548..08b356c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -22,7 +22,8 @@ const { updateUser, updateOnline, - clearSessionState + clearSessionState, + clearDevice } = store; watch( @@ -63,6 +64,11 @@ updateOnline(data.online); } + function onDeviceBindInvalid() { + clearDevice(); + uni.setStorageSync("calibration", false); + } + function onDeviceShoot() { // audioManager.play("射箭声音") } @@ -78,6 +84,7 @@ uni.$on("update-user", emitUpdateUser); uni.$on("update-online", emitUpdateOnline); uni.$on("session-kicked-out", onSessionKickedOut); + uni.$on("device-bind-invalid", onDeviceBindInvalid); const token = uni.getStorageSync( `${uni.getAccountInfoSync().miniProgram.envVersion}_token` ); @@ -91,6 +98,7 @@ uni.$off("update-user", emitUpdateUser); uni.$off("update-online", emitUpdateOnline); uni.$off("session-kicked-out", onSessionKickedOut); + uni.$off("device-bind-invalid", onDeviceBindInvalid); websocket.closeWebSocket(); }); diff --git a/src/apis.js b/src/apis.js index 305a040..a816bf7 100644 --- a/src/apis.js +++ b/src/apis.js @@ -70,6 +70,15 @@ function request(method, url, data = {}) { resolve({binded: true}); return; } + if (message === "BIND_FAILD") { + uni.$emit("device-bind-invalid"); + uni.showToast({ + title: "设备绑定状态已失效,请重新绑定", + icon: "none", + }); + reject({type: "DEVICE_BIND_INVALID", message}); + return; + } if (message === "ERROR_ORDER_UNPAY") { uni.showToast({ title: "当前有未支付订单", diff --git a/src/components/Signin.vue b/src/components/Signin.vue index 619d681..8879378 100644 --- a/src/components/Signin.vue +++ b/src/components/Signin.vue @@ -16,7 +16,7 @@ import { import useStore from "@/store"; const store = useStore(); -const { updateUser, updateDevice, updateOnline } = store; +const { updateUser, updateDevice, updateOnline, clearDevice } = store; const props = defineProps({ show: { @@ -107,6 +107,8 @@ async function doLogin() { ); const data = await getDeviceBatteryAPI(); updateOnline(data.online); + } else { + clearDevice(); } props.onClose(); } catch (error) { diff --git a/src/pages/index.vue b/src/pages/index.vue index bedd679..ae2e860 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -26,6 +26,7 @@ const { updateConfig, updateUser, updateDevice, + clearDevice, getLvlName, getLvlNameByScore, updateOnline, @@ -127,6 +128,8 @@ onShow(async () => { ); const data = await getDeviceBatteryAPI(); updateOnline(data.online); + } else { + clearDevice(); } } } diff --git a/src/pages/my-device.vue b/src/pages/my-device.vue index ad58d3c..c6313b9 100644 --- a/src/pages/my-device.vue +++ b/src/pages/my-device.vue @@ -16,7 +16,7 @@ const showTip = ref(false); const confirmBindTip = ref(false); const addDevice = ref(); const store = useStore(); -const { updateDevice } = store; +const { updateDevice, clearDevice } = store; const { user, device } = storeToRefs(store); const justBind = ref(false); const calibration = ref(false); @@ -84,13 +84,21 @@ const toFristTryPage = () => { }; const unbindDevice = async () => { - await unbindDeviceAPI(device.value.deviceId); + 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", }); - device.value = {}; + clearDevice(); }; const toDeviceIntroPage = () => { @@ -122,8 +130,23 @@ const goCalibration = async () => { }); }; -onShow(() => { +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(); }); diff --git a/src/store.js b/src/store.js index bacc5e5..57bf43e 100644 --- a/src/store.js +++ b/src/store.js @@ -137,6 +137,10 @@ export default defineStore("store", { this.device.deviceId = deviceId; this.device.deviceName = deviceName; }, + clearDevice() { + this.device = getDefaultDevice(); + this.online = false; + }, async updateConfig(config) { this.config = config; if (this.user.scores !== undefined) {