login.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // pages/login/login.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. // 功能列表
  9. funclist: [
  10. {
  11. title: "我的订单", icon: "todo-list", require: true, success () {
  12. wx.navigateTo({
  13. url: `/pages/order/order`,
  14. })
  15. }
  16. },
  17. {
  18. title: "我的余额", icon: "balance-list", require: true, success () {
  19. wx.navigateTo({
  20. url: `/pages/balance/balance`,
  21. })
  22. }
  23. },
  24. {
  25. title: "学生管理", icon: "friends", require: true, success () {
  26. wx.navigateTo({
  27. url: `/pages/adddata/adddata`,
  28. })
  29. }
  30. },
  31. ]
  32. },
  33. // 功能事件
  34. state: false,//用户登录状态
  35. CellSuccess (e) {
  36. let { require = false, index } = e.currentTarget.dataset, { funclist } = this.data;
  37. if (require && this.state) {
  38. funclist[index]["success"]();
  39. return false;
  40. }
  41. if (require) {
  42. wx.navigateTo({
  43. url: '/pages/sgin/sgin',
  44. })
  45. return false;
  46. }
  47. },
  48. /**
  49. * 生命周期函数--监听页面加载
  50. */
  51. onLoad: function (options) {
  52. wx.lxd.Ctr({
  53. // nav
  54. title: "我的", //标题
  55. back: false,//返回按钮,tabber必须false(除非会改)
  56. bgc: true,//使用更改后的颜色
  57. // tabber
  58. tabber: true,//显示
  59. active: 2,//活动值
  60. })
  61. },
  62. // 登录页面
  63. sgin () {
  64. wx.navigateTo({
  65. url: '/pages/sgin/sgin',
  66. })
  67. },
  68. // 更新资料
  69. newbtn () {
  70. if (!this.state) {
  71. wx.navigateTo({
  72. url: '/pages/sgin/sgin',
  73. })
  74. return false;
  75. }
  76. let { axios } = app.globalData, that = this;
  77. wx.getUserProfile({
  78. desc: '用于完善会员资料',
  79. success: (res) => {
  80. app.globalData.encryptedData = res.encryptedData;
  81. app.globalData.iv = res.iv;
  82. let { appid, user, iv, encryptedData } = app.globalData, { openid } = user;
  83. login_face(appid, openid, iv, encryptedData).then(res => {
  84. let { face, name } = res.data.data;
  85. user = { ...user, face, name };
  86. app.globalData["user"] = user;
  87. wx.lxd.Notify({
  88. message: "更新完毕",
  89. type: "success",
  90. icon: 'certificate'
  91. })
  92. that.setData({
  93. user
  94. })
  95. })
  96. }
  97. })
  98. function login_face (appid, openid, iv, encryptedData) {
  99. return new Promise((resovle, reject) => {
  100. axios({
  101. method: 'post',
  102. url: "/account/setUserInfo/",
  103. data: {
  104. appid, openid, iv, encryptedData
  105. },
  106. success (res) {
  107. resovle(res)
  108. }
  109. })
  110. })
  111. }
  112. },
  113. /**
  114. * 生命周期函数--监听页面初次渲染完成
  115. */
  116. onReady: function () {
  117. },
  118. /**
  119. * 生命周期函数--监听页面显示
  120. */
  121. onShow: function () {
  122. let { user, token } = app.globalData;
  123. this.setData({ user });
  124. this.state = token();
  125. },
  126. /**
  127. * 生命周期函数--监听页面隐藏
  128. */
  129. onHide: function () {
  130. },
  131. /**
  132. * 生命周期函数--监听页面卸载
  133. */
  134. onUnload: function () {
  135. },
  136. /**
  137. * 页面相关事件处理函数--监听用户下拉动作
  138. */
  139. onPullDownRefresh: function () {
  140. },
  141. /**
  142. * 页面上拉触底事件的处理函数
  143. */
  144. onReachBottom: function () {
  145. },
  146. })