index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="参数名称" prop="configName">
  5. <el-input
  6. v-model="queryParams.configName"
  7. placeholder="请输入参数名称"
  8. clearable
  9. size="small"
  10. style="width: 240px"
  11. @keyup.enter.native="handleQuery"
  12. />
  13. </el-form-item>
  14. <el-form-item label="参数键名" prop="configKey">
  15. <el-input
  16. v-model="queryParams.configKey"
  17. placeholder="请输入参数键名"
  18. clearable
  19. size="small"
  20. style="width: 240px"
  21. @keyup.enter.native="handleQuery"
  22. />
  23. </el-form-item>
  24. <el-form-item label="系统内置" prop="configType">
  25. <el-select v-model="queryParams.configType" placeholder="系统内置" clearable size="small">
  26. <el-option
  27. v-for="dict in typeOptions"
  28. :key="dict.dictValue"
  29. :label="dict.dictLabel"
  30. :value="dict.dictValue"
  31. />
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="创建时间">
  35. <el-date-picker
  36. v-model="dateRange"
  37. size="small"
  38. style="width: 240px"
  39. value-format="yyyy-MM-dd"
  40. type="daterange"
  41. range-separator="-"
  42. start-placeholder="开始日期"
  43. end-placeholder="结束日期"
  44. ></el-date-picker>
  45. </el-form-item>
  46. <el-form-item>
  47. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  48. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  49. </el-form-item>
  50. </el-form>
  51. <el-row :gutter="10" class="mb8">
  52. <el-col :span="1.5">
  53. <el-button
  54. type="primary"
  55. icon="el-icon-plus"
  56. size="mini"
  57. @click="handleAdd"
  58. v-hasPermi="['system:config:add']"
  59. >新增</el-button>
  60. </el-col>
  61. <el-col :span="1.5">
  62. <el-button
  63. type="success"
  64. icon="el-icon-edit"
  65. size="mini"
  66. :disabled="single"
  67. @click="handleUpdate"
  68. v-hasPermi="['system:config:edit']"
  69. >修改</el-button>
  70. </el-col>
  71. <el-col :span="1.5">
  72. <el-button
  73. type="danger"
  74. icon="el-icon-delete"
  75. size="mini"
  76. :disabled="multiple"
  77. @click="handleDelete"
  78. v-hasPermi="['system:config:remove']"
  79. >删除</el-button>
  80. </el-col>
  81. <el-col :span="1.5">
  82. <el-button
  83. type="warning"
  84. icon="el-icon-download"
  85. size="mini"
  86. @click="handleExport"
  87. v-hasPermi="['system:config:export']"
  88. >导出</el-button>
  89. </el-col>
  90. <el-col :span="1.5">
  91. <el-button
  92. type="danger"
  93. icon="el-icon-refresh"
  94. size="mini"
  95. @click="handleClearCache"
  96. v-hasPermi="['system:config:remove']"
  97. >清理缓存</el-button>
  98. </el-col>
  99. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  100. </el-row>
  101. <el-table v-loading="loading" :data="configList" @selection-change="handleSelectionChange">
  102. <el-table-column type="selection" width="55" align="center" />
  103. <el-table-column label="参数主键" align="center" prop="configId" />
  104. <el-table-column label="参数名称" align="center" prop="configName" :show-overflow-tooltip="true" />
  105. <el-table-column label="参数键名" align="center" prop="configKey" :show-overflow-tooltip="true" />
  106. <el-table-column label="参数键值" align="center" prop="configValue" />
  107. <el-table-column label="系统内置" align="center" prop="configType" :formatter="typeFormat" />
  108. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  109. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  110. <template slot-scope="scope">
  111. <span>{{ parseTime(scope.row.createTime) }}</span>
  112. </template>
  113. </el-table-column>
  114. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  115. <template slot-scope="scope">
  116. <el-button
  117. size="mini"
  118. type="text"
  119. icon="el-icon-edit"
  120. @click="handleUpdate(scope.row)"
  121. v-hasPermi="['system:config:edit']"
  122. >修改</el-button>
  123. <el-button
  124. size="mini"
  125. type="text"
  126. icon="el-icon-delete"
  127. @click="handleDelete(scope.row)"
  128. v-hasPermi="['system:config:remove']"
  129. >删除</el-button>
  130. </template>
  131. </el-table-column>
  132. </el-table>
  133. <pagination
  134. v-show="total>0"
  135. :total="total"
  136. :page.sync="queryParams.pageNum"
  137. :limit.sync="queryParams.pageSize"
  138. @pagination="getList"
  139. />
  140. <!-- 添加或修改参数配置对话框 -->
  141. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  142. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  143. <el-form-item label="参数名称" prop="configName">
  144. <el-input v-model="form.configName" placeholder="请输入参数名称" />
  145. </el-form-item>
  146. <el-form-item label="参数键名" prop="configKey">
  147. <el-input v-model="form.configKey" placeholder="请输入参数键名" />
  148. </el-form-item>
  149. <el-form-item label="参数键值" prop="configValue">
  150. <el-input v-model="form.configValue" placeholder="请输入参数键值" />
  151. </el-form-item>
  152. <el-form-item label="系统内置" prop="configType">
  153. <el-radio-group v-model="form.configType">
  154. <el-radio
  155. v-for="dict in typeOptions"
  156. :key="dict.dictValue"
  157. :label="dict.dictValue"
  158. >{{dict.dictLabel}}</el-radio>
  159. </el-radio-group>
  160. </el-form-item>
  161. <el-form-item label="备注" prop="remark">
  162. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  163. </el-form-item>
  164. </el-form>
  165. <div slot="footer" class="dialog-footer">
  166. <el-button type="primary" @click="submitForm">确 定</el-button>
  167. <el-button @click="cancel">取 消</el-button>
  168. </div>
  169. </el-dialog>
  170. </div>
  171. </template>
  172. <script>
  173. import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig, clearCache } from "@/api/system/config";
  174. export default {
  175. name: "Config",
  176. data() {
  177. return {
  178. // 遮罩层
  179. loading: true,
  180. // 选中数组
  181. ids: [],
  182. // 非单个禁用
  183. single: true,
  184. // 非多个禁用
  185. multiple: true,
  186. // 显示搜索条件
  187. showSearch: true,
  188. // 总条数
  189. total: 0,
  190. // 参数表格数据
  191. configList: [],
  192. // 弹出层标题
  193. title: "",
  194. // 是否显示弹出层
  195. open: false,
  196. // 类型数据字典
  197. typeOptions: [],
  198. // 日期范围
  199. dateRange: [],
  200. // 查询参数
  201. queryParams: {
  202. pageNum: 1,
  203. pageSize: 10,
  204. configName: undefined,
  205. configKey: undefined,
  206. configType: undefined
  207. },
  208. // 表单参数
  209. form: {},
  210. // 表单校验
  211. rules: {
  212. configName: [
  213. { required: true, message: "参数名称不能为空", trigger: "blur" }
  214. ],
  215. configKey: [
  216. { required: true, message: "参数键名不能为空", trigger: "blur" }
  217. ],
  218. configValue: [
  219. { required: true, message: "参数键值不能为空", trigger: "blur" }
  220. ]
  221. }
  222. };
  223. },
  224. created() {
  225. this.getList();
  226. this.getDicts("sys_yes_no").then(response => {
  227. this.typeOptions = response.data;
  228. });
  229. },
  230. methods: {
  231. /** 查询参数列表 */
  232. getList() {
  233. this.loading = true;
  234. listConfig(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  235. this.configList = response.rows;
  236. this.total = response.total;
  237. this.loading = false;
  238. }
  239. );
  240. },
  241. // 参数系统内置字典翻译
  242. typeFormat(row, column) {
  243. return this.selectDictLabel(this.typeOptions, row.configType);
  244. },
  245. // 取消按钮
  246. cancel() {
  247. this.open = false;
  248. this.reset();
  249. },
  250. // 表单重置
  251. reset() {
  252. this.form = {
  253. configId: undefined,
  254. configName: undefined,
  255. configKey: undefined,
  256. configValue: undefined,
  257. configType: "Y",
  258. remark: undefined
  259. };
  260. this.resetForm("form");
  261. },
  262. /** 搜索按钮操作 */
  263. handleQuery() {
  264. this.queryParams.pageNum = 1;
  265. this.getList();
  266. },
  267. /** 重置按钮操作 */
  268. resetQuery() {
  269. this.dateRange = [];
  270. this.resetForm("queryForm");
  271. this.handleQuery();
  272. },
  273. /** 新增按钮操作 */
  274. handleAdd() {
  275. this.reset();
  276. this.open = true;
  277. this.title = "添加参数";
  278. },
  279. // 多选框选中数据
  280. handleSelectionChange(selection) {
  281. this.ids = selection.map(item => item.configId)
  282. this.single = selection.length!=1
  283. this.multiple = !selection.length
  284. },
  285. /** 修改按钮操作 */
  286. handleUpdate(row) {
  287. this.reset();
  288. const configId = row.configId || this.ids
  289. getConfig(configId).then(response => {
  290. this.form = response.data;
  291. this.open = true;
  292. this.title = "修改参数";
  293. });
  294. },
  295. /** 提交按钮 */
  296. submitForm: function() {
  297. this.$refs["form"].validate(valid => {
  298. if (valid) {
  299. if (this.form.configId != undefined) {
  300. updateConfig(this.form).then(response => {
  301. this.msgSuccess("修改成功");
  302. this.open = false;
  303. this.getList();
  304. });
  305. } else {
  306. addConfig(this.form).then(response => {
  307. this.msgSuccess("新增成功");
  308. this.open = false;
  309. this.getList();
  310. });
  311. }
  312. }
  313. });
  314. },
  315. /** 删除按钮操作 */
  316. handleDelete(row) {
  317. const configIds = row.configId || this.ids;
  318. this.$confirm('是否确认删除参数编号为"' + configIds + '"的数据项?', "警告", {
  319. confirmButtonText: "确定",
  320. cancelButtonText: "取消",
  321. type: "warning"
  322. }).then(function() {
  323. return delConfig(configIds);
  324. }).then(() => {
  325. this.getList();
  326. this.msgSuccess("删除成功");
  327. })
  328. },
  329. /** 导出按钮操作 */
  330. handleExport() {
  331. const queryParams = this.queryParams;
  332. this.$confirm('是否确认导出所有参数数据项?', "警告", {
  333. confirmButtonText: "确定",
  334. cancelButtonText: "取消",
  335. type: "warning"
  336. }).then(function() {
  337. return exportConfig(queryParams);
  338. }).then(response => {
  339. this.download(response.msg);
  340. })
  341. },
  342. /** 清理缓存按钮操作 */
  343. handleClearCache() {
  344. clearCache().then(response => {
  345. this.msgSuccess("清理成功");
  346. });
  347. }
  348. }
  349. };
  350. </script>