ZJCF_miniProgram/pages/index/index.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-12-07 10:20:50 +08:00
// index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
const app=getApp()
Page({
data: {
userInfo: {
avatarUrl: defaultAvatarUrl,
nickName: '',
},
userName: '',
},
onChooseAvatar(e) {
const {
avatarUrl
} = e.detail
this.setData({
userInfo: {
avatarUrl
},
})
},
iptHandler(e) {
const nickName = e.detail.value
this.setData({
// 通过e.detail.value获取到文本框最新的值
userName: nickName,
})
},
onLogin() {
if (this.data.userInfo.avatarUrl != defaultAvatarUrl && this.data.userName != '') {
wx.clearStorageSync('userInfo')
var userInfo = {
avatarUrl: '',
nickName: ''
}
userInfo.avatarUrl = this.data.userInfo.avatarUrl
userInfo.nickName = this.data.userName
wx.showToast({
title: '登录中',
icon: "loading",
duration: 800,
complete() {
app.globalData.userInfo=userInfo
app.globalData.hasUserInfo=true;
wx.switchTab({
url: '/pages/intro/intro'
})
}
});
} else {
wx.showToast({
title: '请输入用户头像及昵称',
icon: "error",
duration: 2000
});
}
}
})