2
0

MarkSwitchGroupDialog.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. type="text"
  26. style="color: #5d65ff; font-weight: bold"
  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 lang="ts">
  40. // 不能用 <script setup lang="ts"> ,因为被上层用ref了,暂时没有解决方案
  41. import { doSwitchGroup, getGroups } from "@/api/markPage";
  42. import { message } from "ant-design-vue";
  43. import { ref, defineComponent, onUpdated } from "vue";
  44. import { store } from "./store";
  45. export default defineComponent({
  46. name: "MarkSwitchGroupDialog",
  47. setup() {
  48. const visible = ref<boolean>(false);
  49. onUpdated(async () => {
  50. const groups = await getGroups();
  51. store.groups = groups.data;
  52. });
  53. const showModal = () => {
  54. visible.value = true;
  55. };
  56. const progress = (totalCount: number, markedCount: number) => {
  57. if (totalCount <= 0) return 0;
  58. let p = markedCount / totalCount;
  59. if (p < 0.01 && markedCount >= 1) p = 0.01;
  60. p = Math.floor(p * 100);
  61. return p;
  62. };
  63. const isCurrentGroup = (groupNumber: number) => {
  64. return groupNumber === store.setting.groupNumber;
  65. };
  66. const chooseGroup = async (markerId: number) => {
  67. const res = await doSwitchGroup(markerId)
  68. .then((res) => {
  69. // 切换分组相当于刷新页面,此时之前的所有的状态消失,即task/markResult不存在了
  70. if (res.data.success) {
  71. const body = document.querySelector("body");
  72. if (body) body.innerHTML = "重新加载中...";
  73. return new Promise((resolve) =>
  74. setTimeout(() => resolve(true), 300)
  75. );
  76. } else {
  77. message.error({ content: res.data.message || "错误", duration: 5 });
  78. return false;
  79. }
  80. })
  81. .then((res) => {
  82. if (res) {
  83. window.location.reload();
  84. }
  85. });
  86. };
  87. const handleCancel = () => {
  88. visible.value = false;
  89. };
  90. return {
  91. store,
  92. visible,
  93. showModal,
  94. progress,
  95. isCurrentGroup,
  96. chooseGroup,
  97. handleCancel,
  98. };
  99. },
  100. });
  101. </script>
  102. <style scoped>
  103. .profile-wrapper .ant-modal-title {
  104. color: #283e76;
  105. }
  106. .profile-wrapper .anticon-close {
  107. vertical-align: text-top;
  108. }
  109. .profile-wrapper .ant-modal-body label {
  110. color: #435488 !important;
  111. }
  112. .group-table {
  113. width: 100%;
  114. border-collapse: separate;
  115. border-spacing: 0 0.5em;
  116. }
  117. .current-group {
  118. background-color: #f2f7ff;
  119. }
  120. </style>