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