微信小程序-更改个人信息

wxml代码:

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找到储存在数据库中的信息,并根据微信开放文档给出的函数来进行数据的增删改查。

你可能感兴趣的:(微信小程序,小程序)