authen.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /**
  24. * 这一段作用是直接微信接口跳转
  25. **/
  26. if (str !== undefined) {
  27. const search = querystring.parse(
  28. str.replace(/-/g, "&").replace(/_/g, "=")
  29. );
  30. if (!search.stationId) {
  31. alert("你没有传递站点参数");
  32. return;
  33. }
  34. this.setStationId(search.stationId);
  35. if (!!search.appId) {
  36. this.setAppId(search.appId);
  37. this.havingAuthen();
  38. } else {
  39. this.getAppId(search.stationId).then((res) => {
  40. this.setStationId(res.stationId)
  41. this.havingAuthen();
  42. });
  43. }
  44. } else {
  45. alert("你没有传递站点参数");
  46. return;
  47. }
  48. },
  49. methods: {
  50. handleGoto() {
  51. this.$router.replace({
  52. path: this.redirect,
  53. });
  54. },
  55. havingAuthen() {
  56. if (!this.$route.query.code) {
  57. getAuthen();
  58. } else {
  59. this.$store
  60. .dispatch("authen/login", this.$route.query.code)
  61. .then((res) => {
  62. this.handleGoto();
  63. })
  64. .catch((res) => {
  65. alert(res);
  66. getAuthen();
  67. });
  68. }
  69. },
  70. ...mapMutations({
  71. setStationId: "authen/setStationId",
  72. setAppId: "authen/setAppId",
  73. }),
  74. ...mapActions({
  75. getAppId: "authen/getAppId",
  76. }),
  77. },
  78. });
  79. </script>
  80. <style lang="less">
  81. </style>