Initial commit: ERP system with advance verification fixes

This commit is contained in:
System Administrator
2026-03-25 23:55:36 +07:00
commit 563ca12d76
5920 changed files with 828689 additions and 0 deletions
@@ -0,0 +1,101 @@
import { create } from 'zustand'
import { persist } from 'zustand/middleware'
import { API_CONFIG, API_ENDPOINTS } from '../config/api'
export interface User {
id: number
username: string
name: string
email?: string
role: 'admin' | 'manager' | 'user' | 'finance'
department?: string
avatar?: string
}
export interface AuthState {
user: User | null
token: string | null
isAuthenticated: boolean
isLoading: boolean
// Actions
login: (username: string, password: string) => Promise<void>
logout: () => void
setUser: (user: User) => void
setToken: (token: string) => void
clearAuth: () => void
}
export const useAuthStore = create<AuthState>()(
persist(
(set, get) => ({
user: null,
token: null,
isAuthenticated: false,
isLoading: false,
login: async (username: string, password: string) => {
set({ isLoading: true })
try {
// 调用真实后端API
const response = await fetch(`${API_CONFIG.baseURL}${API_ENDPOINTS.auth.login}`, {
method: 'POST',
headers: API_CONFIG.headers,
body: JSON.stringify({ username, password }),
})
if (!response.ok) {
try {
const error = await response.json()
throw new Error(error.message || '登录失败')
} catch (jsonError) {
// 解析JSON失败,使用默认错误消息
throw new Error('登录失败,请检查网络连接')
}
}
const data = await response.json()
set({
user: data.data,
token: 'mock-token', // 后端没有返回token,使用模拟值
isAuthenticated: true,
isLoading: false
})
} catch (error) {
set({ isLoading: false })
throw error
}
},
logout: () => {
set({
user: null,
token: null,
isAuthenticated: false
})
},
setUser: (user: User) => {
set({ user })
},
setToken: (token: string) => {
set({ token })
},
clearAuth: () => {
set({
user: null,
token: null,
isAuthenticated: false
})
}
}),
{
name: 'auth-storage',
}
)
)
@@ -0,0 +1,56 @@
import { create } from 'zustand'
import { persist } from 'zustand/middleware'
import dayjs from 'dayjs'
import { type LanguageCode, getLanguage, getTranslation } from '../locales'
interface LanguageState {
currentLanguage: LanguageCode
setLanguage: (code: LanguageCode) => void
getLanguageInfo: () => any
t: (key: string) => string
}
export const useLanguageStore = create<LanguageState>()(
persist(
(set, get) => ({
currentLanguage: 'zh-CN',
setLanguage: (code: LanguageCode) => {
set({ currentLanguage: code })
// 更新dayjs语言
import('dayjs/locale/zh-cn')
import('dayjs/locale/th')
const localeMap: Record<LanguageCode, string> = {
'zh-CN': 'zh-cn',
'th-TH': 'th',
'lo-LA': 'en',
'en-US': 'en'
}
dayjs.locale(localeMap[code])
},
getLanguageInfo: () => {
return getLanguage(get().currentLanguage)
},
t: (key: string): string => {
const translation = getTranslation(get().currentLanguage)
const keys = key.split('.')
let result: any = translation
for (const k of keys) {
if (result && typeof result === 'object') {
result = result[k]
} else {
return key // 找不到翻译,返回key
}
}
return typeof result === 'string' ? result : key
}
}),
{
name: 'language-storage',
}
)
)