StudentDetails.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. <template>
  2. <div class="student-details-page">
  3. <!-- 搜索栏 -->
  4. <div class="search-bar">
  5. <a-input
  6. v-model:value="searchForm.queryInfo"
  7. placeholder="姓名/学号/手机"
  8. style="width: 180px; margin-right: 12px"
  9. />
  10. <a-select v-model:value="searchForm.gender" placeholder="选择学生性别" style="width: 150px; margin-right: 12px">
  11. <a-select-option value="男">男</a-select-option>
  12. <a-select-option value="女">女</a-select-option>
  13. </a-select>
  14. <a-select v-model:value="searchForm.userStatus" placeholder="请选择状态" style="width: 120px; margin-right: 12px">
  15. <a-select-option v-for="(item, index) in statusOptions" :key="index" :value="item.value">{{
  16. item.label
  17. }}</a-select-option>
  18. </a-select>
  19. <a-range-picker
  20. @change="handleDateChange"
  21. v-model:value="searchForm.date"
  22. style="margin-right: 12px; width: 240px"
  23. />
  24. <a-button type="primary" @click="onSearch" style="margin-right: 8px">查询</a-button>
  25. <a-button @click="onReset">重置</a-button>
  26. </div>
  27. <!-- 操作按钮 -->
  28. <div class="action-bar">
  29. <a-button type="primary" @click="onAddStudent" style="margin-right: 8px">+ 新增学员</a-button>
  30. <a-upload
  31. name="file"
  32. :showUploadList="false"
  33. :beforeUpload="beforeUpload"
  34. :customRequest="customRequest"
  35. accept=".xlsx,.xls"
  36. >
  37. <a-button>导入</a-button>
  38. </a-upload>
  39. <a-button style="margin-left: 10px" @click="downloadImport">下载导入模板</a-button>
  40. </div>
  41. <!-- 表格 -->
  42. <a-table
  43. :columns="columns"
  44. :row-key="rowKey"
  45. :data-source="pagedDatas"
  46. :pagination="false"
  47. :row-selection="rowSelection"
  48. :scroll="{ x: 1000, y: 320 }"
  49. bordered
  50. class="student-table"
  51. >
  52. <template #bodyCell="{ column, record }">
  53. <template v-if="column.dataIndex === 'status'">
  54. <span>
  55. <a-badge status="success" v-if="record.status === '启用'" text="启用" />
  56. <a-badge status="default" v-else text="禁用" />
  57. </span>
  58. </template>
  59. <template v-else-if="column.dataIndex === 'online'">
  60. <span>
  61. <a-badge status="success" v-if="record.online" text="在线" />
  62. <a-badge status="default" v-else text="离线" />
  63. </span>
  64. </template>
  65. <template v-else-if="column.dataIndex === 'actions'">
  66. <a-space>
  67. <a-button size="small" @click="onDetail(record)">详情</a-button>
  68. <!-- <a-button size="small" @click="onEdit(record)">编辑</a-button> -->
  69. <!-- <a-button size="small" @click="onSetting(record)">设置</a-button> -->
  70. <a-popconfirm title="删除此条目?" @confirm="onDelete(record)">
  71. <a-button size="small" danger>删除</a-button>
  72. </a-popconfirm>
  73. </a-space>
  74. </template>
  75. </template>
  76. </a-table>
  77. <!-- 批量操作和分页 -->
  78. <div class="table-footer">
  79. <div class="batch-actions">
  80. <a-button @click="onSelectAll">选择全部</a-button>
  81. <a-button @click="onInvertSelect">反向选择</a-button>
  82. <a-dropdown>
  83. <a-button>更多操作 <DownOutlined /></a-button>
  84. <template #overlay>
  85. <a-menu>
  86. <a-menu-item>批量启用</a-menu-item>
  87. <a-menu-item>批量禁用</a-menu-item>
  88. <a-menu-item>批量删除</a-menu-item>
  89. </a-menu>
  90. </template>
  91. </a-dropdown>
  92. </div>
  93. <a-pagination
  94. :current="currentPage"
  95. :page-size="pageSize"
  96. :total="total"
  97. @change="onPageChange"
  98. show-quick-jumper
  99. :show-total="(total) => `共${total}条`"
  100. style="margin-left: auto"
  101. />
  102. <a-select v-model:value="pageSize" style="width: 100px; margin-left: 16px" @change="onPageSizeChange">
  103. <a-select-option :value="10">10/页</a-select-option>
  104. <a-select-option :value="20">20/页</a-select-option>
  105. <a-select-option :value="50">50/页</a-select-option>
  106. </a-select>
  107. </div>
  108. <!-- 新增学员弹窗 -->
  109. <a-modal
  110. v-model:visible="addStudentVisible"
  111. title="新增学员"
  112. width="720px"
  113. :footer="null"
  114. @cancel="handleAddStudentCancel"
  115. >
  116. <studentSelection
  117. :studentIds="studentIdss"
  118. @close="handleAddStudentCancel"
  119. @confirm="confirmStudent"
  120. ></studentSelection>
  121. </a-modal>
  122. <!-- 详情弹窗 -->
  123. <a-modal
  124. v-model:visible="detailVisible"
  125. title="个人实名认证"
  126. width="900px"
  127. :footer="null"
  128. @cancel="() => (detailVisible = false)"
  129. >
  130. <div class="student-detail-modal">
  131. <a-table
  132. :pagination="false"
  133. :show-header="false"
  134. :data-source="[detailData]"
  135. :columns="[{ title: '', dataIndex: 'id', key: 'id' }]"
  136. style="display: none"
  137. />
  138. <table class="detail-table">
  139. <tr>
  140. <th>ID编号</th>
  141. <th>学生姓名</th>
  142. <th>手机号码</th>
  143. <th>性别</th>
  144. </tr>
  145. <tr>
  146. <td>{{ detailData.ACCOUNT }}</td>
  147. <td>{{ detailData.userIdName }}</td>
  148. <td>{{ detailData.phone }}</td>
  149. <td>{{ detailData.gender }}</td>
  150. </tr>
  151. <tr>
  152. <th>所在院系</th>
  153. <th>所在班级</th>
  154. <th>生日</th>
  155. <th>所在城市</th>
  156. </tr>
  157. <tr>
  158. <td>{{ detailData.orgIdName }}</td>
  159. <td>{{ detailData.className }}</td>
  160. <td>{{ detailData.birth }}</td>
  161. <td>{{ detailData.city }}</td>
  162. </tr>
  163. <tr>
  164. <th>学籍状态</th>
  165. <th>在线状态</th>
  166. <th>注册时间</th>
  167. <th>最后登录</th>
  168. </tr>
  169. <tr>
  170. <td>{{ detailData.userStatusName }}</td>
  171. <td>{{ detailData.isLoginName }}</td>
  172. <td>{{ detailData.createTime }}</td>
  173. <td>{{ detailData.latestLoginTime }}</td>
  174. </tr>
  175. </table>
  176. <div class="modal-btn-bar">
  177. <a-button type="primary" style="width: 120px; margin-top: 24px" @click="() => (detailVisible = false)">
  178. 关闭</a-button
  179. >
  180. </div>
  181. </div>
  182. </a-modal>
  183. </div>
  184. </template>
  185. <script setup>
  186. import { ref, reactive, computed, onMounted, unref} from 'vue'
  187. import { message } from 'ant-design-vue'
  188. import { DownOutlined } from '@ant-design/icons-vue'
  189. import { getDepartmentMembers } from '@/api/course/courseDetail'
  190. import studentDetailsApi from '@/api/courseCenter/studentDetails.js'
  191. import { getStudentDetail } from '@/api/course/courseDetail'
  192. import studentSelection from './studentSelection.vue'
  193. import tool from '@/utils/tool'
  194. const props = defineProps({
  195. //课程id
  196. courseInfoId: {
  197. type: Number,
  198. required: true,
  199. default: null
  200. }
  201. })
  202. // mock数据
  203. const allStudents = ref([
  204. // 生成20条mock数据
  205. ...Array.from({ length: 20 }).map((_, i) => ({
  206. id: i + 1,
  207. studentNo: 'xy' + String(100000 + i),
  208. name: '张小刚',
  209. gender: i % 2 === 0 ? '男' : '女',
  210. userStatus: '启用',
  211. phone: '18088889999',
  212. online: true,
  213. lastLogin: '2020-11-25 23:26:08'
  214. }))
  215. ])
  216. const searchForm = reactive({
  217. queryInfo: null,
  218. gender: null,
  219. userStatus: null,
  220. date: [],
  221. startTime: null, // 新增开始时间字段
  222. endTime: null // 新增结束时间字段
  223. })
  224. const columns = [
  225. { title: '学员编号', dataIndex: 'ACCOUNT', align: 'center' },
  226. { title: '姓名', dataIndex: 'userIdName', align: 'center' },
  227. { title: '性别', dataIndex: 'gender', align: 'center' },
  228. { title: '账号状态', dataIndex: 'userStatusName', align: 'center' },
  229. { title: '手机号', dataIndex: 'phone', align: 'center' },
  230. { title: '在线状态', dataIndex: 'isLoginName', align: 'center' },
  231. { title: '最后登录', dataIndex: 'latestLoginTime', align: 'center' },
  232. { title: '操作', dataIndex: 'actions', fixed: 'right', align: 'center', width: 220 }
  233. ]
  234. const studentIdss = ref([]) //学员回显id
  235. const statusOptions = tool.dictList('COMMON_STATUS') //学员状态
  236. const currentPage = ref(1)
  237. const pageSize = ref(10)
  238. const total = ref(0)
  239. const selectedRowKeys = ref([])
  240. const addStudentVisible = ref(false)
  241. const departments = ref([])
  242. const searchDeptMember = ref('')
  243. const expandedDeptIds = ref([])
  244. const checkedMemberIds = ref([])
  245. const selectedMembers = ref([])
  246. const detailVisible = ref(false)
  247. const detailData = ref({})
  248. const pagedDatas = ref([])
  249. const rowKey = (record) => record.relateId
  250. const filteredData = computed(() => {
  251. let data = allStudents.value
  252. if (searchForm.queryInfo) {
  253. data = data.filter(
  254. (item) =>
  255. item.name.includes(searchForm.queryInfo) ||
  256. item.studentNo.includes(searchForm.queryInfo) ||
  257. item.phone.includes(searchForm.queryInfo)
  258. )
  259. }
  260. if (searchForm.status) {
  261. data = data.filter((item) => item.status === searchForm.status)
  262. }
  263. // 这里可以加更多筛选条件
  264. return data
  265. })
  266. const pagedData = computed(() => {
  267. const start = (currentPage.value - 1) * pageSize.value
  268. return filteredData.value.slice(start, start + pageSize.value)
  269. })
  270. const rowSelection = computed(() => {
  271. return {
  272. selectedRowKeys: unref(selectedRowKeys),
  273. onChange: (changeRowKeys) => {
  274. console.log(changeRowKeys, 'changeRowKeyschangeRowKeys')
  275. selectedRowKeys.value = changeRowKeys
  276. },
  277. hideDefaultSelections: true,
  278. }
  279. })
  280. //添加学员确认
  281. const confirmStudent = (StudentIds) => {
  282. console.log(StudentIds, '学员id')
  283. addStudentVisible.value = false
  284. searchForm.StudentIds = StudentIds.join(',')
  285. let params = {
  286. userIds: searchForm.StudentIds,
  287. courseId: props.courseInfoId
  288. }
  289. studentDetailsApi
  290. .add(params)
  291. .then((res) => {
  292. console.log(res, '学员添加')
  293. getList()
  294. })
  295. .catch((err) => {
  296. console.log(err)
  297. })
  298. }
  299. function onSearch() {
  300. currentPage.value = 1
  301. console.log(searchForm, '搜索参数')
  302. getList()
  303. }
  304. const getList = () => {
  305. const params = {
  306. queryInfo: searchForm.queryInfo,
  307. gender: searchForm.gender,
  308. userStatus: searchForm.userStatus,
  309. latestLoginStartTime: searchForm.startTime,
  310. latestLoginEndTime: searchForm.endTime,
  311. current: currentPage.value,
  312. size: pageSize.value,
  313. courseId: props.courseInfoId
  314. }
  315. studentDetailsApi
  316. .queryList(params)
  317. .then((res) => {
  318. console.log(res, '学院列表')
  319. pagedDatas.value = res.data.records
  320. total.value = res.data.total
  321. })
  322. .catch((err) => {
  323. console.log(err)
  324. })
  325. }
  326. function handleDateChange(dates, dateStrings) {
  327. // dates 是 Moment 对象数组,dateStrings 是格式化后的字符串数组
  328. if (dates && dates.length === 2) {
  329. searchForm.startTime = dateStrings[0] // 开始时间字符串
  330. searchForm.endTime = dateStrings[1] // 结束时间字符串
  331. } else {
  332. searchForm.startTime = null
  333. searchForm.endTime = null
  334. }
  335. }
  336. const importLoading = ref(false)
  337. // 文件上传前校验
  338. const beforeUpload = (file) => {
  339. const isExcel = file.type.includes('excel') || file.name.endsWith('.xlsx') || file.name.endsWith('.xls')
  340. if (!isExcel) {
  341. message.error('只能上传Excel文件!')
  342. return false
  343. }
  344. return true
  345. }
  346. // 自定义上传实现
  347. const customRequest = async (options) => {
  348. const { file, onSuccess, onError } = options
  349. importLoading.value = true
  350. try {
  351. const formData = new FormData()
  352. formData.append('file', file)
  353. formData.append('courseId', props.courseInfoId)
  354. // 调用API接口
  355. const res = await studentDetailsApi.importStudents(formData)
  356. console.log(res)
  357. message.info(
  358. `成功导入 ${res.data.successCount} 条数据,导入失败:${
  359. res.data.errorCount
  360. } 条数据,失败下标为: ${res.data.errorDetail.map((item) => item.index).join(',')}`
  361. )
  362. onSuccess(res, file)
  363. getList() // 刷新列表
  364. } catch (error) {
  365. console.log(error)
  366. message.error(`导入失败: ${error}`)
  367. onError(error)
  368. } finally {
  369. importLoading.value = false
  370. }
  371. }
  372. function onReset() {
  373. searchForm.queryInfo = null
  374. searchForm.gender = null
  375. searchForm.userStatus = null
  376. searchForm.startTime = null
  377. searchForm.date = null
  378. searchForm.endTime = null
  379. currentPage.value = 1
  380. getList()
  381. }
  382. function onPageChange(page) {
  383. currentPage.value = page
  384. getList()
  385. }
  386. function onPageSizeChange(size) {
  387. pageSize.value = size
  388. currentPage.value = 1
  389. getList()
  390. }
  391. function onSelectAll() {
  392. console.log(pagedDatas.value)
  393. selectedRowKeys.value = pagedDatas.value.map((item) => item.relateId)
  394. }
  395. function onInvertSelect() {
  396. const currentIds = pagedDatas.value.map((item) => item.relateId)
  397. selectedRowKeys.value = currentIds.filter((id) => !selectedRowKeys.value.includes(id))
  398. }
  399. function onAddStudent() {
  400. addStudentVisible.value = true
  401. // 默认展开所有部门
  402. // expandedDeptIds.value = departments.value.map((d) => d.id)
  403. }
  404. function downloadImport() {
  405. studentDetailsApi
  406. .downloadImportlate()
  407. .then((res) => {
  408. console.log(res.data, 'messagemessagemessage')
  409. // 创建 blob 对象
  410. const blob = new Blob([res.data], {
  411. type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  412. })
  413. // 创建下载链接
  414. const downloadUrl = window.URL.createObjectURL(blob)
  415. const link = document.createElement('a')
  416. link.href = downloadUrl
  417. // 设置下载文件名(可以从响应头获取或固定)
  418. link.download = '学生导入模板.xlsx'
  419. // 触发下载
  420. document.body.appendChild(link)
  421. link.click()
  422. // 清理
  423. window.URL.revokeObjectURL(downloadUrl)
  424. document.body.removeChild(link)
  425. })
  426. .catch((err) => {
  427. message.error('模板下载失败: ' + (err || err))
  428. console.error(err)
  429. })
  430. }
  431. function handleAddStudentCancel() {
  432. addStudentVisible.value = false
  433. }
  434. function handleAddStudentOk() {
  435. // TODO: 选中成员加入主表
  436. addStudentVisible.value = false
  437. }
  438. function onDeptMemberSearch() {
  439. // 搜索时自动展开所有部门
  440. expandedDeptIds.value = filteredDepartments.value.map((d) => d.id)
  441. }
  442. function toggleDept(id) {
  443. if (expandedDeptIds.value.includes(id)) {
  444. expandedDeptIds.value = expandedDeptIds.value.filter((did) => did !== id)
  445. } else {
  446. expandedDeptIds.value.push(id)
  447. }
  448. }
  449. function onMemberCheckChange(ids) {
  450. // 限制最多30人
  451. if (ids.length > 30) {
  452. ids = ids.slice(0, 30)
  453. }
  454. checkedMemberIds.value = ids
  455. updateSelectedMembers()
  456. }
  457. function isCheckedLimit(id) {
  458. return checkedMemberIds.value.length >= 30 && !checkedMemberIds.value.includes(id)
  459. }
  460. function updateSelectedMembers() {
  461. // 根据 checkedMemberIds 更新 selectedMembers
  462. const all = []
  463. departments.value.forEach((dept) => {
  464. dept.members.forEach((m) => all.push({ ...m, deptName: dept.name }))
  465. })
  466. selectedMembers.value = all.filter((m) => checkedMemberIds.value.includes(m.id))
  467. }
  468. function removeSelected(id) {
  469. checkedMemberIds.value = checkedMemberIds.value.filter((mid) => mid !== id)
  470. updateSelectedMembers()
  471. }
  472. function clearSelected() {
  473. checkedMemberIds.value = []
  474. updateSelectedMembers()
  475. }
  476. const filteredDepartments = computed(() => {
  477. if (!searchDeptMember.value) return departments.value
  478. // 部门名或成员名匹配
  479. return departments.value
  480. .map((dept) => {
  481. const matchDept = dept.name.includes(searchDeptMember.value)
  482. const filteredMembers = dept.members.filter((m) => m.name.includes(searchDeptMember.value))
  483. if (matchDept || filteredMembers.length) {
  484. return {
  485. ...dept,
  486. members: matchDept ? dept.members : filteredMembers
  487. }
  488. }
  489. return null
  490. })
  491. .filter(Boolean)
  492. })
  493. onMounted(async () => {
  494. departments.value = await getDepartmentMembers()
  495. getList()
  496. })
  497. function onDetail(record) {
  498. detailVisible.value = true
  499. let params = {
  500. id: record.relateId
  501. }
  502. studentDetailsApi
  503. .detail(params)
  504. .then((res) => {
  505. console.log(res, '学员详情')
  506. detailData.value = res.data
  507. })
  508. .catch((err) => {
  509. console.log(err)
  510. })
  511. }
  512. function onEdit(record) {
  513. // TODO: 编辑弹窗
  514. }
  515. function onSetting(record) {
  516. // TODO: 设置弹窗
  517. }
  518. function onDelete(record) {
  519. let params = [
  520. {
  521. id: record.relateId
  522. }
  523. ]
  524. studentDetailsApi
  525. .delete(params)
  526. .then((res) => {
  527. console.log(res, '删除学员')
  528. getList()
  529. })
  530. .catch((err) => {
  531. console.log(err)
  532. })
  533. }
  534. </script>
  535. <style lang="less" scoped>
  536. .student-details-page {
  537. background: #fff;
  538. border-radius: 12px;
  539. width: 1200px;
  540. margin: 0 auto;
  541. padding: 32px 32px 24px 32px;
  542. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.04);
  543. height: calc(100vh - 400px);
  544. overflow: auto;
  545. .search-bar {
  546. display: flex;
  547. align-items: center;
  548. margin-bottom: 18px;
  549. }
  550. .action-bar {
  551. margin-bottom: 16px;
  552. display: flex;
  553. align-items: center;
  554. }
  555. .student-table {
  556. margin-bottom: 12px;
  557. .ant-table-thead > tr > th {
  558. background: #f7f8fa;
  559. font-weight: 600;
  560. color: #222;
  561. font-size: 15px;
  562. }
  563. .ant-table-tbody > tr > td {
  564. font-size: 14px;
  565. color: #333;
  566. }
  567. .ant-btn {
  568. font-size: 13px;
  569. padding: 0 10px;
  570. border-radius: 4px;
  571. }
  572. .ant-btn-dangerous {
  573. background: #fff1f0;
  574. color: #ff4d4f;
  575. border: 1px solid #ffccc7;
  576. }
  577. }
  578. .table-footer {
  579. display: flex;
  580. align-items: center;
  581. margin-top: 12px;
  582. .batch-actions {
  583. display: flex;
  584. align-items: center;
  585. gap: 8px;
  586. }
  587. }
  588. }
  589. .add-student-modal {
  590. display: flex;
  591. min-height: 400px;
  592. .left-panel {
  593. width: 320px;
  594. border-right: 1px solid #f0f0f0;
  595. padding-right: 16px;
  596. .search-input {
  597. margin-bottom: 12px;
  598. }
  599. .dept-list {
  600. max-height: 340px;
  601. overflow-y: auto;
  602. }
  603. .dept-name {
  604. font-weight: 600;
  605. margin: 8px 0 4px 0;
  606. cursor: pointer;
  607. display: flex;
  608. align-items: center;
  609. }
  610. .member-list {
  611. margin-left: 20px;
  612. margin-bottom: 8px;
  613. }
  614. .member-item {
  615. margin: 4px 0;
  616. display: flex;
  617. align-items: center;
  618. }
  619. }
  620. .right-panel {
  621. flex: 1;
  622. padding-left: 24px;
  623. .selected-header {
  624. font-weight: 600;
  625. margin-bottom: 8px;
  626. }
  627. .selected-list {
  628. min-height: 340px;
  629. max-height: 340px;
  630. overflow-y: auto;
  631. .selected-item {
  632. display: flex;
  633. align-items: center;
  634. background: #f5f5f5;
  635. border-radius: 4px;
  636. padding: 4px 8px;
  637. margin-bottom: 6px;
  638. .remove-icon {
  639. margin-left: auto;
  640. color: #999;
  641. cursor: pointer;
  642. }
  643. }
  644. }
  645. }
  646. }
  647. .modal-footer {
  648. display: flex;
  649. justify-content: flex-end;
  650. margin-top: 18px;
  651. }
  652. .student-detail-modal {
  653. .detail-table {
  654. width: 100%;
  655. border-collapse: collapse;
  656. margin-bottom: 0;
  657. th,
  658. td {
  659. border: 1px solid #e8e8e8;
  660. padding: 12px 16px;
  661. text-align: left;
  662. font-size: 15px;
  663. background: #fff;
  664. }
  665. th {
  666. background: #fafafa;
  667. font-weight: 600;
  668. color: #222;
  669. }
  670. tr:not(:first-child) td {
  671. color: #333;
  672. }
  673. }
  674. .modal-btn-bar {
  675. text-align: center;
  676. }
  677. }
  678. </style>