uni-app 上传视频

<view >

<view class="uploadv" v-if="form.mp4List.length == 1">

          <view class="u-delete-icon" @click="deletemp4">

            <u-icon class="u-icon" name="close" size="20" color="#ffffff"></u-icon>

          </view>

          <view class="img">

            <image src="../../static/img/mp4.png"></image>

          </view>

        </view>

        <view class="uploadv" @click="uploadMp4" v-if="form.mp4List.length == 0">

          <u-icon name="plus" class="u-add-btn" size="40"></u-icon>

          <view class="u-add-tips">选择视频</view>

        </view>

<view />

css


  .uploadv {

    width: 208upx;

    height: 208upx;

    flex-direction: column;

    color: #606266;

    font-size: 13px;

    overflow: hidden;

    margin: 5px;

    background: #f4f5f6;

    position: relative;

    border-radius: 5px;

    display: flex;

    align-items: center;

    justify-content: center;

    .u-add-tips {

      margin-top: 20upx;

      line-height: 20upx;

    }

    .img {

      width: 60%;

      height: 60%;

      image {

        width: 100%;

        height: 100%;

      }

    }

    .u-delete-icon {

      position: absolute;

      top: 5px;

      right: 5px;

      z-index: 10;

      background-color: #FFAD26 !important;

      border-radius: 52px;

      width: 22px;

      height: 22px;

      display: flex;

      flex-direction: row;

      align-items: center;

      justify-content: center;

    }

  }

js


uploadMp4() {

        let _this = this;

        uni.chooseVideo({

          sourceType: ['camera', 'album'],

          success: function (res) {

            console.log(res)

            // self.src = res.tempFilePath;

            if( res.size >= 5242880 ) {

              uni.showToast({

                title: '不能超过50M',

                icon: 'none',

                mask: true,

              });

              return

            }

            uni.showLoading({

              title: '视频上传中'

            });

            uni.uploadFile({

              url: `${_this.baseUrl}/api/upload`,

              filePath: res.tempFilePath,

              name: 'file',

              method: 'POST',

              header: {

                'token': uni.getStorageSync('zuserInfo').token

              },

              success: (uploadFileRes) => {

                let ures = JSON.parse(uploadFileRes.data);

                _this.form.mp4List = [];

                _this.form.mp4List.push(ures.data);

                uni.hideLoading();

                console.log(_this.form.mp4List);

              },

              fail: (uploadFileRes) => {

                uni.hideLoading();

                // console.log(ures.data);

              }

            });

          }

        });


      },

      // 删除视频

      deletemp4() {

        this.delIds.push(this.form.mp4List[0].fileId);

        this.form.mp4List = [];

      },

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容