Skip to content

Commit 42d030d

Browse files
committed
refactor(student files): refactor student files display
1 parent 191f8b8 commit 42d030d

6 files changed

Lines changed: 369 additions & 973 deletions

File tree

src/router/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ const router = createRouter({
6868
name: 'profile',
6969
component: () => import('@/views/profile/index.vue'),
7070
},
71+
{
72+
path: 'studentFiles',
73+
name: 'studentFiles',
74+
component: () => import('@/views/student/index.vue'),
75+
meta: { role: ['老师', '超级管理员'] },
76+
},
7177
],
7278
},
73-
{
74-
path: '/studentFiles',
75-
name: 'studentFiles',
76-
component: () => import('@/views/student/index.vue'),
77-
meta: { role: ['老师', '超级管理员'] },
78-
},
7979
],
8080
})
8181

@@ -89,7 +89,7 @@ const resolveHomePathByRole = (role: string) => {
8989
return '/home'
9090
}
9191
if (role === '老师') {
92-
return '/studentFiles'
92+
return '/framework/studentFiles'
9393
}
9494
return '/framework'
9595
}
@@ -110,7 +110,12 @@ router.beforeEach((to, _from, next) => {
110110
}
111111

112112
if (allowRoles.length && role && !allowRoles.includes(role)) {
113-
next(resolveHomePathByRole(role))
113+
const fallbackPath = resolveHomePathByRole(role)
114+
if (fallbackPath === to.path) {
115+
next()
116+
return
117+
}
118+
next(fallbackPath)
114119
return
115120
}
116121

src/stores/student-store.ts

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
import { computed, reactive, ref } from 'vue'
2+
import { defineStore } from 'pinia'
3+
import { ElMessage } from 'element-plus'
4+
import { getFieldDisplayValue, type FieldConfigType } from '@/utils/field-config'
5+
import {
6+
formatEthnicity,
7+
formatCollege,
8+
formatMajor,
9+
formatAssistLevel,
10+
formatCampus,
11+
formatDegree,
12+
formatGender,
13+
formatMarry,
14+
formatPoliticalStatus,
15+
formatStudentStatus,
16+
} from '@/constants/default'
17+
import { formatDay } from '@/utils/format-time'
18+
import { studentFilesApi } from '@/api/student-files.api'
19+
20+
export interface StudentRow {
21+
userId: string
22+
studentId?: string
23+
name?: string
24+
grade?: string
25+
major?: string
26+
degree?: string
27+
[key: string]: any
28+
}
29+
30+
interface StudentTableColumn {
31+
key: string
32+
label: string
33+
minWidth: number
34+
prop: keyof StudentRow
35+
formatter?: (value: any, row: StudentRow) => string
36+
}
37+
38+
export const useStudentStore = defineStore('student', () => {
39+
const getDisplayValue = getFieldDisplayValue
40+
const formatEdu = formatDegree
41+
42+
const tableColumns: StudentTableColumn[] = [
43+
{ key: 'studentId', prop: 'studentId', label: '学号', minWidth: 180 },
44+
{ key: 'name', prop: 'name', label: '姓名', minWidth: 180 },
45+
{ key: 'grade', prop: 'grade', label: '年级', minWidth: 180 },
46+
{
47+
key: 'major',
48+
prop: 'major',
49+
label: '专业',
50+
minWidth: 180,
51+
formatter: (value) => formatMajor(value),
52+
},
53+
{
54+
key: 'degree',
55+
prop: 'degree',
56+
label: '学位',
57+
minWidth: 180,
58+
formatter: (value) => formatEdu(value),
59+
},
60+
]
61+
62+
const fieldConfigs: FieldConfigType[] = [
63+
{ prop: 'studentId', label: '学号' },
64+
{ prop: 'name', label: '姓名' },
65+
{ prop: 'gender', label: '性别', formatter: formatGender },
66+
{ prop: 'degree', label: '学历', formatter: formatDegree },
67+
{ prop: 'status', label: '学生状态', formatter: formatStudentStatus },
68+
{ prop: 'birthday', label: '生日', formatter: formatDay },
69+
{ prop: 'grade', label: '年级' },
70+
{ prop: 'nationality', label: '民族', formatter: formatEthnicity },
71+
{ prop: 'college', label: '学院', formatter: formatCollege },
72+
{ prop: 'major', label: '专业', formatter: formatMajor },
73+
{ prop: 'admissionDate', label: '入学日期' },
74+
{ prop: 'telephone', label: '手机号' },
75+
{ prop: 'email', label: '邮箱' },
76+
{ prop: 'apartment', label: '校区', formatter: formatCampus },
77+
{ prop: 'dormitory', label: '公寓' },
78+
{ prop: 'homeAddress', label: '家庭住址' },
79+
{ prop: 'political', label: '政治面貌', formatter: formatPoliticalStatus },
80+
{ prop: 'marry', label: '婚姻状态', formatter: formatMarry },
81+
{ prop: 'fundType', label: '资助类型', formatter: formatAssistLevel },
82+
]
83+
84+
const tableData = ref<StudentRow[]>([])
85+
const selectedIds = ref<string[]>([])
86+
const query = reactive({
87+
pageNum: 1,
88+
pageSize: 10,
89+
})
90+
const total = ref(0)
91+
const loadings = reactive({
92+
table: false,
93+
})
94+
95+
const viewedUserId = ref('')
96+
const studentRow = ref<Record<string, any>>({})
97+
const fundPunishVo = ref<any[]>([])
98+
const fundScholarshipVo = ref<any[]>([])
99+
const fundProjectVo = ref<any[]>([])
100+
const visible = ref(false)
101+
102+
const currentPage = ref(1)
103+
const totalNum = ref(0)
104+
const currentPage2 = ref(1)
105+
const totalNum2 = ref(0)
106+
const currentPage3 = ref(1)
107+
const totalNum3 = ref(0)
108+
109+
const paginatedProjectVo = computed(() => {
110+
const start = (currentPage.value - 1) * 6
111+
return fundProjectVo.value.slice(start, start + 6)
112+
})
113+
114+
const paginatedPunishVo = computed(() => {
115+
const start = (currentPage2.value - 1) * 6
116+
return fundPunishVo.value.slice(start, start + 6)
117+
})
118+
119+
const paginatedScholarshipVo = computed(() => {
120+
const start = (currentPage3.value - 1) * 6
121+
return fundScholarshipVo.value.slice(start, start + 6)
122+
})
123+
124+
const handleSelectionChange = (selection: StudentRow[]) => {
125+
selectedIds.value = selection.map((student) => student.userId)
126+
}
127+
128+
const getList = async (
129+
pageNum = query.pageNum,
130+
pageSize = query.pageSize,
131+
queryData: Record<string, any> = {},
132+
) => {
133+
loadings.table = true
134+
try {
135+
const params = {
136+
pageNum,
137+
pageSize,
138+
...queryData,
139+
}
140+
const res = await studentFilesApi.getStudentList(params)
141+
const rows = res.data?.rows || []
142+
143+
query.pageNum = pageNum
144+
query.pageSize = pageSize
145+
tableData.value = rows
146+
total.value = res.data?.total || 0
147+
} catch (error) {
148+
tableData.value = []
149+
total.value = 0
150+
ElMessage.error('学生列表加载失败,请稍后重试')
151+
} finally {
152+
loadings.table = false
153+
}
154+
}
155+
156+
const search = async (params: Record<string, any>) => {
157+
await getList(1, query.pageSize, params)
158+
}
159+
160+
const handleViewDetail = async (row: StudentRow) => {
161+
viewedUserId.value = row.userId
162+
try {
163+
const res = await studentFilesApi.getStudentDetail(row.userId)
164+
const detailData = res.data?.data || {}
165+
166+
studentRow.value = detailData.fundUserInfoVo || {}
167+
fundProjectVo.value = detailData.fundProjectVo || []
168+
fundScholarshipVo.value = detailData.fundScholarshipVo || []
169+
fundPunishVo.value = detailData.fundPunishVo || []
170+
171+
totalNum.value = fundProjectVo.value.length
172+
totalNum2.value = fundPunishVo.value.length
173+
totalNum3.value = fundScholarshipVo.value.length
174+
175+
currentPage.value = 1
176+
currentPage2.value = 1
177+
currentPage3.value = 1
178+
visible.value = true
179+
} catch (error) {
180+
ElMessage.error('学生详情加载失败,请稍后重试')
181+
}
182+
}
183+
184+
const closeDialog = () => {
185+
visible.value = false
186+
}
187+
188+
const exportStudentInfo = async () => {
189+
if (!viewedUserId.value) {
190+
ElMessage.warning('请先查看学生详情后再导出')
191+
return
192+
}
193+
194+
try {
195+
const response = await studentFilesApi.exportStudentInfo(viewedUserId.value)
196+
197+
const blob = new Blob([response.data], {
198+
type: 'application/vnd.ms-excel',
199+
})
200+
const url = window.URL.createObjectURL(blob)
201+
const link = document.createElement('a')
202+
link.href = url
203+
link.download = 'student_info.xlsx'
204+
document.body.appendChild(link)
205+
link.click()
206+
document.body.removeChild(link)
207+
window.URL.revokeObjectURL(url)
208+
ElMessage.success('导出成功')
209+
} catch (error) {
210+
ElMessage.error('导出失败,请稍后重试')
211+
}
212+
}
213+
214+
const handleSizeChange = async (val: number) => {
215+
await getList(query.pageNum, val)
216+
}
217+
218+
const handleCurrentChange = async (val: number) => {
219+
await getList(val, query.pageSize)
220+
}
221+
222+
const handlePageChange = (val: number) => {
223+
currentPage.value = val
224+
}
225+
226+
const handlePageChange2 = (val: number) => {
227+
currentPage2.value = val
228+
}
229+
230+
const handlePageChange3 = (val: number) => {
231+
currentPage3.value = val
232+
}
233+
234+
return {
235+
getDisplayValue,
236+
tableColumns,
237+
fieldConfigs,
238+
tableData,
239+
selectedIds,
240+
query,
241+
total,
242+
loadings,
243+
studentRow,
244+
visible,
245+
totalNum,
246+
totalNum2,
247+
totalNum3,
248+
currentPage,
249+
currentPage2,
250+
currentPage3,
251+
paginatedProjectVo,
252+
paginatedPunishVo,
253+
paginatedScholarshipVo,
254+
255+
getList,
256+
search,
257+
handleSelectionChange,
258+
handleViewDetail,
259+
closeDialog,
260+
exportStudentInfo,
261+
handleSizeChange,
262+
handleCurrentChange,
263+
handlePageChange,
264+
handlePageChange2,
265+
handlePageChange3,
266+
}
267+
})

src/views/framework/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ const menuList: MenuItem[] = [
118118
label: '个人成长档案',
119119
page: 'personalProfile',
120120
route: '/framework/profile',
121-
roles: ['资助对象', '超级管理员'],
121+
roles: ['资助对象'],
122122
},
123123
{
124124
key: 'studentsProfile',
125125
label: '学生档案',
126126
page: 'studentsProfile',
127-
route: '/studentFiles',
127+
route: '/framework/studentFiles',
128128
roles: ['老师', '超级管理员'],
129129
},
130130
]

0 commit comments

Comments
 (0)