From 3fccf2450a3ed31ceca512551858f886b30c499d Mon Sep 17 00:00:00 2001 From: liweilong <515897141@qq.com> Date: 星期四, 24 十二月 2020 18:13:48 +0800 Subject: [PATCH] 上传视频组件 --- src/pages/system/banner.vue | 87 ++++--------------------------------------- 1 files changed, 9 insertions(+), 78 deletions(-) diff --git a/src/pages/system/banner.vue b/src/pages/system/banner.vue index f22319e..ff35688 100644 --- a/src/pages/system/banner.vue +++ b/src/pages/system/banner.vue @@ -64,24 +64,12 @@ <el-input v-model="dialogData.orderNum" placeholder="璇疯緭鍏ユ帓搴忓彿" /> </el-form-item> <el-form-item ref="uploadFormItem" label="杞挱鍥撅細" prop="uploadImgs"> - <!-- 涓婁紶鍥剧墖缁勪欢(鍗曞浘) --> - <el-upload + <!-- 涓婁紶鍥剧墖缁勪欢(澶氬浘) --> + <UploadSingleImg ref="refUploadImg" - accept="image/jpeg,image/jpg,image/gif,image/png" - :auto-upload="false" - list-type="picture-card" - :class="{disabled:uploadDisabled}" - action="#" - :limit="1" - :file-list="dialogData.uploadImgs" - :on-change="addUploadImg" - :on-remove="delUploadImg" - :http-request="uploadImg" - :on-preview="uploadPreview" - :before-upload="beforeUploadImg" - > - <i class="el-icon-plus" /> - </el-upload> + v-model="dialogData.uploadImgs" + @change.capture="$refs[formName].clearValidate()" + /> </el-form-item> <el-form-item label="璺宠浆绫诲瀷锛�" prop="jumpType"> <el-select @@ -130,8 +118,10 @@ import mixin_Upload from '@/mixins/upload.js' import mixin_bannerOpts from '@/mixins/bannerOpts.js' // 閫氱敤杞挱鍥句笅鎷夐�夐」 +import UploadSingleImg from '@/components_simple/UploadSingleImg' export default { name: 'Equipment', + components: { UploadSingleImg }, mixins: [mixin_Upload, mixin_bannerOpts], data() { return { @@ -192,66 +182,6 @@ init() { this.getList() }, - - // 涓婁紶鍥剧墖 鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌 - // 涓婁紶鍓嶇‘璁ゆ牸寮� - beforeUploadImg(file) { - const isImg = file.type.indexOf('image/') > -1 - if (!isImg) { - this.$message.error('蹇呴』鏄�夋嫨鍥剧墖鏂囦欢') - } - return isImg - }, - // 澧炲姞鍥剧墖 - addUploadImg(file, fileList) { - this.$refs.uploadFormItem.resetField() - this.dialogData.uploadImgs = fileList - }, - // 鍒犻櫎鍥剧墖 - delUploadImg(file, fileList) { - this.dialogData.uploadImgs = fileList - }, - // 鎵ц涓婁紶鍥� - runUploadImg(suc_cb) { - if (this.checkNeedUpload(this.dialogData.uploadImgs)) { - this.$refs.refUploadImg.submit() - } else { - suc_cb && suc_cb() - } - }, - // 涓婁紶鍥� - uploadImg(res) { - console.log(res) - const file = res.file - const formData = new FormData() - formData.append('file', file) - console.log(formData) - this.postFN({ - url: 'admin/image/upload', - header: { 'Content-Type': 'multipart/form-data' }, - params: formData, - mockData: { - code: 100, - msg: '', - data: { - imgUrl: 'xxxx' - } - } - }, (inf) => { - console.log('涓婁紶鍥剧墖鎴愬姛') - - // 鏇挎崲鎺夋湭涓婁紶鐨勫浘鐗� - this.dialogData.uploadImgs[0] = { url: inf.imgUrl, status: 'success' } - this.dialogData.uploadImgs = JSON.parse(JSON.stringify(this.dialogData.uploadImgs)) - this.$set(this.dialogData, 'imgUrl', inf.imgUrl) - - console.log('涓婁紶鍥剧墖缁撴潫') - - // 鎻愪氦 - this.submit(this.dialogData.type) - }) - }, - // 涓婁紶鍥剧墖 鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈 // 鑾峰彇鍒楄〃 getList() { @@ -351,7 +281,8 @@ this.$refs[this.formName].validate((valid) => { if (valid) { // 涓婁紶鍥剧墖 - this.runUploadImg(() => { + this.$refs.refUploadImg.runUploadImg((imgUrl) => { + imgUrl && this.$set(this.dialogData, 'imgUrl', imgUrl) this.submit(type) }) } -- Gitblit v1.8.0