Initial commit: 网络验证平台
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { storeToRefs } from 'pinia'
|
||||
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
export function useAuth() {
|
||||
const router = useRouter()
|
||||
|
||||
const authStore = useAuthStore()
|
||||
const { isLogin, user } = storeToRefs(authStore)
|
||||
const loading = ref(false)
|
||||
|
||||
function logout() {
|
||||
authStore.logout()
|
||||
router.push({ path: '/auth/sign-in' })
|
||||
}
|
||||
|
||||
function toHome() {
|
||||
router.push({ path: '/dashboard' })
|
||||
}
|
||||
|
||||
async function login() {
|
||||
loading.value = true
|
||||
await new Promise(resolve => setTimeout(resolve, 10))
|
||||
isLogin.value = true
|
||||
loading.value = false
|
||||
|
||||
const redirect = router.currentRoute.value.query.redirect as string
|
||||
if (!redirect || redirect.startsWith('//')) {
|
||||
toHome()
|
||||
}
|
||||
else {
|
||||
router.push(redirect)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
logout,
|
||||
login,
|
||||
isLogin,
|
||||
user,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import type { AxiosError } from 'axios'
|
||||
|
||||
import axios from 'axios'
|
||||
|
||||
import env from '@/utils/env'
|
||||
|
||||
export function useAxios() {
|
||||
const axiosInstance = axios.create({
|
||||
baseURL: env.VITE_SERVER_API_URL + env.VITE_SERVER_API_PREFIX,
|
||||
timeout: env.VITE_SERVER_API_TIMEOUT,
|
||||
})
|
||||
|
||||
axiosInstance.interceptors.request.use((config) => {
|
||||
return config
|
||||
}, (error) => {
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
axiosInstance.interceptors.response.use((response) => {
|
||||
return response
|
||||
}, (error: AxiosError) => {
|
||||
// if status is not 2xx, throw error
|
||||
// you can handle error here
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
return {
|
||||
axiosInstance,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { BadgeHelp, BellDot, Boxes, Bug, Component, CreditCard, LayoutDashboard, ListTodo, Palette, PictureInPicture2, Podcast, Settings, SquareUserRound, User, Users, Wrench } from 'lucide-vue-next'
|
||||
import { ref } from 'vue'
|
||||
|
||||
import type { NavGroup } from '@/components/app-sidebar/types'
|
||||
|
||||
export function useSidebar() {
|
||||
const settingsNavItems = [
|
||||
{ title: 'Profile', url: '/settings/', icon: User },
|
||||
{ title: 'Account', url: '/settings/account', icon: Wrench },
|
||||
{ title: 'Appearance', url: '/settings/appearance', icon: Palette },
|
||||
{ title: 'Notifications', url: '/settings/notifications', icon: BellDot },
|
||||
{ title: 'Display', url: '/settings/display', icon: PictureInPicture2 },
|
||||
]
|
||||
|
||||
const navData = ref<NavGroup[]> ([
|
||||
{
|
||||
title: 'General',
|
||||
items: [
|
||||
{ title: 'Dashboard', url: '/dashboard', icon: LayoutDashboard },
|
||||
{ title: 'Tasks', url: '/tasks', icon: ListTodo },
|
||||
{ title: 'Apps', url: '/apps', icon: Boxes },
|
||||
{ title: 'Users', url: '/users', icon: Users },
|
||||
{ title: 'Ai Talk Example', url: '/ai-talk', icon: Podcast },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Pages',
|
||||
items: [
|
||||
{
|
||||
title: 'Auth',
|
||||
icon: SquareUserRound,
|
||||
items: [
|
||||
{ title: 'Sign In', url: '/auth/sign-in' },
|
||||
{ title: 'Sign In(2 Col)', url: '/auth/sign-in-2' },
|
||||
{ title: 'Sign Up', url: '/auth/sign-up' },
|
||||
{ title: 'Forgot Password', url: '/auth/forgot-password' },
|
||||
{ title: 'OTP', url: '/auth/otp' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Errors',
|
||||
icon: Bug,
|
||||
items: [
|
||||
{ title: '401 | Unauthorized', url: '/errors/401' },
|
||||
{ title: '403 | Forbidden', url: '/errors/403' },
|
||||
{ title: '404 | Not Found', url: '/errors/404' },
|
||||
{ title: '500 | Internal Server Error', url: '/errors/500' },
|
||||
{ title: '503 | Maintenance Error', url: '/errors/503' },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'Other',
|
||||
items: [
|
||||
{ title: 'Settings', icon: Settings, items: settingsNavItems },
|
||||
{ title: 'SVA Components', url: '/sva-components', icon: Component },
|
||||
{ title: 'Help Center', url: '/help-center', icon: BadgeHelp,
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const otherPages = ref<NavGroup[]>([
|
||||
{
|
||||
title: 'Other',
|
||||
items: [
|
||||
{
|
||||
title: 'Plans & Pricing',
|
||||
icon: CreditCard,
|
||||
url: '/billing',
|
||||
},
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
return {
|
||||
navData,
|
||||
otherPages,
|
||||
settingsNavItems,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { watch } from 'vue'
|
||||
|
||||
import { THEMES } from '@/constants/themes'
|
||||
import { useThemeStore } from '@/stores/theme'
|
||||
|
||||
export function useSystemTheme() {
|
||||
const themeStore = useThemeStore()
|
||||
const { setTheme, setRadius } = themeStore
|
||||
const { theme, radius } = storeToRefs(themeStore)
|
||||
|
||||
if (typeof document !== 'undefined') {
|
||||
watch(theme, (theme) => {
|
||||
document.documentElement.classList.remove(...THEMES.map(t => `theme-${t}`))
|
||||
document.documentElement.classList.add(`theme-${theme}`)
|
||||
}, { immediate: true })
|
||||
|
||||
watch(radius, (radius) => {
|
||||
document.documentElement.style.setProperty('--radius', `${radius}rem`)
|
||||
}, { immediate: true })
|
||||
}
|
||||
|
||||
return {
|
||||
theme,
|
||||
radius,
|
||||
setTheme,
|
||||
setRadius,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user