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