index.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import MHeader from '@/components/m-header';
  2. import MSticky from '@/components/m-sticky';
  3. import { defineComponent, onMounted, reactive } from 'vue';
  4. import styles from './index.module.less';
  5. import { Button, Field, showToast } from 'vant';
  6. import MUploader from '@/components/m-uploader';
  7. import { api_userMusicDetail, api_userMusicSave } from '../api';
  8. import { useRoute, useRouter } from 'vue-router';
  9. import videoBg from '../images/videoBg.png';
  10. import { postMessage } from '@/helpers/native-message';
  11. export default defineComponent({
  12. name: 'creation-edit',
  13. setup() {
  14. const route = useRoute();
  15. const router = useRouter();
  16. const state = reactive({
  17. id: route.query.id,
  18. playType: '',
  19. musicDetail: {} as any,
  20. desc: '',
  21. videoImg: '', // 视频封面
  22. img: [] as any
  23. });
  24. const onSubmit = async () => {
  25. try {
  26. await api_userMusicSave({
  27. id: state.id,
  28. img: state.img.join(','),
  29. videoImg: state.videoImg,
  30. desc: state.desc || '我发布了一首演奏作品,快来听听吧~',
  31. musicPracticeRecordId: state.musicDetail.musicPracticeRecordId,
  32. type: 'FORMAL'
  33. });
  34. router.back();
  35. } catch {
  36. //
  37. }
  38. };
  39. // 截图
  40. const onCropper = () => {
  41. postMessage(
  42. {
  43. api: 'videoCrop',
  44. content: {
  45. url: state.musicDetail.videoUrl
  46. }
  47. },
  48. res => {
  49. if (res?.content.videoCover) {
  50. state.videoImg = res.content.videoCover;
  51. }
  52. }
  53. );
  54. };
  55. onMounted(async () => {
  56. try {
  57. const { data } = await api_userMusicDetail(state.id);
  58. state.musicDetail = data;
  59. state.desc = data.desc;
  60. state.videoImg = data.videoImg;
  61. state.img = data.img ? [data.img] : [];
  62. if (data?.videoUrl.lastIndexOf('mp4') !== -1) {
  63. state.playType = 'Video';
  64. } else {
  65. state.playType = 'Audio';
  66. }
  67. } catch {
  68. //
  69. }
  70. });
  71. return () => (
  72. <div class={styles.edit}>
  73. <MSticky position="top">
  74. <MHeader background={"#F1F1F1"} border={false} />
  75. </MSticky>
  76. <div class={styles.editBg}></div>
  77. <div class={[styles.section, styles.sectionFile]}>
  78. <div class={styles.uploadImg}>
  79. <MUploader
  80. class={styles.muploader}
  81. // native
  82. cropper
  83. deletable={false}
  84. v-model:modelValue={state.img}
  85. />
  86. {/* <div class={styles.tip}>选封面</div> */}
  87. </div>
  88. <div class={styles.musicDetail}>
  89. <p class={styles.musicName}>{state.musicDetail.musicSheetName}</p>
  90. <p class={styles.username}>{state.musicDetail.username}</p>
  91. </div>
  92. </div>
  93. {state.playType === 'Video' && (
  94. <div class={[styles.section, styles.sectionVideo]}>
  95. <img src={state.videoImg || videoBg} class={styles.videoBg} />
  96. <div class={styles.btnGroup}>
  97. <MUploader
  98. class={styles.btnImg}
  99. cropper
  100. deletable={false}
  101. onUploadChange={img => {
  102. if (img.length > 0) {
  103. state.videoImg = img[0];
  104. }
  105. }}
  106. options={{
  107. fixedNumber: [16, 9]
  108. }}
  109. />
  110. <div class={styles.btnCropper} onClick={onCropper}>
  111. 视频截取封面
  112. </div>
  113. </div>
  114. </div>
  115. )}
  116. <div class={styles.section}>
  117. <Field
  118. rows={4}
  119. autosize
  120. type="textarea"
  121. maxlength={150}
  122. placeholder="我发布了一首演奏作品,快来听听吧~"
  123. showWordLimit
  124. v-model={state.desc}
  125. />
  126. </div>
  127. <div class={styles.btnGroup}>
  128. <Button
  129. type="primary"
  130. round
  131. block
  132. color="linear-gradient(90deg, #44C9FF 0%, #259CFE 100%)"
  133. onClick={onSubmit}>
  134. {state.musicDetail.type === 'FORMAL' ? '保存' : '发布'}
  135. </Button>
  136. </div>
  137. </div>
  138. );
  139. }
  140. });