用户中心逻辑完善

This commit is contained in:
kron
2025-12-31 11:56:45 +08:00
parent 910530748d
commit 25f51ad53a
2 changed files with 26 additions and 9 deletions

View File

@@ -7,7 +7,7 @@ import Avatar from "@/components/Avatar.vue";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user, device } = storeToRefs(store);
const { user, device, online } = storeToRefs(store);
const { updateUser } = store;
const toOrderPage = () => {
@@ -16,13 +16,20 @@ const toOrderPage = () => {
});
};
const toFristTryPage = () => {
const toFristTryPage = async () => {
if (!online.value) {
return uni.showToast({
title: "智能弓未连接",
icon: "none",
});
}
if (!device.value.deviceId) {
return uni.showToast({
title: "请先绑定设备",
icon: "none",
});
}
await uni.$checkAudio();
uni.navigateTo({
url: "/pages/first-try",
});
@@ -75,9 +82,15 @@ onMounted(() => {
<template>
<Container title="用户信息">
<scroll-view :style="{ width: '100%' }">
<view :style="{ width: '100%', height: '100%' }">
<UserHeader />
<view class="container">
<scroll-view
scroll-y
:show-scrollbar="false"
:enhanced="true"
class="container"
>
<view :style="{ height: '10px' }"></view>
<UserItem title="用户名">{{ user.nickName }}</UserItem>
<UserItem title="头像">
<Avatar :src="user.avatar" :size="35" />
@@ -141,17 +154,17 @@ onMounted(() => {
:onClick="logout"
v-if="showLogout"
/>
</view>
</scroll-view>
<view :style="{ height: '10px' }"></view>
</scroll-view>
</view>
</Container>
</template>
<style scoped>
.container {
background-color: #f5f5f5;
height: calc(100vh - 161px);
margin-top: 20px;
padding-top: 10px;
height: calc(100% - 65px);
margin-top: 15px;
}
.my-grow {
width: 100%;

View File

@@ -49,6 +49,7 @@ export default defineStore("store", {
rank: [],
ringRank: [],
},
online: false,
}),
// 计算属性
@@ -69,6 +70,9 @@ export default defineStore("store", {
updateRank(data = {}) {
this.rankData = { ...(data || {}) };
},
updateOnline(online) {
this.online = online;
},
async updateUser(user = {}) {
this.user = { ...defaultUser, ...user };
if (this.user.rankLvl !== undefined) {