feat(aihr): complete uni-app role workflows

This commit is contained in:
2026-07-09 10:42:20 +08:00
parent e4070c8b8c
commit 678543e8a5
73 changed files with 15696 additions and 134 deletions
+49
View File
@@ -0,0 +1,49 @@
import type { LoginResult } from '@/types/api';
export const tokenKey = 'aihr_mobile_access_token';
export const clientIdKey = 'aihr_mobile_client_id';
export const phoneKey = 'aihr_mobile_phone';
export const loginRedirectKey = 'aihr_mobile_login_redirect';
export const phonePattern = /^1[3-9]\d{9}$/;
export interface AuthState {
token: string;
clientId: string;
phone: string;
}
export const getAuth = (): AuthState => ({
token: uni.getStorageSync(tokenKey) || '',
clientId: uni.getStorageSync(clientIdKey) || '',
phone: uni.getStorageSync(phoneKey) || ''
});
export const isLoggedIn = () => {
const auth = getAuth();
return Boolean(auth.token && auth.clientId && auth.phone);
};
export const saveAuth = (result: LoginResult, phone: string) => {
uni.setStorageSync(tokenKey, result.access_token);
uni.setStorageSync(clientIdKey, result.client_id);
uni.setStorageSync(phoneKey, phone);
};
export const clearAuth = () => {
uni.removeStorageSync(tokenKey);
uni.removeStorageSync(clientIdKey);
uni.removeStorageSync(phoneKey);
uni.removeStorageSync(loginRedirectKey);
};
export const rememberLoginRedirect = (url: string) => {
uni.setStorageSync(loginRedirectKey, url);
};
export const consumeLoginRedirect = () => {
const url = uni.getStorageSync(loginRedirectKey) || '';
uni.removeStorageSync(loginRedirectKey);
return url;
};
export const validatePhone = (phone: string) => phonePattern.test(phone);