index.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { Button, Dialog, Grid, GridItem, Popup, Toast } from 'vant'
  2. import { defineComponent, ref, toRefs } from 'vue'
  3. import styles from './index.module.less'
  4. import iconTitle from './icons/title.svg'
  5. import iconCancel from './icons/cancel.svg'
  6. import iconConfirm from './icons/confirm.svg'
  7. import Content from './content'
  8. import SettingState from '/src/pages/detail/setting-state'
  9. import { IPostMessage, postMessage } from '/src/helpers/native-message'
  10. export const evaluatingShow = ref<boolean>(false)
  11. const open = ref(false)
  12. export type ResultContent = {
  13. /* 节奏 */
  14. cadence: number
  15. /* 完整性 */
  16. integrity: number
  17. /* 音调 */
  18. intonation: number
  19. playTime: number
  20. recordId: number
  21. /** 评测记录ID */
  22. recordIdStr: string
  23. /* 分数 */
  24. score: number
  25. }
  26. //效音组件
  27. export default defineComponent({
  28. name: 'ColexiuEvaluating',
  29. props: {
  30. data: {
  31. type: Object as () => ResultContent | null,
  32. default: () => null,
  33. },
  34. },
  35. emits: ['restart'],
  36. setup(props) {
  37. const confirmShow = ref<boolean>(false)
  38. //
  39. const isSaveVideo = SettingState.sett.camera && SettingState.eva.save
  40. const sendUploadMessage = (res?: IPostMessage) => {
  41. postMessage({
  42. api: 'proxyServiceMessage',
  43. content: {
  44. header: {
  45. commond: 'videoUpload',
  46. status: 200,
  47. type: 'SOUND_COMPARE',
  48. },
  49. body: {
  50. filePath: res?.content?.filePath,
  51. recordId: props.data?.recordId,
  52. },
  53. },
  54. })
  55. }
  56. const videoUpdate = () => {
  57. if (isSaveVideo) {
  58. postMessage(
  59. {
  60. api: 'videoUpdate',
  61. },
  62. (res) => {
  63. confirmShow.value = false
  64. if (res?.content) {
  65. if (res.content.type === 'error') {
  66. Toast(res.content.message)
  67. return
  68. }
  69. sendUploadMessage(res)
  70. }
  71. }
  72. )
  73. } else {
  74. confirmShow.value = false
  75. sendUploadMessage()
  76. Toast.success('上传成功')
  77. }
  78. }
  79. return () => {
  80. return (
  81. <div>
  82. <Popup
  83. position="bottom"
  84. v-model:show={evaluatingShow.value}
  85. onOpen={() => (open.value = true)}
  86. onClosed={() => (open.value = false)}
  87. teleport="body"
  88. style={{ backgroundColor: 'transparent' }}
  89. >
  90. {open && (
  91. <Content
  92. data={props.data}
  93. onUpload={() => (confirmShow.value = true)}
  94. onRestart={() => (evaluatingShow.value = false)}
  95. />
  96. )}
  97. </Popup>
  98. <Dialog.Component
  99. teleport="body"
  100. class={styles.confirm}
  101. style={{
  102. overflow: 'initial',
  103. }}
  104. vSlots={{
  105. title: () => <img class={styles.iconTitle} src={iconTitle} />,
  106. footer: () => (
  107. <div class={styles.footer}>
  108. <img src={iconCancel} onClick={() => (confirmShow.value = false)} />
  109. <img src={iconConfirm} onClick={videoUpdate} />
  110. </div>
  111. ),
  112. }}
  113. v-model:show={confirmShow.value}
  114. message={`评测${isSaveVideo ? '音视频' : '音频'}是否保存演奏?`}
  115. />
  116. </div>
  117. )
  118. }
  119. },
  120. })