index 5.4 KB

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