login.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. const app = require('../../utils/util.js');
  2. var util = require('../../utils/md5.js')
  3. import Notify from '../../miniprogram_npm/vant-weapp/notify/notify';
  4. //import Dialog from '../../miniprogram_npm/vant-weapp/dialog/dialog';
  5. Page({
  6. data: {
  7. defaultType1: true,
  8. passwordType1: true
  9. },
  10. eyeStatus1() {
  11. if (this.data.defaultType1) {
  12. this.setData({
  13. passwordType1: false,
  14. defaultType1: false,
  15. })
  16. } else {
  17. this.setData({
  18. passwordType1: true,
  19. defaultType1: true,
  20. })
  21. }
  22. },
  23. formSubmit(e) {
  24. console.log(e.detail, "daying");
  25. var password = e.detail.value.pwd;
  26. if (e.detail.value.name) {
  27. if (e.detail.value.pwd) {
  28. wx.showLoading({
  29. title: '加载中',
  30. })
  31. wx.request({
  32. url: app.globalData.publicUrl + '/applet/bing',
  33. method: "GET",
  34. data: {
  35. name: e.detail.value.name,
  36. pwd: util.hexMD5(password),
  37. appletsId: wx.getStorageSync('openId')
  38. },
  39. success: (res) => {
  40. console.log(res, "777777");
  41. if (res.data.code == 0) {
  42. Notify({
  43. type: 'success',
  44. message: '登录成功'
  45. });
  46. wx.setStorageSync('user', 'user');
  47. wx.switchTab({
  48. url: '/pages/index/index',
  49. })
  50. } else {
  51. Notify({
  52. type: 'danger',
  53. message: res.data.message
  54. });
  55. }
  56. },
  57. complete:(res) => {
  58. wx.hideLoading()
  59. }
  60. })
  61. } else {
  62. wx.showToast({
  63. title: "密码不能为空",
  64. icon: 'none',
  65. duration: 2000,
  66. })
  67. }
  68. } else {
  69. wx.showToast({
  70. title: "账号不能为空",
  71. icon: 'none',
  72. duration: 2000,
  73. })
  74. }
  75. },
  76. goHome() {
  77. wx.switchTab({
  78. url: '/pages/index/index',
  79. })
  80. },
  81. onLoad: function () {
  82. var that = this;
  83. wx.login({
  84. success: res => {
  85. // 获取到用户的 code 之后:res.code
  86. console.log("用户的code:" + res.code);
  87. const appid = "wx1c015df104db7030"
  88. const secret = "d1956c1b5d3601657c98b0dc80a006f7"
  89. let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
  90. wx.request({
  91. // 自行补上自己的 APPID 和 SECRET
  92. url: url,
  93. success: res => {
  94. // 获取到用户的 openid
  95. console.log("用户的openid:" + res.data.openid);
  96. wx.setStorageSync('openId', res.data.openid)
  97. wx.request({
  98. url: app.globalData.publicUrl + '/applet/isExist',
  99. method: "GET",
  100. data: {
  101. appletsId: wx.getStorageSync('openId')
  102. },
  103. success: (res) => {
  104. }
  105. })
  106. }
  107. });
  108. }
  109. });
  110. },
  111. })