authen.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div>认证中,请稍等</div>
  3. </template>
  4. <script>
  5. import Vue from "vue";
  6. import { getAuthen } from "../assets/util";
  7. import querystring from "querystring";
  8. import { mapMutations, mapActions } from "vuex";
  9. export default Vue.extend({
  10. head() {
  11. return {
  12. title: "认证",
  13. };
  14. },
  15. data() {
  16. return {
  17. redirect: "",
  18. };
  19. },
  20. created() {
  21. const [url, str] = this.$route.query.state.split(".");
  22. this.redirect = url;
  23. if (str !== undefined) {
  24. const search = querystring.parse(
  25. str.replace(/-/g, "&").replace(/_/g, "=")
  26. );
  27. if (!search.stationId) {
  28. alert("你没有传递站点参数");
  29. return;
  30. }
  31. this.setStationId(search.stationId);
  32. if (!!search.appId) {
  33. this.setAppId(search.appId);
  34. this.havingAuthen();
  35. } else {
  36. this.getAppId(search.stationId).then(() => {
  37. this.havingAuthen();
  38. });
  39. }
  40. } else {
  41. alert("你没有传递站点参数");
  42. return;
  43. }
  44. },
  45. methods: {
  46. handleGoto() {
  47. this.$router.replace({
  48. path: this.redirect,
  49. });
  50. },
  51. havingAuthen() {
  52. if (!this.$route.query.code) {
  53. getAuthen();
  54. } else {
  55. this.$store
  56. .dispatch("authen/login", this.$route.query.code)
  57. .then((res) => {
  58. this.handleGoto();
  59. })
  60. .catch((res) => {
  61. alert(res);
  62. getAuthen();
  63. });
  64. }
  65. },
  66. ...mapMutations({
  67. setStationId: "authen/setStationId",
  68. setAppId: "authen/setAppId",
  69. }),
  70. ...mapActions({
  71. getAppId: "authen/getAppId",
  72. }),
  73. },
  74. });
  75. </script>
  76. <style lang="less">
  77. </style>