潘志宝
2024-09-09 ed81b7371e376df35448b81531d30dd9024bd44a
提交 | 用户 | 时间
e7c126 1 <template>
H 2   <div class="app-container">
3     <!-- 搜索工作栏 -->
4     <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
5       <el-form-item label="名字" prop="name">
6         <el-input v-model="queryParams.name" placeholder="请输入名字" clearable @keyup.enter.native="handleQuery"/>
7       </el-form-item>
8       <el-form-item label="出生日期" prop="birthday">
9         <el-date-picker clearable v-model="queryParams.birthday" type="date" value-format="yyyy-MM-dd" placeholder="选择出生日期" />
10       </el-form-item>
11       <el-form-item label="性别" prop="sex">
12         <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small">
13           <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)"
14                        :key="dict.value" :label="dict.label" :value="dict.value"/>
15         </el-select>
16       </el-form-item>
17       <el-form-item label="是否有效" prop="enabled">
18         <el-select v-model="queryParams.enabled" placeholder="请选择是否有效" clearable size="small">
19           <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)"
20                        :key="dict.value" :label="dict.label" :value="dict.value"/>
21         </el-select>
22       </el-form-item>
23       <el-form-item label="创建时间" prop="createTime">
24         <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
25                         range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
26       </el-form-item>
27       <el-form-item>
28         <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
29         <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
30       </el-form-item>
31     </el-form>
32
33     <!-- 操作工具栏 -->
34     <el-row :gutter="10" class="mb8">
35       <el-col :span="1.5">
36         <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
37                    v-hasPermi="['infra:student:create']">新增</el-button>
38       </el-col>
39       <el-col :span="1.5">
40         <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
41                    v-hasPermi="['infra:student:export']">导出</el-button>
42       </el-col>
43               <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
44     </el-row>
45
46             <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
47             <el-table-column label="编号" align="center" prop="id">
48         <template v-slot="scope">
49           <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" />
50         </template>
51       </el-table-column>
52       <el-table-column label="名字" align="center" prop="name">
53         <template v-slot="scope">
54           <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.name" />
55         </template>
56       </el-table-column>
57       <el-table-column label="简介" align="center" prop="description">
58         <template v-slot="scope">
59           <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.description" />
60         </template>
61       </el-table-column>
62       <el-table-column label="出生日期" align="center" prop="birthday" width="180">
63         <template v-slot="scope">
64           <span>{{ parseTime(scope.row.birthday) }}</span>
65         </template>
66       </el-table-column>
67       <el-table-column label="性别" align="center" prop="sex">
68         <template v-slot="scope">
69           <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" />
70         </template>
71       </el-table-column>
72       <el-table-column label="是否有效" align="center" prop="enabled">
73         <template v-slot="scope">
74           <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" />
75         </template>
76       </el-table-column>
77       <el-table-column label="头像" align="center" prop="avatar">
78         <template v-slot="scope">
79           <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.avatar" />
80         </template>
81       </el-table-column>
82       <el-table-column label="附件" align="center" prop="video">
83         <template v-slot="scope">
84           <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.video" />
85         </template>
86       </el-table-column>
87       <el-table-column label="备注" align="center" prop="memo">
88         <template v-slot="scope">
89           <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.memo" />
90         </template>
91       </el-table-column>
92       <el-table-column label="创建时间" align="center" prop="createTime" width="180">
93         <template v-slot="scope">
94           <span>{{ parseTime(scope.row.createTime) }}</span>
95         </template>
96       </el-table-column>
97       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
98         <template v-slot="scope">
99           <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)"
100                      v-hasPermi="['infra:student:update']">修改</el-button>
101           <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
102                      v-hasPermi="['infra:student:delete']">删除</el-button>
103         </template>
104       </el-table-column>
105     </el-table>
106     <!-- 分页组件 -->
107     <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
108                 @pagination="getList"/>
109     <!-- 对话框(添加 / 修改) -->
110     <StudentForm ref="formRef" @success="getList" />
111     </div>
112 </template>
113
114 <script>
115 import * as StudentApi from '@/api/infra/demo';
116 import StudentForm from './StudentForm.vue';
117 export default {
118   name: "Student",
119   components: {
120           StudentForm,
121   },
122   data() {
123     return {
124       // 遮罩层
125       loading: true,
126       // 导出遮罩层
127       exportLoading: false,
128       // 显示搜索条件
129       showSearch: true,
130               // 总条数
131         total: 0,
132       // 学生列表
133       list: [],
134       // 是否展开,默认全部展开
135       isExpandAll: true,
136       // 重新渲染表格状态
137       refreshTable: true,
138       // 选中行
139       currentRow: {},
140       // 查询参数
141       queryParams: {
142                     pageNo: 1,
143             pageSize: 10,
144         name: null,
145         birthday: null,
146         sex: null,
147         enabled: null,
148         createTime: [],
149       },
150             };
151   },
152   created() {
153     this.getList();
154   },
155   methods: {
156     /** 查询列表 */
157     async getList() {
158       try {
159       this.loading = true;
160               const res = await StudentApi.getStudentPage(this.queryParams);
161         this.list = res.data.list;
162         this.total = res.data.total;
163       } finally {
164         this.loading = false;
165       }
166     },
167     /** 搜索按钮操作 */
168     handleQuery() {
169       this.queryParams.pageNo = 1;
170       this.getList();
171     },
172     /** 重置按钮操作 */
173     resetQuery() {
174       this.resetForm("queryForm");
175       this.handleQuery();
176     },
177     /** 添加/修改操作 */
178     openForm(id) {
179       this.$refs["formRef"].open(id);
180     },
181     /** 删除按钮操作 */
182     async handleDelete(row) {
183       const id = row.id;
184       await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?')
185       try {
186        await StudentApi.deleteStudent(id);
187        await this.getList();
188        this.$modal.msgSuccess("删除成功");
189       } catch {}
190     },
191     /** 导出按钮操作 */
192     async handleExport() {
193       await this.$modal.confirm('是否确认导出所有学生数据项?');
194       try {
195         this.exportLoading = true;
196         const res = await StudentApi.exportStudentExcel(this.queryParams);
197         this.$download.excel(res.data, '学生.xls');
198       } catch {
199       } finally {
200         this.exportLoading = false;
201       }
202     },
203               }
204 };
205 </script>