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}} {{form.mobile}}
</view> </view>
<view v-else> <view v-else>
<view class="submit" @click="navigateTo(form.username)">绑定手机号码</view> <view class="submit" style="text-align: left;" @click="navigateTo(form.username)">绑定手机号码</view>
</view> </view>
</u-form-item> </u-form-item>
@@ -59,8 +59,8 @@ export default {
region: storage.getUserInfo().region || [], //地址 region: storage.getUserInfo().region || [], //地址
sex: storage.getUserInfo().sex, //性别 sex: storage.getUserInfo().sex, //性别
___path: storage.getUserInfo().region, ___path: storage.getUserInfo().region,
mobile: storage.getUserInfo().mobile, mobile: storage.getUserInfo().mobile,
username: storage.getUserInfo().username, username: storage.getUserInfo().username,
}, },
birthday: storage.getUserInfo().birthday || "", //生日 birthday: storage.getUserInfo().birthday || "", //生日
photo: [ photo: [
@@ -183,6 +183,24 @@ export default {
* 加载数据 * 加载数据
*/ */
onLoad() {}, 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> </script>
<style> <style>
@@ -201,6 +219,7 @@ page{
margin: 0 auto; margin: 0 auto;
color: $main-color; color: $main-color;
border-radius: 100px; border-radius: 100px;
} }
.head { .head {
height: 260rpx; height: 260rpx;

View File

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