config.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <script setup lang="ts">
  2. import FormSearch from "@/components/opts/form-search.vue";
  3. import TableButtons from "@/components/opts/btns2.vue";
  4. import ConfigEdit from "./modules/config-edit.vue";
  5. import { PureTable } from "@pureadmin/table";
  6. import { reactive, ref } from "vue";
  7. import { configTypeOptions } from "@/constants/constants";
  8. import * as $configApi from "@/api/sys/config";
  9. import { onMounted } from "vue";
  10. import { hasAuth } from "@/router/utils";
  11. import message from "@/utils/message";
  12. const configEditRef = ref();
  13. const pageData: any = reactive({
  14. permission: {
  15. query: ["sys:config:query"],
  16. save: ["sys:config:save"],
  17. update: ["sys:config:update"],
  18. del: ["sys:config:del"],
  19. refreshCache: ["sys:config:refresh"]
  20. },
  21. searchParam: {
  22. searchState: true,
  23. searchForm: {},
  24. formFields: [
  25. {
  26. type: "select",
  27. label: "配置类型",
  28. prop: "type",
  29. placeholder: "请选择配置类型",
  30. dataSourceKey: "configTypeOptions",
  31. options: {
  32. clearable: true,
  33. filterable: true,
  34. keys: {
  35. prop: "value",
  36. value: "value",
  37. label: "label"
  38. }
  39. }
  40. },
  41. {
  42. type: "input",
  43. label: "配置项",
  44. prop: "code",
  45. placeholder: "请输入配置项",
  46. options: {
  47. clearable: true
  48. }
  49. }
  50. ]
  51. },
  52. dataSource: {
  53. configTypeOptions: configTypeOptions
  54. },
  55. btnOpts: {
  56. size: "small",
  57. left: [
  58. {
  59. key: "add",
  60. label: "新增",
  61. type: "primary",
  62. icon: "ep:plus",
  63. state: true,
  64. permission: ["sys:config:save"]
  65. }
  66. // {
  67. // key: "update",
  68. // label: "修改",
  69. // type: "success",
  70. // icon: "ep:edit",
  71. // state: false,
  72. // permission: ["sys:config:update"]
  73. // }
  74. ],
  75. right: [
  76. {
  77. key: "search",
  78. label: "查询",
  79. icon: "ep:search",
  80. state: true,
  81. options: {
  82. circle: true
  83. }
  84. },
  85. {
  86. key: "refresh",
  87. label: "刷新",
  88. icon: "ep:refresh",
  89. state: true,
  90. options: {
  91. circle: true
  92. }
  93. }
  94. ]
  95. },
  96. tableParam: {
  97. columns: [
  98. {
  99. label: "配置类型",
  100. prop: "typeName"
  101. },
  102. {
  103. label: "配置项",
  104. prop: "code"
  105. },
  106. {
  107. label: "配置值",
  108. prop: "value"
  109. },
  110. {
  111. label: "备注",
  112. prop: "memo"
  113. },
  114. {
  115. label: "创建时间",
  116. prop: "createTime"
  117. },
  118. {
  119. label: "更新时间",
  120. prop: "updateTime"
  121. },
  122. {
  123. label: "操作",
  124. fixed: "right",
  125. slot: "operation"
  126. }
  127. ],
  128. list: [],
  129. loading: false,
  130. pagination: {
  131. pageSize: 10,
  132. defaultPageSize: 10,
  133. currentPage: 1,
  134. background: true,
  135. total: 0
  136. }
  137. }
  138. });
  139. const handleBtnClick = (val: string) => {
  140. switch (val) {
  141. case "add":
  142. configEditRef.value!.open({}, pageData.dataSource, "add");
  143. break;
  144. case "update":
  145. break;
  146. case "search":
  147. _updateSearchState();
  148. break;
  149. case "refresh":
  150. _loadData();
  151. break;
  152. }
  153. };
  154. /**
  155. * 更新搜索表单
  156. * @param data .
  157. */
  158. const _updateSearchFormData = (data: any) => {
  159. pageData.searchParam.searchForm = data;
  160. };
  161. /**
  162. * 点击搜索按钮
  163. */
  164. const _searchForm = (data: any) => {
  165. pageData.searchParam.searchForm = data;
  166. _loadData();
  167. };
  168. /**
  169. * 重置
  170. */
  171. const _resetSearchForm = (data?: any) => {
  172. pageData.searchParam.searchForm = data;
  173. };
  174. /**
  175. * 更新搜索表达的状态
  176. */
  177. const _updateSearchState = () => {
  178. pageData.searchParam.searchState = !pageData.searchParam.searchState;
  179. };
  180. const handleChangePageSize = (val: any) => {
  181. pageData.tableParam.pagination.pageSize = val;
  182. _loadData();
  183. };
  184. const handleChangeCurrentPage = (val: any) => {
  185. pageData.tableParam.pagination.currentPage = val;
  186. _loadData();
  187. };
  188. const getQueryParams = () => {
  189. const sqp = {};
  190. const param = Object.assign(sqp, pageData.searchParam.searchForm);
  191. param.current = pageData.tableParam.pagination.currentPage;
  192. param.size = pageData.tableParam.pagination.pageSize;
  193. return param;
  194. };
  195. /**
  196. * 查询数据
  197. */
  198. const _loadData = (page?: number) => {
  199. pageData.tableParam.loading = true;
  200. const query = getQueryParams();
  201. if (page) {
  202. query.current = page;
  203. }
  204. $configApi
  205. .queryPage(query)
  206. .then((res: any) => {
  207. if (res.success) {
  208. pageData.tableParam.list = res.result.records;
  209. pageData.tableParam.pagination.total = Number(res.result.total);
  210. }
  211. })
  212. .finally(() => {
  213. pageData.tableParam.loading = false;
  214. });
  215. };
  216. const handleEdit = (row: any) => {
  217. configEditRef.value!.open(row, pageData.dataSource, "update");
  218. };
  219. const handleDel = (row: any) => {
  220. message.confirm("是否删除当前数据").then(() => {
  221. _batchDel([row.id]);
  222. });
  223. };
  224. const _batchDel = (ids: string[]) => {
  225. pageData.tableParam.loading = true;
  226. $configApi
  227. .delByIds(ids)
  228. .then((res: any) => {
  229. if (res.success) {
  230. message.success("删除成功");
  231. _loadData();
  232. }
  233. })
  234. .finally(() => {
  235. pageData.tableParam.loading = false;
  236. });
  237. };
  238. const handleRefreshCache = (row: any) => {
  239. message
  240. .confirm("是否刷新缓存")
  241. .then(() => {
  242. _refreshCache(row.id);
  243. })
  244. .catch(() => {});
  245. };
  246. const _refreshCache = (id: string) => {
  247. pageData.tableParam.loading = true;
  248. $configApi
  249. .refreshCache(id)
  250. .then((res: any) => {
  251. if (res.success) {
  252. message.success("刷新成功");
  253. _loadData();
  254. }
  255. })
  256. .finally(() => {
  257. pageData.tableParam.loading = false;
  258. });
  259. };
  260. onMounted(() => {
  261. _loadData();
  262. });
  263. defineOptions({
  264. name: "SysConfig"
  265. });
  266. </script>
  267. <template>
  268. <div>
  269. <el-card :shadow="'never'">
  270. <template #default>
  271. <!--form search-->
  272. <FormSearch
  273. :show="pageData.searchParam.searchState"
  274. :size="'default'"
  275. :form-field="pageData.searchParam.formFields"
  276. :query-permission="pageData.permission.query"
  277. :data-source="pageData.dataSource"
  278. @search-form="_updateSearchFormData"
  279. @search="_searchForm"
  280. @reset="_resetSearchForm"
  281. />
  282. <table-buttons
  283. :size="pageData.btnOpts.size"
  284. :left-btns="pageData.btnOpts.left"
  285. :right-btns="pageData.btnOpts.right"
  286. @click="handleBtnClick"
  287. />
  288. <pure-table
  289. :columns="pageData.tableParam.columns"
  290. :data="pageData.tableParam.list"
  291. :border="true"
  292. :stripe="true"
  293. :loading="pageData.tableParam.loading"
  294. :pagination="pageData.tableParam.pagination"
  295. :header-row-class-name="'table-header'"
  296. @page-current-change="handleChangeCurrentPage"
  297. @page-size-change="handleChangePageSize"
  298. >
  299. <!---->
  300. <template #operation="{ row }">
  301. <el-link
  302. v-show="hasAuth(pageData.permission.update)"
  303. type="primary"
  304. @click="handleEdit(row)"
  305. >编辑</el-link
  306. >
  307. <el-divider
  308. direction="vertical"
  309. v-show="hasAuth(pageData.permission.refreshCache)"
  310. />
  311. <el-link
  312. v-show="hasAuth(pageData.permission.refreshCache)"
  313. type="primary"
  314. @click="handleRefreshCache(row)"
  315. >刷新缓存</el-link
  316. >
  317. <el-divider
  318. v-show="hasAuth(pageData.permission.del)"
  319. direction="vertical"
  320. />
  321. <el-link
  322. v-show="hasAuth(pageData.permission.del)"
  323. type="primary"
  324. @click="handleDel(row)"
  325. >删除</el-link
  326. >
  327. </template>
  328. </pure-table>
  329. </template>
  330. </el-card>
  331. <config-edit ref="configEditRef" @confirm="_loadData()" />
  332. </div>
  333. </template>