index.vue 11 KB

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