图片支持width和height属性默认设为auto

This commit is contained in:
feipeng 2019-07-17 20:18:45 +08:00
parent 733ff9d213
commit e82d27f5e4

View File

@ -184,35 +184,27 @@ export default class Painter {
case 'image': {
// image的长宽设置成auto的逻辑处理
const ratio = getApp().systemInfo.pixelRatio ? getApp().systemInfo.pixelRatio : 2;
if (!view.css) {
// 有css却未设置width或height则默认为auto
if (view.css) {
if (!view.css.width) {
view.css.width = 'auto';
}
if (!view.css.height) {
view.css.height = 'auto';
}
}
if (!view.css || (view.css.width === 'auto' && view.css.height === 'auto')) {
width = Math.round(view.sWidth / ratio);
height = Math.round(view.sHeight / ratio);
} else if (view.css.width === 'auto') {
height = view.css.height.toPx();
width = view.sWidth / view.sHeight * height;
} else if (view.css.height === 'auto') {
width = view.css.width.toPx();
height = view.sHeight / view.sWidth * width;
} else {
if (!view.css.width) {
width = Math.round(view.sWidth / ratio);
if ((!view.css.height) || view.css.height === 'auto') {
height = Math.round(view.sHeight / ratio);
} else {
height = view.css.height.toPx();
}
} else if (view.css.width === 'auto') {
if ((!view.css.height) || view.css.height === 'auto') {
width = Math.round(view.sWidth / ratio);
height = Math.round(view.sHeight / ratio);
} else {
height = view.css.height.toPx();
width = view.sWidth / view.sHeight * height;
}
} else {
width = view.css.width.toPx();
if (!view.css.height) {
height = Math.round(view.sHeight / ratio);
} else if (view.css.height === 'auto') {
height = view.sHeight / view.sWidth * width;
} else {
height = view.css.height.toPx();
}
}
width = view.css.width.toPx();
height = view.css.height.toPx();
}
break;
}