fix: 任务中没有聊天记录时,发送图片无法成功

This commit is contained in:
kuaifan 2022-01-26 18:05:53 +08:00
parent 3bb7e958dc
commit 8ff94bc138
4 changed files with 142 additions and 151 deletions

View File

@ -282,24 +282,11 @@ export default {
this.msgText = ''; this.msgText = '';
}, },
chatKeydown(e) { sendFileMsg(files) {
if (e.keyCode === 13) { if (files.length > 0) {
if (e.shiftKey) {
return;
}
e.preventDefault();
this.sendMsg();
}
},
pasteDrag(e, type) {
const files = type === 'drag' ? e.dataTransfer.files : e.clipboardData.files;
const postFiles = Array.prototype.slice.call(files);
if (postFiles.length > 0) {
e.preventDefault();
this.pasteFile = []; this.pasteFile = [];
this.pasteItem = []; this.pasteItem = [];
postFiles.some(file => { files.some(file => {
let reader = new FileReader(); let reader = new FileReader();
reader.readAsDataURL(file); reader.readAsDataURL(file);
reader.onload = ({target}) => { reader.onload = ({target}) => {
@ -316,10 +303,28 @@ export default {
} }
}, },
pasteSend() { chatKeydown(e) {
this.pasteFile.some(file => { if (e.keyCode === 13) {
this.$refs.chatUpload.upload(file) if (e.shiftKey) {
}); return;
}
e.preventDefault();
this.sendMsg();
}
},
pasteDrag(e, type) {
const files = type === 'drag' ? e.dataTransfer.files : e.clipboardData.files;
const postFiles = Array.prototype.slice.call(files);
if (postFiles.length > 0) {
e.preventDefault();
this.sendFileMsg(postFiles);
}
},
chatPasteDrag(e, type) {
this.dialogDrag = false;
this.pasteDrag(e, type);
}, },
chatDragOver(show, e) { chatDragOver(show, e) {
@ -338,29 +343,10 @@ export default {
} }
}, },
chatPasteDrag(e, type) { pasteSend() {
this.dialogDrag = false; this.pasteFile.some(file => {
const files = type === 'drag' ? e.dataTransfer.files : e.clipboardData.files; this.$refs.chatUpload.upload(file)
const postFiles = Array.prototype.slice.call(files); });
if (postFiles.length > 0) {
e.preventDefault();
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
}
});
}
}, },
chatFile(type, file) { chatFile(type, file) {

View File

@ -66,7 +66,12 @@
</Poptip> </Poptip>
</li> </li>
<!--主任务--> <!--主任务-->
<div v-else-if="ready" :class="{'task-detail':true, 'open-dialog': hasOpenDialog, 'completed': taskDetail.complete_at}"> <div
v-else-if="ready"
:class="{'task-detail':true, 'open-dialog': hasOpenDialog, 'completed': taskDetail.complete_at}"
@drop.prevent="taskPasteDrag($event, 'drag')"
@dragover.prevent="taskDragOver(true, $event)"
@dragleave.prevent="taskDragOver(false, $event)">
<div v-show="taskDetail.id > 0" class="task-info"> <div v-show="taskDetail.id > 0" class="task-info">
<div class="head"> <div class="head">
<TaskMenu <TaskMenu
@ -377,7 +382,7 @@
<div v-else class="no-dialog"> <div v-else class="no-dialog">
<div class="no-tip">{{$L('暂无消息')}}</div> <div class="no-tip">{{$L('暂无消息')}}</div>
<div class="no-input"> <div class="no-input">
<Input <DragInput
class="dialog-input" class="dialog-input"
v-model="msgText" v-model="msgText"
type="textarea" type="textarea"
@ -386,8 +391,9 @@
:autosize="{ minRows: 1, maxRows: 3 }" :autosize="{ minRows: 1, maxRows: 3 }"
:maxlength="255" :maxlength="255"
:placeholder="$L('输入消息...')" :placeholder="$L('输入消息...')"
@on-keydown="msgKeydown"/> @on-keydown="msgKeydown"
<div class="no-send" @click="openSend"> @on-input-paste="msgPasteDrag"/>
<div class="no-send" @click="msgDialog">
<Loading v-if="sendLoad > 0"/> <Loading v-if="sendLoad > 0"/>
<Icon v-else type="md-send" /> <Icon v-else type="md-send" />
</div> </div>
@ -396,6 +402,9 @@
</div> </div>
</div> </div>
<div v-if="!taskDetail.id" class="task-load"><Loading/></div> <div v-if="!taskDetail.id" class="task-load"><Loading/></div>
<div v-if="dialogDrag" class="drag-over" @click="dialogDrag=false">
<div class="drag-text">{{$L('拖动到这里发送')}}</div>
</div>
</div> </div>
</template> </template>
@ -409,10 +418,11 @@ import DialogWrapper from "./DialogWrapper";
import ProjectLog from "./ProjectLog"; import ProjectLog from "./ProjectLog";
import {Store} from "le5le-store"; import {Store} from "le5le-store";
import TaskMenu from "./TaskMenu"; import TaskMenu from "./TaskMenu";
import DragInput from "../../../components/DragInput";
export default { export default {
name: "TaskDetail", name: "TaskDetail",
components: {TaskMenu, ProjectLog, DialogWrapper, TaskUpload, UserInput, TaskPriority, TEditor}, components: {DragInput, TaskMenu, ProjectLog, DialogWrapper, TaskUpload, UserInput, TaskPriority, TEditor},
props: { props: {
taskId: { taskId: {
type: Number, type: Number,
@ -461,6 +471,7 @@ export default {
innerHeight: Math.min(1100, window.innerHeight), innerHeight: Math.min(1100, window.innerHeight),
msgText: '', msgText: '',
msgFile: [],
navActive: 'dialog', navActive: 'dialog',
logLoadIng: false, logLoadIng: false,
@ -489,6 +500,7 @@ export default {
toolbar: 'uploadImages | uploadFiles | bold italic underline forecolor backcolor | codesample | preview screenload' toolbar: 'uploadImages | uploadFiles | bold italic underline forecolor backcolor | codesample | preview screenload'
}, },
dialogDrag: false,
receiveTaskSubscribe: null, receiveTaskSubscribe: null,
} }
}, },
@ -524,6 +536,8 @@ export default {
'taskContents', 'taskContents',
'taskFiles', 'taskFiles',
'taskPriority', 'taskPriority',
'windowMax768'
]), ]),
projectName() { projectName() {
@ -582,7 +596,7 @@ export default {
}, },
hasOpenDialog() { hasOpenDialog() {
return this.taskDetail.dialog_id > 0 && !this.$store.state.windowMax768; return this.taskDetail.dialog_id > 0 && !this.windowMax768;
}, },
dialogStyle() { dialogStyle() {
@ -988,14 +1002,13 @@ export default {
return; return;
} }
e.preventDefault(); e.preventDefault();
this.msgDialog(); if (this.msgText) {
this.msgDialog();
}
} }
}, },
msgDialog() { msgDialog() {
if (!this.msgText) {
return;
}
if (this.sendLoad > 0) { if (this.sendLoad > 0) {
return; return;
} }
@ -1011,18 +1024,20 @@ export default {
this.$store.dispatch("getDialogOne", data.dialog_id).then(() => { this.$store.dispatch("getDialogOne", data.dialog_id).then(() => {
this.sendLoad--; this.sendLoad--;
if ($A.isSubElectron) { if ($A.isSubElectron) {
this.resizeDialog(); this.resizeDialog().then(() => {
this.sendDialogMsg();
});
} else { } else {
this.$nextTick(() => { this.$nextTick(() => {
if (this.$store.state.windowMax768) { if (this.windowMax768) {
this.goForward({path: '/manage/messenger', query: {sendmsg: this.msgText}}); this.goForward({path: '/manage/messenger', query: {sendmsg: this.msgText}});
this.msgText = "";
$A.setStorage("messenger::dialogId", data.dialog_id) $A.setStorage("messenger::dialogId", data.dialog_id)
this.$store.state.dialogOpenId = data.dialog_id; this.$store.state.dialogOpenId = data.dialog_id;
this.$store.dispatch('openTask', 0); this.$store.dispatch('openTask', 0);
} else { } else {
this.$refs.dialog.sendMsg(this.msgText); this.sendDialogMsg();
} }
this.msgText = "";
}); });
} }
}).catch(({msg}) => { }).catch(({msg}) => {
@ -1035,35 +1050,47 @@ export default {
}); });
}, },
openSend() { sendDialogMsg() {
if (this.sendLoad > 0) { if (this.msgFile.length > 0) {
this.$refs.dialog.sendFileMsg(this.msgFile);
} else if (this.msgText) {
this.$refs.dialog.sendMsg(this.msgText);
}
this.msgFile = [];
this.msgText = "";
},
msgPasteDrag(e, type) {
if (this.windowMax768) {
return; return;
} }
this.sendLoad++; const files = type === 'drag' ? e.dataTransfer.files : e.clipboardData.files;
// this.msgFile = Array.prototype.slice.call(files);
this.$store.dispatch("call", { if (this.msgFile.length > 0) {
url: 'project/task/dialog', e.preventDefault();
data: { this.msgDialog()
task_id: this.taskDetail.id, }
}, },
}).then(({data}) => {
this.sendLoad--; taskPasteDrag(e, type) {
this.$store.dispatch("saveTask", data); this.dialogDrag = false;
this.$store.dispatch("getDialogOne", data.dialog_id).catch(() => {}) this.msgPasteDrag(e, type);
if ($A.isSubElectron) { },
this.resizeDialog();
} else { taskDragOver(show, e) {
this.$nextTick(() => { let random = (this.__dialogDrag = $A.randomString(8));
this.goForward({path: '/manage/messenger', query: {sendmsg: this.msgText}}); if (!show) {
$A.setStorage("messenger::dialogId", data.dialog_id) setTimeout(() => {
this.$store.state.dialogOpenId = data.dialog_id; if (random === this.__dialogDrag) {
this.$store.dispatch('openTask', 0); this.dialogDrag = show;
}); }
}, 150);
} else {
if (e.dataTransfer.effectAllowed === 'move') {
return;
} }
}).catch(({msg}) => { this.dialogDrag = true;
this.sendLoad--; }
$A.modalError(msg);
});
}, },
deleteFile(file) { deleteFile(file) {
@ -1112,26 +1139,25 @@ export default {
}, },
resizeDialog() { resizeDialog() {
this.$Electron.ipcRenderer.sendSync('windowSize', { return new Promise(resolve => {
width: Math.max(1100, window.innerWidth), this.$Electron.ipcRenderer.sendSync('windowSize', {
height: Math.max(720, window.innerHeight), width: Math.max(1100, window.innerWidth),
minWidth: 800, height: Math.max(720, window.innerHeight),
minHeight: 600, minWidth: 800,
autoZoom: true, minHeight: 600,
}); autoZoom: true,
if (this.msgText) { });
let num = 0; let num = 0;
let interval = setInterval(() => { let interval = setInterval(() => {
num++; num++;
if (this.$refs.dialog || num > 20) { if (this.$refs.dialog || num > 20) {
clearInterval(interval); clearInterval(interval);
if (this.$refs.dialog) { if (this.$refs.dialog) {
this.$refs.dialog.sendMsg(this.msgText); resolve()
this.msgText = "";
} }
} }
}, 100); }, 100);
} })
}, },
downFile(file) { downFile(file) {

View File

@ -2,23 +2,18 @@
<Upload <Upload
name="files" name="files"
ref="upload" ref="upload"
:action="actionUrl" action=""
:headers="headers"
:data="params"
multiple multiple
:format="uploadFormat" :format="uploadFormat"
:show-upload-list="false" :show-upload-list="false"
:max-size="maxSize" :max-size="maxSize"
:on-progress="handleProgress"
:on-success="handleSuccess"
:on-format-error="handleFormatError" :on-format-error="handleFormatError"
:on-exceeded-size="handleMaxSize"> :on-exceeded-size="handleMaxSize"
:before-upload="handleBeforeUpload">
</Upload> </Upload>
</template> </template>
<script> <script>
import {mapState} from "vuex";
export default { export default {
name: 'TaskUpload', name: 'TaskUpload',
props: { props: {
@ -31,54 +26,10 @@ export default {
data() { data() {
return { return {
uploadFormat: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mov', 'mp3', 'mp4', 'pr', 'psd', 'svg', 'tif'], uploadFormat: ['jpg', 'jpeg', 'png', 'gif', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'txt', 'esp', 'pdf', 'rar', 'zip', 'gz', 'ai', 'avi', 'bmp', 'cdr', 'eps', 'mov', 'mp3', 'mp4', 'pr', 'psd', 'svg', 'tif'],
actionUrl: $A.apiUrl('project/task/upload'),
} }
}, },
computed: {
...mapState(['userToken', 'taskId', 'taskFiles']),
headers() {
return {
fd: $A.getStorageString("userWsFd"),
token: this.userToken,
}
},
params() {
return {
task_id: this.taskId,
}
},
},
methods: { methods: {
handleProgress(event, file) {
//
if (typeof file.tempId === "undefined") {
file.tempId = $A.randomString(8);
file.task_id = this.taskId;
this.taskFiles.push(file);
}
},
handleSuccess({ret, data, msg}, file) {
//
let index = this.taskFiles.findIndex(({tempId}) => tempId == file.tempId);
if (index > -1) {
this.taskFiles.splice(index, 1);
}
if (ret === 1) {
this.taskFiles.push(data);
} else {
this.$refs.upload.fileList.pop();
$A.modalWarning({
title: '发送失败',
content: '文件 ' + file.name + ' 发送失败,' + msg
});
}
},
handleFormatError(file) { handleFormatError(file) {
// //
$A.modalWarning({ $A.modalWarning({
@ -95,15 +46,16 @@ export default {
}); });
}, },
handleBeforeUpload(file) {
//
this.$emit("on-select-file", file)
return false;
},
handleClick() { handleClick() {
// //
this.$refs.upload.handleClick() this.$refs.upload.handleClick()
}, },
upload(file) {
//file
this.$refs.upload.upload(file);
},
} }
} }
</script> </script>

View File

@ -593,6 +593,33 @@
height: 32px; height: 32px;
} }
} }
.drag-over {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 3;
background-color: rgba(255, 255, 255, 0.78);
display: flex;
align-items: center;
justify-content: center;
&:before {
content: "";
position: absolute;
top: 16px;
left: 16px;
right: 16px;
bottom: 16px;
border: 2px dashed #7b7b7b;
border-radius: 12px;
}
.drag-text {
padding: 12px;
font-size: 18px;
color: #666666;
}
}
&.open-dialog { &.open-dialog {
flex-direction: row; flex-direction: row;