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({
onLaunch() {
// 登录
xhs.login({
success: res => {
success: (res) => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
console.log('login', res)
}
console.log("login, code", res.code);
},
});
},
globalData: {
userInfo: null
}
userInfo: null,
},
});

View File

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

View File

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