123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- // 处理 区分处理管乐迷 管乐团的数据
- import {
- queryLessonCourseware_gym,
- getLessonCoursewareCourseList_gym,
- getMyCourseware_gyt,
- getMyCoursewareDetail_gyt,
- getuyAlbumInfo_klx,
- queryLessonCourseware_klx,
- getLessonCoursewareCourseList_klx
- } from "@/api/cloudTextbooks.api"
- import { httpAjaxErrMsg, httpAjax } from "@/plugin/httpAjax"
- import { CODE_ERR_CANCELED } from "@/libs/auth"
- import { ElMessage } from "element-plus"
- import userStore from "@/store/modules/user"
- import { ref, shallowRef, computed } from "vue"
- type listType = {
- type: string
- name: string
- img: string
- id: string
- courseNum: number // 课程数量
- }[][]
- /**
- * 列表数据
- */
- export const useDataList = () => {
- const userStoreHook = userStore()
- const listData = shallowRef<listType>([])
- let storeData: listType[number] = []
- // 专辑
- const albumId = ref("")
- const albumOpt = shallowRef<{ value: string; label: string }[]>([])
- const loading = ref(false)
- let coursewareController: AbortController
- function handleGetList() {
- // GYM,GYT,KLX 区分 获取列表数据
- if (userStoreHook.roles === "GYM") {
- handleGetList_gym("", "")
- } else if (userStoreHook.roles === "GYT") {
- handleGetList_gyt()
- } else if (userStoreHook.roles === "KLX") {
- loading.value = true
- httpAjax(getuyAlbumInfo_klx).then(res => {
- loading.value = false
- if (res.code === 200) {
- // 专辑赋值
- albumOpt.value = (res.data || []).reduce((arr: any[], item: any) => {
- if (item.coursewareCounts > 0) {
- arr.push({
- value: item.id,
- label: item.name
- })
- }
- return arr
- }, [])
- // 默认取第一个专辑
- albumOpt.value.length && (albumId.value = albumOpt.value[0].value)
- handleGetList_klx("", albumId.value, "")
- }
- })
- }
- }
- function handleListQuery(type: string, queryStr: string) {
- // GYM,GYT,KLX 区分 查询列表数据
- if (userStoreHook.roles === "GYM") {
- handleQueryGetList_gym(type, queryStr)
- } else if (userStoreHook.roles === "GYT") {
- handleQueryGetList_gyt(type, queryStr)
- } else if (userStoreHook.roles === "KLX") {
- handleQueryGetList_klx(type, albumId.value, queryStr)
- }
- }
- // 获取管乐团数据
- function handleGetList_gyt() {
- loading.value = true
- httpAjaxErrMsg(getMyCourseware_gyt).then(res => {
- loading.value = false
- if (res.code === 200) {
- storeData = (res.data || []).map((item: any) => {
- return {
- name: item.name,
- type: item.courseTypeCode,
- img: item.coverImg,
- id: item.id,
- courseNum: item.courseNum
- }
- })
- listData.value = chunkArray(storeData, 5)
- }
- })
- }
- // 管乐团数据查询
- function handleQueryGetList_gyt(type: string, queryStr: string) {
- const computeData = storeData.filter(item => {
- return (type ? item.type === type : true) && (queryStr ? item.name.includes(queryStr) : true)
- })
- listData.value = chunkArray(computeData, 5)
- }
- // 获取管乐迷数据
- function handleGetList_gym(type: string, queryStr: string) {
- if (coursewareController) {
- coursewareController.abort()
- }
- coursewareController = new AbortController()
- loading.value = true
- httpAjax(queryLessonCourseware_gym, type, coursewareController).then(res => {
- // 自己关闭的时候不取消加载
- if (res.code === CODE_ERR_CANCELED) {
- return
- }
- loading.value = false
- if (res.code === 200) {
- const data = (res.data?.rows || []).reduce((arr: any[], item: any) => {
- if ((type ? item.subjectId === type : true) && (queryStr ? item.name.includes(queryStr) : true)) {
- arr.push({
- name: item.name,
- type: item.subjectId,
- img: item.cover,
- id: item.lessonCoursewareId,
- courseNum: item.courseNum
- })
- }
- return arr
- }, [])
- listData.value = chunkArray(data, 5)
- } else {
- if (res.code !== 511) {
- ElMessage({
- showClose: true,
- message: res.message,
- type: "error"
- })
- }
- }
- })
- }
- // 管乐迷数据查询
- function handleQueryGetList_gym(type: string, queryStr: string) {
- handleGetList_gym(type, queryStr)
- }
- // 获取酷乐秀数据
- function handleGetList_klx(type: string, albumId: string, queryStr: string) {
- // 当没有专辑id时候 不查询
- if (!albumId) {
- return
- }
- if (coursewareController) {
- coursewareController.abort()
- }
- coursewareController = new AbortController()
- loading.value = true
- httpAjax(queryLessonCourseware_klx, type, albumId, coursewareController).then(res => {
- // 自己关闭的时候不取消加载
- if (res.code === CODE_ERR_CANCELED) {
- return
- }
- loading.value = false
- if (res.code === 200) {
- const data = (res.data?.rows || []).reduce((arr: any[], item: any) => {
- if (queryStr ? item.musicSheetName.includes(queryStr) : true) {
- arr.push({
- name: item.musicSheetName,
- type: item.subjectId,
- img: item.titleImg,
- id: item.id,
- courseNum: item.courseNum
- })
- }
- return arr
- }, [])
- listData.value = chunkArray(data, 5)
- } else {
- if (res.code !== 511) {
- ElMessage({
- showClose: true,
- message: res.message,
- type: "error"
- })
- }
- }
- })
- }
- // 管乐迷数据查询
- function handleQueryGetList_klx(type: string, albumId: string, queryStr: string) {
- handleGetList_klx(type, albumId, queryStr)
- }
- return { loading, listData, albumId, albumOpt, handleGetList, handleListQuery }
- }
- /**
- * 列表详情数据
- */
- type listDetail = {
- name: string
- id: string
- useNum?: number
- lockFlag?: boolean
- }[]
- type listDetailType = [listDetail, listDetail]
- export const useDataDetailList = () => {
- const userStoreHook = userStore()
- let coursewareDetailController: AbortController
- const listData = shallowRef<listDetail[][]>([])
- const listSearchData = shallowRef<any[]>([])
- const flattenCoursewareList = ref<any[]>([]) // 扁平化coursewareList
- const activeCollapse = ref<any>({
- parentData: {
- ids: []
- }
- })
- const pageNum = ref<number>(0)
- const loading = ref(false)
- const searchLoading = ref(false)
- const listDetailData = computed<listDetailType>(() => {
- const data = listData.value[pageNum.value] || []
- return [data[0] || [], data[1] || []]
- })
- function handleGetDetailList(id: string, isSearch = false, search?: string) {
- // GYM,GYT,KLX 区分 查询详情列表
- if (userStoreHook.roles === "GYM") {
- handleGetDetaList_gym(id, isSearch, search)
- } else if (userStoreHook.roles === "GYT") {
- handleGetDetailList_gyt(id)
- } else if (userStoreHook.roles === "KLX") {
- handleGetDetailList_klx(id)
- }
- }
- function handlePage(type: "next" | "prev") {
- type === "next" ? pageNum.value++ : pageNum.value--
- }
- let flattenCoursewareListData: any[] = []
- // 获取管乐迷
- function handleGetDetaList_gym(id: string, isSearch = false, search?: string) {
- if (coursewareDetailController) {
- coursewareDetailController.abort()
- }
- coursewareDetailController = new AbortController()
- if (!isSearch) loading.value = true
- searchLoading.value = true
- httpAjax(getLessonCoursewareCourseList_gym, { id, search, abortController: coursewareDetailController }).then(res => {
- if (!isSearch) loading.value = false
- searchLoading.value = false
- if (res.code === 200) {
- const data = (res.data || []).map((item: any) => {
- return {
- name: item.coursewareDetailName,
- id: item.coursewareDetailId
- }
- })
- if (!isSearch) {
- listData.value = chunkArray(chunkArray(data, 7), 2)
- }
- const resultList = res.data || []
- resultList.forEach((item: any) => {
- item.children = item.knowledgePointList || []
- item.id = item.coursewareDetailId
- item.name = item.coursewareDetailName
- })
- flattenCoursewareListData = []
- listSearchData.value = filterPointList(resultList)
- flattenCoursewareList.value = flattenCoursewareListData
- if (flattenCoursewareList.value[0]) {
- activeCollapse.value = flattenCoursewareList.value[0]
- }
- }
- })
- }
- // 获取管乐团
- function handleGetDetailList_gyt(id: string) {
- loading.value = true
- httpAjaxErrMsg(getMyCoursewareDetail_gyt, id).then(res => {
- loading.value = false
- if (res.code === 200) {
- const data = (res.data || []).map((item: any) => {
- return {
- name: item.coursewareDetailName,
- id: item.lessonCoursewareDetailId,
- useNum: item.useNum,
- lockFlag: false // 云课堂默认不锁
- }
- })
- listData.value = chunkArray(chunkArray(data, 7), 2)
- }
- })
- }
- // 获取酷乐秀
- function handleGetDetailList_klx(id: string) {
- loading.value = true
- httpAjaxErrMsg(getLessonCoursewareCourseList_klx, id).then(res => {
- loading.value = false
- if (res.code === 200) {
- const data = (res.data || []).map((item: any) => {
- return {
- name: item.coursewareDetailName,
- id: item.coursewareDetailId
- }
- })
- listData.value = chunkArray(chunkArray(data, 7), 2)
- }
- })
- }
- function filterPointList(pointList: any[], parentData?: { ids: string[]; name: string }): any[] {
- // 设置父级及以上id数组和父级name
- return pointList.map(point => {
- if (point.children) {
- return Object.assign(point, {
- children: filterPointList(point.children, { ids: [...(parentData?.ids || []), point.id], name: point.name })
- })
- } else {
- return Object.assign(point, {
- materialList: point.materialList.map((item: any) => {
- item.parentData = {
- ids: [...(parentData?.ids || []), point.id],
- name: point.name
- }
- flattenCoursewareListData.push(item)
- return item
- })
- })
- }
- })
- }
- return {
- handleGetDetailList,
- loading,
- listDetailData,
- searchLoading,
- listSearchData,
- activeCollapse,
- listData,
- pageNum,
- handlePage
- }
- }
- function chunkArray(array: any[], size: number) {
- const result = []
- for (let i = 0; i < array.length; i += size) {
- result.push(array.slice(i, i + size))
- }
- return result
- }
|