MarkSwitchGroupDialog.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <a-modal
  3. title="切换分组"
  4. v-model:visible="visible"
  5. :zIndex="6000"
  6. wrapClassName="profile-wrapper"
  7. >
  8. <table class="group-table">
  9. <tr>
  10. <th style="padding-left: 15px">分组号</th>
  11. <th>分组名</th>
  12. <th>进度</th>
  13. <td class="tw-text-right" style="padding-right: 15px">操作</td>
  14. </tr>
  15. <tr
  16. v-for="(group, index) in store.groups"
  17. :key="index"
  18. :class="isCurrentGroup(group.number) && 'current-group'"
  19. >
  20. <td style="padding-left: 15px">{{ group.number }}</td>
  21. <td>{{ group.title }}</td>
  22. <td>{{ progress(group.totalCount, group.markedCount) }}%</td>
  23. <td class="tw-text-right">
  24. <qm-button
  25. :disabled="isCurrentGroup(group.number)"
  26. type="primary"
  27. @click="chooseGroup(group.markerId)"
  28. >
  29. 选择
  30. </qm-button>
  31. </td>
  32. </tr>
  33. </table>
  34. <template #footer>
  35. <a-button key="back" @click="handleCancel">取消</a-button>
  36. </template>
  37. </a-modal>
  38. </template>
  39. <script setup lang="ts">
  40. import { doSwitchGroup, getGroups } from "@/api/markPage";
  41. import { message } from "ant-design-vue";
  42. import { onUpdated } from "vue";
  43. import { store } from "@/store/store";
  44. let visible = $ref(false);
  45. onUpdated(async () => {
  46. if (visible) {
  47. const groups = await getGroups();
  48. store.groups = groups.data;
  49. }
  50. });
  51. const showModal = () => {
  52. visible = true;
  53. };
  54. const progress = (totalCount: number, markedCount: number) => {
  55. if (totalCount <= 0) return 0;
  56. let p = markedCount / totalCount;
  57. if (p < 0.01 && markedCount >= 1) p = 0.01;
  58. p = Math.floor(p * 100);
  59. return p;
  60. };
  61. const isCurrentGroup = (groupNumber: number) => {
  62. return groupNumber === store.setting.groupNumber;
  63. };
  64. const chooseGroup = async (markerId: number) => {
  65. const res = await doSwitchGroup(markerId)
  66. .then((res) => {
  67. // 切换分组相当于刷新页面,此时之前的所有的状态消失,即task/markResult不存在了
  68. if (res.data.success) {
  69. const body = document.querySelector("body");
  70. if (body) body.innerHTML = "重新加载中...";
  71. return new Promise((resolve) => setTimeout(() => resolve(true), 300));
  72. } else {
  73. message.error({ content: res.data.message || "错误", duration: 5 });
  74. return false;
  75. }
  76. })
  77. .then((res) => {
  78. if (res) {
  79. window.location.reload();
  80. }
  81. });
  82. };
  83. const handleCancel = () => {
  84. visible = false;
  85. };
  86. defineExpose({ showModal });
  87. </script>
  88. <style scoped>
  89. .group-table {
  90. width: 100%;
  91. border-collapse: separate;
  92. border-spacing: 0 0.5em;
  93. }
  94. .current-group {
  95. background-color: #f2f7ff;
  96. }
  97. </style>
  98. <style>
  99. .profile-wrapper .ant-modal-title {
  100. color: var(--app-main-text-color);
  101. }
  102. .profile-wrapper .anticon-close {
  103. vertical-align: text-top;
  104. }
  105. .profile-wrapper .ant-modal-body {
  106. color: var(--app-bold-text-color);
  107. }
  108. .profile-wrapper .ant-modal-body th {
  109. color: var(--app-small-header-text-color);
  110. }
  111. </style>