Skip to content

Commit

Permalink
feat: 聊天粘贴发送文件、图片时预览确认
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Jan 23, 2022
1 parent 2d83faf commit d516330
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 9 deletions.
2 changes: 1 addition & 1 deletion electron/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "DooTask",
"version": "0.6.96",
"version": "0.6.97",
"description": "DooTask is task management system.",
"main": "main.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "DooTask",
"version": "0.6.96",
"version": "0.6.97",
"description": "DooTask is task management system.",
"scripts": {
"start": "./cmd dev",
Expand Down
2 changes: 1 addition & 1 deletion public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/build/161.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/build/43.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/build/857.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/build/893.js

Large diffs are not rendered by default.

53 changes: 51 additions & 2 deletions resources/assets/js/pages/manage/components/DialogWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@
<div v-if="dialogDrag" class="drag-over" @click="dialogDrag=false">
<div class="drag-text">{{$L('拖动到这里发送')}}</div>
</div>

<Modal
v-model="pasteShow"
:title="$L(pasteTitle)"
:cancel-text="$L('取消')"
:ok-text="$L('发送')"
@on-ok="pasteSend">
<div class="dialog-wrapper-paste">
<template v-for="item in pasteItem">
<img v-if="item.type == 'image'" :src="item.result"/>
<div v-else>{{$L('文件')}}: {{item.name}} ({{$A.bytesToSize(item.size)}})</div>
</template>
</div>
</Modal>
</div>
</template>

Expand Down Expand Up @@ -125,6 +139,10 @@ export default {
tempMsgs: [],
dialogMsgSubscribe: null,
pasteShow: false,
pasteFile: [],
pasteItem: [],
}
},
Expand Down Expand Up @@ -180,6 +198,18 @@ export default {
peopleNum() {
return this.dialogData.type === 'group' ? $A.runNum(this.dialogData.people) : 0;
},
pasteTitle() {
const {pasteItem} = this;
let hasImage = pasteItem.find(({type}) => type == 'image')
let hasFile = pasteItem.find(({type}) => type != 'image')
if (hasImage && hasFile) {
return '发送文件/图片'
} else if (hasImage) {
return '发送图片'
}
return '发送文件'
}
},
Expand Down Expand Up @@ -267,12 +297,31 @@ export default {
const postFiles = Array.prototype.slice.call(files);
if (postFiles.length > 0) {
e.preventDefault();
postFiles.forEach((file) => {
this.$refs.chatUpload.upload(file);
this.pasteFile = [];
this.pasteItem = [];
postFiles.some(file => {
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = ({target}) => {
this.pasteFile.push(file)
this.pasteItem.push({
type: $A.getMiddle(file.type, null, '/'),
name: file.name,
size: file.size,
result: target.result
})
this.pasteShow = true
}
});
}
},
pasteSend() {
this.pasteFile.some(file => {
this.$refs.chatUpload.upload(file)
});
},
chatDragOver(show, e) {
let random = (this.__dialogDrag = $A.randomString(8));
if (!show) {
Expand Down
7 changes: 7 additions & 0 deletions resources/assets/sass/pages/components/dialog-wrapper.scss
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@
}
}

.dialog-wrapper-paste {
img {
max-width: 100%;
max-height: 1000px;
}
}

@media (max-width: 768px) {
.dialog-wrapper {
.dialog-footer {
Expand Down

0 comments on commit d516330

Please sign in to comment.