ChooseMarkers.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="choose-markers">
  3. <el-button type="primary" :disabled="!subjectCode || !mainNumber" @click="openDialog"
  4. >选择评卷员{{ confirmResult?.length ? `(已选${confirmResult.length}人)` : '' }}</el-button
  5. >
  6. <base-dialog v-model="modalVisible" title="选择评卷员" :width="450" class="marker-dialog">
  7. <div class="m-b-base">
  8. <el-input
  9. v-model.trim="filterText"
  10. placeholder="输入评卷员登录名或姓名查询"
  11. clearable
  12. style="width: 200px; margin-right: 10px"
  13. ></el-input>
  14. <el-button type="primary" @click="filterSearch">查询</el-button>
  15. </div>
  16. <vxe-table
  17. :key="tableKey"
  18. size="small"
  19. show-overflow
  20. :max-height="tableMaxHeight"
  21. :tree-config="{ childrenField: 'markers', rowField: 'id', expandAll: true, transform: true }"
  22. :data="tableData"
  23. :checkbox-config="{ highlight: false }"
  24. :scroll-y="{ enabled: true, gt: 40 }"
  25. @checkbox-change="selectChangeEvent"
  26. @checkbox-all="selectChangeEvent"
  27. >
  28. <vxe-column type="checkbox" title="" width="80" tree-node></vxe-column>
  29. <vxe-column field="showName" title="姓名">
  30. <template #default="{ row }">
  31. <span :style="{ fontWeight: !row.parentId ? 'bold' : 'normal' }">{{ row.showName }}</span>
  32. </template>
  33. </vxe-column>
  34. </vxe-table>
  35. <template #footer>
  36. <div class="flex justify-end">
  37. <confirm-button
  38. :disabled="!chooseResult.length"
  39. @confirm="confirm"
  40. @cancel="modalVisible = false"
  41. ></confirm-button>
  42. </div>
  43. </template>
  44. </base-dialog>
  45. </div>
  46. </template>
  47. <script name="ChooseMarkers" lang="ts" setup>
  48. import { watch, ref, computed } from 'vue'
  49. import useFetch from '@/hooks/useFetch'
  50. import { ElButton, ElInput } from 'element-plus'
  51. import BaseDialog from '../element/BaseDialog.vue'
  52. import { VxeTableEvents } from 'vxe-table'
  53. import ConfirmButton from '@/components/common/ConfirmButton.vue'
  54. import { cloneDeep } from 'lodash-es'
  55. const tableKey = ref(Date.now() + '')
  56. const emits = defineEmits(['user-list'])
  57. const tableMaxHeight = window.innerHeight - 150 + 'px'
  58. const modalVisible = ref(false)
  59. const { fetch: fetchMarkers, result } = useFetch('adminGetMarkers')
  60. const filterText = ref('')
  61. const computedFilterText = ref('')
  62. const filterSearch = () => {
  63. computedFilterText.value = filterText.value
  64. chooseResult.value = []
  65. tableKey.value = Date.now() + ''
  66. }
  67. const tableData = computed(() => {
  68. let arr = []
  69. let res = result.value || []
  70. for (let i = 0; i < res.length; i++) {
  71. let item = res[i]
  72. item.id = '_' + item.markingGroupNumber
  73. item.showName = `第${item.markingGroupNumber}组`
  74. item.parentId = null
  75. item.loginName = ''
  76. let children = item.markers || []
  77. if (
  78. !(
  79. computedFilterText.value &&
  80. !children.find((item: any) => {
  81. return item.loginName.includes(computedFilterText.value) || item.name.includes(computedFilterText.value)
  82. })
  83. )
  84. ) {
  85. arr.push({ ...item })
  86. }
  87. for (let j = 0; j < children.length; j++) {
  88. let child = children[j]
  89. let v = {
  90. id: child.id + '',
  91. parentId: item.id,
  92. showName: child.loginName + '-' + child.name,
  93. loginName: child.loginName,
  94. }
  95. if (
  96. !(
  97. computedFilterText.value &&
  98. !(child.loginName.includes(computedFilterText.value) || child.name.includes(computedFilterText.value))
  99. )
  100. ) {
  101. arr.push({ ...v })
  102. }
  103. }
  104. }
  105. return arr
  106. //以下为大数据量下的测试代码,经验证不卡顿
  107. // let arr = result.value || []
  108. // let arr2 = []
  109. // for (let i = 0; i < 10000; i++) {
  110. // let item = JSON.parse(JSON.stringify(arr[0]))
  111. // item.id = Math.random() + ''
  112. // item.parentId = null
  113. // item.showName = '组组组'
  114. // arr2.push({ ...item })
  115. // for (let j = 0; j < item.markers.length; j++) {
  116. // let v = { id: Math.random(), parentId: item.id, showName: item.markers[j].loginName + '-' + item.markers[j].name }
  117. // arr2.push({ ...v })
  118. // }
  119. // }
  120. // return arr2
  121. })
  122. const props = defineProps<{
  123. subjectCode: string | number | undefined
  124. mainNumber: string | number | undefined
  125. }>()
  126. watch([() => props.subjectCode, () => props.mainNumber], (valArr) => {
  127. if (valArr[0] && valArr[1]) {
  128. fetchMarkers({ subjectCode: valArr[0], mainNumber: valArr[1] })
  129. }
  130. })
  131. const chooseResult = ref<any>([])
  132. const confirmResult = ref<any>([])
  133. const selectChangeEvent: VxeTableEvents.CheckboxChange<any> = ({ $table }) => {
  134. const records = $table.getCheckboxRecords()
  135. // console.info(`勾选${records.length}个树形节点`, records)
  136. chooseResult.value = records.filter((item) => !!item.loginName)
  137. }
  138. const confirm = () => {
  139. confirmResult.value = cloneDeep(chooseResult.value)
  140. emits('user-list', [...confirmResult.value])
  141. modalVisible.value = false
  142. }
  143. const openDialog = () => {
  144. tableKey.value = Date.now() + ''
  145. modalVisible.value = true
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. .choose-markers {
  150. max-height: 100vh;
  151. }
  152. </style>