StudentDetails.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <template>
  2. <div class="student-details-page">
  3. <!-- 搜索栏 -->
  4. <div class="search-bar">
  5. <a-input
  6. v-model:value="searchForm.keyword"
  7. placeholder="姓名/学号/手机"
  8. style="width: 180px; margin-right: 12px"
  9. />
  10. <a-select v-model:value="searchForm.type" 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-option value="VIP">VIP</a-select-option>
  14. </a-select>
  15. <a-select v-model:value="searchForm.status" placeholder="状态选项" style="width: 120px; margin-right: 12px">
  16. <a-select-option value="">全部状态</a-select-option>
  17. <a-select-option value="启用">启用</a-select-option>
  18. <a-select-option value="禁用">禁用</a-select-option>
  19. </a-select>
  20. <a-range-picker v-model:value="searchForm.date" style="margin-right: 12px; width: 240px" />
  21. <a-button type="primary" @click="onSearch" style="margin-right: 8px">查询</a-button>
  22. <a-button @click="onReset">重置</a-button>
  23. </div>
  24. <!-- 操作按钮 -->
  25. <div class="action-bar">
  26. <a-button type="primary" @click="onAddStudent" style="margin-right: 8px">+ 新增学员</a-button>
  27. <a-button>导入导出</a-button>
  28. </div>
  29. <!-- 表格 -->
  30. <a-table
  31. row-key="id"
  32. :columns="columns"
  33. :data-source="pagedData"
  34. :pagination="false"
  35. :row-selection="rowSelection"
  36. bordered
  37. class="student-table"
  38. >
  39. <template #bodyCell="{ column, record }">
  40. <template v-if="column.dataIndex === 'status'">
  41. <span>
  42. <a-badge status="success" v-if="record.status === '启用'" text="启用" />
  43. <a-badge status="default" v-else text="禁用" />
  44. </span>
  45. </template>
  46. <template v-else-if="column.dataIndex === 'online'">
  47. <span>
  48. <a-badge status="success" v-if="record.online" text="在线" />
  49. <a-badge status="default" v-else text="离线" />
  50. </span>
  51. </template>
  52. <template v-else-if="column.dataIndex === 'actions'">
  53. <a-space>
  54. <a-button size="small" @click="onDetail(record)">详情</a-button>
  55. <a-button size="small" @click="onEdit(record)">编辑</a-button>
  56. <a-button size="small" @click="onSetting(record)">设置</a-button>
  57. <a-button size="small" danger @click="onDelete(record)">删除</a-button>
  58. </a-space>
  59. </template>
  60. </template>
  61. </a-table>
  62. <!-- 批量操作和分页 -->
  63. <div class="table-footer">
  64. <div class="batch-actions">
  65. <a-button @click="onSelectAll">选择全部</a-button>
  66. <a-button @click="onInvertSelect">反向选择</a-button>
  67. <a-dropdown>
  68. <a-button>更多操作 <DownOutlined /></a-button>
  69. <template #overlay>
  70. <a-menu>
  71. <a-menu-item>批量启用</a-menu-item>
  72. <a-menu-item>批量禁用</a-menu-item>
  73. <a-menu-item>批量删除</a-menu-item>
  74. </a-menu>
  75. </template>
  76. </a-dropdown>
  77. </div>
  78. <a-pagination
  79. :current="currentPage"
  80. :page-size="pageSize"
  81. :total="filteredData.length"
  82. @change="onPageChange"
  83. show-quick-jumper
  84. :show-total="(total) => `共${total}条`"
  85. style="margin-left: auto"
  86. />
  87. <a-select v-model:value="pageSize" style="width: 100px; margin-left: 16px" @change="onPageSizeChange">
  88. <a-select-option :value="10">10/页</a-select-option>
  89. <a-select-option :value="20">20/页</a-select-option>
  90. <a-select-option :value="50">50/页</a-select-option>
  91. </a-select>
  92. </div>
  93. <!-- 新增学员弹窗 -->
  94. <a-modal
  95. v-model:visible="addStudentVisible"
  96. title="新增学员"
  97. width="720px"
  98. :footer="null"
  99. @cancel="handleAddStudentCancel"
  100. >
  101. <div class="add-student-modal">
  102. <!-- 左侧部门成员树 -->
  103. <div class="left-panel">
  104. <a-input
  105. v-model:value="searchDeptMember"
  106. placeholder="输入部门或成员名称"
  107. allow-clear
  108. class="search-input"
  109. @input="onDeptMemberSearch"
  110. />
  111. <div class="dept-list">
  112. <template v-for="dept in filteredDepartments" :key="dept.id">
  113. <div class="dept-name" @click="toggleDept(dept.id)">
  114. <DownOutlined v-if="expandedDeptIds.includes(dept.id)" style="margin-right: 4px" />
  115. <RightOutlined v-else style="margin-right: 4px" />
  116. {{ dept.name }}
  117. </div>
  118. <div v-if="expandedDeptIds.includes(dept.id)" class="member-list">
  119. <a-checkbox-group :value="checkedMemberIds" @change="onMemberCheckChange">
  120. <div v-for="member in dept.members" :key="member.id" class="member-item">
  121. <a-checkbox :value="member.id" :disabled="isCheckedLimit(member.id)">
  122. <UserOutlined style="margin-right: 4px" />{{ member.name }}
  123. </a-checkbox>
  124. </div>
  125. </a-checkbox-group>
  126. </div>
  127. </template>
  128. </div>
  129. </div>
  130. <!-- 右侧已选成员列表 -->
  131. <div class="right-panel">
  132. <div class="selected-header">
  133. 已选 {{ selectedMembers.length }}/30
  134. <a @click="clearSelected" style="float: right; color: #1890ff">清空</a>
  135. </div>
  136. <div class="selected-list">
  137. <div v-for="member in selectedMembers" :key="member.id" class="selected-item">
  138. <UserOutlined style="margin-right: 4px" />{{ member.name }}
  139. <CloseOutlined class="remove-icon" @click="removeSelected(member.id)" />
  140. </div>
  141. </div>
  142. </div>
  143. </div>
  144. <div class="modal-footer">
  145. <a-button @click="handleAddStudentCancel">取消</a-button>
  146. <a-button type="primary" @click="handleAddStudentOk">确定</a-button>
  147. </div>
  148. </a-modal>
  149. <!-- 详情弹窗 -->
  150. <a-modal
  151. v-model:visible="detailVisible"
  152. title="个人实名认证"
  153. width="900px"
  154. :footer="null"
  155. @cancel="() => (detailVisible = false)"
  156. >
  157. <div class="student-detail-modal">
  158. <a-table
  159. :pagination="false"
  160. :show-header="false"
  161. :data-source="[detailData]"
  162. :columns="[{ title: '', dataIndex: 'id', key: 'id' }]"
  163. style="display: none"
  164. />
  165. <table class="detail-table">
  166. <tr>
  167. <th>ID编号</th>
  168. <th>学生姓名</th>
  169. <th>手机号码</th>
  170. <th>性别</th>
  171. </tr>
  172. <tr>
  173. <td>{{ detailData.id }}</td>
  174. <td>{{ detailData.name }}</td>
  175. <td>{{ detailData.phone }}</td>
  176. <td>{{ detailData.gender }}</td>
  177. </tr>
  178. <tr>
  179. <th>所在院系</th>
  180. <th>所在班级</th>
  181. <th>生日</th>
  182. <th>所在城市</th>
  183. </tr>
  184. <tr>
  185. <td>{{ detailData.college }}</td>
  186. <td>{{ detailData.className }}</td>
  187. <td>{{ detailData.birthday }}</td>
  188. <td>{{ detailData.city }}</td>
  189. </tr>
  190. <tr>
  191. <th>学籍状态</th>
  192. <th>在线状态</th>
  193. <th>注册时间</th>
  194. <th>最后登录</th>
  195. </tr>
  196. <tr>
  197. <td>{{ detailData.educationStatus }}</td>
  198. <td>{{ detailData.onlineStatus }}</td>
  199. <td>{{ detailData.registerTime }}</td>
  200. <td>{{ detailData.lastLogin }}</td>
  201. </tr>
  202. </table>
  203. <div class="modal-btn-bar">
  204. <a-button type="primary" style="width: 120px; margin-top: 24px" @click="() => (detailVisible = false)">
  205. 关闭</a-button
  206. >
  207. </div>
  208. </div>
  209. </a-modal>
  210. </div>
  211. </template>
  212. <script setup>
  213. import { ref, computed, onMounted } from 'vue'
  214. import { DownOutlined } from '@ant-design/icons-vue'
  215. import { getDepartmentMembers } from '@/api/course/courseDetail'
  216. import { getStudentDetail } from '@/api/course/courseDetail'
  217. // mock数据
  218. const allStudents = ref([
  219. // 生成20条mock数据
  220. ...Array.from({ length: 20 }).map((_, i) => ({
  221. id: i + 1,
  222. studentNo: 'xy' + String(100000 + i),
  223. name: '张小刚',
  224. gender: i % 2 === 0 ? '男' : '女',
  225. status: '启用',
  226. phone: '18088889999',
  227. online: true,
  228. lastLogin: '2020-11-25 23:26:08'
  229. }))
  230. ])
  231. const searchForm = ref({
  232. keyword: '',
  233. type: '',
  234. status: '',
  235. date: []
  236. })
  237. const columns = [
  238. { title: '学号', dataIndex: 'studentNo', align: 'center' },
  239. { title: '姓名', dataIndex: 'name', align: 'center' },
  240. { title: '性别', dataIndex: 'gender', align: 'center' },
  241. { title: '账号状态', dataIndex: 'status', align: 'center' },
  242. { title: '手机', dataIndex: 'phone', align: 'center' },
  243. { title: '在线状态', dataIndex: 'online', align: 'center' },
  244. { title: '最后登录', dataIndex: 'lastLogin', align: 'center' },
  245. { title: '操作', dataIndex: 'actions', align: 'center', width: 220 }
  246. ]
  247. const currentPage = ref(1)
  248. const pageSize = ref(10)
  249. const selectedRowKeys = ref([])
  250. const addStudentVisible = ref(false)
  251. const departments = ref([])
  252. const searchDeptMember = ref('')
  253. const expandedDeptIds = ref([])
  254. const checkedMemberIds = ref([])
  255. const selectedMembers = ref([])
  256. const detailVisible = ref(false)
  257. const detailData = ref({})
  258. const filteredData = computed(() => {
  259. let data = allStudents.value
  260. if (searchForm.value.keyword) {
  261. data = data.filter(
  262. (item) =>
  263. item.name.includes(searchForm.value.keyword) ||
  264. item.studentNo.includes(searchForm.value.keyword) ||
  265. item.phone.includes(searchForm.value.keyword)
  266. )
  267. }
  268. if (searchForm.value.status) {
  269. data = data.filter((item) => item.status === searchForm.value.status)
  270. }
  271. // 这里可以加更多筛选条件
  272. return data
  273. })
  274. const pagedData = computed(() => {
  275. const start = (currentPage.value - 1) * pageSize.value
  276. return filteredData.value.slice(start, start + pageSize.value)
  277. })
  278. const rowSelection = {
  279. selectedRowKeys: selectedRowKeys.value,
  280. onChange: (keys) => {
  281. selectedRowKeys.value = keys
  282. }
  283. }
  284. function onSearch() {
  285. currentPage.value = 1
  286. }
  287. function onReset() {
  288. searchForm.value = { keyword: '', type: '', status: '', date: [] }
  289. currentPage.value = 1
  290. }
  291. function onPageChange(page) {
  292. currentPage.value = page
  293. }
  294. function onPageSizeChange(size) {
  295. pageSize.value = size
  296. currentPage.value = 1
  297. }
  298. function onSelectAll() {
  299. selectedRowKeys.value = pagedData.value.map((item) => item.id)
  300. }
  301. function onInvertSelect() {
  302. const currentIds = pagedData.value.map((item) => item.id)
  303. selectedRowKeys.value = currentIds.filter((id) => !selectedRowKeys.value.includes(id))
  304. }
  305. function onAddStudent() {
  306. addStudentVisible.value = true
  307. // 默认展开所有部门
  308. expandedDeptIds.value = departments.value.map((d) => d.id)
  309. }
  310. function handleAddStudentCancel() {
  311. addStudentVisible.value = false
  312. }
  313. function handleAddStudentOk() {
  314. // TODO: 选中成员加入主表
  315. addStudentVisible.value = false
  316. }
  317. function onDeptMemberSearch() {
  318. // 搜索时自动展开所有部门
  319. expandedDeptIds.value = filteredDepartments.value.map((d) => d.id)
  320. }
  321. function toggleDept(id) {
  322. if (expandedDeptIds.value.includes(id)) {
  323. expandedDeptIds.value = expandedDeptIds.value.filter((did) => did !== id)
  324. } else {
  325. expandedDeptIds.value.push(id)
  326. }
  327. }
  328. function onMemberCheckChange(ids) {
  329. // 限制最多30人
  330. if (ids.length > 30) {
  331. ids = ids.slice(0, 30)
  332. }
  333. checkedMemberIds.value = ids
  334. updateSelectedMembers()
  335. }
  336. function isCheckedLimit(id) {
  337. return checkedMemberIds.value.length >= 30 && !checkedMemberIds.value.includes(id)
  338. }
  339. function updateSelectedMembers() {
  340. // 根据 checkedMemberIds 更新 selectedMembers
  341. const all = []
  342. departments.value.forEach((dept) => {
  343. dept.members.forEach((m) => all.push({ ...m, deptName: dept.name }))
  344. })
  345. selectedMembers.value = all.filter((m) => checkedMemberIds.value.includes(m.id))
  346. }
  347. function removeSelected(id) {
  348. checkedMemberIds.value = checkedMemberIds.value.filter((mid) => mid !== id)
  349. updateSelectedMembers()
  350. }
  351. function clearSelected() {
  352. checkedMemberIds.value = []
  353. updateSelectedMembers()
  354. }
  355. const filteredDepartments = computed(() => {
  356. if (!searchDeptMember.value) return departments.value
  357. // 部门名或成员名匹配
  358. return departments.value
  359. .map((dept) => {
  360. const matchDept = dept.name.includes(searchDeptMember.value)
  361. const filteredMembers = dept.members.filter((m) => m.name.includes(searchDeptMember.value))
  362. if (matchDept || filteredMembers.length) {
  363. return {
  364. ...dept,
  365. members: matchDept ? dept.members : filteredMembers
  366. }
  367. }
  368. return null
  369. })
  370. .filter(Boolean)
  371. })
  372. onMounted(async () => {
  373. departments.value = await getDepartmentMembers()
  374. })
  375. function onDetail(record) {
  376. getStudentDetail().then((data) => {
  377. detailData.value = data
  378. detailVisible.value = true
  379. })
  380. }
  381. function onEdit(record) {
  382. // TODO: 编辑弹窗
  383. }
  384. function onSetting(record) {
  385. // TODO: 设置弹窗
  386. }
  387. function onDelete(record) {
  388. // TODO: 删除确认
  389. }
  390. </script>
  391. <style lang="less" scoped>
  392. .student-details-page {
  393. background: #fff;
  394. border-radius: 12px;
  395. width: 1200px;
  396. margin: 0 auto;
  397. padding: 32px 32px 24px 32px;
  398. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.04);
  399. height: calc(100vh - 400px);
  400. overflow: auto;
  401. .search-bar {
  402. display: flex;
  403. align-items: center;
  404. margin-bottom: 18px;
  405. }
  406. .action-bar {
  407. margin-bottom: 16px;
  408. display: flex;
  409. align-items: center;
  410. }
  411. .student-table {
  412. margin-bottom: 12px;
  413. .ant-table-thead > tr > th {
  414. background: #f7f8fa;
  415. font-weight: 600;
  416. color: #222;
  417. font-size: 15px;
  418. }
  419. .ant-table-tbody > tr > td {
  420. font-size: 14px;
  421. color: #333;
  422. }
  423. .ant-btn {
  424. font-size: 13px;
  425. padding: 0 10px;
  426. border-radius: 4px;
  427. }
  428. .ant-btn-dangerous {
  429. background: #fff1f0;
  430. color: #ff4d4f;
  431. border: 1px solid #ffccc7;
  432. }
  433. }
  434. .table-footer {
  435. display: flex;
  436. align-items: center;
  437. margin-top: 12px;
  438. .batch-actions {
  439. display: flex;
  440. align-items: center;
  441. gap: 8px;
  442. }
  443. }
  444. }
  445. .add-student-modal {
  446. display: flex;
  447. min-height: 400px;
  448. .left-panel {
  449. width: 320px;
  450. border-right: 1px solid #f0f0f0;
  451. padding-right: 16px;
  452. .search-input {
  453. margin-bottom: 12px;
  454. }
  455. .dept-list {
  456. max-height: 340px;
  457. overflow-y: auto;
  458. }
  459. .dept-name {
  460. font-weight: 600;
  461. margin: 8px 0 4px 0;
  462. cursor: pointer;
  463. display: flex;
  464. align-items: center;
  465. }
  466. .member-list {
  467. margin-left: 20px;
  468. margin-bottom: 8px;
  469. }
  470. .member-item {
  471. margin: 4px 0;
  472. display: flex;
  473. align-items: center;
  474. }
  475. }
  476. .right-panel {
  477. flex: 1;
  478. padding-left: 24px;
  479. .selected-header {
  480. font-weight: 600;
  481. margin-bottom: 8px;
  482. }
  483. .selected-list {
  484. min-height: 340px;
  485. max-height: 340px;
  486. overflow-y: auto;
  487. .selected-item {
  488. display: flex;
  489. align-items: center;
  490. background: #f5f5f5;
  491. border-radius: 4px;
  492. padding: 4px 8px;
  493. margin-bottom: 6px;
  494. .remove-icon {
  495. margin-left: auto;
  496. color: #999;
  497. cursor: pointer;
  498. }
  499. }
  500. }
  501. }
  502. }
  503. .modal-footer {
  504. display: flex;
  505. justify-content: flex-end;
  506. margin-top: 18px;
  507. }
  508. .student-detail-modal {
  509. .detail-table {
  510. width: 100%;
  511. border-collapse: collapse;
  512. margin-bottom: 0;
  513. th,
  514. td {
  515. border: 1px solid #e8e8e8;
  516. padding: 12px 16px;
  517. text-align: left;
  518. font-size: 15px;
  519. background: #fff;
  520. }
  521. th {
  522. background: #fafafa;
  523. font-weight: 600;
  524. color: #222;
  525. }
  526. tr:not(:first-child) td {
  527. color: #333;
  528. }
  529. }
  530. .modal-btn-bar {
  531. text-align: center;
  532. }
  533. }
  534. </style>