From 957aeeb3420b0c17f8a0e8202e07baf3d8df07ef Mon Sep 17 00:00:00 2001 From: pzy Date: Thu, 17 Feb 2022 17:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E4=B8=8A=E4=B8=8B=E7=BA=BF?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/get-img-width.js | 47 +++++++++++++++++----- src/views/article/index.vue | 80 +++++++++++++++++++++++-------------- 2 files changed, 88 insertions(+), 39 deletions(-) diff --git a/src/utils/get-img-width.js b/src/utils/get-img-width.js index a315805..35a2bf2 100644 --- a/src/utils/get-img-width.js +++ b/src/utils/get-img-width.js @@ -1,5 +1,29 @@ import { Message } from 'element-ui' -export default function (file, width, height) { +export default function (file, id) { + let width = 0; + let height = 0; + switch (id) { + case 23: //深度解说 + width = 650; + height = 350; + break; + case 25: //行情分析 + width = 130; + height = 130; + break; + case 24: //热点追踪 + width = 130; + height = 130; + break; + case 7: //基础教程 + width = 380; + height = 220; + break; + case 6: //图文教程 + width = 380; + height = 220; + break; + }; return new Promise(resolve => { let reader = new FileReader(); reader.readAsDataURL(file); @@ -8,15 +32,20 @@ export default function (file, width, height) { let img = document.createElement("img"); img.src = txt; img.onload = function () { - if (img.width === width && img.height === height) { - resolve(true) + console.log(id, width, height); + if (width && height) { + if (img.width === width && img.height === height) { + resolve(true) + } else { + Message({ + message: `图片上传失败,宽高错误`, + type: "warning", + duration: 5000 + }); + resolve(false); + } } else { - Message({ - message: `图片上传失败,宽高错误`, - type: "warning", - duration: 5000 - }); - resolve(false); + resolve(true) } }; }; diff --git a/src/views/article/index.vue b/src/views/article/index.vue index 95ddc92..b1647ba 100644 --- a/src/views/article/index.vue +++ b/src/views/article/index.vue @@ -3,7 +3,7 @@ - +
{{ row.url }} + + +