useData.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // 处理 区分处理管乐迷 管乐团的数据
  2. import { queryTree_gym } from "@/api/cloudPractice.api"
  3. import { httpAjaxErrMsg, httpAjax } from "@/plugin/httpAjax"
  4. // import { CODE_ERR_CANCELED } from "@/libs/auth"
  5. // import { ElMessage } from "element-plus"
  6. import userStore from "@/store/modules/user"
  7. import { ref, shallowRef } from "vue"
  8. /**
  9. * 搜索数据
  10. */
  11. export const useDataSearchObj = () => {
  12. const userStoreHook = userStore()
  13. const loading = ref(false)
  14. // let coursewareController: AbortController
  15. const storeData = shallowRef<any[]>([])
  16. async function handleSearchList_gym() {
  17. loading.value = true
  18. await httpAjaxErrMsg(queryTree_gym).then(res => {
  19. loading.value = false
  20. if (res.code === 200) {
  21. storeData.value = res.data || []
  22. }
  23. })
  24. }
  25. function handleGetSearchList() {
  26. userStoreHook.roles === "GYM" ? handleSearchList_gym() : () => {}
  27. }
  28. return { loading, storeData, handleGetSearchList }
  29. }
  30. // type listType = {
  31. // type: string
  32. // name: string
  33. // img: string
  34. // id: string
  35. // courseNum: number // 课程数量
  36. // }[][]
  37. /**
  38. * 列表数据
  39. */
  40. // export const useDataList = () => {
  41. // const userStoreHook = userStore()
  42. // const listData = shallowRef<listType>([])
  43. // let storeData: listType[number] = []
  44. // const loading = ref(false)
  45. // let coursewareController: AbortController
  46. // function handleGetList() {
  47. // userStoreHook.roles === "GYM" ? handleGetList_gym("", "") : handleGetList_gyt()
  48. // }
  49. // function handleListQuery(type: string, queryStr: string) {
  50. // userStoreHook.roles === "GYM" ? handleQueryGetList_gym(type, queryStr) : handleQueryGetList_gyt(type, queryStr)
  51. // }
  52. // // 获取管乐团数据
  53. // function handleGetList_gyt() {
  54. // loading.value = true
  55. // httpAjaxErrMsg(getMyCourseware_gyt).then(res => {
  56. // loading.value = false
  57. // if (res.code === 200) {
  58. // storeData = (res.data || []).map((item: any) => {
  59. // return {
  60. // name: item.name,
  61. // type: item.courseTypeCode,
  62. // img: item.coverImg,
  63. // id: item.id,
  64. // courseNum: item.courseNum
  65. // }
  66. // })
  67. // listData.value = chunkArray(storeData, 5)
  68. // }
  69. // })
  70. // }
  71. // // 管乐团数据查询
  72. // function handleQueryGetList_gyt(type: string, queryStr: string) {
  73. // const computeData = storeData.filter(item => {
  74. // return (type ? item.type === type : true) && (queryStr ? item.name.includes(queryStr) : true)
  75. // })
  76. // listData.value = chunkArray(computeData, 5)
  77. // }
  78. // // 获取管乐迷数据
  79. // function handleGetList_gym(type: string, queryStr: string) {
  80. // if (coursewareController) {
  81. // coursewareController.abort()
  82. // }
  83. // coursewareController = new AbortController()
  84. // loading.value = true
  85. // httpAjax(queryLessonCourseware_gym, type, coursewareController).then(res => {
  86. // // 自己关闭的时候不取消加载
  87. // if (res.code === CODE_ERR_CANCELED) {
  88. // return
  89. // }
  90. // loading.value = false
  91. // if (res.code === 200) {
  92. // const data = (res.data?.rows || []).reduce((arr: any[], item: any) => {
  93. // if ((type ? item.subjectId === type : true) && (queryStr ? item.name.includes(queryStr) : true)) {
  94. // arr.push({
  95. // name: item.name,
  96. // type: item.subjectId,
  97. // img: item.cover,
  98. // id: item.lessonCoursewareId,
  99. // courseNum: item.courseNum
  100. // })
  101. // }
  102. // return arr
  103. // }, [])
  104. // listData.value = chunkArray(data, 5)
  105. // } else {
  106. // if (res.code !== 511) {
  107. // ElMessage({
  108. // showClose: true,
  109. // message: res.message,
  110. // type: "error"
  111. // })
  112. // }
  113. // }
  114. // })
  115. // }
  116. // // 管乐迷数据查询
  117. // function handleQueryGetList_gym(type: string, queryStr: string) {
  118. // handleGetList_gym(type, queryStr)
  119. // }
  120. // return { loading, listData, handleGetList, handleListQuery }
  121. // }
  122. function chunkArray(array: any[], size: number) {
  123. const result = []
  124. for (let i = 0; i < array.length; i += size) {
  125. result.push(array.slice(i, i + size))
  126. }
  127. return result
  128. }