This commit is contained in:
2025-09-14 01:58:23 +08:00
parent cbed8ff6ac
commit dd9228da0d
4 changed files with 27 additions and 16 deletions

11
app.js
View File

@@ -1,16 +1,15 @@
// app.js // app.js
App({ App({
onLaunch() { onLaunch() {
// 登录 // 登录
xhs.login({ xhs.login({
success: res => { success: (res) => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId // 发送 res.code 到后台换取 openId, sessionKey, unionId
console.log('login', res) console.log("login, code", res.code);
} },
}); });
}, },
globalData: { globalData: {
userInfo: null userInfo: null,
} },
}); });

View File

@@ -1,23 +1,23 @@
// index.js // index.js
const defaultAvatarUrl = import { getPhone } from '../../utils/get-phone.js';
"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0"; const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0';
Page({ Page({
data: { data: {
motto: "Hello World", motto: 'Hello World',
userInfo: { userInfo: {
avatarUrl: defaultAvatarUrl, avatarUrl: defaultAvatarUrl,
nickName: "", nickName: '',
}, },
hasUserInfo: false, hasUserInfo: false,
canIUseGetUserProfile: xhs.canIUse("getUserProfile"), canIUseGetUserProfile: xhs.canIUse('getUserProfile'),
canIUseNicknameComp: xhs.canIUse("input.type.nickname"), canIUseNicknameComp: xhs.canIUse('input.type.nickname'),
}, },
bindViewTap() {}, bindViewTap() {},
onChooseAvatar(e) { onChooseAvatar(e) {
const { avatarUrl } = e.detail; const { avatarUrl } = e.detail;
const { nickName } = this.data.userInfo; const { nickName } = this.data.userInfo;
this.setData({ this.setData({
"userInfo.avatarUrl": avatarUrl, 'userInfo.avatarUrl': avatarUrl,
hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
}); });
}, },
@@ -25,12 +25,12 @@ Page({
const nickName = e.detail.value; const nickName = e.detail.value;
const { avatarUrl } = this.data.userInfo; const { avatarUrl } = this.data.userInfo;
this.setData({ this.setData({
"userInfo.nickName": nickName, 'userInfo.nickName': nickName,
hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
}); });
}, },
getUserProfile(e) { getUserProfile(e) {
console.log("user -profile", e); console.log('user -profile', e);
// 推荐使用xhs.getUserProfile获取用户信息开发者每次通过该接口获取用户个人信息均需用户确认开发者妥善保管用户快速填写的头像昵称避免重复弹窗 // 推荐使用xhs.getUserProfile获取用户信息开发者每次通过该接口获取用户个人信息均需用户确认开发者妥善保管用户快速填写的头像昵称避免重复弹窗
const userInfo = e.detail.userInfo; const userInfo = e.detail.userInfo;
this.setData({ this.setData({
@@ -38,4 +38,9 @@ Page({
hasUserInfo: true, hasUserInfo: true,
}); });
}, },
getPhoneNumber(e) {
const { detail } = e;
// console.log('e', detail);
getPhone(detail);
},
}); });

View File

@@ -23,5 +23,8 @@
<view class="usermotto"> <view class="usermotto">
<text class="user-motto">{{motto}}</text> <text class="user-motto">{{motto}}</text>
</view> </view>
<view class="userphone">
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">获取手机号</button>
</view>
</view> </view>
</scroll-view> </scroll-view>

4
utils/get-phone.js Normal file
View File

@@ -0,0 +1,4 @@
export const getPhone = (data) => {
console.log("getPhone", data);
return data;
}