潘志宝
3 天以前 34ba735bfa0d272e063054c7ba0ef6fde65880f4
提交 | 用户 | 时间
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
98       v-loading="loading"
99       :data="list"
100       :stripe="true"
101       :show-overflow-tooltip="true"
102       highlight-current-row
103       @current-change="handleCurrentChange"
104     >
105       <el-table-column label="编号" align="center" prop="id" />
106       <el-table-column label="名字" align="center" prop="name" />
107       <el-table-column label="简介" align="center" prop="description" />
108       <el-table-column
109         label="出生日期"
110         align="center"
111         prop="birthday"
112         :formatter="dateFormatter"
113         width="180px"
114       />
115       <el-table-column label="性别" align="center" prop="sex">
116         <template #default="scope">
117           <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" />
118         </template>
119       </el-table-column>
120       <el-table-column label="是否有效" align="center" prop="enabled">
121         <template #default="scope">
122           <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" />
123         </template>
124       </el-table-column>
125       <el-table-column label="头像" align="center" prop="avatar" />
126       <el-table-column label="附件" align="center" prop="video" />
127       <el-table-column label="备注" align="center" prop="memo" />
128       <el-table-column
129         label="创建时间"
130         align="center"
131         prop="createTime"
132         :formatter="dateFormatter"
133         width="180px"
134       />
135       <el-table-column label="操作" align="center">
136         <template #default="scope">
137           <el-button
138             link
139             type="primary"
140             @click="openForm('update', scope.row.id)"
141             v-hasPermi="['infra:student:update']"
142           >
143             编辑
144           </el-button>
145           <el-button
146             link
147             type="danger"
148             @click="handleDelete(scope.row.id)"
149             v-hasPermi="['infra:student:delete']"
150           >
151             删除
152           </el-button>
153         </template>
154       </el-table-column>
155     </el-table>
156     <!-- 分页 -->
157     <Pagination
158       :total="total"
159       v-model:page="queryParams.pageNo"
160       v-model:limit="queryParams.pageSize"
161       @pagination="getList"
162     />
163   </ContentWrap>
164
165   <!-- 表单弹窗:添加/修改 -->
166   <StudentForm ref="formRef" @success="getList" />
167   <!-- 子表的列表 -->
168   <ContentWrap>
169     <el-tabs model-value="studentContact">
170       <el-tab-pane label="学生联系人" name="studentContact">
171         <StudentContactList :student-id="currentRow.id" />
172       </el-tab-pane>
173       <el-tab-pane label="学生班主任" name="studentTeacher">
174         <StudentTeacherList :student-id="currentRow.id" />
175       </el-tab-pane>
176     </el-tabs>
177   </ContentWrap>
178 </template>
179
180 <script setup lang="ts">
181 import { getIntDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict'
182 import { dateFormatter } from '@/utils/formatTime'
183 import download from '@/utils/download'
184 import * as StudentApi from '@/api/infra/demo'
185 import StudentForm from './StudentForm.vue'
186 import StudentContactList from './components/StudentContactList.vue'
187 import StudentTeacherList from './components/StudentTeacherList.vue'
188
189 defineOptions({ name: 'InfraStudent' })
190
191 const message = useMessage() // 消息弹窗
192 const { t } = useI18n() // 国际化
193
194 const loading = ref(true) // 列表的加载中
195 const list = ref([]) // 列表的数据
196 const total = ref(0) // 列表的总页数
197 const queryParams = reactive({
198   pageNo: 1,
199   pageSize: 10,
200   name: undefined,
201   birthday: undefined,
202   birthday: [],
203   sex: undefined,
204   enabled: undefined,
205   createTime: [],
206 })
207 const queryFormRef = ref() // 搜索的表单
208 const exportLoading = ref(false) // 导出的加载中
209
210 /** 查询列表 */
211 const getList = async () => {
212   loading.value = true
213   try {
214     const data = await StudentApi.getStudentPage(queryParams)
215     list.value = data.list
216     total.value = data.total
217   } finally {
218     loading.value = false
219   }
220 }
221
222 /** 搜索按钮操作 */
223 const handleQuery = () => {
224   queryParams.pageNo = 1
225   getList()
226 }
227
228 /** 重置按钮操作 */
229 const resetQuery = () => {
230   queryFormRef.value.resetFields()
231   handleQuery()
232 }
233
234 /** 添加/修改操作 */
235 const formRef = ref()
236 const openForm = (type: string, id?: number) => {
237   formRef.value.open(type, id)
238 }
239
240 /** 删除按钮操作 */
241 const handleDelete = async (id: number) => {
242   try {
243     // 删除的二次确认
244     await message.delConfirm()
245     // 发起删除
246     await StudentApi.deleteStudent(id)
247     message.success(t('common.delSuccess'))
248     // 刷新列表
249     await getList()
250   } catch {}
251 }
252
253 /** 导出按钮操作 */
254 const handleExport = async () => {
255   try {
256     // 导出的二次确认
257     await message.exportConfirm()
258     // 发起导出
259     exportLoading.value = true
260     const data = await StudentApi.exportStudent(queryParams)
261     download.excel(data, '学生.xls')
262   } catch {
263   } finally {
264     exportLoading.value = false
265   }
266 }
267
268 /** 选中行操作 */
269 const currentRow = ref({}) // 选中行
270 const handleCurrentChange = (row) => {
271   currentRow.value = row
272 }
273
274 /** 初始化 **/
275 onMounted(() => {
276   getList()
277 })
278 </script>