App.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <div id="app" v-cloak>
  3. <router-view />
  4. </div>
  5. </template>
  6. <script>
  7. import { JudgeEnvironment } from "@/utils/validate";
  8. import { getCode } from "@/utils/dingding";
  9. export default {
  10. name: "App",
  11. data() {
  12. return {
  13. code: "",
  14. };
  15. },
  16. async created() {
  17. if (JudgeEnvironment() === "isDingDing") {
  18. await this.testing();
  19. } else {
  20. await this.getMenu();
  21. }
  22. },
  23. methods: {
  24. async testing() {
  25. await getCode(async (code) => {
  26. this.code = code;
  27. if (this.code != null && this.code != "") {
  28. await this.setcode(this.code);
  29. } else {
  30. await this.logout();
  31. }
  32. });
  33. },
  34. async setcode(code) {
  35. let model = { code: code };
  36. this.$store
  37. .dispatch("user/dingUserInfor", model)
  38. .then(async (res) => {
  39. if (res === "success") {
  40. await this.getMenu();
  41. } else {
  42. await this.logout();
  43. }
  44. })
  45. .catch(async (err) => {
  46. await this.logout();
  47. });
  48. },
  49. async getMenu() {
  50. this.$store
  51. .dispatch("user/getMenuList", this)
  52. .then(async (res) => {
  53. if (res === "noToken") {
  54. await this.logout();
  55. } else if (res === "success") {
  56. if (
  57. this.$route.path === "/loadingPage" ||
  58. this.$route.path === "/" ||
  59. this.$route.path === "/login"
  60. ) {
  61. window.vm.$router.replace("/welcome");
  62. }
  63. } else {
  64. await this.logout();
  65. }
  66. })
  67. .catch(async (err) => {
  68. await this.logout();
  69. });
  70. },
  71. async logout() {
  72. if (this.$route.path !== "/login") {
  73. await this.$store.dispatch("user/logout");
  74. console.log(this.$route.fullPath);
  75. this.$router.push(`/login`);
  76. }
  77. },
  78. },
  79. };
  80. </script>
  81. <style lang="scss">
  82. @import "./assets/css/index.scss";
  83. </style>