auth.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <view>
  3. <!-- 顶部导航 -->
  4. <fa-navbar title="授权登录"></fa-navbar>
  5. <u-modal v-model="show" title="" :content="content" confirm-text="返回" @confirm="confirm">
  6. <view class="slot-content u-text-center u-m-b-30">
  7. <u-loading mode="flower" size="100"></u-loading>
  8. <view class="u-p-20">{{ content }}</view>
  9. </view>
  10. </u-modal>
  11. </view>
  12. </template>
  13. <script>
  14. import {loginfunc} from '@/common/fa.mixin.js'
  15. export default {
  16. mixins:[loginfunc],
  17. onLoad() {
  18. this.state = this.$util.getQueryString('state');
  19. this.code = this.$util.getQueryString('code');
  20. if (this.state && this.code) {
  21. this.goWxAuth();
  22. } else {
  23. this.content = '授权登录失败!';
  24. }
  25. },
  26. data() {
  27. return {
  28. state: '',
  29. code: '',
  30. show: true,
  31. content: '授权登录中...'
  32. };
  33. },
  34. methods: {
  35. goWxAuth: async function() {
  36. let data = {
  37. code: this.code,
  38. state: this.state,
  39. platform: 'wechat' //暂时微信 后期判断其他
  40. };
  41. let res = await this.$api.goAuthCallback(data);
  42. if (!res) {
  43. this.content = '授权登录失败!';
  44. return;
  45. }
  46. if(res.data.user){
  47. this.$u.vuex('vuex_token',res.data.user.token);
  48. this.success();
  49. return;
  50. }
  51. this.$u.vuex('vuex_third',res.data.third);
  52. this.$Router.push({ path: '/pages/login/register', query: { bind: 'bind' }});
  53. },
  54. confirm() {
  55. window.history.go(-2);
  56. }
  57. }
  58. };
  59. </script>
  60. <style></style>