Skip to content

Commit a3fb00a

Browse files
committed
fixed(student tablecols): 调整columns的数据类型
1 parent e3d0a22 commit a3fb00a

2 files changed

Lines changed: 101 additions & 71 deletions

File tree

src/stores/student-store.ts

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
formatEthnicity,
77
formatCollege,
88
formatMajor,
9+
formatFundType,
10+
formatPunishType,
911
formatAssistLevel,
1012
formatCampus,
1113
formatDegree,
@@ -37,6 +39,23 @@ interface StudentTableColumn {
3739

3840
type DetailSection = 'project' | 'punish' | 'scholarship'
3941

42+
interface DetailColumn {
43+
key: string
44+
prop: string
45+
label: string
46+
minWidth: number
47+
formatter?: (row: Record<string, any>) => string
48+
}
49+
50+
interface DetailTabConfig {
51+
section: DetailSection
52+
label: string
53+
rows: any[]
54+
total: number
55+
currentPage: number
56+
columns: DetailColumn[]
57+
}
58+
4059
export const useStudentStore = defineStore('student', () => {
4160
const getDisplayValue = getFieldDisplayValue
4261
const formatEdu = formatDegree
@@ -132,6 +151,57 @@ export const useStudentStore = defineStore('student', () => {
132151
const punishTotal = computed(() => fundPunishVo.value.length)
133152
const scholarshipTotal = computed(() => fundScholarshipVo.value.length)
134153

154+
const detailTabConfigs = computed<DetailTabConfig[]>(() => [
155+
{
156+
section: 'punish',
157+
label: '个人处分',
158+
rows: paginatedPunishVo.value,
159+
total: punishTotal.value,
160+
currentPage: punishPage.value,
161+
columns: [
162+
{
163+
key: 'category',
164+
prop: 'category',
165+
label: '类别',
166+
minWidth: 180,
167+
formatter: (row) => formatPunishType(Number(row.category)),
168+
},
169+
{ key: 'reason', prop: 'reason', label: '原因', minWidth: 180 },
170+
{ key: 'punishTime', prop: 'punishTime', label: '处分时间', minWidth: 180 },
171+
],
172+
},
173+
{
174+
section: 'scholarship',
175+
label: '个人奖励',
176+
rows: paginatedScholarshipVo.value,
177+
total: scholarshipTotal.value,
178+
currentPage: scholarshipPage.value,
179+
columns: [
180+
{
181+
key: 'type',
182+
prop: 'type',
183+
label: '类型',
184+
minWidth: 180,
185+
formatter: (row) => formatFundType(Number(row.type)),
186+
},
187+
{ key: 'grantDate', prop: 'grantDate', label: '授予日期', minWidth: 180 },
188+
{ key: 'amount', prop: 'amount', label: '金额', minWidth: 180 },
189+
],
190+
},
191+
{
192+
section: 'project',
193+
label: '社会经历',
194+
rows: paginatedProjectVo.value,
195+
total: projectTotal.value,
196+
currentPage: projectPage.value,
197+
columns: [
198+
{ key: 'startDate', prop: 'startDate', label: '开始日期', minWidth: 180 },
199+
{ key: 'endDate', prop: 'endDate', label: '结束日期', minWidth: 180 },
200+
{ key: 'experience', prop: 'experience', label: '经历描述', minWidth: 180 },
201+
],
202+
},
203+
])
204+
135205
const hasSelectedItems = computed(() => selectedIds.value.length > 0)
136206

137207
const handleSelectionChange = (selection: StudentRow[]) => {
@@ -291,6 +361,10 @@ export const useStudentStore = defineStore('student', () => {
291361
await getList(val, query.pageSize)
292362
}
293363

364+
const initPage = async () => {
365+
await getList(1, query.pageSize)
366+
}
367+
294368
const setDetailPage = (section: DetailSection, page: number) => {
295369
if (section === 'project') {
296370
projectPage.value = page
@@ -317,15 +391,7 @@ export const useStudentStore = defineStore('student', () => {
317391
studentRow,
318392
visible,
319393
detailPageSize,
320-
projectTotal,
321-
punishTotal,
322-
scholarshipTotal,
323-
projectPage,
324-
punishPage,
325-
scholarshipPage,
326-
paginatedProjectVo,
327-
paginatedPunishVo,
328-
paginatedScholarshipVo,
394+
detailTabConfigs,
329395

330396
getList,
331397
resetSearchForm,
@@ -337,6 +403,7 @@ export const useStudentStore = defineStore('student', () => {
337403
exportStudentInfo,
338404
handleSizeChange,
339405
handleCurrentChange,
406+
initPage,
340407
setDetailPage,
341408
}
342409
})

src/views/student/index.vue

Lines changed: 25 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -52,62 +52,28 @@
5252
</el-descriptions-item>
5353
</el-descriptions>
5454
<el-tabs type="border-card" style="margin-top: 20px">
55-
<el-tab-pane label="个人处分">
56-
<el-table :data="paginatedPunishVo" height="350">
57-
<el-table-column prop="category" label="类别" minWidth="180">
58-
<template #default="{ row }">
59-
{{ formatPunishType(+row.category) }}
55+
<el-tab-pane v-for="tab in detailTabConfigs" :key="tab.section" :label="tab.label">
56+
<el-table :data="tab.rows" height="350">
57+
<el-table-column
58+
v-for="column in tab.columns"
59+
:key="column.key"
60+
:prop="column.prop"
61+
:label="column.label"
62+
:min-width="column.minWidth"
63+
>
64+
<template #default="{ row }" v-if="column.formatter">
65+
{{ column.formatter(row) }}
6066
</template>
6167
</el-table-column>
62-
<el-table-column prop="reason" label="原因" minWidth="180"></el-table-column>
63-
<el-table-column prop="punishTime" label="处分时间" minWidth="180"></el-table-column>
6468
</el-table>
6569
<el-pagination
6670
background
6771
layout="prev, pager, next"
68-
:total="punishTotal"
72+
:total="tab.total"
6973
:page-size="detailPageSize"
70-
v-model:current-page="punishPage"
74+
:current-page="tab.currentPage"
7175
pager-count="50"
72-
@current-change="setDetailPage.bind(null, 'punish')"
73-
class="pagination"
74-
/>
75-
</el-tab-pane>
76-
<el-tab-pane label="个人奖励">
77-
<el-table :data="paginatedScholarshipVo" height="350">
78-
<el-table-column prop="category" label="类型" minWidth="180">
79-
<template #default="{ row }">
80-
{{ formatFundType(+row.type) }}
81-
</template>
82-
</el-table-column>
83-
<el-table-column prop="grantDate" label="授予日期" minWidth="180"></el-table-column>
84-
<el-table-column prop="amount" label="金额" minWidth="180"></el-table-column>
85-
</el-table>
86-
<el-pagination
87-
background
88-
layout="prev, pager, next"
89-
:total="scholarshipTotal"
90-
:page-size="detailPageSize"
91-
v-model:current-page="scholarshipPage"
92-
pager-count="50"
93-
@current-change="setDetailPage.bind(null, 'scholarship')"
94-
class="pagination"
95-
/>
96-
</el-tab-pane>
97-
<el-tab-pane label="社会经历">
98-
<el-table :data="paginatedProjectVo" height="350">
99-
<el-table-column prop="startDate" label="开始日期" minWidth="180"></el-table-column>
100-
<el-table-column prop="endDate" label="结束日期" minWidth="180"></el-table-column>
101-
<el-table-column prop="experience" label="经历描述" minWidth="180"></el-table-column>
102-
</el-table>
103-
<el-pagination
104-
background
105-
layout="prev, pager, next"
106-
:total="projectTotal"
107-
:page-size="detailPageSize"
108-
v-model:current-page="projectPage"
109-
pager-count="50"
110-
@current-change="setDetailPage.bind(null, 'project')"
76+
@current-change="setDetailPage(tab.section, $event)"
11177
class="pagination"
11278
/>
11379
</el-tab-pane>
@@ -123,14 +89,14 @@
12389

12490
<script setup lang="ts">
12591
import SearchBox from './components/search-box.vue'
126-
import { onMounted } from 'vue'
92+
import { onActivated, onMounted } from 'vue'
12793
import { storeToRefs } from 'pinia'
128-
import { formatFundType, formatPunishType } from '@/constants/default'
12994
import { useStudentStore } from '@/stores/student-store'
13095
13196
const studentStore = useStudentStore()
13297
13398
const {
99+
tableColumns,
134100
getDisplayValue,
135101
handleSelectionChange,
136102
handleViewDetail,
@@ -139,11 +105,10 @@ const {
139105
handleSizeChange,
140106
handleCurrentChange,
141107
setDetailPage,
142-
getList,
108+
initPage,
143109
} = studentStore
144110
145111
const {
146-
tableColumns,
147112
fieldConfigs,
148113
tableData,
149114
query,
@@ -152,19 +117,17 @@ const {
152117
studentRow,
153118
visible,
154119
detailPageSize,
155-
projectTotal,
156-
punishTotal,
157-
scholarshipTotal,
158-
projectPage,
159-
punishPage,
160-
scholarshipPage,
161-
paginatedProjectVo,
162-
paginatedPunishVo,
163-
paginatedScholarshipVo,
120+
detailTabConfigs,
164121
} = storeToRefs(studentStore)
165122
166123
onMounted(() => {
167-
getList()
124+
void initPage()
125+
})
126+
127+
onActivated(() => {
128+
if (!tableData.value.length) {
129+
void initPage()
130+
}
168131
})
169132
</script>
170133

0 commit comments

Comments
 (0)