index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryRef" :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="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="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 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="创建时间" style="width: 308px;">
  33. <el-date-picker
  34. v-model="dateRange"
  35. value-format="YYYY-MM-DD"
  36. type="daterange"
  37. range-separator="-"
  38. start-placeholder="开始日期"
  39. end-placeholder="结束日期"
  40. ></el-date-picker>
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  44. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  45. </el-form-item>
  46. </el-form>
  47. <el-row :gutter="10" class="mb8">
  48. <el-col :span="1.5">
  49. <el-button
  50. type="primary"
  51. plain
  52. icon="Plus"
  53. @click="handleAdd"
  54. v-hasPermi="['system:config:add']"
  55. >新增</el-button>
  56. </el-col>
  57. <el-col :span="1.5">
  58. <el-button
  59. type="success"
  60. plain
  61. icon="Edit"
  62. :disabled="single"
  63. @click="handleUpdate"
  64. v-hasPermi="['system:config:edit']"
  65. >修改</el-button>
  66. </el-col>
  67. <el-col :span="1.5">
  68. <el-button
  69. type="danger"
  70. plain
  71. icon="Delete"
  72. :disabled="multiple"
  73. @click="handleDelete"
  74. v-hasPermi="['system:config:remove']"
  75. >删除</el-button>
  76. </el-col>
  77. <el-col :span="1.5">
  78. <el-button
  79. type="warning"
  80. plain
  81. icon="Download"
  82. @click="handleExport"
  83. v-hasPermi="['system:config:export']"
  84. >导出</el-button>
  85. </el-col>
  86. <el-col :span="1.5">
  87. <el-button
  88. type="danger"
  89. plain
  90. icon="Refresh"
  91. @click="handleRefreshCache"
  92. v-hasPermi="['system:config:remove']"
  93. >刷新缓存</el-button>
  94. </el-col>
  95. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  96. </el-row>
  97. <el-table v-loading="loading" :data="configList" @selection-change="handleSelectionChange">
  98. <el-table-column type="selection" width="55" align="center" />
  99. <el-table-column label="参数主键" align="center" prop="configId" />
  100. <el-table-column label="参数名称" align="center" prop="configName" :show-overflow-tooltip="true" />
  101. <el-table-column label="参数键名" align="center" prop="configKey" :show-overflow-tooltip="true" />
  102. <el-table-column label="参数键值" align="center" prop="configValue" :show-overflow-tooltip="true" />
  103. <el-table-column label="系统内置" align="center" prop="configType">
  104. <template #default="scope">
  105. <dict-tag :options="sys_yes_no" :value="scope.row.configType" />
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  109. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  110. <template #default="scope">
  111. <span>{{ parseTime(scope.row.createTime) }}</span>
  112. </template>
  113. </el-table-column>
  114. <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
  115. <template #default="scope">
  116. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:config:edit']" >修改</el-button>
  117. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:config:remove']">删除</el-button>
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. <pagination
  122. v-show="total > 0"
  123. :total="total"
  124. v-model:page="queryParams.pageNum"
  125. v-model:limit="queryParams.pageSize"
  126. @pagination="getList"
  127. />
  128. <!-- 添加或修改参数配置对话框 -->
  129. <el-dialog :title="title" v-model="open" width="500px" append-to-body>
  130. <el-form ref="configRef" :model="form" :rules="rules" label-width="80px">
  131. <el-form-item label="参数名称" prop="configName">
  132. <el-input v-model="form.configName" placeholder="请输入参数名称" />
  133. </el-form-item>
  134. <el-form-item label="参数键名" prop="configKey">
  135. <el-input v-model="form.configKey" placeholder="请输入参数键名" />
  136. </el-form-item>
  137. <el-form-item label="参数键值" prop="configValue">
  138. <el-input v-model="form.configValue" placeholder="请输入参数键值" />
  139. </el-form-item>
  140. <el-form-item label="系统内置" prop="configType">
  141. <el-radio-group v-model="form.configType">
  142. <el-radio
  143. v-for="dict in sys_yes_no"
  144. :key="dict.value"
  145. :label="dict.value"
  146. >{{ dict.label }}</el-radio>
  147. </el-radio-group>
  148. </el-form-item>
  149. <el-form-item label="备注" prop="remark">
  150. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  151. </el-form-item>
  152. </el-form>
  153. <template #footer>
  154. <div class="dialog-footer">
  155. <el-button type="primary" @click="submitForm">确 定</el-button>
  156. <el-button @click="cancel">取 消</el-button>
  157. </div>
  158. </template>
  159. </el-dialog>
  160. </div>
  161. </template>
  162. <script setup name="Config">
  163. import { listConfig, getConfig, delConfig, addConfig, updateConfig, refreshCache } from "@/api/system/config";
  164. const { proxy } = getCurrentInstance();
  165. const { sys_yes_no } = proxy.useDict("sys_yes_no");
  166. const configList = ref([]);
  167. const open = ref(false);
  168. const loading = ref(true);
  169. const showSearch = ref(true);
  170. const ids = ref([]);
  171. const single = ref(true);
  172. const multiple = ref(true);
  173. const total = ref(0);
  174. const title = ref("");
  175. const dateRange = ref([]);
  176. const data = reactive({
  177. form: {},
  178. queryParams: {
  179. pageNum: 1,
  180. pageSize: 10,
  181. configName: undefined,
  182. configKey: undefined,
  183. configType: undefined
  184. },
  185. rules: {
  186. configName: [{ required: true, message: "参数名称不能为空", trigger: "blur" }],
  187. configKey: [{ required: true, message: "参数键名不能为空", trigger: "blur" }],
  188. configValue: [{ required: true, message: "参数键值不能为空", trigger: "blur" }]
  189. }
  190. });
  191. const { queryParams, form, rules } = toRefs(data);
  192. /** 查询参数列表 */
  193. function getList() {
  194. loading.value = true;
  195. listConfig(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
  196. configList.value = response.rows;
  197. total.value = response.total;
  198. loading.value = false;
  199. });
  200. }
  201. /** 取消按钮 */
  202. function cancel() {
  203. open.value = false;
  204. reset();
  205. }
  206. /** 表单重置 */
  207. function reset() {
  208. form.value = {
  209. configId: undefined,
  210. configName: undefined,
  211. configKey: undefined,
  212. configValue: undefined,
  213. configType: "Y",
  214. remark: undefined
  215. };
  216. proxy.resetForm("configRef");
  217. }
  218. /** 搜索按钮操作 */
  219. function handleQuery() {
  220. queryParams.value.pageNum = 1;
  221. getList();
  222. }
  223. /** 重置按钮操作 */
  224. function resetQuery() {
  225. dateRange.value = [];
  226. proxy.resetForm("queryRef");
  227. handleQuery();
  228. }
  229. /** 多选框选中数据 */
  230. function handleSelectionChange(selection) {
  231. ids.value = selection.map(item => item.configId);
  232. single.value = selection.length != 1;
  233. multiple.value = !selection.length;
  234. }
  235. /** 新增按钮操作 */
  236. function handleAdd() {
  237. reset();
  238. open.value = true;
  239. title.value = "添加参数";
  240. }
  241. /** 修改按钮操作 */
  242. function handleUpdate(row) {
  243. reset();
  244. const configId = row.configId || ids.value;
  245. getConfig(configId).then(response => {
  246. form.value = response.data;
  247. open.value = true;
  248. title.value = "修改参数";
  249. });
  250. }
  251. /** 提交按钮 */
  252. function submitForm() {
  253. proxy.$refs["configRef"].validate(valid => {
  254. if (valid) {
  255. if (form.value.configId != undefined) {
  256. updateConfig(form.value).then(response => {
  257. proxy.$modal.msgSuccess("修改成功");
  258. open.value = false;
  259. getList();
  260. });
  261. } else {
  262. addConfig(form.value).then(response => {
  263. proxy.$modal.msgSuccess("新增成功");
  264. open.value = false;
  265. getList();
  266. });
  267. }
  268. }
  269. });
  270. }
  271. /** 删除按钮操作 */
  272. function handleDelete(row) {
  273. const configIds = row.configId || ids.value;
  274. proxy.$modal.confirm('是否确认删除参数编号为"' + configIds + '"的数据项?').then(function () {
  275. return delConfig(configIds);
  276. }).then(() => {
  277. getList();
  278. proxy.$modal.msgSuccess("删除成功");
  279. }).catch(() => {});
  280. }
  281. /** 导出按钮操作 */
  282. function handleExport() {
  283. proxy.download("system/config/export", {
  284. ...queryParams.value
  285. }, `config_${new Date().getTime()}.xlsx`);
  286. }
  287. /** 刷新缓存按钮操作 */
  288. function handleRefreshCache() {
  289. refreshCache().then(() => {
  290. proxy.$modal.msgSuccess("刷新缓存成功");
  291. });
  292. }
  293. getList();
  294. </script>