任务三

This commit is contained in:
Yvan 2026-01-07 19:37:51 +08:00
parent 66e28bad92
commit 0f2e043133
5 changed files with 247 additions and 0 deletions

View File

@ -0,0 +1,37 @@
import React from 'react';
interface LogoProps {
collapsed?: boolean;
}
const Logo: React.FC<LogoProps> = ({ collapsed }) => {
return (
<div style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
}}>
<img
src="/logo.svg"
alt="KRA Admin"
style={{
height: 32,
width: 32,
}}
/>
{!collapsed && (
<span style={{
marginLeft: 8,
fontSize: 18,
fontWeight: 'bold',
color: '#3b82f6',
}}>
KRA Admin
</span>
)}
</div>
);
};
export default Logo;

76
web/src/utils/format.ts Normal file
View File

@ -0,0 +1,76 @@
/**
* - GVA的format.js
*/
/**
* - GVA的setBodyPrimaryColor
* @param color
* @param mode 'light' | 'dark'
*/
export function setBodyPrimaryColor(color: string, mode: 'light' | 'dark' = 'light'): void {
const root = document.documentElement;
root.style.setProperty('--primary-color', color);
// 设置不同透明度的主题色变体
root.style.setProperty('--primary-color-hover', adjustColor(color, mode === 'dark' ? 20 : -10));
root.style.setProperty('--primary-color-active', adjustColor(color, mode === 'dark' ? 30 : -20));
root.style.setProperty('--primary-color-light', adjustColor(color, mode === 'dark' ? -30 : 40));
}
/**
*
* @param color
* @param amount
*/
function adjustColor(color: string, amount: number): string {
const hex = color.replace('#', '');
const num = parseInt(hex, 16);
let r = (num >> 16) + amount;
let g = ((num >> 8) & 0x00FF) + amount;
let b = (num & 0x0000FF) + amount;
r = Math.max(0, Math.min(255, r));
g = Math.max(0, Math.min(255, g));
b = Math.max(0, Math.min(255, b));
return `#${((r << 16) | (g << 8) | b).toString(16).padStart(6, '0')}`;
}
/**
*
* @param date
* @param format
*/
export function formatDate(date: Date | string | number, format: string = 'YYYY-MM-DD HH:mm:ss'): string {
const d = new Date(date);
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, '0');
const day = String(d.getDate()).padStart(2, '0');
const hours = String(d.getHours()).padStart(2, '0');
const minutes = String(d.getMinutes()).padStart(2, '0');
const seconds = String(d.getSeconds()).padStart(2, '0');
return format
.replace('YYYY', String(year))
.replace('MM', month)
.replace('DD', day)
.replace('HH', hours)
.replace('mm', minutes)
.replace('ss', seconds);
}
/**
*
* @param bytes
*/
export function formatFileSize(bytes: number): string {
if (bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}

7
web/src/utils/index.ts Normal file
View File

@ -0,0 +1,7 @@
/**
* - GVA的utils
*/
export * from './page';
export * from './storage';
export * from './format';

25
web/src/utils/page.ts Normal file
View File

@ -0,0 +1,25 @@
/**
* - GVA的page.js
*/
const APP_NAME = 'KRA Admin';
/**
*
* @param pageTitle
* @returns
*/
export function getPageTitle(pageTitle?: string): string {
if (pageTitle) {
return `${pageTitle} - ${APP_NAME}`;
}
return APP_NAME;
}
/**
*
* @param title
*/
export function setPageTitle(title?: string): void {
document.title = getPageTitle(title);
}

102
web/src/utils/storage.ts Normal file
View File

@ -0,0 +1,102 @@
/**
* - GVA的用户存储逻辑
*/
const TOKEN_KEY = 'token';
const USER_INFO_KEY = 'userInfo';
/**
* Token
*/
export function getToken(): string | null {
return localStorage.getItem(TOKEN_KEY);
}
/**
* Token
*/
export function setToken(token: string): void {
localStorage.setItem(TOKEN_KEY, token);
}
/**
* Token
*/
export function removeToken(): void {
localStorage.removeItem(TOKEN_KEY);
}
/**
*
*/
export function getUserInfo(): API.UserInfo | null {
const userInfo = localStorage.getItem(USER_INFO_KEY);
if (userInfo) {
try {
return JSON.parse(userInfo);
} catch (e) {
return null;
}
}
return null;
}
/**
*
*/
export function setUserInfo(userInfo: API.UserInfo): void {
localStorage.setItem(USER_INFO_KEY, JSON.stringify(userInfo));
}
/**
*
*/
export function removeUserInfo(): void {
localStorage.removeItem(USER_INFO_KEY);
}
/**
* - GVA的ClearStorage
*/
export function clearStorage(): void {
removeToken();
removeUserInfo();
sessionStorage.clear();
localStorage.removeItem('originSetting');
}
/**
*
*/
export function checkNeedToHome(): boolean {
const need = sessionStorage.getItem('needToHome') === 'true';
if (need) {
sessionStorage.removeItem('needToHome');
}
return need;
}
/**
*
*/
export function setNeedToHome(): void {
sessionStorage.setItem('needToHome', 'true');
}
/**
*
*/
export function checkNeedCloseAll(): boolean {
const need = sessionStorage.getItem('needCloseAll') === 'true';
if (need) {
sessionStorage.removeItem('needCloseAll');
}
return need;
}
/**
*
*/
export function setNeedCloseAll(): void {
sessionStorage.setItem('needCloseAll', 'true');
}