diff --git a/index.html b/index.html index 30d398b..1929734 100644 --- a/index.html +++ b/index.html @@ -40,7 +40,7 @@
- +
{{ offerinfo?.school?.name }}
@@ -216,7 +216,7 @@
- +
{{ item.schoolname }}
@@ -410,6 +410,7 @@ }, mounted() { // axios.defaults.headers.common["Authorization"] = "813blr43ue2hhf2kjnlfibyy9swlxm2x" + this.base01 = base01 this.base02 = base02 this.base03 = base03 @@ -423,21 +424,48 @@ this.arrowsgray = arrowsgray }, methods: { - getBase64ImageFromURL(url, type, index) { - fetch(url) - .then(response => response.blob()) - .then(blob => { - const reader = new FileReader() - reader.onloadend = () => { - if (type == "offer") { - this.offerinfo.school["base64"] = reader.result - } else { - this.offercollege[index]["base64"] = reader.result - this.$forceUpdate() - } - } - reader.readAsDataURL(blob) - }) + getBase64ImageFromURL(type, index) { + if (type == "offer") { + const img = this.$refs.offerImage + const canvas = document.createElement("canvas") + canvas.width = img.naturalWidth + canvas.height = img.naturalHeight + + const ctx = canvas.getContext("2d") + ctx.drawImage(img, 0, 0) + + this.offerinfo.school["base64"] = canvas.toDataURL("image/jpeg") + } else { + const img = this.$refs["schoolimg" + index][0] + // console.log("img", img) + const canvas = document.createElement("canvas") + canvas.width = img.naturalWidth + canvas.height = img.naturalHeight + + const ctx = canvas.getContext("2d") + ctx.drawImage(img, 0, 0) + + // console.log("666", canvas.toDataURL("image/jpeg")) + + this.offercollege[index]["base64"] = canvas.toDataURL("image/jpeg") + this.$forceUpdate() + } + + // return + // fetch(url) + // .then(response => response.blob()) + // .then(blob => { + // const reader = new FileReader() + // reader.onloadend = () => { + // if (type == "offer") { + // this.offerinfo.school["base64"] = reader.result + // } else { + // this.offercollege[index]["base64"] = reader.result + // this.$forceUpdate() + // } + // } + // reader.readAsDataURL(blob) + // }) }, // 获取 offer 详情 @@ -458,7 +486,6 @@ this.offerinfo = offerinfo this.moodmessage = data.moodmessage this.getPersonalBackground(data.backgroundid) - this.getBase64ImageFromURL(offerinfo.school.image, "offer") }) }, @@ -477,9 +504,6 @@ const data = res.data const offercollege = data.offercollege || [] - offercollege.forEach((element, index) => { - this.getBase64ImageFromURL(element.schoolimage, "summary", index) - }) this.offercollege = offercollege