新增空闲锁屏、修复401等问题,新增文件版本管理、共享库等占位符
This commit is contained in:
@@ -47,6 +47,9 @@ export const useAuthStore = defineStore("auth", () => {
|
||||
login,
|
||||
fetchMe: fetchMeAction,
|
||||
logout,
|
||||
setToken: (newToken: string) => {
|
||||
token.value = newToken;
|
||||
},
|
||||
requestReLogin: () => {
|
||||
forceLogin.value = true;
|
||||
},
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
|
||||
export type LockReason = "idle" | "extend_failed" | "token_invalid";
|
||||
|
||||
export const useSessionStore = defineStore("session", () => {
|
||||
const locked = ref(false);
|
||||
const lockReason = ref<LockReason | null>(null);
|
||||
const unlockAttempts = ref(0);
|
||||
const lastUserActiveAt = ref(Date.now());
|
||||
const lastNetworkActiveAt = ref(Date.now());
|
||||
const lastExtendAt = ref(0);
|
||||
|
||||
const recordUserActivity = (ts: number = Date.now()) => {
|
||||
lastUserActiveAt.value = ts;
|
||||
};
|
||||
|
||||
const recordNetworkActivity = (ts: number = Date.now()) => {
|
||||
lastNetworkActiveAt.value = ts;
|
||||
};
|
||||
|
||||
const lock = (reason: LockReason) => {
|
||||
locked.value = true;
|
||||
lockReason.value = reason;
|
||||
};
|
||||
|
||||
const unlock = () => {
|
||||
locked.value = false;
|
||||
lockReason.value = null;
|
||||
unlockAttempts.value = 0;
|
||||
};
|
||||
|
||||
const incrementUnlockAttempt = () => {
|
||||
unlockAttempts.value += 1;
|
||||
};
|
||||
|
||||
const setLastExtendAt = (ts: number) => {
|
||||
lastExtendAt.value = ts;
|
||||
};
|
||||
|
||||
return {
|
||||
locked,
|
||||
lockReason,
|
||||
unlockAttempts,
|
||||
lastUserActiveAt,
|
||||
lastNetworkActiveAt,
|
||||
lastExtendAt,
|
||||
recordUserActivity,
|
||||
recordNetworkActivity,
|
||||
lock,
|
||||
unlock,
|
||||
incrementUnlockAttempt,
|
||||
setLastExtendAt,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user