publish.vue 6.0 KB

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