From 2d9354a39e50c042a5d4e4f97f9ccb6e0802db2e Mon Sep 17 00:00:00 2001 From: long <515897141@qq.com> Date: 星期五, 11 六月 2021 17:03:22 +0800 Subject: [PATCH] 修复接口返回字段名 --- src/pages/system/basic.vue | 85 +++++------------------------------------- 1 files changed, 11 insertions(+), 74 deletions(-) diff --git a/src/pages/system/basic.vue b/src/pages/system/basic.vue index d7e9c46..828c5e7 100644 --- a/src/pages/system/basic.vue +++ b/src/pages/system/basic.vue @@ -5,7 +5,7 @@ <el-form ref="basicForm" label-position="left" :model="basicData" label-width="150px" :rules="rules"> <el-form-item label="鍒嗕韩鏍囬锛�" prop="shareTitle"> - <el-input v-model="basicData.shareTitle" placeholder="璇疯緭鍏ュ垎浜爣棰�" class="com-edit-input" /> + <el-input v-model="basicData.shareTitle" placeholder="璇疯緭鍏ュ垎浜爣棰�" maxlength="100" class="com-edit-input" /> </el-form-item> <el-form-item prop="uploadShareImgs"> @@ -13,22 +13,11 @@ 鍒嗕韩鍥剧墖锛�<br><span>(500*400鍍忕礌)</span> </span> <!-- 涓婁紶鍥剧墖缁勪欢(鍗曞浘) --> - <el-upload - ref="refUploadShareImg" - :auto-upload="false" - list-type="picture-card" - :class="{disabled:uploadDisabled}" - action="#" - :limit="1" - :file-list="basicData.uploadShareImgs" - :on-change="addUploadFiles" - :on-remove="delUploadFiles" - :http-request="uploadFileHandle" - :on-preview="uploadPreview" - :before-upload="beforeUploadImg" - > - <i class="el-icon-plus" /> - </el-upload> + <UploadSingleImg + ref="refUploadImg" + v-model="basicData.uploadShareImgs" + @change.capture="$refs['basicForm'].clearValidate()" + /> </el-form-item> </el-form> @@ -46,8 +35,9 @@ <script> import mixin_upload from '@/mixins/upload.js' // 閫氱敤涓婁紶鍥剧墖棰勮 +import UploadSingleImg from '@/components_simple/UploadSingleImg' export default { - components: {}, + components: { UploadSingleImg }, mixins: [mixin_upload], data() { return { @@ -65,11 +55,6 @@ required: true, message: '璇烽�夋嫨鍥剧墖' }] } - } - }, - computed: { - uploadDisabled() { - return this.basicData.uploadShareImgs.length > 0 } }, mounted() { @@ -103,61 +88,13 @@ this.$router.go(-1) }, - // 涓婁紶鏀粯鏂囦欢 鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌鈫撯啌 - // 涓婁紶鍓嶇‘璁ゆ牸寮� - beforeUploadImg(file) { - const isImg = file.type.indexOf('image/') > -1 - if (!isImg) { - this.$message.error('蹇呴』鏄�夋嫨鍥剧墖鏂囦欢') - } - return isImg - }, - // 澧炲姞鏂囦欢 - addUploadFiles(file) { - this.basicData.uploadShareImgs = [file] - }, - // 鍒犻櫎鏂囦欢 - delUploadFiles(file, fileList) { - this.basicData.uploadShareImgs = fileList - }, - // 鎵ц涓婁紶鍗曟枃浠� - runUploadFiles(cb) { - if (this.checkNeedUpload(this.basicData.uploadShareImgs)) { - this.$refs.refUploadShareImg.submit() - } else { - cb && cb() - } - }, - // 涓婁紶鍒嗕韩鍥� - uploadFileHandle(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: 'xxx' - } - } - }, (inf) => { - this.basicData.shareImg = inf.imgUrl - // this.$refs.refUploadShareImg.clearFiles(); - this.submitReq() - }) - }, - // 涓婁紶鏀粯鏂囦欢 鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈鈫戔啈 - // 鎻愪氦缂栬緫 submit() { this.$refs['basicForm'].validate(valid => { if (valid) { - this.runUploadFiles(() => { + // 涓婁紶鍥剧墖 + this.$refs.refUploadImg.runUploadImg((imgUrl) => { + imgUrl && this.$set(this.basicData, 'shareImg', imgUrl) this.submitReq() }) } -- Gitblit v1.8.0