|
|
@ -2,54 +2,59 @@
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<a-upload
|
|
|
|
<a-upload
|
|
|
|
:action="`${$upload}`"
|
|
|
|
:action="`${$upload}`"
|
|
|
|
accept='.jpg,.JPG,.png,.PNG,.jpeg,.JPEG'
|
|
|
|
accept=".jpg,.JPG,.png,.PNG,.jpeg,.JPEG"
|
|
|
|
list-type="picture-card"
|
|
|
|
list-type="picture-card"
|
|
|
|
:headers="uploadHeaders"
|
|
|
|
:headers="uploadHeaders"
|
|
|
|
:file-list="fileList"
|
|
|
|
:file-list="fileList"
|
|
|
|
@preview="handlePreview"
|
|
|
|
@preview="handlePreview"
|
|
|
|
@change="handleChange"
|
|
|
|
@change="handleChange"
|
|
|
|
|
|
|
|
:beforeUpload="beforeUpload"
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<div v-if="fileList.length < limit">
|
|
|
|
<div v-if="fileList.length < limit">
|
|
|
|
<a-icon type="plus" />
|
|
|
|
<a-icon type="plus" />
|
|
|
|
<div class="ant-upload-text">上传图片</div>
|
|
|
|
<div class="ant-upload-text">上传图片</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</a-upload>
|
|
|
|
</a-upload>
|
|
|
|
<imgModal :previewVisible='previewVisible' :previewImage='previewImage' @handleCancel='handleCancel'/>
|
|
|
|
<imgModal
|
|
|
|
|
|
|
|
:previewVisible="previewVisible"
|
|
|
|
|
|
|
|
:previewImage="previewImage"
|
|
|
|
|
|
|
|
@handleCancel="handleCancel"
|
|
|
|
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
import imgModal from "./imgModal.vue"
|
|
|
|
import imgModal from "./imgModal.vue";
|
|
|
|
function getBase64(file) {
|
|
|
|
function getBase64(file) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const reader = new FileReader();
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
reader.onload = () => resolve(reader.result);
|
|
|
|
reader.onload = () => resolve(reader.result);
|
|
|
|
reader.onerror = error => reject(error);
|
|
|
|
reader.onerror = (error) => reject(error);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
import store from "@/store";
|
|
|
|
import store from "@/store";
|
|
|
|
export default {
|
|
|
|
export default {
|
|
|
|
components:{
|
|
|
|
components: {
|
|
|
|
imgModal
|
|
|
|
imgModal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
props:{
|
|
|
|
props: {
|
|
|
|
fileList:Array,
|
|
|
|
fileList: Array,
|
|
|
|
limit:{
|
|
|
|
limit: {
|
|
|
|
type:Number,
|
|
|
|
type: Number,
|
|
|
|
default:1
|
|
|
|
default: 1,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
data() {
|
|
|
|
return{
|
|
|
|
return {
|
|
|
|
previewVisible: false,
|
|
|
|
previewVisible: false,
|
|
|
|
previewImage: '',
|
|
|
|
previewImage: "",
|
|
|
|
uploadHeaders: {
|
|
|
|
uploadHeaders: {
|
|
|
|
"manage-login-token": store.getters.getToken
|
|
|
|
"manage-login-token": store.getters.getToken,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods:{
|
|
|
|
methods: {
|
|
|
|
async handlePreview(file) {
|
|
|
|
async handlePreview(file) {
|
|
|
|
if (!file.url && !file.preview) {
|
|
|
|
if (!file.url && !file.preview) {
|
|
|
|
file.preview = await getBase64(file.originFileObj);
|
|
|
|
file.preview = await getBase64(file.originFileObj);
|
|
|
@ -57,15 +62,24 @@ export default {
|
|
|
|
this.previewImage = file.url || file.preview;
|
|
|
|
this.previewImage = file.url || file.preview;
|
|
|
|
this.previewVisible = true;
|
|
|
|
this.previewVisible = true;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
handleCancel(){
|
|
|
|
handleCancel() {
|
|
|
|
this.previewVisible = false;
|
|
|
|
this.previewVisible = false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
handleChange({ fileList }) {
|
|
|
|
handleChange({ fileList }) {
|
|
|
|
this.$emit('handleChange',fileList)
|
|
|
|
this.$emit("handleChange", fileList);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
// 限制50mb
|
|
|
|
|
|
|
|
beforeUpload(f, l) {
|
|
|
|
|
|
|
|
const isLt50M = f.size / 1024 / 1024 < 50;
|
|
|
|
|
|
|
|
if (!isLt50M) {
|
|
|
|
|
|
|
|
this.$message.error(f.name + "文件大小超出限制,请修改后重新上传");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
<style></style>
|
|
|
|
</style>
|
|
|
|
|
|
|
|