diff --git a/src/apis.js b/src/apis.js index 210f24c..48bca6b 100644 --- a/src/apis.js +++ b/src/apis.js @@ -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); diff --git a/src/components/SButton.vue b/src/components/SButton.vue index 7881366..12b5b18 100644 --- a/src/components/SButton.vue +++ b/src/components/SButton.vue @@ -16,6 +16,14 @@ const props = defineProps({ type: Boolean, default: false, }, + backgroundColor: { + type: String, + default: "#fed847", + }, + color: { + type: String, + default: "#000", + }, }); @@ -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({ diff --git a/src/components/Signin.vue b/src/components/Signin.vue index 9f78069..eb5848e 100644 --- a/src/components/Signin.vue +++ b/src/components/Signin.vue @@ -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 @@ -96,7 +96,7 @@ const handleLogin = () => { type="nickname" class="nickname-input" placeholder="请输入昵称" - placeholder-style="color: #ccc" + placeholder-style="color: #ccc" @change="onNicknameChange" @blur="onNicknameBlur" /> diff --git a/src/constants.js b/src/constants.js index 968f451..9ce8e9b 100644 --- a/src/constants.js +++ b/src/constants.js @@ -12,7 +12,7 @@ export const MESSAGETYPES = { RoundPoint: 4061248646, UserEnterRoom: 2133805521, UserExitRoom: 3896523333, - RoomDestroy: 389652333311, + RoomDestroy: 3617539277, }; export const roundsName = { diff --git a/src/pages/index.vue b/src/pages/index.vue index dc800fa..2537268 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -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 diff --git a/src/pages/my-device.vue b/src/pages/my-device.vue index 15765c1..5651cc0 100644 --- a/src/pages/my-device.vue +++ b/src/pages/my-device.vue @@ -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(); +};