Browse Source

图片上传-尺寸提示

master
pzy 3 years ago
parent
commit
d502e46f8f
  1. 9
      src/utils/get-img-width.js
  2. 21
      src/views/ad/index.vue
  3. 20
      src/views/article/index.vue

9
src/utils/get-img-width.js

@ -43,17 +43,18 @@ export default function (file, id) {
// console.log(id, width, height); // console.log(id, width, height);
if (width && height) { if (width && height) {
if (img.width === width && img.height === height) { if (img.width === width && img.height === height) {
resolve(true)
resolve({ validation: true })
} else { } else {
Message({ Message({
message: `图片上传失败,宽高错误`,
message: `图片上传失败,宽高错误。正确尺寸${width}x${height}`,
type: "warning", type: "warning",
duration: 5000 duration: 5000
}); });
resolve(false);
let res = { width, height, validation: false }
resolve(res);
} }
} else { } else {
resolve(true)
resolve({ validation: true })
} }
}; };
}; };

21
src/views/ad/index.vue

@ -151,6 +151,12 @@
> >
<i class="el-icon-plus" /> <i class="el-icon-plus" />
</el-upload> </el-upload>
<div
v-if="validation === false"
style="padding-left: 10px; color: red"
>
提示宽高{{ dislabelSize.width }}x{{ dislabelSize.height }}
</div>
</el-form-item> </el-form-item>
</el-form> </el-form>
<div class="drawer__footer"> <div class="drawer__footer">
@ -214,7 +220,10 @@ export default {
downloadLoading: false, downloadLoading: false,
searchArticleLoading: false, searchArticleLoading: false,
articles: [], articles: [],
//
validation: true, validation: true,
//
dislabelSize: {},
}; };
}, },
created() { created() {
@ -230,13 +239,21 @@ export default {
return ""; return "";
}, },
}, },
watch: {
dialogFormVisible(newVal) {
if (newVal === false) {
this.validation = true;
}
},
},
methods: { methods: {
// //
async validationImages(file) { async validationImages(file) {
let desc = this.temp.static === 1 ? "bigSwiper" : "smallSwiper"; let desc = this.temp.static === 1 ? "bigSwiper" : "smallSwiper";
let res = await this.$getImgWidth(file, desc); let res = await this.$getImgWidth(file, desc);
this.validation = res;
return res;
this.validation = res.validation;
this.dislabelSize = res;
return res.validation;
}, },
getList() { getList() {
this.listLoading = true; this.listLoading = true;

20
src/views/article/index.vue

@ -274,6 +274,12 @@
> >
<i class="el-icon-plus" /> <i class="el-icon-plus" />
</el-upload> </el-upload>
<div
v-if="validation === false"
style="padding-left: 10px; color: red"
>
提示宽高{{ dislabelSize.width }}x{{ dislabelSize.height }}
</div>
</el-form-item> </el-form-item>
<el-form-item prop="file" label="上传脚本"> <el-form-item prop="file" label="上传脚本">
<el-upload <el-upload
@ -402,7 +408,9 @@ export default {
// tagData:[], // tagData:[],
chooseTagData: [], chooseTagData: [],
// //
validation: false,
validation: true,
//
dislabelSize: {},
}; };
}, },
mounted() { mounted() {
@ -425,6 +433,11 @@ export default {
}, },
}, },
watch: { watch: {
dialogFormVisible(newVal) {
if (newVal === false) {
this.validation = true;
}
},
tagData(newVal) { tagData(newVal) {
console.log("tagDAta"); console.log("tagDAta");
console.log(newVal); console.log(newVal);
@ -480,8 +493,9 @@ export default {
// //
async validationImages(file) { async validationImages(file) {
let res = await this.$getImgWidth(file, this.temp.category_id); let res = await this.$getImgWidth(file, this.temp.category_id);
this.validation = res;
return res;
this.validation = res.validation;
this.dislabelSize = res;
return res.validation;
}, },
// //
handleNodeClick(data) { handleNodeClick(data) {

Loading…
Cancel
Save