wxml代码:
<view class="user-info" bindtap="authorize">
<view class="info-one">
<view hidden="{{info_hidden}}">
<image src="{{userImg}}" class="pic"></image>
</view>
<view hidden="{{!info_hidden}}">
<image src="/images/user-unlogin.png" class="pic"></image>
</view>
<view class="name">{{userName}}</view>
</view>
<view class="info-two" bindtap="change" hidden="{{info_hidden}}">
<view class="school">
<view hidden="{{info_hidden}}">
<image src="/images/xuexiao.png" class="icon"></image>
</view>
<view class="text">{{userSchool}}</view>
</view>
<view class="school">
<view hidden="{{info_hidden}}">
<image src="/images/xueyuan.png" class="icon"></image>
</view>
<view class="text">{{userFaculty}}</view>
</view>
</view>
</view>
js代码:
// pages/mine/mine.js
const db = wx.cloud.database()
const userInfo = db.collection('User-Info')
Page({
/**
* 页面的初始数据
*/
data: {
userImg: null,
userName: "点击登录",
userOpenid: null,
userSchool: '',
userFaculty: '',
showModal: false,
change: false,
info_hidden: true,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var app = getApp()
var that = this
app.globalData.isMyFile = false
app.globalData.isMyQes = false
console.log(app.globalData.userInfo.userSchool)
setTimeout(function () {
if (app.globalData.userInfo.userSchool != '') {
that.setData({
userImg: app.globalData.userInfo.avatarUrl,
userName: app.globalData.userInfo.nickName,
userOpenid: app.globalData.userInfo.openid,
userSchool: app.globalData.userInfo.userSchool,
userFaculty: app.globalData.userInfo.userFaculty,
info_hidden: false
})
} else {
that.setData({
info_hidden: true,
})
}
}, 1000)
},
onShow: function () {
this.onLoad()
},
//点击头像授权登录
authorize: function () {
if(getApp().globalData.userInfo.userSchool == ''){
wx.navigateTo({
url: '../load/load',
})
}
},
//修改信息
change: function () {
this.setData({
showModal: true
})
},
school: function (e) {
this.setData({
userSchool: e.detail.value,
change: true
})
},
faculty: function (e) {
this.setData({
userFaculty: e.detail.value,
change: true
})
},
})
原理是根据用户的userInfo找到储存在数据库中的信息,并根据微信开放文档给出的函数来进行数据的增删改查。
|