musicScore.tsx 4.1 KB

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