index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <div
  3. class="creationEdit"
  4. :style="{
  5. '--navBarHeight': navBarHeight + 'px'
  6. }"
  7. >
  8. <van-sticky>
  9. <van-nav-bar class="nav" :fixed="false" title="编辑" left-arrow @click-left="goBack" />
  10. </van-sticky>
  11. <div class="section sectionFile ">
  12. <div :class="['uploadImg2']">
  13. <!-- <img class="muploader showImg" :src="img || this.musicBg" /> -->
  14. <MUpload class="muploader mupload uploadSingleImg opacity" cropper :defaultImg="musicBg" v-model="img" :previewImage="true" />
  15. </div>
  16. <div class="musicDetail">
  17. <p class="musicName">{{ musicDetail.musicSheetName }}</p>
  18. <p class="username">{{ musicDetail.username }}</p>
  19. </div>
  20. </div>
  21. <div class="section sectionVideo" v-if="playType === 'Video'">
  22. <img :src="videoImg || videoBg" class="videoBg" />
  23. <div class="btnGroup">
  24. <MUpload class="muploader imgCover" cropper :previewImage="false" v-model="videoImg" :options="{ fixedNumber: [16, 9] }">
  25. <template #default>
  26. <div class="btnImg" @click="onCropper">
  27. 相册获取封面
  28. </div>
  29. </template>
  30. </MUpload>
  31. <div class="btnCropper" @click="onCropper">
  32. 视频截取封面
  33. </div>
  34. </div>
  35. </div>
  36. <div class="section">
  37. <van-field
  38. class="fieldText"
  39. :rows="4"
  40. autosize
  41. type="textarea"
  42. maxlength="150"
  43. placeholder="我发布了一首演奏作品,快来听听吧~"
  44. showWordLimit
  45. v-model="desc"
  46. />
  47. </div>
  48. <div class="btnGroup">
  49. <van-button class="subBtn" type="primary" round block color="#01C1B5" @click="onSubmit">
  50. {{ musicDetail.type === "FORMAL" ? "保存" : "发布" }}
  51. </van-button>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { postMessage } from "@/helpers/native-message"
  57. import { browser } from "@/common/common"
  58. import { api_userMusicSave, api_userMusicDetail } from "../api"
  59. import MUpload from "@/components/MUpload"
  60. export default {
  61. name: "creationEdit",
  62. data() {
  63. return {
  64. navBarHeight: 0,
  65. files: [],
  66. id: this.$route.query.id,
  67. musicDetail: {},
  68. playType: "",
  69. desc: "",
  70. videoImg: "", // 视频封面
  71. img: "",
  72. videoBg: require("../img/video-bg.png"),
  73. musicBg: require("../img/music_bg.png")
  74. }
  75. },
  76. components: { MUpload },
  77. methods: {
  78. goBack() {
  79. if (browser().isApp) {
  80. postMessage({
  81. api: "goBack"
  82. })
  83. } else {
  84. this.$router.back()
  85. }
  86. },
  87. async onSubmit() {
  88. try {
  89. await api_userMusicSave({
  90. id: this.id,
  91. img: this.img,
  92. videoImg: this.videoImg,
  93. desc: this.desc || "我发布了一首演奏作品,快来听听吧~",
  94. musicPracticeRecordId: this.musicDetail.musicPracticeRecordId,
  95. type: "FORMAL"
  96. })
  97. this.$router.back()
  98. } catch {
  99. //
  100. }
  101. },
  102. // 截图
  103. onCropper() {
  104. postMessage(
  105. {
  106. api: "videoCrop",
  107. content: {
  108. url: this.musicDetail.videoUrl
  109. }
  110. },
  111. res => {
  112. if (res?.content.videoCover) {
  113. this.videoImg = res.content.videoCover
  114. }
  115. }
  116. )
  117. }
  118. },
  119. created() {
  120. postMessage({ api: "getNavHeight" }, res => {
  121. const { content } = res
  122. const dpi = content.dpi || 2
  123. if (content.navHeight) {
  124. const navHeight = content.navHeight / dpi
  125. this.navBarHeight = navHeight
  126. }
  127. })
  128. },
  129. async mounted() {
  130. try {
  131. const { data } = await api_userMusicDetail(this.id)
  132. this.musicDetail = data
  133. this.desc = data.desc
  134. this.videoImg = data.videoImg
  135. this.img = data.img
  136. if (data?.videoUrl.lastIndexOf("mp4") !== -1) {
  137. this.playType = "Video"
  138. } else {
  139. this.playType = "Audio"
  140. }
  141. } catch {
  142. //
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="less" scoped>
  148. .creationEdit {
  149. min-height: 100vh;
  150. overflow: hidden;
  151. .nav {
  152. padding-top: var(--navBarHeight, 0);
  153. background: #f1f1f1;
  154. &::after {
  155. display: none;
  156. }
  157. /deep/ .van-nav-bar__content {
  158. height: 44px;
  159. .van-icon {
  160. font-size: 0.19rem;
  161. color: #333333;
  162. }
  163. .van-nav-bar__title {
  164. font-size: 0.18rem;
  165. color: #333333;
  166. font-weight: 500;
  167. }
  168. }
  169. }
  170. .sectionVideo {
  171. position: relative;
  172. line-height: 0;
  173. overflow: visible !important;
  174. margin-bottom: 24px !important;
  175. .videoBg {
  176. width: 100%;
  177. height: 196px;
  178. object-fit: cover;
  179. border-radius: 10px;
  180. }
  181. .btnGroup {
  182. position: absolute;
  183. left: 50%;
  184. bottom: 12px;
  185. background: linear-gradient(180deg, rgba(128, 177, 200, 0.59) 0%, rgba(58, 152, 162, 0.59) 100%);
  186. border-radius: 15px;
  187. height: 30px;
  188. // transform: translate(-50%);
  189. display: flex;
  190. align-items: center;
  191. flex: 1;
  192. font-size: 12px;
  193. font-weight: 500;
  194. color: #ffffff;
  195. line-height: 17px;
  196. width: 300px;
  197. margin: 0 0 0 -150px;
  198. & > div {
  199. flex: 1;
  200. text-align: center;
  201. display: flex;
  202. align-items: center;
  203. justify-content: center;
  204. }
  205. .btnCropper {
  206. border-left: 1px solid #fff;
  207. line-height: 1;
  208. &::before {
  209. content: "";
  210. width: 16px;
  211. height: 16px;
  212. display: inline-block;
  213. background: url("../img/icon-cropper.png") no-repeat center;
  214. background-size: contain;
  215. margin-right: 4px;
  216. }
  217. }
  218. /deep/.imgCover {
  219. .mcropperSection {
  220. display: none;
  221. }
  222. }
  223. .btnImg {
  224. position: absolute;
  225. top: 0;
  226. left: 0;
  227. right: 0;
  228. bottom: 0;
  229. margin: 0;
  230. line-height: 1;
  231. display: flex;
  232. align-items: center;
  233. justify-content: center;
  234. &::before {
  235. content: "";
  236. width: 16px;
  237. height: 16px;
  238. display: inline-block;
  239. background: url("../img/icon-image.png") no-repeat center;
  240. background-size: contain;
  241. margin-right: 4px;
  242. vertical-align: text-top;
  243. }
  244. // &::after {
  245. // content: "相册获取封面";
  246. // font-size: 12px;
  247. // color: #fff;
  248. // }
  249. img {
  250. display: none;
  251. }
  252. }
  253. }
  254. }
  255. .section {
  256. margin: 12px 13px;
  257. background: #ffffff;
  258. border-radius: 10px;
  259. font-size: 16px;
  260. overflow: hidden;
  261. .fieldText /deep/.van-field__control{
  262. caret-color: #01C1B5;
  263. }
  264. .van-field__control::placeholder {
  265. color: #aaa;
  266. }
  267. }
  268. .sectionFile {
  269. padding: 12px;
  270. display: flex;
  271. .van-uploader {
  272. border-radius: 8px;
  273. overflow: hidden;
  274. }
  275. .van-uploader__upload,
  276. .van-uploader__preview-image {
  277. margin: 0;
  278. width: 0.62rem !important;
  279. height: 0.62rem !important;
  280. }
  281. /deep/.muploader {
  282. position: relative;
  283. z-index: 8;
  284. width: 0.62rem;
  285. height: 0.62rem;
  286. border: none;
  287. margin: 0;
  288. border-radius: 8px;
  289. background-color: #ffffff;
  290. }
  291. .uploadImg2 {
  292. position: relative;
  293. border-radius: 8px;
  294. margin-right: 16px;
  295. .showImg {
  296. position: absolute;
  297. left: 0;
  298. top: 0;
  299. }
  300. .tip {
  301. position: absolute;
  302. bottom: 0;
  303. left: 0;
  304. right: 0;
  305. z-index: 10;
  306. background: #000000;
  307. opacity: 0.37;
  308. font-size: 13px;
  309. color: #ffffff;
  310. line-height: 18px;
  311. text-align: center;
  312. border-radius: 0 0 8px 8px;
  313. pointer-events: none;
  314. }
  315. &::before {
  316. content: "";
  317. background: url("../img/audio-pan.png") no-repeat center;
  318. background-size: contain;
  319. position: absolute;
  320. top: 0;
  321. right: -6px;
  322. z-index: 4;
  323. width: 60px;
  324. height: 60px;
  325. }
  326. }
  327. .musicDetail {
  328. display: flex;
  329. justify-content: center;
  330. flex-direction: column;
  331. .musicName {
  332. font-size: 16px;
  333. font-weight: 600;
  334. color: #131415;
  335. line-height: 22px;
  336. }
  337. .username {
  338. padding-top: 4px;
  339. font-size: 14px;
  340. color: #777777;
  341. line-height: 20px;
  342. }
  343. }
  344. }
  345. .showInfoImg {
  346. width: 0.62rem;
  347. height: 0.62rem;
  348. }
  349. .btnGroup {
  350. margin: 32px 24px 12px;
  351. font-weight: 500;
  352. font-size: 16px;
  353. .subBtn /deep/.van-button__text{
  354. font-size: 16px;
  355. }
  356. }
  357. /deep/.uploadSingleImg {
  358. .mcropperSection,
  359. .cropper {
  360. width: 0.62rem !important;
  361. height: 0.62rem !important;
  362. border-radius: 6px !important;
  363. overflow: hidden !important;
  364. }
  365. .mcropperSection .uploadImg {
  366. margin-right: 0;
  367. }
  368. .cropper::before {
  369. content: "选封面";
  370. position: absolute;
  371. bottom: 0;
  372. left: 0;
  373. right: 0;
  374. z-index: 10;
  375. background: #000000;
  376. opacity: 0.37;
  377. line-height: 20px;
  378. height: 20px;
  379. font-size: 13px;
  380. color: #ffffff;
  381. line-height: 18px;
  382. text-align: center;
  383. border-radius: 0 0 8px 8px;
  384. pointer-events: none;
  385. }
  386. &.opacity {
  387. // &::before {
  388. // display: none;
  389. // }
  390. .upbtn > input {
  391. width: 0.62rem !important;
  392. height: 0.62rem !important;
  393. }
  394. }
  395. }
  396. }
  397. </style>