index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :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. style="width: 240px"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="参数键名" prop="configKey">
  14. <el-input
  15. v-model="queryParams.configKey"
  16. placeholder="请输入参数键名"
  17. clearable
  18. style="width: 240px"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="系统内置" prop="configType">
  23. <el-select v-model="queryParams.configType" placeholder="系统内置" clearable>
  24. <el-option
  25. v-for="dict in dict.type.sys_yes_no"
  26. :key="dict.value"
  27. :label="dict.label"
  28. :value="dict.value"
  29. />
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="创建时间">
  33. <el-date-picker
  34. v-model="dateRange"
  35. style="width: 240px"
  36. value-format="yyyy-MM-dd"
  37. type="daterange"
  38. range-separator="-"
  39. start-placeholder="开始日期"
  40. end-placeholder="结束日期"
  41. ></el-date-picker>
  42. </el-form-item>
  43. <el-form-item>
  44. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  45. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  46. </el-form-item>
  47. </el-form>
  48. <el-row :gutter="10" class="mb8">
  49. <el-col :span="1.5">
  50. <el-button
  51. type="primary"
  52. plain
  53. icon="el-icon-plus"
  54. size="mini"
  55. @click="handleAdd"
  56. v-hasPermi="['system:config:add']"
  57. >新增</el-button>
  58. </el-col>
  59. <el-col :span="1.5">
  60. <el-button
  61. type="success"
  62. plain
  63. icon="el-icon-edit"
  64. size="mini"
  65. :disabled="single"
  66. @click="handleUpdate"
  67. v-hasPermi="['system:config:edit']"
  68. >修改</el-button>
  69. </el-col>
  70. <el-col :span="1.5">
  71. <el-button
  72. type="danger"
  73. plain
  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. plain
  85. icon="el-icon-download"
  86. size="mini"
  87. @click="handleExport"
  88. v-hasPermi="['system:config:export']"
  89. >导出</el-button>
  90. </el-col>
  91. <el-col :span="1.5">
  92. <el-button
  93. type="danger"
  94. plain
  95. icon="el-icon-refresh"
  96. size="mini"
  97. @click="handleRefreshCache"
  98. v-hasPermi="['system:config:remove']"
  99. >刷新缓存</el-button>
  100. </el-col>
  101. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  102. </el-row>
  103. <el-table v-loading="loading" :data="configList" @selection-change="handleSelectionChange">
  104. <el-table-column type="selection" width="55" align="center" />
  105. <el-table-column label="参数主键" align="center" prop="configId" />
  106. <el-table-column label="参数名称" align="center" prop="configName" :show-overflow-tooltip="true" />
  107. <el-table-column label="参数键名" align="center" prop="configKey" :show-overflow-tooltip="true" />
  108. <el-table-column label="参数键值" align="center" prop="configValue" />
  109. <el-table-column label="系统内置" align="center" prop="configType">
  110. <template slot-scope="scope">
  111. <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.configType"/>
  112. </template>
  113. </el-table-column>
  114. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  115. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  116. <template slot-scope="scope">
  117. <span>{{ parseTime(scope.row.createTime) }}</span>
  118. </template>
  119. </el-table-column>
  120. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  121. <template slot-scope="scope">
  122. <el-button
  123. size="mini"
  124. type="text"
  125. icon="el-icon-edit"
  126. @click="handleUpdate(scope.row)"
  127. v-hasPermi="['system:config:edit']"
  128. >修改</el-button>
  129. <el-button
  130. size="mini"
  131. type="text"
  132. icon="el-icon-delete"
  133. @click="handleDelete(scope.row)"
  134. v-hasPermi="['system:config:remove']"
  135. >删除</el-button>
  136. </template>
  137. </el-table-column>
  138. </el-table>
  139. <pagination
  140. v-show="total>0"
  141. :total="total"
  142. :page.sync="queryParams.pageNum"
  143. :limit.sync="queryParams.pageSize"
  144. @pagination="getList"
  145. />
  146. <!-- 添加或修改参数配置对话框 -->
  147. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  148. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  149. <el-form-item label="参数名称" prop="configName">
  150. <el-input v-model="form.configName" placeholder="请输入参数名称" />
  151. </el-form-item>
  152. <el-form-item label="参数键名" prop="configKey">
  153. <el-input v-model="form.configKey" placeholder="请输入参数键名" />
  154. </el-form-item>
  155. <el-form-item label="参数键值" prop="configValue">
  156. <el-input v-model="form.configValue" placeholder="请输入参数键值" />
  157. </el-form-item>
  158. <el-form-item label="系统内置" prop="configType">
  159. <el-radio-group v-model="form.configType">
  160. <el-radio
  161. v-for="dict in dict.type.sys_yes_no"
  162. :key="dict.value"
  163. :label="dict.value"
  164. >{{dict.label}}</el-radio>
  165. </el-radio-group>
  166. </el-form-item>
  167. <el-form-item label="备注" prop="remark">
  168. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  169. </el-form-item>
  170. </el-form>
  171. <div slot="footer" class="dialog-footer">
  172. <el-button type="primary" @click="submitForm">确 定</el-button>
  173. <el-button @click="cancel">取 消</el-button>
  174. </div>
  175. </el-dialog>
  176. </div>
  177. </template>
  178. <script>
  179. import { listConfig, getConfig, delConfig, addConfig, updateConfig, refreshCache } from "@/api/system/config";
  180. export default {
  181. name: "Config",
  182. dicts: ['sys_yes_no'],
  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. 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. },
  232. methods: {
  233. /** 查询参数列表 */
  234. getList() {
  235. this.loading = true;
  236. listConfig(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  237. this.configList = response.rows;
  238. this.total = response.total;
  239. this.loading = false;
  240. }
  241. );
  242. },
  243. // 取消按钮
  244. cancel() {
  245. this.open = false;
  246. this.reset();
  247. },
  248. // 表单重置
  249. reset() {
  250. this.form = {
  251. configId: undefined,
  252. configName: undefined,
  253. configKey: undefined,
  254. configValue: undefined,
  255. configType: "Y",
  256. remark: undefined
  257. };
  258. this.resetForm("form");
  259. },
  260. /** 搜索按钮操作 */
  261. handleQuery() {
  262. this.queryParams.pageNum = 1;
  263. this.getList();
  264. },
  265. /** 重置按钮操作 */
  266. resetQuery() {
  267. this.dateRange = [];
  268. this.resetForm("queryForm");
  269. this.handleQuery();
  270. },
  271. /** 新增按钮操作 */
  272. handleAdd() {
  273. this.reset();
  274. this.open = true;
  275. this.title = "添加参数";
  276. },
  277. // 多选框选中数据
  278. handleSelectionChange(selection) {
  279. this.ids = selection.map(item => item.configId)
  280. this.single = selection.length!=1
  281. this.multiple = !selection.length
  282. },
  283. /** 修改按钮操作 */
  284. handleUpdate(row) {
  285. this.reset();
  286. const configId = row.configId || this.ids
  287. getConfig(configId).then(response => {
  288. this.form = response.data;
  289. this.open = true;
  290. this.title = "修改参数";
  291. });
  292. },
  293. /** 提交按钮 */
  294. submitForm: function() {
  295. this.$refs["form"].validate(valid => {
  296. if (valid) {
  297. if (this.form.configId != undefined) {
  298. updateConfig(this.form).then(response => {
  299. this.$modal.msgSuccess("修改成功");
  300. this.open = false;
  301. this.getList();
  302. });
  303. } else {
  304. addConfig(this.form).then(response => {
  305. this.$modal.msgSuccess("新增成功");
  306. this.open = false;
  307. this.getList();
  308. });
  309. }
  310. }
  311. });
  312. },
  313. /** 删除按钮操作 */
  314. handleDelete(row) {
  315. const configIds = row.configId || this.ids;
  316. this.$modal.confirm('是否确认删除参数编号为"' + configIds + '"的数据项?').then(function() {
  317. return delConfig(configIds);
  318. }).then(() => {
  319. this.getList();
  320. this.$modal.msgSuccess("删除成功");
  321. }).catch(() => {});
  322. },
  323. /** 导出按钮操作 */
  324. handleExport() {
  325. this.download('system/config/export', {
  326. ...this.queryParams
  327. }, `config_${new Date().getTime()}.xlsx`)
  328. },
  329. /** 刷新缓存按钮操作 */
  330. handleRefreshCache() {
  331. refreshCache().then(() => {
  332. this.$modal.msgSuccess("刷新成功");
  333. });
  334. }
  335. }
  336. };
  337. </script>