up. ws update.
This commit is contained in:
parent
64f9ffe310
commit
a4768d49b0
@ -3,6 +3,7 @@
|
|||||||
namespace app\command\admin;
|
namespace app\command\admin;
|
||||||
|
|
||||||
|
|
||||||
|
use app\entity\SysUserClient;
|
||||||
use app\service\admin\LoginService;
|
use app\service\admin\LoginService;
|
||||||
use think\console\Command;
|
use think\console\Command;
|
||||||
use think\console\Input;
|
use think\console\Input;
|
||||||
@ -51,16 +52,30 @@ class Worker extends Command
|
|||||||
if($messageJson) {
|
if($messageJson) {
|
||||||
if($messageJson['event'] == 'bind_connect_id') {
|
if($messageJson['event'] == 'bind_connect_id') {
|
||||||
$authorization = $messageJson['data']['token'] ?? '';
|
$authorization = $messageJson['data']['token'] ?? '';
|
||||||
|
$clientId = $messageJson['data']['clientId'] ?? '';
|
||||||
|
$clientName = $messageJson['data']['clientName'] ?? '';
|
||||||
|
$clientVersion = $messageJson['data']['clientVersion'] ?? '';
|
||||||
$authorization = str_replace('Bearer ', '', $authorization);
|
$authorization = str_replace('Bearer ', '', $authorization);
|
||||||
$loginSrv = new LoginService();
|
$loginSrv = new LoginService();
|
||||||
$auth = $loginSrv->checkUserAccessToken($authorization);
|
$auth = $loginSrv->checkUserAccessToken($authorization);
|
||||||
var_dump("当前用户: ".$auth->userId);
|
var_dump("当前用户: ".$auth->userId);
|
||||||
|
// 用户信息
|
||||||
$connection->userId = $auth->userId;
|
$connection->userId = $auth->userId;
|
||||||
|
// 客户端信息
|
||||||
|
$connection->clientId = $clientId;
|
||||||
|
$connection->clientName = $clientName;
|
||||||
|
$connection->clientVersion = $clientVersion;
|
||||||
|
// 绑定成功通知
|
||||||
$connection->send(json_encode(['event'=>'bind_connect_id_success','userId'=>$auth->userId]));
|
$connection->send(json_encode(['event'=>'bind_connect_id_success','userId'=>$auth->userId]));
|
||||||
}
|
}
|
||||||
if ($messageJson['event'] == 'lock_client_screen') {
|
if ($messageJson['event'] == 'lock_client_screen') {
|
||||||
if($connection->userId) {
|
if($connection->userId) {
|
||||||
|
$lock_password = $messageJson['data']['lockPassword'] ?? '';
|
||||||
var_dump("锁定客户端/通知全部ws触发锁定操作");
|
var_dump("锁定客户端/通知全部ws触发锁定操作");
|
||||||
|
SysUserClient::where([
|
||||||
|
'client_id' => $connection->clientId,
|
||||||
|
'client_name'=> $connection->clientName
|
||||||
|
])->update(['is_lock'=>1,'lock_password'=>$lock_password,'lock_time'=>date('Y-m-d H:i:s')]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,9 +11,16 @@
|
|||||||
:close-on-press-escape="false"
|
:close-on-press-escape="false"
|
||||||
:close-on-click-modal="false"
|
:close-on-click-modal="false"
|
||||||
>
|
>
|
||||||
<el-input type="password" v-model="lockPassword" size="large" placeholder="请输入临时锁定密码/为空则使用默认使用账号密码"></el-input>
|
<el-input
|
||||||
<div style="margin-top: 20px;">
|
type="password"
|
||||||
<el-button class="ele-fluid" type="primary" @click="confirmLock">锁定客户端</el-button>
|
v-model="lockPassword"
|
||||||
|
size="large"
|
||||||
|
placeholder="请输入临时锁定密码/为空则使用默认使用账号密码"
|
||||||
|
/>
|
||||||
|
<div style="margin-top: 20px">
|
||||||
|
<el-button class="ele-fluid" type="primary" @click="confirmLock"
|
||||||
|
>锁定客户端</el-button
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</ele-modal>
|
</ele-modal>
|
||||||
</template>
|
</template>
|
||||||
@ -21,6 +28,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useMobile } from '@/utils/use-mobile';
|
import { useMobile } from '@/utils/use-mobile';
|
||||||
|
import { wsInstance, WsSendEventType } from '@/plugins/websocket';
|
||||||
|
|
||||||
/** 弹窗是否打开 */
|
/** 弹窗是否打开 */
|
||||||
const visible = defineModel({ type: Boolean });
|
const visible = defineModel({ type: Boolean });
|
||||||
@ -29,8 +37,11 @@ const visible = defineModel({ type: Boolean });
|
|||||||
const { mobile } = useMobile();
|
const { mobile } = useMobile();
|
||||||
|
|
||||||
const lockLoading = ref(false);
|
const lockLoading = ref(false);
|
||||||
const lockPassword = ref("");
|
const lockPassword = ref('');
|
||||||
const confirmLock = () => {
|
const confirmLock = () => {
|
||||||
lockLoading.value = true;
|
lockLoading.value = true;
|
||||||
}
|
wsInstance.sendMessage(WsSendEventType.LOCK_CLIENT_SCREEN, {
|
||||||
|
lockPassword: lockPassword.value
|
||||||
|
});
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -6,7 +6,8 @@ export enum WsEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum WsSendEventType {
|
export enum WsSendEventType {
|
||||||
BIND_CONNECT_ID = 'bind_connect_id'
|
BIND_CONNECT_ID = 'bind_connect_id',
|
||||||
|
LOCK_CLIENT_SCREEN = 'lock_client_screen',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum WsConnectionStatus {
|
export enum WsConnectionStatus {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import type { User } from '@/api/system/user/model';
|
|||||||
import type { Menu } from '@/api/system/menu/model';
|
import type { Menu } from '@/api/system/menu/model';
|
||||||
import type { DictionaryData } from '@/api/system/dictionary-data/model';
|
import type { DictionaryData } from '@/api/system/dictionary-data/model';
|
||||||
import { getUserInfo } from '@/api/layout';
|
import { getUserInfo } from '@/api/layout';
|
||||||
import { getToken } from '@/utils/token-util';
|
import {getClientInfo, getToken} from '@/utils/token-util';
|
||||||
import {
|
import {
|
||||||
WsEventContext,
|
WsEventContext,
|
||||||
wsEventManager,
|
wsEventManager,
|
||||||
@ -79,9 +79,13 @@ export const useUserStore = defineStore('user', {
|
|||||||
wsEventManager.subscribe(WsEvent.CONNECTED, (sub: WsEventContext) => {
|
wsEventManager.subscribe(WsEvent.CONNECTED, (sub: WsEventContext) => {
|
||||||
console.log('事件执行, 绑定连接和用户关系');
|
console.log('事件执行, 绑定连接和用户关系');
|
||||||
// 绑定用户到websocket的connect_id中
|
// 绑定用户到websocket的connect_id中
|
||||||
|
const clientInfo = getClientInfo();
|
||||||
wsInstance.sendMessage(WsSendEventType.BIND_CONNECT_ID, {
|
wsInstance.sendMessage(WsSendEventType.BIND_CONNECT_ID, {
|
||||||
token: getToken(),
|
token: getToken(),
|
||||||
userId: result.userId
|
userId: result.userId,
|
||||||
|
clientId: clientInfo.id,
|
||||||
|
clientName: clientInfo.name,
|
||||||
|
clientVersion: clientInfo.version
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return { menus, homePath };
|
return { menus, homePath };
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user