publish.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. <img :src="item.cover" alt="item.title" v-if="item.cover" />
  42. <video :src="item.ossUrl" crossorigin="anonlymous" v-else></video>
  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. if (/iPad|iPhone|iPod/.test(navigator.userAgent)) {
  119. this.publishVideoSave()
  120. return
  121. }
  122. // 生成封面
  123. const imageUrl = process.env.EVN === 'development' ? '/flower.mp4' : this.formData.ossUrl
  124. const cover = await getVideoBase64(imageUrl)
  125. const file = new File([cover], 'cover.jpg', { type: 'image/jpeg' })
  126. const formData = new FormData()
  127. formData.append('file', file)
  128. const res = await fetch(`${process.env.BASE_URL}/wx/upload/image`, {
  129. method: 'post',
  130. body: formData,
  131. })
  132. const result = await res.json()
  133. this.formData.cover = result.data
  134. this.publishVideoSave()
  135. } catch (error) {
  136. console.log(error)
  137. }
  138. },
  139. // 保存视频
  140. async publishVideoSave() {
  141. try {
  142. const { authId, mobile } = this.userInfo
  143. this.formData.authId = authId
  144. this.formData.userName = mobile
  145. this.formData.authUserId = this.authUserId
  146. await this.$http.api.publishVideo(this.formData)
  147. this.$router.replace(`${this.routePrefix}/activity/challenge/message`)
  148. } catch (error) {
  149. console.log(error)
  150. }
  151. },
  152. // 视频上传成功
  153. onVideoUploadSuccess({ file, fileList }) {
  154. this.formData.ossUrl = file.url
  155. this.formData.ossName = file.uuid
  156. },
  157. // 返回
  158. onBack() {
  159. this.$router.back()
  160. },
  161. // 播放视频
  162. onPlay(row) {
  163. this.videoUrl = row.ossUrl
  164. this.description = row.title
  165. this.$refs.videoPlayer.open()
  166. },
  167. },
  168. }
  169. </script>
  170. <style lang="scss" scoped>
  171. ::v-deep {
  172. .el-form-item__label {
  173. font-size: 16px;
  174. }
  175. .el-textarea .el-input__count {
  176. bottom: -32px;
  177. background: transparent;
  178. }
  179. }
  180. ::v-deep {
  181. .el-input.is-active .el-input__inner,
  182. .el-input__inner:focus,
  183. .el-textarea__inner:focus,
  184. .el-upload--picture-card:hover,
  185. .el-upload:focus {
  186. border-color: #f3920d;
  187. }
  188. }
  189. @media screen and (min-width: 768px) {
  190. .page {
  191. background: #fff;
  192. padding: 40px 0;
  193. .video-container {
  194. width: 568px;
  195. margin: 0 auto;
  196. margin-top: 100px;
  197. .title {
  198. font-size: 16px;
  199. color: #282828;
  200. margin-bottom: 16px;
  201. }
  202. .video-list {
  203. display: grid;
  204. grid-template-columns: repeat(3, 1fr);
  205. grid-column-gap: 16px;
  206. grid-row-gap: 16px;
  207. .video {
  208. background: #fff;
  209. box-sizing: border-box;
  210. border: 1px solid #efefef;
  211. &:hover {
  212. .info {
  213. .club-name {
  214. color: #f3920d;
  215. }
  216. }
  217. }
  218. &:nth-child(4n) {
  219. margin-right: 0;
  220. }
  221. .cover {
  222. height: 248px;
  223. position: relative;
  224. video {
  225. display: block;
  226. width: 100%;
  227. height: 100%;
  228. background: #000;
  229. }
  230. img {
  231. display: block;
  232. width: 100%;
  233. height: 100%;
  234. background: #000;
  235. }
  236. .play {
  237. position: absolute;
  238. z-index: 2;
  239. width: 32px;
  240. height: 32px;
  241. background: url(~assets/theme-images/common/pc-icon-play.png) no-repeat center;
  242. background-size: 32px;
  243. left: 50%;
  244. top: 50%;
  245. transform: translate(-50%, -50%);
  246. cursor: pointer;
  247. }
  248. .name {
  249. display: flex;
  250. align-items: flex-end;
  251. width: 100%;
  252. height: 75px;
  253. padding: 17px 16px;
  254. box-sizing: border-box;
  255. position: absolute;
  256. left: 0;
  257. bottom: 0;
  258. background: linear-gradient(180deg, rgba(51, 51, 51, 0) 0%, #333333 100%);
  259. span {
  260. color: #fff;
  261. font-size: 14px;
  262. line-height: 20px;
  263. max-height: 40px;
  264. @include ellipsis(2);
  265. }
  266. }
  267. }
  268. }
  269. }
  270. }
  271. .page-content {
  272. width: 568px;
  273. margin: 0 auto;
  274. .tip {
  275. margin: 60px 0;
  276. font-size: 14px;
  277. line-height: 1.8;
  278. .title {
  279. color: #666666;
  280. margin-bottom: 8px;
  281. }
  282. .content {
  283. color: #f94b4b;
  284. }
  285. }
  286. .control {
  287. .button {
  288. width: 295px;
  289. height: 50px;
  290. margin: 0 auto;
  291. border-radius: 4px;
  292. cursor: pointer;
  293. display: flex;
  294. justify-content: center;
  295. align-items: center;
  296. font-size: 16px;
  297. &.cancel {
  298. border: 1px solid #c2c2c2;
  299. color: #666666;
  300. margin-top: 16px;
  301. }
  302. &.publish {
  303. background: #f3920d;
  304. color: #fff;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. }
  311. @media screen and (max-width: 768px) {
  312. ::v-deep {
  313. .el-form-item__label {
  314. font-size: 3.4vw;
  315. line-height: 4.6vw;
  316. }
  317. }
  318. .page {
  319. background: #fff;
  320. padding: 8vw 0;
  321. .line {
  322. width: 100%;
  323. height: 3.2vw;
  324. background: #f1f1f1;
  325. margin: 7.2vw 0;
  326. }
  327. .video-container {
  328. padding: 0 3.2vw;
  329. .title {
  330. font-size: 3.4vw;
  331. color: #282828;
  332. margin-bottom: 4vw;
  333. span {
  334. font-weight: bold;
  335. }
  336. }
  337. .video-list {
  338. display: grid;
  339. grid-template-columns: repeat(2, 1fr);
  340. grid-column-gap: 2.4vw;
  341. grid-row-gap: 2.4vw;
  342. .video {
  343. background: #fff;
  344. box-sizing: border-box;
  345. border: 0.1vw solid #efefef;
  346. &:hover {
  347. .info {
  348. .club-name {
  349. color: #f3920d;
  350. }
  351. }
  352. }
  353. &:nth-child(4n) {
  354. margin-right: 0;
  355. }
  356. .cover {
  357. height: 64.4vw;
  358. position: relative;
  359. // video {
  360. // display: block;
  361. // width: 100%;
  362. // height: 100%;
  363. // background: #000;
  364. // }
  365. img {
  366. display: block;
  367. width: 100%;
  368. height: 100%;
  369. background: #000;
  370. }
  371. .play {
  372. position: absolute;
  373. z-index: 2;
  374. width: 7.2vw;
  375. height: 7.2vw;
  376. background: url(~assets/theme-images/common/h5-icon-play.png) no-repeat center;
  377. background-size: 7.2vw;
  378. left: 50%;
  379. top: 50%;
  380. transform: translate(-50%, -50%);
  381. cursor: pointer;
  382. }
  383. .name {
  384. display: flex;
  385. align-items: flex-end;
  386. width: 100%;
  387. height: 16vw;
  388. padding: 4.4vw 3vw;
  389. box-sizing: border-box;
  390. position: absolute;
  391. left: 0;
  392. bottom: 0;
  393. background: linear-gradient(180deg, rgba(51, 51, 51, 0) 0%, #333333 100%);
  394. span {
  395. color: #fff;
  396. font-size: 3vw;
  397. line-height: 3.6vw;
  398. max-height: 7.2vw;
  399. @include ellipsis(2);
  400. }
  401. }
  402. }
  403. }
  404. }
  405. }
  406. .page-content {
  407. padding: 0 3.2vw;
  408. .tip {
  409. margin: 20vw 0 12vw;
  410. font-size: 3vw;
  411. line-height: 1.8;
  412. .title {
  413. color: #666666;
  414. margin-bottom: 8px;
  415. }
  416. .content {
  417. color: #f94b4b;
  418. }
  419. }
  420. .control {
  421. .button {
  422. height: 12vw;
  423. cursor: pointer;
  424. display: flex;
  425. justify-content: center;
  426. align-items: center;
  427. font-size: 3.6vw;
  428. &.cancel {
  429. border: 0.1vw solid #c2c2c2;
  430. color: #666666;
  431. margin-top: 3.2vw;
  432. }
  433. &.publish {
  434. background: #f3920d;
  435. color: #fff;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. }
  442. </style>