login.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import * as API_user from '@/apis/user'
  2. import {
  3. checkPhone,
  4. } from '@/utils'
  5. export default {
  6. data() {
  7. return {
  8. openId:"",
  9. subFormCode: {
  10. phone: '',
  11. openId: '',
  12. verifyCode: ''
  13. },
  14. isSendMsgIng: false,
  15. sendMsgSecond: 60,
  16. back:false,
  17. }
  18. },
  19. methods: {
  20. gotoHome(){
  21. uni.switchTab({
  22. url: '/pages/index/index'
  23. });
  24. },
  25. codeCheckForm() {
  26. let phoneResult = checkPhone(this.subFormCode.phone);
  27. if (typeof phoneResult == 'string') {
  28. this.$refs.common.alert(phoneResult)
  29. return false;
  30. } else if (!this.subFormCode.verifyCode) {
  31. this.$refs.common.alert('请输入验证码')
  32. return false;
  33. } else {
  34. return true;
  35. }
  36. },
  37. login() {
  38. this.codeSubmit();
  39. },
  40. //验证码登录
  41. codeSubmit() {
  42. if (this.codeCheckForm()) {
  43. this.$refs.common.showLoading()
  44. API_user.validateCode(this.subFormCode).then(response => {
  45. if(response.data){
  46. var token = response.data ? response.data.token : '';
  47. this.carhelp.setToken(token);
  48. this.carhelp.setPersonInfo(response.data.userInfo)
  49. this.loginSuccess();
  50. }else{
  51. this.$refs.common.showLoading(false,response.message);
  52. }
  53. }).catch(error => {
  54. this.$refs.common.showLoading(false,error);
  55. })
  56. }
  57. },
  58. //发送验证码
  59. sendMsg() {
  60. if (!this.isSendMsgIng) {
  61. let phoneResult = checkPhone(this.subFormCode.phone);
  62. if (typeof phoneResult == 'string') {
  63. this.$refs.common.alert(phoneResult)
  64. } else {
  65. this.$refs.common.showLoading()
  66. API_user.getVerifyCode(this.subFormCode).then(response => {
  67. this.$refs.common.showLoading(false)
  68. if(response.message){
  69. //倒计时
  70. this.msgTimeInterval();
  71. }else{
  72. this.$refs.common.alert("您的验证码已经发送[5分钟有效],请勿重复点击")
  73. }
  74. }).catch(error => {
  75. this.$refs.common.alert(error)
  76. })
  77. }
  78. }
  79. },
  80. //倒计时
  81. msgTimeInterval() {
  82. this.isSendMsgIng = true;
  83. var time = this.sendMsgSecond;
  84. var _this = this;
  85. this.timer = setInterval(() => {
  86. if (time > 0) {
  87. _this.sendMsgSecond = time--;
  88. } else {
  89. _this.isSendMsgIng = false;
  90. _this.sendMsgSecond = 60;
  91. clearInterval(_this.timer)
  92. }
  93. }, 1000)
  94. }, //登录成功
  95. loginSuccess() {
  96. uni.switchTab({
  97. url: '/pages/my/index'
  98. });
  99. },
  100. },
  101. onLoad(temp) {
  102. var ob=this.carhelp.getPersonInfo()
  103. if(ob){
  104. this.loginSuccess()
  105. }
  106. if(temp.back){
  107. this.back=true;
  108. }
  109. console.log(ob)
  110. this.subFormCode.openId = this.carhelp.getOpenId();
  111. if (process.car.SIMPLE_RUN) {
  112. this.subFormCode.openId = "test";
  113. }
  114. console.log(this.carhelp.getPrefix())
  115. }
  116. }