publishWork.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="post-work-page">
  3. <view class="content-box">
  4. <view class="upload-area u-f u-f-ajc u-f-column" @click="chooseVideo">
  5. <view class="u-f-ajc es-ver" v-if="!videoUrl">
  6. <view class="u-f-ajc">
  7. <image src="/static/images/enter/activity/icon_upload_video.png" class="camera-icon"
  8. mode="aspectFit"></image>
  9. </view>
  10. <view class="upload-view es-mt-18">上传视频</view>
  11. </view>
  12. <video v-else :src="videoUrl" class="video-preview" object-fit="cover"
  13. :show-center-play-btn="false"></video>
  14. <view v-if="videoUrl" class="re-upload-btn" @click.stop="chooseVideo">重新上传</view>
  15. </view>
  16. <view class="form-item">
  17. <view class="label">标题</view>
  18. <u-input v-model="title" placeholder="请输入标题" border="none" clearable></u-input>
  19. </view>
  20. <view class="submit-btn" @click="handleSubmit">
  21. 发布
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. uploadVideo
  29. } from '@/api/activity.js';
  30. export default {
  31. data() {
  32. return {
  33. videoUrl: '',
  34. coverUrl: '',
  35. title: '',
  36. teamId: '',
  37. loading: false,
  38. id: '',
  39. }
  40. },
  41. onLoad(options) {
  42. if (options.teamId) {
  43. this.teamId = options.teamId
  44. }
  45. if (options.id) {
  46. this.id = options.id
  47. }
  48. },
  49. methods: {
  50. uploadFilePromise(url) {
  51. return new Promise((resolve, reject) => {
  52. uni.showLoading({
  53. title: '上传中',
  54. })
  55. this.loading = true
  56. uni.uploadFile({
  57. url: uni.getStorageSync('requestPath') +
  58. '/app/talent/uploadOSSTalent',
  59. filePath: url,
  60. name: 'file',
  61. success: (res) => {
  62. resolve(JSON.parse(res.data))
  63. },
  64. fail: (err) => {
  65. uni.showToast({
  66. title: '上传视频失败',
  67. icon: 'error'
  68. })
  69. },
  70. complete: () => {
  71. uni.hideLoading()
  72. this.loading = false
  73. }
  74. });
  75. })
  76. },
  77. chooseVideo() {
  78. uni.chooseVideo({
  79. sourceType: ['album'],
  80. success: async (res) => {
  81. const result = await this.uploadFilePromise(res.tempFilePath)
  82. this.videoUrl = result.url
  83. this.coverUrl = result.thumbnailUrl
  84. }
  85. });
  86. },
  87. handleSubmit() {
  88. if (!this.videoUrl) {
  89. uni.showToast({
  90. title: '请上传视频',
  91. icon: 'none'
  92. });
  93. return;
  94. }
  95. if (!this.title) {
  96. uni.showToast({
  97. title: '请输入标题',
  98. icon: 'none'
  99. });
  100. return;
  101. }
  102. uni.showLoading({
  103. title: '发布中...'
  104. });
  105. uploadVideo({
  106. coverUrl: this.coverUrl,
  107. videoUrl: this.videoUrl,
  108. workName: this.title,
  109. teamId: this.teamId,
  110. activityId: getApp().globalData.activityId,
  111. }).then(res => {
  112. uni.hideLoading();
  113. if (res.code === 200) {
  114. uni.showToast({
  115. title: '发布成功',
  116. icon: 'success'
  117. });
  118. setTimeout(() => {
  119. uni.navigateBack();
  120. }, 1500);
  121. } else {
  122. uni.showToast({
  123. title: res.msg || '发布失败',
  124. icon: 'none'
  125. });
  126. }
  127. }).catch(() => {
  128. uni.hideLoading();
  129. uni.showToast({
  130. title: '发布成功',
  131. icon: 'success'
  132. });
  133. setTimeout(() => {
  134. uni.navigateBack();
  135. }, 1500);
  136. });
  137. }
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .post-work-page {
  143. min-height: 100vh;
  144. background-color: #f8f8f8;
  145. padding: 40rpx;
  146. }
  147. .content-box {
  148. margin-top: 40rpx;
  149. }
  150. .upload-area {
  151. width: 100%;
  152. height: 400rpx;
  153. background-color: #EBF5FF;
  154. border: 2rpx dashed #2583EB;
  155. border-radius: 24rpx;
  156. margin-bottom: 40rpx;
  157. position: relative;
  158. overflow: hidden;
  159. .camera-icon {
  160. width: 80rpx;
  161. height: 80rpx;
  162. margin-bottom: 20rpx;
  163. }
  164. .upload-text {
  165. font-size: 28rpx;
  166. color: #333;
  167. }
  168. .video-preview {
  169. width: 100%;
  170. height: 100%;
  171. }
  172. .re-upload-btn {
  173. position: absolute;
  174. bottom: 20rpx;
  175. right: 20rpx;
  176. background-color: rgba(0, 0, 0, 0.5);
  177. color: #fff;
  178. font-size: 24rpx;
  179. padding: 8rpx 20rpx;
  180. border-radius: 30rpx;
  181. z-index: 10;
  182. }
  183. }
  184. .form-item {
  185. background-color: #fff;
  186. border-radius: 24rpx;
  187. padding: 30rpx;
  188. margin-bottom: 80rpx;
  189. .label {
  190. font-size: 32rpx;
  191. font-weight: bold;
  192. color: #333;
  193. margin-bottom: 20rpx;
  194. }
  195. :deep(.u-input) {
  196. padding: 0 !important;
  197. }
  198. }
  199. .submit-btn {
  200. height: 90rpx;
  201. background: #2583EB;
  202. border-radius: 45rpx;
  203. color: #fff;
  204. font-size: 32rpx;
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. box-shadow: 0 4rpx 16rpx rgba(37, 131, 235, 0.3);
  209. &:active {
  210. opacity: 0.8;
  211. }
  212. }
  213. </style>