login.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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: "friends", require: true, success () {
  19. wx.navigateTo({
  20. url: `/pages/adddata/adddata`,
  21. })
  22. }
  23. },
  24. {
  25. title: "请假管理", icon: "column", require: true, success () {
  26. wx.navigateTo({
  27. url: `/pages/leave/leave`,
  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. console.log("请登录");
  43. return false;
  44. }
  45. console.log("普通触发")
  46. },
  47. /**
  48. * 生命周期函数--监听页面加载
  49. */
  50. onLoad: function (options) {
  51. wx.lxd.Ctr({
  52. // nav
  53. title: "我的", //标题
  54. back: false,//返回按钮,tabber必须false(除非会改)
  55. bgc: true,//使用更改后的颜色
  56. // tabber
  57. tabber: true,//显示
  58. active: 1,//活动值
  59. })
  60. },
  61. // 登录页面
  62. sgin () {
  63. wx.navigateTo({
  64. url: '/pages/sgin/sgin',
  65. })
  66. },
  67. // 更新资料
  68. newbtn () {
  69. if (!this.state) {
  70. wx.showToast({
  71. title: '请先登录!',
  72. icon: "none"
  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.showToast({
  88. title: '更新完毕',
  89. })
  90. that.setData({
  91. user
  92. })
  93. })
  94. }
  95. })
  96. function login_face (appid, openid, iv, encryptedData) {
  97. return new Promise((resovle, reject) => {
  98. axios({
  99. method: 'post',
  100. url: "/account/setUserInfo/",
  101. data: {
  102. appid, openid, iv, encryptedData
  103. },
  104. success (res) {
  105. resovle(res)
  106. }
  107. })
  108. })
  109. }
  110. },
  111. /**
  112. * 生命周期函数--监听页面初次渲染完成
  113. */
  114. onReady: function () {
  115. },
  116. /**
  117. * 生命周期函数--监听页面显示
  118. */
  119. onShow: function () {
  120. let { user } = app.globalData;
  121. this.setData({ user });
  122. this.state = user.lock;
  123. },
  124. /**
  125. * 生命周期函数--监听页面隐藏
  126. */
  127. onHide: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面卸载
  131. */
  132. onUnload: function () {
  133. },
  134. /**
  135. * 页面相关事件处理函数--监听用户下拉动作
  136. */
  137. onPullDownRefresh: function () {
  138. },
  139. /**
  140. * 页面上拉触底事件的处理函数
  141. */
  142. onReachBottom: function () {
  143. },
  144. /**
  145. * 用户点击右上角分享
  146. */
  147. onShareAppMessage: function () {
  148. }
  149. })