index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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">
  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. data() {
  166. return {
  167. // 遮罩层
  168. loading: true,
  169. // 选中数组
  170. ids: [],
  171. // 非单个禁用
  172. single: true,
  173. // 非多个禁用
  174. multiple: true,
  175. // 总条数
  176. total: 0,
  177. // 参数表格数据
  178. configList: [],
  179. // 弹出层标题
  180. title: "",
  181. // 是否显示弹出层
  182. open: false,
  183. // 类型数据字典
  184. typeOptions: [],
  185. // 日期范围
  186. dateRange: [],
  187. // 查询参数
  188. queryParams: {
  189. pageNum: 1,
  190. pageSize: 10,
  191. configName: undefined,
  192. configKey: undefined,
  193. configType: undefined
  194. },
  195. // 表单参数
  196. form: {},
  197. // 表单校验
  198. rules: {
  199. configName: [
  200. { required: true, message: "参数名称不能为空", trigger: "blur" }
  201. ],
  202. configKey: [
  203. { required: true, message: "参数键名不能为空", trigger: "blur" }
  204. ],
  205. configValue: [
  206. { required: true, message: "参数键值不能为空", trigger: "blur" }
  207. ]
  208. }
  209. };
  210. },
  211. created() {
  212. this.getList();
  213. this.getDicts("sys_yes_no").then(response => {
  214. this.typeOptions = response.data;
  215. });
  216. },
  217. methods: {
  218. /** 查询参数列表 */
  219. getList() {
  220. this.loading = true;
  221. listConfig(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
  222. this.configList = response.rows;
  223. this.total = response.total;
  224. this.loading = false;
  225. }
  226. );
  227. },
  228. // 参数系统内置字典翻译
  229. typeFormat(row, column) {
  230. return this.selectDictLabel(this.typeOptions, row.configType);
  231. },
  232. // 取消按钮
  233. cancel() {
  234. this.open = false;
  235. this.reset();
  236. },
  237. // 表单重置
  238. reset() {
  239. this.form = {
  240. configId: undefined,
  241. configName: undefined,
  242. configKey: undefined,
  243. configValue: undefined,
  244. configType: "Y",
  245. remark: undefined
  246. };
  247. this.resetForm("form");
  248. },
  249. /** 搜索按钮操作 */
  250. handleQuery() {
  251. this.queryParams.pageNum = 1;
  252. this.getList();
  253. },
  254. /** 重置按钮操作 */
  255. resetQuery() {
  256. this.dateRange = [];
  257. this.resetForm("queryForm");
  258. this.handleQuery();
  259. },
  260. /** 新增按钮操作 */
  261. handleAdd() {
  262. this.reset();
  263. this.open = true;
  264. this.title = "添加参数";
  265. },
  266. // 多选框选中数据
  267. handleSelectionChange(selection) {
  268. this.ids = selection.map(item => item.configId)
  269. this.single = selection.length!=1
  270. this.multiple = !selection.length
  271. },
  272. /** 修改按钮操作 */
  273. handleUpdate(row) {
  274. this.reset();
  275. const configId = row.configId || this.ids
  276. getConfig(configId).then(response => {
  277. this.form = response.data;
  278. this.open = true;
  279. this.title = "修改参数";
  280. });
  281. },
  282. /** 提交按钮 */
  283. submitForm: function() {
  284. this.$refs["form"].validate(valid => {
  285. if (valid) {
  286. if (this.form.configId != undefined) {
  287. updateConfig(this.form).then(response => {
  288. if (response.code === 200) {
  289. this.msgSuccess("修改成功");
  290. this.open = false;
  291. this.getList();
  292. } else {
  293. this.msgError(response.msg);
  294. }
  295. });
  296. } else {
  297. addConfig(this.form).then(response => {
  298. if (response.code === 200) {
  299. this.msgSuccess("新增成功");
  300. this.open = false;
  301. this.getList();
  302. } else {
  303. this.msgError(response.msg);
  304. }
  305. });
  306. }
  307. }
  308. });
  309. },
  310. /** 删除按钮操作 */
  311. handleDelete(row) {
  312. const configIds = row.configId || this.ids;
  313. this.$confirm('是否确认删除参数编号为"' + configIds + '"的数据项?', "警告", {
  314. confirmButtonText: "确定",
  315. cancelButtonText: "取消",
  316. type: "warning"
  317. }).then(function() {
  318. return delConfig(configIds);
  319. }).then(() => {
  320. this.getList();
  321. this.msgSuccess("删除成功");
  322. }).catch(function() {});
  323. },
  324. /** 导出按钮操作 */
  325. handleExport() {
  326. const queryParams = this.queryParams;
  327. this.$confirm('是否确认导出所有参数数据项?', "警告", {
  328. confirmButtonText: "确定",
  329. cancelButtonText: "取消",
  330. type: "warning"
  331. }).then(function() {
  332. return exportConfig(queryParams);
  333. }).then(response => {
  334. this.download(response.msg);
  335. }).catch(function() {});
  336. }
  337. }
  338. };
  339. </script>