diff --git a/packages/pro-components/chat/attachments/_example/attachments.json b/packages/pro-components/chat/attachments/_example/attachments.json index c8df4ffe9..b886d7832 100644 --- a/packages/pro-components/chat/attachments/_example/attachments.json +++ b/packages/pro-components/chat/attachments/_example/attachments.json @@ -1,5 +1,6 @@ { "navigationBarTitleText": "Attachments 聊天附件", + "disableScroll": true, "usingComponents": { "base": "./base", "fileLoading": "./file-loading", diff --git a/packages/pro-components/chat/attachments/_example/attachments.less b/packages/pro-components/chat/attachments/_example/attachments.less index e69de29bb..2d7f838b4 100644 --- a/packages/pro-components/chat/attachments/_example/attachments.less +++ b/packages/pro-components/chat/attachments/_example/attachments.less @@ -0,0 +1,10 @@ +.skyline { + display: flex; + flex-direction: column; + height: 100vh; + + .scroll-view { + flex: 1; + height: 0; + } +} diff --git a/packages/pro-components/chat/attachments/_example/attachments.wxml b/packages/pro-components/chat/attachments/_example/attachments.wxml index b09a7e2cb..850c8d501 100644 --- a/packages/pro-components/chat/attachments/_example/attachments.wxml +++ b/packages/pro-components/chat/attachments/_example/attachments.wxml @@ -1,20 +1,24 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/packages/pro-components/chat/attachments/attachments.less b/packages/pro-components/chat/attachments/attachments.less index 3ff937047..66ff8ce6c 100644 --- a/packages/pro-components/chat/attachments/attachments.less +++ b/packages/pro-components/chat/attachments/attachments.less @@ -23,7 +23,7 @@ // 可滚动内容区域 &__scrollable { - height: 100%; + /* 移除固定高度设置,由动态绑定控制高度 */ display: flex; align-items: center; justify-content: flex-start; @@ -80,6 +80,7 @@ &__files { box-sizing: border-box; margin-left: @attachments-file-margin; + display: inline-block; &:first-of-type { margin-left: 0; diff --git a/packages/pro-components/chat/attachments/attachments.ts b/packages/pro-components/chat/attachments/attachments.ts index 2c78d7785..84cf41f93 100644 --- a/packages/pro-components/chat/attachments/attachments.ts +++ b/packages/pro-components/chat/attachments/attachments.ts @@ -27,11 +27,17 @@ export default class Attachments extends SuperComponent { data = { classPrefix: name, files: [], + isSkyline: false, + scrollViewHeight: 0, // 新增:scroll-view的高度 }; observers = { items() { this.setFiles(); + // 新增:文件列表变化时重新计算高度 + wx.nextTick(() => { + this.getScrollViewHeight(); + }); }, }; @@ -51,6 +57,13 @@ export default class Attachments extends SuperComponent { this.handleRemove(item, index); } }, + // 新增:图片加载完成回调 + onImageLoad() { + // 图片加载完成后重新计算高度 + wx.nextTick(() => { + this.getScrollViewHeight(); + }); + }, handleFileClick(item) { if (this.data.imageViewer && item.fileType === 'image') { wx.previewImage({ @@ -62,6 +75,20 @@ export default class Attachments extends SuperComponent { handleRemove(item, index) { this.triggerEvent('remove', { item, index }); }, + // 修改:获取所有文件元素的最大高度 + getScrollViewHeight() { + const query = this.createSelectorQuery(); + query.selectAll('.t-attachments__files').boundingClientRect(); + query.exec((res) => { + if (res[0] && res[0].length > 0) { + // 获取所有文件元素的最大高度 + const maxFileHeight = Math.max(...res[0].map((rect) => rect.height)); + this.setData({ + scrollViewHeight: maxFileHeight, + }); + } + }); + }, renderDesc(item) { const sizeInBytes = item.size || 0; let formattedSize; @@ -187,9 +214,15 @@ export default class Attachments extends SuperComponent { this.data.renderIcon = this.renderIcon.bind(this); this.data.renderFileType = this.renderFileType.bind(this); this.data.renderExtension = this.renderExtension.bind(this); + // 检测 Skyline 模式 + this.setData({ isSkyline: this.renderer === 'skyline' }); }, attached() { this.setFiles(); + // 新增:组件挂载时计算高度 + wx.nextTick(() => { + this.getScrollViewHeight(); + }); }, detached() {}, }; diff --git a/packages/pro-components/chat/attachments/attachments.wxml b/packages/pro-components/chat/attachments/attachments.wxml index 0769446fe..09fdda5ed 100644 --- a/packages/pro-components/chat/attachments/attachments.wxml +++ b/packages/pro-components/chat/attachments/attachments.wxml @@ -1,75 +1,102 @@ + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {{item.name}} - - 上传中...{{item.progress || 0+"%"}} - 上传失败 - {{item.errorMessage}} - {{item.desc}} - - - - - - - - - - + + + + + + +