houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
提交 | 用户 | 时间
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>
9         <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
10         <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
11       </el-form-item>
12     </el-form>
13
14     <!-- 操作工具栏 -->
15     <el-row :gutter="10" class="mb8">
16       <el-col :span="1.5">
17         <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
18                    v-hasPermi="['infra:category:create']">新增</el-button>
19       </el-col>
20       <el-col :span="1.5">
21         <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
22                    v-hasPermi="['infra:category:export']">导出</el-button>
23       </el-col>
24                   <el-col :span="1.5">
25             <el-button type="danger" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">
26               展开/折叠
27             </el-button>
28           </el-col>
29       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
30     </el-row>
31
32             <el-table
33         v-loading="loading"
34         :data="list"
35         :stripe="true"
36         :show-overflow-tooltip="true"
37         v-if="refreshTable"
38         row-key="id"
39         :default-expand-all="isExpandAll"
40         :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
41       >
42             <el-table-column label="编号" align="center" prop="id">
43         <template v-slot="scope">
44           <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" />
45         </template>
46       </el-table-column>
47       <el-table-column label="名字" align="center" prop="name">
48         <template v-slot="scope">
49           <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.name" />
50         </template>
51       </el-table-column>
52       <el-table-column label="父编号" align="center" prop="parentId">
53         <template v-slot="scope">
54           <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.parentId" />
55         </template>
56       </el-table-column>
57       <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
58         <template v-slot="scope">
59           <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)"
60                      v-hasPermi="['infra:category:update']">修改</el-button>
61           <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
62                      v-hasPermi="['infra:category:delete']">删除</el-button>
63         </template>
64       </el-table-column>
65     </el-table>
66     <!-- 对话框(添加 / 修改) -->
67     <CategoryForm ref="formRef" @success="getList" />
68     </div>
69 </template>
70
71 <script>
72 import * as CategoryApi from '@/api/infra/demo';
73 import CategoryForm from './CategoryForm.vue';
74 export default {
75   name: "Category",
76   components: {
77           CategoryForm,
78   },
79   data() {
80     return {
81       // 遮罩层
82       loading: true,
83       // 导出遮罩层
84       exportLoading: false,
85       // 显示搜索条件
86       showSearch: true,
87             // 分类列表
88       list: [],
89       // 是否展开,默认全部展开
90       isExpandAll: true,
91       // 重新渲染表格状态
92       refreshTable: true,
93       // 选中行
94       currentRow: {},
95       // 查询参数
96       queryParams: {
97                 name: null,
98       },
99             };
100   },
101   created() {
102     this.getList();
103   },
104   methods: {
105     /** 查询列表 */
106     async getList() {
107       try {
108       this.loading = true;
109              const res = await CategoryApi.getCategoryList(this.queryParams);
110        this.list = this.handleTree(res.data, 'id', 'parentId');
111       } finally {
112         this.loading = false;
113       }
114     },
115     /** 搜索按钮操作 */
116     handleQuery() {
117       this.queryParams.pageNo = 1;
118       this.getList();
119     },
120     /** 重置按钮操作 */
121     resetQuery() {
122       this.resetForm("queryForm");
123       this.handleQuery();
124     },
125     /** 添加/修改操作 */
126     openForm(id) {
127       this.$refs["formRef"].open(id);
128     },
129     /** 删除按钮操作 */
130     async handleDelete(row) {
131       const id = row.id;
132       await this.$modal.confirm('是否确认删除分类编号为"' + id + '"的数据项?')
133       try {
134        await CategoryApi.deleteCategory(id);
135        await this.getList();
136        this.$modal.msgSuccess("删除成功");
137       } catch {}
138     },
139     /** 导出按钮操作 */
140     async handleExport() {
141       await this.$modal.confirm('是否确认导出所有分类数据项?');
142       try {
143         this.exportLoading = true;
144         const res = await CategoryApi.exportCategoryExcel(this.queryParams);
145         this.$download.excel(res.data, '分类.xls');
146       } catch {
147       } finally {
148         this.exportLoading = false;
149       }
150     },
151                     /** 展开/折叠操作 */
152         toggleExpandAll() {
153           this.refreshTable = false
154           this.isExpandAll = !this.isExpandAll
155           this.$nextTick(function () {
156             this.refreshTable = true
157           })
158         }
159   }
160 };
161 </script>