| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- <template>
- <view class="post-work-page">
- <view class="content-box">
- <view class="upload-area u-f u-f-ajc u-f-column" @click="chooseVideo">
- <view class="u-f-ajc es-ver" v-if="!videoUrl">
- <view class="u-f-ajc">
- <image src="/static/images/enter/activity/icon_upload_video.png" class="camera-icon"
- mode="aspectFit"></image>
- </view>
- <view class="upload-view es-mt-18">上传视频</view>
- </view>
- <video v-else :src="videoUrl" class="video-preview" object-fit="cover"
- :show-center-play-btn="false"></video>
- <view v-if="videoUrl" class="re-upload-btn" @click.stop="chooseVideo">重新上传</view>
- </view>
- <view class="form-item">
- <view class="label">标题</view>
- <u-input v-model="title" placeholder="请输入标题" border="none" clearable></u-input>
- </view>
- <view class="submit-btn" @click="handleSubmit">
- 发布
- </view>
- </view>
- </view>
- </template>
- <script>
- import {
- uploadVideo
- } from '@/api/activity.js';
- export default {
- data() {
- return {
- videoUrl: '',
- coverUrl: '',
- title: '',
- teamId: '',
- loading: false,
- id: '',
- }
- },
- onLoad(options) {
- if (options.teamId) {
- this.teamId = options.teamId
- }
- if (options.id) {
- this.id = options.id
- }
- },
- methods: {
- uploadFilePromise(url) {
- return new Promise((resolve, reject) => {
- uni.showLoading({
- title: '上传中',
- })
- this.loading = true
- uni.uploadFile({
- url: uni.getStorageSync('requestPath') +
- '/app/talent/uploadOSSTalent',
- filePath: url,
- name: 'file',
- success: (res) => {
- resolve(JSON.parse(res.data))
- },
- fail: (err) => {
- uni.showToast({
- title: '上传视频失败',
- icon: 'error'
- })
- },
- complete: () => {
- uni.hideLoading()
- this.loading = false
- }
- });
- })
- },
- chooseVideo() {
- uni.chooseVideo({
- sourceType: ['album'],
- success: async (res) => {
- const result = await this.uploadFilePromise(res.tempFilePath)
- this.videoUrl = result.url
- this.coverUrl = result.thumbnailUrl
- }
- });
- },
- handleSubmit() {
- if (!this.videoUrl) {
- uni.showToast({
- title: '请上传视频',
- icon: 'none'
- });
- return;
- }
- if (!this.title) {
- uni.showToast({
- title: '请输入标题',
- icon: 'none'
- });
- return;
- }
- uni.showLoading({
- title: '发布中...'
- });
- uploadVideo({
- coverUrl: this.coverUrl,
- videoUrl: this.videoUrl,
- workName: this.title,
- teamId: this.teamId,
- activityId: getApp().globalData.activityId,
- }).then(res => {
- uni.hideLoading();
- if (res.code === 200) {
- uni.showToast({
- title: '发布成功',
- icon: 'success'
- });
- setTimeout(() => {
- uni.navigateBack();
- }, 1500);
- } else {
- uni.showToast({
- title: res.msg || '发布失败',
- icon: 'none'
- });
- }
- }).catch(() => {
- uni.hideLoading();
- uni.showToast({
- title: '发布成功',
- icon: 'success'
- });
- setTimeout(() => {
- uni.navigateBack();
- }, 1500);
- });
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .post-work-page {
- min-height: 100vh;
- background-color: #f8f8f8;
- padding: 40rpx;
- }
- .content-box {
- margin-top: 40rpx;
- }
- .upload-area {
- width: 100%;
- height: 400rpx;
- background-color: #EBF5FF;
- border: 2rpx dashed #2583EB;
- border-radius: 24rpx;
- margin-bottom: 40rpx;
- position: relative;
- overflow: hidden;
- .camera-icon {
- width: 80rpx;
- height: 80rpx;
- margin-bottom: 20rpx;
- }
- .upload-text {
- font-size: 28rpx;
- color: #333;
- }
- .video-preview {
- width: 100%;
- height: 100%;
- }
- .re-upload-btn {
- position: absolute;
- bottom: 20rpx;
- right: 20rpx;
- background-color: rgba(0, 0, 0, 0.5);
- color: #fff;
- font-size: 24rpx;
- padding: 8rpx 20rpx;
- border-radius: 30rpx;
- z-index: 10;
- }
- }
- .form-item {
- background-color: #fff;
- border-radius: 24rpx;
- padding: 30rpx;
- margin-bottom: 80rpx;
- .label {
- font-size: 32rpx;
- font-weight: bold;
- color: #333;
- margin-bottom: 20rpx;
- }
- :deep(.u-input) {
- padding: 0 !important;
- }
- }
- .submit-btn {
- height: 90rpx;
- background: #2583EB;
- border-radius: 45rpx;
- color: #fff;
- font-size: 32rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- box-shadow: 0 4rpx 16rpx rgba(37, 131, 235, 0.3);
- &:active {
- opacity: 0.8;
- }
- }
- </style>
|