publish.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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="description">
  6. <el-input
  7. type="textarea"
  8. rows="10"
  9. v-model="formData.description"
  10. placeholder="添加作品描述,能让更多的人看到..."
  11. maxlength="300"
  12. show-word-limit
  13. ></el-input>
  14. </el-form-item>
  15. <el-form-item label="视频封面:" prop="coverImage">
  16. <el-input v-show="false" v-model="formData.coverImage"></el-input>
  17. <div>
  18. <SimpleUploadImage
  19. :limit="1"
  20. :image-list="coverList"
  21. :before-upload="beforeCoverImageUpload"
  22. tip="建议尺寸 286 * 198px"
  23. @success="uploadCoverImageSuccess"
  24. @remove="handleCoverImageRemove"
  25. ></SimpleUploadImage>
  26. </div>
  27. </el-form-item>
  28. <el-form-item label="视频文件:" prop="fileUrl">
  29. <SimpleOssUpload
  30. @success="onVideoUploadSuccess"
  31. :limit="1"
  32. ></SimpleOssUpload>
  33. <el-input v-show="false" v-model="formData.fileUrl"></el-input>
  34. </el-form-item>
  35. </el-form>
  36. <div class="tip">
  37. <div class="title">温馨提示:</div>
  38. <div class="content">
  39. 视频文件大小不超过8G,时长在30分钟以内;分辨率为720p(720x1280)及以上;
  40. 支持常用视频格式,推荐使用mp4、webm
  41. </div>
  42. </div>
  43. <div class="control">
  44. <div class="button cancel" @click="onBack">取消</div>
  45. <div class="button publish" @click="onPublish">发布</div>
  46. </div>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import { mapGetters } from 'vuex'
  52. export default {
  53. layout: 'app-ross',
  54. data() {
  55. return {
  56. formData: {
  57. coverImage: '',
  58. fileUrl: '',
  59. description: '',
  60. ossName: '',
  61. },
  62. rules: {
  63. coverImage: [
  64. {
  65. required: true,
  66. message: '请上传视频封面图片',
  67. trigger: ['change'],
  68. },
  69. ],
  70. fileUrl: [
  71. {
  72. required: true,
  73. message: '请上传视频',
  74. trigger: ['change'],
  75. },
  76. ],
  77. description: [
  78. {
  79. required: true,
  80. message: '请上传视频',
  81. trigger: ['blur'],
  82. },
  83. ],
  84. },
  85. coverList: [],
  86. }
  87. },
  88. computed: {
  89. ...mapGetters(['routePrefix', 'userInfo', 'authUserId']),
  90. },
  91. methods: {
  92. // 发布视频
  93. async onPublish() {
  94. try {
  95. await this.$refs.form.validate()
  96. this.publishVideoSave()
  97. } catch (error) {
  98. console.log(error)
  99. }
  100. },
  101. // 保存视频
  102. async publishVideoSave() {
  103. try {
  104. const { authId, mobile } = this.userInfo
  105. await this.$http.api.publishVideoSave({
  106. authId,
  107. authUserId: this.authUserId,
  108. userName: mobile,
  109. title: this.formData.description,
  110. ossName: this.formData.ossName,
  111. cover: this.formData.coverImage,
  112. ossUrl: this.formData.fileUrl,
  113. })
  114. this.$router.replace(`${this.routePrefix}/activity/challenge/message`)
  115. } catch (error) {
  116. console.log(error)
  117. }
  118. },
  119. // 视频封面上传
  120. beforeCoverImageUpload(file) {
  121. const flag = file.size / 1024 / 1024 < 5
  122. if (!flag) {
  123. this.$message.error('视屏封面图片大小不能超过 5MB!')
  124. }
  125. return flag
  126. },
  127. uploadCoverImageSuccess({ response, file, fileList }) {
  128. this.coverList = fileList
  129. this.formData.coverImage = response.data
  130. },
  131. handleCoverImageRemove() {
  132. this.coverList = []
  133. this.formData.coverImage = ''
  134. },
  135. // 视频上传成功
  136. onVideoUploadSuccess({ file, fileList }) {
  137. this.formData.fileUrl = file.url
  138. this.formData.ossName = file.uuid
  139. },
  140. // 返回
  141. onBack() {
  142. this.$router.back()
  143. },
  144. },
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. @media screen and (min-width: 768px) {
  149. ::v-deep {
  150. .el-form-item__label {
  151. font-size: 16px;
  152. }
  153. .el-textarea .el-input__count {
  154. bottom: -32px;
  155. background: transparent;
  156. }
  157. }
  158. ::v-deep {
  159. .el-input.is-active .el-input__inner,
  160. .el-input__inner:focus,
  161. .el-textarea__inner:focus,
  162. .el-upload--picture-card:hover,
  163. .el-upload:focus {
  164. border-color: #f3920d;
  165. }
  166. }
  167. .page {
  168. background: #fff;
  169. padding: 40px 0;
  170. .page-content {
  171. width: 568px;
  172. margin: 0 auto;
  173. .tip {
  174. margin: 60px 0;
  175. font-size: 14px;
  176. line-height: 1.8;
  177. .title {
  178. color: #666666;
  179. margin-bottom: 8px;
  180. }
  181. .content {
  182. color: #999999;
  183. }
  184. }
  185. .control {
  186. .button {
  187. width: 295px;
  188. height: 50px;
  189. margin: 0 auto;
  190. border-radius: 4px;
  191. cursor: pointer;
  192. display: flex;
  193. justify-content: center;
  194. align-items: center;
  195. font-size: 16px;
  196. &.cancel {
  197. border: 1px solid #c2c2c2;
  198. color: #666666;
  199. }
  200. &.publish {
  201. background: #f3920d;
  202. color: #fff;
  203. margin-top: 16px;
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. @media screen and (max-width: 768px) {
  211. ::v-deep {
  212. .el-form-item__label {
  213. font-size: 3.4vw;
  214. line-height: 4.6vw;
  215. }
  216. }
  217. .page {
  218. background: #fff;
  219. padding: 8vw 0;
  220. .page-content {
  221. width: 85.6vw;
  222. margin: 0 auto;
  223. .tip {
  224. margin: 20vw 0 12vw;
  225. font-size: 3vw;
  226. line-height: 1.8;
  227. .title {
  228. color: #666666;
  229. margin-bottom: 8px;
  230. }
  231. .content {
  232. color: #999999;
  233. }
  234. }
  235. .control {
  236. .button {
  237. width: 85.6vw;
  238. height: 12vw;
  239. margin: 0 auto;
  240. cursor: pointer;
  241. display: flex;
  242. justify-content: center;
  243. align-items: center;
  244. font-size: 3.6vw;
  245. &.cancel {
  246. border: 0.1vw solid #c2c2c2;
  247. color: #666666;
  248. }
  249. &.publish {
  250. background: #f3920d;
  251. color: #fff;
  252. margin-top: 3.2vw;
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. </style>