publish.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <template>
  2. <div class="page">
  3. <div class="page-content">
  4. <el-form label-position="top" :model="formData" :rules="rules" ref="form">
  5. <el-form-item label="作品描述:" prop="title">
  6. <el-input
  7. type="textarea"
  8. rows="6"
  9. v-model="formData.title"
  10. placeholder="添加作品描述,能让更多的人看到..."
  11. maxlength="300"
  12. show-word-limit
  13. ></el-input>
  14. </el-form-item>
  15. <el-form-item label="上传视频:" prop="ossUrl">
  16. <SimpleOssUpload @success="onVideoUploadSuccess" :limit="1"></SimpleOssUpload>
  17. <el-input v-show="false" v-model="formData.ossUrl"></el-input>
  18. </el-form-item>
  19. <el-form-item label="抖音视频链接:" prop="linked">
  20. <el-input type="textarea" rows="3" v-model="formData.linked" placeholder="请添加抖音视频链接"></el-input>
  21. </el-form-item>
  22. </el-form>
  23. <div class="tip">
  24. <div class="title">温馨提示:</div>
  25. <div class="content">
  26. 视频文件大小不超过8G,时长在30分钟以内;分辨率为720p(720x1280)及以上; 支持常用视频格式,推荐使用mp4、webm
  27. </div>
  28. </div>
  29. <div class="control">
  30. <div class="button publish" @click="onPublish">提交</div>
  31. <div class="button cancel" @click="onBack">取消</div>
  32. </div>
  33. </div>
  34. <!-- 已上传视频列表 -->
  35. <div class="line"></div>
  36. <div class="video-container" v-if="videoList.length > 0">
  37. <div class="title"><span>已上传</span>({{ videoList.length }}个)</div>
  38. <div class="video-list">
  39. <div class="video" v-for="(item, index) in videoList" :key="index" @click="onPlay(item)">
  40. <div class="cover">
  41. <!-- <video :src="item.ossUrl" :poster="item.cover" crossorigin="anonlymous" autoplay="autoplay"></video> -->
  42. <img :src="item.cover" alt="item.title" />
  43. <div class="name">
  44. <span>{{ item.title }}</span>
  45. </div>
  46. <div class="play"></div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. <!-- 提示框 -->
  52. <GeneralDialog
  53. v-model="promptDialog"
  54. title="提示"
  55. content="抱歉,最多只能上传3个视频!!"
  56. @confirm="promptDialog = false"
  57. ></GeneralDialog>
  58. <!-- 视频播放组件 -->
  59. <SimpleVideoPlayer :videoSrc="videoUrl" :description="description" ref="videoPlayer"></SimpleVideoPlayer>
  60. </div>
  61. </template>
  62. <script>
  63. import { mapGetters } from 'vuex'
  64. import { getVideoBase64 } from '~/utils'
  65. export default {
  66. layout: 'app-ross',
  67. data() {
  68. return {
  69. promptDialog: false,
  70. formData: {
  71. authUserId: '',
  72. authId: '',
  73. userName: '',
  74. title: '',
  75. ossName: '',
  76. cover: '',
  77. ossUrl: '',
  78. linked: '',
  79. },
  80. rules: {
  81. ossUrl: [{ required: true, message: '请上传视频', trigger: ['change'] }],
  82. linked: [{ required: true, message: '请填写抖音链接', trigger: ['blur'] }],
  83. },
  84. videoList: [],
  85. videoUrl: '',
  86. description: '',
  87. }
  88. },
  89. computed: {
  90. ...mapGetters(['routePrefix', 'userInfo', 'authUserId']),
  91. },
  92. created() {
  93. this.fetchVideoList()
  94. },
  95. methods: {
  96. // 获取当前机构已发布的视频列表
  97. async fetchVideoList() {
  98. try {
  99. const { clubUserId, mobile } = this.userInfo
  100. const res = await this.$http.api.fetchOwnerVideoList({
  101. mobile: mobile,
  102. clubUserId: clubUserId,
  103. authUserId: this.authUserId,
  104. })
  105. this.videoList = res.data
  106. } catch (error) {
  107. console.log(error)
  108. }
  109. },
  110. // 发布视频
  111. async onPublish() {
  112. if (this.videoList.length >= 3) {
  113. this.promptDialog = true
  114. return
  115. }
  116. try {
  117. await this.$refs.form.validate()
  118. // 生成封面
  119. const imageUrl = process.env.EVN === 'development' ? '/flower.mp4' : this.formData.ossUrl
  120. const cover = await getVideoBase64(imageUrl)
  121. const file = new File([cover], 'cover.jpg', { type: 'image/jpeg' })
  122. const formData = new FormData()
  123. formData.append('file', file)
  124. const res = await fetch(`${process.env.BASE_URL}/wx/upload/image`, {
  125. method: 'post',
  126. body: formData,
  127. })
  128. const result = await res.json()
  129. this.formData.cover = result.data
  130. this.publishVideoSave()
  131. } catch (error) {
  132. console.log(error)
  133. }
  134. },
  135. // 保存视频
  136. async publishVideoSave() {
  137. try {
  138. const { authId, mobile } = this.userInfo
  139. this.formData.authId = authId
  140. this.formData.userName = mobile
  141. this.formData.authUserId = this.authUserId
  142. await this.$http.api.publishVideo(this.formData)
  143. this.$router.replace(`${this.routePrefix}/activity/challenge/message`)
  144. } catch (error) {
  145. console.log(error)
  146. }
  147. },
  148. // 视频上传成功
  149. onVideoUploadSuccess({ file, fileList }) {
  150. this.formData.ossUrl = file.url
  151. this.formData.ossName = file.uuid
  152. },
  153. // 返回
  154. onBack() {
  155. this.$router.back()
  156. },
  157. // 播放视频
  158. onPlay(row) {
  159. this.videoUrl = row.ossUrl
  160. this.description = row.title
  161. this.$refs.videoPlayer.open()
  162. },
  163. },
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. ::v-deep {
  168. .el-form-item__label {
  169. font-size: 16px;
  170. }
  171. .el-textarea .el-input__count {
  172. bottom: -32px;
  173. background: transparent;
  174. }
  175. }
  176. ::v-deep {
  177. .el-input.is-active .el-input__inner,
  178. .el-input__inner:focus,
  179. .el-textarea__inner:focus,
  180. .el-upload--picture-card:hover,
  181. .el-upload:focus {
  182. border-color: #f3920d;
  183. }
  184. }
  185. @media screen and (min-width: 768px) {
  186. .page {
  187. background: #fff;
  188. padding: 40px 0;
  189. .video-container {
  190. width: 568px;
  191. margin: 0 auto;
  192. margin-top: 100px;
  193. .title {
  194. font-size: 16px;
  195. color: #282828;
  196. margin-bottom: 16px;
  197. }
  198. .video-list {
  199. display: grid;
  200. grid-template-columns: repeat(3, 1fr);
  201. grid-column-gap: 16px;
  202. grid-row-gap: 16px;
  203. .video {
  204. background: #fff;
  205. box-sizing: border-box;
  206. border: 1px solid #efefef;
  207. &:hover {
  208. .info {
  209. .club-name {
  210. color: #f3920d;
  211. }
  212. }
  213. }
  214. &:nth-child(4n) {
  215. margin-right: 0;
  216. }
  217. .cover {
  218. height: 248px;
  219. position: relative;
  220. // video {
  221. // display: block;
  222. // width: 100%;
  223. // height: 100%;
  224. // background: #000;
  225. // }
  226. img {
  227. display: block;
  228. width: 100%;
  229. height: 100%;
  230. background: #000;
  231. }
  232. .play {
  233. position: absolute;
  234. z-index: 2;
  235. width: 32px;
  236. height: 32px;
  237. background: url(~assets/theme-images/common/pc-icon-play.png) no-repeat center;
  238. background-size: 32px;
  239. left: 50%;
  240. top: 50%;
  241. transform: translate(-50%, -50%);
  242. cursor: pointer;
  243. }
  244. .name {
  245. display: flex;
  246. align-items: flex-end;
  247. width: 100%;
  248. height: 75px;
  249. padding: 17px 16px;
  250. box-sizing: border-box;
  251. position: absolute;
  252. left: 0;
  253. bottom: 0;
  254. background: linear-gradient(180deg, rgba(51, 51, 51, 0) 0%, #333333 100%);
  255. span {
  256. color: #fff;
  257. font-size: 14px;
  258. line-height: 20px;
  259. max-height: 40px;
  260. @include ellipsis(2);
  261. }
  262. }
  263. }
  264. }
  265. }
  266. }
  267. .page-content {
  268. width: 568px;
  269. margin: 0 auto;
  270. .tip {
  271. margin: 60px 0;
  272. font-size: 14px;
  273. line-height: 1.8;
  274. .title {
  275. color: #666666;
  276. margin-bottom: 8px;
  277. }
  278. .content {
  279. color: #f94b4b;
  280. }
  281. }
  282. .control {
  283. .button {
  284. width: 295px;
  285. height: 50px;
  286. margin: 0 auto;
  287. border-radius: 4px;
  288. cursor: pointer;
  289. display: flex;
  290. justify-content: center;
  291. align-items: center;
  292. font-size: 16px;
  293. &.cancel {
  294. border: 1px solid #c2c2c2;
  295. color: #666666;
  296. margin-top: 16px;
  297. }
  298. &.publish {
  299. background: #f3920d;
  300. color: #fff;
  301. }
  302. }
  303. }
  304. }
  305. }
  306. }
  307. @media screen and (max-width: 768px) {
  308. ::v-deep {
  309. .el-form-item__label {
  310. font-size: 3.4vw;
  311. line-height: 4.6vw;
  312. }
  313. }
  314. .page {
  315. background: #fff;
  316. padding: 8vw 0;
  317. .line {
  318. width: 100%;
  319. height: 3.2vw;
  320. background: #f1f1f1;
  321. margin: 7.2vw 0;
  322. }
  323. .video-container {
  324. padding: 0 3.2vw;
  325. .title {
  326. font-size: 3.4vw;
  327. color: #282828;
  328. margin-bottom: 4vw;
  329. span {
  330. font-weight: bold;
  331. }
  332. }
  333. .video-list {
  334. display: grid;
  335. grid-template-columns: repeat(2, 1fr);
  336. grid-column-gap: 2.4vw;
  337. grid-row-gap: 2.4vw;
  338. .video {
  339. background: #fff;
  340. box-sizing: border-box;
  341. border: 0.1vw solid #efefef;
  342. &:hover {
  343. .info {
  344. .club-name {
  345. color: #f3920d;
  346. }
  347. }
  348. }
  349. &:nth-child(4n) {
  350. margin-right: 0;
  351. }
  352. .cover {
  353. height: 64.4vw;
  354. position: relative;
  355. // video {
  356. // display: block;
  357. // width: 100%;
  358. // height: 100%;
  359. // background: #000;
  360. // }
  361. img {
  362. display: block;
  363. width: 100%;
  364. height: 100%;
  365. background: #000;
  366. }
  367. .play {
  368. position: absolute;
  369. z-index: 2;
  370. width: 7.2vw;
  371. height: 7.2vw;
  372. background: url(~assets/theme-images/common/h5-icon-play.png) no-repeat center;
  373. background-size: 7.2vw;
  374. left: 50%;
  375. top: 50%;
  376. transform: translate(-50%, -50%);
  377. cursor: pointer;
  378. }
  379. .name {
  380. display: flex;
  381. align-items: flex-end;
  382. width: 100%;
  383. height: 16vw;
  384. padding: 4.4vw 3vw;
  385. box-sizing: border-box;
  386. position: absolute;
  387. left: 0;
  388. bottom: 0;
  389. background: linear-gradient(180deg, rgba(51, 51, 51, 0) 0%, #333333 100%);
  390. span {
  391. color: #fff;
  392. font-size: 3vw;
  393. line-height: 3.6vw;
  394. max-height: 7.2vw;
  395. @include ellipsis(2);
  396. }
  397. }
  398. }
  399. }
  400. }
  401. }
  402. .page-content {
  403. padding: 0 3.2vw;
  404. .tip {
  405. margin: 20vw 0 12vw;
  406. font-size: 3vw;
  407. line-height: 1.8;
  408. .title {
  409. color: #666666;
  410. margin-bottom: 8px;
  411. }
  412. .content {
  413. color: #f94b4b;
  414. }
  415. }
  416. .control {
  417. .button {
  418. height: 12vw;
  419. cursor: pointer;
  420. display: flex;
  421. justify-content: center;
  422. align-items: center;
  423. font-size: 3.6vw;
  424. &.cancel {
  425. border: 0.1vw solid #c2c2c2;
  426. color: #666666;
  427. margin-top: 3.2vw;
  428. }
  429. &.publish {
  430. background: #f3920d;
  431. color: #fff;
  432. }
  433. }
  434. }
  435. }
  436. }
  437. }
  438. </style>