feat: 更新用户信息获取逻辑

- 在personMsg.vue中添加onShow生命周期钩子,重新获取用户信息并更新表单数据
- 在bindMobile.vue中绑定手机成功后,获取最新用户信息并更新缓存
- 调整绑定手机按钮的样式以改善用户体验
This commit is contained in:
Yer11214
2025-09-16 10:39:10 +08:00
parent 83da8f3003
commit 3219f6d576
2 changed files with 47 additions and 19 deletions

View File

@@ -28,7 +28,7 @@
{{form.mobile}}
</view>
<view v-else>
<view class="submit" @click="navigateTo(form.username)">绑定手机号码</view>
<view class="submit" style="text-align: left;" @click="navigateTo(form.username)">绑定手机号码</view>
</view>
</u-form-item>
@@ -59,8 +59,8 @@ export default {
region: storage.getUserInfo().region || [], //地址
sex: storage.getUserInfo().sex, //性别
___path: storage.getUserInfo().region,
mobile: storage.getUserInfo().mobile,
username: storage.getUserInfo().username,
mobile: storage.getUserInfo().mobile,
username: storage.getUserInfo().username,
},
birthday: storage.getUserInfo().birthday || "", //生日
photo: [
@@ -183,6 +183,24 @@ export default {
* 加载数据
*/
onLoad() {},
/**
* 页面显示时执行
*/
onShow() {
// 从缓存中重新获取用户信息
const userInfo = storage.getUserInfo();
// 更新表单数据
this.form.nickName = userInfo.nickName || "";
this.form.birthday = userInfo.birthday || "";
this.form.face = userInfo.face || "/static/missing-face.png";
this.form.region = userInfo.region || [];
this.form.sex = userInfo.sex;
this.form.___path = userInfo.region;
this.form.mobile = userInfo.mobile;
this.form.username = userInfo.username;
this.birthday = userInfo.birthday || "";
},
};
</script>
<style>
@@ -201,6 +219,7 @@ page{
margin: 0 auto;
color: $main-color;
border-radius: 100px;
}
.head {
height: 260rpx;

View File

@@ -30,13 +30,15 @@
</template>
<script>
import {
sendMobile,
bindMobile
} from "@/api/login";
import {
sendMobile,
bindMobile
} from "@/api/login";
import { getUserInfo } from "@/api/members.js";
import storage from "@/utils/storage.js";
import myVerification from "@/components/verification/verification.vue"; //验证
import uuid from "@/utils/uuid.modified.js";
import myVerification from "@/components/verification/verification.vue"; //验证
import uuid from "@/utils/uuid.modified.js";
export default {
components: {
myVerification,
@@ -123,17 +125,24 @@
bindMobile(this.codeForm).then((res) => {
if (res.data.success) {
this.validateFlage = !this.validateFlage;
// 登录成功
uni.showToast({
title: "绑定成功!",
duration: 2000,
icon: "none",
});
setTimeout(() => {
uni.navigateBack({
delta: 1,
// 获取最新的用户信息并更新缓存
getUserInfo().then(userRes => {
if (userRes.data.success) {
storage.setUserInfo(userRes.data.result);
}
// 显示成功提示
uni.showToast({
title: "绑定成功!",
duration: 2000,
icon: "none",
});
}, 1000);
// 返回上一页
setTimeout(() => {
uni.navigateBack({
delta: 1,
});
}, 1000);
});
}
});
}