index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <template>
  2. <div class="app-container">
  3. <doc-alert title="配置中心" url="https://doc.iocoder.cn/config-center/" />
  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 style="width: 240px"
  8. @keyup.enter.native="handleQuery"/>
  9. </el-form-item>
  10. <el-form-item label="参数键名" prop="key">
  11. <el-input v-model="queryParams.key" placeholder="请输入参数键名" clearable style="width: 240px"
  12. @keyup.enter.native="handleQuery"/>
  13. </el-form-item>
  14. <el-form-item label="系统内置" prop="type">
  15. <el-select v-model="queryParams.type" placeholder="系统内置" clearable>
  16. <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_CONFIG_TYPE)" :key="parseInt(dict.value)"
  17. :label="dict.label" :value="parseInt(dict.value)"/>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item label="创建时间">
  21. <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
  22. range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  26. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  27. </el-form-item>
  28. </el-form>
  29. <el-row :gutter="10" class="mb8">
  30. <el-col :span="1.5">
  31. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  32. v-hasPermi="['infra:config:create']">新增</el-button>
  33. </el-col>
  34. <el-col :span="1.5">
  35. <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
  36. v-hasPermi="['infra:config:export']">导出</el-button>
  37. </el-col>
  38. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  39. </el-row>
  40. <el-table v-loading="loading" :data="configList">
  41. <el-table-column label="参数主键" align="center" prop="id" />
  42. <el-table-column label="参数分类" align="center" prop="group" />
  43. <el-table-column label="参数名称" align="center" prop="name" :show-overflow-tooltip="true" />
  44. <el-table-column label="参数键名" align="center" prop="key" :show-overflow-tooltip="true" />
  45. <el-table-column label="参数键值" align="center" prop="value" />
  46. <el-table-column label="系统内置" align="center" prop="type">
  47. <template slot-scope="scope">
  48. <dict-tag :type="DICT_TYPE.INFRA_CONFIG_TYPE" :value="scope.row.type" />
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="是否可见" align="center" prop="visible">
  52. <template slot-scope="scope">
  53. <span>{{ scope.row.visible ? '是' : '否' }}</span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  57. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  58. <template slot-scope="scope">
  59. <span>{{ parseTime(scope.row.createTime) }}</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  63. <template slot-scope="scope">
  64. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  65. v-hasPermi="['infra:config:update']">修改</el-button>
  66. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  67. v-hasPermi="['infra:config:delete']">删除</el-button>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" @pagination="getList"/>
  72. <!-- 添加或修改参数配置对话框 -->
  73. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  74. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  75. <el-form-item label="参数分类" prop="category">
  76. <el-input v-model="form.category" placeholder="请输入参数分类" />
  77. </el-form-item>
  78. <el-form-item label="参数名称" prop="name">
  79. <el-input v-model="form.name" placeholder="请输入参数名称" />
  80. </el-form-item>
  81. <el-form-item label="参数键名" prop="key">
  82. <el-input v-model="form.key" placeholder="请输入参数键名" />
  83. </el-form-item>
  84. <el-form-item label="参数键值" prop="value">
  85. <el-input v-model="form.value" placeholder="请输入参数键值" />
  86. </el-form-item>
  87. <el-form-item label="是否可见" prop="type">
  88. <el-radio-group v-model="form.visible">
  89. <el-radio :key="true" :label="true">是</el-radio>
  90. <el-radio :key="false" :label="false">否</el-radio>
  91. </el-radio-group>
  92. </el-form-item>
  93. <el-form-item label="备注" prop="remark">
  94. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  95. </el-form-item>
  96. </el-form>
  97. <div slot="footer" class="dialog-footer">
  98. <el-button type="primary" @click="submitForm">确 定</el-button>
  99. <el-button @click="cancel">取 消</el-button>
  100. </div>
  101. </el-dialog>
  102. </div>
  103. </template>
  104. <script>
  105. import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig } from "@/api/infra/config";
  106. export default {
  107. name: "Config",
  108. data() {
  109. return {
  110. // 遮罩层
  111. loading: true,
  112. // 导出遮罩层
  113. exportLoading: false,
  114. // 显示搜索条件
  115. showSearch: true,
  116. // 总条数
  117. total: 0,
  118. // 参数表格数据
  119. configList: [],
  120. // 弹出层标题
  121. title: "",
  122. // 是否显示弹出层
  123. open: false,
  124. // 类型数据字典
  125. typeOptions: [],
  126. // 日期范围
  127. dateRange: [],
  128. // 查询参数
  129. queryParams: {
  130. pageNo: 1,
  131. pageSize: 10,
  132. name: undefined,
  133. key: undefined,
  134. type: undefined
  135. },
  136. // 表单参数
  137. form: {},
  138. // 表单校验
  139. rules: {
  140. category: [
  141. { required: true, message: "参数分类不能为空", trigger: "blur" }
  142. ],
  143. name: [
  144. { required: true, message: "参数名称不能为空", trigger: "blur" }
  145. ],
  146. key: [
  147. { required: true, message: "参数键名不能为空", trigger: "blur" }
  148. ],
  149. value: [
  150. { required: true, message: "参数键值不能为空", trigger: "blur" }
  151. ]
  152. }
  153. };
  154. },
  155. created() {
  156. this.getList();
  157. },
  158. methods: {
  159. /** 查询参数列表 */
  160. getList() {
  161. this.loading = true;
  162. listConfig(this.addDateRange(this.queryParams, [
  163. this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined,
  164. this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined,
  165. ])).then(response => {
  166. this.configList = response.data.list;
  167. this.total = response.data.total;
  168. this.loading = false;
  169. }
  170. );
  171. },
  172. // 取消按钮
  173. cancel() {
  174. this.open = false;
  175. this.reset();
  176. },
  177. // 表单重置
  178. reset() {
  179. this.form = {
  180. id: undefined,
  181. name: undefined,
  182. key: undefined,
  183. value: undefined,
  184. remark: undefined
  185. };
  186. this.resetForm("form");
  187. },
  188. /** 搜索按钮操作 */
  189. handleQuery() {
  190. this.queryParams.pageNo = 1;
  191. this.getList();
  192. },
  193. /** 重置按钮操作 */
  194. resetQuery() {
  195. this.dateRange = [];
  196. this.resetForm("queryForm");
  197. this.handleQuery();
  198. },
  199. /** 新增按钮操作 */
  200. handleAdd() {
  201. this.reset();
  202. this.open = true;
  203. this.title = "添加参数";
  204. },
  205. /** 修改按钮操作 */
  206. handleUpdate(row) {
  207. this.reset();
  208. const id = row.id || this.ids
  209. getConfig(id).then(response => {
  210. this.form = response.data;
  211. this.open = true;
  212. this.title = "修改参数";
  213. });
  214. },
  215. /** 提交按钮 */
  216. submitForm: function() {
  217. this.$refs["form"].validate(valid => {
  218. if (valid) {
  219. if (this.form.id !== undefined) {
  220. updateConfig(this.form).then(response => {
  221. this.$modal.msgSuccess("修改成功");
  222. this.open = false;
  223. this.getList();
  224. });
  225. } else {
  226. addConfig(this.form).then(response => {
  227. this.$modal.msgSuccess("新增成功");
  228. this.open = false;
  229. this.getList();
  230. });
  231. }
  232. }
  233. });
  234. },
  235. /** 删除按钮操作 */
  236. handleDelete(row) {
  237. const ids = row.id || this.ids;
  238. this.$modal.confirm('是否确认删除参数编号为"' + ids + '"的数据项?').then(function() {
  239. return delConfig(ids);
  240. }).then(() => {
  241. this.getList();
  242. this.$modal.msgSuccess("删除成功");
  243. }).catch(() => {});
  244. },
  245. /** 导出按钮操作 */
  246. handleExport() {
  247. const queryParams = this.addDateRange(this.queryParams, [
  248. this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined,
  249. this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined,
  250. ]);
  251. this.$modal.confirm('是否确认导出所有参数数据项?').then(() => {
  252. this.exportLoading = true;
  253. return exportConfig(queryParams);
  254. }).then(response => {
  255. this.$download.excel(response, '参数配置.xls');
  256. this.exportLoading = false;
  257. }).catch(() => {});
  258. },
  259. }
  260. };
  261. </script>