musicScore.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { defineComponent, ref, watch } from 'vue';
  2. import { NSkeleton } from 'naive-ui';
  3. import styles from './musicScore.module.less';
  4. import { usePageVisibility } from '@vant/use';
  5. export default defineComponent({
  6. name: 'musicScore',
  7. props: {
  8. music: {
  9. type: Object,
  10. default: () => ({})
  11. },
  12. activeModel: {
  13. type: Boolean
  14. }
  15. },
  16. emits: ['setIframe'],
  17. setup(props, { emit }) {
  18. const isLoading = ref(false);
  19. const pageVisibility = usePageVisibility();
  20. /** 页面显示和隐藏 */
  21. watch(pageVisibility, value => {
  22. console.log('🚀 ~ value:', value);
  23. if (value == 'hidden') {
  24. isLoading.value = false;
  25. }
  26. });
  27. const iframeRef = ref();
  28. const isLoaded = ref(false);
  29. const renderError = ref(false);
  30. const renderSuccess = ref(false);
  31. const origin = /(localhost|192)/.test(location.host)
  32. ? 'https://dev.kt.colexiu.com'
  33. : location.origin;
  34. const src = `${origin}/instrument?platform=pc&modelType=practise`;
  35. const checkView = () => {
  36. fetch(src)
  37. .then(() => {
  38. renderSuccess.value = true;
  39. renderError.value = false;
  40. })
  41. .catch(() => {
  42. renderError.value = true;
  43. });
  44. };
  45. watch(props.music, () => {
  46. if (renderSuccess.value) return;
  47. renderError.value = false;
  48. if (props.music.display) {
  49. checkView();
  50. }
  51. });
  52. // 去云教练完整版
  53. // const gotoAccomany = () => {
  54. // if (isLoading.value) return;
  55. // if (!browserInfo.ios) {
  56. // isLoading.value = true;
  57. // }
  58. // // const parmas = qs.stringify({
  59. // // id: props.music.content
  60. // // });
  61. // // let src = `${location.origin}/orchestra-music-score/?` + parmas
  62. // const src = `https://test.lexiaoya.cn/orchestra-music-score/?_t=1687590480955&id=11707&modelType=practice&modeType=json&Authorization=bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsib2F1dGgyLXJlc291cmNlIl0sImNsaWVudFR5cGUiOiJCQUNLRU5EIiwidXNlcl9uYW1lIjoiMTgxNjI4NTU4MDAiLCJzY29wZSI6WyJhbGwiXSwidXNlcklkIjoiMTAwMDE0OSIsImF1dGhvcml0aWVzIjpbIjE4MTYyODU1ODAwIl0sImp0aSI6IjY0MzA2NjllLTE5NGItNDk3Yy1hMDQ5LWM4YWUxMGU0NDNiOCIsImNsaWVudF9pZCI6ImptZWR1LWJhY2tlbmQifQ.aeJ0o-lSfx1Ok-YptZuC-AUY6M7k3LK9rr0Bmx7sj81pPt2HDiDqeT2PuriYdJacxWnxboyhdG_lwU0QK-W-vON97c45NQpSEFLVpZ0m1xdIqwllwf20xhyj5YJwdOFUzxf1TNEfGsHZg66J7wEJQBSzlmQwcxmEE5lqLVD8o_3f2SBqnWCj9RqE4air7FUemllMnZiu8HsS-TKtLDaGa_XW8Yb_Zjzzz6r5UcYNI-C1uKPXg18o1dhHBJ8O-Pl0U8WivPRub_opvO2NSn5L9YtPt7Dd50UeSwaIOdMeCGdii1bg__h77Stek1_5IaZLYkoo2gvmUA-xk09TwCQBpA`;
  63. // postMessage(
  64. // {
  65. // api: 'openAccompanyWebView',
  66. // content: {
  67. // url: src,
  68. // orientation: 0,
  69. // isHideTitle: true,
  70. // statusBarTextColor: false,
  71. // isOpenLight: true
  72. // }
  73. // },
  74. // () => {
  75. // if (browserInfo.ios) {
  76. // isLoading.value = true;
  77. // }
  78. // }
  79. // );
  80. // };
  81. return () => (
  82. <div class={styles.musicScore}>
  83. <iframe
  84. ref={iframeRef}
  85. onLoad={() => {
  86. emit('setIframe', iframeRef.value);
  87. isLoaded.value = true;
  88. }}
  89. class={[styles.container, 'musicIframe']}
  90. frameborder="0"
  91. src={src}></iframe>
  92. <div class={styles.skeletonWrap}>
  93. <NSkeleton text repeat={8} />
  94. </div>
  95. </div>
  96. );
  97. }
  98. });