index.vue 11 KB

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