musicScore.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. import { postMessage } from '@/helpers/native-message'
  7. import { Loading } from 'vant'
  8. import { usePageVisibility } from '@vant/use'
  9. export default defineComponent({
  10. name: 'musicScore',
  11. props: {
  12. music: {
  13. type: Object,
  14. default: () => {}
  15. },
  16. activeModel:{
  17. type: Boolean
  18. }
  19. },
  20. emits: ['setIframe'],
  21. setup(props, { emit }) {
  22. const isLoading = ref(false)
  23. const pageVisibility = usePageVisibility()
  24. /** 页面显示和隐藏 */
  25. watch(pageVisibility, (value) => {
  26. if(value == 'hidden'){
  27. isLoading.value = true
  28. } else {
  29. isLoading.value = false
  30. }
  31. })
  32. const iframeRef = ref()
  33. const renderError = ref(false)
  34. const renderSuccess = ref(false)
  35. const Authorization = sessionStorage.getItem('Authorization') || ''
  36. const origin = /(localhost|192)/.test(location.host)
  37. ? 'https://ponline.colexiu.com' //'http://localhost:3000' ////
  38. : location.origin
  39. const query = qs.stringify({
  40. id: props.music.content,
  41. modelType: 'practice',
  42. headerHeight: 32,
  43. Authorization: Authorization
  44. })
  45. let src = `${origin}/orchestra-music-score/?` + query
  46. const checkView = () => {
  47. fetch(src)
  48. .then(() => {
  49. renderSuccess.value = true
  50. renderError.value = false
  51. })
  52. .catch((err) => {
  53. renderError.value = true
  54. })
  55. }
  56. watch(props.music, () => {
  57. if (renderSuccess.value) return
  58. renderError.value = false
  59. if (props.music.display) {
  60. checkView()
  61. }
  62. })
  63. // 去云教练完整版
  64. const gotoAccomany = () => {
  65. // if (isLoading.value) return;
  66. isLoading.value = true
  67. const parmas = qs.stringify({
  68. id: props.music.content,
  69. })
  70. let src = `${location.origin}/orchestra-music-score/?` + parmas
  71. postMessage({
  72. api: 'openAccompanyWebView',
  73. content: {
  74. url: src,
  75. orientation: 0,
  76. isHideTitle: true,
  77. statusBarTextColor: false,
  78. isOpenLight: true
  79. }
  80. })
  81. }
  82. return () => (
  83. <div class={styles.musicScore}>
  84. {renderError.value ? (
  85. <div class={styles.errorModel}>
  86. <OEmpty type="network" tips="请检查网络环境" />
  87. </div>
  88. ) : (
  89. <>
  90. <iframe
  91. ref={iframeRef}
  92. onLoad={(e: Event) => {
  93. emit('setIframe', iframeRef.value)
  94. }}
  95. class={[styles.container, 'musicIframe']}
  96. frameborder="0"
  97. src={src}
  98. ></iframe>
  99. <div style={{
  100. display: props.activeModel ? '' : 'none'
  101. }} class={styles.startBtn} onClick={(e: Event) => {
  102. e.stopPropagation()
  103. gotoAccomany()
  104. }}>
  105. <img src={iconStart} />
  106. {/* <Loading class={styles.loading} color="rgba(63,134,237,1)" /> */}
  107. </div>
  108. </>
  109. )}
  110. </div>
  111. )
  112. }
  113. })