Skip to content

Commit

Permalink
优化缓存数据
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaifan committed Dec 13, 2021
1 parent 7cf76d9 commit a5b1fec
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public static function userProject($project_id, $ignoreArchived = true)
}
$project = $builder->first();
if (empty($project)) {
throw new ApiException('项目不存在或不在成员列表内');
throw new ApiException('项目不存在或不在成员列表内', [ 'project_id' => $project_id ], -4001);
}
return $project;
}
Expand Down
19 changes: 12 additions & 7 deletions app/Models/ProjectTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Tasks\PushTask;
use Arr;
use Carbon\Carbon;
use Exception;
use Hhxsv5\LaravelS\Swoole\Task\Task;
use Illuminate\Database\Eloquent\SoftDeletes;
use Request;
Expand Down Expand Up @@ -753,16 +754,20 @@ public static function userTask($task_id, $with = [], $ignoreArchived = true, &$
}
$task = $builder->first();
if (empty($task)) {
throw new ApiException('任务不存在');
throw new ApiException('任务不存在', [ 'task_id' => $task_id ], -4002);
}
//
if (ProjectTaskUser::whereUserid(User::userid())->whereTaskPid($task->id)->exists()) {
$project = Project::find($task->project_id);
if (empty($project)) {
throw new ApiException('项目不存在或已被删除');
}
} else {
try {
$project = Project::userProject($task->project_id, $ignoreArchived);
} catch (Exception $e) {
if (ProjectTaskUser::whereUserid(User::userid())->whereTaskPid($task->id)->exists()) {
$project = Project::find($task->project_id);
if (empty($project)) {
throw new ApiException('项目不存在或已被删除', [ 'task_id' => $task_id ], -4002);
}
} else {
throw new ApiException($e->getMessage(), [ 'task_id' => $task_id ], -4002);
}
}
//
return $task;
Expand Down
8 changes: 4 additions & 4 deletions app/Models/WebSocketDialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ public function deleteDialog()

/**
* 获取对话(同时检验对话身份)
* @param $id
* @param $dialog_id
* @return self
*/
public static function checkDialog($id)
public static function checkDialog($dialog_id)
{
$dialog = WebSocketDialog::whereId($id)->first();
$dialog = WebSocketDialog::find($dialog_id);
if (empty($dialog)) {
throw new ApiException('对话不存在或已被删除');
throw new ApiException('对话不存在或已被删除', ['dialog_id' => $dialog_id], -4003);
}
//
$userid = User::userid();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<div
v-if="dialogData && dialogData.id"
class="dialog-wrapper"
@drop.prevent="chatPasteDrag($event, 'drag')"
@dragover.prevent="chatDragOver(true, $event)"
Expand Down
8 changes: 4 additions & 4 deletions resources/assets/js/pages/manage/messenger.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@
</div>

<div class="messenger-msg">
<div class="msg-dialog-bg">
<div class="msg-dialog-bg-icon"><Icon type="ios-chatbubbles" /></div>
<div class="msg-dialog-bg-text">{{$L('选择一个会话开始聊天')}}</div>
</div>
<DialogWrapper v-if="dialogId > 0" :dialogId="dialogId" @on-active="scrollIntoActive">
<div slot="inputBefore" class="dialog-back" @click="closeDialog">
<Icon type="md-arrow-back" />
</div>
</DialogWrapper>
<div v-else class="dialog-no">
<div class="dialog-no-icon"><Icon type="ios-chatbubbles" /></div>
<div class="dialog-no-text">{{$L('选择一个会话开始聊天')}}</div>
</div>
</div>
</div>
</div>
Expand Down
26 changes: 26 additions & 0 deletions resources/assets/js/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ export default {
resolve({data, msg});
} else {
reject({data, msg: msg || "Unknown error"})
//
if (ret === -4001) {
dispatch("forgetProject", data.project_id);
} else if (ret === -4002) {
dispatch("forgetTask", data.task_id);
} else if (ret === -4003) {
dispatch("forgetDialog", data.dialog_id);
}
}
};
params.error = () => {
Expand Down Expand Up @@ -1287,6 +1295,24 @@ export default {
}
},

/**
* 忘记对话数据
* @param state
* @param dialog_id
*/
forgetDialog({state}, dialog_id) {
let index = state.dialogs.findIndex(({id}) => id == dialog_id);
if (index > -1) {
state.dialogs.splice(index, 1);
}
if (dialog_id == state.method.getStorageInt("messenger::dialogId")) {
state.method.setStorage("messenger::dialogId", 0)
}
setTimeout(() => {
state.method.setStorage("cacheDialogs", state.cacheDialogs = state.dialogs);
})
},

/** *****************************************************************************************/
/** ************************************** 消息 **********************************************/
/** *****************************************************************************************/
Expand Down
12 changes: 9 additions & 3 deletions resources/assets/sass/pages/page-messenger.scss
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,19 @@
}
}
}
.dialog-no {
.msg-dialog-bg {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 0;
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
.dialog-no-icon {
.msg-dialog-bg-icon {
background-color: #f4f5f7;
padding: 20px;
border-radius: 50%;
Expand All @@ -284,7 +290,7 @@
font-size: 46px;
}
}
.dialog-no-text {
.msg-dialog-bg-text {
margin-top: 16px;
color: #bec6cc;
background-color: #f4f5f7;
Expand Down

0 comments on commit a5b1fec

Please sign in to comment.