login.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. },
  83. onShow(){
  84. console.log("登录onshow000000")
  85. var that = this;
  86. wx.login({
  87. success: res => {
  88. // 获取到用户的 code 之后:res.code
  89. console.log("用户的code:" + res.code);
  90. const appid = "wx1c015df104db7030"
  91. const secret = "d1956c1b5d3601657c98b0dc80a006f7"
  92. let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
  93. wx.request({
  94. // 自行补上自己的 APPID 和 SECRET
  95. url: url,
  96. success: res => {
  97. // 获取到用户的 openid
  98. console.log("用户的openid:" + res.data.openid);
  99. wx.setStorageSync('openId', res.data.openid)
  100. wx.request({
  101. url: app.globalData.publicUrl + '/applet/isExist',
  102. method: "GET",
  103. data: {
  104. appletsId: wx.getStorageSync('openId')
  105. },
  106. success: (res) => {
  107. }
  108. })
  109. }
  110. });
  111. }
  112. });
  113. },
  114. })