exLists.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="app-container">
  3. <div v-if="modeTag == 'list'">
  4. <!-- 查询表单 -->
  5. <a-form :model="queryParam" layout="inline" class="search-form">
  6. <a-form-item label="题目ID:">
  7. <a-input v-model:value="queryParam.id" placeholder="请输入题目ID" allow-clear />
  8. </a-form-item>
  9. <!-- <a-form-item label="年级:">
  10. <a-select
  11. v-model:value="queryParam.level"
  12. placeholder="请选择年级"
  13. @change="levelChange"
  14. allow-clear
  15. style="width: 120px"
  16. >
  17. <a-select-option v-for="item in levelEnum" :key="item.key" :value="item.key">
  18. {{ item.value }}
  19. </a-select-option>
  20. </a-select>
  21. </a-form-item>
  22. <a-form-item label="学科:">
  23. <a-select v-model:value="queryParam.subjectId" placeholder="请选择学科" allow-clear style="width: 200px">
  24. <a-select-option v-for="item in subjectFilter" :key="item.id" :value="item.id">
  25. {{ item.name }} ( {{ item.levelName }} )
  26. </a-select-option>
  27. </a-select>
  28. </a-form-item> -->
  29. <a-form-item>
  30. <a-button type="primary" @click="submitForm">查询</a-button>
  31. <!-- <a-button type="primary" @click="openDrawer('add')" style="margin-left: 8px">添加</a-button>-->
  32. </a-form-item>
  33. </a-form>
  34. <!-- 数据表格 -->
  35. <a-table
  36. :loading="listLoading"
  37. :data-source="tableData"
  38. :columns="columns"
  39. :pagination="false"
  40. row-key="id"
  41. class="data-table"
  42. :locale="{ emptyText: '暂无数据' }"
  43. >
  44. <template #bodyCell="{ column, record }">
  45. <template v-if="column.key === 'action'">
  46. <a-button style="margin-right: 10px" type="primary" @click="handleOk(record)">选择
  47. </a-button>
  48. <!-- <a-button size="small" @click="openDrawer('edit', record.id)">编辑</a-button>-->
  49. <!-- <a-button size="small" type="primary" danger @click="deletePaper(record)" style="margin-left: 8px">-->
  50. <!-- 删除-->
  51. <!-- </a-button>-->
  52. </template>
  53. </template>
  54. </a-table>
  55. <!-- 分页 -->
  56. <a-pagination
  57. v-if="total > 0"
  58. :current="queryParam.pageIndex"
  59. :page-size="queryParam.pageSize"
  60. :total="total"
  61. :show-size-changer="true"
  62. :show-quick-jumper="true"
  63. :show-total="(total, range) => `第 ${range[0]}-${range[1]} 条/共 ${total} 条`"
  64. @change="handlePageChange"
  65. @show-size-change="handlePageSizeChange"
  66. class="pagination"
  67. />
  68. <!-- 编辑/添加 抽屉 -->
  69. <a-drawer
  70. :visible="drawerVisible"
  71. :title="drawerTitle"
  72. placement="right"
  73. width="900"
  74. @close="closeDrawer"
  75. destroyOnClose
  76. >
  77. <!-- <FormEdit v-if="drawerVisible" :id="editId" @success="onEditSuccess" />-->
  78. </a-drawer>
  79. </div>
  80. <div v-if="modeTag == 'item'">
  81. <a-table
  82. :loading="listLoading"
  83. :data-source="itemDatas"
  84. :columns="columns"
  85. :pagination="false"
  86. row-key="id"
  87. class="data-table"
  88. :locale="{ emptyText: '暂无数据' }"
  89. >
  90. <template #bodyCell="{ column, record }">
  91. <template v-if="column.key === 'action'">
  92. <a-button style="margin-right: 10px" type="primary" @click="handleReset(record)">重新选择
  93. </a-button>
  94. <!-- <a-button size="small" @click="openDrawer('edit', record.id)">编辑</a-button>-->
  95. <!-- <a-button size="small" type="primary" danger @click="deletePaper(record)" style="margin-left: 8px">-->
  96. <!-- 删除-->
  97. <!-- </a-button>-->
  98. </template>
  99. </template>
  100. </a-table>
  101. </div>
  102. </div>
  103. </template>
  104. <script setup>
  105. import { ref, reactive, computed, onMounted } from 'vue'
  106. import { message, Modal } from 'ant-design-vue'
  107. import { useExamStore } from '@/store/exam'
  108. import examPaperApi from '@/api/exam/paper/examPaperApi'
  109. // import FormEdit from './form.vue'
  110. import { parseTime } from '@/utils/exam'
  111. const emit = defineEmits(['handlerExs'])
  112. const examStore = useExamStore()
  113. const modeTag = ref('list')
  114. const itemDatas = ref([])
  115. // 响应式数据
  116. const queryParam = reactive({
  117. id: null,
  118. // level: null,
  119. // subjectId: null,
  120. current: 1,
  121. size: 10
  122. })
  123. const subjectFilter = ref([])
  124. const listLoading = ref(false)
  125. const tableData = ref([])
  126. const total = ref(0)
  127. // Drawer 控制
  128. const drawerVisible = ref(false)
  129. const drawerTitle = ref('')
  130. const editId = ref(null)
  131. function openDrawer(type, id = null) {
  132. if (type === 'add') {
  133. drawerTitle.value = '添加试卷'
  134. editId.value = null
  135. } else {
  136. drawerTitle.value = '编辑试卷'
  137. editId.value = id
  138. }
  139. drawerVisible.value = true
  140. }
  141. function closeDrawer() {
  142. drawerVisible.value = false
  143. }
  144. function onEditSuccess() {
  145. closeDrawer()
  146. search()
  147. }
  148. // 表格列配置
  149. const columns = [
  150. {
  151. title: 'Id',
  152. dataIndex: 'id',
  153. key: 'id',
  154. width: 90
  155. },
  156. {
  157. title: '学科',
  158. dataIndex: 'subjectId',
  159. key: 'subjectId',
  160. width: 200,
  161. customRender: ({ text }) => examStore.subjectEnumFormat(text)
  162. },
  163. {
  164. title: '名称',
  165. dataIndex: 'name',
  166. key: 'name'
  167. },
  168. {
  169. title: '创建时间',
  170. dataIndex: 'createTime',
  171. key: 'createTime',
  172. width: 200,
  173. customRender: ({ text }) => parseTime(text, '{y}-{m}-{d} {h}:{i}:{s}')
  174. },
  175. {
  176. title: '操作',
  177. key: 'action',
  178. width: 160,
  179. align: 'center'
  180. }
  181. ]
  182. // 计算属性
  183. const levelEnum = computed(() => examStore.getLevelEnum)
  184. // 方法
  185. const submitForm = () => {
  186. queryParam.pageIndex = 1
  187. search()
  188. }
  189. const search = async () => {
  190. listLoading.value = true
  191. try {
  192. const response = await examPaperApi.pageList(queryParam)
  193. if (response) {
  194. const data = response
  195. tableData.value = data.records || []
  196. total.value = data.total || 0
  197. queryParam.pageIndex = data.current || 1
  198. listLoading.value = false
  199. } else {
  200. message.error(response.message || '获取数据失败')
  201. }
  202. } catch (error) {
  203. console.error('获取试卷列表失败:', error)
  204. message.error('获取数据失败')
  205. } finally {
  206. listLoading.value = false
  207. }
  208. }
  209. const deletePaper = async (row) => {
  210. try {
  211. // 显示确认对话框
  212. const confirmed = await new Promise((resolve) => {
  213. Modal.confirm({
  214. title: '确认删除',
  215. content: `确定要删除试卷"${row.name}"吗?`,
  216. okText: '确定',
  217. cancelText: '取消',
  218. onOk: () => resolve(true),
  219. onCancel: () => resolve(false)
  220. })
  221. })
  222. if (!confirmed) return
  223. await examPaperApi.deletePaper(row.id)
  224. search()
  225. } catch (error) {
  226. console.error('删除试卷失败:', error)
  227. message.error('删除失败')
  228. }
  229. }
  230. const levelChange = () => {
  231. queryParam.subjectId = null
  232. subjectFilter.value = examStore.subjects.filter((data) => data.level === queryParam.level)
  233. }
  234. const handlePageChange = (page, pageSize) => {
  235. queryParam.pageIndex = page
  236. queryParam.pageSize = pageSize
  237. search()
  238. }
  239. const handlePageSizeChange = (current, size) => {
  240. queryParam.pageIndex = 1
  241. queryParam.pageSize = size
  242. search()
  243. }
  244. const handleOk = (item) => {
  245. console.log("选取了",item)
  246. modeTag.value = 'item'
  247. itemDatas.value = []
  248. itemDatas.value.push(item)
  249. emit('handlerExs', [item])
  250. }
  251. const handleReset = (item) => {
  252. console.log("选取了",item)
  253. modeTag.value = 'list'
  254. itemDatas.value = []
  255. queryParam.pageIndex = 1
  256. search()
  257. emit('handlerExs',null)
  258. }
  259. const getItemData = () => {
  260. return itemDatas.value
  261. }
  262. const edit = async (id) => {
  263. modeTag.value = 'item'
  264. listLoading.value = true
  265. try {
  266. const response = await examPaperApi.pageList({id :id,current : 1 ,size:10 })
  267. if (response) {
  268. const data = response
  269. itemDatas.value = data.records || []
  270. listLoading.value = false
  271. } else {
  272. message.error(response.message || '获取数据失败')
  273. }
  274. } catch (error) {
  275. console.error('获取试卷列表失败:', error)
  276. message.error('获取数据失败')
  277. } finally {
  278. listLoading.value = false
  279. }
  280. }
  281. // 生命周期
  282. onMounted(async () => {
  283. // examStore.initSubject(search)
  284. })
  285. const open=() =>{
  286. examStore.initSubject(search)
  287. }
  288. defineExpose({getItemData,edit,open})
  289. </script>
  290. <style lang="less" scoped>
  291. .app-container {
  292. padding: 24px;
  293. background: #fff;
  294. .search-form {
  295. margin-bottom: 24px;
  296. padding: 24px;
  297. background: #fafafa;
  298. border-radius: 6px;
  299. }
  300. .data-table {
  301. margin-bottom: 24px;
  302. }
  303. .pagination {
  304. text-align: right;
  305. }
  306. }
  307. </style>