hook.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import router from "@/router";
  2. import { reactive, onMounted, ref, ElMessage, ElMessageBox, http, getGroupUrl, RegularVerification, verification, PaginationProps } from "@/utils/importUsed"
  3. // 表单实例
  4. const ruleFormRef = ref()
  5. export function usePriProject() {
  6. // 接口列表实例
  7. let UrlList = reactive(null)
  8. // 获取当前板块接口列表
  9. onMounted(async () => {
  10. UrlList = await getGroupUrl(["prizeSet"]);
  11. onSearch(ruleFormRef.value);
  12. });
  13. let form = reactive({
  14. projectName: "", //项目名称
  15. requestMode: "", //调用方式
  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: "ID",
  41. prop: "id",
  42. minWidth: 200
  43. },
  44. {
  45. label: "项目名称",
  46. prop: "projectName",
  47. minWidth: 200
  48. },
  49. {
  50. label: "调用方式",
  51. prop: "requestMode",
  52. minWidth: 200
  53. },
  54. {
  55. label: "是否通知",
  56. prop: "noticeFlag",
  57. minWidth: 200
  58. },
  59. {
  60. label: "请求地址",
  61. prop: "requestUrl",
  62. minWidth: 200
  63. },
  64. {
  65. label: "返回数据类型",
  66. prop: "returnType",
  67. minWidth: 200
  68. },
  69. {
  70. label: "操作",
  71. fixed: "right",
  72. width: 200,
  73. slot: "operation"
  74. }
  75. ];
  76. // 当前页数量切换
  77. function handleSizeChange(val: number) {
  78. if (typeof val === "number") {
  79. pagination.pageSize = val;
  80. onSearch(ruleFormRef.value);
  81. }
  82. }
  83. // 当前页码切换
  84. function handleCurrentChange(val: number) {
  85. console.log(`current page: ${val}`);
  86. if (typeof val === "number") {
  87. pagination.currentPage = val;
  88. onSearch(ruleFormRef.value);
  89. }
  90. }
  91. // 选择表格项
  92. function handleSelectionChange(val) {
  93. console.log(`SelectionChange: ${val}`);
  94. onSearch(ruleFormRef.value);
  95. }
  96. // 搜索列表
  97. async function onSearch(formEl) {
  98. // 表单校验拦截
  99. if (!formEl) return
  100. await formEl.validate(async (valid, fields) => {
  101. if (valid) {
  102. //表单校验成功回调
  103. console.log('submit!')
  104. // 状态调整为加载中
  105. loading.value = true;
  106. // 调用接口(需动态生成接口)
  107. const { status, msg, data }: any = await http.Request({
  108. method: UrlList.prizeSet.prigetPriProjectList.method,
  109. url: UrlList.prizeSet.prigetPriProjectList.url,
  110. params: {
  111. ...form,
  112. pageSize: pagination.pageSize,
  113. pageNum: pagination.currentPage
  114. }
  115. });
  116. dataList.value = data.records;
  117. pagination.total = data.total;
  118. setTimeout(() => {
  119. loading.value = false;
  120. }, 500);
  121. } else {
  122. //表单校验失败回调
  123. ElMessage({
  124. message: "请输入完整信息",
  125. type: "error"
  126. });
  127. }
  128. })
  129. }
  130. function test(row) {
  131. router.push({ path: '../../api/apiGroup/index', query: { id: row.id } });
  132. }
  133. // 删除
  134. function handleDelete(row) {
  135. ElMessageBox.confirm(
  136. `是否删除该奖励项目? `,
  137. "提示",
  138. {
  139. confirmButtonText: "删除",
  140. cancelButtonText: "取消",
  141. type: "warning"
  142. }
  143. ).then(async () => {
  144. const { status, msg }: any = await http.Request({ method: UrlList.prizeSet.prideletePriProject.method, url: UrlList.prizeSet.prideletePriProject.url, params: String(row.id) });
  145. if (status === 1) {
  146. ElMessage({
  147. message: "删除成功",
  148. type: "success"
  149. });
  150. onSearch(ruleFormRef.value);
  151. } else {
  152. ElMessageBox.alert(msg, "提示", {
  153. confirmButtonText: "关闭",
  154. type: "warning"
  155. });
  156. };
  157. })
  158. }
  159. // 新增
  160. const addVisible = ref(false);
  161. function handleAdd() {
  162. addVisible.value = true;
  163. };
  164. // 修改
  165. const editUpdatePriProjectVisible = ref(false);
  166. const editUpdatePriProjectFormData = ref({});
  167. function handleUpdatePriProject(row) {
  168. editUpdatePriProjectVisible.value = true;
  169. // 表格数据赋值
  170. editUpdatePriProjectFormData.value = row;
  171. };
  172. return {
  173. form,
  174. loading,
  175. columns,
  176. dataList,
  177. pagination,
  178. onSearch,
  179. handleSizeChange,
  180. handleCurrentChange,
  181. handleSelectionChange,
  182. ruleFormRef,
  183. handleAdd,
  184. addVisible,
  185. handleUpdatePriProject,
  186. editUpdatePriProjectVisible,
  187. editUpdatePriProjectFormData,
  188. handleDelete,
  189. test,
  190. };
  191. }