lex-xin 7 months ago
parent
commit
8c8768ed4d
2 changed files with 585 additions and 526 deletions
  1. 427 327
      src/tenant/music/music-detail/new-index.tsx
  2. 158 199
      src/views/music/music-detail/index.tsx

File diff suppressed because it is too large
+ 427 - 327
src/tenant/music/music-detail/new-index.tsx


+ 158 - 199
src/views/music/music-detail/index.tsx

@@ -67,11 +67,11 @@ import Download from './download'
 import { getInstrumentName } from '@/constant/instruments'
 import { svgtopng } from '@/tenant/music/music-detail/formatSvgToImg'
 import { useThrottleFn } from '@vueuse/core'
-import {
-  formatXML,
-  getCustomInfo,
-  onlyVisible
-} from '@/tenant/music/music-detail/instrument'
+// import {
+//   formatXML,
+//   getCustomInfo,
+//   onlyVisible
+// } from '@/tenant/music/music-detail/instrument'
 
 export const getAssetsHomeFile = (fileName: string) => {
   const path = `../component/images/${fileName}`
@@ -93,26 +93,11 @@ export default defineComponent({
     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 staffData = reactive({
-      // open: false,
-      // iframeSrc: '',
-      // musicXml: '',
-      // instrumentName: '',
-      // iframeRef: null as any,
-      // partIndex: 0,
-      // partXmlIndex: 0,
-      // tempPartList: [] as any[],
-      // partList: [] as any[],
-      // xmlPartList: [] as any[]
-
       musicId: route.query.id as any,
+      instrumentId: '', // 声部编号
       isConcert: false, // 是否合奏
       details: {} as any,
       list: [], // 列表数据
@@ -140,15 +125,10 @@ export default defineComponent({
       return partColumns.value.find((item: any) => item.value === staffData.selectedPartIndex)
     })
 
-    const defaultImgs = ref({
-      first: false,
-      fixed: false,
-      staff: false
-    })
     const downloadStatus = ref<boolean>(false)
     const staff = reactive({
       status: false,
-      radio: 'staff' // staff first fixed
+      radio: 'STAVE' // STAVE: 五线谱; JIAN: 固定调; FIRST: 首调
     })
 
     const colors: any = {
@@ -170,41 +150,29 @@ export default defineComponent({
     const onChangeStaff = (type: string) => {
       staff.radio = type
       staff.status = false
-      if (type == 'first') {
+      if (type == 'FIRST') {
         loading.value = false
         const tempPdf = staffData.details?.firstPdfUrl
-        initIframe(tempPdf, 'first', staffData.musicXml)
-      } else if (type == 'fixed') {
+        initIframe(tempPdf, 'FIRST', staffData.musicXml)
+      } else if (type == 'JIAN') {
         loading.value = false
         const tempPdf = staffData.details?.jianPdfUrl
         console.log(tempPdf, 'tempPdf')
-        initIframe(tempPdf, 'fixed', staffData.musicXml)
+        initIframe(tempPdf, 'JIAN', staffData.musicXml)
       } else {
         loading.value = false
         const tempPdf = staffData.details?.musicPdfUrl
-        initIframe(tempPdf, 'staff', staffData.musicXml)
+        initIframe(tempPdf, 'STAVE', staffData.musicXml)
       }
-
     }
 
     const initIframe = (tempPdf: string, staff: string, xml: string) => {
       if (tempPdf) {
         staffData.musicPdfUrl = tempPdf
-        renderStaff()
       } else {
         staffData.musicPdfUrl = ''
-        // 为了处理,之前是使用pdf渲染,现在又用osmd,iframe没有重新加载
-        // if (
-        //   !staffData.iframeSrc ||
-        //   staffData.iframeSrc.indexOf('pdf/web') !== -1
-        // ) {
-        //   renderStaff()
-        // } else {
-        //   resetRenderPage(staff, xml)
-        // }
-
-        renderStaff()
       }
+      renderStaff()
     }
     
     const FetchList = async (id?: any) => {
@@ -215,27 +183,26 @@ export default defineComponent({
       isError.value = false
       try {
         const { data } = await request.get(state.platformType === 'TEACHER' ? '/api-teacher' : '/api-student' + '/musicSheet/cbsDetail/' + route.query.id)
-        musicDetail.value = data
         staffData.details = data
 
         await toDetail(data)
 
 
 
-        // if (res.data.auditStatus === 'DOING') {
-        //   Dialog.confirm({
-        //     message: '曲目审核中',
-        //     showConfirmButton: true,
-        //     showCancelButton: false,
-        //     confirmButtonColor: 'var(--van-primary)'
-        //   }).then(() => {
-        //     if (browser().isApp) {
-        //       postMessage({ api: 'goBack' })
-        //     } else {
-        //       router.back()
-        //     }
-        //   })
-        // }
+        if (data.auditStatus === 'DOING') {
+          Dialog.confirm({
+            message: '曲目审核中',
+            showConfirmButton: true,
+            showCancelButton: false,
+            confirmButtonColor: 'var(--van-primary)'
+          }).then(() => {
+            if (browser().isApp) {
+              postMessage({ api: 'goBack' })
+            } else {
+              router.back()
+            }
+          })
+        }
       } catch (error) {
         isError.value = true
       }
@@ -310,6 +277,12 @@ export default defineComponent({
       }
     }
     onMounted(async () => {
+      const instrumentIds = state.user.data?.instrumentId
+      if(instrumentIds) {
+        const instrumentId = instrumentIds.split(',')[0]
+        staffData.instrumentId = instrumentId
+      }
+        
       postMessage({
         api: 'setStatusBarTextColor',
         content: { statusBarTextColor: true }
@@ -544,30 +517,30 @@ export default defineComponent({
 
     
     /** 渲染五线谱 */
-    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 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 getPartNames = async (xmlUrl: string) => {
       const partNames: string[] = [];
@@ -600,7 +573,7 @@ export default defineComponent({
     // 根据当前选中的声部和曲目筛选出对应的声轨
     function filterSoundCodes(musicalInstruments: any) {
       // 老师端,加上乐器id
-      const instrumentIds = 2160 // appState.instrumentId || appState.user?.instrumentId || route.query.instrumentId
+      const instrumentIds = staffData.instrumentId // appState.instrumentId || appState.user?.instrumentId || route.query.instrumentId
       if (instrumentIds) {
         const { code } =  musicalInstruments.find((item: any) => {
                return instrumentIds == item.id
@@ -614,7 +587,7 @@ export default defineComponent({
    function filterSoundInfo(musicalInstruments: any) {
     if(musicalInstruments.length <= 0) return null
     // 老师端,加上乐器id
-    const instrumentIds = 2160 //appState.instrumentId || appState.user?.instrumentId || route.query.instrumentId
+    const instrumentIds = staffData.instrumentId //appState.instrumentId || appState.user?.instrumentId || route.query.instrumentId
     if (instrumentIds) {
       const item =  musicalInstruments.find((item: any) => {
              return instrumentIds == item.musicalInstrumentId && item.audioPlayType == 'PLAY'
@@ -624,9 +597,23 @@ export default defineComponent({
     return null
   }
 
-  const toDetail = async (row) => {
+  // 获取PDF
+  const getCurrentPdf = (item: any, scoreType: string) => {
+    let pdfUrl = ''
+    if(scoreType === 'FIRST') {
+      pdfUrl = item.firstPdfUrl
+    } else if(scoreType === 'JIAN') {
+      pdfUrl = item.jianPdfUrl
+    } else if(scoreType === 'STAVE') {
+      pdfUrl = item.musicPdfUrl
+    }
+    return pdfUrl || ''
+  }
+
+  const toDetail = async (row: any) => {
     // const partNames = await getPartNames(row.xmlFileUrl);
     // staffData.partNames = partNames;
+    staff.radio = row.scoreType // 默认是什么谱页
     const tempSongList = row.musicSheetSoundList || []
     let partList = tempSongList.filter((item: any) => item.audioPlayType === 'PLAY')
     staffData.list = tempSongList.filter((item: any) => item.audioPlayType === 'PLAY')
@@ -643,7 +630,9 @@ export default defineComponent({
         text: getInstrumentName(item.track as string),
         name: getInstrumentName(item.track as string), // true
         track: item.track,
-        musicPdfUrl: item.soundMusicPdfUrl,
+        musicPdfUrl: item.musicPdfUrl,
+        firstPdfUrl: item.firstPdfUrl,
+        jianPdfUrl: item.jianPdfUrl,
         // xmlIndex,
         value: defaultIndex,
       };
@@ -673,7 +662,7 @@ export default defineComponent({
                     .trim()
           )
         )
-        console.log(defaultShowStaff, 'defaultShowStaff')
+        // console.log(defaultShowStaff, 'defaultShowStaff')
         if(defaultShowStaff) {
           staffData.selectedPartIndex = defaultShowStaff.value
         }
@@ -697,18 +686,18 @@ export default defineComponent({
           name: "总谱",
         });
         // 如果是总谱则默认选中,否则选择
-        console.log(defaultShowStaff, 'defaultShowStaff')
         staffData.selectedPartIndex = row.defaultScoreRender? 0 : defaultShowStaff  ? defaultShowStaff.value : 1
+        let pdfUrl = ''
         if(row.defaultScoreRender) {
-          staffData.musicPdfUrl = row.musicPdfUrl;
+          pdfUrl = getCurrentPdf(row, row.scoreType)
         } else {
-          staffData.musicPdfUrl = defaultShowStaff.musicPdfUrl;
+          staffData.musicPdfUrl = getCurrentPdf(defaultShowStaff, row.scoreType)
         }
+        staffData.musicPdfUrl = pdfUrl
       } else {
         const item = partColumns.value.find((item: any) => item.value === staffData.selectedPartIndex)
-        console.log(item, partColumns.value, staffData.selectedPartIndex, 'selectedPartIndex')
         if (item) {
-          staffData.musicPdfUrl = item.musicPdfUrl;
+          staffData.musicPdfUrl = getCurrentPdf(item, row.scoreType) //item.musicPdfUrl;
         } else {
           staffData.musicPdfUrl = "";
         }
@@ -759,94 +748,56 @@ export default defineComponent({
     href += ('&systemType=' +( state.platformType === "STUDENT" ? `student` : 'teacher'));
     // if (location.pathname.includes("accompany-teacher")) {
     //   href += `&systemType=teacher`;
-    // }    
+    // }
+    //   musicRenderType
+    //   /** 五线谱 */
+    // staff = "staff",
+    // /** 简谱(首调) */
+    // firstTone = "firstTone",
+    // /** 固定音高 */
+    // fixedTone = "fixedTone",
+    if(staff.radio === "STAVE") {
+      href += '&musicRenderType=staff'
+    } else if(staff.radio === 'JIAN') {
+      href += '&musicRenderType=fixedTone'
+    } else if(staff.radio === 'FIRST') {
+      href += '&musicRenderType=firstTone'
+    }
+      
     return href
   };
-    const renderStaff = async () => {
-      try {
-        nextTick(() => {
-          console.log(staffData.musicPdfUrl, 'staffData.musicPdfUrl')
-          if (staffData.musicPdfUrl) {
-            const url = `${location.origin}${
-              location.pathname
-            }pdf/web/viewer-pdf.html?file=${encodeURIComponent(
-              staffData.musicPdfUrl
-            )}&t=${Date.now()}`
-
-            const iframeRef = document.querySelector('#staffIframeRef') as any
-            iframeRef.contentWindow.location.replace(url)
-            staffData.iframeSrc = url
-          } else {
-            const url = getPreViewCloud(staffData.musicId, currentColumn.value.xmlIndex)
-            console.log(url, 'staffIframeRef')
 
-            const iframeRef = document.querySelector('#staffIframeRef') as any
-            iframeRef.contentWindow.location.replace(
-              `${location.origin}${location.pathname}osmd/index.html`
-            )
-            staffData.iframeSrc = url
-          }
-        })
-      } catch (error) {
-        //
-      }
+  const renderStaff = async () => {
+    try {
+      nextTick(() => {
+        console.log(staffData.musicPdfUrl, 'staffData.musicPdfUrl')
+        if (staffData.musicPdfUrl) {
+          const url = `${location.origin}${
+            location.pathname
+          }pdf/web/viewer-pdf.html?file=${encodeURIComponent(
+            staffData.musicPdfUrl
+          )}&t=${Date.now()}`
+
+          const iframeRef = document.querySelector('#staffIframeRef') as any
+          iframeRef.contentWindow.location.replace(url)
+          staffData.iframeSrc = url
+        } else {
+          const url = getPreViewCloud(staffData.musicId, currentColumn.value.xmlIndex)
+          console.log(url, 'staffIframeRef')
+          const iframeRef = document.querySelector('#staffIframeRef') as any
+          iframeRef.contentWindow.location.replace(url)
+          staffData.iframeSrc = url
+        }
+      })
+    } catch (error) {
+      //
     }
+  }
 
     const resetRender = () => {
       const iframeRef: any = document.getElementById("staffIframeRef")
       iframeRef.contentWindow.location.replace(getPreViewCloud(staffData.musicId, currentColumn.value.xmlIndex))
     }
-    // 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, staff.radio)
-
-    //     // iframeRef.contentWindow.renderXml(
-    //     //   staffData.musicXml,
-    //     //   staffData.partXmlIndex
-    //     // )
-    //   }
-    // }
-
-    // const resetRenderPage = async (type: string, xmlUrl: string) => {
-    //   const iframeRef: any = document.getElementById('staffIframeRef')
-    //   if (iframeRef && iframeRef.contentWindow.renderXml) {
-    //     loading.value = true
-    //     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 =
-    //       staffData.details?.musicSheetType === 'CONCERT'
-    //         ? getInstrumentName(item.track)
-    //         : ''
-    //     return {
-    //       text: item.track + (instrumentName ? `(${instrumentName})` : ''),
-    //       value: index,
-    //       instrumentName,
-    //       musicPdfUrl: item.musicPdfUrl,
-    //       firstPdfUrl: item.firstPdfUrl,
-    //       jianPdfUrl: item.jianPdfUrl,
-    //       xmlValue: item.index,
-    //       track: item.track
-    //     }
-    //   })
-    // })
     return () => {
       return (
         <div class={styles.detail}>
@@ -1076,7 +1027,7 @@ export default defineComponent({
                   class={[styles.functionItem, (loading.value ||
                     (!staffData.musicPdfUrl && staffData.imgs.length <= 0)) ? styles.disabled : '']}
                   onClick={() => {
-                    console.log(loading.value, staffData.musicPdfUrl, staffData.imgs, '---------------')
+                    // console.log(loading.value, staffData.musicPdfUrl, staffData.imgs, '---------------')
                     if((loading.value ||
                       (!staffData.musicPdfUrl && staffData.imgs.length <= 0))) return
                     if (staffData.musicPdfUrl) {
@@ -1112,7 +1063,7 @@ export default defineComponent({
                 <>
                   {staffData.musicPdfUrl ? (
                     <>
-                      {loading.value && (
+                      {/* {loading.value && (
                         <>
                           <Vue3Lottie
                             animationData={AstronautJSON}
@@ -1120,7 +1071,7 @@ export default defineComponent({
                           ></Vue3Lottie>
                           <p class={styles.finchLoad}>加载中...</p>
                         </>
-                      )}
+                      )} */}
                       <iframe
                         style={{
                           opacity: loading.value ? 0 : 1,
@@ -1149,7 +1100,7 @@ export default defineComponent({
                           </>
                         )}
                       </p>
-                      {loading.value && (
+                      {/* {loading.value && (
                         <>
                           <Vue3Lottie
                             animationData={AstronautJSON}
@@ -1157,7 +1108,7 @@ export default defineComponent({
                           ></Vue3Lottie>
                           <p class={styles.finchLoad}>加载中...</p>
                         </>
-                      )}
+                      )} */}
                       <iframe
                         id="staffIframeRef"
                         style={{
@@ -1215,18 +1166,28 @@ export default defineComponent({
                     onClick={() => {
                       const throttleFn = useThrottleFn(() => {
                         player.value && player.value.stop()
-                        
                         // 新版云教练的谱面类型使用musicRenderType字段
-                        const musicRenderType = staff.radio === 'staff' ? 'staff' : staff.radio === 'first' ? 'firstTone' :  staff.radio === 'fixed' ? 'fixedTone' : '';
+                        let musicRenderType = ''
+                        if(staff.radio === "STAVE") {
+                          musicRenderType = 'staff'
+                        } else if(staff.radio === 'JIAN') {
+                          musicRenderType = 'fixedTone'
+                        } else if(staff.radio === 'FIRST') {
+                          musicRenderType = 'firstTone'
+                        }
                         let extraParam: any = {
-                          'part-index': currentColumn.value.xmlIndex || 0,
-                          // musicRenderType,
+                          // 'part-index': currentColumn.value.xmlIndex || 0,
+                          'part-name': currentColumn.value.track?.trim(),
+                          musicRenderType,
                         }
+                        console.log(currentColumn.value, 'currentColumn.value')
                         if (route.query.tenantAlbumId) {
                           extraParam.albumId = route.query.tenantAlbumId
                         }
-                        musicBuy(staffData.details, () => {}, extraParam)
-                      }, 500)
+                        musicBuy({
+                          id: staffData.details.bizId
+                        }, () => {}, extraParam)
+                      }, 300)
                       throttleFn()
                     }}
                   >
@@ -1349,8 +1310,8 @@ export default defineComponent({
                   <Cell
                     center
                     border={false}
-                    class={staff.radio === 'staff' ? styles.active : ''}
-                    onClick={() => onChangeStaff('staff')}
+                    class={staff.radio === 'STAVE' ? styles.active : ''}
+                    onClick={() => onChangeStaff('STAVE')}
                   >
                     {{
                       icon: () => (
@@ -1358,7 +1319,7 @@ export default defineComponent({
                       ),
                       title: () => <span class={styles.name}>五线谱</span>,
                       value: () => (
-                        <Radio name="staff">
+                        <Radio name="STAVE">
                           {{
                             icon: (props: any) => (
                               <Icon
@@ -1379,8 +1340,8 @@ export default defineComponent({
                   <Cell
                     center
                     border={false}
-                    class={staff.radio === 'first' ? styles.active : ''}
-                    onClick={() => onChangeStaff('first')}
+                    class={staff.radio === 'FIRST' ? styles.active : ''}
+                    onClick={() => onChangeStaff('FIRST')}
                   >
                     {{
                       icon: () => (
@@ -1388,7 +1349,7 @@ export default defineComponent({
                       ),
                       title: () => <span class={styles.name}>简谱-首调</span>,
                       value: () => (
-                        <Radio name="first">
+                        <Radio name="FIRST">
                           {{
                             icon: (props: any) => (
                               <Icon
@@ -1409,8 +1370,8 @@ export default defineComponent({
                   <Cell
                     center
                     border={false}
-                    class={staff.radio === 'fixed' ? styles.active : ''}
-                    onClick={() => onChangeStaff('fixed')}
+                    class={staff.radio === 'JIAN' ? styles.active : ''}
+                    onClick={() => onChangeStaff('JIAN')}
                   >
                     {{
                       icon: () => (
@@ -1418,7 +1379,7 @@ export default defineComponent({
                       ),
                       title: () => <span class={styles.name}>简谱-固定调</span>,
                       value: () => (
-                        <Radio name="fixed">
+                        <Radio name="JIAN">
                           {{
                             icon: (props: any) => (
                               <Icon
@@ -1456,19 +1417,17 @@ export default defineComponent({
                 nextTick(() => {
                   let tempPdf = "";
                   if (staffData.isComberRender && value.xmlIndex === 999) {
-                    if (staffData.details.musicPdfUrl) {
-                      tempPdf = staffData.details.musicPdfUrl;
+                    if (getCurrentPdf(staffData.list, staff.radio)) {
+                      tempPdf = getCurrentPdf(staffData.list, staff.radio);
                     }
                   } else {
                     const item = getInstrumentItem(staffData.list, value.track);
-                    console.log(item, 'item---------', value.track, staffData.list)
-                    if (item && item.soundMusicPdfUrl) {
-                      tempPdf = item.soundMusicPdfUrl;
+                    if (item && getCurrentPdf(item, staff.radio)) {
+                      tempPdf = getCurrentPdf(item, staff.radio);
                     }
                   }
                   staffData.musicPdfUrl = tempPdf;
                   if (tempPdf) {
-                    console.log(staffData.musicPdfUrl, 'musicPadUrl')
                     renderStaff();
                   } else {
                     loading.value = true;

Some files were not shown because too many files changed in this diff