phone.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import Toast from '@vant/weapp/toast/toast';
  2. const _Http = getApp().globalData.http;
  3. const md5 = require("../../utils/md5");
  4. const loginMsg = require("./modules/login");
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. isAgree: true,
  11. accountno: "",
  12. password: "",
  13. inputType: "password", //密码输入框类型
  14. focus: false,
  15. memory: true, //记忆
  16. disabled: true, //是否禁用
  17. loading: false, //登陆中
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad(options) {
  23. this.setData({
  24. ...wx.getStorageSync('loginMsg')
  25. })
  26. wx.getUserProfile({
  27. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  28. success: (res) => {
  29. console.log("用户信息",res)
  30. /* this.setData({
  31. userInfo: res.userInfo,
  32. hasUserInfo: true
  33. }) */
  34. }
  35. })
  36. this.allowOrNot()
  37. },
  38. /* 微信登录 */
  39. wechatLogin() {
  40. if (!this.data.isAgree) return Toast({
  41. message: '请阅读并勾选用户协议',
  42. position: 'bottom'
  43. });
  44. wx.login({
  45. success(res) {
  46. if (res.code) {
  47. _Http.loginbywechat({
  48. wechat_code: res.code,
  49. "systemclient": "wechatsaletool"
  50. }).then(res => {
  51. console.log(res)
  52. if (res.code == 0) return wx.showToast({
  53. title: res.msg,
  54. icon: "none"
  55. })
  56. loginMsg.loginMsg(res);
  57. })
  58. } else {
  59. console.log('登录失败!' + res.errMsg)
  60. }
  61. }
  62. })
  63. },
  64. /* 用户登录 */
  65. userLogin() {
  66. if (this.data.loading || this.data.disabled) return;
  67. if (!this.data.isAgree) return Toast({
  68. message: '请阅读并勾选用户协议',
  69. position: 'bottom'
  70. });
  71. this.setData({
  72. loading: true
  73. })
  74. _Http.login({
  75. "accountno": this.data.accountno,
  76. "password": md5.hexMD5(this.data.password),
  77. "systemclient": "wechatsaletool"
  78. }).then(res => {
  79. console.log("登录", res)
  80. this.setData({
  81. loading: false
  82. })
  83. if (res.msg != '成功') return wx.showToast({
  84. title: res.msg,
  85. icon: "none"
  86. })
  87. wx.setStorageSync('loginMsg', {
  88. accountno: this.data.accountno,
  89. password: (this.data.memory) ? this.data.password : ''
  90. })
  91. loginMsg.loginMsg(res);
  92. })
  93. },
  94. /* 改变密码输入框类型 */
  95. changePasswordType() {
  96. this.setData({
  97. inputType: this.data.inputType == "text" ? 'password' : 'text'
  98. })
  99. },
  100. /* 授权 */
  101. agreementChange({
  102. detail
  103. }) {
  104. this.setData({
  105. isAgree: detail
  106. })
  107. },
  108. /* 手机号 */
  109. inputPhone(e) {
  110. this.setData({
  111. accountno: e.detail.value.trim()
  112. })
  113. this.allowOrNot()
  114. },
  115. /* 密码 */
  116. inputPassword(e) {
  117. this.setData({
  118. password: e.detail.value.trim()
  119. })
  120. this.allowOrNot()
  121. },
  122. /* 验证是否允许登录 */
  123. allowOrNot() {
  124. this.setData({
  125. disabled: (this.data.accountno.length > 0 && this.data.password.length > 5) ? false : true
  126. })
  127. },
  128. /* 是否记忆密码 */
  129. isMemory() {
  130. this.setData({
  131. memory: !this.data.memory
  132. })
  133. },
  134. /**
  135. * 生命周期函数--监听页面初次渲染完成
  136. */
  137. onReady() {
  138. },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow() {
  143. },
  144. /**
  145. * 生命周期函数--监听页面隐藏
  146. */
  147. onHide() {
  148. },
  149. /**
  150. * 生命周期函数--监听页面卸载
  151. */
  152. onUnload() {
  153. },
  154. /**
  155. * 页面相关事件处理函数--监听用户下拉动作
  156. */
  157. onPullDownRefresh() {
  158. },
  159. /**
  160. * 页面上拉触底事件的处理函数
  161. */
  162. onReachBottom() {
  163. },
  164. /**
  165. * 用户点击右上角分享
  166. */
  167. onShareAppMessage() {
  168. }
  169. })