phone.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import Toast from '@vant/weapp/toast/toast';
  2. const _Http = getApp().globalData.http,
  3. loginMsg = require("./modules/login");
  4. let count = 0;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. loginFunc: true,
  11. isAgree: false,
  12. disabled: true, //是否禁用
  13. loading: false, //登陆中
  14. showChange: false
  15. },
  16. onLoad() {
  17. let accountInfo = wx.getAccountInfoSync();
  18. const ENV = accountInfo.miniProgram.envVersion
  19. if (ENV === 'release') { // 正式版
  20. console.log("正式")
  21. this.setData({
  22. loginFunc: true
  23. })
  24. } else { // 开发,测试
  25. this.setData({
  26. showChange: true,
  27. loginFunc: false
  28. })
  29. }
  30. },
  31. /* 微信登录 */
  32. wechatLogin() {
  33. if (!this.data.isAgree) return Toast({
  34. message: '请阅读并勾选用户协议',
  35. position: 'bottom'
  36. });
  37. wx.login({
  38. success(res) {
  39. if (res.code) {
  40. _Http.loginbywechat({
  41. wechat_code: res.code,
  42. "systemclient": "wechatsaletool"
  43. }).then(res => {
  44. console.log("微信快捷登录", res)
  45. if (res.code == 0) return wx.showToast({
  46. title: res.msg,
  47. icon: "none"
  48. })
  49. loginMsg.loginMsg(res);
  50. })
  51. } else {
  52. console.log('登录失败!' + res.errMsg)
  53. }
  54. }
  55. })
  56. },
  57. /* 用户登录 */
  58. userLogin() {
  59. if (this.data.loading || this.data.disabled) return;
  60. if (!this.data.isAgree) return Toast({
  61. message: '请阅读并勾选用户协议',
  62. position: 'bottom'
  63. });
  64. this.setData({
  65. loading: true
  66. })
  67. this.selectComponent('#login').handleLogin();
  68. },
  69. changeLoginFun() {
  70. this.setData({
  71. loginFunc: !this.data.loginFunc
  72. })
  73. },
  74. /* 授权 */
  75. agreementChange({
  76. detail
  77. }) {
  78. this.setData({
  79. isAgree: detail
  80. })
  81. },
  82. openChange() {
  83. count += 1;
  84. if (count == 10) this.setData({
  85. showChange: true
  86. })
  87. },
  88. })