up. 使用状态管理器管理设备
This commit is contained in:
parent
ed15d9ffd8
commit
64e91f1f5c
@ -38,7 +38,7 @@
|
||||
import { ref } from 'vue';
|
||||
import { WsEvent, wsEventManager } from '@/plugins/websocket';
|
||||
import { clientScreenUnlock } from '@/api/layout';
|
||||
import {useClientStore} from "@/store/modules/client";
|
||||
import { LockScreenStatus, useClientStore } from "@/store/modules/client";
|
||||
|
||||
/** 设备状态管理器 */
|
||||
const clientStore = useClientStore();
|
||||
@ -55,7 +55,7 @@
|
||||
|
||||
clientScreenUnlock({ password: lockPassword.value })
|
||||
.then(() => {
|
||||
clientStore.setLockScreen(false)
|
||||
clientStore.setLockScreen(LockScreenStatus.UNLOCK)
|
||||
lockPassword.value = ''; // 清空密码
|
||||
})
|
||||
.catch((message) => {
|
||||
@ -67,6 +67,6 @@
|
||||
};
|
||||
/** 事件订阅器 - 锁屏事件 */
|
||||
wsEventManager.subscribe(WsEvent.LOCK_CLIENT_SCREEN, () => {
|
||||
clientStore.setLockScreen(true);
|
||||
clientStore.setLockScreen(LockScreenStatus.LOCK);
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -2,20 +2,58 @@
|
||||
* 设备状态管理
|
||||
*/
|
||||
import { defineStore } from 'pinia';
|
||||
import {CLIENT_ID_CACHE_NAME} from "@/config/setting";
|
||||
import { generateGUID } from "@/utils/common";
|
||||
|
||||
export enum LockScreenStatus {
|
||||
LOCK = 1,
|
||||
UNLOCK = 0
|
||||
}
|
||||
|
||||
export interface ClientState {
|
||||
/** 客户端ID */
|
||||
clientId: string;
|
||||
/** 客户端名称 */
|
||||
clientName: string;
|
||||
/** 客户端版本号 */
|
||||
clientVersion: string;
|
||||
/** 是否锁定会话 */
|
||||
lockScreen: boolean;
|
||||
}
|
||||
|
||||
|
||||
export const useClientStore = defineStore('client', {
|
||||
state: (): ClientState => ({
|
||||
/** 客户端ID */
|
||||
clientId: getClientId(),
|
||||
/** 客户端名称 */
|
||||
clientName: 'PAdmin',
|
||||
/** 客户端版本号 */
|
||||
clientVersion: "1.0.0",
|
||||
/** 锁定会话 */
|
||||
lockScreen: false,
|
||||
}),
|
||||
actions: {
|
||||
setLockScreen(value: boolean) {
|
||||
console.log("锁屏")
|
||||
this.lockScreen = value;
|
||||
/**
|
||||
* 设置锁屏状态
|
||||
* @param isLock
|
||||
*/
|
||||
setLockScreen(isLock: LockScreenStatus = LockScreenStatus.UNLOCK) {
|
||||
this.lockScreen = isLock == 1;
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* 获取客户端ID、没有的话则生成,格式为GUID格式
|
||||
*/
|
||||
function getClientId(): string {
|
||||
let clientId = localStorage.getItem(CLIENT_ID_CACHE_NAME);
|
||||
if (!clientId) {
|
||||
clientId = generateGUID();
|
||||
localStorage.setItem(CLIENT_ID_CACHE_NAME, clientId);
|
||||
return clientId
|
||||
}
|
||||
return clientId
|
||||
}
|
||||
|
||||
@ -2,14 +2,19 @@ import type { Router } from 'vue-router';
|
||||
import type { Action } from 'element-plus';
|
||||
import { ElMessageBox } from 'element-plus';
|
||||
import { removeToken } from '@/utils/token-util';
|
||||
import { uuid } from 'ele-admin-plus';
|
||||
|
||||
export function generateGUID() {
|
||||
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
|
||||
export function generateGUID(): string {
|
||||
let guidStr = ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c: number) =>
|
||||
(
|
||||
c ^
|
||||
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
|
||||
).toString(16)
|
||||
);
|
||||
if (guidStr) {
|
||||
return guidStr
|
||||
}
|
||||
return uuid()
|
||||
}
|
||||
/**
|
||||
* 退出登录
|
||||
|
||||
@ -4,6 +4,19 @@
|
||||
import { TOKEN_CACHE_NAME, CLIENT_ID_CACHE_NAME } from '@/config/setting';
|
||||
import {generateGUID} from "@/utils/common";
|
||||
|
||||
export function getClientId() {
|
||||
let clientId = localStorage.getItem(CLIENT_ID_CACHE_NAME);
|
||||
if (!clientId) {
|
||||
clientId = generateGUID();
|
||||
localStorage.setItem(CLIENT_ID_CACHE_NAME, clientId);
|
||||
}
|
||||
return {
|
||||
name: 'PAdmin',
|
||||
id: clientId,
|
||||
version: "1.0.0"
|
||||
};
|
||||
}
|
||||
|
||||
export function getClientInfo() {
|
||||
let clientId = localStorage.getItem(CLIENT_ID_CACHE_NAME);
|
||||
if (!clientId) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user