Skip to content

Commit

Permalink
fix: 移动端无法上传任务文件的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Jan 26, 2022
1 parent 886baa4 commit 08372fa
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 82 deletions.
1 change: 0 additions & 1 deletion app/Http/Controllers/Api/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\Controllers\Api;


use App\Exceptions\ApiException;
use App\Models\AbstractModel;
use App\Models\File;
Expand Down
66 changes: 0 additions & 66 deletions app/Http/Controllers/Api/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1274,72 +1274,6 @@ public function task__update()
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. 创建/获取聊天室
*
Expand Down
3 changes: 0 additions & 3 deletions app/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class VerifyCsrfToken extends Middleware
// 修改任务
'api/project/task/update/',

// 上传任务问题
'api/project/task/upload/',

// 聊天发文件
'api/dialog/msg/sendfile/',

Expand Down
17 changes: 13 additions & 4 deletions resources/assets/js/pages/manage/components/DialogWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions resources/assets/js/pages/manage/components/TaskDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -1110,9 +1118,7 @@ export default {
openMenu(task) {
const el = this.$refs[`taskMenu_${task.id}`];
if (el) {
el.handleClick()
}
el && el.handleClick()
},
openNewWin() {
Expand Down

0 comments on commit 08372fa

Please sign in to comment.