index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div class="data-check">
  3. <div class="check-menu">
  4. <div class="check-menu-body">
  5. <ul>
  6. <li
  7. v-for="(item, index) in studentList"
  8. :key="item.id"
  9. :class="{ 'is-active': dataCheckStore.curStudent?.id === item.id }"
  10. @click="onSelectStudent(index)"
  11. >
  12. {{ item.examNumber }}
  13. </li>
  14. </ul>
  15. </div>
  16. <div class="check-menu-page">
  17. <SimplePagination
  18. :total="total"
  19. :page-size="pageSize"
  20. @change="onChangeListPage"
  21. />
  22. </div>
  23. </div>
  24. <div class="check-body">
  25. <ScanImage
  26. v-if="dataCheckStore.curPage && isOriginImage"
  27. :key="dataCheckStore.curPage.kid"
  28. @prev="onPrevPage"
  29. @next="onNextPage"
  30. />
  31. <SliceImage v-if="dataCheckStore.curPage && !isOriginImage" />
  32. </div>
  33. <CheckAction @search="onSearch" />
  34. </div>
  35. </template>
  36. <script setup lang="ts">
  37. import { ref, reactive, onMounted, computed, onBeforeUnmount } from "vue";
  38. import { message } from "ant-design-vue";
  39. import { CaretLeftOutlined, CaretRightOutlined } from "@ant-design/icons-vue";
  40. import { DataCheckListFilter, DataCheckListItem } from "@/ap/types/dataCheck";
  41. import { dataCheckList } from "@/ap/dataCheck";
  42. import { StudentPage } from "./types";
  43. import { useDataCheckStore, useUserStore } from "@/store";
  44. import SimplePagination from "@/components/SimplePagination/index.vue";
  45. import ScanImage from "./ScanImage/index.vue";
  46. import SliceImage from "./SliceImage/index.vue";
  47. import CheckAction from "./CheckAction.vue";
  48. defineOptions({
  49. name: "DataCheck",
  50. });
  51. const dataCheckStore = useDataCheckStore();
  52. dataCheckStore.resetInfo();
  53. const userStore = useUserStore();
  54. let searchModel = {} as DataCheckListFilter;
  55. const pageNumber = ref(1);
  56. const pageSize = ref(20);
  57. const total = ref(0);
  58. const pageCount = ref(0);
  59. const studentList = ref<DataCheckListItem[]>([]);
  60. const dataList = ref<StudentPage[]>([]);
  61. const loading = ref(false);
  62. async function getList() {
  63. loading.value = true;
  64. const datas = {
  65. ...searchModel,
  66. pageNumber: pageNumber.value,
  67. pageSize: pageSize.value,
  68. };
  69. const res = await dataCheckList(datas).catch(() => null);
  70. loading.value = false;
  71. if (!res) return;
  72. total.value = res.totalCount;
  73. pageCount.value = res.pageCount;
  74. studentList.value = res.result;
  75. parseStudentPageList(res.result);
  76. }
  77. function parseStudentPageList(students: DataCheckListItem[]) {
  78. dataList.value = [] as StudentPage[];
  79. students.forEach((student, studentIndex) => {
  80. student.papers.forEach((paper, paperIndex) => {
  81. if (!paper.pages) return;
  82. paper.pages.forEach((page, pageIndex) => {
  83. const row: StudentPage = {
  84. ...page,
  85. paperId: paper.id,
  86. paperIndex,
  87. paperNumber: paper.number,
  88. pageIndex,
  89. studentIndex,
  90. studentId: student.id,
  91. examId: searchModel.examId,
  92. kid: `${student.id}-${studentIndex}-${paperIndex}-${pageIndex}`,
  93. };
  94. if (
  95. row.question?.result?.length &&
  96. Array.isArray(row.question?.result)
  97. ) {
  98. row.question.result = row.question.result.map((item: string) =>
  99. item.replace(/[^#a-zA-Z]/g, "")
  100. );
  101. }
  102. dataList.value.push(row);
  103. });
  104. });
  105. });
  106. }
  107. // imageType
  108. const isOriginImage = computed(() => {
  109. return dataCheckStore.imageType === "ORIGIN";
  110. });
  111. // table
  112. async function onChangeListPage(index: number) {
  113. pageNumber.value = index;
  114. await getList();
  115. selectPage(0);
  116. }
  117. async function onSearch(datas: DataCheckListFilter) {
  118. console.log("datas", datas);
  119. searchModel = {
  120. ...datas,
  121. examStatus:
  122. datas.examStatus === "UNCHECK"
  123. ? "UNCHECK1,UNCHECK2,UNCHECK3"
  124. : datas.examStatus,
  125. };
  126. pageNumber.value = 1;
  127. if (!searchModel.subjectCode) {
  128. total.value = 0;
  129. pageCount.value = 0;
  130. studentList.value = [];
  131. dataCheckStore.resetInfo();
  132. window.$message.error("请选择科目");
  133. return;
  134. }
  135. await getList();
  136. selectPage(0);
  137. }
  138. // onSearch({ examId: userStore.curExam.id } as DataCheckListFilter);
  139. // student
  140. function onSelectStudent(index: number) {
  141. const student = studentList.value[index];
  142. const pageIndex = dataList.value.findIndex(
  143. (item) => item.studentId === student.id
  144. );
  145. if (pageIndex === -1) return;
  146. selectPage(pageIndex);
  147. }
  148. async function onPrevStudent() {
  149. if (dataCheckStore.curStudentIndex <= 0) {
  150. if (pageNumber.value === 1) {
  151. message.error("没有上一个学生了");
  152. return;
  153. }
  154. pageNumber.value--;
  155. await getList();
  156. onSelectStudent(studentList.value.length - 1);
  157. return;
  158. }
  159. onSelectStudent(dataCheckStore.curStudentIndex - 1);
  160. }
  161. async function onNextStudent() {
  162. if (dataCheckStore.curStudentIndex >= studentList.value.length - 1) {
  163. if (pageNumber.value >= pageCount.value) {
  164. message.error("没有下一个学生了");
  165. return;
  166. }
  167. pageNumber.value++;
  168. await getList();
  169. onSelectStudent(0);
  170. return;
  171. }
  172. onSelectStudent(dataCheckStore.curStudentIndex + 1);
  173. }
  174. // page
  175. function selectPage(index: number) {
  176. dataCheckStore.setInfo({
  177. curPage: dataList.value[index],
  178. curPageIndex: index,
  179. });
  180. if (!dataCheckStore.curPage) return;
  181. const curStudent = studentList.value[
  182. dataCheckStore.curPage.studentIndex
  183. ] as DataCheckListItem;
  184. dataCheckStore.setInfo({
  185. curStudent,
  186. curStudentIndex: dataCheckStore.curPage.studentIndex,
  187. });
  188. }
  189. async function onPrevPage() {
  190. if (dataCheckStore.curPageIndex <= 0) {
  191. if (pageNumber.value === 1) {
  192. message.error("没有上一张了");
  193. return;
  194. }
  195. pageNumber.value--;
  196. await getList();
  197. selectPage(dataList.value.length - 1);
  198. return;
  199. }
  200. selectPage(dataCheckStore.curPageIndex - 1);
  201. }
  202. async function onNextPage() {
  203. if (dataCheckStore.curPageIndex >= dataList.value.length - 1) {
  204. if (pageNumber.value >= pageCount.value) {
  205. message.error("没有下一张了");
  206. return;
  207. }
  208. pageNumber.value++;
  209. await getList();
  210. selectPage(0);
  211. return;
  212. }
  213. selectPage(dataCheckStore.curPageIndex + 1);
  214. }
  215. // shortcut
  216. function registShortcut() {
  217. document.addEventListener("keydown", shortcutHandle);
  218. }
  219. function removeShortcut() {
  220. document.removeEventListener("keydown", shortcutHandle);
  221. }
  222. function shortcutHandle(e: KeyboardEvent) {
  223. const moveAction = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
  224. if (!moveAction.includes(e.code) || e.repeat) {
  225. return;
  226. }
  227. e.preventDefault();
  228. if (e.code === "ArrowUp") {
  229. onPrevStudent();
  230. return;
  231. }
  232. if (e.code === "ArrowDown") {
  233. onNextStudent();
  234. return;
  235. }
  236. if (e.code === "ArrowLeft") {
  237. onPrevPage();
  238. return;
  239. }
  240. if (e.code === "ArrowRight") {
  241. onNextPage();
  242. return;
  243. }
  244. }
  245. onMounted(() => {
  246. registShortcut();
  247. });
  248. onBeforeUnmount(() => {
  249. removeShortcut();
  250. });
  251. </script>