new-index.tsx 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. import TheSticky from '@/components/the-sticky'
  2. import styles from './new-index.module.less'
  3. import { useEventListener, useThrottleFn, useWindowScroll } from '@vueuse/core'
  4. import { postMessage, promisefiyPostMessage } from '@/helpers/native-message'
  5. // import iconShare from '../../images/icon-share.png'
  6. import oStart from '../album-detail/icon-hart.png'
  7. import iStart from '../album-detail/icon-hart-active.png'
  8. import iconDownload from './images/icon-download.png'
  9. import iconMemberSmall from './images/icon-member-small.png'
  10. import {
  11. computed,
  12. defineComponent,
  13. nextTick,
  14. onMounted,
  15. onUnmounted,
  16. reactive,
  17. ref,
  18. toRaw,
  19. watch
  20. } from 'vue'
  21. import umiRequest from 'umi-request'
  22. import { useRoute, useRouter } from 'vue-router'
  23. import request from '@/helpers/request'
  24. import ColHeader from '@/components/col-header'
  25. import {
  26. Button,
  27. Cell,
  28. CellGroup,
  29. Dialog,
  30. Icon,
  31. Image,
  32. Popup,
  33. RadioGroup,
  34. Radio,
  35. Toast,
  36. Picker
  37. } from 'vant'
  38. import { useRect } from '@vant/use'
  39. import { Vue3Lottie } from 'vue3-lottie'
  40. import { getRandomKey, musicBuy } from '../music'
  41. import { getOssUploadUrl, state } from '@/state'
  42. import { browser, moneyFormat } from '@/helpers/utils'
  43. import { orderStatus } from '@/views/order-detail/orderStatus'
  44. import AstronautJSON from './animate/refresh_anim.json'
  45. // import ColShare from '@/components/col-share'
  46. import iconListen from './images/icon_listen.png'
  47. import iconTeacher from '@common/images/icon_teacher.png'
  48. import emtpy from './images/emtpy.png'
  49. import { state as baseState } from '@/state'
  50. import activeButtonIcon from './images/icon_checkbox.png'
  51. import inactiveButtonIcon from './images/icon_checkbox_default.png'
  52. import staffDetafult from './images/staff-default.png'
  53. import firstDefault from './images/first-default.png'
  54. import fixedDefault from './images/fixed-default.png'
  55. import Plyr from 'plyr'
  56. import 'plyr/dist/plyr.css'
  57. import Download from './download'
  58. import { getInstrumentName } from '@/constant/instruments'
  59. // import { getUploadSign, onOnlyFileUpload } from '@/helpers/oss-file-upload'
  60. import { svgtopng } from './formatSvgToImg'
  61. // import { shareCall } from '@/teacher/share-page/share'
  62. import deepClone from '@/helpers/deep-clone'
  63. import { formatXML, getCustomInfo, onlyVisible } from './instrument'
  64. import { data } from 'browserslist'
  65. export default defineComponent({
  66. name: 'new-index',
  67. setup() {
  68. localStorage.setItem('behaviorId', getRandomKey())
  69. const router = useRouter()
  70. const route = useRoute()
  71. const loading = ref(false)
  72. const background = ref<string>('rgba(55, 205, 177, 0)')
  73. const color = ref<string>('#fff')
  74. const aId = Number(route.query.activityId) || 0
  75. const studentActivityId = ref(aId)
  76. const isError = ref(false)
  77. const headers = ref(null)
  78. const footers = ref(null)
  79. const heightInfo = ref<any>('0')
  80. const musicDetail = ref<any>(null)
  81. const audioFileUrl = ref('')
  82. const showImg = ref([] as any)
  83. const firstList = ref<Array<any>>([])
  84. const fixedList = ref<Array<any>>([])
  85. const staffList = ref<Array<any>>([])
  86. const musicPdfUrl = ref('')
  87. const uploadImgs = ref<boolean>(false)
  88. const defaultImgs = ref({
  89. first: false,
  90. fixed: false,
  91. staff: false
  92. })
  93. const downloadStatus = ref<boolean>(false)
  94. const staff = reactive({
  95. status: false,
  96. radio: 'staff' // staff first fixed
  97. })
  98. const apiSuffix = ref(
  99. baseState.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
  100. )
  101. // 更改预览状态
  102. const onChangeStaff = (type: string) => {
  103. staff.radio = type
  104. staff.status = false
  105. if (type == 'first') {
  106. loading.value = false
  107. const tempPdf = musicDetail.value?.firstPdfUrl
  108. initIframe(tempPdf, 'first', staffData.musicXml)
  109. } else if (type == 'fixed') {
  110. loading.value = false
  111. const tempPdf = musicDetail.value?.jianPdfUrl
  112. initIframe(tempPdf, 'first', staffData.musicXml)
  113. } else {
  114. loading.value = false
  115. const tempPdf = musicDetail.value?.musicPdfUrl
  116. initIframe(tempPdf, 'first', staffData.musicXml)
  117. }
  118. }
  119. watch(
  120. () => staff.radio,
  121. (val: string) => {
  122. if (val == 'first') {
  123. showImg.value = deepClone(firstList.value)
  124. } else if (val == 'fixed') {
  125. showImg.value = deepClone(fixedList.value)
  126. } else {
  127. showImg.value = deepClone(staffList.value)
  128. }
  129. }
  130. )
  131. const FetchList = async (id?: any) => {
  132. if (loading.value) {
  133. return
  134. }
  135. loading.value = true
  136. isError.value = false
  137. try {
  138. const res = await request.get(`/music/sheet/detail/${route.query.id}`, {
  139. prefix:
  140. state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student',
  141. params: {
  142. tenantAlbumId: route.query.tenantAlbumId || null
  143. }
  144. })
  145. musicDetail.value = res.data
  146. // 取原音,如果有多个则默认第一个
  147. const background = res.data.background
  148. audioFileUrl.value =
  149. background && background.length > 0 ? background[0].audioFileUrl : ''
  150. showImg.value = res.data.musicImg ? res.data.musicImg.split(',') : []
  151. firstList.value = res.data.firstTone
  152. ? res.data.firstTone.split(',')
  153. : []
  154. fixedList.value = res.data.fixedTone
  155. ? res.data.fixedTone.split(',')
  156. : []
  157. staffList.value = res.data.musicImg ? res.data.musicImg.split(',') : []
  158. // 初始化默认数据是否有值
  159. if (firstList.value.length > 0) {
  160. defaultImgs.value.first = true
  161. }
  162. if (fixedList.value.length > 0) {
  163. defaultImgs.value.fixed = true
  164. }
  165. if (staffList.value.length > 0) {
  166. defaultImgs.value.staff = true
  167. }
  168. nextTick(async () => {
  169. await toDetail()
  170. renderStaff()
  171. })
  172. } catch (error) {
  173. isError.value = true
  174. }
  175. if (musicDetail.value?.musicSheetType !== 'CONCERT') {
  176. loading.value = false
  177. }
  178. }
  179. const player = ref<any>(null)
  180. const audio = ref<any>(null)
  181. const freeRate = ref<any>(0)
  182. const initAudio = async () => {
  183. const controls = [
  184. // 'play-large',
  185. 'play',
  186. 'progress',
  187. 'captions',
  188. // 'fullscreen',
  189. 'duration'
  190. ]
  191. player.value = new Plyr(audio.value, {
  192. controls: controls
  193. })
  194. const config = await request.get(
  195. '/api-student/sysConfig/queryByParamNameList',
  196. {
  197. params: {
  198. paramNames: 'music_sheet_free_rate'
  199. }
  200. }
  201. )
  202. freeRate.value = config.data[0]?.paramValue || 0
  203. player.value.on('timeupdate', () => {
  204. // 允许播放时间
  205. const players = player.value
  206. const playTime = (players.duration * freeRate.value) / 100 || 0
  207. // 时间,不能播放
  208. if (players.currentTime >= playTime && !buyState.value.play) {
  209. players.stop()
  210. // players.pause()
  211. }
  212. })
  213. }
  214. const showLoading = async (e: any) => {
  215. // console.log(e, 'showLoading')
  216. if (e.data?.api === 'musicStaffRender') {
  217. const osmdImg = e.data.osmdImg
  218. showImg.value = []
  219. const imgs: any = []
  220. // 独奏并且的图片则不用生成
  221. if (
  222. musicDetail.value?.musicSheetType === 'SINGLE' &&
  223. musicDetail.value?.notation
  224. ) {
  225. if (
  226. (staff.radio === 'first' && firstList.value.length > 0) ||
  227. (staff.radio === 'fixed' && fixedList.value.length > 0) ||
  228. (staff.radio === 'staff' && staffList.value.length > 0)
  229. ) {
  230. if (staff.radio === 'first') {
  231. showImg.value = firstList.value
  232. } else if (staff.radio === 'fixed') {
  233. showImg.value = fixedList.value
  234. }
  235. if (staff.radio === 'staff') {
  236. showImg.value = staffList.value
  237. }
  238. loading.value = e.data.loading
  239. return
  240. }
  241. }
  242. uploadImgs.value = true
  243. if (osmdImg) {
  244. for (let i = 0; i < osmdImg.length; i++) {
  245. const img = await svgtopng(
  246. osmdImg[i].img,
  247. osmdImg[i].width,
  248. osmdImg[i].height
  249. )
  250. imgs.push(img)
  251. }
  252. }
  253. uploadImgs.value = false
  254. // 判断是否为独奏
  255. if (
  256. musicDetail.value?.musicSheetType === 'SINGLE' &&
  257. musicDetail.value?.notation
  258. ) {
  259. if (staff.radio === 'first') {
  260. firstList.value = imgs
  261. } else if (staff.radio === 'fixed') {
  262. fixedList.value = imgs
  263. } else if (staff.radio === 'staff') {
  264. staffList.value = imgs
  265. }
  266. showImg.value = imgs
  267. } else {
  268. showImg.value = imgs
  269. }
  270. loading.value = e.data.loading
  271. }
  272. }
  273. onMounted(async () => {
  274. postMessage({
  275. api: 'setStatusBarTextColor',
  276. content: { statusBarTextColor: true }
  277. })
  278. await FetchList()
  279. const { height } = useRect(headers as any)
  280. const footer = useRect(footers as any)
  281. heightInfo.value = height + footer.height
  282. // 初始化音频
  283. if (audioFileUrl.value) {
  284. initAudio()
  285. }
  286. window.addEventListener('message', showLoading)
  287. })
  288. onUnmounted(() => {
  289. postMessage({
  290. api: 'setStatusBarTextColor',
  291. content: { statusBarTextColor: false }
  292. })
  293. window.removeEventListener('message', showLoading)
  294. })
  295. const toggleFavorite = async () => {
  296. try {
  297. await request.post('/music/sheet/favorite/' + musicDetail.value?.id, {
  298. prefix:
  299. state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student'
  300. })
  301. musicDetail.value.favorite = musicDetail.value?.favorite ? 0 : 1
  302. musicDetail.value.favoriteCount = musicDetail.value?.favorite
  303. ? musicDetail.value.favoriteCount + 1
  304. : musicDetail.value.favoriteCount - 1 < 0
  305. ? 0
  306. : musicDetail.value.favoriteCount - 1
  307. setTimeout(() => {
  308. Toast(musicDetail.value?.favorite ? '收藏成功' : '取消收藏成功')
  309. }, 100)
  310. } catch (error) {
  311. //
  312. }
  313. }
  314. const onBuy = async () => {
  315. const music = musicDetail.value
  316. orderStatus.orderObject.orderType = 'MUSIC'
  317. orderStatus.orderObject.orderName = music.musicSheetName
  318. orderStatus.orderObject.orderDesc = music.musicSheetName
  319. orderStatus.orderObject.actualPrice = music.musicPrice
  320. orderStatus.orderObject.recomUserId = route.query.recomUserId || 0
  321. orderStatus.orderObject.activityId = route.query.activityId || 0
  322. orderStatus.orderObject.orderNo = ''
  323. orderStatus.orderObject.orderList = [
  324. {
  325. orderType: 'MUSIC',
  326. goodsName: music.musicSheetName,
  327. actualPrice: music.musicPrice,
  328. ...music
  329. }
  330. ]
  331. const res = await request.post('/api-student/userOrder/getPendingOrder', {
  332. data: {
  333. goodType: 'MUSIC',
  334. bizId: music.id
  335. }
  336. })
  337. const result = res.data
  338. if (result) {
  339. Dialog.confirm({
  340. title: '提示',
  341. message: '您有一个未支付的订单,是否继续支付?',
  342. theme: 'round-button',
  343. className: 'confirm-button-group',
  344. cancelButtonText: '取消订单',
  345. confirmButtonText: '继续支付'
  346. })
  347. .then(async () => {
  348. orderStatus.orderObject.orderNo = result.orderNo
  349. orderStatus.orderObject.actualPrice = result.actualPrice
  350. orderStatus.orderObject.discountPrice = result.discountPrice
  351. orderStatus.orderObject.paymentConfig = {
  352. ...result.paymentConfig,
  353. paymentVendor: result.paymentVendor,
  354. paymentVersion: result.paymentVersion
  355. }
  356. routerTo()
  357. })
  358. .catch(() => {
  359. Dialog.close()
  360. // 只用取消订单,不用做其它处理
  361. cancelPayment(result.orderNo)
  362. })
  363. } else {
  364. routerTo()
  365. }
  366. }
  367. const routerTo = () => {
  368. const music = musicDetail.value
  369. router.push({
  370. path: '/orderDetail',
  371. query: {
  372. orderType: 'MUSIC',
  373. musicId: music.id
  374. }
  375. })
  376. }
  377. const cancelPayment = async (orderNo: string) => {
  378. try {
  379. await request.post('/api-student/userOrder/orderCancel', {
  380. data: {
  381. orderNo
  382. }
  383. })
  384. } catch {
  385. //
  386. }
  387. }
  388. const buyState = computed(() => {
  389. const music = musicDetail.value
  390. return {
  391. hasTenantAlbum: route.query?.tenantAlbumId ? true : false, // 是否从专辑来的
  392. play: music.play ? true : false, // 是否可以播放
  393. free: music?.paymentType.includes('FREE'),
  394. charge: music?.paymentType.includes('CHARGE'),
  395. vip: music?.paymentType.includes('VIP'),
  396. buy: music?.orderStatus === 'PAID' // 是否已买
  397. }
  398. })
  399. const staffData = reactive({
  400. open: false,
  401. iframeSrc: '',
  402. musicXml: '',
  403. instrumentName: '',
  404. iframeRef: null as any,
  405. partIndex: 0,
  406. partXmlIndex: 0,
  407. partList: [] as any[],
  408. tempPartList: [] as any[],
  409. xmlPartList: [] as any[]
  410. })
  411. /** 渲染五线谱 */
  412. // 长笛、单簧管、萨克斯、小号、长号、圆号、大号、上低音号
  413. const sortList = {
  414. 长笛: 1,
  415. 单簧管: 2,
  416. 中音单簧管: 3,
  417. 低音单簧管: 4,
  418. 高音萨克斯风: 5,
  419. 中音萨克斯风: 6,
  420. 次中音萨克斯风: 7,
  421. 低音萨克斯风: 8,
  422. 小号: 9,
  423. 长号: 10,
  424. 圆号: 11,
  425. 大号: 12,
  426. 上低音号: 13
  427. }
  428. const instrumentSort = (list: Array<any>) => {
  429. list.sort((a, b) => {
  430. return (
  431. (sortList[getInstrumentName(a.track)] || 20) -
  432. (sortList[getInstrumentName(b.track)] || 20)
  433. )
  434. })
  435. return list
  436. }
  437. const toDetail = async () => {
  438. try {
  439. if (musicDetail.value?.xmlFileUrl) {
  440. // 获取文件
  441. const res = await umiRequest.get(musicDetail.value?.xmlFileUrl, {
  442. mode: 'cors'
  443. })
  444. let partNames: string[] = []
  445. const xml: any = new DOMParser().parseFromString(res, 'text/xml')
  446. for (const item of xml.getElementsByTagName('part-name')) {
  447. if (item.textContent) {
  448. partNames.push(item.textContent)
  449. }
  450. }
  451. partNames = partNames.filter(
  452. (item: any) => !item?.toLocaleUpperCase()?.includes('COMMON')
  453. )
  454. const partList: any = []
  455. for (let j = 0; j < partNames.length; j++) {
  456. partList.push({
  457. name: partNames[j],
  458. value: j
  459. })
  460. }
  461. staffData.xmlPartList = partList
  462. }
  463. staffData.musicXml = musicDetail.value?.xmlFileUrl || ''
  464. const tempList = musicDetail.value?.background || []
  465. const tempPartList = [] as any
  466. staffData.xmlPartList.forEach((part: any) => {
  467. const item = tempList.find((item: any) => item.track === part.name)
  468. if (item) {
  469. tempPartList.push({
  470. ...item,
  471. index: part.value
  472. })
  473. }
  474. })
  475. staffData.partList = tempPartList
  476. staffData.tempPartList = JSON.parse(JSON.stringify(staffData.partList))
  477. staffData.partList = instrumentSort(staffData.partList)
  478. // console.log(staffData.partList, ' staffData.partList')
  479. staffData.partXmlIndex = staffData.partList[0]?.index || 0
  480. staffData.instrumentName =
  481. musicDetail.value?.musicSheetType === 'CONCERT'
  482. ? getInstrumentName(staffData.partList[staffData.partIndex]?.track)
  483. : ''
  484. if (musicDetail.value?.musicSheetType === 'SINGLE') {
  485. musicPdfUrl.value = musicDetail.value?.musicPdfUrl
  486. } else {
  487. musicPdfUrl.value = staffData.partList[0]?.musicPdfUrl
  488. }
  489. } catch (error) {
  490. //
  491. }
  492. }
  493. const renderStaff = async () => {
  494. try {
  495. nextTick(() => {
  496. if (musicPdfUrl.value) {
  497. // const url = `${location.origin}${
  498. // location.pathname
  499. // }pdf/web/viewer-pdf.html?file=${encodeURIComponent(
  500. // musicPdfUrl.value
  501. // )}&t=${Date.now()}`
  502. const url = '/pdf/web/viewer-pdf.html?file=' +
  503. encodeURIComponent(musicPdfUrl.value) +
  504. '&t=' +
  505. Date.now()
  506. const iframeRef = document.querySelector('#staffIframeRef') as any
  507. iframeRef.contentWindow.location.replace(
  508. url
  509. )
  510. staffData.iframeSrc = url
  511. } else {
  512. // const url = `${location.origin}${location.pathname}osmd/index.html`
  513. const url = `${location.origin}/osmd/index.html`
  514. const iframeRef = document.querySelector('#staffIframeRef') as any
  515. iframeRef.contentWindow.location.replace(url)
  516. staffData.iframeSrc = url
  517. }
  518. })
  519. } catch (error) {
  520. //
  521. }
  522. }
  523. const musicIframeLoad = async () => {
  524. const iframeRef: any = document.getElementById('staffIframeRef')
  525. if (iframeRef && iframeRef.contentWindow.renderXml) {
  526. const res = await umiRequest.get(staffData.musicXml, {
  527. mode: 'cors'
  528. })
  529. const parseXmlInfo = getCustomInfo(res)
  530. const xml = formatXML(parseXmlInfo.parsedXML)
  531. const currentXml = onlyVisible(xml, staffData.partXmlIndex)
  532. iframeRef.contentWindow.renderXml(currentXml, 0)
  533. // iframeRef.contentWindow.renderXml(
  534. // staffData.musicXml,
  535. // staffData.partXmlIndex
  536. // )
  537. }
  538. }
  539. const resetRender = async () => {
  540. const iframeRef: any = document.getElementById('staffIframeRef')
  541. if (iframeRef && iframeRef.contentWindow.renderXml) {
  542. loading.value = true
  543. // iframeRef.contentWindow.resetRender(staffData.partXmlIndex)
  544. const res = await umiRequest.get(staffData.musicXml, {
  545. mode: 'cors'
  546. })
  547. const parseXmlInfo = getCustomInfo(res)
  548. const xml = formatXML(parseXmlInfo.parsedXML)
  549. const currentXml = onlyVisible(xml, staffData.partXmlIndex)
  550. iframeRef.contentWindow.renderXml(currentXml, 0)
  551. staffData.instrumentName = getInstrumentName(
  552. staffData.partList[staffData.partIndex]?.track
  553. )
  554. }
  555. }
  556. const resetRenderPage = async (type: string, xmlUrl: string) => {
  557. const iframeRef: any = document.getElementById('staffIframeRef')
  558. if (iframeRef && iframeRef.contentWindow.renderXml) {
  559. // console.log('resetRenderPage')
  560. // iframeRef.contentWindow.resetRenderPage(type, xmlUrl)
  561. const res = await umiRequest.get(staffData.musicXml, {
  562. mode: 'cors'
  563. })
  564. const parseXmlInfo = getCustomInfo(res)
  565. const xml = formatXML(parseXmlInfo.parsedXML)
  566. const currentXml = onlyVisible(xml, staffData.partXmlIndex)
  567. iframeRef.contentWindow.resetRenderPage(type, currentXml)
  568. }
  569. }
  570. const partColumns = computed(() => {
  571. return staffData.partList.map((item: any, index: number) => {
  572. const instrumentName =
  573. musicDetail.value?.musicSheetType === 'CONCERT'
  574. ? getInstrumentName(item.track)
  575. : ''
  576. return {
  577. text: item.track + (instrumentName ? `(${instrumentName})` : ''),
  578. value: index,
  579. instrumentName,
  580. musicPdfUrl: item.musicPdfUrl,
  581. firstPdfUrl: item.firstPdfUrl,
  582. jianPdfUrl: item.jianPdfUrl,
  583. xmlValue: item.index,
  584. track: item.track
  585. }
  586. })
  587. })
  588. const onDownloadApp = () => {
  589. Dialog.alert({
  590. title: '提示',
  591. message: '请在酷乐秀APP中使用',
  592. confirmButtonColor: '#2dc7aa'
  593. }).then(() => {
  594. window.location.href = location.origin + '/student/#/download'
  595. })
  596. }
  597. // 购买
  598. const onSubmit = async () => {
  599. const url =
  600. apiSuffix.value +
  601. '/tenantGroupAlbum/buyAlbumInfo?tenantGroupAlbumId=' +
  602. (route.query.taId || '')
  603. // if (state.albumId) {
  604. // url = url + '?albumId=' + state.albumId
  605. // }
  606. const { data } = await request.get(url)
  607. const details = data[0]
  608. orderStatus.orderObject.orderType = 'TENANT_ALBUM'
  609. orderStatus.orderObject.orderName = details.name
  610. orderStatus.orderObject.orderDesc = details.name
  611. orderStatus.orderObject.actualPrice = details.actualPrice
  612. // orderStatus.orderObject.recomUserId = route.query.recomUserId || 0
  613. // orderStatus.orderObject.activityId = route.query.activityId || 0
  614. orderStatus.orderObject.orderNo = ''
  615. orderStatus.orderObject.orderList = [
  616. {
  617. orderType: 'TENANT_ALBUM',
  618. goodsName: details.name,
  619. actualPrice: details.actualPrice,
  620. price: details.actualPrice,
  621. ...details
  622. }
  623. ]
  624. const res = await request.post('/api-student/userOrder/getPendingOrder', {
  625. data: {
  626. goodType: 'TENANT_ALBUM',
  627. bizId: details.id
  628. }
  629. })
  630. const result = res.data
  631. if (result) {
  632. Dialog.confirm({
  633. title: '提示',
  634. message: '您有一个未支付的订单,是否继续支付?',
  635. theme: 'round-button',
  636. className: 'confirm-button-group',
  637. cancelButtonText: '取消订单',
  638. confirmButtonText: '继续支付'
  639. })
  640. .then(async () => {
  641. orderStatus.orderObject.orderNo = result.orderNo
  642. orderStatus.orderObject.actualPrice = result.actualPrice
  643. orderStatus.orderObject.discountPrice = result.discountPrice
  644. orderStatus.orderObject.paymentConfig = {
  645. ...result.paymentConfig,
  646. paymentVendor: result.paymentVendor,
  647. paymentVersion: result.paymentVersion
  648. }
  649. routerToALBUM(details.id)
  650. })
  651. .catch(() => {
  652. Dialog.close()
  653. // 只用取消订单,不用做其它处理
  654. cancelPaymentALBUM(result.orderNo)
  655. })
  656. } else {
  657. routerToALBUM(details.id)
  658. }
  659. }
  660. const cancelPaymentALBUM = async (orderNo: string) => {
  661. try {
  662. await request.post('/api-student/userOrder/orderCancel/v2', {
  663. data: {
  664. orderNo
  665. }
  666. })
  667. } catch {
  668. //
  669. }
  670. }
  671. const routerToALBUM = (id: string) => {
  672. router.push({
  673. path: '/orderDetail',
  674. query: {
  675. orderType: 'ALBUM',
  676. album: id
  677. }
  678. })
  679. }
  680. const initIframe = (tempPdf: string, staff: string, xml: string) => {
  681. if (tempPdf) {
  682. musicPdfUrl.value = tempPdf
  683. renderStaff()
  684. } else {
  685. musicPdfUrl.value = ''
  686. // 为了处理,之前是使用pdf渲染,现在又用osmd,iframe没有重新加载
  687. if (staffData.iframeSrc.indexOf('pdf/web') !== -1) {
  688. renderStaff()
  689. } else {
  690. resetRenderPage(staff, xml)
  691. }
  692. }
  693. }
  694. return () => (
  695. <div class={styles.detail}>
  696. <TheSticky position="top">
  697. <ColHeader
  698. background={background.value}
  699. hideHeader={false}
  700. border={false}
  701. isFixed={false}
  702. color={color.value}
  703. backIconColor="white"
  704. />
  705. </TheSticky>
  706. <img class={styles.bgImg} src={musicDetail.value?.titleImg} />
  707. <div class={styles.musicContentBg}></div>
  708. <div class={styles.bg}>
  709. <div class={styles.alumWrap}>
  710. <div class={styles.img}>
  711. {/* {albumDetail.value?.paymentType === 'CHARGE' && (
  712. <span class={styles.albumType}>付费</span>
  713. )} */}
  714. <Image
  715. class={styles.image}
  716. width="100%"
  717. height="100%"
  718. fit="cover"
  719. src={musicDetail.value?.titleImg}
  720. />
  721. </div>
  722. <div class={styles.alumDes}>
  723. <div class={[styles.alumTitle, 'van-ellipsis']}>
  724. {musicDetail.value?.musicSheetName}
  725. </div>
  726. <div class={[styles.des, 'van-multi-ellipsis--l2']}>
  727. {!musicDetail.value?.composer
  728. ? `上传者:${musicDetail.value?.addName || ''}`
  729. : `作曲:${musicDetail.value?.composer || ''}`}
  730. </div>
  731. </div>
  732. </div>
  733. <div class={[styles.alumCollect]}>
  734. <div
  735. class={[
  736. styles.alumCollectItem,
  737. showImg.value.length <= 0 && !musicPdfUrl.value
  738. ? styles.alumCollectItemActive
  739. : ''
  740. ]}
  741. onClick={() => {
  742. if (browser().isApp) {
  743. if (musicPdfUrl.value) {
  744. const songName =
  745. musicDetail.value?.musicSheetName +
  746. (staffData.instrumentName
  747. ? `(${staffData.instrumentName})`
  748. : '')
  749. promisefiyPostMessage({
  750. api: 'downloadFile',
  751. content: {
  752. downloadUrl: musicPdfUrl.value,
  753. fileName: songName
  754. }
  755. })
  756. return
  757. }
  758. if (showImg.value.length > 0) {
  759. downloadStatus.value = true
  760. }
  761. } else {
  762. onDownloadApp()
  763. }
  764. }}
  765. >
  766. <img src={iconDownload} />
  767. <span>下载曲谱</span>
  768. </div>
  769. <div
  770. class={styles.alumCollectItem}
  771. onClick={() => toggleFavorite()}
  772. >
  773. <img src={musicDetail.value?.favorite ? iStart : oStart} />
  774. <span>{musicDetail.value?.favoriteCount}人收藏</span>
  775. </div>
  776. </div>
  777. {/* {buyState.value.hasTenantAlbum ? 'true' : 'false'} */}
  778. {musicDetail.value?.id &&
  779. !buyState.value.play &&
  780. !buyState.value.hasTenantAlbum && (
  781. <div class={styles.albumTips}>
  782. {buyState.value.charge && buyState.value.vip ? (
  783. <>
  784. <span>开通会员或点播单曲,即可自由练习该曲谱</span>
  785. <span class={styles.albumPrice}>
  786. ¥{moneyFormat(musicDetail.value?.musicPrice)}
  787. </span>
  788. </>
  789. ) : buyState.value.vip ? (
  790. <span>
  791. <img src={iconMemberSmall} class={styles.iconMemberSmall} />
  792. 此曲谱为会员专享,开通会员即可自由练习该曲谱
  793. </span>
  794. ) : buyState.value.charge ? (
  795. <>
  796. <span>此曲谱为点播曲谱,点播即可自由练习该曲谱</span>
  797. <span class={styles.albumPrice}>
  798. ¥{moneyFormat(musicDetail.value?.musicPrice)}
  799. </span>
  800. </>
  801. ) : (
  802. ''
  803. )}
  804. </div>
  805. )}
  806. </div>
  807. <div class={styles.musicContent}>
  808. {musicDetail.value?.notation ? (
  809. <span
  810. class={styles.iconTransfer}
  811. style={{
  812. display:
  813. musicDetail.value?.musicSheetType === 'SINGLE' ? '' : 'none',
  814. // opacity: showImg.value.length <= 0 || data.musicPdfUrl ? 0.6 : 1
  815. }}
  816. onClick={() => {
  817. // if (showImg.value.length <= 0 || data.musicPdfUrl) return
  818. staff.status = true
  819. }}
  820. >
  821. 转谱
  822. </span>
  823. ) : null}
  824. <span
  825. class={styles.iconTransfer}
  826. style={{
  827. display:
  828. musicDetail.value?.musicSheetType === 'CONCERT' ? '' : 'none'
  829. }}
  830. onClick={() => {
  831. staffData.open = true
  832. }}
  833. >
  834. 切换声轨
  835. </span>
  836. {musicDetail.value?.musicSheetType === 'CONCERT' || musicPdfUrl.value ||
  837. !defaultImgs.value[staff.radio] ? (
  838. <>
  839. {musicPdfUrl.value ? (
  840. <iframe
  841. id="staffIframeRef"
  842. style={{
  843. opacity: loading.value ? 0 : 1,
  844. flex: "1 auto"
  845. }}
  846. // src={staffData.iframeSrc}
  847. onLoad={() => {
  848. // 判断是用哪个渲染的
  849. loading.value = false
  850. }}
  851. ></iframe>
  852. ) : (
  853. <>
  854. <p class={styles.musicTitle}>
  855. {(musicDetail.value?.musicSheetName
  856. ? musicDetail.value?.musicSheetName
  857. : '') +
  858. (staffData.instrumentName
  859. ? `(${staffData.instrumentName})`
  860. : '')}
  861. </p>
  862. {loading.value && (
  863. <div>
  864. <Vue3Lottie
  865. animationData={AstronautJSON}
  866. class={styles.finch}
  867. ></Vue3Lottie>
  868. {/* <p class={styles.finchLoad}>加载中...</p> */}
  869. </div>
  870. )}
  871. <iframe
  872. id="staffIframeRef"
  873. style={{
  874. opacity: loading.value ? 0 : 1,
  875. flex: "1 auto"
  876. }}
  877. // src={staffData.iframeSrc}
  878. onLoad={() => {
  879. musicIframeLoad()
  880. }}
  881. ></iframe>
  882. </>
  883. )}
  884. </>
  885. ) : (
  886. <div class={styles.imgSection}>
  887. <p class={styles.musicTitle}>
  888. {(musicDetail.value?.musicSheetName
  889. ? musicDetail.value?.musicSheetName
  890. : '') +
  891. (staffData.instrumentName
  892. ? `(${staffData.instrumentName})`
  893. : '')}
  894. </p>
  895. {showImg.value.length > 0 ? (
  896. <div class={styles.musicImg}>
  897. <div>
  898. <img src={showImg.value[0]} alt="" />
  899. </div>
  900. </div>
  901. ) : loading.value ? (
  902. <>
  903. <Vue3Lottie
  904. animationData={AstronautJSON}
  905. class={styles.finch}
  906. ></Vue3Lottie>
  907. {/* <p class={styles.finchLoad}>加载中...</p> */}
  908. </>
  909. ) : (
  910. <div class={styles.empty}>
  911. <Image src={emtpy} class={styles.emptyImg} />
  912. <p class={styles.emptyTip}>暂无乐谱预览图</p>
  913. </div>
  914. )}
  915. </div>
  916. )}
  917. </div>
  918. {musicDetail.value?.id && (
  919. <TheSticky position="bottom" varName="--bottom-height">
  920. <div style={{ backgroundColor: '#fff' }}>
  921. <div class={styles.videoOperation}>
  922. {audioFileUrl.value && (
  923. <>
  924. {!buyState.value.play &&
  925. freeRate.value != 100 &&
  926. freeRate.value != 0 && (
  927. <div class={[styles.audition]}>
  928. <img src={iconListen} />
  929. <span>每首曲目可试听{freeRate.value}%</span>
  930. </div>
  931. )}
  932. <div class={[styles.audio, styles.collectCell]}>
  933. <audio id="player" controls ref={audio}>
  934. <source src={audioFileUrl.value} type="audio/mp3" />
  935. </audio>
  936. </div>
  937. </>
  938. )}
  939. </div>
  940. <div ref={footers} class={styles.footers}>
  941. {/* 判断是否是免费的,或者已经购买过 */}
  942. {buyState.value.play ? (
  943. <Button
  944. round
  945. block
  946. type="primary"
  947. color="linear-gradient( 270deg, #FF204B 0%, #FE5B71 100%)"
  948. onClick={() => {
  949. if (!browser().isApp) {
  950. onDownloadApp()
  951. return
  952. }
  953. const throttleFn = useThrottleFn(() => {
  954. player.value && player.value.stop()
  955. const item: any = partColumns.value.find(
  956. (c: any) => c.value === staffData.partIndex
  957. )
  958. // const index = staffData.tempPartList.findIndex(
  959. // (i: any) => i.track === item?.track
  960. // )
  961. musicBuy(musicDetail.value, () => {}, {
  962. 'part-index': item?.xmlValue || 0,
  963. sett: staff.radio,
  964. albumId: route.query.tenantAlbumId || '', // 专辑编号
  965. // 1:忽略系统节拍器
  966. ignoreSysMetronome:
  967. route.query.subjectType === 'MUSIC' ? 1 : 0
  968. })
  969. }, 500)
  970. throttleFn()
  971. }}
  972. >
  973. 立即练习
  974. </Button>
  975. ) : buyState.value.hasTenantAlbum && !buyState.value.play ? (
  976. <Button
  977. disabled={route.query.buyStatus === '1'}
  978. round
  979. block
  980. type="primary"
  981. color="linear-gradient( 270deg, #FF204B 0%, #FE5B71 100%)"
  982. onClick={() => {
  983. if (!browser().isApp) {
  984. onDownloadApp()
  985. return
  986. }
  987. if (route.query.type === 'search') {
  988. router.push('train-tool')
  989. } else {
  990. onSubmit()
  991. }
  992. }}
  993. >
  994. 开通训练教程
  995. </Button>
  996. ) : (
  997. <div class={[styles.buyBtn]}>
  998. {/* 判断是否是需要收费的 */}
  999. {buyState.value.charge && (
  1000. <Button
  1001. round
  1002. type="primary"
  1003. color="linear-gradient(270deg, #FF204B 0%, #FE5B71 100%)"
  1004. class={styles.primary}
  1005. onClick={() => {
  1006. if (!browser().isApp) {
  1007. onDownloadApp()
  1008. return
  1009. }
  1010. onBuy()
  1011. }}
  1012. >
  1013. 立即点播
  1014. </Button>
  1015. )}
  1016. {/* 判断是否有会员的 */}
  1017. {buyState.value.vip && (
  1018. <Button
  1019. round
  1020. block={!buyState.value.charge ? true : false}
  1021. type="primary"
  1022. color="linear-gradient(270deg, #FF204B 0%, #FE5B71 100%)"
  1023. class={styles.memeber}
  1024. onClick={() => {
  1025. if (!browser().isApp) {
  1026. onDownloadApp()
  1027. return
  1028. }
  1029. router.push({
  1030. path: '/memberCenter',
  1031. query: {
  1032. ...route.query
  1033. }
  1034. })
  1035. }}
  1036. >
  1037. {studentActivityId.value > 0 && (
  1038. <div class={[styles.buttonDiscount]}>专属优惠</div>
  1039. )}
  1040. 开通会员
  1041. </Button>
  1042. )}
  1043. </div>
  1044. )}
  1045. </div>
  1046. </div>
  1047. </TheSticky>
  1048. )}
  1049. <Popup v-model:show={downloadStatus.value} position="bottom" round>
  1050. {downloadStatus.value && (
  1051. <Download
  1052. imgList={JSON.parse(JSON.stringify(showImg.value))}
  1053. musicSheetName={musicDetail.value?.musicSheetName +
  1054. (staffData.instrumentName
  1055. ? `(${staffData.instrumentName})`
  1056. : '')}
  1057. />
  1058. )}
  1059. </Popup>
  1060. <Popup
  1061. v-model:show={staff.status}
  1062. teleport="body"
  1063. closeable
  1064. style={{ width: '80%' }}
  1065. class={styles.staffChange}
  1066. round
  1067. >
  1068. <div class={styles.staffContainer}>
  1069. <div class={styles.staffTitle}>转换曲谱</div>
  1070. <RadioGroup v-model={staff.radio}>
  1071. <CellGroup border={false}>
  1072. <Cell
  1073. center
  1074. border={false}
  1075. class={staff.radio === 'staff' ? styles.active : ''}
  1076. onClick={() => onChangeStaff('staff')}
  1077. >
  1078. {{
  1079. icon: () => (
  1080. <Image src={staffDetafult} class={styles.staffImg} />
  1081. ),
  1082. title: () => <span class={styles.name}>五线谱</span>,
  1083. value: () => (
  1084. <Radio name="staff">
  1085. {{
  1086. icon: (props: any) => (
  1087. <Icon
  1088. class={styles.boxStyle}
  1089. name={
  1090. props.checked
  1091. ? activeButtonIcon
  1092. : inactiveButtonIcon
  1093. }
  1094. />
  1095. )
  1096. }}
  1097. </Radio>
  1098. )
  1099. }}
  1100. </Cell>
  1101. <Cell
  1102. center
  1103. border={false}
  1104. class={staff.radio === 'first' ? styles.active : ''}
  1105. onClick={() => onChangeStaff('first')}
  1106. >
  1107. {{
  1108. icon: () => (
  1109. <Image src={firstDefault} class={styles.staffImg} />
  1110. ),
  1111. title: () => <span class={styles.name}>简谱-首调</span>,
  1112. value: () => (
  1113. <Radio name="first">
  1114. {{
  1115. icon: (props: any) => (
  1116. <Icon
  1117. class={styles.boxStyle}
  1118. name={
  1119. props.checked
  1120. ? activeButtonIcon
  1121. : inactiveButtonIcon
  1122. }
  1123. />
  1124. )
  1125. }}
  1126. </Radio>
  1127. )
  1128. }}
  1129. </Cell>
  1130. <Cell
  1131. center
  1132. border={false}
  1133. class={staff.radio === 'fixed' ? styles.active : ''}
  1134. onClick={() => onChangeStaff('fixed')}
  1135. >
  1136. {{
  1137. icon: () => (
  1138. <Image src={fixedDefault} class={styles.staffImg} />
  1139. ),
  1140. title: () => <span class={styles.name}>简谱-固定调</span>,
  1141. value: () => (
  1142. <Radio name="fixed">
  1143. {{
  1144. icon: (props: any) => (
  1145. <Icon
  1146. class={styles.boxStyle}
  1147. name={
  1148. props.checked
  1149. ? activeButtonIcon
  1150. : inactiveButtonIcon
  1151. }
  1152. />
  1153. )
  1154. }}
  1155. </Radio>
  1156. )
  1157. }}
  1158. </Cell>
  1159. </CellGroup>
  1160. </RadioGroup>
  1161. </div>
  1162. </Popup>
  1163. <Popup
  1164. teleport="body"
  1165. position="bottom"
  1166. round
  1167. v-model:show={staffData.open}
  1168. >
  1169. <Picker
  1170. columns={partColumns.value}
  1171. onConfirm={value => {
  1172. staffData.open = false
  1173. staffData.partIndex = value.value
  1174. staffData.partXmlIndex = value.xmlValue
  1175. staffData.instrumentName = value.instrumentName
  1176. showImg.value = []
  1177. nextTick(() => {
  1178. // const item = getInstrumentItem(musicDetail.value?.background || [], value.selectedOptions[0].track);
  1179. let tempPdf = value?.musicPdfUrl
  1180. if (musicDetail.value?.musicSheetType !== 'CONCERT') {
  1181. // tempPdf = ''
  1182. if (staff.radio === 'first') {
  1183. tempPdf = value?.firstPdfUrl
  1184. } else if (staff.radio === 'fixed') {
  1185. tempPdf = value?.jianPdfUrl
  1186. } else if (staff.radio === 'staff') {
  1187. tempPdf = value?.musicPdfUrl
  1188. }
  1189. }
  1190. if (tempPdf) {
  1191. musicPdfUrl.value = tempPdf
  1192. renderStaff()
  1193. } else {
  1194. musicPdfUrl.value = ''
  1195. loading.value = true
  1196. // 为了处理,之前是使用pdf渲染,现在又用osmd,iframe没有重新加载
  1197. if (staffData.iframeSrc.indexOf('pdf/web') !== -1) {
  1198. renderStaff()
  1199. } else {
  1200. resetRender()
  1201. }
  1202. }
  1203. // resetRender()
  1204. })
  1205. }}
  1206. onCancel={() => (staffData.open = false)}
  1207. />
  1208. </Popup>
  1209. </div>
  1210. )
  1211. }
  1212. })