index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import MHeader from '@/components/m-header';
  2. import MSticky from '@/components/m-sticky';
  3. import { defineComponent, onMounted, reactive, onBeforeUnmount } 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. // 设置导航栏颜色
  56. function setStatusBarTextColor(isWhite:boolean){
  57. postMessage({
  58. api: 'setStatusBarTextColor',
  59. content: { statusBarTextColor: isWhite }
  60. })
  61. }
  62. onMounted(async () => {
  63. setStatusBarTextColor(false)
  64. try {
  65. const { data } = await api_userMusicDetail(state.id);
  66. state.musicDetail = data;
  67. state.desc = data.desc;
  68. state.videoImg = data.videoImg;
  69. state.img = data.img ? [data.img] : [];
  70. if (data?.videoUrl.lastIndexOf('mp4') !== -1) {
  71. state.playType = 'Video';
  72. } else {
  73. state.playType = 'Audio';
  74. }
  75. } catch {
  76. //
  77. }
  78. });
  79. onBeforeUnmount(()=>{
  80. setStatusBarTextColor(true)
  81. })
  82. return () => (
  83. <div>
  84. <MSticky position="top">
  85. <MHeader background={"#F1F1F1"} border={false} />
  86. </MSticky>
  87. <div class={[styles.section, styles.sectionFile]}>
  88. <div class={styles.uploadImg}>
  89. <MUploader
  90. class={styles.muploader}
  91. // native
  92. cropper
  93. deletable={false}
  94. v-model:modelValue={state.img}
  95. />
  96. {/* <div class={styles.tip}>选封面</div> */}
  97. </div>
  98. <div class={styles.musicDetail}>
  99. <p class={styles.musicName}>{state.musicDetail.musicSheetName}</p>
  100. <p class={styles.username}>{state.musicDetail.username}</p>
  101. </div>
  102. </div>
  103. {state.playType === 'Video' && (
  104. <div class={[styles.section, styles.sectionVideo]}>
  105. <img src={state.videoImg || videoBg} class={styles.videoBg} />
  106. <div class={styles.btnGroup}>
  107. <MUploader
  108. class={styles.btnImg}
  109. cropper
  110. deletable={false}
  111. onUploadChange={img => {
  112. if (img.length > 0) {
  113. state.videoImg = img[0];
  114. }
  115. }}
  116. options={{
  117. fixedNumber: [16, 9]
  118. }}
  119. />
  120. <div class={styles.btnCropper} onClick={onCropper}>
  121. 视频截取封面
  122. </div>
  123. </div>
  124. </div>
  125. )}
  126. <div class={styles.section}>
  127. <Field
  128. rows={4}
  129. autosize
  130. type="textarea"
  131. maxlength={150}
  132. placeholder="我发布了一首演奏作品,快来听听吧~"
  133. showWordLimit
  134. v-model={state.desc}
  135. />
  136. </div>
  137. <div class={styles.btnGroup}>
  138. <Button
  139. type="primary"
  140. round
  141. block
  142. color="linear-gradient(90deg, #44C9FF 0%, #259CFE 100%)"
  143. onClick={onSubmit}>
  144. {state.musicDetail.type === 'FORMAL' ? '保存' : '发布'}
  145. </Button>
  146. </div>
  147. </div>
  148. );
  149. }
  150. });