login.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. const app = require('../../utils/util.js');
  2. const tools = require('../../utils/tools.js');
  3. var util = require('../../utils/md5.js')
  4. import Notify from '../../miniprogram_npm/@vant/weapp/notify/notify';
  5. //import Dialog from '../../miniprogram_npm/vant-weapp/dialog/dialog';
  6. Page({
  7. data: {
  8. defaultType1: true,
  9. passwordType1: true,
  10. xyAgree: false
  11. },
  12. change(e) {
  13. console.log(e)
  14. if (e.detail.value.length != 0) {
  15. this.setData({
  16. xyAgree: true
  17. })
  18. } else {
  19. this.setData({
  20. xyAgree: false
  21. })
  22. }
  23. console.log(this.data.xyAgree)
  24. },
  25. eyeStatus1() {
  26. if (this.data.defaultType1) {
  27. this.setData({
  28. passwordType1: false,
  29. defaultType1: false,
  30. })
  31. } else {
  32. this.setData({
  33. passwordType1: true,
  34. defaultType1: true,
  35. })
  36. }
  37. },
  38. formSubmit(e) {
  39. console.log(e.detail, "daying");
  40. var password = e.detail.value.pwd;
  41. if (e.detail.value.name) {
  42. if (e.detail.value.pwd) {
  43. if (!this.data.xyAgree) {
  44. wx.showToast({
  45. title: '仔细阅读协议并勾选',
  46. icon: 'none',
  47. duration: 3000,
  48. })
  49. return
  50. }
  51. wx.showLoading({
  52. title: '加载中',
  53. })
  54. wx.request({
  55. url: app.globalData.publicUrl + '/applet/bing',
  56. method: "GET",
  57. data: {
  58. name: e.detail.value.name,
  59. pwd: util.hexMD5(password),
  60. appletsId: wx.getStorageSync('openId')
  61. },
  62. success: (res) => {
  63. console.log(res, "777777");
  64. if (res.data.code == 0) {
  65. Notify({
  66. type: 'success',
  67. message: '登录成功'
  68. });
  69. // wx.clearStorageSync();
  70. wx.setStorageSync('user', 'user');
  71. wx.switchTab({
  72. url: '/pages/index/index',
  73. })
  74. // tools.finishInfo().then((res) => {
  75. // console.log(res.data.data.perfect, '我完善信息了吗 1代表完后 0代表未完成')
  76. // console.log(res.data.data.comparison, '我人脸识别过了吗 1代表完后 0代表未完成')
  77. // if (res.data.data.perfect == '0') {
  78. // wx.redirectTo({
  79. // url: '/pages/finishInfo/finishInfo',
  80. // })
  81. // }
  82. // if (res.data.data.perfect == '1' && res.data.data.comparison == '0') {
  83. // wx.redirectTo({
  84. // url: '/pages/faceRecognition/faceRecognition',
  85. // })
  86. // }
  87. // })
  88. } else {
  89. Notify({
  90. type: 'danger',
  91. message: res.data.message
  92. });
  93. }
  94. },
  95. complete: (res) => {
  96. wx.hideLoading()
  97. }
  98. })
  99. } else {
  100. wx.showToast({
  101. title: "密码不能为空",
  102. icon: 'none',
  103. duration: 2000,
  104. })
  105. }
  106. } else {
  107. wx.showToast({
  108. title: "账号不能为空",
  109. icon: 'none',
  110. duration: 2000,
  111. })
  112. }
  113. },
  114. goXy() {
  115. wx.navigateTo({
  116. url: '/pages/xy/xy',
  117. })
  118. },
  119. goHome() {
  120. wx.switchTab({
  121. url: '/pages/index/index',
  122. })
  123. },
  124. onShow() {
  125. wx.login({
  126. success: res => {
  127. // 获取到用户的 code 之后:res.code
  128. console.log("用户的code:" + res.code);
  129. // const appid = "wx1c015df104db7030"
  130. // const secret = "d1956c1b5d3601657c98b0dc80a006f7"
  131. // let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
  132. wx.request({
  133. // 自行补上自己的 APPID 和 SECRET
  134. url: app.globalData.publicUrl + '/wx/getAppletOpenId',
  135. method: "GET",
  136. data: {
  137. cid: 'applet',
  138. code: res.code
  139. },
  140. success: res => {
  141. // 获取到用户的 openid
  142. console.log("用户的openid:" + res.data.data.openid);
  143. wx.setStorageSync('openId', res.data.data.openid)
  144. wx.request({
  145. url: app.globalData.publicUrl + '/applet/isExist',
  146. method: "GET",
  147. data: {
  148. appletsId: wx.getStorageSync('openId')
  149. },
  150. success: () => {}
  151. })
  152. }
  153. });
  154. }
  155. });
  156. },
  157. })