123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428 |
- import TheSticky from '@/components/the-sticky'
- import styles from './new-index.module.less'
- import { useEventListener, useThrottleFn, useWindowScroll } from '@vueuse/core'
- import { postMessage } from '@/helpers/native-message'
- import iconShare from '../../images/icon-share.png'
- import oStart from '../album-detail/icon-hart.png'
- import iStart from '../album-detail/icon-hart-active.png'
- import iconDownload from './images/icon-download.png'
- import iconMemberSmall from './images/icon-member-small.png'
- import {
- computed,
- defineComponent,
- nextTick,
- onMounted,
- onUnmounted,
- reactive,
- ref,
- toRaw,
- watch
- } from 'vue'
- import umiRequest from 'umi-request'
- import { useRoute, useRouter } from 'vue-router'
- import request from '@/helpers/request'
- import ColHeader from '@/components/col-header'
- import {
- Button,
- Cell,
- CellGroup,
- Dialog,
- Icon,
- Image,
- Popup,
- RadioGroup,
- Radio,
- Toast,
- Picker
- } from 'vant'
- import { useRect } from '@vant/use'
- import { Vue3Lottie } from 'vue3-lottie'
- import { getRandomKey, musicBuy } from '../music'
- import { getOssUploadUrl, state } from '@/state'
- import { browser, moneyFormat } from '@/helpers/utils'
- import { orderStatus } from '@/views/order-detail/orderStatus'
- import AstronautJSON from './animate/refresh_anim.json'
- import ColShare from '@/components/col-share'
- import iconListen from './images/icon_listen.png'
- import iconTeacher from '@common/images/icon_teacher.png'
- import emtpy from './images/emtpy.png'
- import { state as baseState } from '@/state'
- import activeButtonIcon from './images/icon_checkbox.png'
- import inactiveButtonIcon from './images/icon_checkbox_default.png'
- import staffDetafult from './images/staff-default.png'
- import firstDefault from './images/first-default.png'
- import fixedDefault from './images/fixed-default.png'
- import Plyr from 'plyr'
- import 'plyr/dist/plyr.css'
- import Download from './download'
- import { getInstrumentName } from '@/constant/instruments'
- import { getUploadSign, onOnlyFileUpload } from '@/helpers/oss-file-upload'
- import { svgtopng } from './formatSvgToImg'
- import { shareCall } from '@/teacher/share-page/share'
- import deepClone from '@/helpers/deep-clone'
- import { formatXML, getCustomInfo, onlyVisible } from './instrument'
- export default defineComponent({
- name: 'new-index',
- setup() {
- localStorage.setItem('behaviorId', getRandomKey())
- const router = useRouter()
- const route = useRoute()
- const loading = ref(false)
- const background = ref<string>('rgba(55, 205, 177, 0)')
- const color = ref<string>('#fff')
- const aId = Number(route.query.activityId) || 0
- const studentActivityId = ref(aId)
- const isError = ref(false)
- const headers = ref(null)
- const footers = ref(null)
- const heightInfo = ref<any>('0')
- const musicDetail = ref<any>(null)
- const audioFileUrl = ref('')
- const showImg = ref([] as any)
- const firstList = ref<Array<any>>([])
- const fixedList = ref<Array<any>>([])
- const staffList = ref<Array<any>>([])
- const uploadImgs = ref<boolean>(false)
- const defaultImgs = ref({
- first: false,
- fixed: false,
- staff: false
- })
- const accompanyUrl = ref<string>('')
- const downloadStatus = ref<boolean>(false)
- const staff = reactive({
- status: false,
- radio: 'staff' // staff first fixed
- })
- const colors: any = {
- FREE: {
- color: '#88D5AC',
- text: '免费'
- },
- VIP: {
- color: '#FFFA6B',
- text: '会员'
- },
- CHARGE: {
- color: '#AEFAFF',
- text: '点播'
- }
- }
- const apiSuffix = ref(
- baseState.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
- )
- // 更改预览状态
- const onChangeStaff = (type: string) => {
- staff.radio = type
- staff.status = false
- if (type == 'first' && !defaultImgs.value.first) {
- loading.value = false
- resetRenderPage('first', staffData.musicXml)
- } else if (type == 'fixed' && !defaultImgs.value.fixed) {
- loading.value = false
- resetRenderPage('fixed', staffData.musicXml)
- } else {
- if (!defaultImgs.value.staff) {
- loading.value = false
- resetRenderPage('staff', staffData.musicXml)
- }
- }
- }
- watch(
- () => staff.radio,
- (val: string) => {
- if (val == 'first') {
- showImg.value = deepClone(firstList.value)
- } else if (val == 'fixed') {
- showImg.value = deepClone(fixedList.value)
- } else {
- showImg.value = deepClone(staffList.value)
- }
- }
- )
- const FetchList = async (id?: any) => {
- if (loading.value) {
- return
- }
- loading.value = true
- isError.value = false
- try {
- const res = await request.get(`/music/sheet/detail/${route.query.id}`, {
- prefix:
- state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student',
- params: {
- tenantAlbumId: route.query.tenantAlbumId || null
- }
- })
- musicDetail.value = res.data
- // 取原音,如果有多个则默认第一个
- const background = res.data.background
- audioFileUrl.value =
- background && background.length > 0 ? background[0].audioFileUrl : ''
- showImg.value = res.data.musicImg ? res.data.musicImg.split(',') : []
- firstList.value = res.data.firstTone
- ? res.data.firstTone.split(',')
- : []
- fixedList.value = res.data.fixedTone
- ? res.data.fixedTone.split(',')
- : []
- staffList.value = res.data.musicImg ? res.data.musicImg.split(',') : []
- // 初始化默认数据是否有值
- if (firstList.value.length > 0) {
- defaultImgs.value.first = true
- }
- if (fixedList.value.length > 0) {
- defaultImgs.value.fixed = true
- }
- if (staffList.value.length > 0) {
- defaultImgs.value.staff = true
- }
- nextTick(() => {
- renderStaff()
- })
- } catch (error) {
- isError.value = true
- }
- if (musicDetail.value?.musicSheetType !== 'CONCERT') {
- loading.value = false
- }
- }
- const base64ToBlob = data => {
- const arr = data.split(','),
- mime = arr[0].match(/:(.*?);/)[1]
- const bstr = atob(arr[1])
- let n = bstr.length
- const u8arr = new Uint8Array(n)
- while (n--) {
- u8arr[n] = bstr.charCodeAt(n)
- }
- return new Blob([u8arr], { type: mime })
- }
- const uploadFunction = async file => {
- try {
- const formData = new FormData()
- const fileName =
- new Date().getTime() + Math.ceil(Math.random() * 1000) + '.png'
- const keyTime = new Date().getTime() + fileName
- const obj = {
- filename: keyTime,
- bucketName: 'cloud-coach',
- postData: {
- filename: keyTime,
- acl: 'public-read',
- key: keyTime
- }
- }
- // const res = await request.post(state.platformApi + '/getUploadSign', {
- // data: obj
- // })
- const res = await getUploadSign(obj)
- Toast.loading({
- message: '加载中...',
- forbidClick: true,
- loadingType: 'spinner',
- duration: 0
- })
- const dataObj = {
- policy: res.data.policy,
- signature: res.data.signature,
- key: keyTime,
- KSSAccessKeyId: res.data.kssAccessKeyId,
- acl: 'public-read',
- name: fileName
- }
- const files = base64ToBlob(file)
- const ossUploadUrl = getOssUploadUrl('cloud-coach')
- const imgurl = await onOnlyFileUpload(ossUploadUrl, {
- ...dataObj,
- file: files
- })
- Toast.clear()
- // const imgurl = getOssUploadUrl('cloud-coach') + keyTime
- await request.post(state.platformApi + '/open/music/sheet/img', {
- data: { musicSheetId: musicDetail.value.id, musicImg: imgurl }
- })
- // showImg.value.value = imgurl
- } catch (e) {
- console.log(e)
- }
- }
- const setAccompanyUrl = () => {
- let url = location.origin
- if (
- location.host.includes('dev.colexiu') ||
- location.host.includes('192.168') ||
- location.host.includes('localhost')
- ) {
- url = 'https://dev.colexiu.com'
- }
- const music = musicDetail.value
- let subjectId = ''
- if (music.background && music.background.length > 0) {
- subjectId = music.background[0].id
- }
- accompanyUrl.value =
- url +
- `/accompany/colxiu-website.html?id=${music.id}&part-index=${subjectId}`
- }
- const player = ref<any>(null)
- const audio = ref<any>(null)
- const freeRate = ref<any>(0)
- const initAudio = async () => {
- const controls = [
- // 'play-large',
- 'play',
- 'progress',
- 'captions',
- // 'fullscreen',
- 'duration'
- ]
- player.value = new Plyr(audio.value, {
- controls: controls
- })
- const config = await request.get(
- '/api-student/sysConfig/queryByParamNameList',
- {
- params: {
- paramNames: 'music_sheet_free_rate'
- }
- }
- )
- freeRate.value = config.data[0]?.paramValue || 0
- player.value.on('timeupdate', () => {
- // 允许播放时间
- const players = player.value
- const playTime = (players.duration * freeRate.value) / 100 || 0
- // 时间,不能播放
- if (players.currentTime >= playTime && !buyState.value.play) {
- players.stop()
- // players.pause()
- }
- })
- }
- const showLoading = async (e: any) => {
- // console.log(e, 'showLoading')
- if (e.data?.api === 'musicStaffRender') {
- const osmdImg = e.data.osmdImg
- showImg.value = []
- const imgs: any = []
- // 独奏并且的图片则不用生成
- if (
- musicDetail.value?.musicSheetType === 'SINGLE' &&
- musicDetail.value?.notation
- ) {
- if (
- (staff.radio === 'first' && firstList.value.length > 0) ||
- (staff.radio === 'fixed' && fixedList.value.length > 0) ||
- (staff.radio === 'staff' && staffList.value.length > 0)
- ) {
- if (staff.radio === 'first') {
- showImg.value = firstList.value
- } else if (staff.radio === 'fixed') {
- showImg.value = fixedList.value
- }
- if (staff.radio === 'staff') {
- showImg.value = staffList.value
- }
- loading.value = e.data.loading
- return
- }
- }
- uploadImgs.value = true
- if (osmdImg) {
- for (let i = 0; i < osmdImg.length; i++) {
- const img = await svgtopng(
- osmdImg[i].img,
- osmdImg[i].width,
- osmdImg[i].height
- )
- const fileName =
- route.query.id + state.user.data.userId + +new Date() + '.png'
- const obj = {
- filename: fileName,
- bucketName: 'cloud-coach',
- postData: {
- filename: fileName,
- acl: 'public-read',
- key: fileName
- }
- }
- const { data } = await getUploadSign(obj, true)
- const dataObj = {
- policy: data.policy,
- signature: data.signature,
- key: fileName,
- KSSAccessKeyId: data.kssAccessKeyId,
- acl: 'public-read',
- name: fileName
- }
- const files = base64ToBlob(img)
- const ossUploadUrl = getOssUploadUrl('cloud-coach')
- const imgurl = await onOnlyFileUpload(ossUploadUrl, {
- ...dataObj,
- file: files
- })
- imgs.push(imgurl)
- }
- }
- uploadImgs.value = false
- // 判断是否为独奏
- if (
- musicDetail.value?.musicSheetType === 'SINGLE' &&
- musicDetail.value?.notation
- ) {
- if (staff.radio === 'first') {
- firstList.value = imgs
- } else if (staff.radio === 'fixed') {
- fixedList.value = imgs
- } else if (staff.radio === 'staff') {
- staffList.value = imgs
- }
- showImg.value = imgs
- } else {
- showImg.value = imgs
- }
- loading.value = e.data.loading
- }
- }
- onMounted(async () => {
- postMessage({
- api: 'setStatusBarTextColor',
- content: { statusBarTextColor: true }
- })
- await FetchList()
- const { height } = useRect(headers as any)
- const footer = useRect(footers as any)
- heightInfo.value = height + footer.height
- // 初始化音频
- if (audioFileUrl.value) {
- initAudio()
- }
- window.addEventListener('message', showLoading)
- })
- onUnmounted(() => {
- postMessage({
- api: 'setStatusBarTextColor',
- content: { statusBarTextColor: false }
- })
- window.removeEventListener('message', showLoading)
- })
- const toggleFavorite = async () => {
- try {
- await request.post('/music/sheet/favorite/' + musicDetail.value?.id, {
- prefix:
- state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student'
- })
- musicDetail.value.favorite = musicDetail.value?.favorite ? 0 : 1
- musicDetail.value.favoriteCount = musicDetail.value?.favorite
- ? musicDetail.value.favoriteCount + 1
- : musicDetail.value.favoriteCount - 1 < 0
- ? 0
- : musicDetail.value.favoriteCount - 1
- setTimeout(() => {
- Toast(musicDetail.value?.favorite ? '收藏成功' : '取消收藏成功')
- }, 100)
- } catch (error) {
- //
- }
- }
- const onAddCourse = async () => {
- try {
- const res = await request.post('/api-teacher/courseCourseware/submit', {
- data: {
- musicSheetId: musicDetail.value.id,
- clientType: 'TEACHER',
- userId: state.user.data?.userId
- }
- })
- // console.log(res)
- setTimeout(() => {
- musicDetail.value.coursewareId = res.data.id || ''
- Toast('添加成功')
- musicDetail.value.coursewareStatus = 1
- }, 100)
- } catch {
- //
- }
- }
- const removeCourse = async () => {
- Dialog.confirm({
- title: '提示',
- message: '您是否确定移除课件',
- confirmButtonColor: '#269a93',
- cancelButtonText: '取消',
- confirmButtonText: '确定'
- }).then(async () => {
- try {
- await request.post(
- '/api-teacher/courseCourseware/remove/' +
- musicDetail.value.coursewareId,
- {
- data: {}
- }
- )
- setTimeout(() => {
- Toast('移除成功')
- musicDetail.value.coursewareStatus = 0
- }, 100)
- } catch {
- //
- }
- })
- }
- const onBuy = async () => {
- const music = musicDetail.value
- orderStatus.orderObject.orderType = 'MUSIC'
- orderStatus.orderObject.orderName = music.musicSheetName
- orderStatus.orderObject.orderDesc = music.musicSheetName
- orderStatus.orderObject.actualPrice = music.musicPrice
- orderStatus.orderObject.recomUserId = route.query.recomUserId || 0
- orderStatus.orderObject.activityId = route.query.activityId || 0
- orderStatus.orderObject.orderNo = ''
- orderStatus.orderObject.orderList = [
- {
- orderType: 'MUSIC',
- goodsName: music.musicSheetName,
- actualPrice: music.musicPrice,
- ...music
- }
- ]
- const res = await request.post('/api-student/userOrder/getPendingOrder', {
- data: {
- goodType: 'MUSIC',
- bizId: music.id
- }
- })
- const result = res.data
- if (result) {
- Dialog.confirm({
- title: '提示',
- message: '您有一个未支付的订单,是否继续支付?',
- theme: 'round-button',
- className: 'confirm-button-group',
- cancelButtonText: '取消订单',
- confirmButtonText: '继续支付'
- })
- .then(async () => {
- orderStatus.orderObject.orderNo = result.orderNo
- orderStatus.orderObject.actualPrice = result.actualPrice
- orderStatus.orderObject.discountPrice = result.discountPrice
- orderStatus.orderObject.paymentConfig = {
- ...result.paymentConfig,
- paymentVendor: result.paymentVendor,
- paymentVersion: result.paymentVersion
- }
- routerTo()
- })
- .catch(() => {
- Dialog.close()
- // 只用取消订单,不用做其它处理
- cancelPayment(result.orderNo)
- })
- } else {
- routerTo()
- }
- }
- const routerTo = () => {
- const music = musicDetail.value
- router.push({
- path: '/orderDetail',
- query: {
- orderType: 'MUSIC',
- musicId: music.id
- }
- })
- }
- const cancelPayment = async (orderNo: string) => {
- try {
- await request.post('/api-student/userOrder/orderCancel', {
- data: {
- orderNo
- }
- })
- } catch {
- //
- }
- }
- const paymentType = computed(() => {
- let paymentType = musicDetail.value?.paymentType
- if (typeof paymentType === 'string') {
- paymentType = paymentType.split(',')
- return paymentType
- }
- return []
- })
- const buyState = computed(() => {
- const music = musicDetail.value
- return {
- hasTenantAlbum: route.query?.tenantAlbumId ? true : false, // 是否从专辑来的
- play: music.play ? true : false, // 是否可以播放
- free: music?.paymentType.includes('FREE'),
- charge: music?.paymentType.includes('CHARGE'),
- vip: music?.paymentType.includes('VIP'),
- buy: music?.orderStatus === 'PAID' // 是否已买
- }
- })
- const shareStatus = ref(false)
- const shareUrl = ref('')
- const shareDiscount = ref(0)
- const onShare = async () => {
- try {
- const res = await request.post('/api-teacher/open/musicShareProfit', {
- data: {
- bizId: musicDetail.value?.id,
- userId: state.user.data?.userId
- }
- })
- let url =
- location.origin +
- `/teacher/#/shareMusic?id=${musicDetail.value?.id}&recomUserId=${state.user.data?.userId}&userType=${state.platformType}`
- // 判断是否有活动
- if (res.data.discount === 1) {
- url += `&activityId=${res.data.activityId}`
- }
- shareDiscount.value = res.data.discount || 0
- console.log(url)
- shareUrl.value = url
- shareStatus.value = true
- return
- } catch {
- //
- }
- }
- const staffData = reactive({
- open: false,
- iframeSrc: '',
- musicXml: '',
- instrumentName: '',
- iframeRef: null as any,
- partIndex: 0,
- partXmlIndex: 0,
- partList: [] as any[],
- tempPartList: [] as any[],
- xmlPartList: [] as any[]
- })
- /** 渲染五线谱 */
- // 长笛、单簧管、萨克斯、小号、长号、圆号、大号、上低音号
- const sortList = {
- 长笛: 1,
- 单簧管: 2,
- 中音单簧管: 3,
- 低音单簧管: 4,
- 高音萨克斯风: 5,
- 中音萨克斯风: 6,
- 次中音萨克斯风: 7,
- 低音萨克斯风: 8,
- 小号: 9,
- 长号: 10,
- 圆号: 11,
- 大号: 12,
- 上低音号: 13
- }
- const instrumentSort = (list: Array<any>) => {
- list.sort((a, b) => {
- return (
- (sortList[getInstrumentName(a.track)] || 20) -
- (sortList[getInstrumentName(b.track)] || 20)
- )
- })
- return list
- }
- const renderStaff = async () => {
- try {
- if (musicDetail.value?.xmlFileUrl) {
- // 获取文件
- const res = await umiRequest.get(musicDetail.value?.xmlFileUrl, {
- mode: 'cors'
- })
- let partNames: string[] = []
- const xml: any = new DOMParser().parseFromString(res, 'text/xml')
- for (const item of xml.getElementsByTagName('part-name')) {
- if (item.textContent) {
- partNames.push(item.textContent)
- }
- }
- partNames = partNames.filter(
- (item: any) => !item?.toLocaleUpperCase()?.includes('COMMON')
- )
- const partList: any = []
- for (let j = 0; j < partNames.length; j++) {
- partList.push({
- name: partNames[j],
- value: j
- })
- }
- staffData.xmlPartList = partList
- }
- // staffData.iframeSrc = `${
- // location.origin
- // }/osmd/index.html?t=${new Date().getTime()}`
- staffData.iframeSrc = `${location.origin}${
- location.pathname
- }osmd/index.html?t=${new Date().getTime()}`
- staffData.musicXml = musicDetail.value?.xmlFileUrl || ''
- const tempList = musicDetail.value?.background || []
- const tempPartList = [] as any
- staffData.xmlPartList.forEach((part: any) => {
- const item = tempList.find((item: any) => item.track === part.name)
- if (item) {
- tempPartList.push({
- ...item,
- index: part.value
- })
- }
- })
- staffData.partList = tempPartList
- console.log(
- staffData.partList,
- tempPartList,
- 'staffData.partList',
- tempList
- )
- staffData.tempPartList = JSON.parse(JSON.stringify(staffData.partList))
- staffData.partList = instrumentSort(staffData.partList)
- // console.log(staffData.partList, ' staffData.partList')
- staffData.partXmlIndex = staffData.partList[0].index || 0
- staffData.instrumentName =
- musicDetail.value?.musicSheetType === 'CONCERT'
- ? getInstrumentName(staffData.partList[staffData.partIndex]?.track)
- : ''
- // console.log(staffData.partList, 'staffData', staffData.xmlPartList)
- } catch (error) {
- //
- }
- }
- const musicIframeLoad = async () => {
- const iframeRef: any = document.getElementById('staffIframeRef')
- if (iframeRef && iframeRef.contentWindow.renderXml) {
- const res = await umiRequest.get(staffData.musicXml, {
- mode: 'cors'
- })
- const parseXmlInfo = getCustomInfo(res)
- const xml = formatXML(parseXmlInfo.parsedXML)
- const currentXml = onlyVisible(xml, staffData.partXmlIndex)
- iframeRef.contentWindow.renderXml(currentXml, 0)
- // iframeRef.contentWindow.renderXml(
- // staffData.musicXml,
- // staffData.partXmlIndex
- // )
- }
- }
- const resetRender = async () => {
- const iframeRef: any = document.getElementById('staffIframeRef')
- if (iframeRef && iframeRef.contentWindow.renderXml) {
- loading.value = true
- // iframeRef.contentWindow.resetRender(staffData.partXmlIndex)
- const res = await umiRequest.get(staffData.musicXml, {
- mode: 'cors'
- })
- const parseXmlInfo = getCustomInfo(res)
- const xml = formatXML(parseXmlInfo.parsedXML)
- const currentXml = onlyVisible(xml, staffData.partXmlIndex)
- iframeRef.contentWindow.renderXml(currentXml, 0)
- staffData.instrumentName = getInstrumentName(
- staffData.partList[staffData.partIndex]?.track
- )
- }
- }
- const resetRenderPage = async (type: string, xmlUrl: string) => {
- const iframeRef: any = document.getElementById('staffIframeRef')
- if (iframeRef && iframeRef.contentWindow.renderXml) {
- // console.log('resetRenderPage')
- // iframeRef.contentWindow.resetRenderPage(type, xmlUrl)
- const res = await umiRequest.get(staffData.musicXml, {
- mode: 'cors'
- })
- const parseXmlInfo = getCustomInfo(res)
- const xml = formatXML(parseXmlInfo.parsedXML)
- const currentXml = onlyVisible(xml, staffData.partXmlIndex)
- iframeRef.contentWindow.resetRenderPage(type, currentXml)
- }
- }
- const partColumns = computed(() => {
- return staffData.partList.map((item: any, index: number) => {
- const instrumentName =
- musicDetail.value?.musicSheetType === 'CONCERT'
- ? getInstrumentName(item.track)
- : ''
- return {
- text: item.track + (instrumentName ? `(${instrumentName})` : ''),
- value: index,
- xmlValue: item.index,
- track: item.track
- }
- })
- })
- const onDownloadApp = () => {
- Dialog.alert({
- title: '提示',
- message: '请在酷乐秀APP中使用',
- confirmButtonColor: '#2dc7aa'
- }).then(() => {
- window.location.href = location.origin + '/student/#/download'
- })
- }
- // 购买
- const onSubmit = async () => {
- const url =
- apiSuffix.value +
- '/tenantGroupAlbum/buyAlbumInfo?tenantGroupAlbumId=' +
- (route.query.taId || '')
- // if (state.albumId) {
- // url = url + '?albumId=' + state.albumId
- // }
- const { data } = await request.get(url)
- const details = data[0]
- orderStatus.orderObject.orderType = 'TENANT_ALBUM'
- orderStatus.orderObject.orderName = details.name
- orderStatus.orderObject.orderDesc = details.name
- orderStatus.orderObject.actualPrice = details.actualPrice
- // orderStatus.orderObject.recomUserId = route.query.recomUserId || 0
- // orderStatus.orderObject.activityId = route.query.activityId || 0
- orderStatus.orderObject.orderNo = ''
- orderStatus.orderObject.orderList = [
- {
- orderType: 'TENANT_ALBUM',
- goodsName: details.name,
- actualPrice: details.actualPrice,
- price: details.actualPrice,
- ...details
- }
- ]
- const res = await request.post('/api-student/userOrder/getPendingOrder', {
- data: {
- goodType: 'TENANT_ALBUM',
- bizId: details.id
- }
- })
- const result = res.data
- if (result) {
- Dialog.confirm({
- title: '提示',
- message: '您有一个未支付的订单,是否继续支付?',
- theme: 'round-button',
- className: 'confirm-button-group',
- cancelButtonText: '取消订单',
- confirmButtonText: '继续支付'
- })
- .then(async () => {
- orderStatus.orderObject.orderNo = result.orderNo
- orderStatus.orderObject.actualPrice = result.actualPrice
- orderStatus.orderObject.discountPrice = result.discountPrice
- orderStatus.orderObject.paymentConfig = {
- ...result.paymentConfig,
- paymentVendor: result.paymentVendor,
- paymentVersion: result.paymentVersion
- }
- routerToALBUM(details.id)
- })
- .catch(() => {
- Dialog.close()
- // 只用取消订单,不用做其它处理
- cancelPaymentALBUM(result.orderNo)
- })
- } else {
- routerToALBUM(details.id)
- }
- }
- const cancelPaymentALBUM = async (orderNo: string) => {
- try {
- await request.post('/api-student/userOrder/orderCancel/v2', {
- data: {
- orderNo
- }
- })
- } catch {
- //
- }
- }
- const routerToALBUM = (id: string) => {
- router.push({
- path: '/orderDetail',
- query: {
- orderType: 'ALBUM',
- album: id
- }
- })
- }
- return () => (
- <div class={styles.detail}>
- <TheSticky position="top">
- <ColHeader
- background={background.value}
- border={false}
- isFixed={false}
- color={color.value}
- backIconColor="white"
- />
- </TheSticky>
- <img class={styles.bgImg} src={musicDetail.value?.titleImg} />
- <div class={styles.musicContentBg}></div>
- <div class={styles.bg}>
- <div class={styles.alumWrap}>
- <div class={styles.img}>
- {/* {albumDetail.value?.paymentType === 'CHARGE' && (
- <span class={styles.albumType}>付费</span>
- )} */}
- <Image
- class={styles.image}
- width="100%"
- height="100%"
- fit="cover"
- src={musicDetail.value?.titleImg}
- />
- </div>
- <div class={styles.alumDes}>
- <div class={[styles.alumTitle, 'van-ellipsis']}>
- {musicDetail.value?.musicSheetName}
- </div>
- <div class={[styles.des, 'van-multi-ellipsis--l2']}>
- {!musicDetail.value?.composer
- ? `上传者:${musicDetail.value?.addName || ''}`
- : `作曲:${musicDetail.value?.composer || ''}`}
- </div>
- <div class={styles.tags}>
- {musicDetail.value?.id && (
- <>
- {musicDetail.value?.musicTagNames &&
- musicDetail.value?.musicTagNames.split(',').map(name => (
- <span
- style={{
- borderColor: colors.FREE.color,
- color: colors.FREE.color
- }}
- class={styles.tag}
- >
- {name}
- </span>
- ))}
- </>
- )}
- </div>
- </div>
- </div>
- <div
- class={[
- styles.alumCollect
- // musicDetail.value?.musicSheetType === 'CONCERT'
- // ? styles.alumCollectCencert
- // : ''
- ]}
- >
- <div
- class={styles.alumCollectItem}
- onClick={() => {
- if (browser().isApp) {
- onShare()
- } else {
- onDownloadApp()
- }
- }}
- >
- <Image src={iconShare} />
- <span>分享</span>
- </div>
- {/* {musicDetail.value?.musicSheetType !== 'CONCERT' && ( */}
- <div
- class={[
- styles.alumCollectItem,
- showImg.value.length <= 0 ? styles.alumCollectItemActive : ''
- ]}
- onClick={() => {
- if (browser().isApp) {
- if (showImg.value.length > 0) {
- downloadStatus.value = true
- }
- } else {
- onDownloadApp()
- }
- }}
- >
- <img src={iconDownload} />
- <span>下载</span>
- </div>
- {/* )} */}
- <div
- class={styles.alumCollectItem}
- onClick={() => toggleFavorite()}
- >
- <img src={musicDetail.value?.favorite ? iStart : oStart} />
- <span>{musicDetail.value?.favoriteCount}</span>
- </div>
- </div>
- {/* {buyState.value.hasTenantAlbum ? 'true' : 'false'} */}
- {musicDetail.value?.id &&
- !buyState.value.play &&
- !buyState.value.hasTenantAlbum && (
- <div class={styles.albumTips}>
- {buyState.value.charge && buyState.value.vip ? (
- <>
- <span>开通会员或点播单曲,即可自由练习该曲谱</span>
- <span class={styles.albumPrice}>
- ¥{moneyFormat(musicDetail.value?.musicPrice)}
- </span>
- </>
- ) : buyState.value.vip ? (
- <span>
- <img src={iconMemberSmall} class={styles.iconMemberSmall} />
- 此曲谱为会员专享,开通会员即可自由练习该曲谱
- </span>
- ) : buyState.value.charge ? (
- <>
- <span>此曲谱为点播曲谱,点播即可自由练习该曲谱</span>
- <span class={styles.albumPrice}>
- ¥{moneyFormat(musicDetail.value?.musicPrice)}
- </span>
- </>
- ) : (
- ''
- )}
- </div>
- )}
- </div>
- <div class={styles.musicContent}>
- {musicDetail.value?.notation ? (
- <span
- class={styles.iconTransfer}
- style={{
- display:
- musicDetail.value?.musicSheetType === 'SINGLE' ? '' : 'none',
- opacity: showImg.value.length <= 0 ? 0.6 : 1
- }}
- onClick={() => {
- if (showImg.value.length <= 0) return
- staff.status = true
- }}
- >
- 转谱
- </span>
- ) : null}
- <span
- class={styles.iconTransfer}
- style={{
- display:
- musicDetail.value?.musicSheetType === 'CONCERT' ? '' : 'none'
- }}
- onClick={() => {
- staffData.open = true
- }}
- >
- 切换声轨
- </span>
- <p class={styles.musicTitle}>
- {(musicDetail.value?.musicSheetName
- ? musicDetail.value?.musicSheetName
- : '') +
- (staffData.instrumentName ? `(${staffData.instrumentName})` : '')}
- </p>
- {musicDetail.value?.musicSheetType === 'CONCERT' ||
- !defaultImgs.value[staff.radio] ? (
- <>
- {loading.value && (
- <div>
- <Vue3Lottie
- animationData={AstronautJSON}
- class={styles.finch}
- ></Vue3Lottie>
- {/* <p class={styles.finchLoad}>加载中...</p> */}
- </div>
- )}
- <iframe
- id="staffIframeRef"
- style={{
- opacity: loading.value ? 0 : 1
- }}
- src={staffData.iframeSrc}
- onLoad={() => {
- if (!defaultImgs.value[staff.radio]) {
- onChangeStaff(staff.radio)
- } else {
- musicIframeLoad()
- }
- }}
- ></iframe>
- {/* <OsmdPreview ref={osmdPreviewRef} /> */}
- </>
- ) : (
- <>
- {showImg.value.length > 0 ? (
- <div class={styles.musicImg}>
- <img src={showImg.value[0]} alt="" />
- </div>
- ) : loading.value ? (
- <>
- <Vue3Lottie
- animationData={AstronautJSON}
- class={styles.finch}
- ></Vue3Lottie>
- {/* <p class={styles.finchLoad}>加载中...</p> */}
- </>
- ) : (
- <div class={styles.empty}>
- <Image src={emtpy} class={styles.emptyImg} />
- <p class={styles.emptyTip}>暂无乐谱预览图</p>
- </div>
- )}
- </>
- )}
- </div>
- {musicDetail.value?.id && (
- <TheSticky position="bottom">
- <div style={{ backgroundColor: '#fff' }}>
- <div class={styles.videoOperation}>
- {audioFileUrl.value && (
- <>
- {!buyState.value.play &&
- freeRate.value != 100 &&
- freeRate.value != 0 && (
- <div class={[styles.audition]}>
- <img src={iconListen} />
- <span>每首曲目可试听{freeRate.value}%</span>
- </div>
- )}
- <div class={[styles.audio, styles.collectCell]}>
- <audio id="player" controls ref={audio}>
- <source src={audioFileUrl.value} type="audio/mp3" />
- </audio>
- </div>
- </>
- )}
- </div>
- <div ref={footers} class={styles.footers}>
- {/* 判断是否是免费的,或者已经购买过 */}
- {buyState.value.play ? (
- <Button
- round
- block
- type="primary"
- color="linear-gradient( 270deg, #FF204B 0%, #FE5B71 100%)"
- onClick={() => {
- if (!browser().isApp) {
- onDownloadApp()
- return
- }
- const throttleFn = useThrottleFn(() => {
- player.value && player.value.stop()
- const item: any = partColumns.value.find(
- (c: any) => c.value === staffData.partIndex
- )
- // const index = staffData.tempPartList.findIndex(
- // (i: any) => i.track === item?.track
- // )
- musicBuy(musicDetail.value, () => {}, {
- 'part-index': item.xmlValue || 0,
- sett: staff.radio,
- // 1:忽略系统节拍器
- ignoreSysMetronome:
- route.query.subjectType === 'MUSIC' ? 1 : 0
- })
- }, 500)
- throttleFn()
- }}
- >
- 立即练习
- </Button>
- ) : buyState.value.hasTenantAlbum && !buyState.value.play ? (
- <Button
- disabled={route.query.buyStatus === '1'}
- round
- block
- type="primary"
- color="linear-gradient( 270deg, #FF204B 0%, #FE5B71 100%)"
- onClick={() => {
- if (!browser().isApp) {
- onDownloadApp()
- return
- }
- if (route.query.type === 'search') {
- router.push('train-tool')
- } else {
- onSubmit()
- }
- }}
- >
- 开通训练教程
- </Button>
- ) : (
- <div class={[styles.buyBtn]}>
- {/* 判断是否是需要收费的 */}
- {buyState.value.charge && (
- <Button
- round
- type="primary"
- color="linear-gradient(270deg, #FF204B 0%, #FE5B71 100%)"
- class={styles.primary}
- onClick={() => {
- if (!browser().isApp) {
- onDownloadApp()
- return
- }
- onBuy()
- }}
- >
- 立即点播
- </Button>
- )}
- {/* 判断是否有会员的 */}
- {buyState.value.vip && (
- <Button
- round
- block={!buyState.value.charge ? true : false}
- type="primary"
- color="linear-gradient(270deg, #FF204B 0%, #FE5B71 100%)"
- class={styles.memeber}
- onClick={() => {
- if (!browser().isApp) {
- onDownloadApp()
- return
- }
- router.push({
- path: '/memberCenter',
- query: {
- ...route.query
- }
- })
- }}
- >
- {studentActivityId.value > 0 && (
- <div class={[styles.buttonDiscount]}>专属优惠</div>
- )}
- 开通会员
- </Button>
- )}
- </div>
- )}
- </div>
- </div>
- </TheSticky>
- )}
- <Popup
- v-model:show={shareStatus.value}
- style={{ background: 'transparent' }}
- teleport="body"
- >
- <ColShare
- teacherId={state.user.data?.userId}
- shareUrl={shareUrl.value}
- shareType="music"
- type="tenant"
- >
- <div class={styles.shareMate}>
- {shareDiscount.value === 1 && (
- <div class={styles.tagDiscount}>专属优惠</div>
- )}
- <img
- class={styles.icon}
- crossorigin="anonymous"
- src={musicDetail.value?.titleImg + `?t=${+new Date()}`}
- />
- <div class={styles.info}>
- <h4 class="van-multi-ellipsis--l2">
- {musicDetail.value?.musicSheetName}
- </h4>
- <p>作曲人:{musicDetail.value?.composer}</p>
- </div>
- </div>
- </ColShare>
- </Popup>
- <Popup v-model:show={downloadStatus.value} position="bottom" round>
- {downloadStatus.value && (
- <Download
- imgList={JSON.parse(JSON.stringify(showImg.value))}
- musicSheetName={musicDetail.value.musicSheetName}
- />
- )}
- </Popup>
- <Popup
- v-model:show={staff.status}
- teleport="body"
- closeable
- style={{ width: '80%' }}
- class={styles.staffChange}
- round
- >
- <div class={styles.staffContainer}>
- <div class={styles.staffTitle}>选择转换曲谱</div>
- <RadioGroup v-model={staff.radio}>
- <CellGroup border={false}>
- <Cell
- center
- border={false}
- class={staff.radio === 'staff' ? styles.active : ''}
- onClick={() => onChangeStaff('staff')}
- >
- {{
- icon: () => (
- <Image src={staffDetafult} class={styles.staffImg} />
- ),
- title: () => <span class={styles.name}>五线谱</span>,
- value: () => (
- <Radio name="staff">
- {{
- icon: (props: any) => (
- <Icon
- class={styles.boxStyle}
- name={
- props.checked
- ? activeButtonIcon
- : inactiveButtonIcon
- }
- />
- )
- }}
- </Radio>
- )
- }}
- </Cell>
- <Cell
- center
- border={false}
- class={staff.radio === 'first' ? styles.active : ''}
- onClick={() => onChangeStaff('first')}
- >
- {{
- icon: () => (
- <Image src={firstDefault} class={styles.staffImg} />
- ),
- title: () => <span class={styles.name}>简谱-首调</span>,
- value: () => (
- <Radio name="first">
- {{
- icon: (props: any) => (
- <Icon
- class={styles.boxStyle}
- name={
- props.checked
- ? activeButtonIcon
- : inactiveButtonIcon
- }
- />
- )
- }}
- </Radio>
- )
- }}
- </Cell>
- <Cell
- center
- border={false}
- class={staff.radio === 'fixed' ? styles.active : ''}
- onClick={() => onChangeStaff('fixed')}
- >
- {{
- icon: () => (
- <Image src={fixedDefault} class={styles.staffImg} />
- ),
- title: () => <span class={styles.name}>简谱-固定调</span>,
- value: () => (
- <Radio name="fixed">
- {{
- icon: (props: any) => (
- <Icon
- class={styles.boxStyle}
- name={
- props.checked
- ? activeButtonIcon
- : inactiveButtonIcon
- }
- />
- )
- }}
- </Radio>
- )
- }}
- </Cell>
- </CellGroup>
- </RadioGroup>
- </div>
- </Popup>
- <Popup
- teleport="body"
- position="bottom"
- round
- v-model:show={staffData.open}
- >
- <Picker
- columns={partColumns.value}
- onConfirm={value => {
- staffData.open = false
- staffData.partIndex = value.value
- staffData.partXmlIndex = value.xmlValue
- showImg.value = []
- nextTick(() => {
- resetRender()
- })
- }}
- onCancel={() => (staffData.open = false)}
- />
- </Popup>
- </div>
- )
- }
- })
|