修复绑定设备BUG
This commit is contained in:
@@ -12,6 +12,12 @@ function request(method, url, data = {}) {
|
||||
data,
|
||||
success: (res) => {
|
||||
if (res.data.code === 0) resolve(res.data.data);
|
||||
else {
|
||||
uni.showToast({
|
||||
title: res.data.message,
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
|
||||
@@ -16,6 +16,14 @@ const props = defineProps({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
backgroundColor: {
|
||||
type: String,
|
||||
default: "#fed847",
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
default: "#000",
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -26,7 +34,8 @@ const props = defineProps({
|
||||
:style="{
|
||||
width: width,
|
||||
borderRadius: rounded + 'px',
|
||||
backgroundColor: disabled ? '#757575' : '#fed847',
|
||||
backgroundColor: disabled ? '#757575' : backgroundColor,
|
||||
color,
|
||||
}"
|
||||
open-type="getUserInfo"
|
||||
@click="
|
||||
@@ -42,14 +51,13 @@ const props = defineProps({
|
||||
<style scoped>
|
||||
.sbtn {
|
||||
margin: 0 auto;
|
||||
height: 40px;
|
||||
line-height: 40px;
|
||||
height: 44px;
|
||||
line-height: 44px;
|
||||
font-weight: bold;
|
||||
font-size: 15px;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
color: #000;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -57,7 +57,7 @@ const handleLogin = () => {
|
||||
avatarUrl: avatarUrl.value,
|
||||
});
|
||||
const devices = await getMyDevicesAPI();
|
||||
if (devices.bindings.length) {
|
||||
if (devices.bindings && devices.bindings.length) {
|
||||
updateDevice(
|
||||
devices.bindings[0].deviceId,
|
||||
devices.bindings[0].deviceName
|
||||
|
||||
@@ -12,7 +12,7 @@ export const MESSAGETYPES = {
|
||||
RoundPoint: 4061248646,
|
||||
UserEnterRoom: 2133805521,
|
||||
UserExitRoom: 3896523333,
|
||||
RoomDestroy: 389652333311,
|
||||
RoomDestroy: 3617539277,
|
||||
};
|
||||
|
||||
export const roundsName = {
|
||||
|
||||
@@ -46,7 +46,7 @@ onMounted(async () => {
|
||||
if (result.user) {
|
||||
updateUser(result.user);
|
||||
const devices = await getMyDevicesAPI();
|
||||
if (devices.bindings.length) {
|
||||
if (devices.bindings && devices.bindings.length) {
|
||||
updateDevice(
|
||||
devices.bindings[0].deviceId,
|
||||
devices.bindings[0].deviceName
|
||||
|
||||
@@ -8,41 +8,28 @@ import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
const showTip = ref(false);
|
||||
const confirmBindTip = ref(false);
|
||||
const device = ref({
|
||||
id: "wefefweee",
|
||||
deviceName: "DS3F298SDfF",
|
||||
});
|
||||
const addDevice = ref();
|
||||
const loading = ref(true);
|
||||
const store = useStore();
|
||||
const { user } = storeToRefs(store);
|
||||
const { updateDevice } = store;
|
||||
const { user, device } = storeToRefs(store);
|
||||
const justBind = ref(false);
|
||||
|
||||
const step = ref(1);
|
||||
|
||||
onMounted(async () => {
|
||||
const result = await getMyDevicesAPI();
|
||||
loading.value = false;
|
||||
device.value = result.bindings[0] || {};
|
||||
});
|
||||
|
||||
// 扫描二维码方法
|
||||
const handleScan = () => {
|
||||
const { user } = useStore();
|
||||
if (!user.id) {
|
||||
return uni.showToast({
|
||||
title: "请先登录",
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
// 调用扫码API
|
||||
uni.scanCode({
|
||||
// 只支持扫码二维码
|
||||
onlyFromCamera: true,
|
||||
scanType: ["qrCode"],
|
||||
success: async (res) => {
|
||||
addDevice.value = JSON.parse(atob(res.result));
|
||||
confirmBindTip = true;
|
||||
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));
|
||||
confirmBindTip.value = true;
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error("扫码失败:", err);
|
||||
@@ -55,14 +42,15 @@ const handleScan = () => {
|
||||
};
|
||||
|
||||
const confirmBind = async () => {
|
||||
if (addDevice.value.deviceId) {
|
||||
if (addDevice.value.id) {
|
||||
await bindDeviceAPI(addDevice.value);
|
||||
updateDevice(addDevice.value.id, addDevice.value.name);
|
||||
confirmBindTip.value = false;
|
||||
justBind.value = true;
|
||||
uni.showToast({
|
||||
title: "绑定成功",
|
||||
icon: "success",
|
||||
});
|
||||
step.value = 2;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -86,11 +74,15 @@ const toDeviceIntroPage = () => {
|
||||
url: "/pages/device-intro",
|
||||
});
|
||||
};
|
||||
|
||||
const backToHome = () => {
|
||||
uni.navigateBack();
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Container title="弓箭绑定">
|
||||
<view v-if="!loading && !device.deviceId" class="scan-code">
|
||||
<view v-if="!device.deviceId" class="scan-code">
|
||||
<view @click="handleScan">
|
||||
<image src="../static/scan.png" mode="widthFix" />
|
||||
<text>扫码绑定弓箭</text>
|
||||
@@ -155,8 +147,13 @@ const toDeviceIntroPage = () => {
|
||||
<text>赶快进入新手试炼场体验一下吧!</text>
|
||||
</view>
|
||||
<SButton :onClick="toFristTryPage">进入新手试炼</SButton>
|
||||
<view :style="{ marginTop: '15px' }">
|
||||
<SButton :onClick="backToHome" backgroundColor="#fff3" color="#fff"
|
||||
>返回首页</SButton
|
||||
>
|
||||
</view>
|
||||
<view v-if="!loading && device.deviceId && !justBind" class="has-device">
|
||||
</view>
|
||||
<view v-if="device.deviceId && !justBind" class="has-device">
|
||||
<view class="device-binded">
|
||||
<view @click="toDeviceIntroPage">
|
||||
<image src="../static/device-icon.png" mode="widthFix" />
|
||||
@@ -233,6 +230,8 @@ const toDeviceIntroPage = () => {
|
||||
}
|
||||
.confirm-bind {
|
||||
transform: translateY(36px);
|
||||
color: #fff9;
|
||||
font-size: 14px;
|
||||
}
|
||||
.confirm-bind > view:last-child {
|
||||
display: flex;
|
||||
@@ -258,7 +257,7 @@ const toDeviceIntroPage = () => {
|
||||
justify-content: center;
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
margin: 75px 0;
|
||||
margin: 100px 0;
|
||||
}
|
||||
.device-binded > view {
|
||||
display: flex;
|
||||
@@ -267,6 +266,7 @@ const toDeviceIntroPage = () => {
|
||||
}
|
||||
.device-binded > view > image {
|
||||
width: 24vw;
|
||||
height: 24vw;
|
||||
margin-bottom: 5px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user