Files
FreeERP.Applet/miniprogram/miniprogram_npm/tdesign-miniprogram/attachments/attachments.wxs
2026-01-09 16:33:18 +08:00

54 lines
1.4 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var utils = require('../common/utils.wxs');
function imageStyle(imageProps) {
if (imageProps && imageProps.width && imageProps.height) {
return utils._style({
width: utils.addUnit(imageProps.width),
height: utils.addUnit(imageProps.height),
});
}
// 兜底逻辑:没有传入 width 和 height 时,使用默认最大宽高尺寸
return utils._style({
width: '400rpx',
height: '400rpx',
});
}
function getImageMode(imageProps) {
if (imageProps && imageProps.width && imageProps.height) {
return imageProps.width > imageProps.height ? 'widthFix' : 'heightFix';
}
// 兜底逻辑:没有传入 width 和 height 时,使用 aspectFit 保持图片比例
return imageProps && imageProps.mode ? imageProps.mode : 'scaleToFill';
}
function getFileTypeClass(inChat, files) {
// 如果 inChat 不为 true返回空字符串
if (!inChat) {
return '';
}
// 如果 files 为空或不存在,返回空字符串
if (!files || files.length === 0) {
return '';
}
// 检查是否所有文件的 fileType 都是 'image'
var allImages = true;
for (var i = 0; i < files.length; i++) {
if (files[i].fileType !== 'image') {
allImages = false;
break;
}
}
//
return allImages ? 'all_images' : 'all_files';
}
module.exports = {
imageStyle: imageStyle,
getImageMode: getImageMode,
getFileTypeClass: getFileTypeClass,
};