123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- // pages/login/login.js
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- // 功能列表
- funclist: [
- {
- title: "我的订单", icon: "todo-list", require: true, success () {
- wx.navigateTo({
- url: `/pages/order/order`,
- })
- }
- },
- {
- title: "我的余额", icon: "balance-list", require: true, success () {
- wx.navigateTo({
- url: `/pages/balance/balance`,
- })
- }
- },
- {
- title: "学生管理", icon: "friends", require: true, success () {
- wx.navigateTo({
- url: `/pages/adddata/adddata`,
- })
- }
- },
- ]
- },
- // 功能事件
- state: false,//用户登录状态
- CellSuccess (e) {
- let { require = false, index } = e.currentTarget.dataset, { funclist } = this.data;
- if (require && this.state) {
- funclist[index]["success"]();
- return false;
- }
- if (require) {
- wx.navigateTo({
- url: '/pages/sgin/sgin',
- })
- return false;
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- wx.lxd.Ctr({
- // nav
- title: "我的", //标题
- back: false,//返回按钮,tabber必须false(除非会改)
- bgc: true,//使用更改后的颜色
- // tabber
- tabber: true,//显示
- active: 2,//活动值
- })
- },
- // 登录页面
- sgin () {
- wx.navigateTo({
- url: '/pages/sgin/sgin',
- })
- },
- // 更新资料
- newbtn () {
- if (!this.state) {
- wx.navigateTo({
- url: '/pages/sgin/sgin',
- })
- return false;
- }
- let { axios } = app.globalData, that = this;
- wx.getUserProfile({
- desc: '用于完善会员资料',
- success: (res) => {
- app.globalData.encryptedData = res.encryptedData;
- app.globalData.iv = res.iv;
- let { appid, user, iv, encryptedData } = app.globalData, { openid } = user;
- login_face(appid, openid, iv, encryptedData).then(res => {
- let { face, name } = res.data.data;
- user = { ...user, face, name };
- app.globalData["user"] = user;
- wx.lxd.Notify({
- message: "更新完毕",
- type: "success",
- icon: 'certificate'
- })
- that.setData({
- user
- })
- })
- }
- })
- function login_face (appid, openid, iv, encryptedData) {
- return new Promise((resovle, reject) => {
- axios({
- method: 'post',
- url: "/account/setUserInfo/",
- data: {
- appid, openid, iv, encryptedData
- },
- success (res) {
- resovle(res)
- }
- })
- })
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- let { user, token } = app.globalData;
- this.setData({ user });
- this.state = token();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- })
|