hook.tsx 6.4 KB

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