StudentDetails.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. margin: 0 auto;
  396. padding: 32px 32px 24px 32px;
  397. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.04);
  398. height: calc(100vh - 400px);
  399. overflow: auto;
  400. .search-bar {
  401. display: flex;
  402. align-items: center;
  403. margin-bottom: 18px;
  404. }
  405. .action-bar {
  406. margin-bottom: 16px;
  407. display: flex;
  408. align-items: center;
  409. }
  410. .student-table {
  411. margin-bottom: 12px;
  412. .ant-table-thead > tr > th {
  413. background: #f7f8fa;
  414. font-weight: 600;
  415. color: #222;
  416. font-size: 15px;
  417. }
  418. .ant-table-tbody > tr > td {
  419. font-size: 14px;
  420. color: #333;
  421. }
  422. .ant-btn {
  423. font-size: 13px;
  424. padding: 0 10px;
  425. border-radius: 4px;
  426. }
  427. .ant-btn-dangerous {
  428. background: #fff1f0;
  429. color: #ff4d4f;
  430. border: 1px solid #ffccc7;
  431. }
  432. }
  433. .table-footer {
  434. display: flex;
  435. align-items: center;
  436. margin-top: 12px;
  437. .batch-actions {
  438. display: flex;
  439. align-items: center;
  440. gap: 8px;
  441. }
  442. }
  443. }
  444. .add-student-modal {
  445. display: flex;
  446. min-height: 400px;
  447. .left-panel {
  448. width: 320px;
  449. border-right: 1px solid #f0f0f0;
  450. padding-right: 16px;
  451. .search-input {
  452. margin-bottom: 12px;
  453. }
  454. .dept-list {
  455. max-height: 340px;
  456. overflow-y: auto;
  457. }
  458. .dept-name {
  459. font-weight: 600;
  460. margin: 8px 0 4px 0;
  461. cursor: pointer;
  462. display: flex;
  463. align-items: center;
  464. }
  465. .member-list {
  466. margin-left: 20px;
  467. margin-bottom: 8px;
  468. }
  469. .member-item {
  470. margin: 4px 0;
  471. display: flex;
  472. align-items: center;
  473. }
  474. }
  475. .right-panel {
  476. flex: 1;
  477. padding-left: 24px;
  478. .selected-header {
  479. font-weight: 600;
  480. margin-bottom: 8px;
  481. }
  482. .selected-list {
  483. min-height: 340px;
  484. max-height: 340px;
  485. overflow-y: auto;
  486. .selected-item {
  487. display: flex;
  488. align-items: center;
  489. background: #f5f5f5;
  490. border-radius: 4px;
  491. padding: 4px 8px;
  492. margin-bottom: 6px;
  493. .remove-icon {
  494. margin-left: auto;
  495. color: #999;
  496. cursor: pointer;
  497. }
  498. }
  499. }
  500. }
  501. }
  502. .modal-footer {
  503. display: flex;
  504. justify-content: flex-end;
  505. margin-top: 18px;
  506. }
  507. .student-detail-modal {
  508. .detail-table {
  509. width: 100%;
  510. border-collapse: collapse;
  511. margin-bottom: 0;
  512. th,
  513. td {
  514. border: 1px solid #e8e8e8;
  515. padding: 12px 16px;
  516. text-align: left;
  517. font-size: 15px;
  518. background: #fff;
  519. }
  520. th {
  521. background: #fafafa;
  522. font-weight: 600;
  523. color: #222;
  524. }
  525. tr:not(:first-child) td {
  526. color: #333;
  527. }
  528. }
  529. .modal-btn-bar {
  530. text-align: center;
  531. }
  532. }
  533. </style>