You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.5 KiB

3 years ago
  1. export default{
  2. // #ifdef MP-WEIXIN
  3. data(){
  4. return {
  5. mpCodeTimer: 0,
  6. mpWxCode: '',
  7. }
  8. },
  9. computed: {
  10. timerIdent(){
  11. return this.$store.state.timerIdent;
  12. }
  13. },
  14. watch: {
  15. timerIdent(){
  16. this.mpCodeTimer ++;
  17. if(this.mpCodeTimer % 30 === 0){
  18. this.getMpWxCode();
  19. }
  20. }
  21. },
  22. onShow(){
  23. this.getMpWxCode();
  24. },
  25. methods: {
  26. //微信小程序登录
  27. mpWxGetUserInfo(userInfoData){
  28. if(!userInfoData.detail.userInfo){
  29. return;
  30. }
  31. if(!this.agreement){
  32. this.$util.msg('请阅读并同意用户服务及隐私协议');
  33. return;
  34. }
  35. this.$util.throttle(async ()=>{
  36. const [err, userData] = await uni.getUserInfo();
  37. const res = await this.$request('user', 'loginByWeixin', {
  38. code: this.mpWxCode,
  39. encryptedData: userData.encryptedData,
  40. iv: userData.iv,
  41. userInfo: JSON.parse(userData.rawData)
  42. }, {
  43. showLoading: true
  44. });
  45. if(res.status === 0){
  46. this.$util.msg(res.msg);
  47. return;
  48. }
  49. if(res.hasBindMobile && res.data.token){
  50. this.loginSuccessCallBack({
  51. token: res.data.token,
  52. tokenExpired: res.data.tokenExpired
  53. });
  54. }else{
  55. this.navTo('/pages/auth/bindMobile?data='+JSON.stringify(res.data))
  56. }
  57. console.log(res);
  58. })
  59. },
  60. //获取code
  61. getMpWxCode(){
  62. uni.login({
  63. provider: 'weixin',
  64. success: res=> {
  65. this.mpWxCode = res.code;
  66. }
  67. })
  68. },
  69. }
  70. // #endif
  71. }