|
| 1 | +<template> |
| 2 | + <div class="app-container"> |
| 3 | + |
| 4 | + <!-- 搜索工作栏 --> |
| 5 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> |
| 6 | + <el-form-item label="名字" prop="name"> |
| 7 | + <el-input v-model="queryParams.name" placeholder="请输入名字" clearable @keyup.enter.native="handleQuery"/> |
| 8 | + </el-form-item> |
| 9 | + <el-form-item label="父级编号" prop="parentId"> |
| 10 | + <el-input v-model="queryParams.parentId" placeholder="请输入父级编号" clearable @keyup.enter.native="handleQuery"/> |
| 11 | + </el-form-item> |
| 12 | + <el-form-item label="创建时间" prop="createTime"> |
| 13 | + <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" |
| 14 | + range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" /> |
| 15 | + </el-form-item> |
| 16 | + <el-form-item> |
| 17 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> |
| 18 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> |
| 19 | + </el-form-item> |
| 20 | + </el-form> |
| 21 | + |
| 22 | + <!-- 操作工具栏 --> |
| 23 | + <el-row :gutter="10" class="mb8"> |
| 24 | + <el-col :span="1.5"> |
| 25 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" |
| 26 | + v-hasPermi="['infra:demo02-category:create']">新增</el-button> |
| 27 | + </el-col> |
| 28 | + <el-col :span="1.5"> |
| 29 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" |
| 30 | + v-hasPermi="['infra:demo02-category:export']">导出</el-button> |
| 31 | + </el-col> |
| 32 | + <el-col :span="1.5"> |
| 33 | + <el-button type="danger" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll"> |
| 34 | + 展开/折叠 |
| 35 | + </el-button> |
| 36 | + </el-col> |
| 37 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| 38 | + </el-row> |
| 39 | + |
| 40 | + <el-table |
| 41 | + v-loading="loading" |
| 42 | + :data="list" |
| 43 | + :stripe="true" |
| 44 | + :show-overflow-tooltip="true" |
| 45 | + v-if="refreshTable" |
| 46 | + row-key="id" |
| 47 | + :default-expand-all="isExpandAll" |
| 48 | + :tree-props="{children: 'children', hasChildren: 'hasChildren'}" |
| 49 | + > |
| 50 | + <el-table-column label="编号" align="center" prop="id" /> |
| 51 | + <el-table-column label="名字" align="center" prop="name" /> |
| 52 | + <el-table-column label="父级编号" align="center" prop="parentId" /> |
| 53 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> |
| 54 | + <template v-slot="scope"> |
| 55 | + <span>{{ parseTime(scope.row.createTime) }}</span> |
| 56 | + </template> |
| 57 | + </el-table-column> |
| 58 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> |
| 59 | + <template v-slot="scope"> |
| 60 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" |
| 61 | + v-hasPermi="['infra:demo02-category:update']">修改</el-button> |
| 62 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" |
| 63 | + v-hasPermi="['infra:demo02-category:delete']">删除</el-button> |
| 64 | + </template> |
| 65 | + </el-table-column> |
| 66 | + </el-table> |
| 67 | + <!-- 分页组件 --> |
| 68 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" |
| 69 | + @pagination="getList"/> |
| 70 | + |
| 71 | + <!-- 对话框(添加 / 修改) --> |
| 72 | + <Demo02CategoryForm ref="formRef" @success="getList" /> |
| 73 | + </div> |
| 74 | +</template> |
| 75 | + |
| 76 | +<script> |
| 77 | +import * as Demo02CategoryApi from '@/api/infra/demo02'; |
| 78 | +import Demo02CategoryForm from './Demo02CategoryForm.vue'; |
| 79 | +export default { |
| 80 | + name: "Demo02Category", |
| 81 | + components: { |
| 82 | + Demo02CategoryForm, |
| 83 | + }, |
| 84 | + data() { |
| 85 | + return { |
| 86 | + // 遮罩层 |
| 87 | + loading: true, |
| 88 | + // 导出遮罩层 |
| 89 | + exportLoading: false, |
| 90 | + // 显示搜索条件 |
| 91 | + showSearch: true, |
| 92 | + // 总条数 |
| 93 | + // 示例分类列表 |
| 94 | + list: [], |
| 95 | + // 是否展开,默认全部展开 |
| 96 | + isExpandAll: true, |
| 97 | + // 重新渲染表格状态 |
| 98 | + refreshTable: true, |
| 99 | + // 选中行 |
| 100 | + currentRow: {}, |
| 101 | + // 查询参数 |
| 102 | + queryParams: { |
| 103 | + name: null, |
| 104 | + parentId: null, |
| 105 | + createTime: [], |
| 106 | + } |
| 107 | + }; |
| 108 | + }, |
| 109 | + created() { |
| 110 | + this.getList(); |
| 111 | + }, |
| 112 | + methods: { |
| 113 | + /** 查询列表 */ |
| 114 | + getList() { |
| 115 | + try { |
| 116 | + this.loading = true; |
| 117 | + Demo02CategoryApi.getDemo02CategoryList(this.queryParams).then(response => { |
| 118 | + this.list = this.handleTree(response.data, 'id', 'parentId'); |
| 119 | + }) |
| 120 | + } finally { |
| 121 | + this.loading = false; |
| 122 | + } |
| 123 | + }, |
| 124 | + /** 搜索按钮操作 */ |
| 125 | + handleQuery() { |
| 126 | + this.queryParams.pageNo = 1; |
| 127 | + this.getList(); |
| 128 | + }, |
| 129 | + /** 重置按钮操作 */ |
| 130 | + resetQuery() { |
| 131 | + this.resetForm("queryForm"); |
| 132 | + this.handleQuery(); |
| 133 | + }, |
| 134 | + /** 添加/修改操作 */ |
| 135 | + openForm(id) { |
| 136 | + this.$refs["formRef"].open(id) |
| 137 | + }, |
| 138 | + /** 删除按钮操作 */ |
| 139 | + handleDelete(row) { |
| 140 | + const that = this; |
| 141 | + try { |
| 142 | + const id = row.id; |
| 143 | + this.$modal.confirm('是否确认删除示例分类编号为"' + id + '"的数据项?').then(()=>{ |
| 144 | + return Demo02CategoryApi.deleteDemo02Category(id); |
| 145 | + }).then(() => { |
| 146 | + that.getList(); |
| 147 | + that.$modal.msgSuccess("删除成功"); |
| 148 | + }).catch(() => {}); |
| 149 | + } catch {} |
| 150 | + }, |
| 151 | + /** 导出按钮操作 */ |
| 152 | + handleExport() { |
| 153 | + const that = this; |
| 154 | + try { |
| 155 | + this.$modal.confirm('是否确认导出所有示例分类数据项?').then(() => { |
| 156 | + that.exportLoading = true; |
| 157 | + return Demo02CategoryApi.exportDemo02CategoryExcel(params); |
| 158 | + }).then(response => { |
| 159 | + that.$download.excel(response, '示例分类.xls'); |
| 160 | + }); |
| 161 | + } catch { |
| 162 | + } finally { |
| 163 | + that.exportLoading = false; |
| 164 | + } |
| 165 | + }, |
| 166 | + /** 展开/折叠操作 */ |
| 167 | + toggleExpandAll() { |
| 168 | + this.refreshTable = false |
| 169 | + this.isExpandAll = !this.isExpandAll |
| 170 | + this.$nextTick(function () { |
| 171 | + this.refreshTable = true |
| 172 | + }) |
| 173 | + } |
| 174 | + } |
| 175 | +}; |
| 176 | +</script> |
0 commit comments