exList.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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(['handlerEx'])
  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. const open=() =>{
  149. examStore.initSubject(search)
  150. }
  151. // 表格列配置
  152. const columns = [
  153. {
  154. title: 'Id',
  155. dataIndex: 'id',
  156. key: 'id',
  157. width: 90
  158. },
  159. {
  160. title: '学科',
  161. dataIndex: 'subjectId',
  162. key: 'subjectId',
  163. width: 200,
  164. customRender: ({ text }) => examStore.subjectEnumFormat(text)
  165. },
  166. {
  167. title: '名称',
  168. dataIndex: 'name',
  169. key: 'name'
  170. },
  171. {
  172. title: '创建时间',
  173. dataIndex: 'createTime',
  174. key: 'createTime',
  175. width: 200,
  176. customRender: ({ text }) => parseTime(text, '{y}-{m}-{d} {h}:{i}:{s}')
  177. },
  178. {
  179. title: '操作',
  180. key: 'action',
  181. width: 160,
  182. align: 'center'
  183. }
  184. ]
  185. // 计算属性
  186. const levelEnum = computed(() => examStore.getLevelEnum)
  187. // 方法
  188. const submitForm = () => {
  189. queryParam.pageIndex = 1
  190. search()
  191. }
  192. const search = async () => {
  193. listLoading.value = true
  194. try {
  195. const response = await examPaperApi.pageList(queryParam)
  196. if (response) {
  197. const data = response
  198. tableData.value = data.records || []
  199. total.value = data.total || 0
  200. queryParam.pageIndex = data.current || 1
  201. listLoading.value = false
  202. } else {
  203. message.error(response.message || '获取数据失败')
  204. }
  205. } catch (error) {
  206. console.error('获取试卷列表失败:', error)
  207. message.error('获取数据失败')
  208. } finally {
  209. listLoading.value = false
  210. }
  211. }
  212. const deletePaper = async (row) => {
  213. try {
  214. // 显示确认对话框
  215. const confirmed = await new Promise((resolve) => {
  216. Modal.confirm({
  217. title: '确认删除',
  218. content: `确定要删除试卷"${row.name}"吗?`,
  219. okText: '确定',
  220. cancelText: '取消',
  221. onOk: () => resolve(true),
  222. onCancel: () => resolve(false)
  223. })
  224. })
  225. if (!confirmed) return
  226. await examPaperApi.deletePaper(row.id)
  227. search()
  228. } catch (error) {
  229. console.error('删除试卷失败:', error)
  230. message.error('删除失败')
  231. }
  232. }
  233. const levelChange = () => {
  234. queryParam.subjectId = null
  235. subjectFilter.value = examStore.subjects.filter((data) => data.level === queryParam.level)
  236. }
  237. const handlePageChange = (page, pageSize) => {
  238. queryParam.pageIndex = page
  239. queryParam.pageSize = pageSize
  240. search()
  241. }
  242. const handlePageSizeChange = (current, size) => {
  243. queryParam.pageIndex = 1
  244. queryParam.pageSize = size
  245. search()
  246. }
  247. const handleOk = (item) => {
  248. console.log("选取了",item)
  249. modeTag.value = 'item'
  250. itemDatas.value = []
  251. itemDatas.value.push(item)
  252. emit('handlerEx', [item])
  253. }
  254. const handleReset = (item) => {
  255. console.log("选取了",item)
  256. modeTag.value = 'list'
  257. itemDatas.value = []
  258. queryParam.pageIndex = 1
  259. search()
  260. emit('handlerEx', null)
  261. }
  262. const getItemData = () => {
  263. return itemDatas.value
  264. }
  265. const edit = async (id) => {
  266. modeTag.value = 'item'
  267. listLoading.value = true
  268. try {
  269. const response = await examPaperApi.pageList({id :id,current : 1 ,size:10 })
  270. if (response) {
  271. const data = response
  272. itemDatas.value = data.records || []
  273. listLoading.value = false
  274. } else {
  275. message.error(response.message || '获取数据失败')
  276. }
  277. } catch (error) {
  278. console.error('获取试卷列表失败:', error)
  279. message.error('获取数据失败')
  280. } finally {
  281. listLoading.value = false
  282. }
  283. }
  284. // 生命周期
  285. onMounted(async () => {
  286. })
  287. defineExpose({getItemData,edit,open})
  288. </script>
  289. <style lang="less" scoped>
  290. .app-container {
  291. padding: 24px;
  292. background: #fff;
  293. .search-form {
  294. margin-bottom: 24px;
  295. padding: 24px;
  296. background: #fafafa;
  297. border-radius: 6px;
  298. }
  299. .data-table {
  300. margin-bottom: 24px;
  301. }
  302. .pagination {
  303. text-align: right;
  304. }
  305. }
  306. </style>