升级package, 以及更新声明文件

This commit is contained in:
zhengw
2026-01-09 16:33:18 +08:00
parent 0c4b2a886c
commit cf461d33f9
238 changed files with 46252 additions and 5857 deletions

View File

@@ -0,0 +1,53 @@
import { SuperComponent, ComponentsOptionsType } from '../../../components/common/src/index';
import { TdAttachmentsProps } from './type';
export interface AttachmentsProps extends TdAttachmentsProps {
}
export default class Attachments extends SuperComponent {
options: ComponentsOptionsType;
properties: {
inChat: {
type: BooleanConstructor;
value: boolean;
};
addable?: {
type: BooleanConstructor;
value?: boolean;
};
imageViewer?: {
type: BooleanConstructor;
value?: boolean;
};
items: {
type: ArrayConstructor;
value?: import("./type").FileItem[];
required?: boolean;
};
removable?: {
type: BooleanConstructor;
value?: boolean;
};
};
data: {
classPrefix: string;
files: any[];
};
observers: {
items(): void;
};
methods: {
onFileWrapTap(e: any): void;
onRemoveTap(e: any): void;
handleFileClick(item: any): void;
handleRemove(item: any, index: any): void;
renderDesc(item: any): string;
renderIcon(item: any): any;
renderFileType(item: any): any;
renderExtension(item: any): any;
setFiles(): void;
};
lifetimes: {
created(): void;
attached(): void;
detached(): void;
};
}

View File

@@ -0,0 +1 @@
import{__decorate}from"tslib";import{SuperComponent,wxComponent}from"../common/src/index";import config from"../common/config";import props from"./props";const{prefix:prefix}=config,name=`${prefix}-attachments`;let Attachments=class extends SuperComponent{constructor(){super(...arguments),this.options={multipleSlots:!0},this.properties=Object.assign(Object.assign({},props),{inChat:{type:Boolean,value:!1}}),this.data={classPrefix:name,files:[]},this.observers={items(){this.setFiles()}},this.methods={onFileWrapTap(e){var i;const{index:t}=e.currentTarget.dataset||{},o=null===(i=this.data.files)||void 0===i?void 0:i[t];o&&this.handleFileClick(o)},onRemoveTap(e){var i;const{index:t}=e.currentTarget.dataset||{},o=null===(i=this.data.files)||void 0===i?void 0:i[t];"function"==typeof(null==e?void 0:e.stopPropagation)&&e.stopPropagation(),void 0!==o&&this.handleRemove(o,t)},handleFileClick(e){this.data.imageViewer&&"image"===e.fileType&&wx.previewImage({urls:[e.url]}),this.triggerEvent("fileClick",{item:e})},handleRemove(e,i){this.triggerEvent("remove",{item:e,index:i})},renderDesc(e){const i=e.size||0;let t,o;if(i<1024)t=i,o="B";else if(i<1048576){const e=i/1024;t=e%1==0?e:e.toFixed(2),o="KB"}else{const e=i/1048576;t=e%1==0?e:e.toFixed(2),o="MB"}return`${t} ${o}`},renderIcon(e){const i={file:{name:"file-zip-filled",color:"#E37318"},video:{name:"video-filled",color:"#D54941"},pdf:{name:"file-pdf-filled",color:"#D54941"},doc:{name:"file-word-filled",color:"#0052d9"},excel:{name:"file-excel-filled",color:"#2BA471"},ppt:{name:"file-powerpoint-filled",color:"#E37318"},audio:{name:"video-filled",color:"#D54941"}};return i[e.fileType]||i.file},renderFileType(e){if(e.fileType)return e.fileType;if(["image","video","audio","pdf","doc","ppt","txt","excel"].includes(e.type))return e.fileType;const i=e.url||"",t=i.lastIndexOf(".");return{jpg:"image",jpeg:"image",png:"image",gif:"image",bmp:"image",webp:"image",mp4:"video",mov:"video",avi:"video",mkv:"video",webm:"video",mp3:"audio",wav:"audio",ogg:"audio",aac:"audio",pdf:"pdf",doc:"doc",docx:"doc",ppt:"ppt",pptx:"ppt",xls:"excel",xlsx:"excel",txt:"txt"}[-1!==t?i.substring(t+1).toLowerCase():""]||""},renderExtension(e){if(e.extension)return e.extension;return e.extension||(e.url?e.url.split(".").pop().toLowerCase():"")},setFiles(){this.setData({files:this.properties.items.map(e=>Object.assign(Object.assign({},e),{fileType:this.data.renderFileType(e),desc:this.data.renderDesc(e),fileIcon:this.data.renderIcon(e)}))})}},this.lifetimes={created(){this.data.handleFileClick=this.handleFileClick.bind(this),this.data.handleRemove=this.handleRemove.bind(this),this.data.renderDesc=this.renderDesc.bind(this),this.data.renderIcon=this.renderIcon.bind(this),this.data.renderFileType=this.renderFileType.bind(this),this.data.renderExtension=this.renderExtension.bind(this)},attached(){this.setFiles()},detached(){}}}};Attachments=__decorate([wxComponent()],Attachments);export default Attachments;

