App.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <div id="app"><router-view /></div>
  3. </template>
  4. <script>
  5. import timeMixin from "./mixins/timeMixin";
  6. import { QUESTION_API } from "@/constants/constants";
  7. export default {
  8. name: "App",
  9. mixins: [timeMixin],
  10. data() {
  11. return {
  12. signalWaiting: false,
  13. };
  14. },
  15. watch: {
  16. $route: {
  17. immediate: true,
  18. handler(val) {
  19. const unSignalRoutes = ["Root", "Login", "NotFound", "CardBuild"];
  20. if (val.name && unSignalRoutes.includes(val.name)) {
  21. this.signalWaiting = false;
  22. this.clearSetTs();
  23. return;
  24. }
  25. this.onlineSignal();
  26. },
  27. },
  28. },
  29. beforeDestroy() {
  30. this.clearSetTs();
  31. },
  32. methods: {
  33. async onlineSignal() {
  34. if (this.signalWaiting) return;
  35. this.clearSetTs();
  36. this.signalWaiting = true;
  37. let result = true;
  38. await this.$httpWithoutBar
  39. .post(QUESTION_API + "/user/online/signal")
  40. .catch((error) => {
  41. result = false;
  42. console.log("signal error", error);
  43. });
  44. if (!result) {
  45. this.signalWaiting = false;
  46. return;
  47. }
  48. this.addSetTime(() => {
  49. this.signalWaiting = false;
  50. this.onlineSignal();
  51. }, 50 * 1000);
  52. },
  53. },
  54. };
  55. </script>