2
0

Mark.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <div class="my-container">
  3. <mark-header></mark-header>
  4. <mark-body></mark-body>
  5. </div>
  6. </template>
  7. <script lang="ts">
  8. import { defineComponent, onMounted, toRefs } from "vue";
  9. import {
  10. clearMarkTask,
  11. getGroup,
  12. getSetting,
  13. getStatus,
  14. getTask,
  15. } from "@/api/markPage";
  16. import { store } from "./store";
  17. import MarkHeader from "./MarkHeader.vue";
  18. import MarkBody from "./MarkBody.vue";
  19. import { useTimers } from "@/setups/useTimers";
  20. export default defineComponent({
  21. name: "Mark",
  22. components: {
  23. MarkHeader,
  24. MarkBody,
  25. },
  26. setup: () => {
  27. const { addInterval } = useTimers();
  28. async function updateMarkTask() {
  29. const settingRes = await clearMarkTask();
  30. }
  31. async function updateSetting() {
  32. const settingRes = await getSetting();
  33. store.setting = settingRes.data;
  34. }
  35. async function updateStatus() {
  36. const res = await getStatus();
  37. store.status = res.data;
  38. }
  39. async function updateGroups() {
  40. const res = await getGroup();
  41. store.groups = res.data;
  42. }
  43. async function updateTask() {
  44. const res = await getTask();
  45. if (res.data.libraryId) {
  46. store.tasks.push(res.data);
  47. store.currentTask = store.tasks[0];
  48. }
  49. }
  50. // 5秒更新一次tasks
  51. addInterval(() => {
  52. // console.log("get task", store.tasks);
  53. if (store.tasks.length < 3) {
  54. updateTask();
  55. }
  56. }, 5 * 1000);
  57. onMounted(async () => {
  58. await updateMarkTask();
  59. updateSetting();
  60. updateStatus();
  61. updateGroups();
  62. updateTask();
  63. });
  64. return { store };
  65. },
  66. });
  67. </script>
  68. <style scoped>
  69. .my-container {
  70. width: 100%;
  71. }
  72. a {
  73. color: #42b983;
  74. }
  75. label {
  76. margin: 0 0.5em;
  77. font-weight: bold;
  78. }
  79. code {
  80. background-color: #eee;
  81. padding: 2px 4px;
  82. border-radius: 4px;
  83. color: #304455;
  84. }
  85. </style>