View File

@@ -0,0 +1 @@
{"component":true,"styleIsolation":"apply-shared","usingComponents":{"t-icon":"../icon/icon","t-image":"../image/image","t-loading":"../loading/loading"}}

View File

@@ -0,0 +1 @@
<wxs src="./attachments.wxs" module="_this"/><wxs src="../common/utils.wxs" module="_"/><view class="{{classPrefix}} {{[inChat ? classPrefix + '--chatting' : '', _this.getFileTypeClass(inChat, files)]}}" style="{{_._style([style, customStyle])}}"><view class="{{classPrefix}}__left"><view class="{{classPrefix}}__scrollable scroll-x"><block wx:for="{{files}}" wx:for-item="item" wx:for-index="index" wx:key="index"><view class="{{classPrefix}}__files" bindtap="onFileWrapTap" data-index="{{index}}"><block wx:if="{{item.fileType==='image'}}"><view class="file-image {{classPrefix}}__file {{removable ? classPrefix + '__file--removable' : ''}}"><block wx:if="{{item.status==='pending' || item.status==='fail' || item.status==='error'}}"><view class="{{item.status}} {{classPrefix}}__file--{{item.status}}"><t-loading theme="circular" size="48rpx"/></view></block><block wx:else><image class="image" src="{{item.url}}" mode="{{_this.getImageMode(item)}}" lazy-load="false" style="{{inChat ? _this.imageStyle(item) : ''}}"></image></block><view wx:if="{{removable}}" class="{{classPrefix}}__remove"><t-icon data-index="{{index}}" name="multiply" size="16px" catchtap="onRemoveTap"/></view></view></block><block wx:else><view class="file {{classPrefix}}__file {{removable ? classPrefix + '__file--removable' : ''}}"><view class="image"><block wx:if="{{item.status==='pending'}}"><view class="loading {{classPrefix}}__file--pending"><t-loading theme="circular" size="48rpx"/></view></block><block wx:elif="{{item.status==='fail'}}"><view class="fail {{classPrefix}}__file--fail"><t-loading theme="circular" size="48rpx"/></view></block><block wx:elif="{{item.status==='error'}}"><view class="error {{classPrefix}}__file--error"><t-loading theme="circular" size="48rpx"/></view></block><block wx:else><t-icon name="{{item.fileIcon.name}}" color="{{item.fileIcon.color}}" size="48rpx"></t-icon></block></view><view class="{{classPrefix}}__content"><view class="{{classPrefix}}__title">{{item.name}}</view><block><view wx:if="{{item.status==='pending'}}" class="{{classPrefix}}__desc">上传中...{{item.progress || 0+"%"}}</view><view wx:elif="{{item.status==='fail'}}" class="{{classPrefix}}__desc">上传失败</view><view wx:elif="{{item.status==='error'}}" class="{{classPrefix}}__desc">{{item.errorMessage}}</view><view wx:else class="{{classPrefix}}__desc">{{item.desc}}</view></block></view><view wx:if="{{removable}}" class="{{classPrefix}}__remove"><t-icon data-index="{{index}}" name="multiply" size="16px" catchtap="onRemoveTap"/></view></view></block></view></block></view></view></view>

View File

@@ -0,0 +1,53 @@
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,
};

View File

