MarkSwitchGroupDialog.vue 2.9 KB

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