index.vue 11 KB

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