phone.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import Toast from '@vant/weapp/toast/toast';
  2. const _Http = getApp().globalData.http,
  3. loginMsg = require("./modules/login");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. isAgree: false,
  10. disabled: true, //是否禁用
  11. loading: false, //登陆中
  12. },
  13. onLoad(options) {
  14. if (wx.getStorageSync('isAgree')) this.setData({
  15. isAgree: wx.getStorageSync('isAgree')
  16. })
  17. },
  18. /* 微信登录 */
  19. wechatLogin() {
  20. if (!this.data.isAgree) return Toast({
  21. message: '请阅读并勾选用户协议',
  22. position: 'bottom'
  23. });
  24. wx.login({
  25. success(res) {
  26. if (res.code) {
  27. _Http.loginbywechat({
  28. wechat_code: res.code,
  29. "systemclient": "wechatsaletool"
  30. }).then(res => {
  31. console.log("微信快捷登录", res)
  32. if (res.code == 0) return wx.showToast({
  33. title: res.msg,
  34. icon: "none"
  35. })
  36. loginMsg.loginMsg(res);
  37. })
  38. } else {
  39. console.log('登录失败!' + res.errMsg)
  40. }
  41. }
  42. })
  43. },
  44. /* 用户登录 */
  45. userLogin() {
  46. if (this.data.loading || this.data.disabled) return;
  47. if (!this.data.isAgree) return Toast({
  48. message: '请阅读并勾选用户协议',
  49. position: 'bottom'
  50. });
  51. this.setData({
  52. loading: true
  53. })
  54. this.selectComponent('#login').handleLogin();
  55. },
  56. /* 授权 */
  57. agreementChange({
  58. detail
  59. }) {
  60. this.setData({
  61. isAgree: detail
  62. })
  63. },
  64. onShareAppMessage() {}
  65. })