dengzedong
2024-12-19 85b2001c0ec2f1adc598db3bf47ad457dcca7074
提交 | 用户 | 时间
e7c126 1 <template>
H 2   <ContentWrap>
3     <!-- 搜索工作栏 -->
4     <el-form
5       class="-mb-15px"
6       :model="queryParams"
7       ref="queryFormRef"
8       :inline="true"
9       label-width="68px"
10     >
11       <el-form-item label="名字" prop="name">
12         <el-input
13           v-model="queryParams.name"
14           placeholder="请输入名字"
15           clearable
16           @keyup.enter="handleQuery"
17           class="!w-240px"
18         />
19       </el-form-item>
20       <el-form-item label="出生日期" prop="birthday">
21         <el-date-picker
22           v-model="queryParams.birthday"
23           value-format="YYYY-MM-DD"
24           type="date"
25           placeholder="选择出生日期"
26           clearable
27           class="!w-240px"
28         />
29       </el-form-item>
30       <el-form-item label="性别" prop="sex">
31         <el-select
32           v-model="queryParams.sex"
33           placeholder="请选择性别"
34           clearable
35           class="!w-240px"
36         >
37           <el-option
38             v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX)"
39             :key="dict.value"
40             :label="dict.label"
41             :value="dict.value"
42           />
43         </el-select>
44       </el-form-item>
45       <el-form-item label="是否有效" prop="enabled">
46         <el-select
47           v-model="queryParams.enabled"
48           placeholder="请选择是否有效"
49           clearable
50           class="!w-240px"
51         >
52           <el-option
53             v-for="dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
54             :key="dict.value"
55             :label="dict.label"
56             :value="dict.value"
57           />
58         </el-select>
59       </el-form-item>
60       <el-form-item label="创建时间" prop="createTime">
61         <el-date-picker
62           v-model="queryParams.createTime"
63           value-format="YYYY-MM-DD HH:mm:ss"
64           type="daterange"
65           start-placeholder="开始日期"
66           end-placeholder="结束日期"
67           :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
68           class="!w-240px"
69         />
70       </el-form-item>
71       <el-form-item>
72         <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
73         <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
74         <el-button
75           type="primary"
76           plain
77           @click="openForm('create')"
78           v-hasPermi="['infra:student:create']"
79         >
80           <Icon icon="ep:plus" class="mr-5px" /> 新增
81         </el-button>
82         <el-button
83           type="success"
84           plain
85           @click="handleExport"
86           :loading="exportLoading"
87           v-hasPermi="['infra:student:export']"
88         >
89           <Icon icon="ep:download" class="mr-5px" /> 导出
90         </el-button>
91       </el-form-item>
92     </el-form>
93   </ContentWrap>
94
95   <!-- 列表 -->
96   <ContentWrap>
97     <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
98       <!-- 子表的列表 -->
99       <el-table-column type="expand">
100         <template #default="scope">
101           <el-tabs model-value="studentContact">
102             <el-tab-pane label="学生联系人" name="studentContact">
103               <StudentContactList :student-id="scope.row.id" />
104             </el-tab-pane>
105             <el-tab-pane label="学生班主任" name="studentTeacher">
106               <StudentTeacherList :student-id="scope.row.id" />
107             </el-tab-pane>
108           </el-tabs>
109         </template>
110       </el-table-column>
111       <el-table-column label="编号" align="center" prop="id" />
112       <el-table-column label="名字" align="center" prop="name" />
113       <el-table-column label="简介" align="center" prop="description" />
114       <el-table-column
115         label="出生日期"
116         align="center"
117         prop="birthday"
118         :formatter="dateFormatter"
119         width="180px"
120       />
121       <el-table-column label="性别" align="center" prop="sex">
122         <template #default="scope">
123           <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" />
124         </template>
125       </el-table-column>
126       <el-table-column label="是否有效" align="center" prop="enabled">
127         <template #default="scope">
128           <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" />
129         </template>
130       </el-table-column>
131       <el-table-column label="头像" align="center" prop="avatar" />
132       <el-table-column label="附件" align="center" prop="video" />
133       <el-table-column label="备注" align="center" prop="memo" />
134       <el-table-column
135         label="创建时间"
136         align="center"
137         prop="createTime"
138         :formatter="dateFormatter"
139         width="180px"
140       />
141       <el-table-column label="操作" align="center">
142         <template #default="scope">
143           <el-button
144             link
145             type="primary"
146             @click="openForm('update', scope.row.id)"
147             v-hasPermi="['infra:student:update']"
148           >
149             编辑
150           </el-button>
151           <el-button
152             link
153             type="danger"
154             @click="handleDelete(scope.row.id)"
155             v-hasPermi="['infra:student:delete']"
156           >
157             删除
158           </el-button>
159         </template>
160       </el-table-column>
161     </el-table>
162     <!-- 分页 -->
163     <Pagination
164       :total="total"
165       v-model:page="queryParams.pageNo"
166       v-model:limit="queryParams.pageSize"
167       @pagination="getList"
168     />
169   </ContentWrap>
170
171   <!-- 表单弹窗:添加/修改 -->
172   <StudentForm ref="formRef" @success="getList" />
173 </template>
174
175 <script setup lang="ts">
176 import { getIntDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
177 import { dateFormatter } from '@/utils/formatTime'
178 import download from '@/utils/download'
179 import * as StudentApi from '@/api/infra/demo'
180 import StudentForm from './StudentForm.vue'
181 import StudentContactList from './components/StudentContactList.vue'
182 import StudentTeacherList from './components/StudentTeacherList.vue'
183
184 defineOptions({ name: 'InfraStudent' })
185
186 const message = useMessage() // 消息弹窗
187 const { t } = useI18n() // 国际化
188
189 const loading = ref(true) // 列表的加载中
190 const list = ref([]) // 列表的数据
191 const total = ref(0) // 列表的总页数
192 const queryParams = reactive({
193   pageNo: 1,
194   pageSize: 10,
195   name: undefined,
196   birthday: undefined,
197   birthday: [],
198   sex: undefined,
199   enabled: undefined,
200   createTime: [],
201 })
202 const queryFormRef = ref() // 搜索的表单
203 const exportLoading = ref(false) // 导出的加载中
204
205 /** 查询列表 */
206 const getList = async () => {
207   loading.value = true
208   try {
209     const data = await StudentApi.getStudentPage(queryParams)
210     list.value = data.list
211     total.value = data.total
212   } finally {
213     loading.value = false
214   }
215 }
216
217 /** 搜索按钮操作 */
218 const handleQuery = () => {
219   queryParams.pageNo = 1
220   getList()
221 }
222
223 /** 重置按钮操作 */
224 const resetQuery = () => {
225   queryFormRef.value.resetFields()
226   handleQuery()
227 }
228
229 /** 添加/修改操作 */
230 const formRef = ref()
231 const openForm = (type: string, id?: number) => {
232   formRef.value.open(type, id)
233 }
234
235 /** 删除按钮操作 */
236 const handleDelete = async (id: number) => {
237   try {
238     // 删除的二次确认
239     await message.delConfirm()
240     // 发起删除
241     await StudentApi.deleteStudent(id)
242     message.success(t('common.delSuccess'))
243     // 刷新列表
244     await getList()
245   } catch {}
246 }
247
248 /** 导出按钮操作 */
249 const handleExport = async () => {
250   try {
251     // 导出的二次确认
252     await message.exportConfirm()
253     // 发起导出
254     exportLoading.value = true
255     const data = await StudentApi.exportStudent(queryParams)
256     download.excel(data, '学生.xls')
257   } catch {
258   } finally {
259     exportLoading.value = false
260   }
261 }
262
263 /** 初始化 **/
264 onMounted(() => {
265   getList()
266 })
267 </script>