hook.tsx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import { reactive, onMounted, ref, ElMessage, ElMessageBox, http, getGroupUrl, RegularVerification, verification, PaginationProps } from "@/utils/importUsed"
  2. // 表单实例
  3. const ruleFormRef = ref()
  4. export function useFileUpdateInfo() {
  5. // 接口列表实例
  6. let UrlList = reactive(null)
  7. // 获取当前板块接口列表
  8. onMounted(async () => {
  9. UrlList = await getGroupUrl(["kxsConfigServer"]);
  10. onSearch(ruleFormRef.value);
  11. });
  12. let form = reactive({
  13. kind: "", //分类
  14. });
  15. const dataList = ref([]);
  16. const loading = ref(false);
  17. const dialogAddVisible = ref(false);
  18. const pagination = reactive<PaginationProps>({
  19. total: 0,
  20. pageSize: 10,
  21. currentPage: 1,
  22. background: true
  23. });
  24. const columns: TableColumnList = [
  25. {
  26. type: "selection",
  27. width: 55,
  28. align: "left",
  29. hide: ({ checkList }) => !checkList.includes("勾选列")
  30. },
  31. {
  32. label: "序号",
  33. type: "index",
  34. width: 70,
  35. hide: ({ checkList }) => !checkList.includes("序号列")
  36. },
  37. {
  38. label: "ID",
  39. prop: "id",
  40. minWidth: 200
  41. },
  42. {
  43. label: "更新版本",
  44. prop: "versionNum",
  45. minWidth: 200
  46. },
  47. {
  48. label: "路径",
  49. prop: "path",
  50. minWidth: 200
  51. },
  52. {
  53. label: "文件名",
  54. prop: "fileName",
  55. minWidth: 200
  56. },
  57. {
  58. label: "操作",
  59. fixed: "right",
  60. width: 200,
  61. slot: "operation"
  62. }
  63. ];
  64. // 当前页数量切换
  65. function handleSizeChange(val: number) {
  66. if (typeof val === "number") {
  67. pagination.pageSize = val;
  68. onSearch(ruleFormRef.value);
  69. }
  70. }
  71. // 当前页码切换
  72. function handleCurrentChange(val: number) {
  73. console.log(`current page: ${val}`);
  74. if (typeof val === "number") {
  75. pagination.currentPage = val;
  76. onSearch(ruleFormRef.value);
  77. }
  78. }
  79. // 选择表格项
  80. function handleSelectionChange(val) {
  81. console.log(`SelectionChange: ${val}`);
  82. onSearch(ruleFormRef.value);
  83. }
  84. // 搜索列表
  85. async function onSearch(formEl) {
  86. // 表单校验拦截
  87. if (!formEl) return
  88. await formEl.validate(async (valid, fields) => {
  89. if (valid) {
  90. //表单校验成功回调
  91. console.log('submit!')
  92. // 状态调整为加载中
  93. loading.value = true;
  94. // 调用接口(需动态生成接口)
  95. const { status, msg, data }: any = await http.Request({
  96. method: UrlList.kxsConfigServer.fileUpdateInfolist.method,
  97. url: UrlList.kxsConfigServer.fileUpdateInfolist.url,
  98. params: {
  99. ...form,
  100. pageSize: pagination.pageSize,
  101. pageNum: pagination.currentPage
  102. }
  103. });
  104. dataList.value = data.records;
  105. pagination.total = data.total;
  106. setTimeout(() => {
  107. loading.value = false;
  108. }, 500);
  109. } else {
  110. //表单校验失败回调
  111. ElMessage({
  112. message: "请输入完整信息",
  113. type: "error"
  114. });
  115. }
  116. })
  117. }
  118. // 删除
  119. function handleDelete(row) {
  120. ElMessageBox.confirm(
  121. `是否删除该资源文件更新信息? `,
  122. "提示",
  123. {
  124. confirmButtonText: "删除",
  125. cancelButtonText: "取消",
  126. type: "warning"
  127. }
  128. ).then(async () => {
  129. const { status, msg }: any = await http.Request({ method: UrlList.kxsConfigServer.fileUpdateInfodelete.method, url: UrlList.kxsConfigServer.fileUpdateInfodelete.url, params: String(row.id) });
  130. if (status === 1) {
  131. ElMessage({
  132. message: "删除成功",
  133. type: "success"
  134. });
  135. onSearch(ruleFormRef.value);
  136. } else {
  137. ElMessageBox.alert(msg, "提示", {
  138. confirmButtonText: "关闭",
  139. type: "warning"
  140. });
  141. };
  142. })
  143. }
  144. function handleSycn() {
  145. if (form.kind == "") {
  146. ElMessageBox.alert("请筛选分类", "提示", {
  147. confirmButtonText: "关闭",
  148. type: "warning"
  149. });
  150. return;
  151. }
  152. ElMessageBox.confirm(
  153. `是否同步资源文件? `,
  154. "提示",
  155. {
  156. confirmButtonText: "同步",
  157. cancelButtonText: "取消",
  158. type: "warning"
  159. }
  160. ).then(async () => {
  161. const { status, msg }: any = await http.Request({ method: UrlList.kxsConfigServer.fileUpdateInfoupdateFile.method, url: UrlList.kxsConfigServer.fileUpdateInfoupdateFile.url, params: { kind: form.kind } });
  162. if (status === 1) {
  163. ElMessage({
  164. message: "同步成功",
  165. type: "success"
  166. });
  167. onSearch(ruleFormRef.value);
  168. } else {
  169. ElMessageBox.alert(msg, "提示", {
  170. confirmButtonText: "关闭",
  171. type: "warning"
  172. });
  173. };
  174. })
  175. }
  176. // 新增
  177. const addVisible = ref(false);
  178. function handleAdd() {
  179. addVisible.value = true;
  180. };
  181. // 修改
  182. const editUpdateVisible = ref(false);
  183. const editUpdateFormData = ref({});
  184. function handleUpdate(row) {
  185. editUpdateVisible.value = true;
  186. // 表格数据赋值
  187. editUpdateFormData.value = row;
  188. };
  189. // 更新版本号
  190. const editUpVersionVisible = ref(false);
  191. const editUpVersionFormData = ref({});
  192. function handleUpVersion(row) {
  193. editUpVersionVisible.value = true;
  194. // 表格数据赋值
  195. editUpVersionFormData.value = row;
  196. };
  197. return {
  198. form,
  199. loading,
  200. columns,
  201. dataList,
  202. pagination,
  203. onSearch,
  204. handleSizeChange,
  205. handleCurrentChange,
  206. handleSelectionChange,
  207. ruleFormRef,
  208. handleAdd,
  209. addVisible,
  210. handleUpdate,
  211. editUpdateVisible,
  212. editUpdateFormData,
  213. handleDelete,
  214. handleUpVersion,
  215. handleSycn,
  216. editUpVersionVisible,
  217. editUpVersionFormData,
  218. };
  219. }