App.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 asyncRequest from "@/apis/service/test";
  9. import { getCode } from "@/utils/dingding";
  10. export default {
  11. name: "App",
  12. data() {
  13. return {
  14. code: "",
  15. };
  16. },
  17. async created() {
  18. // const res = await asyncRequest.list({type_code:"WSM8b49211013191450"});
  19. // console.log(res);
  20. // if (res && res.code === 0 && res.data) {
  21. // this.tableData = res.data.list;
  22. // this.pageInfo.total = Number(res.data.count);
  23. // } else if (res && res.code >= 100 && res.code <= 104) {
  24. // await this.logout();
  25. // } else {
  26. // this.tableData = [];
  27. // this.pageInfo.total = 0;
  28. // }
  29. // axios
  30. // .post("/process/statistics", {})
  31. // .then((res) => {
  32. // console.log(res);
  33. // })
  34. // .catch((err) => {});
  35. if (JudgeEnvironment() === "isDingDing") {
  36. await this.testing();
  37. } else {
  38. await this.getMenu();
  39. }
  40. },
  41. methods: {
  42. async testing() {
  43. await getCode(async (code) => {
  44. this.code = code;
  45. if (this.code != null && this.code != "") {
  46. await this.setcode(this.code);
  47. } else {
  48. await this.logout();
  49. }
  50. });
  51. },
  52. async setcode(code) {
  53. let model = { code: code };
  54. this.$store
  55. .dispatch("user/dingUserInfor", model)
  56. .then(async (res) => {
  57. if (res === "success") {
  58. await this.getMenu();
  59. } else {
  60. await this.logout();
  61. }
  62. })
  63. .catch(async (err) => {
  64. await this.logout();
  65. });
  66. },
  67. async getMenu() {
  68. this.$store
  69. .dispatch("user/getMenuList", this)
  70. .then(async (res) => {
  71. if (res === "noToken") {
  72. await this.logout();
  73. } else if (res === "success") {
  74. if (
  75. this.$route.path === "/loadingPage" ||
  76. this.$route.path === "/" ||
  77. this.$route.path === "/login"
  78. ) {
  79. window.vm.$router.replace("/welcome");
  80. }
  81. } else {
  82. await this.logout();
  83. }
  84. })
  85. .catch(async (err) => {
  86. await this.logout();
  87. });
  88. },
  89. async logout() {
  90. if (this.$route.path !== "/login") {
  91. await this.$store.dispatch("user/logout");
  92. this.$router.push(`/login`);
  93. }
  94. },
  95. },
  96. };
  97. </script>
  98. <style lang="scss">
  99. @import "./assets/css/index.scss";
  100. </style>