authen.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <template>
  2. <div>认证中,请稍等</div>
  3. </template>
  4. <script>
  5. import Vue from "vue";
  6. import { getAuthen } from "../assets/util";
  7. export default Vue.extend({
  8. head() {
  9. return {
  10. title: "认证",
  11. };
  12. },
  13. data() {
  14. return {
  15. redirect: "",
  16. };
  17. },
  18. mounted() {
  19. this.redirect = this.$route.query.state;
  20. if (!this.$route.query.code) {
  21. getAuthen();
  22. } else {
  23. this.$axios
  24. .$get("/getGzhAuthorizeInfo", {
  25. params: {
  26. code: this.$route.query.code,
  27. stationId: this.stationId,
  28. },
  29. })
  30. .then((res) => {
  31. if (res.retCode === 0) {
  32. this.$store.dispatch("authen/setBaseData", {
  33. openId: res.data.openid,
  34. accessToken: res.data.access_token,
  35. unionId: res.data.unionid,
  36. });
  37. this.handleGoto();
  38. }
  39. })
  40. .catch((res) => {
  41. alert("网络出错,正在尝试重新加载");
  42. getAuthen();
  43. });
  44. }
  45. },
  46. methods: {
  47. handleGoto() {
  48. this.$router.replace({
  49. path: this.redirect,
  50. });
  51. },
  52. },
  53. });
  54. </script>
  55. <style lang="less">
  56. </style>