cloudPractice.tsx 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. import { computed, defineComponent, nextTick, onMounted, reactive, ref, shallowRef } from "vue"
  2. import styles from "./index.module.scss"
  3. import NavContainer from "@/businessComponents/navContainer"
  4. import { ElEmpty, ElScrollbar } from "element-plus"
  5. import Dictionary from "@/components/dictionary"
  6. import MyInput from "@/components/myInput"
  7. import { NImage, NPopselect, NSpin } from "naive-ui"
  8. // import PlayLoading from "./component/play-loading"
  9. import PlayItem from "./component/play-item"
  10. import icon_default from "../../img/cloudPractice/icon_default.png"
  11. import iconBtnPause from "../../img/cloudPractice/icon-btn-pause.png"
  12. import iconBtnPlay from "../../img/cloudPractice/icon-btn-play.png"
  13. import btnSubmit from "../../img/cloudPractice/btn-submit.png"
  14. import iconTransfer from "../../img/cloudPractice/icon-transfer.png"
  15. import { httpAjaxErrMsg } from "@/plugin/httpAjax"
  16. import {
  17. queryPage2_gym,
  18. queryPage2_gyt,
  19. queryPage2_klx,
  20. querySubjectIds_gym,
  21. querySubjectIds_gyt,
  22. querySubjectIds_klx,
  23. queryTree_gym,
  24. queryTree_gyt,
  25. queryTree_klx,
  26. selectCondition_klx
  27. } from "@/api/cloudPractice.api"
  28. // import { getToken } from "@/libs/auth"
  29. // import { URL_TEACH_GYM } from "@/config"
  30. import axios from "axios"
  31. import { getInstrumentName } from "@/libs/instruments"
  32. import { formatXML, getCustomInfo, onlyVisible } from "./instrument"
  33. import { useFunction } from "./useData"
  34. import userStore from "@/store/modules/user"
  35. export default defineComponent({
  36. name: "cloudPractice",
  37. setup() {
  38. const userStoreHook = userStore()
  39. const { goToCloud } = useFunction()
  40. const navs = [
  41. {
  42. name: "主页",
  43. url: "/"
  44. },
  45. {
  46. name: "云练习"
  47. }
  48. ]
  49. const spinRef = ref()
  50. const state = reactive({
  51. finshed: false,
  52. reshing: false,
  53. page: 1,
  54. rows: 20,
  55. iframeSrc: "",
  56. listActive: 0, // 当前选中的对象
  57. firstTreeId: null as any, // 左侧
  58. categoryId: null as any, // 类型
  59. categoryName: "" as any, // 类型名称
  60. categoryList: [] as any[],
  61. levelList: [] as any[], // 级别
  62. levelId: null as any,
  63. typeList: [] as any[], // 类型
  64. typeId: -1 as any,
  65. subjectList: [] as any[], // 声部列表
  66. subjectId: -1 as any,
  67. list: [] as any[],
  68. searchStatus: false,
  69. queryStr: "", // 搜索条件
  70. partList: [] as any[],
  71. partNames: [] as any[],
  72. selectedPartName: "" as any,
  73. selectedPartIndex: 0,
  74. partXmlIndex: 0,
  75. playState: "pause" as "play" | "pause", // 播放状态
  76. showPlayer: false // 是否显示播放器
  77. })
  78. const partColumns = ref<any>([])
  79. /** 选中的item */
  80. const activeItem = computed(() => {
  81. const list = state.list[state.listActive] || {}
  82. let tempList: any = {}
  83. if (userStoreHook.roles === "GYM") {
  84. const item = list.background?.[0]
  85. const audioFileUrl = item?.musicSheetType === "CONCERT" ? item?.metronomeUrl : item?.metronomeMp3Url || item?.mp3Url
  86. tempList = {
  87. id: item?.id,
  88. name: item?.examSongName,
  89. background: list?.background,
  90. xmlUrl: item?.xmlUrl,
  91. musicSheetType: item?.musicSheetType,
  92. audioFileUrl,
  93. isComberRender: false
  94. }
  95. } else if (userStoreHook.roles === "GYT") {
  96. tempList = {
  97. id: list?.id,
  98. name: list?.musicSheetName,
  99. background: list?.background,
  100. xmlUrl: list?.xmlFileUrl,
  101. musicSheetType: list?.musicSheetType,
  102. audioFileUrl: list?.audioFileUrl,
  103. isComberRender: list?.musicSubject === "1"
  104. }
  105. } else if (userStoreHook.roles === "KLX") {
  106. const item: any = list.background?.[0]
  107. tempList = {
  108. id: list?.id,
  109. name: list?.musicSheetName,
  110. background: list?.background,
  111. xmlUrl: list?.xmlFileUrl,
  112. musicSheetType: list?.musicSheetType,
  113. audioFileUrl: item?.audioFileUrl,
  114. isComberRender: false
  115. }
  116. }
  117. return tempList
  118. })
  119. const songPrevNextStatus = computed(() => {
  120. let prev = true,
  121. next = true
  122. if (state.listActive === 0) {
  123. prev = false
  124. }
  125. if (state.listActive >= state.list.length - 1) {
  126. next = false
  127. }
  128. return {
  129. prev,
  130. next
  131. }
  132. })
  133. const loading = ref(false)
  134. const staffLoading = ref(false)
  135. const storeData = shallowRef<any[]>([])
  136. const handleSearchList_gym = async () => {
  137. loading.value = true
  138. await httpAjaxErrMsg(queryTree_gym).then(res => {
  139. loading.value = false
  140. if (res.code === 200) {
  141. storeData.value = res.data || []
  142. setDefaultData()
  143. }
  144. })
  145. }
  146. const handleGetSubject_gym = async () => {
  147. loading.value = true
  148. // , { categoriesId: state.categoryId || state.firstTreeId }
  149. await httpAjaxErrMsg(querySubjectIds_gym).then(res => {
  150. loading.value = false
  151. if (res.code === 200) {
  152. const result = res.data || []
  153. state.subjectList = result.map((item: any) => {
  154. return {
  155. label: item.name,
  156. value: item.id
  157. }
  158. })
  159. state.subjectList.unshift({
  160. label: "全部声部",
  161. value: -1
  162. })
  163. const userSubjectId = userStoreHook.userInfo.subjectId
  164. if (userSubjectId) {
  165. const tempSubjectId = userSubjectId.split(",")[0]
  166. state.subjectList.forEach((item: any) => {
  167. // 判断是否存在声部编号
  168. if (item.value === Number(tempSubjectId)) {
  169. state.subjectId = Number(tempSubjectId)
  170. }
  171. })
  172. }
  173. }
  174. })
  175. }
  176. const handleGetList_gym = async () => {
  177. loading.value = true
  178. const params = {
  179. page: state.page,
  180. rows: state.rows,
  181. subjectId: state.subjectId === -1 ? null : state.subjectId,
  182. categoriesId: state.typeId === -1 ? state.levelId : state.typeId,
  183. search: state.queryStr
  184. }
  185. await httpAjaxErrMsg(queryPage2_gym, params).then(res => {
  186. loading.value = false
  187. if (res.code === 200) {
  188. const result = res.data || []
  189. if (state.reshing) {
  190. state.list = []
  191. state.reshing = false
  192. }
  193. if (Array.isArray(result.rows)) {
  194. state.list = [...state.list, ...result.rows]
  195. state.finshed = state.page >= result.totalPage
  196. } else {
  197. state.finshed = true
  198. }
  199. }
  200. })
  201. }
  202. /** 管乐团数据查询 */
  203. const handleSearchList_gyt = async () => {
  204. loading.value = true
  205. await httpAjaxErrMsg(queryTree_gyt, {
  206. enable: true,
  207. page: 1,
  208. parentId: 0,
  209. rows: 10
  210. }).then(res => {
  211. loading.value = false
  212. if (res.code === 200) {
  213. storeData.value = res.data || []
  214. setDefaultData()
  215. }
  216. })
  217. }
  218. const handleGetSubject_gyt = async () => {
  219. loading.value = true
  220. await httpAjaxErrMsg(querySubjectIds_gyt, {
  221. enableFlag: true,
  222. page: 1,
  223. rows: 100
  224. }).then(res => {
  225. loading.value = false
  226. if (res.code === 200) {
  227. const result = res.data || []
  228. state.subjectList = result.map((item: any) => {
  229. return {
  230. label: item.name,
  231. value: item.id
  232. }
  233. })
  234. state.subjectList.unshift({
  235. label: "全部声部",
  236. value: -1
  237. })
  238. const userSubjectId = userStoreHook.userInfo.subjectId
  239. if (userSubjectId) {
  240. const tempSubjectId = userSubjectId.split(",")[0]
  241. state.subjectList.forEach((item: any) => {
  242. // 判断是否存在声部编号
  243. if (item.value === Number(tempSubjectId)) {
  244. state.subjectId = Number(tempSubjectId)
  245. }
  246. })
  247. }
  248. }
  249. })
  250. }
  251. const handleGetList_gyt = async () => {
  252. loading.value = true
  253. const params = {
  254. page: state.page,
  255. rows: state.rows,
  256. musicSubject: state.subjectId === -1 ? null : state.subjectId,
  257. musicSheetCategoriesId: state.typeId === -1 ? state.levelId : state.typeId,
  258. keyword: state.queryStr,
  259. detailFlag: true,
  260. status: 1
  261. }
  262. await httpAjaxErrMsg(queryPage2_gyt, params).then(res => {
  263. loading.value = false
  264. if (res.code === 200) {
  265. const result = res.data || {}
  266. if (state.reshing) {
  267. state.list = []
  268. state.reshing = false
  269. }
  270. if (Array.isArray(result.rows)) {
  271. result.rows.forEach((item: any) => {
  272. item.name = item.musicSheetName
  273. })
  274. state.list = [...state.list, ...result.rows]
  275. state.finshed = state.page >= result.pages
  276. } else {
  277. state.finshed = true
  278. }
  279. }
  280. })
  281. }
  282. /** 酷乐秀机构数据查询 */
  283. const handleSearchList_klx = async () => {
  284. loading.value = true
  285. await httpAjaxErrMsg(queryTree_klx, {
  286. enable: true,
  287. page: 1,
  288. parentId: 0,
  289. rows: 10
  290. })
  291. .then(res => {
  292. loading.value = false
  293. if (res.code === 200) {
  294. const result = res.data || []
  295. const tempList: any = []
  296. result.forEach((item: any) => {
  297. if (item.musicNum > 0) {
  298. const subjectCounts = item.subjectCounts ? true : false
  299. const musicCounts = item.musicCounts ? true : false
  300. const ensembleCounts = item.ensembleCounts ? true : false
  301. const list: any = []
  302. if (subjectCounts) {
  303. list.push({
  304. label: "基础云练",
  305. value: "SUBJECT"
  306. })
  307. }
  308. if (musicCounts) {
  309. list.push({
  310. label: "独奏云练",
  311. value: "MUSIC"
  312. })
  313. }
  314. if (ensembleCounts) {
  315. list.push({
  316. label: "合奏云练",
  317. value: "ENSEMBLE"
  318. })
  319. }
  320. tempList.push({
  321. value: item.id,
  322. label: item.name,
  323. musicSheetCategoriesList: list
  324. })
  325. }
  326. })
  327. state.categoryList = tempList
  328. setDefaultData()
  329. }
  330. })
  331. .catch(() => {
  332. state.finshed = true
  333. })
  334. }
  335. const handleGetSubject_klx = async () => {
  336. loading.value = true
  337. await httpAjaxErrMsg(querySubjectIds_klx, {
  338. queryType: "list",
  339. page: 1,
  340. rows: 100
  341. }).then(res => {
  342. loading.value = false
  343. if (res.code === 200) {
  344. const result = res.data?.rows || []
  345. state.subjectList = result.map((item: any) => {
  346. return {
  347. label: item.name,
  348. value: item.id
  349. }
  350. })
  351. state.subjectList.unshift({
  352. label: "全部声部",
  353. value: -1
  354. })
  355. const userSubjectId = userStoreHook.userInfo.subjectId
  356. if (userSubjectId) {
  357. const tempSubjectId = userSubjectId.split(",")[0]
  358. state.subjectList.forEach((item: any) => {
  359. // 判断是否存在声部编号
  360. if (item.value === Number(tempSubjectId)) {
  361. state.subjectId = Number(tempSubjectId)
  362. }
  363. })
  364. }
  365. }
  366. })
  367. }
  368. const handleGetList_klx = async () => {
  369. if (!state.categoryId) return
  370. loading.value = true
  371. const params = {
  372. page: state.page,
  373. rows: state.rows,
  374. albumId: state.categoryId,
  375. subjectId: state.subjectId === -1 ? null : state.subjectId,
  376. subjectType: state.firstTreeId,
  377. level: state.levelId === -1 ? null : state.levelId,
  378. type: state.typeId === -1 ? null : state.typeId,
  379. keyword: state.queryStr
  380. }
  381. await httpAjaxErrMsg(queryPage2_klx, params).then(res => {
  382. loading.value = false
  383. if (res.code === 200) {
  384. const result = res.data || {}
  385. if (state.reshing) {
  386. state.list = []
  387. state.reshing = false
  388. }
  389. if (Array.isArray(result.rows)) {
  390. result.rows.forEach((item: any) => {
  391. item.name = item.musicSheetName
  392. })
  393. state.list = [...state.list, ...result.rows]
  394. state.finshed = state.page >= result.totalPage
  395. } else {
  396. state.finshed = true
  397. }
  398. }
  399. })
  400. }
  401. const handleSelectCondition_klx = async () => {
  402. if (!state.categoryId || !state.firstTreeId) return
  403. loading.value = true
  404. const params = {
  405. tenantAlbumId: state.categoryId,
  406. subjectType: state.firstTreeId
  407. }
  408. await httpAjaxErrMsg(selectCondition_klx, params).then(res => {
  409. loading.value = false
  410. if (res.code === 200) {
  411. const result = res.data || {}
  412. if (result.levelList && result.levelList.length > 0) {
  413. state.levelList = result.levelList.map((item: any) => {
  414. return {
  415. label: item.value,
  416. value: item.id
  417. }
  418. })
  419. state.levelList.unshift({
  420. label: "全部级别",
  421. value: -1
  422. })
  423. state.levelId = -1
  424. }
  425. if (result.typeList && result.typeList.length > 0) {
  426. state.typeList = result.typeList.map((item: any) => {
  427. return {
  428. label: item.value,
  429. value: item.id
  430. }
  431. })
  432. state.typeList.unshift({
  433. label: "全部类型",
  434. value: -1
  435. })
  436. state.typeId = -1
  437. }
  438. }
  439. })
  440. }
  441. /** 条件查询 */
  442. const handleAllSearchList = async () => {
  443. // GYM,GYT,KLX 区分 查询搜索条件数据
  444. if (userStoreHook.roles === "GYM") {
  445. await handleSearchList_gym()
  446. } else if (userStoreHook.roles === "GYT") {
  447. await handleSearchList_gyt()
  448. } else if (userStoreHook.roles === "KLX") {
  449. await handleSearchList_klx()
  450. }
  451. }
  452. const handleAllGetSubject = async () => {
  453. // GYM,GYT,KLX 区分 查询声部数据
  454. if (userStoreHook.roles === "GYM") {
  455. await handleGetSubject_gym()
  456. } else if (userStoreHook.roles === "GYT") {
  457. await handleGetSubject_gyt()
  458. } else if (userStoreHook.roles === "KLX") {
  459. await handleGetSubject_klx()
  460. }
  461. }
  462. const handleAllGetList = async () => {
  463. // GYM,GYT,KLX 区分 查询声部数据·
  464. if (userStoreHook.roles === "GYM") {
  465. await handleGetList_gym()
  466. } else if (userStoreHook.roles === "GYT") {
  467. await handleGetList_gyt()
  468. } else if (userStoreHook.roles === "KLX") {
  469. await handleGetList_klx()
  470. }
  471. }
  472. /** 初始化数据 */
  473. const setDefaultData = async (type?: "first" | "category" | "level" | "type") => {
  474. if (userStoreHook.roles === "GYM") {
  475. initCategories_gym(type)
  476. } else if (userStoreHook.roles === "GYT") {
  477. initCategories_gyt(type)
  478. } else if (userStoreHook.roles === "KLX") {
  479. await initCategories_klx(type)
  480. }
  481. }
  482. const initCategories_gym = (type?: "first" | "category" | "level" | "type") => {
  483. if (storeData.value.length > 0 && !["category", "level", "type"].includes(type as any)) {
  484. let result: any = []
  485. if (type === "first" && state.firstTreeId) {
  486. result = storeData.value.find((item: any) => item.id === state.firstTreeId)?.sysMusicScoreCategoriesList || []
  487. } else {
  488. state.firstTreeId = storeData.value[0]?.id
  489. result = storeData.value[0]?.sysMusicScoreCategoriesList || []
  490. }
  491. state.categoryList = result.map((item: any) => {
  492. return {
  493. label: item.name,
  494. value: item.id,
  495. sysMusicScoreCategoriesList: item.sysMusicScoreCategoriesList || []
  496. }
  497. })
  498. }
  499. if (state.categoryList.length > 0 && !["level", "type"].includes(type as any)) {
  500. let result: any = []
  501. if (type === "category" && state.categoryId) {
  502. result = state.categoryList.find((item: any) => item.value === state.categoryId)?.sysMusicScoreCategoriesList || []
  503. } else {
  504. state.categoryId = state.categoryList[0]?.value
  505. state.categoryName = state.categoryList[0]?.label
  506. result = state.categoryList[0]?.sysMusicScoreCategoriesList || []
  507. }
  508. state.levelList = result.map((item: any) => {
  509. return {
  510. label: item.name,
  511. value: item.id,
  512. sysMusicScoreCategoriesList: item.sysMusicScoreCategoriesList || []
  513. }
  514. })
  515. }
  516. if (state.levelList.length > 0) {
  517. let result: any = []
  518. if (type === "level" && state.levelId) {
  519. result = state.levelList.find((item: any) => item.value === state.levelId)?.sysMusicScoreCategoriesList
  520. } else {
  521. state.levelId = state.levelList[0]?.value
  522. result = state.levelList[0]?.sysMusicScoreCategoriesList || []
  523. }
  524. state.typeList = result.map((item: any) => {
  525. return {
  526. label: item.name,
  527. value: item.id
  528. }
  529. })
  530. state.typeList.unshift({
  531. label: "全部",
  532. value: -1
  533. })
  534. }
  535. }
  536. const initCategories_gyt = (type?: "first" | "category" | "level" | "type") => {
  537. if (storeData.value.length > 0 && !["level", "type"].includes(type as any)) {
  538. let result: any = []
  539. if (type === "first" && state.firstTreeId) {
  540. result = storeData.value.find((item: any) => item.id === state.firstTreeId)?.musicSheetCategoriesList || []
  541. } else {
  542. state.firstTreeId = storeData.value[0]?.id
  543. result = storeData.value[0]?.musicSheetCategoriesList || []
  544. }
  545. state.levelList = result.map((item: any) => {
  546. return {
  547. label: item.name,
  548. value: item.id,
  549. musicSheetCategoriesList: item.musicSheetCategoriesList || []
  550. }
  551. })
  552. }
  553. if (state.levelList.length > 0) {
  554. let result: any = []
  555. if (type === "level" && state.levelId) {
  556. result = state.levelList.find((item: any) => item.value === state.levelId)?.musicSheetCategoriesList
  557. } else {
  558. state.levelId = state.levelList[0]?.value
  559. result = state.levelList[0]?.musicSheetCategoriesList || []
  560. }
  561. state.typeList = result.map((item: any) => {
  562. return {
  563. label: item.name,
  564. value: item.id
  565. }
  566. })
  567. state.typeList.unshift({
  568. label: "全部",
  569. value: -1
  570. })
  571. }
  572. }
  573. const initCategories_klx = async (type?: "first" | "category" | "level" | "type") => {
  574. if (state.categoryList.length > 0 && !["level", "type", "first"].includes(type as any)) {
  575. let result: any = []
  576. if (type === "category" && state.categoryId) {
  577. result = state.categoryList.find((item: any) => item.value === state.categoryId)?.musicSheetCategoriesList || []
  578. } else {
  579. state.categoryId = state.categoryList[0]?.value
  580. state.categoryName = state.categoryList[0]?.label
  581. result = state.categoryList[0]?.musicSheetCategoriesList || []
  582. }
  583. storeData.value = result.map((item: any) => {
  584. return {
  585. id: item.value,
  586. name: item.label
  587. }
  588. })
  589. }
  590. if (storeData.value.length > 0 && !["level", "type"].includes(type as any)) {
  591. console.log(storeData.value.length, "storeData.value.length", type)
  592. if (type === "first" && state.firstTreeId) {
  593. await handleSelectCondition_klx()
  594. } else {
  595. //
  596. state.firstTreeId = storeData.value[0]?.id
  597. await handleSelectCondition_klx()
  598. }
  599. }
  600. }
  601. const __init = async () => {
  602. await handleAllSearchList()
  603. await handleAllGetSubject()
  604. await handleAllGetList()
  605. await toDetail()
  606. renderStaff()
  607. }
  608. __init()
  609. const handleResh = () => {
  610. if (loading.value || state.finshed) return
  611. state.page = state.page + 1
  612. handleAllGetList()
  613. }
  614. const handleGetList = async () => {
  615. state.listActive = 0
  616. state.showPlayer = false
  617. state.playState = "pause"
  618. document.querySelector(".musicList-container")?.scroll(0, 0)
  619. state.page = 1
  620. state.finshed = false
  621. state.reshing = true
  622. state.list = []
  623. await handleAllGetList()
  624. }
  625. const toDetail = async () => {
  626. const row: any = activeItem.value
  627. if (row.musicSheetType === "SINGLE") {
  628. loading.value = false
  629. return
  630. }
  631. console.log(row, "row")
  632. state.partNames = await getPartNames(row.xmlUrl)
  633. let partList = row.background || []
  634. partList = partList.filter((item: any) => !item.track?.toLocaleUpperCase()?.includes("COMMON"))
  635. partColumns.value = partList.map((item: any, index: number) => {
  636. const instrumentName = getInstrumentName(item.track)
  637. const xmlIndex = state.partNames.findIndex((name: any) => name === item.track)
  638. return {
  639. label: item.track + (instrumentName ? `(${instrumentName})` : ""),
  640. instrumentName: instrumentName,
  641. xmlIndex,
  642. value: index
  643. }
  644. })
  645. // 初始化数据
  646. const defaultShowStaff = partColumns.value[state.selectedPartIndex]
  647. console.log(defaultShowStaff, partList)
  648. state.selectedPartName = defaultShowStaff?.instrumentName
  649. state.partXmlIndex = defaultShowStaff?.xmlIndex
  650. console.log(partColumns.value, "partColumns partColumns")
  651. }
  652. const getPartNames = async (xmlUrl: string) => {
  653. const partNames: string[] = []
  654. try {
  655. const res: any = await axios.get(xmlUrl)
  656. const xml: any = new DOMParser().parseFromString(res, "text/xml")
  657. console.log(xml, "xmlxmlxmlxml")
  658. for (const item of xml.getElementsByTagName("part-name")) {
  659. if (item.textContent) {
  660. partNames.push(item.textContent)
  661. }
  662. }
  663. } catch (error) {
  664. //
  665. }
  666. return partNames.filter((text: string) => text.toLocaleUpperCase() !== "COMMON") || []
  667. }
  668. // const musicIframeLoad = async () => {
  669. // const iframeRef: any = document.getElementById("staffIframeRef")
  670. // if (iframeRef && iframeRef.contentWindow?.renderXml) {
  671. // staffLoading.value = true
  672. // const res = await axios.get(activeItem.value.xmlUrl)
  673. // const parseXmlInfo = getCustomInfo(res.data)
  674. // const xml = formatXML(parseXmlInfo.parsedXML)
  675. // const currentXml = onlyVisible(xml, state.selectedPartIndex)
  676. // iframeRef.contentWindow.renderXml(currentXml, state.selectedPartIndex)
  677. // }
  678. // }
  679. // const resetRender = async () => {
  680. // const iframeRef: any = document.getElementById("staffIframeRef")
  681. // if (iframeRef && iframeRef.contentWindow?.renderXml) {
  682. // staffLoading.value = true
  683. // const res = await axios.get(activeItem.value.xmlUrl)
  684. // const parseXmlInfo = getCustomInfo(res.data)
  685. // const xml = formatXML(parseXmlInfo.parsedXML)
  686. // const currentXml = onlyVisible(xml, state.selectedPartIndex)
  687. // iframeRef.contentWindow.renderXml(currentXml, state.selectedPartIndex)
  688. // }
  689. // }
  690. const musicIframeLoad = async () => {
  691. const iframeRef: any = document.getElementById("staffIframeRef")
  692. if (iframeRef && iframeRef.contentWindow.renderXml) {
  693. staffLoading.value = true
  694. const res: any = await axios.get(activeItem.value.xmlUrl)
  695. const parseXmlInfo = getCustomInfo(res.data)
  696. const xml = formatXML(parseXmlInfo.parsedXML)
  697. if (activeItem.value.isComberRender) {
  698. iframeRef.contentWindow.renderXml(xml, state.partXmlIndex, activeItem.value.isComberRender)
  699. } else {
  700. const currentXml = onlyVisible(xml, state.partXmlIndex)
  701. iframeRef.contentWindow.renderXml(currentXml, state.partXmlIndex, activeItem.value.isComberRender)
  702. }
  703. }
  704. }
  705. const resetRender = async () => {
  706. const iframeRef: any = document.getElementById("staffIframeRef")
  707. if (iframeRef && iframeRef.contentWindow.renderXml) {
  708. staffLoading.value = true
  709. loading.value = true
  710. const res: any = await axios.get(activeItem.value.xmlUrl)
  711. const parseXmlInfo = getCustomInfo(res.data)
  712. const xml = formatXML(parseXmlInfo.parsedXML)
  713. if (activeItem.value.isComberRender) {
  714. iframeRef.contentWindow.renderXml(xml, state.partXmlIndex, activeItem.value.isComberRender)
  715. } else {
  716. const currentXml = onlyVisible(xml, state.partXmlIndex)
  717. iframeRef.contentWindow.renderXml(currentXml, 0, activeItem.value.isComberRender)
  718. }
  719. }
  720. }
  721. const renderStaff = async () => {
  722. try {
  723. // ${location.origin}${location.pathname}
  724. state.iframeSrc = `/osmd/index.html`
  725. } catch (error) {
  726. //
  727. }
  728. }
  729. /** 音频控制 */
  730. const handleChangeAudio = (type: "play" | "pause" | "pre" | "next") => {
  731. if (type === "play") {
  732. state.playState = "play"
  733. } else if (type === "pause") {
  734. state.playState = "pause"
  735. } else if (type === "pre") {
  736. if (state.list[state.listActive - 1]) {
  737. handlePlay(state.list[state.listActive - 1])
  738. }
  739. } else if (type === "next") {
  740. if (state.list[state.listActive + 1]) {
  741. handlePlay(state.list[state.listActive + 1])
  742. }
  743. }
  744. }
  745. /** 播放曲目 */
  746. const handlePlay = (item: any) => {
  747. const index = state.list.findIndex((_item: any) => _item.id === item.id)
  748. if (index > -1) {
  749. if (state.listActive === index) {
  750. state.playState = state.playState === "play" ? "pause" : "play"
  751. } else {
  752. state.playState = "play"
  753. }
  754. state.showPlayer = true
  755. state.listActive = index
  756. }
  757. }
  758. const showLoading = async (e: any) => {
  759. if (e.data?.api === "musicStaffRender") {
  760. staffLoading.value = e.data.loading
  761. }
  762. }
  763. onMounted(() => {
  764. const obv = new IntersectionObserver(entries => {
  765. if (entries[0].intersectionRatio > 0) {
  766. handleResh()
  767. }
  768. })
  769. obv.observe(spinRef.value)
  770. window.addEventListener("message", showLoading)
  771. })
  772. return () => (
  773. <NavContainer navs={navs}>
  774. <ElScrollbar class="elScrollbar">
  775. <div class={styles.cloudPractice}>
  776. <div class={styles.leftContainer}>
  777. <div class={styles.details}>
  778. {storeData.value.length > 0 && (
  779. <ElScrollbar class={styles.leftSection}>
  780. {/* 基 础 云 练 */}
  781. {storeData.value.map((item: any) => (
  782. <div
  783. class={[styles.leftSection_item, item.id === state.firstTreeId && styles.leftSection_item__active]}
  784. onClick={async () => {
  785. state.firstTreeId = item.id
  786. await setDefaultData("first")
  787. handleGetList()
  788. }}
  789. >
  790. {item.name}
  791. </div>
  792. ))}
  793. </ElScrollbar>
  794. )}
  795. <div class={[styles.musicList, "musicList-container"]}>
  796. <div class={styles.searchHeader}>
  797. {state.categoryList.length > 1 && (
  798. <div class={[styles.categorySection]}>
  799. <NPopselect
  800. options={state.categoryList}
  801. v-model:value={state.categoryId}
  802. onUpdate:value={async (val: any) => {
  803. const item = state.categoryList.find((item: any) => item.value === val)
  804. if (item) {
  805. state.categoryName = item.label
  806. state.categoryId = item.value
  807. await setDefaultData("category")
  808. handleGetList()
  809. }
  810. }}
  811. trigger="click"
  812. class={"PopSelect"}
  813. >
  814. <span class={styles.iconTagName}>{state.categoryName}</span>
  815. </NPopselect>
  816. </div>
  817. )}
  818. <div class={styles.searchMore}>
  819. <div class={styles.searchSection}>
  820. <Dictionary
  821. popperClass="classTypePopper"
  822. v-model={state.subjectId}
  823. height={42}
  824. options={state.subjectList}
  825. placeholder="全部声部"
  826. onChange={handleGetList}
  827. />
  828. {state.levelList.length ? (
  829. <Dictionary
  830. popperClass="classTypePopper"
  831. v-model={state.levelId}
  832. height={42}
  833. options={state.levelList}
  834. placeholder="级别"
  835. onChange={() => {
  836. setDefaultData("level")
  837. handleGetList()
  838. }}
  839. />
  840. ) : null}
  841. {state.typeList.length > 0 ? (
  842. <Dictionary
  843. popperClass="classTypePopper"
  844. v-model={state.typeId}
  845. height={42}
  846. options={state.typeList}
  847. propsOpt={{
  848. labelField: "name",
  849. valueField: "id"
  850. }}
  851. placeholder="分类"
  852. onChange={handleGetList}
  853. />
  854. ) : null}
  855. </div>
  856. <div
  857. class={[styles.btnSearch, state.searchStatus && styles.btnSearchActive]}
  858. onClick={() => (state.searchStatus = !state.searchStatus)}
  859. ></div>
  860. </div>
  861. {state.searchStatus && (
  862. <MyInput
  863. class="queryCp"
  864. v-model={state.queryStr}
  865. height={42}
  866. placeholder="请输入曲目关键词"
  867. onKeyup={(e: any) => {
  868. if (e.code === "Enter" || e.key === "Enter") {
  869. handleGetList()
  870. }
  871. }}
  872. onHandleQuery={handleGetList}
  873. clearable
  874. />
  875. )}
  876. </div>
  877. <div class={[styles.wrapList, !state.list.length && !loading.value && styles.wrapListEmpty]}>
  878. {state.list.map((item: any, index: number) => (
  879. <div
  880. class={[styles.item, index === state.listActive && styles.active]}
  881. onClick={async () => {
  882. state.listActive = index
  883. await toDetail()
  884. resetRender()
  885. }}
  886. >
  887. <div class={styles.itemInfo}>
  888. <div class={styles.img}>
  889. <NImage
  890. lazy
  891. objectFit="cover"
  892. previewDisabled={true}
  893. src={icon_default}
  894. onLoad={(e: any) => {
  895. ;(e.target as any).dataset.loaded = "true"
  896. }}
  897. />
  898. {/* <PlayLoading
  899. class={[
  900. data.listActive === index &&
  901. data.playState === 'play'
  902. ? ''
  903. : styles.showPlayLoading
  904. ]}
  905. /> */}
  906. </div>
  907. <div class={styles.title}>
  908. <div class={styles.titleName}>
  909. <ellipsisScroll title={item.name} />
  910. </div>
  911. </div>
  912. </div>
  913. <div class={styles.btnSection}>
  914. <div
  915. class={styles.btn}
  916. onClick={(e: any) => {
  917. e.stopPropagation()
  918. handlePlay(item)
  919. if (state.listActive === index && state.playState === "play") {
  920. musicIframeLoad()
  921. }
  922. }}
  923. >
  924. {state.listActive === index && (
  925. <>
  926. {state.playState === "pause" ? "播放" : "暂停"}
  927. <img src={state.playState === "pause" ? iconBtnPlay : (iconBtnPause as any)} />
  928. </>
  929. )}
  930. {state.listActive !== index && (
  931. <>
  932. 播放
  933. <img src={iconBtnPlay as any} />
  934. </>
  935. )}
  936. </div>
  937. </div>
  938. </div>
  939. ))}
  940. {!state.list.length && !loading.value && (
  941. <ElEmpty class={styles.empty} image={require("@/img/layout/empty.png")} description="暂无结果" />
  942. )}
  943. <div ref={spinRef} class={[styles.loadingWrap, state.finshed && styles.showLoading]}>
  944. <NSpin show={true} stroke="#FF531C"></NSpin>
  945. </div>
  946. </div>
  947. </div>
  948. </div>
  949. </div>
  950. <div class={styles.rightContainer}>
  951. {/* <i class={styles.leftArrow}></i> */}
  952. <NSpin show={staffLoading.value} stroke="#FF531C">
  953. <div class={styles.musicName}>{activeItem.value.name}</div>
  954. <div class={[styles.staffImgs, !loading.value && !activeItem.value?.id && styles.staffImgsEmpty]}>
  955. {state.iframeSrc && activeItem.value?.id && (
  956. <iframe
  957. id="staffIframeRef"
  958. style={{
  959. // opacity: loading.value ? 0 : 1,
  960. width: "100%",
  961. height: "100%"
  962. }}
  963. src={state.iframeSrc}
  964. onLoad={musicIframeLoad}
  965. ></iframe>
  966. )}
  967. {!loading.value && !activeItem.value?.id && (
  968. <ElEmpty class={styles.empty} image={require("@/img/layout/empty.png")} description="暂无结果" />
  969. )}
  970. </div>
  971. </NSpin>
  972. <img
  973. style={{
  974. display: activeItem.value?.id ? "" : "none"
  975. }}
  976. class={[styles.goBtn]}
  977. src={btnSubmit as any}
  978. onClick={() => goToCloud(activeItem.value.id)}
  979. />
  980. <div
  981. class={styles.rightBtns}
  982. style={{ display: activeItem.value.id && activeItem.value.musicSheetType === "CONCERT" ? "" : "none" }}
  983. >
  984. <NPopselect
  985. options={partColumns.value}
  986. trigger="click"
  987. v-model:value={state.selectedPartIndex}
  988. scrollable
  989. onUpdate:value={async (value: any) => {
  990. console.log(value, "value")
  991. const item = partColumns.value.find((item: any) => item.value === value)
  992. state.selectedPartIndex = value
  993. state.selectedPartName = item.instrumentName
  994. state.partXmlIndex = item.xmlIndex
  995. nextTick(() => {
  996. resetRender()
  997. })
  998. }}
  999. class={"PopSelect"}
  1000. >
  1001. <img class={styles.transBtn} src={iconTransfer as any} />
  1002. </NPopselect>
  1003. </div>
  1004. </div>
  1005. </div>
  1006. </ElScrollbar>
  1007. {state.list.length !== 0 && activeItem.value.audioFileUrl && (
  1008. <PlayItem
  1009. show={state.showPlayer}
  1010. playState={state.playState}
  1011. songPrevNextStatus={songPrevNextStatus.value}
  1012. item={activeItem.value}
  1013. onChange={value => handleChangeAudio(value)}
  1014. onShow={(status: boolean) => {
  1015. state.showPlayer = status
  1016. }}
  1017. />
  1018. )}
  1019. </NavContainer>
  1020. )
  1021. }
  1022. })