index.vue 12 KB

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