musicScore.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { defineComponent, ref, nextTick, onMounted, watch } from 'vue'
  2. import styles from './musicScore.module.less'
  3. import qs from 'query-string'
  4. import OEmpty from '@/components/o-empty'
  5. import iconStart from '../image/icon-start.svg'
  6. export default defineComponent({
  7. name: 'musicScore',
  8. props: {
  9. music: {
  10. type: Object,
  11. default: () => {}
  12. },
  13. activeModel:{
  14. type: Boolean
  15. }
  16. },
  17. emits: ['setIframe'],
  18. setup(props, { emit }) {
  19. const iframeRef = ref()
  20. const renderError = ref(false)
  21. const renderSuccess = ref(false)
  22. const Authorization = sessionStorage.getItem('Authorization') || ''
  23. const origin = /(localhost|192)/.test(location.host)
  24. ? 'https://ponline.colexiu.com' //'http://localhost:3000' ////
  25. : location.origin
  26. const query = qs.stringify({
  27. id: props.music.content,
  28. modelType: 'practice',
  29. headerHeight: 32,
  30. Authorization: Authorization
  31. })
  32. let src = `${origin}/orchestra-music-score/?` + query
  33. const checkView = () => {
  34. fetch(src)
  35. .then(() => {
  36. renderSuccess.value = true
  37. renderError.value = false
  38. })
  39. .catch((err) => {
  40. renderError.value = true
  41. })
  42. }
  43. watch(props.music, () => {
  44. if (renderSuccess.value) return
  45. renderError.value = false
  46. if (props.music.display) {
  47. checkView()
  48. }
  49. })
  50. // 去云教练完整版
  51. const gotoAccomany = () => {
  52. const parmas = qs.stringify({
  53. id: props.music.content,
  54. })
  55. let src = `${location.origin}/orchestra-music-score/?` + parmas
  56. postMessage({
  57. api: 'openAccompanyWebView',
  58. content: {
  59. url: src,
  60. orientation: 0,
  61. isHideTitle: true,
  62. statusBarTextColor: false,
  63. isOpenLight: true
  64. }
  65. })
  66. }
  67. return () => (
  68. <div class={styles.musicScore}>
  69. {renderError.value ? (
  70. <div class={styles.errorModel}>
  71. <OEmpty type="network" tips="请检查网络环境" />
  72. </div>
  73. ) : (
  74. <>
  75. <iframe
  76. ref={iframeRef}
  77. onLoad={(e: Event) => {
  78. emit('setIframe', iframeRef.value)
  79. }}
  80. class={[styles.container, 'musicIframe']}
  81. frameborder="0"
  82. src={src}
  83. ></iframe>
  84. <div style={{
  85. display: props.activeModel ? '' : 'none'
  86. }} class={styles.startBtn} onClick={(e: Event) => {
  87. e.stopPropagation()
  88. gotoAccomany()
  89. }}>
  90. <img src={iconStart} />
  91. </div>
  92. </>
  93. )}
  94. </div>
  95. )
  96. }
  97. })