fix: 移动端无法上传任务文件的问题

This commit is contained in:
kuaifan 2022-01-26 19:11:16 +08:00
parent 886baa427b
commit 08372facd7
5 changed files with 27 additions and 82 deletions

View File

@ -2,7 +2,6 @@
namespace App\Http\Controllers\Api;
use App\Exceptions\ApiException;
use App\Models\AbstractModel;
use App\Models\File;

View File

@ -1274,72 +1274,6 @@ class ProjectController extends AbstractController
return Base::retSuccess('修改成功', $data);
}
/**
* @api {post} api/project/task/upload 26. 上传文件
*
* @apiDescription 需要token身份项目、任务负责人
* @apiVersion 1.0.0
* @apiGroup project
* @apiName task__upload
*
* @apiParam {Number} task_id 任务ID
* @apiParam {String} [filename] post-文件名称
* @apiParam {String} [image64] post-base64图片二选一
* @apiParam {File} [files] post-文件对象(二选一)
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function task__upload()
{
$user = User::auth();
//
$task_id = Base::getPostInt('task_id');
//
$task = ProjectTask::userTask($task_id, true, true);
//
$path = "uploads/task/" . $task->id . "/";
$image64 = Base::getPostValue('image64');
$fileName = Base::getPostValue('filename');
if ($image64) {
$data = Base::image64save([
"image64" => $image64,
"path" => $path,
"fileName" => $fileName,
]);
} else {
$data = Base::upload([
"file" => Request::file('files'),
"type" => 'file',
"path" => $path,
"fileName" => $fileName,
]);
}
//
if (Base::isError($data)) {
return Base::retError($data['msg']);
} else {
$fileData = $data['data'];
$file = ProjectTaskFile::createInstance([
'project_id' => $task->project_id,
'task_id' => $task->id,
'name' => $fileData['name'],
'size' => $fileData['size'] * 1024,
'ext' => $fileData['ext'],
'path' => $fileData['path'],
'thumb' => Base::unFillUrl($fileData['thumb']),
'userid' => $user->userid,
]);
$file->save();
//
$file = ProjectTaskFile::find($file->id);
$task->addLog("上传文件:" . $file->name);
$task->pushMsg('upload', $file);
return Base::retSuccess("上传成功", $file);
}
}
/**
* @api {get} api/project/task/dialog 27. 创建/获取聊天室
*

View File

@ -30,9 +30,6 @@ class VerifyCsrfToken extends Middleware
// 修改任务
'api/project/task/update/',
// 上传任务问题
'api/project/task/upload/',
// 聊天发文件
'api/dialog/msg/sendfile/',

View File

@ -216,12 +216,21 @@ export default {
watch: {
'$route': {
handler (route) {
if (route.query && route.query.sendmsg && this.msgText == '') {
if ($A.isJson(window.__sendDialogMsg) && window.__sendDialogMsg.time > $A.Time()) {
const {msgFile, msgText} = window.__sendDialogMsg;
window.__sendDialogMsg = null;
this.$nextTick(() => {
if ($A.isArray(msgFile) && msgFile.length > 0) {
this.sendFileMsg(msgFile);
} else if (msgText) {
this.sendMsg(msgText);
}
});
}
if (route.query && route.query._) {
let query = $A.cloneJSON(route.query);
delete query.sendmsg;
delete query._;
this.goForward({query}, true);
this.msgText = route.query.sendmsg;
this.$nextTick(this.sendMsg);
}
},
immediate: true

View File

@ -347,7 +347,7 @@
</EDropdown>
</div>
</div>
<TaskUpload ref="upload" class="upload"/>
<TaskUpload ref="upload" class="upload" @on-select-file="onSelectFile"/>
</div>
<div v-show="taskDetail.id > 0" class="task-dialog" :style="dialogStyle">
<template v-if="hasOpenDialog">
@ -1030,8 +1030,14 @@ export default {
} else {
this.$nextTick(() => {
if (this.windowMax768) {
this.goForward({path: '/manage/messenger', query: {sendmsg: this.msgText}});
window.__sendDialogMsg = {
time: $A.Time() + 10,
msgText: this.msgText,
msgFile: this.msgFile
};
this.msgFile = [];
this.msgText = "";
this.goForward({path: '/manage/messenger', query: {_: $A.randomString(6)}});
$A.setStorage("messenger::dialogId", data.dialog_id)
this.$store.state.dialogOpenId = data.dialog_id;
this.$store.dispatch('openTask', 0);
@ -1061,9 +1067,6 @@ export default {
},
msgPasteDrag(e, type) {
if (this.windowMax768) {
return;
}
const files = type === 'drag' ? e.dataTransfer.files : e.clipboardData.files;
this.msgFile = Array.prototype.slice.call(files);
if (this.msgFile.length > 0) {
@ -1093,6 +1096,11 @@ export default {
}
},
onSelectFile(file) {
this.msgFile = [file];
this.msgDialog()
},
deleteFile(file) {
this.$set(file, '_deling', false);
this.$store.dispatch("forgetTaskFile", file.id)
@ -1110,9 +1118,7 @@ export default {
openMenu(task) {
const el = this.$refs[`taskMenu_${task.id}`];
if (el) {
el.handleClick()
}
el && el.handleClick()
},
openNewWin() {