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