From c01aab181d94e87645470b5f159c093e77ae79d3 Mon Sep 17 00:00:00 2001 From: whyczyk <525500596@qq.com> Date: 星期五, 10 九月 2021 14:08:30 +0800 Subject: [PATCH] 优化图片显示问题 --- src/components/v-upload.vue | 195 +++++++++++++++++++++++++----------------------- 1 files changed, 101 insertions(+), 94 deletions(-) diff --git a/src/components/v-upload.vue b/src/components/v-upload.vue index 9259d87..644fe61 100644 --- a/src/components/v-upload.vue +++ b/src/components/v-upload.vue @@ -1,101 +1,108 @@ <template> - <van-uploader :after-read="afterRead" v-model="getFileList" accept="image/png, image/jpeg" - :max-size="10 * 1024 * 1024" @oversize="oversize" :disabled="disabled" :readonly="readonly" /> + <van-uploader + :after-read="afterRead" + v-model="getFileList" + accept="image/png, image/jpeg" + :max-size="10 * 1024 * 1024" + @oversize="oversize" + :disabled="disabled" + :readonly="readonly" + /> </template> <script> - import { - uploadAlarmFile - } from '@/assets/js/api' - export default { - name: "v-upload", - props: { - value: { - type: String, - default: "" - }, - disabled: { - type: Boolean, - default: false - }, - readonly: { - type: Boolean, - default: false - }, - afterOrBefore: { - type: String, - default: 'before' - } - }, - data() { - return { - fileList: this.value - } - }, - model: { - prop: "value", - event: "valChange" - }, - watch: { - value(newValue) { - this.fileList = newValue; - }, - fileList(newValue) { - this.$emit("valChange", newValue); - } - }, - computed: { - getFileList: { - get() { - if (this.fileList) { - return this.fileList.split(",").map(item => { - return { - url: item - }; - }); - } - return []; - }, - set(newValue) { - var fileList = []; - newValue.forEach(item => { - if (item.url) { - fileList.push(item.url); - } - }); - this.fileList = fileList.join(","); - } - } - }, - methods: { - // 涓婁紶鍥剧墖 - afterRead(file) { - var formData = new FormData(); - let json = JSON.stringify({ - afterOrBefore: this.afterOrBefore - }) - formData.append("file", file.file); - formData.append("json", json); - //涓婁紶鍥剧墖鎺ュ彛 - uploadAlarmFile(formData).then(res => { - let resData = JSON.parse(res.data.result); - if (resData.code == 1) { - if (this.fileList) { - var arr = this.fileList.split(","); - arr.push(resData.data[0]); - this.fileList = arr.join(","); - return false; - } - this.fileList = resData.data[0]; - } - }); - }, - // 鏂囦欢杩囧ぇ - oversize(e) { - this.$toast.fail("鍥剧墖杩囧ぇ锛�"); - } - } - } +import { uploadAlarmFile } from "@/assets/js/api" +export default { + name: "v-upload", + props: { + value: { + type: String, + default: "", + }, + disabled: { + type: Boolean, + default: false, + }, + readonly: { + type: Boolean, + default: false, + }, + afterOrBefore: { + type: String, + default: "before", + }, + }, + data() { + return { + fileList: this.value, + } + }, + model: { + prop: "value", + event: "valChange", + }, + watch: { + value(newValue) { + this.fileList = newValue + }, + fileList(newValue) { + this.$emit("valChange", newValue) + }, + }, + computed: { + getFileList: { + get() { + if (this.fileList) { + return this.fileList.split(",").map((item) => { + console.log(this.$units.getStationSrc(item)) + return { + url: this.$units.getStationSrc(item), + url1: item, + } + }) + } + return [] + }, + set(newValue) { + var fileList = [] + newValue.forEach((item) => { + if (item.url1) { + fileList.push(item.url1) + } + }) + this.fileList = fileList.join(",") + }, + }, + }, + methods: { + // 涓婁紶鍥剧墖 + afterRead(file) { + var formData = new FormData() + let json = JSON.stringify({ + afterOrBefore: this.afterOrBefore, + }) + formData.append("file", file.file) + formData.append("json", json) + //涓婁紶鍥剧墖鎺ュ彛 + uploadAlarmFile(formData).then((res) => { + let resData = JSON.parse(res.data.result) + if (resData.code == 1) { + if (this.fileList) { + var arr = this.fileList.split(",") + arr.push(resData.data[0]) + this.fileList = arr.join(",") + return false + } + this.fileList = resData.data[0] + } + }) + }, + // 鏂囦欢杩囧ぇ + oversize(e) { + this.$toast.fail("鍥剧墖杩囧ぇ锛�") + }, + }, +} </script> <style scoped> -- Gitblit v1.9.1