useData.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // 处理 区分处理管乐迷 管乐团的数据
  2. import { instrumentCode_gym, instrumentCode_gyt, instrumentCode_klx } from "@/api/cloudPractice.api"
  3. import { URL_TEACH_GYM, URL_TEACH_GYT, URL_TEACH_KLX } from "@/config"
  4. import { getToken } from "@/libs/auth"
  5. import { httpAjax } from "@/plugin/httpAjax"
  6. import userStore from "@/store/modules/user"
  7. import { ref } from "vue"
  8. /**
  9. * 搜索数据
  10. */
  11. export const useFunction = () => {
  12. const userStoreHook = userStore()
  13. const loading = ref(false)
  14. const instrumentCodes = ref<any>({}) // 乐器code
  15. /** 跳转云教练 */
  16. const isPracticeShow = ref(false)
  17. const practiceUrl = ref("")
  18. function goToCloud(musicId: string, partIndex = 0, track = "", musicRenderType = "") {
  19. // GYM,GYT,KLX 区分 云教练
  20. let gymUrl = `${URL_TEACH_GYM}#/?id=${musicId}&Authorization=${getToken()}&platform=pc&isYjt=1&isHideMusicList=true&systemType=teacher`
  21. let klxUrl = `${URL_TEACH_KLX}#/?id=${musicId}&Authorization=${getToken()}&platform=pc&isYjt=1&isHideMusicList=true&systemType=teacher&musicRenderType=${musicRenderType}`
  22. if (partIndex === 999) {
  23. gymUrl += `&part-index=${partIndex}`
  24. klxUrl += `&part-index=${partIndex}`
  25. } else {
  26. gymUrl += `&part-name=${track}`
  27. klxUrl += `&part-name=${track}`
  28. }
  29. const urlObj = {
  30. GYT: `${URL_TEACH_GYT}?id=${musicId}&modelType=practice&modeType=json&part-index=${partIndex}&Authorization=${getToken()}&isYjt=1&&isHideBack=false`,
  31. GYM: gymUrl,
  32. KLX: klxUrl
  33. }
  34. isPracticeShow.value = true
  35. practiceUrl.value = urlObj[userStoreHook.roles!]
  36. //window.open(urlObj[userStoreHook.roles!], "_blank")
  37. }
  38. function handlePracticeClose() {
  39. isPracticeShow.value = false
  40. practiceUrl.value = ""
  41. }
  42. function getPreViewCloud(musicId: string, partIndex = 0, track = "", musicRenderType = "") {
  43. // GYM,GYT,KLX 区分 云教练
  44. let gymUrl = `${URL_TEACH_GYM}?t=${Date.now()}#/?id=${musicId}&Authorization=${getToken()}&isPreView=true&zoom=1&downPng=A4&systemType=teacher`
  45. let klxUrl = `${URL_TEACH_KLX}?t=${Date.now()}#/?id=${musicId}&Authorization=${getToken()}&isPreView=true&zoom=1&downPng=A4&systemType=teacher&musicRenderType=${musicRenderType}`
  46. if (partIndex === 999) {
  47. gymUrl += `&part-index=${partIndex}`
  48. klxUrl += `&part-index=${partIndex}`
  49. } else {
  50. gymUrl += `&part-name=${track}`
  51. klxUrl += `&part-name=${track}`
  52. }
  53. const urlObj = {
  54. GYT: `${URL_TEACH_GYT}?id=${musicId}&modelType=practice&modeType=json&part-index=${partIndex}&Authorization=${getToken()}&isYjt=1&&isHideBack=false`,
  55. GYM: gymUrl,
  56. KLX: klxUrl
  57. }
  58. return urlObj[userStoreHook.roles!]
  59. }
  60. function formatInstrumentCodes(data: any[]) {
  61. if (Array.isArray(data)) {
  62. const tempCodes: any = {}
  63. data.forEach((item: any) => {
  64. const codes = item.code?.split(",")
  65. codes.forEach((code: any) => {
  66. tempCodes[code] = item.name
  67. })
  68. })
  69. return tempCodes
  70. } else {
  71. return {}
  72. }
  73. }
  74. /**
  75. * 获取乐器code
  76. */
  77. async function getInstrumentCodes() {
  78. // GYM,GYT,KLX 区分 查询接口
  79. const instrumentCodesApi = {
  80. GYT: instrumentCode_gyt,
  81. GYM: instrumentCode_gym,
  82. KLX: instrumentCode_klx
  83. }
  84. await httpAjax(instrumentCodesApi[userStoreHook.roles!], {}).then(res => {
  85. loading.value = false
  86. if (res.code === 200) {
  87. instrumentCodes.value = formatInstrumentCodes(res.data)
  88. }
  89. })
  90. }
  91. return { loading, goToCloud, getPreViewCloud, isPracticeShow, practiceUrl, handlePracticeClose, instrumentCodes, getInstrumentCodes }
  92. }
  93. // function chunkArray(array: any[], size: number) {
  94. // const result = []
  95. // for (let i = 0; i < array.length; i += size) {
  96. // result.push(array.slice(i, i + size))
  97. // }
  98. // return result
  99. // }