@@ -0,0 +1,33 @@
@import '../common/style/index.wxss';.t-attachments{display:flex;width:100%;height:auto;}
.t-attachments__scrollable{height:100%;display:flex;align-items:center;justify-content:flex-start;}
.t-attachments .scroll-x{white-space:nowrap;overflow-x:auto;overflow-y:hidden;scrollbar-width:none;-ms-overflow-style:none;}
.t-attachments .scroll-x::-webkit-scrollbar{display:none;}
.t-attachments .wrap{flex-wrap:wrap;overflow-x:hidden;}
.t-attachments__left{flex:1;overflow:hidden;}
.t-attachments__file--error,.t-attachments__file--fail,.t-attachments__file--pending,.t-attachments__file--success{position:absolute;width:100%;height:100%;top:0;left:0;border-radius:var(--td-radius-extraLarge,24rpx);display:flex;flex-direction:column;align-items:center;justify-content:center;}
.t-attachments__files{box-sizing:border-box;margin-left:16rpx;}
.t-attachments__files:first-of-type{margin-left:0;}
.t-attachments__file{border-radius:var(--td-radius-extraLarge,24rpx);display:block;position:relative;background-color:var(--td-bg-color-secondarycontainer,var(--td-gray-color-1,#f3f3f3));overflow:visible;}
.t-attachments__file--removable{margin-top:12rpx;margin-right:8rpx;}
.t-attachments__file .t-attachments__remove{background-color:var(--td-text-color-primary,var(--td-font-gray-1,rgba(0,0,0,.9)));color:var(--td-bg-color-container,var(--td-font-white-1,#fff));border-radius:var(--td-radius-circle,50%);position:absolute;right:-8rpx;top:-8rpx;}
.t-attachments__file.file-image{width:104rpx;height:104rpx;}
.t-attachments__file.file-image .image{width:100%;height:100%;border-radius:var(--td-radius-extraLarge,24rpx);}
.t-attachments__file.file{width:256rpx;height:104rpx;display:flex;align-items:stretch;justify-content:flex-start;padding:0 24rpx;}
.t-attachments__file.file .image{width:64rpx;height:auto;box-sizing:border-box;overflow:hidden;position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;}
.t-attachments__file.file .image image{width:100%;height:100%;}
.t-attachments__file.file .t-attachments__content{flex:1;overflow:hidden;display:flex;flex-direction:column;align-items:flex-start;justify-content:center;margin-left:16rpx;}
.t-attachments__file.file .t-attachments__content .t-attachments__title{width:100%;color:var(--td-text-color-primary,var(--td-font-gray-1,rgba(0,0,0,.9)));font:var(--td-font-body-medium,28rpx / 44rpx var(--td-font-family,PingFang SC,Microsoft YaHei,Arial Regular));font-style:normal;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;margin-bottom:-2rpx;padding:0;}
.t-attachments__file.file .t-attachments__content .t-attachments__desc{width:100%;color:var(--td-text-color-placeholder,var(--td-font-gray-3,rgba(0,0,0,.4)));font:var(--td-font-body-small,24rpx / 40rpx var(--td-font-family,PingFang SC,Microsoft YaHei,Arial Regular));font-style:normal;margin-top:-4rpx;}
.t-attachments--chatting.all_images{width:100%;}
.t-attachments--chatting.all_images .file-image.t-attachments__file{background-color:transparent!important;}
.t-attachments--chatting.all_images .file-image{width:auto;height:auto;}
.t-attachments--chatting.all_images .file-image .image{max-width:400rpx;max-height:400rpx;border-radius:var(--td-radius-extraLarge,24rpx);}
.t-attachments--chatting.all_files{width:auto;}
.t-attachments--chatting.all_files .t-attachments__files:not(:last-child){margin-bottom:16rpx;}
.t-attachments--chatting.all_files .file-image.t-attachments__file{background-color:transparent!important;}
.t-attachments--chatting.all_files .file-image{width:auto;height:auto;}
.t-attachments--chatting.all_files .file-image .image{max-width:400rpx;max-height:400rpx;border-radius:var(--td-radius-extraLarge,24rpx);}
.t-attachments--chatting.all_files .t-attachments__files{margin-left:0;}
.t-attachments--chatting.all_files .t-attachments__scrollable{display:contents;}
.t-attachments--chatting.all_files .file.t-attachments__file{width:352rpx;}
.t-chat__inner.right .t-attachments--chatting .file-image.t-attachments__file{text-align:right;}

View File

@@ -0,0 +1,3 @@
export * from './props';
export * from './type';
export * from './attachments';

View File

@@ -0,0 +1 @@
export*from"./props";export*from"./type";export*from"./attachments";

View File

@@ -0,0 +1,3 @@
import { TdAttachmentsProps } from './type';
declare const props: TdAttachmentsProps;
export default props;

View File

@@ -0,0 +1 @@
const props={addable:{type:Boolean,value:!0},imageViewer:{type:Boolean,value:!0},items:{type:Array,value:[],required:!0},removable:{type:Boolean,value:!0}};export default props;

View File

@@ -0,0 +1,32 @@
export interface TdAttachmentsProps {
addable?: {
type: BooleanConstructor;
value?: boolean;
};
imageViewer?: {
type: BooleanConstructor;
value?: boolean;
};
items: {
type: ArrayConstructor;
value?: FileItem[];
required?: boolean;
};
removable?: {
type: BooleanConstructor;
value?: boolean;
};
}
export interface FileItem {
fileType: 'image' | 'video' | 'audio' | 'pdf' | 'doc' | 'ppt' | 'txt';
name: string;
url: string;
size: number;
status?: 'success' | 'fail' | 'pending' | 'error';
progress?: number;
errorMessage?: string;
fileIcon?: string;
width?: number;
height?: number;
mode?: 'aspectFit' | 'aspectFill' | 'widthFix' | 'heightFix' | 'scaleToFill';
}

View File

@@ -0,0 +1 @@
export{};