index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. <div class="top-right-btn">
  100. <el-tooltip class="item" effect="dark" content="刷新" placement="top">
  101. <el-button size="mini" circle icon="el-icon-refresh" @click="handleQuery" />
  102. </el-tooltip>
  103. <el-tooltip class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top">
  104. <el-button size="mini" circle icon="el-icon-search" @click="showSearch=!showSearch" />
  105. </el-tooltip>
  106. </div>
  107. </el-row>
  108. <el-table v-loading="loading" :data="configList" @selection-change="handleSelectionChange">
  109. <el-table-column type="selection" width="55" align="center" />
  110. <el-table-column label="参数主键" align="center" prop="configId" />
  111. <el-table-column label="参数名称" align="center" prop="configName" :show-overflow-tooltip="true" />
  112. <el-table-column label="参数键名" align="center" prop="configKey" :show-overflow-tooltip="true" />
  113. <el-table-column label="参数键值" align="center" prop="configValue" />
  114. <el-table-column label="系统内置" align="center" prop="configType" :formatter="typeFormat" />
  115. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  116. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  117. <template slot-scope="scope">
  118. <span>{{ parseTime(scope.row.createTime) }}</span>
  119. </template>
  120. </el-table-column>
  121. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  122. <template slot-scope="scope">
  123. <el-button
  124. size="mini"
  125. type="text"
  126. icon="el-icon-edit"
  127. @click="handleUpdate(scope.row)"
  128. v-hasPermi="['system:config:edit']"
  129. >修改</el-button>
  130. <el-button
  131. size="mini"
  132. type="text"
  133. icon="el-icon-delete"
  134. @click="handleDelete(scope.row)"
  135. v-hasPermi="['system:config:remove']"
  136. >删除</el-button>
  137. </template>
  138. </el-table-column>
  139. </el-table>
  140. <pagination
  141. v-show="total>0"
  142. :total="total"
  143. :page.sync="queryParams.pageNum"
  144. :limit.sync="queryParams.pageSize"
  145. @pagination="getList"
  146. />
  147. <!-- 添加或修改参数配置对话框 -->
  148. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  149. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  150. <el-form-item label="参数名称" prop="configName">
  151. <el-input v-model="form.configName" placeholder="请输入参数名称" />
  152. </el-form-item>
  153. <el-form-item label="参数键名" prop="configKey">
  154. <el-input v-model="form.configKey" placeholder="请输入参数键名" />
  155. </el-form-item>
  156. <el-form-item label="参数键值" prop="configValue">
  157. <el-input v-model="form.configValue" placeholder="请输入参数键值" />
  158. </el-form-item>
  159. <el-form-item label="系统内置" prop="configType">
  160. <el-radio-group v-model="form.configType">
  161. <el-radio
  162. v-for="dict in typeOptions"
  163. :key="dict.dictValue"
  164. :label="dict.dictValue"
  165. >{{dict.dictLabel}}</el-radio>
  166. </el-radio-group>
  167. </el-form-item>
  168. <el-form-item label="备注" prop="remark">
  169. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  170. </el-form-item>
  171. </el-form>
  172. <div slot="footer" class="dialog-footer">
  173. <el-button type="primary" @click="submitForm">确 定</el-button>
  174. <el-button @click="cancel">取 消</el-button>
  175. </div>
  176. </el-dialog>
  177. </div>
  178. </template>
  179. <script>
  180. import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig, clearCache } from "@/api/system/config";
  181. export default {
  182. name: "Config",
  183. data() {
  184. return {
  185. // 遮罩层
  186. loading: true,
  187. // 选中数组
  188. ids: [],
  189. // 非单个禁用
  190. single: true,
  191. // 非多个禁用
  192. multiple: true,
  193. // 显示搜索条件
  194. showSearch: true,
  195. // 总条数
  196. total: 0,
  197. // 参数表格数据
  198. configList: [],
  199. // 弹出层标题
  200. title: "",
  201. // 是否显示弹出层
  202. open: false,
  203. // 类型数据字典
  204. typeOptions: [],
  205. // 日期范围
  206. dateRange: [],
  207. // 查询参数
  208. queryParams: {
  209. pageNum: 1,
  210. pageSize: 10,
  211. configName: undefined,
  212. configKey: undefined,
  213. configType: undefined
  214. },
  215. // 表单参数
  216. form: {},
  217. // 表单校验
  218. rules: {
  219. configName: [
  220. { required: true, message: "参数名称不能为空", trigger: "blur" }
  221. ],
  222. configKey: [
  223. { required: true, message: "参数键名不能为空", trigger: "blur" }
  224. ],
  225. configValue: [
  226. { required: true, message: "参数键值不能为空", trigger: "blur" }
  227. ]
  228. }
  229. };
  230. },
  231. created() {
  232. this.getList();
  233. this.getDicts("sys_yes_no").then(response => {
  234. this.typeOptions = response.data;
  235. });
  236. },
  237. methods: {
  238. /** 查询参数列表 */
  239. getList() {
  240. this.loading = true;
  241. listConfig(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  242. this.configList = response.rows;
  243. this.total = response.total;
  244. this.loading = false;
  245. }
  246. );
  247. },
  248. // 参数系统内置字典翻译
  249. typeFormat(row, column) {
  250. return this.selectDictLabel(this.typeOptions, row.configType);
  251. },
  252. // 取消按钮
  253. cancel() {
  254. this.open = false;
  255. this.reset();
  256. },
  257. // 表单重置
  258. reset() {
  259. this.form = {
  260. configId: undefined,
  261. configName: undefined,
  262. configKey: undefined,
  263. configValue: undefined,
  264. configType: "Y",
  265. remark: undefined
  266. };
  267. this.resetForm("form");
  268. },
  269. /** 搜索按钮操作 */
  270. handleQuery() {
  271. this.queryParams.pageNum = 1;
  272. this.getList();
  273. },
  274. /** 重置按钮操作 */
  275. resetQuery() {
  276. this.dateRange = [];
  277. this.resetForm("queryForm");
  278. this.handleQuery();
  279. },
  280. /** 新增按钮操作 */
  281. handleAdd() {
  282. this.reset();
  283. this.open = true;
  284. this.title = "添加参数";
  285. },
  286. // 多选框选中数据
  287. handleSelectionChange(selection) {
  288. this.ids = selection.map(item => item.configId)
  289. this.single = selection.length!=1
  290. this.multiple = !selection.length
  291. },
  292. /** 修改按钮操作 */
  293. handleUpdate(row) {
  294. this.reset();
  295. const configId = row.configId || this.ids
  296. getConfig(configId).then(response => {
  297. this.form = response.data;
  298. this.open = true;
  299. this.title = "修改参数";
  300. });
  301. },
  302. /** 提交按钮 */
  303. submitForm: function() {
  304. this.$refs["form"].validate(valid => {
  305. if (valid) {
  306. if (this.form.configId != undefined) {
  307. updateConfig(this.form).then(response => {
  308. if (response.code === 200) {
  309. this.msgSuccess("修改成功");
  310. this.open = false;
  311. this.getList();
  312. }
  313. });
  314. } else {
  315. addConfig(this.form).then(response => {
  316. if (response.code === 200) {
  317. this.msgSuccess("新增成功");
  318. this.open = false;
  319. this.getList();
  320. }
  321. });
  322. }
  323. }
  324. });
  325. },
  326. /** 删除按钮操作 */
  327. handleDelete(row) {
  328. const configIds = row.configId || this.ids;
  329. this.$confirm('是否确认删除参数编号为"' + configIds + '"的数据项?', "警告", {
  330. confirmButtonText: "确定",
  331. cancelButtonText: "取消",
  332. type: "warning"
  333. }).then(function() {
  334. return delConfig(configIds);
  335. }).then(() => {
  336. this.getList();
  337. this.msgSuccess("删除成功");
  338. }).catch(function() {});
  339. },
  340. /** 导出按钮操作 */
  341. handleExport() {
  342. const queryParams = this.queryParams;
  343. this.$confirm('是否确认导出所有参数数据项?', "警告", {
  344. confirmButtonText: "确定",
  345. cancelButtonText: "取消",
  346. type: "warning"
  347. }).then(function() {
  348. return exportConfig(queryParams);
  349. }).then(response => {
  350. this.download(response.msg);
  351. }).catch(function() {});
  352. },
  353. /** 清理缓存按钮操作 */
  354. handleClearCache() {
  355. clearCache().then(response => {
  356. if (response.code === 200) {
  357. this.msgSuccess("清理成功");
  358. }
  359. });
  360. }
  361. }
  362. };
  363. </script>