优化缓存数据

This commit is contained in:
kuaifan 2021-12-13 12:00:48 +08:00
parent 7cf76d91a0
commit a5b1fec6b1
7 changed files with 57 additions and 19 deletions

View File

@ -379,7 +379,7 @@ class Project extends AbstractModel
}
$project = $builder->first();
if (empty($project)) {
throw new ApiException('项目不存在或不在成员列表内');
throw new ApiException('项目不存在或不在成员列表内', [ 'project_id' => $project_id ], -4001);
}
return $project;
}

View File

@ -7,6 +7,7 @@ use App\Module\Base;
use App\Tasks\PushTask;
use Arr;
use Carbon\Carbon;
use Exception;
use Hhxsv5\LaravelS\Swoole\Task\Task;
use Illuminate\Database\Eloquent\SoftDeletes;
use Request;
@ -753,16 +754,20 @@ class ProjectTask extends AbstractModel
}
$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;

View File

@ -65,14 +65,14 @@ class WebSocketDialog extends AbstractModel
/**
* 获取对话(同时检验对话身份)
* @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();

View File

@ -1,5 +1,6 @@
<template>
<div
v-if="dialogData && dialogData.id"
class="dialog-wrapper"
@drop.prevent="chatPasteDrag($event, 'drag')"
@dragover.prevent="chatDragOver(true, $event)"

View File

@ -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>

View File

@ -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 = () => {
@ -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);
})
},
/** *****************************************************************************************/
/** ************************************** 消息 **********************************************/
/** *****************************************************************************************/

View File

@ -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%;
@ -284,7 +290,7 @@
font-size: 46px;
}
}
.dialog-no-text {
.msg-dialog-bg-text {
margin-top: 16px;
color: #bec6cc;
background-color: #f4f5f7;