1
This commit is contained in:
@@ -4,7 +4,7 @@ ENV = 'development'
|
||||
# base api
|
||||
# VUE_APP_BASE_API = '/dev-api'
|
||||
# 线上
|
||||
VUE_APP_BASE_API = 'https://wxapp.diyouzhijia.com/car_admin_api'
|
||||
VUE_APP_BASE_API = 'https://cms.diyouzhijia.com/car_admin_api'
|
||||
# 花花
|
||||
# VUE_APP_BASE_API = 'http://192.168.31.16:8080/car_admin_api'
|
||||
# 薛磊
|
||||
|
||||
@@ -3,5 +3,5 @@ ENV = 'production'
|
||||
|
||||
# base api
|
||||
# VUE_APP_BASE_API = '/prod-api'
|
||||
VUE_APP_BASE_API = 'https://wxapp.diyouzhijia.com/car_admin_api'
|
||||
VUE_APP_BASE_API = 'https://cms.diyouzhijia.com/car_admin_api'
|
||||
|
||||
|
||||
@@ -1,18 +1,38 @@
|
||||
<template>
|
||||
<div class="component-upload-image">
|
||||
<el-upload multiple :action="uploadImgUrl" list-type="picture-card" :on-success="handleUploadSuccess"
|
||||
:before-upload="handleBeforeUpload" :limit="limit" :on-error="handleUploadError" :on-exceed="handleExceed"
|
||||
name="file" :on-remove="handleRemove" :show-file-list="true" :headers="headers" :file-list="fileList"
|
||||
:on-preview="handlePictureCardPreview" :class="{ hide: this.fileList.length >= this.limit }" :disabled="isDel">
|
||||
<el-upload
|
||||
multiple
|
||||
:action="uploadImgUrl"
|
||||
list-type="picture-card"
|
||||
:on-success="handleUploadSuccess"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:limit="limit"
|
||||
:on-error="handleUploadError"
|
||||
:on-exceed="handleExceed"
|
||||
name="file"
|
||||
:on-remove="handleRemove"
|
||||
:show-file-list="true"
|
||||
:headers="headers"
|
||||
:file-list="fileList"
|
||||
:on-preview="handlePictureCardPreview"
|
||||
:class="{ hide: this.fileList.length >= this.limit }"
|
||||
:disabled="isDel"
|
||||
>
|
||||
<i class="el-icon-plus"></i>
|
||||
</el-upload>
|
||||
|
||||
<!-- 上传提示 -->
|
||||
<div class="el-upload__tip" slot="tip" v-if="showTip">
|
||||
请上传
|
||||
<template v-if="proportion"> 图片比例为 <b style="color: #f56c6c">{{ proportion }}</b> </template>
|
||||
<template v-if="fileSize"> 大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b> </template>
|
||||
<template v-if="fileType"> 格式为 <b style="color: #f56c6c">{{ fileType.join("/") }}</b> </template>
|
||||
<template v-if="proportion">
|
||||
图片比例为 <b style="color: #f56c6c">{{ proportion }}</b>
|
||||
</template>
|
||||
<template v-if="fileSize">
|
||||
大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b>
|
||||
</template>
|
||||
<template v-if="fileType">
|
||||
格式为 <b style="color: #f56c6c">{{ fileType.join('/') }}</b>
|
||||
</template>
|
||||
的文件
|
||||
</div>
|
||||
|
||||
@@ -23,7 +43,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getToken } from "@/utils/auth";
|
||||
import { getToken } from '@/utils/auth';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
@@ -51,29 +71,29 @@ export default {
|
||||
// 文件类型, 例如['png', 'jpg', 'jpeg']
|
||||
fileType: {
|
||||
type: Array,
|
||||
default: () => ["png", "jpg", "jpeg", "bmp"],
|
||||
default: () => ['png', 'jpg', 'jpeg', 'bmp'],
|
||||
},
|
||||
// 是否显示提示
|
||||
isShowTip: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
number: 0,
|
||||
uploadList: [],
|
||||
dialogImageUrl: "",
|
||||
dialogImageUrl: '',
|
||||
dialogVisible: false,
|
||||
hideUpload: false,
|
||||
baseUrl: process.env.VUE_APP_BASE_API,
|
||||
//https://wxapp.diyouzhijia.com/car_admin_api/api/admin/platform/upload/image
|
||||
// https://wxapp.diyouzhijia.com/car_admin_api/system/oss/upload
|
||||
uploadImgUrl: process.env.VUE_APP_BASE_API + "/api/admin/platform/upload/image", // 上传的图片服务器地址
|
||||
//https://cms.diyouzhijia.com/car_admin_api/api/admin/platform/upload/image
|
||||
// https://cms.diyouzhijia.com/car_admin_api/system/oss/upload
|
||||
uploadImgUrl: process.env.VUE_APP_BASE_API + '/api/admin/platform/upload/image', // 上传的图片服务器地址
|
||||
headers: {
|
||||
Authorization: "Bearer " + getToken(),
|
||||
Authorization: 'Bearer ' + getToken(),
|
||||
},
|
||||
fileList: []
|
||||
fileList: [],
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
@@ -83,8 +103,8 @@ export default {
|
||||
// 首先将值转为数组
|
||||
const list = Array.isArray(val) ? val : this.value.split(',');
|
||||
// 然后将数组转为对象数组
|
||||
this.fileList = list.map(item => {
|
||||
if (typeof item === "string") {
|
||||
this.fileList = list.map((item) => {
|
||||
if (typeof item === 'string') {
|
||||
item = { name: item, url: item };
|
||||
}
|
||||
return item;
|
||||
@@ -95,8 +115,8 @@ export default {
|
||||
}
|
||||
},
|
||||
deep: true,
|
||||
immediate: true
|
||||
}
|
||||
immediate: true,
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
// 是否显示提示
|
||||
@@ -107,11 +127,11 @@ export default {
|
||||
methods: {
|
||||
// 删除图片
|
||||
handleRemove(file, fileList) {
|
||||
const findex = this.fileList.map(f => f.name).indexOf(file.name);
|
||||
const findex = this.fileList.map((f) => f.name).indexOf(file.name);
|
||||
if (findex > -1) {
|
||||
this.fileList.splice(findex, 1);
|
||||
this.$emit("input", this.listToString(this.fileList));
|
||||
this.$emit("delIndex", findex);
|
||||
this.$emit('input', this.listToString(this.fileList));
|
||||
this.$emit('delIndex', findex);
|
||||
}
|
||||
},
|
||||
// 上传成功回调
|
||||
@@ -122,10 +142,10 @@ export default {
|
||||
// this.uploadList.push({ name: res.data.fileName, url: res.data.url });
|
||||
if (this.uploadList.length === this.number) {
|
||||
this.fileList = this.fileList.concat(this.uploadList);
|
||||
this.$emit("imageNameArr", this.uploadList);
|
||||
this.$emit('imageNameArr', this.uploadList);
|
||||
this.uploadList = [];
|
||||
this.number = 0;
|
||||
this.$emit("input", this.listToString(this.fileList));
|
||||
this.$emit('input', this.listToString(this.fileList));
|
||||
this.$modal.closeLoading();
|
||||
}
|
||||
} else {
|
||||
@@ -137,9 +157,9 @@ export default {
|
||||
handleBeforeUpload(file) {
|
||||
let isImg = false;
|
||||
if (this.fileType.length) {
|
||||
let fileExtension = "";
|
||||
if (file.name.lastIndexOf(".") > -1) {
|
||||
fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);
|
||||
let fileExtension = '';
|
||||
if (file.name.lastIndexOf('.') > -1) {
|
||||
fileExtension = file.name.slice(file.name.lastIndexOf('.') + 1);
|
||||
}
|
||||
isImg = this.fileType.some((type) => {
|
||||
if (file.type.indexOf(type) > -1) return true;
|
||||
@@ -147,11 +167,11 @@ export default {
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
isImg = file.type.indexOf("image") > -1;
|
||||
isImg = file.type.indexOf('image') > -1;
|
||||
}
|
||||
|
||||
if (!isImg) {
|
||||
this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}图片格式文件!`);
|
||||
this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join('/')}图片格式文件!`);
|
||||
return false;
|
||||
}
|
||||
if (this.fileSize) {
|
||||
@@ -161,7 +181,7 @@ export default {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
this.$modal.loading("正在上传图片,请稍候...");
|
||||
this.$modal.loading('正在上传图片,请稍候...');
|
||||
this.number++;
|
||||
},
|
||||
// 文件个数超出
|
||||
@@ -170,7 +190,7 @@ export default {
|
||||
},
|
||||
// 上传失败
|
||||
handleUploadError(res) {
|
||||
this.$modal.msgError("上传图片失败,请重试");
|
||||
this.$modal.msgError('上传图片失败,请重试');
|
||||
this.$modal.closeLoading();
|
||||
},
|
||||
// 预览
|
||||
@@ -180,14 +200,14 @@ export default {
|
||||
},
|
||||
// 对象转成指定字符串分隔
|
||||
listToString(list, separator) {
|
||||
let strs = "";
|
||||
separator = separator || ",";
|
||||
let strs = '';
|
||||
separator = separator || ',';
|
||||
for (let i in list) {
|
||||
strs += list[i].url + separator;
|
||||
}
|
||||
return strs != '' ? strs.substr(0, strs.length - 1) : '';
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user