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