hook.tsx 6.5 KB

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