微信小程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

184 righe
4.4 KiB

  1. // pages/phoneLogin.js
  2. import * as UTIL from '../utils/util.js';
  3. import * as jsencrypt from '../utils/jsencrypt.js';
  4. import * as API from '../utils/API.js';
  5. let EVN_CONFIG = require('../env/env');
  6. const app = getApp();
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. isIPX: app.globalData.isIPX,
  13. formData:{
  14. username:'',
  15. password:'',
  16. code:'',
  17. },
  18. codeUrl:''
  19. },
  20. back:function(){
  21. wx.navigateBack({
  22. delta: 1
  23. })
  24. },
  25. onChange(event){
  26. this.setData({
  27. [event.currentTarget.dataset.value]: event.detail,
  28. })
  29. },
  30. onSubmit(){
  31. var that = this;
  32. if (this.data.formData.rememberMe) {
  33. wx.setStorageSync("username", this.data.formData.username, { expires: 30 });
  34. wx.setStorageSync('key', data)("password", encrypt(this.data.formData.password), { expires: 30 });
  35. wx.setStorageSync("rememberMe", this.data.formData.rememberMe, { expires: 30 });
  36. } else {
  37. wx.removeStorage("username");
  38. wx.removeStorage("password");
  39. wx.removeStorage("rememberMe");
  40. }
  41. //账号密码登录
  42. if (this.data.formData.username == "") {
  43. UTIL.showToastNoneIcon('账号不能为空')
  44. return false;
  45. } else if (this.data.formData.password == "") {
  46. UTIL.showToastNoneIcon('密码不能为空')
  47. return false;
  48. } else if (!this.data.formData.code) {
  49. UTIL.showToastNoneIcon('图片验证码不能为空')
  50. return false;
  51. }
  52. let form = {
  53. username:this.data.formData.username,
  54. password:this.data.formData.password,
  55. code:this.data.formData.code,
  56. uuid:this.data.formData.uuid,
  57. }
  58. form.username = jsencrypt.encrypt(this.data.formData.username);
  59. form.password = jsencrypt.encrypt(this.data.formData.password);
  60. console.log(jsencrypt.encrypt(this.data.formData.username))
  61. console.log(jsencrypt.encrypt(this.data.formData.password))
  62. console.log(jsencrypt.decrypt(form.username))
  63. console.log(jsencrypt.decrypt(form.password))
  64. // return;
  65. wx.showLoading({
  66. title: '正在登录',
  67. mask:true
  68. })
  69. UTIL.httpRequestNoneDetal(API.URL_GET_LOGIN,form, "POST", {
  70. success: (res) => {
  71. if (res.code == API.SUCCESS_CODE) {
  72. wx.hideLoading();
  73. wx.setStorageSync('token', res.token);
  74. getApp().globalData.userInfo.token = res.token;
  75. wx.reLaunch({
  76. url: '/pages/index/index',
  77. })
  78. }else{
  79. wx.hideLoading();
  80. UTIL.showToastNoneIcon(res.msg)
  81. that.getCode();
  82. }
  83. }
  84. })
  85. // UTIL.httpRequestNoneDetal(API.URL_GET_GETPHONELOGIN+this.data.form.phone,{}, "GET", {
  86. // success: (res) => {
  87. // if (res.code == API.SUCCESS_CODE) {
  88. // wx.setStorageSync('token', res.token);
  89. // getApp().globalData.userInfo.token = res.token;
  90. // wx.reLaunch({
  91. // url: '/pages/index/index',
  92. // })
  93. // }else{
  94. // UTIL.showToastNoneIcon(res.msg)
  95. // }
  96. // }
  97. // })
  98. },
  99. /**
  100. * 生命周期函数--监听页面加载
  101. */
  102. onLoad(options) {
  103. },
  104. /**
  105. * 生命周期函数--监听页面初次渲染完成
  106. */
  107. onReady() {
  108. },
  109. getCode(){
  110. var that = this;
  111. UTIL.httpRequestNoneDetal(API.URL_GET_GETCODE,{}, "GET", {
  112. success: (res) => {
  113. if (res.code == API.SUCCESS_CODE) {
  114. that.setData({
  115. ["formData.uuid"]:res.uuid,
  116. codeUrl:"data:image/gif;base64," + res.img
  117. })
  118. }else{
  119. UTIL.showToastNoneIcon(res.msg)
  120. }
  121. }
  122. })
  123. },
  124. /**
  125. * 生命周期函数--监听页面显示
  126. */
  127. onShow() {
  128. var that = this;
  129. UTIL.httpRequestNoneDetal(API.URL_GET_GETCODE,{}, "GET", {
  130. success: (res) => {
  131. if (res.code == API.SUCCESS_CODE) {
  132. that.setData({
  133. ["formData.uuid"]:res.uuid,
  134. codeUrl:"data:image/gif;base64," + res.img
  135. })
  136. }else{
  137. UTIL.showToastNoneIcon(res.msg)
  138. }
  139. }
  140. })
  141. },
  142. /**
  143. * 生命周期函数--监听页面隐藏
  144. */
  145. onHide() {
  146. },
  147. /**
  148. * 生命周期函数--监听页面卸载
  149. */
  150. onUnload() {
  151. },
  152. /**
  153. * 页面相关事件处理函数--监听用户下拉动作
  154. */
  155. onPullDownRefresh() {
  156. },
  157. /**
  158. * 页面上拉触底事件的处理函数
  159. */
  160. onReachBottom() {
  161. },
  162. /**
  163. * 用户点击右上角分享
  164. */
  165. onShareAppMessage() {
  166. }
  167. })