Files
jd-code-exchange/pages/index/index.js
2025-09-14 00:00:03 +08:00

42 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// index.js
const defaultAvatarUrl =
"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0";
Page({
data: {
motto: "Hello World",
userInfo: {
avatarUrl: defaultAvatarUrl,
nickName: "",
},
hasUserInfo: false,
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,
hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
});
},
onInputChange(e) {
const nickName = e.detail.value;
const { avatarUrl } = this.data.userInfo;
this.setData({
"userInfo.nickName": nickName,
hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
});
},
getUserProfile(e) {
console.log("user -profile", e);
// 推荐使用xhs.getUserProfile获取用户信息开发者每次通过该接口获取用户个人信息均需用户确认开发者妥善保管用户快速填写的头像昵称避免重复弹窗
const userInfo = e.detail.userInfo;
this.setData({
userInfo: userInfo,
hasUserInfo: true,
});
},
});