perf: 聊天文件发送进度

This commit is contained in:
kuaifan 2024-03-15 12:33:16 +09:00
parent 01bda83fcd
commit dc3e5f0a59
4 changed files with 40 additions and 2 deletions

View File

@ -140,8 +140,8 @@ export default {
file.msg = this.fileMsgCaches[msgName]
delete this.fileMsgCaches[msgName]
}
this.$emit('on-progress', file)
}
this.$emit('on-progress', file)
},
handleSuccess(res, file) {

View File

@ -40,6 +40,9 @@
<div class="file-size">{{$A.bytesToSize(msgData.msg.size)}}</div>
</div>
</div>
<div v-if="msgData.msg.percentage" class="file-percentage">
<span :style="fileStyle(msgData.msg.percentage)"></span>
</div>
</div>
</div>
<!--录音-->
@ -508,6 +511,15 @@ export default {
return `${Math.max(1, seconds)}`
},
fileStyle(percentage) {
if (percentage) {
return {
width: (100 - percentage) + '%'
};
}
return {};
},
imageStyle(info) {
const {width, height} = info;
if (width && height) {

View File

@ -1983,13 +1983,19 @@ export default {
chatFile(type, file) {
switch (type) {
case 'progress':
const percentage = file.showProgress ? Math.max(file.percentage, 0.01) : false
const temp = this.tempMsgs.find(({id}) => id == file.tempId);
if (temp) {
temp.msg.percentage = percentage
return;
}
const tempMsg = {
id: file.tempId,
dialog_id: this.dialogData.id,
reply_id: this.quoteId,
type: 'file',
userid: this.userId,
msg: file.msg || {},
msg: Object.assign(file.msg || {}, {percentage}),
}
this.tempMsgs.push(tempMsg)
this.msgType = ''

View File

@ -937,6 +937,26 @@
}
.content-file {
position: relative;
.file-percentage {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 3px;
overflow: hidden;
> span {
position: absolute;
top: 0;
right: 0;
bottom: 0;
width: 0;
background-color: rgba(170, 170, 170, 0.2);
}
}
&.file {
display: inline-block;