mirror of
https://github.com/fantastic-admin/basic.git
synced 2026-10-06 12:53:21 +08:00
feat: 增加 core-element-plus 应用,同时 core 应用将不再集成任何第三方组件库
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
- AI 友好的工程底座,内置多个 Skills
|
||||
- 一流的技术栈:Vue 3.6 / Vite 8 / Pinia / UnoCSS / VueUse / TypeScript / ESLint / Stylelint / ...
|
||||
- 自由选择喜爱的 UI 库,默认 Element Plus
|
||||
- 自由选择喜爱的三方 UI 库
|
||||
- 18 套默认主题方案且可扩展,给不同行业提供专属品牌气质
|
||||
- 7 款导航菜单模式,匹配产品发展的各个阶段
|
||||
- 精细可控的页面保活策略
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
function Layout() {
|
||||
return import('@/layouts/index.vue')
|
||||
}
|
||||
|
||||
const routes: RouteRecordRaw = {
|
||||
path: '/ant_design_vue_example',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: 'Ant Design Vue',
|
||||
icon: 'https://antdv.com/favicon.ico',
|
||||
menu: false,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'antDesignVueExample',
|
||||
component: () => import('@/views/ant_design_vue_example/index.vue'),
|
||||
meta: {
|
||||
title: 'Ant Design Vue',
|
||||
menu: false,
|
||||
breadcrumb: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export default routes
|
||||
+5
-6
@@ -5,20 +5,19 @@ function Layout() {
|
||||
}
|
||||
|
||||
const routes: RouteRecordRaw = {
|
||||
path: '/naive_ui_example',
|
||||
path: '/ui_example',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: 'Naive UI',
|
||||
icon: 'i-logos:naiveui',
|
||||
title: 'UI',
|
||||
menu: false,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'naiveUiExample',
|
||||
component: () => import('@/views/naive_ui_example/index.vue'),
|
||||
name: 'uiExample',
|
||||
component: () => import('@/views/ui_example/index.vue'),
|
||||
meta: {
|
||||
title: 'Naive UI',
|
||||
title: 'UI',
|
||||
menu: false,
|
||||
breadcrumb: false,
|
||||
},
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { RouteRecordMainRaw } from '@fantastic-admin/types'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import pinia from '@/store'
|
||||
import AntDesignVueExample from './modules/ant.design.vue.example'
|
||||
import MultilevelMenuExample from './modules/multilevel.menu.example'
|
||||
import UiExample from './modules/ui.example'
|
||||
|
||||
// 固定路由(默认路由)
|
||||
const constantRoutes: RouteRecordRaw[] = [
|
||||
@@ -72,7 +72,7 @@ const asyncRoutes: RouteRecordMainRaw[] = [
|
||||
icon: 'i-whh:jqueryui',
|
||||
},
|
||||
children: [
|
||||
AntDesignVueExample,
|
||||
UiExample,
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -35,6 +35,8 @@ declare module 'vue' {
|
||||
FaDropdown: typeof import('@fantastic-admin/components')['FaDropdown']
|
||||
FaFileUpload: typeof import('@fantastic-admin/components')['FaFileUpload']
|
||||
FaFixedBar: typeof import('@fantastic-admin/components')['FaFixedBar']
|
||||
FaForm: typeof import('@fantastic-admin/components')['FaForm']
|
||||
FaFormItem: typeof import('@fantastic-admin/components')['FaFormItem']
|
||||
FaHoverCard: typeof import('@fantastic-admin/components')['FaHoverCard']
|
||||
FaIcon: typeof import('@fantastic-admin/components')['FaIcon']
|
||||
FaImagePreview: typeof import('@fantastic-admin/components')['FaImagePreview']
|
||||
@@ -93,6 +95,8 @@ declare global {
|
||||
const FaDropdown: typeof import('@fantastic-admin/components')['FaDropdown']
|
||||
const FaFileUpload: typeof import('@fantastic-admin/components')['FaFileUpload']
|
||||
const FaFixedBar: typeof import('@fantastic-admin/components')['FaFixedBar']
|
||||
const FaForm: typeof import('@fantastic-admin/components')['FaForm']
|
||||
const FaFormItem: typeof import('@fantastic-admin/components')['FaFormItem']
|
||||
const FaHoverCard: typeof import('@fantastic-admin/components')['FaHoverCard']
|
||||
const FaIcon: typeof import('@fantastic-admin/components')['FaIcon']
|
||||
const FaImagePreview: typeof import('@fantastic-admin/components')['FaImagePreview']
|
||||
|
||||
+7
-1
@@ -56,7 +56,13 @@ function open(url: string) {
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<FaPageHeader title="Ant Design Vue" description="框架内置 Ant Design Vue 组件库,本页仅展示部分组件,更多组件及使用说明请查看 Ant Design Vue 官网。">
|
||||
<FaPageHeader description="框架提供已集成 Ant Design Vue 组件库的模板,支持开箱即用。本页仅展示部分组件,更多组件及使用说明请查看 Ant Design Vue 官网。">
|
||||
<template #title>
|
||||
<div class="flex gap-2 items-center">
|
||||
<FaIcon name="https://antdv.com/favicon.ico" />
|
||||
Ant Design Vue
|
||||
</div>
|
||||
</template>
|
||||
<FaButton variant="outline" @click="open('https://antdv.com/components/overview-cn')">
|
||||
<FaIcon name="i-ant-design:link-outlined" />
|
||||
Ant Design Vue 官网
|
||||
@@ -1,29 +0,0 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
function Layout() {
|
||||
return import('@/layouts/index.vue')
|
||||
}
|
||||
|
||||
const routes: RouteRecordRaw = {
|
||||
path: '/antdv_next_example',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: 'Antdv Next',
|
||||
icon: 'https://www.antdv-next.com/antdv-next.svg',
|
||||
menu: false,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'antdvNextExample',
|
||||
component: () => import('@/views/antdv_next_example/index.vue'),
|
||||
meta: {
|
||||
title: 'Antdv Next',
|
||||
menu: false,
|
||||
breadcrumb: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export default routes
|
||||
+5
-6
@@ -5,20 +5,19 @@ function Layout() {
|
||||
}
|
||||
|
||||
const routes: RouteRecordRaw = {
|
||||
path: '/vexip_ui_example',
|
||||
path: '/ui_example',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: 'Vexip UI',
|
||||
icon: 'https://www.vexipui.com/vexip-ui.svg',
|
||||
title: 'UI',
|
||||
menu: false,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'vexipUiExample',
|
||||
component: () => import('@/views/vexip_ui_example/index.vue'),
|
||||
name: 'uiExample',
|
||||
component: () => import('@/views/ui_example/index.vue'),
|
||||
meta: {
|
||||
title: 'Vexip UI',
|
||||
title: 'UI',
|
||||
menu: false,
|
||||
breadcrumb: false,
|
||||
},
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { RouteRecordMainRaw } from '@fantastic-admin/types'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import pinia from '@/store'
|
||||
import AntdvNextExample from './modules/antdv.next.example'
|
||||
import MultilevelMenuExample from './modules/multilevel.menu.example'
|
||||
import UiExample from './modules/ui.example'
|
||||
|
||||
// 固定路由(默认路由)
|
||||
const constantRoutes: RouteRecordRaw[] = [
|
||||
@@ -72,7 +72,7 @@ const asyncRoutes: RouteRecordMainRaw[] = [
|
||||
icon: 'i-whh:jqueryui',
|
||||
},
|
||||
children: [
|
||||
AntdvNextExample,
|
||||
UiExample,
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -35,6 +35,8 @@ declare module 'vue' {
|
||||
FaDropdown: typeof import('@fantastic-admin/components')['FaDropdown']
|
||||
FaFileUpload: typeof import('@fantastic-admin/components')['FaFileUpload']
|
||||
FaFixedBar: typeof import('@fantastic-admin/components')['FaFixedBar']
|
||||
FaForm: typeof import('@fantastic-admin/components')['FaForm']
|
||||
FaFormItem: typeof import('@fantastic-admin/components')['FaFormItem']
|
||||
FaHoverCard: typeof import('@fantastic-admin/components')['FaHoverCard']
|
||||
FaIcon: typeof import('@fantastic-admin/components')['FaIcon']
|
||||
FaImagePreview: typeof import('@fantastic-admin/components')['FaImagePreview']
|
||||
@@ -93,6 +95,8 @@ declare global {
|
||||
const FaDropdown: typeof import('@fantastic-admin/components')['FaDropdown']
|
||||
const FaFileUpload: typeof import('@fantastic-admin/components')['FaFileUpload']
|
||||
const FaFixedBar: typeof import('@fantastic-admin/components')['FaFixedBar']
|
||||
const FaForm: typeof import('@fantastic-admin/components')['FaForm']
|
||||
const FaFormItem: typeof import('@fantastic-admin/components')['FaFormItem']
|
||||
const FaHoverCard: typeof import('@fantastic-admin/components')['FaHoverCard']
|
||||
const FaIcon: typeof import('@fantastic-admin/components')['FaIcon']
|
||||
const FaImagePreview: typeof import('@fantastic-admin/components')['FaImagePreview']
|
||||
|
||||
+7
-1
@@ -56,7 +56,13 @@ function open(url: string) {
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<FaPageHeader title="Antdv Next" description="框架内置 Antdv Next 组件库,本页仅展示部分组件,更多组件及使用说明请查看 Antdv Next 官网。">
|
||||
<FaPageHeader description="框架提供已集成 Antdv Next 组件库的模板,支持开箱即用。本页仅展示部分组件,更多组件及使用说明请查看 Antdv Next 官网。">
|
||||
<template #title>
|
||||
<div class="flex gap-2 items-center">
|
||||
<FaIcon name="https://www.antdv-next.com/antdv-next.svg" />
|
||||
Antdv Next
|
||||
</div>
|
||||
</template>
|
||||
<FaButton variant="outline" @click="open('https://www.antdv-next.com/')">
|
||||
<FaIcon name="i-ant-design:link-outlined" />
|
||||
Antdv Next 官网
|
||||
@@ -1,29 +0,0 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
function Layout() {
|
||||
return import('@/layouts/index.vue')
|
||||
}
|
||||
|
||||
const routes: RouteRecordRaw = {
|
||||
path: '/arco_design_vue_example',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: 'Arco Design Vue',
|
||||
icon: 'https://unpkg.byted-static.com/latest/byted/arco-config/assets/favicon.ico',
|
||||
menu: false,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'arcoDesignVueExample',
|
||||
component: () => import('@/views/arco_design_vue_example/index.vue'),
|
||||
meta: {
|
||||
title: 'Arco Design Vue',
|
||||
menu: false,
|
||||
breadcrumb: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export default routes
|
||||
+5
-6
@@ -5,20 +5,19 @@ function Layout() {
|
||||
}
|
||||
|
||||
const routes: RouteRecordRaw = {
|
||||
path: '/element_plus_example',
|
||||
path: '/ui_example',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: 'Element Plus',
|
||||
icon: 'i-ep:element-plus',
|
||||
title: 'UI',
|
||||
menu: false,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'elementPlusExample',
|
||||
component: () => import('@/views/element_plus_example/index.vue'),
|
||||
name: 'uiExample',
|
||||
component: () => import('@/views/ui_example/index.vue'),
|
||||
meta: {
|
||||
title: 'Element Plus',
|
||||
title: 'UI',
|
||||
menu: false,
|
||||
breadcrumb: false,
|
||||
},
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { RouteRecordMainRaw } from '@fantastic-admin/types'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import pinia from '@/store'
|
||||
import ArcoDesignVueExample from './modules/arco.design.vue.example'
|
||||
import MultilevelMenuExample from './modules/multilevel.menu.example'
|
||||
import UiExample from './modules/ui.example'
|
||||
|
||||
// 固定路由(默认路由)
|
||||
const constantRoutes: RouteRecordRaw[] = [
|
||||
@@ -72,7 +72,7 @@ const asyncRoutes: RouteRecordMainRaw[] = [
|
||||
icon: 'i-whh:jqueryui',
|
||||
},
|
||||
children: [
|
||||
ArcoDesignVueExample,
|
||||
UiExample,
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -35,6 +35,8 @@ declare module 'vue' {
|
||||
FaDropdown: typeof import('@fantastic-admin/components')['FaDropdown']
|
||||
FaFileUpload: typeof import('@fantastic-admin/components')['FaFileUpload']
|
||||
FaFixedBar: typeof import('@fantastic-admin/components')['FaFixedBar']
|
||||
FaForm: typeof import('@fantastic-admin/components')['FaForm']
|
||||
FaFormItem: typeof import('@fantastic-admin/components')['FaFormItem']
|
||||
FaHoverCard: typeof import('@fantastic-admin/components')['FaHoverCard']
|
||||
FaIcon: typeof import('@fantastic-admin/components')['FaIcon']
|
||||
FaImagePreview: typeof import('@fantastic-admin/components')['FaImagePreview']
|
||||
@@ -93,6 +95,8 @@ declare global {
|
||||
const FaDropdown: typeof import('@fantastic-admin/components')['FaDropdown']
|
||||
const FaFileUpload: typeof import('@fantastic-admin/components')['FaFileUpload']
|
||||
const FaFixedBar: typeof import('@fantastic-admin/components')['FaFixedBar']
|
||||
const FaForm: typeof import('@fantastic-admin/components')['FaForm']
|
||||
const FaFormItem: typeof import('@fantastic-admin/components')['FaFormItem']
|
||||
const FaHoverCard: typeof import('@fantastic-admin/components')['FaHoverCard']
|
||||
const FaIcon: typeof import('@fantastic-admin/components')['FaIcon']
|
||||
const FaImagePreview: typeof import('@fantastic-admin/components')['FaImagePreview']
|
||||
|
||||
+7
-1
@@ -84,7 +84,13 @@ function open(url: string) {
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<FaPageHeader title="Arco Design Vue" description="框架内置 Arco Design Vue 组件库,本页仅展示部分组件,更多组件及使用说明请查看 Arco Design Vue 官网。">
|
||||
<FaPageHeader description="框架提供已集成 Arco Design Vue 组件库的模板,支持开箱即用。本页仅展示部分组件,更多组件及使用说明请查看 Arco Design Vue 官网。">
|
||||
<template #title>
|
||||
<div class="flex gap-2 items-center">
|
||||
<FaIcon name="https://unpkg.byted-static.com/latest/byted/arco-config/assets/favicon.ico" />
|
||||
Arco Design Vue
|
||||
</div>
|
||||
</template>
|
||||
<FaButton variant="outline" @click="open('https://arco.design/vue/docs/start')">
|
||||
<FaIcon name="i-ant-design:link-outlined" />
|
||||
Arco Design Vue 官网
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
# 应用配置面板
|
||||
# Application configuration panel
|
||||
VITE_APP_SETTING = true
|
||||
|
||||
# 网站标题
|
||||
# Website title
|
||||
VITE_APP_TITLE = Fantastic-admin
|
||||
|
||||
# 网络请求地址,应用于 axios 的 baseURL
|
||||
# Network request address, applied to axios's baseURL
|
||||
VITE_APP_API_BASEURL = /
|
||||
|
||||
# localStorage/sessionStorage 前缀
|
||||
# localStorage/sessionStorage prefix
|
||||
VITE_APP_STORAGE_PREFIX = fa_dev_
|
||||
|
||||
# 调试工具,可设置 eruda 或 vconsole
|
||||
# Debugging tool, can set eruda or vconsole
|
||||
VITE_APP_DEBUG_TOOL =
|
||||
|
||||
# ===== 以下配置仅在开发环境生效 =====
|
||||
# ===== The following configuration is only effective in the development environment. =====
|
||||
|
||||
# 启用代理
|
||||
# Enable proxy
|
||||
VITE_ENABLE_PROXY = false
|
||||
|
||||
# 启用 Vue 开发工具
|
||||
# Enable Vue DevTools
|
||||
VITE_ENABLE_VUE_DEVTOOLS = false
|
||||
|
||||
# 启用 turbo console
|
||||
# Enable turbo console
|
||||
VITE_ENABLE_TURBO_CONSOLE = false
|
||||
|
||||
# 启动编辑器,用于 vite-plugin-vue-devtools 和 unplugin-turbo-console
|
||||
# 支持的编辑器 https://github.com/yyx990803/launch-editor#supported-editors
|
||||
# Launch the editor for vite-plugin-vue-devtools and unplugin-turbo-console
|
||||
# Supported editors https://github.com/yyx990803/launch-editor#supported-editors
|
||||
VITE_LAUNCH_EDITOR = code
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
# 应用配置面板
|
||||
# Application configuration panel
|
||||
VITE_APP_SETTING = false
|
||||
|
||||
# 网站标题
|
||||
# Website title
|
||||
VITE_APP_TITLE = Fantastic-admin
|
||||
|
||||
# 网络请求地址,应用于 axios 的 baseURL
|
||||
# Network request address, applied to axios's baseURL
|
||||
VITE_APP_API_BASEURL = /
|
||||
|
||||
# localStorage/sessionStorage 前缀
|
||||
# localStorage/sessionStorage prefix
|
||||
VITE_APP_STORAGE_PREFIX = fa_
|
||||
|
||||
# 调试工具,可设置 eruda 或 vconsole
|
||||
# Debugging tool, can set eruda or vconsole
|
||||
VITE_APP_DEBUG_TOOL =
|
||||
|
||||
# ===== 以下配置仅在生产环境生效 =====
|
||||
# ===== The following configuration is only effective in the production environment. =====
|
||||
|
||||
# 启用假数据
|
||||
# Enable build fake data
|
||||
VITE_BUILD_FAKE = false
|
||||
|
||||
# 启用 sourcemap
|
||||
# Enable build sourcemap
|
||||
VITE_BUILD_SOURCEMAP = false
|
||||
|
||||
# 压缩方式,支持 gzip 和 brotli
|
||||
# Build compression method, supports gzip and brotli
|
||||
VITE_BUILD_COMPRESS = gzip,brotli
|
||||
|
||||
# 构建后生成存档,支持 zip 和 tar
|
||||
# Generate archive after build, supports zip and tar
|
||||
VITE_BUILD_ARCHIVE =
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
# 应用配置面板
|
||||
# Application configuration panel
|
||||
VITE_APP_SETTING = false
|
||||
|
||||
# 网站标题
|
||||
# Website title
|
||||
VITE_APP_TITLE = Fantastic-admin
|
||||
|
||||
# 网络请求地址,应用于 axios 的 baseURL
|
||||
# Network request address, applied to axios's baseURL
|
||||
VITE_APP_API_BASEURL = /
|
||||
|
||||
# localStorage/sessionStorage 前缀
|
||||
# localStorage/sessionStorage prefix
|
||||
VITE_APP_STORAGE_PREFIX = fa_test_
|
||||
|
||||
# 调试工具,可设置 eruda 或 vconsole
|
||||
# Debugging tool, can set eruda or vconsole
|
||||
VITE_APP_DEBUG_TOOL =
|
||||
|
||||
# ===== 以下配置仅在测试环境生效 =====
|
||||
# ===== The following configuration is only effective in the test environment. =====
|
||||
|
||||
# 启用假数据
|
||||
# Enable build fake data
|
||||
VITE_BUILD_FAKE = true
|
||||
|
||||
# 启用 sourcemap
|
||||
# Enable build sourcemap
|
||||
VITE_BUILD_SOURCEMAP = true
|
||||
|
||||
# 压缩方式,支持 gzip 和 brotli
|
||||
# Build compression method, supports gzip and brotli
|
||||
VITE_BUILD_COMPRESS =
|
||||
|
||||
# 构建后生成存档,支持 zip 和 tar
|
||||
# Generate archive after build, supports zip and tar
|
||||
VITE_BUILD_ARCHIVE =
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"$schema": "https://shadcn-vue.com/schema.json",
|
||||
"style": "new-york-v4",
|
||||
"typescript": true,
|
||||
"tailwind": {
|
||||
"config": "tailwind.config.js",
|
||||
"css": "src/assets/index.css",
|
||||
"baseColor": "neutral",
|
||||
"cssVariables": true
|
||||
},
|
||||
"aliases": {
|
||||
"components": "@/ui/shadcn",
|
||||
"utils": "@/utils",
|
||||
"lib": "@/utils"
|
||||
}
|
||||
}
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" href="/favicon.svg" />
|
||||
<link rel="stylesheet" href="/browser_upgrade/index.css" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, viewport-fit=cover"/>
|
||||
<meta http-equiv="Expires" content="0">
|
||||
<meta http-equiv="Pragma" content="no-cache">
|
||||
<meta http-equiv="Cache-control" content="no-cache">
|
||||
<meta http-equiv="Cache" content="no-cache">
|
||||
<title>%VITE_APP_TITLE%</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<div id="browser-upgrade">
|
||||
<div class="title">为了您的体验,推荐使用以下浏览器</div>
|
||||
<div class="browsers">
|
||||
<a href="https://www.microsoft.com/edge" target="_blank" class="browser">
|
||||
<img class="browser-icon" src="/browser_upgrade/edge.png" />
|
||||
<div class="browser-name">Microsoft Edge</div>
|
||||
</a>
|
||||
<a href="https://www.google.cn/chrome/" target="_blank" class="browser">
|
||||
<img class="browser-icon" src="/browser_upgrade/chrome.png" />
|
||||
<div class="browser-name">Google Chrome</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
if (!!window.ActiveXObject || 'ActiveXObject' in window) {
|
||||
document.getElementById('browser-upgrade').style.display = 'block'
|
||||
}
|
||||
</script>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
Executable
+216
@@ -0,0 +1,216 @@
|
||||
<style>
|
||||
@keyframes rainbow {
|
||||
0% { --rainbow-color: #00a98e; }
|
||||
1.25% { --rainbow-color: #00a996; }
|
||||
2.5% { --rainbow-color: #00a99f; }
|
||||
3.75% { --rainbow-color: #00a9a7; }
|
||||
5% { --rainbow-color: #00a9b0; }
|
||||
6.25% { --rainbow-color: #00a9b8; }
|
||||
7.5% { --rainbow-color: #00a9c0; }
|
||||
8.75% { --rainbow-color: #00a8c7; }
|
||||
10% { --rainbow-color: #00a8cf; }
|
||||
11.25% { --rainbow-color: #00a7d5; }
|
||||
12.5% { --rainbow-color: #00a6dc; }
|
||||
13.75% { --rainbow-color: #00a6e2; }
|
||||
15% { --rainbow-color: #00a4e7; }
|
||||
16.25% { --rainbow-color: #00a3ec; }
|
||||
17.5% { --rainbow-color: #00a2f1; }
|
||||
18.75% { --rainbow-color: #00a0f4; }
|
||||
20% { --rainbow-color: #009ff7; }
|
||||
21.25% { --rainbow-color: #009dfa; }
|
||||
22.5% { --rainbow-color: #009bfc; }
|
||||
23.75% { --rainbow-color: #0098fd; }
|
||||
25% { --rainbow-color: #0096fd; }
|
||||
26.25% { --rainbow-color: #0093fd; }
|
||||
27.5% { --rainbow-color: #2e90fc; }
|
||||
28.75% { --rainbow-color: #4d8dfa; }
|
||||
30% { --rainbow-color: #638af8; }
|
||||
31.25% { --rainbow-color: #7587f5; }
|
||||
32.5% { --rainbow-color: #8583f1; }
|
||||
33.75% { --rainbow-color: #9280ed; }
|
||||
35% { --rainbow-color: #9f7ce9; }
|
||||
36.25% { --rainbow-color: #aa78e3; }
|
||||
37.5% { --rainbow-color: #b574dd; }
|
||||
38.75% { --rainbow-color: #be71d7; }
|
||||
40% { --rainbow-color: #c76dd1; }
|
||||
41.25% { --rainbow-color: #cf69c9; }
|
||||
42.5% { --rainbow-color: #d566c2; }
|
||||
43.75% { --rainbow-color: #dc63ba; }
|
||||
45% { --rainbow-color: #e160b3; }
|
||||
46.25% { --rainbow-color: #e65eab; }
|
||||
47.5% { --rainbow-color: #e95ca2; }
|
||||
48.75% { --rainbow-color: #ed5a9a; }
|
||||
50% { --rainbow-color: #ef5992; }
|
||||
51.25% { --rainbow-color: #f15989; }
|
||||
52.5% { --rainbow-color: #f25981; }
|
||||
53.75% { --rainbow-color: #f25a79; }
|
||||
55% { --rainbow-color: #f25c71; }
|
||||
56.25% { --rainbow-color: #f15e69; }
|
||||
57.5% { --rainbow-color: #ef6061; }
|
||||
58.75% { --rainbow-color: #ed635a; }
|
||||
60% { --rainbow-color: #eb6552; }
|
||||
61.25% { --rainbow-color: #e8694b; }
|
||||
62.5% { --rainbow-color: #e46c44; }
|
||||
63.75% { --rainbow-color: #e06f3d; }
|
||||
65% { --rainbow-color: #db7336; }
|
||||
66.25% { --rainbow-color: #d77630; }
|
||||
67.5% { --rainbow-color: #d17a2a; }
|
||||
68.75% { --rainbow-color: #cc7d24; }
|
||||
70% { --rainbow-color: #c6811e; }
|
||||
71.25% { --rainbow-color: #bf8418; }
|
||||
72.5% { --rainbow-color: #b98713; }
|
||||
73.75% { --rainbow-color: #b28a0f; }
|
||||
75% { --rainbow-color: #ab8d0c; }
|
||||
76.25% { --rainbow-color: #a3900b; }
|
||||
77.5% { --rainbow-color: #9c920d; }
|
||||
78.75% { --rainbow-color: #949510; }
|
||||
80% { --rainbow-color: #8b9715; }
|
||||
81.25% { --rainbow-color: #83991b; }
|
||||
82.5% { --rainbow-color: #7a9b21; }
|
||||
83.75% { --rainbow-color: #719d27; }
|
||||
85% { --rainbow-color: #679e2e; }
|
||||
86.25% { --rainbow-color: #5da035; }
|
||||
87.5% { --rainbow-color: #51a13c; }
|
||||
88.75% { --rainbow-color: #44a244; }
|
||||
90% { --rainbow-color: #34a44b; }
|
||||
91.25% { --rainbow-color: #1ba553; }
|
||||
92.5% { --rainbow-color: #00a65b; }
|
||||
93.75% { --rainbow-color: #00a663; }
|
||||
95% { --rainbow-color: #00a76c; }
|
||||
96.25% { --rainbow-color: #00a874; }
|
||||
97.5% { --rainbow-color: #00a87d; }
|
||||
98.75% { --rainbow-color: #00a985; }
|
||||
100% { --rainbow-color: #00a98e; }
|
||||
}
|
||||
|
||||
:root {
|
||||
--rainbow-color: #00a98e;
|
||||
animation: rainbow 20s linear infinite;
|
||||
}
|
||||
|
||||
.loading-container {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 10000;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: var(--rainbow-color);
|
||||
user-select: none;
|
||||
background-color: oklch(var(--background));
|
||||
}
|
||||
|
||||
.loading-container *::before,
|
||||
.loading-container *::after {
|
||||
box-sizing: content-box;
|
||||
}
|
||||
|
||||
.loading-container .loading {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.loading-container .loading .square {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.loading-container .loading .square::before {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
content: "";
|
||||
border: 3px solid var(--rainbow-color);
|
||||
border-radius: 15%;
|
||||
animation: square-to-dot-animation 2s linear infinite;
|
||||
}
|
||||
|
||||
.loading-container .loading .square:nth-child(1)::before {
|
||||
animation-delay: calc(150ms * 1);
|
||||
}
|
||||
|
||||
.loading-container .loading .square:nth-child(2)::before {
|
||||
animation-delay: calc(150ms * 2);
|
||||
}
|
||||
|
||||
.loading-container .loading .square:nth-child(3)::before {
|
||||
animation-delay: calc(150ms * 3);
|
||||
}
|
||||
|
||||
.loading-container .loading .square:nth-child(4)::before {
|
||||
animation-delay: calc(150ms * 4);
|
||||
}
|
||||
|
||||
@keyframes square-to-dot-animation {
|
||||
0%,
|
||||
33.33% {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
margin: initial;
|
||||
border-width: 3px;
|
||||
border-radius: 15%;
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
50%,
|
||||
83.33% {
|
||||
width: 0;
|
||||
height: 0;
|
||||
margin: 5px;
|
||||
border-width: 5px;
|
||||
border-radius: 100%;
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
100% {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
margin: initial;
|
||||
border-width: 3px;
|
||||
border-radius: 15%;
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.loading-container .name {
|
||||
position: relative;
|
||||
margin-top: 20px;
|
||||
font-size: 24px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.loading-container .tips {
|
||||
position: relative;
|
||||
margin-top: 10px;
|
||||
font-size: 16px;
|
||||
opacity: 0.5;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.loading-container .tips::after {
|
||||
position: absolute;
|
||||
padding-left: 5px;
|
||||
content: "…";
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="loading-container">
|
||||
<div class="loading">
|
||||
<div class="square"></div>
|
||||
<div class="square"></div>
|
||||
<div class="square"></div>
|
||||
<div class="square"></div>
|
||||
</div>
|
||||
<div class="name">%VITE_APP_TITLE%</div>
|
||||
<div class="tips">载入中</div>
|
||||
</div>
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
{
|
||||
"name": "@fantastic-admin/core-element-plus",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc -b && vite build",
|
||||
"build:test": "vue-tsc -b && vite build --mode test",
|
||||
"serve": "http-server ./dist -o",
|
||||
"serve:test": "http-server ./dist-test -o",
|
||||
"svgo": "svgo -f src/assets/icons",
|
||||
"generate:icons": "fa-iconify-tools",
|
||||
"lint": "vue-tsc -b"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fantastic-admin/components": "workspace:*",
|
||||
"@fantastic-admin/composables": "workspace:*",
|
||||
"@fantastic-admin/hotkeys": "workspace:*",
|
||||
"@fantastic-admin/settings": "workspace:*",
|
||||
"@fantastic-admin/types": "workspace:*",
|
||||
"@vee-validate/zod": "catalog:",
|
||||
"@vueuse/core": "catalog:",
|
||||
"@vueuse/integrations": "catalog:",
|
||||
"@zumer/snapdom": "catalog:",
|
||||
"axios": "catalog:",
|
||||
"class-variance-authority": "catalog:",
|
||||
"clsx": "catalog:",
|
||||
"dayjs": "catalog:",
|
||||
"element-plus": "catalog:element-plus",
|
||||
"eruda": "catalog:",
|
||||
"es-toolkit": "catalog:",
|
||||
"mitt": "catalog:",
|
||||
"nprogress": "catalog:",
|
||||
"path-browserify": "catalog:",
|
||||
"path-to-regexp": "catalog:",
|
||||
"pinia": "catalog:",
|
||||
"pinia-plugin-persistedstate": "catalog:",
|
||||
"pinyin-pro": "catalog:",
|
||||
"qs": "catalog:",
|
||||
"reka-ui": "catalog:",
|
||||
"scule": "catalog:",
|
||||
"tailwind-merge": "catalog:",
|
||||
"type-fest": "catalog:",
|
||||
"ua-parser-js": "catalog:",
|
||||
"vconsole": "catalog:",
|
||||
"vee-validate": "catalog:",
|
||||
"vue": "catalog:",
|
||||
"vue-router": "catalog:",
|
||||
"zod": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@faker-js/faker": "catalog:",
|
||||
"@fantastic-admin/copyright": "workspace:*",
|
||||
"@fantastic-admin/iconify-tools": "workspace:*",
|
||||
"@iconify/vue": "catalog:",
|
||||
"@spiriit/vite-plugin-svg-spritemap": "catalog:",
|
||||
"@types/nprogress": "catalog:",
|
||||
"@types/path-browserify": "catalog:",
|
||||
"@types/qs": "catalog:",
|
||||
"@vitejs/plugin-legacy": "catalog:",
|
||||
"@vitejs/plugin-vue": "catalog:",
|
||||
"@vitejs/plugin-vue-jsx": "catalog:",
|
||||
"@vue/tsconfig": "catalog:",
|
||||
"http-server": "catalog:",
|
||||
"postcss": "catalog:",
|
||||
"postcss-nested": "catalog:",
|
||||
"sass-embedded": "catalog:",
|
||||
"svgo": "catalog:",
|
||||
"unplugin-auto-import": "catalog:",
|
||||
"unplugin-turbo-console": "catalog:",
|
||||
"unplugin-vue-components": "catalog:",
|
||||
"vite": "catalog:",
|
||||
"vite-plugin-app-loading": "catalog:",
|
||||
"vite-plugin-archiver": "catalog:",
|
||||
"vite-plugin-compression2": "catalog:",
|
||||
"vite-plugin-env-parse": "catalog:",
|
||||
"vite-plugin-fake-server": "catalog:",
|
||||
"vite-plugin-vue-devtools": "catalog:",
|
||||
"vue-tsc": "catalog:"
|
||||
}
|
||||
}
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
plugins: {
|
||||
'autoprefixer': {},
|
||||
'postcss-nested': {},
|
||||
},
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.7 KiB |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 4.0 KiB |
+49
@@ -0,0 +1,49 @@
|
||||
#browser-upgrade {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 10001;
|
||||
display: none;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: #736477;
|
||||
user-select: none;
|
||||
background-color: snow;
|
||||
}
|
||||
|
||||
#browser-upgrade .title {
|
||||
margin: 40px 0;
|
||||
font-size: 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#browser-upgrade .browsers {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#browser-upgrade .browsers .browser {
|
||||
display: inline-block;
|
||||
margin: 0 20px;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#browser-upgrade .browsers .browser .browser-icon {
|
||||
display: block;
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
margin: 0 auto;
|
||||
border: none;
|
||||
}
|
||||
|
||||
#browser-upgrade .browsers .browser .browser-name {
|
||||
padding-bottom: 2px;
|
||||
margin-top: 10px;
|
||||
color: #736477;
|
||||
text-align: center;
|
||||
border-bottom: 1px solid transparent;
|
||||
}
|
||||
|
||||
#browser-upgrade .browsers .browser:hover .browser-name {
|
||||
border-bottom: 1px solid #736477;
|
||||
}
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -21 206 206" xml:space="preserve">
|
||||
<path d="M0,82.57C0,58.4,0,34.23,0,10.06C0,1.35,1.35,0,10.03,0C45.36,0,80.7-0.01,116.03,0.03c1.77,0,3.59,0.26,5.29,0.74
|
||||
c3.07,0.87,3.57,3.21,2.45,5.8c-4.37,10.1-8.83,20.15-13.31,30.2c-1.44,3.23-4.06,4.26-7.54,4.25c-18.5-0.09-37,0.1-55.5-0.14
|
||||
c-4.95-0.06-6.49,2.12-6.46,6.47c0.02,3,0.11,6.01-0.02,9c-0.3,6.8,0.34,9.29,9.51,9.62c5.36,0.19,10.73,0.04,16.09,0.04
|
||||
c7.57,0,15.15-0.04,22.72,0.01c5.13,0.03,6.6,2.12,4.59,6.89C90.43,81.09,86.27,89,83.4,97.35c-2.59,7.55-8.57,7.27-14.28,7.56
|
||||
c-7.48,0.38-15,0.17-22.5,0.06c-3.69-0.05-4.96,1.04-4.86,5.18c0.36,15.83,0.26,31.67,0.12,47.5c-0.04,4.2-2.26,6.53-6.94,6.42
|
||||
c-9-0.21-18-0.06-27-0.06c-6.05,0-7.91-1.8-7.92-7.94C-0.02,131.57,0,107.07,0,82.57z" fill="#42b883" />
|
||||
<path d="M132.98,94.13c-8.21,18.88-16.33,37.1-24.06,55.48c-6.02,14.31-5.81,14.4-21.31,14.4c-6.67,0-13.33,0.05-20-0.01
|
||||
c-5.91-0.05-7.71-2.44-5.46-7.61c6.86-15.8,13.86-31.55,20.82-47.31c9.41-21.32,18.81-42.63,28.24-63.94
|
||||
c5.59-12.62,11.14-25.25,16.94-37.77c0.82-1.78,2.95-4.09,4.47-4.09c1.63,0,4,2.11,4.78,3.86c13.4,29.78,26.56,59.66,39.87,89.49
|
||||
c6.48,14.53,13.16,28.97,19.72,43.46c2.57,5.68,5.11,11.38,7.61,17.1c1.61,3.68-0.13,6.75-4.12,6.77
|
||||
c-23.83,0.08-47.66,0.09-71.49-0.01c-4.03-0.02-5.46-2.47-3.98-6.17c2.26-5.63,4.77-11.16,6.95-16.82c1.74-4.54,4.92-6.06,9.6-5.98
|
||||
c9.65,0.16,9.89-0.55,5.89-9.13c-4.57-9.81-8.76-19.8-13.14-29.7C134.08,95.62,133.68,95.17,132.98,94.13z" fill="#42b883" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
Executable
+60
@@ -0,0 +1,60 @@
|
||||
<script setup lang="ts">
|
||||
import dayjs from '@/utils/dayjs'
|
||||
import { ua } from '@/utils/ua'
|
||||
import Provider from './ui/provider/index.vue'
|
||||
import 'dayjs/locale/zh-cn'
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
|
||||
const { auth } = useAppAuth()
|
||||
const { generateTitle } = useAppMenu()
|
||||
|
||||
document.body.setAttribute('data-os', ua.getOS().name || '')
|
||||
|
||||
const isAuth = computed(() => {
|
||||
return route.matched.every((item) => {
|
||||
return auth(item.meta.auth ?? '')
|
||||
})
|
||||
})
|
||||
|
||||
// 设置网页 title
|
||||
watch([
|
||||
() => appSettingsStore.settings.app.dynamicTitle,
|
||||
() => appSettingsStore.title,
|
||||
], () => {
|
||||
nextTick(() => {
|
||||
if (appSettingsStore.settings.app.dynamicTitle && appSettingsStore.title) {
|
||||
document.title = `${generateTitle(appSettingsStore.title)} - ${import.meta.env.VITE_APP_TITLE}`
|
||||
}
|
||||
else {
|
||||
document.title = import.meta.env.VITE_APP_TITLE
|
||||
}
|
||||
})
|
||||
}, {
|
||||
immediate: true,
|
||||
deep: true,
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
appSettingsStore.setMode(document.documentElement.clientWidth)
|
||||
dayjs.locale('zh-cn')
|
||||
window.addEventListener('resize', () => {
|
||||
appSettingsStore.setMode(document.documentElement.clientWidth)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Provider>
|
||||
<RouterView v-slot="{ Component }">
|
||||
<AppNotSupportedMobile v-if="!appSettingsStore.settings.app.mobile && appSettingsStore.mode === 'mobile'" />
|
||||
<Component :is="Component" v-else-if="isAuth" />
|
||||
<AppNotAllowed v-else />
|
||||
</RouterView>
|
||||
<AppBackToTop />
|
||||
<FaToast :theme="appSettingsStore.currentColorScheme" />
|
||||
<AppSystemInfo />
|
||||
</Provider>
|
||||
</template>
|
||||
+146
@@ -0,0 +1,146 @@
|
||||
import { faker } from '@faker-js/faker'
|
||||
import { defineFakeRoute } from 'vite-plugin-fake-server/client'
|
||||
|
||||
export default defineFakeRoute([
|
||||
{
|
||||
url: '/fake/app/route/list',
|
||||
method: 'get',
|
||||
response: () => {
|
||||
return {
|
||||
error: '',
|
||||
status: 1,
|
||||
data: [
|
||||
// 主导航
|
||||
{
|
||||
meta: {
|
||||
title: '演示',
|
||||
icon: 'uim:box',
|
||||
},
|
||||
children: [
|
||||
// 次导航(一级路由)
|
||||
{
|
||||
path: '/multilevel_menu_example',
|
||||
component: 'Layout',
|
||||
name: 'multilevelMenuExample',
|
||||
meta: {
|
||||
title: '多级导航',
|
||||
icon: 'heroicons-solid:menu-alt-3',
|
||||
},
|
||||
children: [
|
||||
// 次导航(二级路由)
|
||||
{
|
||||
path: 'page',
|
||||
name: 'multilevelMenuExample1',
|
||||
component: 'multilevel_menu_example/page.vue',
|
||||
meta: {
|
||||
title: '导航1',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'level2',
|
||||
name: 'multilevelMenuExample2',
|
||||
meta: {
|
||||
title: '导航2',
|
||||
},
|
||||
children: [
|
||||
// 次导航(三级路由)
|
||||
{
|
||||
path: 'page',
|
||||
name: 'multilevelMenuExample2-1',
|
||||
component: 'multilevel_menu_example/level2/page.vue',
|
||||
meta: {
|
||||
title: '导航2-1',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'level3',
|
||||
name: 'multilevelMenuExample2-2',
|
||||
meta: {
|
||||
title: '导航2-2',
|
||||
},
|
||||
children: [
|
||||
// 次导航(四级路由)
|
||||
{
|
||||
path: 'page1',
|
||||
name: 'multilevelMenuExample2-2-1',
|
||||
component: 'multilevel_menu_example/level2/level3/page1.vue',
|
||||
meta: {
|
||||
title: '导航2-2-1',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'page2',
|
||||
name: 'multilevelMenuExample2-2-2',
|
||||
component: 'multilevel_menu_example/level2/level3/page2.vue',
|
||||
meta: {
|
||||
title: '导航2-2-2',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/fake/app/account/login',
|
||||
method: 'post',
|
||||
response: ({ body }) => {
|
||||
return {
|
||||
error: '',
|
||||
status: 1,
|
||||
data: {
|
||||
account: body.account,
|
||||
token: `${body.account}:${faker.internet.jwt()}`,
|
||||
avatar: `https://api.dicebear.com/9.x/bottts-neutral/svg?seed=${body.account}`,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/fake/app/account/permission',
|
||||
method: 'get',
|
||||
response: ({ headers }) => {
|
||||
let permissions: string[] = []
|
||||
if (headers.token?.indexOf('admin') === 0) {
|
||||
permissions = [
|
||||
'pages.general:browse',
|
||||
'pages.form:browse',
|
||||
'pages.list:browse',
|
||||
'pages.shop:browse',
|
||||
]
|
||||
}
|
||||
else if (headers.token?.indexOf('test') === 0) {
|
||||
permissions = [
|
||||
'pages.general:browse',
|
||||
]
|
||||
}
|
||||
return {
|
||||
error: '',
|
||||
status: 1,
|
||||
data: {
|
||||
permissions,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
url: '/fake/app/account/password/edit',
|
||||
method: 'post',
|
||||
response: () => {
|
||||
return {
|
||||
error: '',
|
||||
status: 1,
|
||||
data: {
|
||||
isSuccess: true,
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
])
|
||||
Executable
+110
@@ -0,0 +1,110 @@
|
||||
import axios from 'axios'
|
||||
// import qs from 'qs'
|
||||
|
||||
// 请求重试配置
|
||||
const MAX_RETRY_COUNT = 3 // 最大重试次数
|
||||
const RETRY_DELAY = 1000 // 重试延迟时间(毫秒)
|
||||
|
||||
// 扩展 AxiosRequestConfig 类型
|
||||
declare module 'axios' {
|
||||
export interface AxiosRequestConfig {
|
||||
retry?: boolean
|
||||
retryCount?: number
|
||||
fake?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: (import.meta.env.DEV && import.meta.env.VITE_ENABLE_PROXY) ? '/proxy/' : import.meta.env.VITE_APP_API_BASEURL,
|
||||
timeout: 1000 * 60,
|
||||
responseType: 'json',
|
||||
})
|
||||
|
||||
api.interceptors.request.use(
|
||||
(request) => {
|
||||
// 如果设置了 fake 属性,强制使用 fake 的 baseURL
|
||||
if (request.fake) {
|
||||
request.baseURL = '/fake/'
|
||||
}
|
||||
// 全局拦截请求发送前提交的参数
|
||||
const appAccountStore = useAppAccountStore()
|
||||
// 设置请求头
|
||||
if (request.headers) {
|
||||
request.headers['Accept-Language'] = 'zh-CN'
|
||||
if (appAccountStore.isLogin) {
|
||||
request.headers.Token = appAccountStore.token
|
||||
}
|
||||
}
|
||||
// 是否将 POST 请求参数进行字符串化处理
|
||||
if (request.method === 'post') {
|
||||
// request.data = qs.stringify(request.data, {
|
||||
// arrayFormat: 'brackets',
|
||||
// })
|
||||
}
|
||||
return request
|
||||
},
|
||||
)
|
||||
|
||||
// 处理错误信息的函数
|
||||
function handleError(error: any) {
|
||||
if (error.status === 401) {
|
||||
useAppAccountStore().requestLogout()
|
||||
}
|
||||
else {
|
||||
useFaToast().error('Error', {
|
||||
description: error.message,
|
||||
})
|
||||
}
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
api.interceptors.response.use(
|
||||
(response) => {
|
||||
/**
|
||||
* 全局拦截请求发送后返回的数据,如果数据有报错则在这做全局的错误提示
|
||||
* 约定的数据格式:{ status: 1 | 0, error: string, data: object }
|
||||
* status 只有两种状态,1 表示请求成功,0 表示接口需要登录或者登录状态失效,需要重新登录
|
||||
* error 只有在请求出错时才会有值,表示错误信息
|
||||
* data 只有在请求成功时才会有值,表示请求返回的数据
|
||||
*/
|
||||
if (typeof response.data === 'object') {
|
||||
if (response.data.status === 1) {
|
||||
if (response.data.error) {
|
||||
useFaToast().warning('Warning', {
|
||||
description: response.data.error,
|
||||
})
|
||||
return Promise.reject(response.data)
|
||||
}
|
||||
}
|
||||
else {
|
||||
useAppAccountStore().requestLogout()
|
||||
}
|
||||
return Promise.resolve(response.data)
|
||||
}
|
||||
else {
|
||||
return Promise.reject(response.data)
|
||||
}
|
||||
},
|
||||
async (error) => {
|
||||
// 获取请求配置
|
||||
const config = error.config
|
||||
// 如果配置不存在或未启用重试,则直接处理错误
|
||||
if (!config || !config.retry) {
|
||||
return handleError(error)
|
||||
}
|
||||
// 设置重试次数
|
||||
config.retryCount = config.retryCount || 0
|
||||
// 判断是否超过重试次数
|
||||
if (config.retryCount >= MAX_RETRY_COUNT) {
|
||||
return handleError(error)
|
||||
}
|
||||
// 重试次数自增
|
||||
config.retryCount += 1
|
||||
// 延迟重试
|
||||
await new Promise(resolve => setTimeout(resolve, RETRY_DELAY))
|
||||
// 重新发起请求
|
||||
return api(config)
|
||||
},
|
||||
)
|
||||
|
||||
export default api
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import api from '../index'
|
||||
|
||||
export default {
|
||||
// 后端获取路由数据
|
||||
routeList: () => api.get('app/route/list', {
|
||||
fake: true,
|
||||
}),
|
||||
|
||||
// 登录
|
||||
login: (data: {
|
||||
account: string
|
||||
password: string
|
||||
}) => api.post('app/account/login', data, {
|
||||
fake: true,
|
||||
}),
|
||||
|
||||
// 获取权限
|
||||
permission: () => api.get('app/account/permission', {
|
||||
fake: true,
|
||||
}),
|
||||
|
||||
// 修改密码
|
||||
passwordEdit: (data: {
|
||||
password: string
|
||||
newPassword: string
|
||||
}) => api.post('app/account/password/edit', data, {
|
||||
fake: true,
|
||||
}),
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="200.781" height="200" class="icon" viewBox="0 0 1028 1024"><path d="M989.867 234.667H499.2c-17.067 0-34.133-21.334-34.133-42.667 0-25.6 12.8-42.667 34.133-42.667h490.667c17.066 0 34.133 17.067 34.133 42.667 0 21.333-12.8 42.667-34.133 42.667m-473.6 128h465.066c25.6 0 46.934 21.333 46.934 42.666 0 25.6-21.334 42.667-46.934 42.667H516.267c-25.6 0-46.934-17.067-46.934-42.667s21.334-42.666 46.934-42.666m0 298.666c-25.6 0-46.934-21.333-46.934-42.666 0-25.6 21.334-42.667 46.934-42.667h465.066c25.6 0 46.934 17.067 46.934 42.667s-21.334 42.666-46.934 42.666zm4.266 128H972.8c29.867 0 51.2 17.067 51.2 42.667s-21.333 42.667-51.2 42.667H520.533c-29.866 0-51.2-17.067-51.2-42.667s21.334-42.667 51.2-42.667m-192 25.6c-17.066 17.067-46.933 17.067-64 0L12.8 541.867c-17.067-17.067-17.067-51.2 0-68.267l251.733-273.067c17.067-17.066 46.934-17.066 64 0s17.067 51.2 0 68.267L106.667 507.733l221.866 238.934c17.067 21.333 17.067 51.2 0 68.266"/></svg>
|
||||
|
After Width: | Height: | Size: 986 B |
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
+14
@@ -0,0 +1,14 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-25 -46 256 256" xml:space="preserve">
|
||||
<path d="M0,82.57C0,58.4,0,34.23,0,10.06C0,1.35,1.35,0,10.03,0C45.36,0,80.7-0.01,116.03,0.03c1.77,0,3.59,0.26,5.29,0.74
|
||||
c3.07,0.87,3.57,3.21,2.45,5.8c-4.37,10.1-8.83,20.15-13.31,30.2c-1.44,3.23-4.06,4.26-7.54,4.25c-18.5-0.09-37,0.1-55.5-0.14
|
||||
c-4.95-0.06-6.49,2.12-6.46,6.47c0.02,3,0.11,6.01-0.02,9c-0.3,6.8,0.34,9.29,9.51,9.62c5.36,0.19,10.73,0.04,16.09,0.04
|
||||
c7.57,0,15.15-0.04,22.72,0.01c5.13,0.03,6.6,2.12,4.59,6.89C90.43,81.09,86.27,89,83.4,97.35c-2.59,7.55-8.57,7.27-14.28,7.56
|
||||
c-7.48,0.38-15,0.17-22.5,0.06c-3.69-0.05-4.96,1.04-4.86,5.18c0.36,15.83,0.26,31.67,0.12,47.5c-0.04,4.2-2.26,6.53-6.94,6.42
|
||||
c-9-0.21-18-0.06-27-0.06c-6.05,0-7.91-1.8-7.92-7.94C-0.02,131.57,0,107.07,0,82.57z" fill="#35495e" />
|
||||
<path d="M132.98,94.13c-8.21,18.88-16.33,37.1-24.06,55.48c-6.02,14.31-5.81,14.4-21.31,14.4c-6.67,0-13.33,0.05-20-0.01
|
||||
c-5.91-0.05-7.71-2.44-5.46-7.61c6.86-15.8,13.86-31.55,20.82-47.31c9.41-21.32,18.81-42.63,28.24-63.94
|
||||
c5.59-12.62,11.14-25.25,16.94-37.77c0.82-1.78,2.95-4.09,4.47-4.09c1.63,0,4,2.11,4.78,3.86c13.4,29.78,26.56,59.66,39.87,89.49
|
||||
c6.48,14.53,13.16,28.97,19.72,43.46c2.57,5.68,5.11,11.38,7.61,17.1c1.61,3.68-0.13,6.75-4.12,6.77
|
||||
c-23.83,0.08-47.66,0.09-71.49-0.01c-4.03-0.02-5.46-2.47-3.98-6.17c2.26-5.63,4.77-11.16,6.95-16.82c1.74-4.54,4.92-6.06,9.6-5.98
|
||||
c9.65,0.16,9.89-0.55,5.89-9.13c-4.57-9.81-8.76-19.8-13.14-29.7C134.08,95.62,133.68,95.17,132.98,94.13z" fill="#42b883" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
+80
@@ -0,0 +1,80 @@
|
||||
/* 页面布局 CSS 变量 */
|
||||
:root {
|
||||
color-scheme: light;
|
||||
|
||||
/* 头部宽度(默认自适应宽度,可固定宽度,固定宽度后为居中显示) */
|
||||
--g-header-width: 100%;
|
||||
|
||||
/* 头部高度 */
|
||||
--g-header-height: 60px;
|
||||
|
||||
/* 侧边栏宽度 */
|
||||
--g-main-sidebar-width: 80px;
|
||||
--g-sub-sidebar-width: 220px;
|
||||
--g-sub-sidebar-collapse-width: 64px;
|
||||
|
||||
/* 侧边栏 Logo 区域高度 */
|
||||
--g-sidebar-logo-height: 50px;
|
||||
|
||||
/* 标签栏高度 */
|
||||
--g-tabbar-height: 50px;
|
||||
|
||||
/* 工具栏高度 */
|
||||
--g-toolbar-height: 50px;
|
||||
|
||||
&.dark {
|
||||
color-scheme: dark;
|
||||
}
|
||||
}
|
||||
|
||||
/* 明暗模式过渡动画 */
|
||||
::view-transition-old(root),
|
||||
::view-transition-new(root) {
|
||||
mix-blend-mode: normal;
|
||||
animation: none;
|
||||
}
|
||||
|
||||
::view-transition-old(root) {
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
::view-transition-new(root) {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.dark {
|
||||
&::view-transition-old(root) {
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
&::view-transition-new(root) {
|
||||
z-index: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.disable-color-scheme-transition-duration *,
|
||||
.disable-color-scheme-transition-duration *::before,
|
||||
.disable-color-scheme-transition-duration *::after {
|
||||
transition-duration: 0ms !important;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
text-autospace: normal;
|
||||
}
|
||||
|
||||
body {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
}
|
||||
|
||||
#app {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
/* textarea 字体跟随系统 */
|
||||
textarea {
|
||||
font-family: inherit;
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#nprogress {
|
||||
pointer-events: none;
|
||||
|
||||
.bar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 3000;
|
||||
width: 100%;
|
||||
height: 2px;
|
||||
background: oklch(var(--primary));
|
||||
}
|
||||
|
||||
.peg {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
display: block;
|
||||
width: 100px;
|
||||
height: 100%;
|
||||
box-shadow: 0 0 10px oklch(var(--primary)), 0 0 5px oklch(var(--primary));
|
||||
opacity: 1;
|
||||
transform: rotate(3deg) translate(0, -4px);
|
||||
}
|
||||
|
||||
.spinner {
|
||||
position: fixed;
|
||||
top: 11px;
|
||||
right: 14px;
|
||||
z-index: 2000;
|
||||
display: block;
|
||||
|
||||
.spinner-icon {
|
||||
box-sizing: border-box;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: solid 2px transparent;
|
||||
border-top-color: oklch(var(--primary));
|
||||
border-left-color: oklch(var(--primary));
|
||||
border-radius: 50%;
|
||||
animation: nprogress-spinner 400ms linear infinite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.nprogress-custom-parent {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
||||
#nprogress .spinner,
|
||||
#nprogress .bar {
|
||||
position: absolute;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes nprogress-spinner {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
@keyframes nprogress-spinner {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// 文字超出隐藏,默认为单行超出隐藏,可设置多行
|
||||
@mixin text-overflow($line: 1, $fixed-width: true) {
|
||||
@if $line == 1 and $fixed-width == true {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
} @else {
|
||||
/* stylelint-disable-next-line value-no-vendor-prefix */
|
||||
display: -webkit-box;
|
||||
overflow: hidden;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: $line;
|
||||
}
|
||||
}
|
||||
|
||||
// 定位居中,默认水平居中,可选择垂直居中,或者水平垂直都居中
|
||||
@mixin position-center($type: x) {
|
||||
position: absolute;
|
||||
|
||||
@if $type == x {
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
|
||||
@if $type == y {
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
|
||||
@if $type == xy {
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%) translateY(-50%);
|
||||
}
|
||||
}
|
||||
|
||||
// 文字两端对齐
|
||||
%justify-align {
|
||||
text-align: justify;
|
||||
text-align-last: justify;
|
||||
}
|
||||
|
||||
// 清除浮动
|
||||
%clearfix {
|
||||
zoom: 1;
|
||||
|
||||
&::before,
|
||||
&::after {
|
||||
clear: both;
|
||||
display: block;
|
||||
content: "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// 全局变量
|
||||
@@ -0,0 +1,94 @@
|
||||
<script setup lang="ts">
|
||||
import type { HTMLAttributes } from 'vue'
|
||||
import { cn } from '@/utils'
|
||||
import eventBus from '@/utils/eventBus'
|
||||
import Profile from './profile.vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'AppAccountButton',
|
||||
})
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
onlyAvatar?: boolean
|
||||
dropdownAlign?: 'start' | 'center' | 'end'
|
||||
dropdownSide?: 'left' | 'right' | 'top' | 'bottom'
|
||||
buttonVariant?: 'secondary' | 'ghost'
|
||||
class?: HTMLAttributes['class']
|
||||
}>(), {
|
||||
dropdownAlign: 'end',
|
||||
dropdownSide: 'right',
|
||||
buttonVariant: 'ghost',
|
||||
})
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appAccountStore = useAppAccountStore()
|
||||
|
||||
const { generateTitle } = useAppMenu()
|
||||
|
||||
const profileModal = useFaModal().create({
|
||||
alignCenter: true,
|
||||
header: false,
|
||||
footer: false,
|
||||
closeOnClickOverlay: false,
|
||||
closeOnPressEscape: false,
|
||||
class: 'h-[500px] sm:max-w-xl overflow-hidden',
|
||||
contentClass: 'min-h-full p-0 flex',
|
||||
content: () => h(Profile),
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FaDropdown
|
||||
:align="dropdownAlign" :side="dropdownSide" :items="[
|
||||
[
|
||||
...(appSettingsStore.settings.app.home.enable
|
||||
? [{ label: generateTitle(appSettingsStore.settings.app.home.title), icon: 'i-mdi:home', handle: () => router.push({ path: appSettingsStore.settings.app.home.fullPath }) }]
|
||||
: []),
|
||||
{ label: '个人设置', icon: 'i-mdi:account', handle: () => profileModal.open() },
|
||||
],
|
||||
[
|
||||
...(appSettingsStore.mode === 'pc'
|
||||
? [{ label: '快捷键', icon: 'i-mdi:keyboard', handle: () => eventBus.emit('global-hotkeys-intro-toggle') }]
|
||||
: []),
|
||||
],
|
||||
[
|
||||
{
|
||||
label: '退出登录',
|
||||
icon: 'i-mdi:logout',
|
||||
handle: () => appAccountStore.logout(appSettingsStore.settings.app.home.fullPath),
|
||||
},
|
||||
],
|
||||
]" class="flex-center"
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex-center-start gap-2">
|
||||
<FaAvatar :src="appAccountStore.avatar" :fallback="appAccountStore.account.slice(0, 2)" shape="square" />
|
||||
<div class="min-w-0 space-y-1">
|
||||
<div class="text-base lh-none truncate">
|
||||
{{ appAccountStore.account }}
|
||||
</div>
|
||||
<div class="text-xs text-secondary-foreground/50 font-normal">
|
||||
[ xyz@xyz.com ]
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<FaButton
|
||||
:variant="buttonVariant" size="icon-sm" :class="cn('flex-center gap-1 p-2', {
|
||||
'p-1': onlyAvatar,
|
||||
}, props.class)"
|
||||
>
|
||||
<FaAvatar :src="appAccountStore.avatar" :class="cn('size-6', { 'size-full': onlyAvatar })">
|
||||
<FaIcon name="i-carbon:user-avatar-filled" class="text-secondary-foreground/50 size-6" />
|
||||
</FaAvatar>
|
||||
<div v-if="!onlyAvatar" class="flex-center-between flex-1 gap-2 min-w-0">
|
||||
<div class="text-start flex-1 truncate">
|
||||
{{ appAccountStore.account }}
|
||||
</div>
|
||||
<FaIcon name="i-material-symbols:expand-all-rounded" />
|
||||
</div>
|
||||
</FaButton>
|
||||
</FaDropdown>
|
||||
</template>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script setup lang="ts">
|
||||
import EditPassword from '@/components/AppAccountForm/edit-password.vue'
|
||||
|
||||
const active = ref(0)
|
||||
const tabs = ref([
|
||||
{
|
||||
title: '基本设置',
|
||||
description: '账号的基本信息,头像、昵称等',
|
||||
},
|
||||
{
|
||||
title: '安全设置',
|
||||
description: '定期修改密码可以提高帐号安全性',
|
||||
},
|
||||
])
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="min-h-full w-full">
|
||||
<div class="border-b border-e bg-background flex flex-row right-0 top-0 fixed z-1 overflow-auto md:(flex-col h-full w-40 inset-s-0 bottom-0)">
|
||||
<div v-for="(tab, index) in tabs" :key="index" class="px-4 py-3 flex-shrink-0 cursor-pointer transition-background-color space-y-2 hover-bg-accent/50" :class="{ 'bg-accent hover-bg-accent!': active === index }" @click="active = index">
|
||||
<div class="text-base text-accent-foreground leading-tight">
|
||||
{{ tab.title }}
|
||||
</div>
|
||||
<div class="text-xs text-accent-foreground/50">
|
||||
{{ tab.description }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-10 pt-20 flex-col-center min-h-full md:(ms-40 pt-10)">
|
||||
<div v-if="active === 0">
|
||||
请开发者自行扩展
|
||||
</div>
|
||||
<EditPassword v-if="active === 1" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,84 @@
|
||||
<script setup lang="ts">
|
||||
import { toTypedSchema } from '@vee-validate/zod'
|
||||
import * as z from 'zod'
|
||||
|
||||
defineOptions({
|
||||
name: 'EditPasswordForm',
|
||||
})
|
||||
|
||||
const appAccountStore = useAppAccountStore()
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
interface EditPasswordModel {
|
||||
password: string
|
||||
newPassword: string
|
||||
checkPassword: string
|
||||
}
|
||||
|
||||
const model = ref<EditPasswordModel>({
|
||||
password: '',
|
||||
newPassword: '',
|
||||
checkPassword: '',
|
||||
})
|
||||
|
||||
const validationSchema = toTypedSchema(
|
||||
z.object({
|
||||
password: z.string().min(1, '请输入原密码'),
|
||||
newPassword: z.string().min(1, '请输入新密码').min(6, '密码长度为6到18位').max(18, '密码长度为6到18位'),
|
||||
checkPassword: z.string().min(1, '请确认新密码'),
|
||||
}).refine(data => data.newPassword === data.checkPassword, {
|
||||
message: '两次输入的密码不一致',
|
||||
path: ['checkPassword'],
|
||||
}),
|
||||
)
|
||||
|
||||
function onSubmit(values: EditPasswordModel) {
|
||||
loading.value = true
|
||||
appAccountStore.editPassword(values).then(async () => {
|
||||
useFaToast().success('模拟修改成功,请重新登录')
|
||||
appAccountStore.logout()
|
||||
}).finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex-col-stretch-center w-full">
|
||||
<div class="mb-6 space-y-2">
|
||||
<h3 class="text-4xl font-bold">
|
||||
修改密码
|
||||
</h3>
|
||||
<p class="text-sm text-muted-foreground lg:text-base">
|
||||
请输入原密码、新密码和确认密码
|
||||
</p>
|
||||
</div>
|
||||
<FaForm :model="model" :validation-schema="validationSchema" @submit="onSubmit">
|
||||
<FaFormItem name="password">
|
||||
<FaInput type="password" placeholder="原密码" class="w-full">
|
||||
<template #start>
|
||||
<FaIcon name="i-lucide:lock" />
|
||||
</template>
|
||||
</FaInput>
|
||||
</FaFormItem>
|
||||
<FaFormItem name="newPassword">
|
||||
<FaInput type="password" placeholder="新密码" class="w-full">
|
||||
<template #start>
|
||||
<FaIcon name="i-lucide:lock" />
|
||||
</template>
|
||||
</FaInput>
|
||||
</FaFormItem>
|
||||
<FaFormItem name="checkPassword">
|
||||
<FaInput type="password" placeholder="确认密码" class="w-full">
|
||||
<template #start>
|
||||
<FaIcon name="i-lucide:lock" />
|
||||
</template>
|
||||
</FaInput>
|
||||
</FaFormItem>
|
||||
<FaButton :loading="loading" size="lg" class="mt-8 w-full" type="submit">
|
||||
保存
|
||||
</FaButton>
|
||||
</FaForm>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,150 @@
|
||||
<script setup lang="ts">
|
||||
import type { FormExpose } from '@fantastic-admin/components'
|
||||
import { toTypedSchema } from '@vee-validate/zod'
|
||||
import * as z from 'zod'
|
||||
|
||||
defineOptions({
|
||||
name: 'LoginForm',
|
||||
})
|
||||
|
||||
const props = defineProps<{
|
||||
account?: string
|
||||
}>()
|
||||
|
||||
const emits = defineEmits<{
|
||||
onLogin: [account?: string]
|
||||
onRegister: [account?: string]
|
||||
onResetPassword: [account?: string]
|
||||
}>()
|
||||
|
||||
const appAccountStore = useAppAccountStore()
|
||||
|
||||
const title = import.meta.env.VITE_APP_TITLE
|
||||
const loading = ref(false)
|
||||
|
||||
// 登录方式,default 账号密码登录,qrcode 扫码登录
|
||||
const type = ref<'default' | 'qrcode'>('default')
|
||||
|
||||
interface LoginModel {
|
||||
account: string
|
||||
password: string
|
||||
remember: boolean
|
||||
}
|
||||
|
||||
const formRef = useTemplateRef<FormExpose<LoginModel>>('formRef')
|
||||
|
||||
const model = ref<LoginModel>({
|
||||
account: props.account ?? localStorage.getItem('login_account') ?? '',
|
||||
password: '',
|
||||
remember: localStorage.getItem('login_account') !== null,
|
||||
})
|
||||
|
||||
const validationSchema = toTypedSchema(z.object({
|
||||
account: z.string().min(1, '请输入用户名'),
|
||||
password: z.string().min(1, '请输入密码'),
|
||||
remember: z.boolean(),
|
||||
}))
|
||||
|
||||
function onSubmit(values: LoginModel) {
|
||||
loading.value = true
|
||||
appAccountStore.login(values).then(() => {
|
||||
if (values.remember) {
|
||||
localStorage.setItem('login_account', values.account)
|
||||
}
|
||||
else {
|
||||
localStorage.removeItem('login_account')
|
||||
}
|
||||
emits('onLogin', values.account)
|
||||
}).finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
async function testAccount(account: string) {
|
||||
model.value.account = account
|
||||
model.value.password = '123456'
|
||||
await formRef.value?.submit()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-12 flex-col-stretch-center min-h-500px w-full">
|
||||
<div class="mb-6 space-y-2">
|
||||
<h3 class="text-4xl font-bold">
|
||||
欢迎使用 👋🏻
|
||||
</h3>
|
||||
<p class="text-sm text-muted-foreground lg:text-base">
|
||||
{{ title }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<FaTabs
|
||||
v-model="type" :list="[
|
||||
{ label: '账号密码登录', value: 'default' },
|
||||
{ label: '扫码登录', value: 'qrcode' },
|
||||
]" class="inline-flex"
|
||||
/>
|
||||
</div>
|
||||
<div v-show="type === 'default'">
|
||||
<FaForm
|
||||
ref="formRef"
|
||||
:model="model"
|
||||
:validation-schema="validationSchema"
|
||||
@submit="onSubmit"
|
||||
>
|
||||
<FaFormItem name="account">
|
||||
<FaInput type="text" placeholder="用户名" class="w-full">
|
||||
<template #start>
|
||||
<FaIcon name="i-lucide:user" />
|
||||
</template>
|
||||
</FaInput>
|
||||
</FaFormItem>
|
||||
<FaFormItem name="password">
|
||||
<FaInput type="password" placeholder="密码" class="w-full">
|
||||
<template #start>
|
||||
<FaIcon name="i-lucide:lock" />
|
||||
</template>
|
||||
</FaInput>
|
||||
</FaFormItem>
|
||||
<div class="flex-start-between">
|
||||
<FaFormItem name="remember" class="min-w-0">
|
||||
<FaCheckbox>
|
||||
记住我
|
||||
</FaCheckbox>
|
||||
</FaFormItem>
|
||||
<FaButton variant="link" class="p-0 h-auto" type="button" @click="emits('onResetPassword', model.account)">
|
||||
忘记密码了?
|
||||
</FaButton>
|
||||
</div>
|
||||
<FaButton :loading="loading" size="lg" class="w-full" type="submit">
|
||||
登录
|
||||
</FaButton>
|
||||
<div class="text-sm mt-4 flex-center gap-2">
|
||||
<span class="text-secondary-foreground op-50">还没有帐号?</span>
|
||||
<FaButton variant="link" class="p-0 h-auto" type="button" @click="emits('onRegister', model.account)">
|
||||
注册新帐号
|
||||
</FaButton>
|
||||
</div>
|
||||
</FaForm>
|
||||
<div class="mt-4 text-center -mb-4">
|
||||
<FaDivider>演示账号一键登录</FaDivider>
|
||||
<div class="space-x-2">
|
||||
<FaButton variant="default" size="sm" plain @click="testAccount('admin')">
|
||||
admin
|
||||
</FaButton>
|
||||
<FaButton variant="outline" size="sm" plain @click="testAccount('test')">
|
||||
test
|
||||
</FaButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-show="type === 'qrcode'">
|
||||
<div class="flex-col-center">
|
||||
<img src="https://s2.loli.net/2024/04/26/GsahtuIZ9XOg5jr.png" class="h-[250px] w-[250px]">
|
||||
<div class="text-sm text-secondary-foreground mt-2 op-50">
|
||||
请使用微信扫码登录
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,93 @@
|
||||
<script setup lang="ts">
|
||||
import { toTypedSchema } from '@vee-validate/zod'
|
||||
import * as z from 'zod'
|
||||
|
||||
defineOptions({
|
||||
name: 'RegisterForm',
|
||||
})
|
||||
|
||||
const props = defineProps<{
|
||||
account?: string
|
||||
}>()
|
||||
|
||||
const emits = defineEmits<{
|
||||
onLogin: [account?: string]
|
||||
onRegister: [account?: string]
|
||||
}>()
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
interface RegisterModel {
|
||||
account: string
|
||||
password: string
|
||||
checkPassword: string
|
||||
}
|
||||
|
||||
const model = ref<RegisterModel>({
|
||||
account: props.account ?? '',
|
||||
password: '',
|
||||
checkPassword: '',
|
||||
})
|
||||
|
||||
const validationSchema = toTypedSchema(
|
||||
z.object({
|
||||
account: z.string().min(1, '请输入用户名'),
|
||||
password: z.string().min(1, '请输入密码').min(6, '密码长度为6到18位').max(18, '密码长度为6到18位'),
|
||||
checkPassword: z.string().min(1, '请再次输入密码'),
|
||||
}).refine(data => data.password === data.checkPassword, {
|
||||
message: '两次输入的密码不一致',
|
||||
path: ['checkPassword'],
|
||||
}),
|
||||
)
|
||||
|
||||
function onSubmit(values: RegisterModel) {
|
||||
loading.value = true
|
||||
emits('onRegister', values.account)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-12 flex-col-stretch-center min-h-500px w-full">
|
||||
<FaForm :model="model" :validation-schema="validationSchema" @submit="onSubmit">
|
||||
<div class="mb-8 space-y-2">
|
||||
<h3 class="text-4xl font-bold">
|
||||
探索从这里开始 🚀
|
||||
</h3>
|
||||
<p class="text-sm text-muted-foreground lg:text-base">
|
||||
演示系统未提供该功能
|
||||
</p>
|
||||
</div>
|
||||
<FaFormItem name="account">
|
||||
<FaInput type="text" placeholder="用户名" class="w-full">
|
||||
<template #start>
|
||||
<FaIcon name="i-lucide:user" />
|
||||
</template>
|
||||
</FaInput>
|
||||
</FaFormItem>
|
||||
<FaFormItem name="password">
|
||||
<FaInput type="password" placeholder="密码" class="w-full">
|
||||
<template #start>
|
||||
<FaIcon name="i-lucide:lock" />
|
||||
</template>
|
||||
</FaInput>
|
||||
<FaPasswordStrength :password="model.password" />
|
||||
</FaFormItem>
|
||||
<FaFormItem name="checkPassword">
|
||||
<FaInput type="password" placeholder="确认密码" class="w-full">
|
||||
<template #start>
|
||||
<FaIcon name="i-lucide:lock" />
|
||||
</template>
|
||||
</FaInput>
|
||||
</FaFormItem>
|
||||
<FaButton :loading="loading" size="lg" class="mt-4 w-full" type="submit">
|
||||
注册
|
||||
</FaButton>
|
||||
<div class="text-sm mt-4 flex-center gap-2">
|
||||
<span class="text-secondary-foreground op-50">已经有帐号?</span>
|
||||
<FaButton variant="link" class="p-0 h-auto" type="button" @click="emits('onLogin', model.account)">
|
||||
去登录
|
||||
</FaButton>
|
||||
</div>
|
||||
</FaForm>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,104 @@
|
||||
<script setup lang="ts">
|
||||
import { toTypedSchema } from '@vee-validate/zod'
|
||||
import * as z from 'zod'
|
||||
|
||||
defineOptions({
|
||||
name: 'ResetPasswordForm',
|
||||
})
|
||||
|
||||
const props = defineProps<{
|
||||
account?: string
|
||||
}>()
|
||||
|
||||
const emits = defineEmits<{
|
||||
onLogin: [account?: string]
|
||||
onResetPassword: [account?: string]
|
||||
}>()
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
interface ResetPasswordModel {
|
||||
account: string
|
||||
captcha: string
|
||||
newPassword: string
|
||||
}
|
||||
|
||||
const model = ref<ResetPasswordModel>({
|
||||
account: props.account ?? '',
|
||||
captcha: '',
|
||||
newPassword: '',
|
||||
})
|
||||
|
||||
const validationSchema = toTypedSchema(z.object({
|
||||
account: z.string().min(1, '请输入用户名'),
|
||||
captcha: z.string().min(6, '请输入验证码'),
|
||||
newPassword: z.string().min(1, '请输入新密码').min(6, '密码长度为6到18位').max(18, '密码长度为6到18位'),
|
||||
}))
|
||||
|
||||
function onSubmit(values: ResetPasswordModel) {
|
||||
loading.value = true
|
||||
emits('onResetPassword', values.account)
|
||||
}
|
||||
|
||||
const countdown = ref(0)
|
||||
const countdownInterval = ref(Number.NaN)
|
||||
function handleSendCaptcha() {
|
||||
countdown.value = 60
|
||||
countdownInterval.value = window.setInterval(() => {
|
||||
countdown.value--
|
||||
if (countdown.value === 0) {
|
||||
clearInterval(countdownInterval.value)
|
||||
}
|
||||
}, 1000)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-12 flex-col-stretch-center min-h-500px w-full">
|
||||
<FaForm :model="model" :validation-schema="validationSchema" @submit="onSubmit">
|
||||
<div class="mb-8 space-y-2">
|
||||
<h3 class="text-4xl font-bold">
|
||||
忘记密码了? 🔒
|
||||
</h3>
|
||||
<p class="text-sm text-muted-foreground lg:text-base">
|
||||
演示系统未提供该功能
|
||||
</p>
|
||||
</div>
|
||||
<FaFormItem name="account">
|
||||
<FaInput type="text" placeholder="用户名" class="w-full">
|
||||
<template #start>
|
||||
<FaIcon name="i-lucide:user" />
|
||||
</template>
|
||||
</FaInput>
|
||||
</FaFormItem>
|
||||
<FaFormItem name="captcha" :auto-bind="false">
|
||||
<div class="flex-start-between gap-2">
|
||||
<FaInputOTP
|
||||
v-model="model.captcha"
|
||||
name="captcha"
|
||||
:length="6"
|
||||
class="border-destructive"
|
||||
/>
|
||||
<FaButton variant="outline" type="button" :disabled="countdown > 0" class="px-4 flex-1" @click="handleSendCaptcha">
|
||||
{{ countdown === 0 ? '发送验证码' : `${countdown} 秒后重发` }}
|
||||
</FaButton>
|
||||
</div>
|
||||
</FaFormItem>
|
||||
<FaFormItem name="newPassword">
|
||||
<FaInput type="password" placeholder="新密码" class="w-full">
|
||||
<template #start>
|
||||
<FaIcon name="i-lucide:lock" />
|
||||
</template>
|
||||
</FaInput>
|
||||
</FaFormItem>
|
||||
<FaButton :loading="loading" size="lg" class="mt-4 w-full" type="submit">
|
||||
确认
|
||||
</FaButton>
|
||||
<div class="text-sm mt-4 flex-center gap-2">
|
||||
<FaButton variant="link" class="p-0 h-auto" type="button" @click="emits('onLogin', model.account)">
|
||||
去登录
|
||||
</FaButton>
|
||||
</div>
|
||||
</FaForm>
|
||||
</div>
|
||||
</template>
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
defineOptions({
|
||||
name: 'AppAuth',
|
||||
})
|
||||
|
||||
const props = defineProps<{
|
||||
value: string | string[]
|
||||
all?: boolean
|
||||
}>()
|
||||
|
||||
const isCheck = computed(() => {
|
||||
return props.all
|
||||
? useAppAuth().authAll(typeof props.value === 'string' ? [props.value] : props.value)
|
||||
: useAppAuth().auth(props.value)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<slot v-if="isCheck" />
|
||||
<slot v-else name="no-auth" />
|
||||
</template>
|
||||
@@ -0,0 +1,69 @@
|
||||
<script setup lang="ts">
|
||||
import { useTimeoutFn } from '@vueuse/core'
|
||||
|
||||
defineOptions({
|
||||
name: 'AppBackToTop',
|
||||
})
|
||||
|
||||
const transitionClass = {
|
||||
enterActiveClass: 'ease-out duration-300',
|
||||
enterFromClass: 'opacity-0 translate-y-4 lg-translate-y-0 lg-scale-95',
|
||||
enterToClass: 'opacity-100 translate-y-0 lg-scale-100',
|
||||
leaveActiveClass: 'ease-in duration-200',
|
||||
leaveFromClass: 'opacity-100 translate-y-0 lg-scale-100',
|
||||
leaveToClass: 'opacity-0 translate-y-4 lg-translate-y-0 lg-scale-95',
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('scroll', handleScroll)
|
||||
handleScroll()
|
||||
})
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('scroll', handleScroll)
|
||||
})
|
||||
|
||||
let timeout: (() => void) | undefined
|
||||
|
||||
const show = ref(false)
|
||||
const scrollTop = ref(0)
|
||||
function handleScroll() {
|
||||
scrollTop.value = document.documentElement.scrollTop
|
||||
}
|
||||
watch(scrollTop, (val) => {
|
||||
if (val >= 200) {
|
||||
handleMouseenter()
|
||||
handleMouseleave()
|
||||
}
|
||||
})
|
||||
|
||||
function handleMouseenter() {
|
||||
timeout?.()
|
||||
// 此处setTimeout是为了避免移动端下和click事件同时触发
|
||||
setTimeout(() => {
|
||||
show.value = true
|
||||
}, 0)
|
||||
}
|
||||
|
||||
function handleMouseleave() {
|
||||
;({ stop: timeout } = useTimeoutFn(() => {
|
||||
show.value = false
|
||||
}, 2000))
|
||||
}
|
||||
|
||||
function handleBackToTop() {
|
||||
show.value && document.documentElement.scrollTo({
|
||||
top: 0,
|
||||
behavior: 'smooth',
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<Transition v-bind="transitionClass">
|
||||
<FaButton v-if="scrollTop >= 200" variant="outline" size="icon" class="rounded-full h-12 w-12 transition-all inset-b-4 fixed z-2000 dark:bg-background -inset-e-9 dark:hover:bg-background/50" :class="{ 'inset-e-3!': show }" @mouseenter="handleMouseenter" @mouseleave="handleMouseleave" @click="handleBackToTop">
|
||||
<FaIcon name="i-icon-park-outline:to-top-one" class="size-6" />
|
||||
</FaButton>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
defineOptions({
|
||||
name: 'AppCopyright',
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<footer v-if="route.meta.copyright ?? appSettingsStore.settings.app.copyright.enable" class="text-sm text-secondary-foreground/50 my-4 px-4 flex flex-wrap items-center justify-center">
|
||||
<span class="px-1">Copyright</span>
|
||||
<FaIcon name="i-ri:copyright-line" class="size-5" />
|
||||
<span v-if="appSettingsStore.settings.app.copyright.dates" class="px-1">{{ appSettingsStore.settings.app.copyright.dates }}</span>
|
||||
<template v-if="appSettingsStore.settings.app.copyright.company">
|
||||
<a v-if="appSettingsStore.settings.app.copyright.website" :href="appSettingsStore.settings.app.copyright.website" target="_blank" rel="noopener" class="px-1 text-center no-underline transition-colors hover-text-secondary-foreground">{{ appSettingsStore.settings.app.copyright.company }}</a>
|
||||
<span v-else class="px-1">{{ appSettingsStore.settings.app.copyright.company }}</span>
|
||||
</template>
|
||||
</footer>
|
||||
</template>
|
||||
@@ -0,0 +1,53 @@
|
||||
<script setup lang="ts">
|
||||
defineOptions({
|
||||
name: 'AppNotAllowed',
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appTabbarStore = useAppTabbarStore()
|
||||
|
||||
onMounted(() => {
|
||||
if (appSettingsStore.settings.topbar.tabbar) {
|
||||
appTabbarStore.remove(route.meta.activeMenu || route.fullPath)
|
||||
}
|
||||
})
|
||||
|
||||
function goBack() {
|
||||
router.push(appSettingsStore.settings.app.home.fullPath)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col h-full">
|
||||
<div class="flex h-[5vh] lg:h-[10vh]">
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
<div class="border-inline border-dashed flex-1" />
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
</div>
|
||||
<div class="border-block border-dashed flex flex-1">
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
<div class="border-inline border-dashed flex-center flex-1 relative">
|
||||
<div class="p-4 flex-col-center gap-4 lg:p-12">
|
||||
<h1 class="text-6xl font-bold m-0 lg:text-9xl">
|
||||
403
|
||||
</h1>
|
||||
<div class="text-xl text-secondary-foreground/50 mx-0 text-center">
|
||||
抱歉,你无权访问该页面
|
||||
</div>
|
||||
<FaButton variant="link" class="text-unset" @click="goBack">
|
||||
返回主页
|
||||
</FaButton>
|
||||
</div>
|
||||
</div>
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
</div>
|
||||
<div class="flex h-[5vh] lg:h-[10vh]">
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
<div class="border-inline border-dashed flex-1" />
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,34 @@
|
||||
<script setup lang="ts">
|
||||
defineOptions({
|
||||
name: 'AppNotSupportedMobile',
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col h-full">
|
||||
<div class="flex h-[5vh] lg:h-[10vh]">
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
<div class="border-inline border-dashed flex-1" />
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
</div>
|
||||
<div class="border-block border-dashed flex flex-1">
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
<div class="border-inline border-dashed flex-center flex-1 relative">
|
||||
<div class="p-4 flex-col-center gap-4 lg:p-12">
|
||||
<h1 class="text-6xl font-bold m-0 lg:text-9xl">
|
||||
<FaIcon name="i-tdesign:mobile-blocked-filled" />
|
||||
</h1>
|
||||
<div class="text-xl text-secondary-foreground/50 mx-0 text-center">
|
||||
抱歉,本网站不支持移动设备访问,请切换到桌面设备
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
</div>
|
||||
<div class="flex h-[5vh] lg:h-[10vh]">
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
<div class="border-inline border-dashed flex-1" />
|
||||
<div class="w-[5vh] lg:w-[10vh]" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,72 @@
|
||||
<script setup lang="ts">
|
||||
import eventBus from '@/utils/eventBus'
|
||||
|
||||
defineOptions({
|
||||
name: 'AppSystemInfo',
|
||||
})
|
||||
|
||||
const isShow = ref(false)
|
||||
|
||||
const { pkg, lastBuildTime } = __SYSTEM_INFO__
|
||||
|
||||
onMounted(() => {
|
||||
eventBus.on('global-system-info-open', () => {
|
||||
isShow.value = true
|
||||
})
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
eventBus.off('global-system-info-open')
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FaDrawer v-model="isShow" title="系统信息" :footer="false">
|
||||
<div v-if="pkg.version">
|
||||
<FaDivider>
|
||||
版本号
|
||||
</FaDivider>
|
||||
<div class="text-lg font-bold font-sans text-center">
|
||||
{{ pkg.version }}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<FaDivider>
|
||||
最后编译时间
|
||||
</FaDivider>
|
||||
<div class="text-lg font-bold font-sans text-center">
|
||||
{{ lastBuildTime }}
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<FaDivider>
|
||||
生产环境依赖
|
||||
</FaDivider>
|
||||
<ul class="text-sm list-none">
|
||||
<li v-for="(val, key) in (pkg.dependencies as object)" :key="key" class="px-2 py-1.5 rounded-lg flex items-center justify-between hover-bg-secondary">
|
||||
<div class="font-bold">
|
||||
{{ key }}
|
||||
</div>
|
||||
<div class="font-sans">
|
||||
{{ val }}
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
<FaDivider>
|
||||
开发环境依赖
|
||||
</FaDivider>
|
||||
<ul class="text-sm list-none">
|
||||
<li v-for="(val, key) in (pkg.devDependencies as object)" :key="key" class="px-2 py-1.5 rounded-lg flex items-center justify-between hover-bg-secondary">
|
||||
<div class="font-bold">
|
||||
{{ key }}
|
||||
</div>
|
||||
<div class="font-sans">
|
||||
{{ val }}
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</FaDrawer>
|
||||
</template>
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
export function useAppAuth() {
|
||||
function hasPermission(permission: string) {
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appAccountStore = useAppAccountStore()
|
||||
if (appSettingsStore.settings.app.account.auth) {
|
||||
return appAccountStore.permissions.includes(permission)
|
||||
}
|
||||
else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
function auth(value: string | string[]) {
|
||||
let auth
|
||||
if (typeof value === 'string') {
|
||||
auth = value !== '' ? hasPermission(value) : true
|
||||
}
|
||||
else {
|
||||
auth = value.length > 0 ? value.some(item => hasPermission(item)) : true
|
||||
}
|
||||
return auth
|
||||
}
|
||||
|
||||
function authAll(value: string[]) {
|
||||
return value.length > 0 ? value.every(item => hasPermission(item)) : true
|
||||
}
|
||||
|
||||
return {
|
||||
auth,
|
||||
authAll,
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
export function useAppMenu() {
|
||||
const router = useRouter()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appMenuStore = useAppMenuStore()
|
||||
|
||||
function generateTitle(title: string | (() => any) = '[ 无标题 ]') {
|
||||
return typeof title === 'function'
|
||||
? title()
|
||||
: title
|
||||
}
|
||||
|
||||
function switchTo(index: number) {
|
||||
appMenuStore.setActived(index)
|
||||
if (
|
||||
appSettingsStore.settings.menu.mainMenuClickMode === 'jump'
|
||||
|| (appSettingsStore.settings.menu.mainMenuClickMode === 'smart' && appMenuStore.sidebarMenusHasOnlyMenu)
|
||||
) {
|
||||
router.push(appMenuStore.sidebarMenusFirstDeepestPath)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
generateTitle,
|
||||
switchTo,
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
export function useAppPage() {
|
||||
const router = useRouter()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
|
||||
function reload() {
|
||||
appSettingsStore.setIsReloading(true)
|
||||
router.push({
|
||||
name: 'reload',
|
||||
}).then(() => {
|
||||
setTimeout(() => {
|
||||
appSettingsStore.setIsReloading(false)
|
||||
}, 100)
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
reload,
|
||||
}
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
export function useAppTabbar() {
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const appTabbarStore = useAppTabbarStore()
|
||||
|
||||
function getId() {
|
||||
return route.fullPath
|
||||
}
|
||||
|
||||
function closeById(tabId = getId()) {
|
||||
if (checkClose(tabId, false)) {
|
||||
const activedTabId = getId()
|
||||
// 如果关闭的标签正好是当前路由
|
||||
if (tabId === activedTabId) {
|
||||
const index = appTabbarStore.list.findIndex(item => item.tabId === tabId)
|
||||
if (index > 0) {
|
||||
router.close(appTabbarStore.list[index - 1].fullPath)
|
||||
}
|
||||
else {
|
||||
router.close(appTabbarStore.list[index + 1].fullPath)
|
||||
}
|
||||
}
|
||||
else {
|
||||
appTabbarStore.remove(tabId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭两侧标签页
|
||||
*/
|
||||
function closeOtherSide(tabId = getId()) {
|
||||
const activedTabId = getId()
|
||||
// 如果操作的是非当前路由标签页,则先跳转到指定路由标签页
|
||||
if (tabId !== activedTabId) {
|
||||
const index = appTabbarStore.list.findIndex(item => item.tabId === tabId)
|
||||
router.push(appTabbarStore.list[index].fullPath)
|
||||
}
|
||||
appTabbarStore.removeOtherSide(tabId)
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭左侧标签页
|
||||
*/
|
||||
function closeLeftSide(tabId = getId()) {
|
||||
const activedTabId = getId()
|
||||
// 如果操作的是非当前路由标签页,需要判断当前标签页是否在指定标签页左侧,如果是则先跳转到指定路由标签页
|
||||
if (tabId !== activedTabId) {
|
||||
const index = appTabbarStore.list.findIndex(item => item.tabId === tabId)
|
||||
const activedIndex = appTabbarStore.list.findIndex(item => item.tabId === activedTabId)
|
||||
if (activedIndex < index) {
|
||||
router.push(appTabbarStore.list[index].fullPath)
|
||||
}
|
||||
}
|
||||
appTabbarStore.removeLeftSide(tabId)
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭右侧标签页
|
||||
*/
|
||||
function closeRightSide(tabId = getId()) {
|
||||
const activedTabId = getId()
|
||||
// 如果操作的是非当前路由标签页,需要判断当前标签页是否在指定标签页右侧,如果是则先跳转到指定路由标签页
|
||||
if (tabId !== activedTabId) {
|
||||
const index = appTabbarStore.list.findIndex(item => item.tabId === tabId)
|
||||
const activedIndex = appTabbarStore.list.findIndex(item => item.tabId === activedTabId)
|
||||
if (activedIndex > index) {
|
||||
router.push(appTabbarStore.list[index].fullPath)
|
||||
}
|
||||
}
|
||||
appTabbarStore.removeRightSide(tabId)
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验指定标签是否可关闭
|
||||
*/
|
||||
function checkClose(tabId = getId(), checkOnly = true) {
|
||||
let flag = true
|
||||
const index = appTabbarStore.list.findIndex(item => item.tabId === tabId)
|
||||
if (index < 0) {
|
||||
flag = false
|
||||
!checkOnly && useFaToast().warning('关闭的标签页不存在', {
|
||||
position: 'top-center',
|
||||
})
|
||||
}
|
||||
else if (appTabbarStore.list.length <= 1) {
|
||||
flag = false
|
||||
!checkOnly && useFaToast().warning('当前只有一个标签页,不可关闭', {
|
||||
position: 'top-center',
|
||||
})
|
||||
}
|
||||
return flag
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验指定标签两侧是否有可关闭的标签
|
||||
*/
|
||||
function checkCloseOtherSide(tabId = getId()) {
|
||||
return appTabbarStore.list.some((item) => {
|
||||
return item.tabId !== tabId
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验指定标签左侧是否有可关闭的标签
|
||||
*/
|
||||
function checkCloseLeftSide(tabId = getId()) {
|
||||
let flag = true
|
||||
if (tabId === appTabbarStore.list[0]?.tabId) {
|
||||
flag = false
|
||||
}
|
||||
else {
|
||||
const index = appTabbarStore.list.findIndex(item => item.tabId === tabId)
|
||||
flag = appTabbarStore.list.some((item, i) => {
|
||||
return i < index && item.tabId !== tabId
|
||||
})
|
||||
}
|
||||
return flag
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验指定标签右侧是否有可关闭的标签
|
||||
*/
|
||||
function checkCloseRightSide(tabId = getId()) {
|
||||
let flag = true
|
||||
if (tabId === appTabbarStore.list.at(-1)?.tabId) {
|
||||
flag = false
|
||||
}
|
||||
else {
|
||||
const index = appTabbarStore.list.findIndex(item => item.tabId === tabId)
|
||||
flag = appTabbarStore.list.some((item, i) => {
|
||||
return i >= index && item.tabId !== tabId
|
||||
})
|
||||
}
|
||||
return flag
|
||||
}
|
||||
|
||||
return {
|
||||
getId,
|
||||
closeById,
|
||||
closeOtherSide,
|
||||
closeLeftSide,
|
||||
closeRightSide,
|
||||
checkClose,
|
||||
checkCloseOtherSide,
|
||||
checkCloseLeftSide,
|
||||
checkCloseRightSide,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import type { HotkeyBinding } from '@fantastic-admin/hotkeys'
|
||||
|
||||
/**
|
||||
* 业务扩展快捷键 id
|
||||
*
|
||||
* 使用方式:
|
||||
*
|
||||
* export const EXT_HOTKEY_ID = {
|
||||
* demoOpen: 'demo.open',
|
||||
* } as const
|
||||
*/
|
||||
export const EXT_HOTKEY_ID = {} as const
|
||||
|
||||
type ExtendHotkeyId = typeof EXT_HOTKEY_ID[keyof typeof EXT_HOTKEY_ID]
|
||||
|
||||
/**
|
||||
* 业务扩展全局快捷键
|
||||
*
|
||||
* 示例:
|
||||
*
|
||||
* export const extendGlobalHotkeyBindings = [
|
||||
* {
|
||||
* id: EXT_HOTKEY_ID.demoOpen,
|
||||
* keys: ['command+j', 'ctrl+j'],
|
||||
* enabled: ctx => ctx.settings.toolbar.menuSearch.enable,
|
||||
* help: {
|
||||
* group: 'global',
|
||||
* titleKey: 'global.demoOpen',
|
||||
* order: 90,
|
||||
* visible: ctx => ctx.settings.toolbar.menuSearch.enable,
|
||||
* displayKeys: {
|
||||
* default: ['Ctrl', 'J'],
|
||||
* mac: ['⌘', 'J'],
|
||||
* },
|
||||
* },
|
||||
* },
|
||||
* ] satisfies HotkeyBinding<ExtendHotkeyId>[]
|
||||
*/
|
||||
export const extendGlobalHotkeyBindings = [] satisfies HotkeyBinding<ExtendHotkeyId>[]
|
||||
|
||||
/**
|
||||
* 业务扩展局部快捷键
|
||||
*
|
||||
* 示例:
|
||||
*
|
||||
* export const extendScopedHotkeyBindings = [
|
||||
* {
|
||||
* id: EXT_HOTKEY_ID.demoConfirm,
|
||||
* keys: ['enter'],
|
||||
* },
|
||||
* {
|
||||
* id: EXT_HOTKEY_ID.demoClose,
|
||||
* keys: ['esc'],
|
||||
* },
|
||||
* ] satisfies HotkeyBinding<ExtendHotkeyId>[]
|
||||
*/
|
||||
export const extendScopedHotkeyBindings = [] satisfies HotkeyBinding<ExtendHotkeyId>[]
|
||||
@@ -0,0 +1,41 @@
|
||||
import type {
|
||||
HotkeyBinding,
|
||||
HotkeyContextBase,
|
||||
HotkeyDisplayKeys,
|
||||
HotkeyHandler,
|
||||
HotkeyHandlerArgs,
|
||||
HotkeyHandlersMap,
|
||||
HotkeyHelpGroup,
|
||||
HotkeyHelpMeta,
|
||||
} from '@fantastic-admin/hotkeys'
|
||||
import { createHotkeys } from '@fantastic-admin/hotkeys'
|
||||
import { EXT_HOTKEY_ID, extendGlobalHotkeyBindings, extendScopedHotkeyBindings } from './extend'
|
||||
|
||||
const appHotkeys = createHotkeys({
|
||||
extendIds: EXT_HOTKEY_ID,
|
||||
extendGlobalHotkeyBindings,
|
||||
extendScopedHotkeyBindings,
|
||||
getContext: () => ({
|
||||
settings: useAppSettingsStore().settings,
|
||||
}),
|
||||
})
|
||||
|
||||
export const HOTKEY_ID = appHotkeys.HOTKEY_ID
|
||||
export const hotkeyIds = appHotkeys.hotkeyIds
|
||||
export const globalHotkeyBindings = appHotkeys.globalHotkeyBindings
|
||||
export const menuSearchHotkeyBindings = appHotkeys.menuSearchHotkeyBindings
|
||||
export const hotkeyBindings = appHotkeys.hotkeyBindings
|
||||
export const useHotkey = appHotkeys.useHotkey
|
||||
export const useHotkeyBindings = appHotkeys.useHotkeyBindings
|
||||
|
||||
export type HotkeyId = typeof HOTKEY_ID[keyof typeof HOTKEY_ID]
|
||||
export type {
|
||||
HotkeyBinding,
|
||||
HotkeyContextBase,
|
||||
HotkeyDisplayKeys,
|
||||
HotkeyHandler,
|
||||
HotkeyHandlerArgs,
|
||||
HotkeyHandlersMap,
|
||||
HotkeyHelpGroup,
|
||||
HotkeyHelpMeta,
|
||||
}
|
||||
Executable
+1
File diff suppressed because one or more lines are too long
+1
@@ -0,0 +1 @@
|
||||
{ "collections": ["ant-design", "ep", "flagpack", "icon-park", "mdi", "ri", "logos", "twemoji", "vscode-icons"], "isOfflineUse": false }
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
import { addCollection } from '@iconify/vue'
|
||||
import data from './data.json'
|
||||
|
||||
export async function downloadAndInstall(name: string) {
|
||||
const data = Object.freeze(await fetch(`./icons/${name}-raw.json`).then(r => r.json()))
|
||||
addCollection(data)
|
||||
}
|
||||
|
||||
export const icons = data.sort((a, b) => a.info.name.localeCompare(b.info.name))
|
||||
@@ -0,0 +1,440 @@
|
||||
<script setup lang="ts">
|
||||
import { diffTwoObj, setSettings } from '@fantastic-admin/settings'
|
||||
import { useClipboard } from '@vueuse/core'
|
||||
import eventBus from '@/utils/eventBus'
|
||||
|
||||
defineOptions({
|
||||
name: 'AppSetting',
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const settingsDefault = setSettings({})
|
||||
const appMenuStore = useAppMenuStore()
|
||||
|
||||
const isShow = ref(false)
|
||||
|
||||
const themeRadius = computed<number[]>({
|
||||
get() {
|
||||
return [appSettingsStore.settings.theme.radius]
|
||||
},
|
||||
set(value) {
|
||||
appSettingsStore.settings.theme.radius = value[0]
|
||||
},
|
||||
})
|
||||
|
||||
watch(() => appSettingsStore.settings.menu.mode, (value) => {
|
||||
if (value === 'single') {
|
||||
appMenuStore.setActived(0)
|
||||
}
|
||||
else {
|
||||
appMenuStore.setActived(route.fullPath)
|
||||
}
|
||||
})
|
||||
onMounted(() => {
|
||||
eventBus.on('global-app-setting-toggle', () => {
|
||||
isShow.value = !isShow.value
|
||||
})
|
||||
})
|
||||
|
||||
const { copy, copied, isSupported } = useClipboard()
|
||||
|
||||
function handleCopy() {
|
||||
copy(JSON.stringify(diffTwoObj(settingsDefault, appSettingsStore.settings), null, 2))
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FaModal v-model="isShow" title="应用配置" description="在生产环境中应关闭该模块" :footer="isSupported" :destroy-on-close="false" class="sm:max-w-4xl" content-class="bg-[var(--g-main-area-bg)] transition-background-color">
|
||||
<div
|
||||
:class="{
|
||||
'columns-1': appSettingsStore.mode === 'mobile',
|
||||
'columns-2': appSettingsStore.mode === 'pc',
|
||||
}"
|
||||
>
|
||||
<FaPageMain title="主题" class="m-0 mb-4 break-inside-avoid light:border-none" title-class="font-bold" main-class="space-y-4">
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
颜色方案
|
||||
</div>
|
||||
<FaButtonGroup>
|
||||
<FaButton
|
||||
v-for="(item, index) in [
|
||||
{ icon: 'i-ri:sun-line', value: 'light' },
|
||||
{ icon: 'i-ri:moon-line', value: 'dark' },
|
||||
{ icon: 'i-codicon:color-mode', value: '' },
|
||||
]" :key="index" :variant="appSettingsStore.settings.theme.colorScheme === item.value ? 'default' : 'outline'" size="sm" :class="{ 'z-1': appSettingsStore.settings.theme.colorScheme === item.value }" @click="appSettingsStore.settings.theme.colorScheme = (item.value as any)"
|
||||
>
|
||||
<FaIcon :name="item.icon" />
|
||||
</FaButton>
|
||||
</FaButtonGroup>
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
圆角
|
||||
</div>
|
||||
<FaSlider v-model="themeRadius" :min="0" :max="1" :step="0.25" class="w-1/2" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
色弱模式
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.theme.colorAmblyopia" />
|
||||
</div>
|
||||
</FaPageMain>
|
||||
<FaPageMain v-if="appSettingsStore.mode === 'pc'" title="导航菜单" class="m-0 mb-4 break-inside-avoid light:border-none" title-class="font-bold" main-class="space-y-4">
|
||||
<div class="menu-mode">
|
||||
<FaTooltip text="侧边栏模式 (有主导航菜单)" :delay="500">
|
||||
<FaButton variant="outline" class="mode mode-side" :class="{ active: appSettingsStore.settings.menu.mode === 'side' }" @click="appSettingsStore.settings.menu.mode = 'side'">
|
||||
<div class="mode-container" />
|
||||
</FaButton>
|
||||
</FaTooltip>
|
||||
<FaTooltip text="顶部模式" :delay="500">
|
||||
<FaButton variant="outline" class="mode mode-head" :class="{ active: appSettingsStore.settings.menu.mode === 'head' }" @click="appSettingsStore.settings.menu.mode = 'head'">
|
||||
<div class="mode-container" />
|
||||
</FaButton>
|
||||
</FaTooltip>
|
||||
<FaTooltip text="侧边栏模式 (无主导航菜单)" :delay="500">
|
||||
<FaButton variant="outline" class="mode mode-single" :class="{ active: appSettingsStore.settings.menu.mode === 'single' }" @click="appSettingsStore.settings.menu.mode = 'single'">
|
||||
<div class="mode-container" />
|
||||
</FaButton>
|
||||
</FaTooltip>
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label" :class="{ 'op-50': !['single', 'side', 'head'].includes(appSettingsStore.settings.menu.mode) }">
|
||||
点击主导航菜单
|
||||
<FaTooltip text="智能模式下默认执行切换操作,当次导航菜单只有一个可访问的导航菜单时执行跳转操作">
|
||||
<FaIcon name="i-ri:question-line" class="text-base text-orange cursor-help" />
|
||||
</FaTooltip>
|
||||
</div>
|
||||
<FaButtonGroup>
|
||||
<FaButton
|
||||
v-for="(item, index) in [
|
||||
{ label: '切换', value: 'switch' },
|
||||
{ label: '跳转', value: 'jump' },
|
||||
{ label: '智能', value: 'smart' },
|
||||
]" :key="index" :variant="appSettingsStore.settings.menu.mainMenuClickMode === item.value ? 'default' : 'outline'" size="sm" :disabled="!['single', 'side', 'head'].includes(appSettingsStore.settings.menu.mode)" :class="{ 'z-1': appSettingsStore.settings.menu.mainMenuClickMode === item.value }" @click="appSettingsStore.settings.menu.mainMenuClickMode = (item.value as any)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</FaButton>
|
||||
</FaButtonGroup>
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
次导航菜单唯一展开
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.menu.subMenuUniqueExpand" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
次导航菜单收起
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.menu.subMenuCollapse" />
|
||||
</div>
|
||||
<div v-if="appSettingsStore.mode === 'pc'" class="setting-item">
|
||||
<div class="label">
|
||||
次导航菜单展开/收起按钮
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.menu.subMenuCollapseButton" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label" :class="{ 'op-50': appSettingsStore.settings.menu.mode === 'single' }">
|
||||
快捷键
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.menu.hotkeys" :disabled="appSettingsStore.settings.menu.mode === 'single'" />
|
||||
</div>
|
||||
</FaPageMain>
|
||||
<FaPageMain title="顶栏" class="m-0 mb-4 break-inside-avoid light:border-none" title-class="font-bold" main-class="space-y-4">
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
标签栏
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.topbar.tabbar" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
工具栏
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.topbar.toolbar" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
模式
|
||||
</div>
|
||||
<FaButtonGroup>
|
||||
<FaButton
|
||||
v-for="(item, index) in [
|
||||
{ label: '静态', value: 'static' },
|
||||
{ label: '固定', value: 'fixed' },
|
||||
{ label: '粘性', value: 'sticky' },
|
||||
]" :key="index" :variant="appSettingsStore.settings.topbar.mode === item.value ? 'default' : 'outline'" size="sm" :class="{ 'z-1': appSettingsStore.settings.topbar.mode === item.value }" :disabled="!appSettingsStore.settings.topbar.tabbar && !appSettingsStore.settings.topbar.toolbar" @click="appSettingsStore.settings.topbar.mode = (item.value as any)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</FaButton>
|
||||
</FaButtonGroup>
|
||||
</div>
|
||||
</FaPageMain>
|
||||
<FaPageMain title="标签栏" class="m-0 mb-4 break-inside-avoid light:border-none" title-class="font-bold" main-class="space-y-4">
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
显示图标
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.tabbar.icon" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
快捷键
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.tabbar.hotkeys" />
|
||||
</div>
|
||||
</FaPageMain>
|
||||
<FaPageMain title="工具栏" class="m-0 mb-4 break-inside-avoid light:border-none" title-class="font-bold" main-class="space-y-4">
|
||||
<div v-if="appSettingsStore.mode === 'pc'" class="setting-item">
|
||||
<div class="label">
|
||||
<FaIcon name="i-ic:twotone-double-arrow" />
|
||||
面包屑导航
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.toolbar.breadcrumb" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
<FaIcon name="i-ri:search-line" />
|
||||
导航搜索
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.toolbar.menuSearch.enable" />
|
||||
</div>
|
||||
<div class="ps-8 space-y-4">
|
||||
<div class="setting-item">
|
||||
<div class="label" :class="{ 'op-50': !appSettingsStore.settings.toolbar.menuSearch.enable }">
|
||||
快捷键
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.toolbar.menuSearch.hotkeys" :disabled="!appSettingsStore.settings.toolbar.menuSearch.enable" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="appSettingsStore.mode === 'pc'" class="setting-item">
|
||||
<div class="label">
|
||||
<FaIcon name="i-ri:fullscreen-line" />
|
||||
全屏
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.toolbar.fullscreen" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
<FaIcon name="i-iconoir:refresh-double" />
|
||||
页面刷新
|
||||
<FaTooltip text="重新载入当前页面,并且不刷新浏览器">
|
||||
<FaIcon name="i-ri:question-line" class="text-base text-orange cursor-help" />
|
||||
</FaTooltip>
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.toolbar.pageReload" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
<FaIcon name="i-ri:sun-line" />
|
||||
颜色主题
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.toolbar.colorScheme" />
|
||||
</div>
|
||||
</FaPageMain>
|
||||
<FaPageMain title="页面" class="m-0 mb-4 break-inside-avoid light:border-none" title-class="font-bold" main-class="space-y-4">
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
载入进度条
|
||||
<FaTooltip text="路由跳转时会在页面顶部显示进度条,该进度仅为模拟效果,并非真实加载进度">
|
||||
<FaIcon name="i-ri:question-line" class="text-base text-orange cursor-help" />
|
||||
</FaTooltip>
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.page.progress" />
|
||||
</div>
|
||||
</FaPageMain>
|
||||
<FaPageMain title="应用" class="m-0 mb-4 break-inside-avoid light:border-none" title-class="font-bold" main-class="space-y-4">
|
||||
<div class="p-4 pb-4 pt-14 border rounded-lg relative space-y-4">
|
||||
<div class="font-bold px-4 py-2 border-b border-e rounded-rb-lg inset-s-0 inset-t-0 absolute">
|
||||
账号
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
权限验证
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.app.account.auth" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
动态标题
|
||||
<FaTooltip text="开启时页面标题会显示当前路由标题,格式为“页面标题 - 网站名称”;关闭时则显示网站名称,网站名称在项目根目录下 .env.* 文件里配置">
|
||||
<FaIcon name="i-ri:question-line" class="text-base text-orange cursor-help" />
|
||||
</FaTooltip>
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.app.dynamicTitle" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
哀悼模式
|
||||
<FaTooltip text="网站整体变灰色">
|
||||
<FaIcon name="i-ri:question-line" class="text-base text-orange cursor-help" />
|
||||
</FaTooltip>
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.app.rip" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
移动端访问
|
||||
<FaTooltip text="关闭后,将禁用移动端访问">
|
||||
<FaIcon name="i-ri:question-line" class="text-base text-orange cursor-help" />
|
||||
</FaTooltip>
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.app.mobile" />
|
||||
</div>
|
||||
<div class="p-4 pb-4 pt-14 border rounded-lg relative space-y-4">
|
||||
<div class="font-bold px-4 py-2 border-b border-e rounded-rb-lg inset-s-0 inset-t-0 absolute">
|
||||
主页
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
启用
|
||||
<FaTooltip text="登录后默认进入主页,否则默认进入第一个导航页面">
|
||||
<FaIcon name="i-ri:question-line" class="text-base text-orange cursor-help" />
|
||||
</FaTooltip>
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.app.home.enable" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
标题
|
||||
<FaTooltip text="用于设置首页显示标题,支持直接输入简体中文内容">
|
||||
<FaIcon name="i-ri:question-line" class="text-base text-orange cursor-help" />
|
||||
</FaTooltip>
|
||||
</div>
|
||||
<FaInput v-model="appSettingsStore.settings.app.home.title" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="p-4 pb-4 pt-14 border rounded-lg relative space-y-4">
|
||||
<div class="font-bold px-4 py-2 border-b border-e rounded-rb-lg inset-s-0 inset-t-0 absolute">
|
||||
版权
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
启用
|
||||
</div>
|
||||
<FaSwitch v-model="appSettingsStore.settings.app.copyright.enable" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
日期
|
||||
</div>
|
||||
<FaInput v-model="appSettingsStore.settings.app.copyright.dates" :disabled="!appSettingsStore.settings.app.copyright.enable" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
公司
|
||||
</div>
|
||||
<FaInput v-model="appSettingsStore.settings.app.copyright.company" :disabled="!appSettingsStore.settings.app.copyright.enable" />
|
||||
</div>
|
||||
<div class="setting-item">
|
||||
<div class="label">
|
||||
网站
|
||||
</div>
|
||||
<FaInput v-model="appSettingsStore.settings.app.copyright.website" :disabled="!appSettingsStore.settings.app.copyright.enable" />
|
||||
</div>
|
||||
</div>
|
||||
</FaPageMain>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="w-full">
|
||||
<div class="text-sm/6 c-rose mb-2 px-4 py-2 text-center rounded-lg bg-rose/20">
|
||||
在此处调整配置只是临时生效,要想真正应用于项目,请点击「复制配置」按钮,并粘贴到
|
||||
<code class="text-sm font-mono font-semibold px-[0.3rem] py-[0.2rem] rounded bg-muted relative">src/settings.ts</code>
|
||||
文件中。
|
||||
</div>
|
||||
<FaButton class="w-full" @click="handleCopy">
|
||||
<FaIcon :name="copied ? 'i-tabler:clipboard-check' : 'i-tabler:clipboard'" class="size-5" />
|
||||
复制配置
|
||||
</FaButton>
|
||||
</div>
|
||||
</template>
|
||||
</FaModal>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.menu-mode {
|
||||
--uno: flex items-center justify-center gap-4;
|
||||
|
||||
.mode {
|
||||
--uno: relative w-16 h-12;
|
||||
|
||||
&.active {
|
||||
--uno: ring-primary ring-2;
|
||||
}
|
||||
|
||||
&::before,
|
||||
&::after,
|
||||
.mode-container {
|
||||
--uno: absolute pointer-events-none;
|
||||
}
|
||||
|
||||
&::before {
|
||||
--uno: content-empty bg-primary;
|
||||
}
|
||||
|
||||
&::after {
|
||||
--uno: content-empty bg-primary/60;
|
||||
}
|
||||
|
||||
.mode-container {
|
||||
--uno: bg-primary/20 border-width-1.5 border-dashed border-primary;
|
||||
|
||||
&::before {
|
||||
--uno: content-empty absolute w-full h-full;
|
||||
}
|
||||
}
|
||||
|
||||
&-side {
|
||||
&::before {
|
||||
--uno: top-2 bottom-2 start-2 w-2 rounded-ss-1 rounded-es-1;
|
||||
}
|
||||
|
||||
&::after {
|
||||
--uno: top-2 bottom-2 start-4.5 w-3;
|
||||
}
|
||||
|
||||
.mode-container {
|
||||
--uno: inset-t-2 inset-e-2 inset-b-2 inset-s-8 rounded-se-1 rounded-ee-1;
|
||||
}
|
||||
}
|
||||
|
||||
&-head {
|
||||
&::before {
|
||||
--uno: top-2 start-2 end-2 h-2 rounded-ss-1 rounded-se-1;
|
||||
}
|
||||
|
||||
&::after {
|
||||
--uno: top-4.5 start-2 bottom-2 w-3 rounded-es-1;
|
||||
}
|
||||
|
||||
.mode-container {
|
||||
--uno: inset-t-4.5 inset-e-2 inset-b-2 inset-s-5.5 rounded-ee-1;
|
||||
}
|
||||
}
|
||||
|
||||
&-single {
|
||||
&::after {
|
||||
--uno: top-2 start-2 bottom-2 w-3 rounded-ss-1 rounded-es-1;
|
||||
}
|
||||
|
||||
.mode-container {
|
||||
--uno: inset-t-2 inset-e-2 inset-b-2 inset-s-5.5 rounded-se-1 rounded-ee-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.setting-item {
|
||||
--uno: flex items-center justify-between gap-4;
|
||||
|
||||
.label {
|
||||
--uno: flex items-center flex-shrink-0 gap-2 text-sm;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<div class="text-sm flex items-center">
|
||||
<slot />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
:deep(.breadcrumb-item) {
|
||||
&:first-child {
|
||||
.separator {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
.text {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,38 @@
|
||||
<script setup lang="ts">
|
||||
import type { RouteLocationRaw } from 'vue-router'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
to?: RouteLocationRaw
|
||||
replace?: boolean
|
||||
separator?: string
|
||||
}>(),
|
||||
{
|
||||
separator: '/',
|
||||
},
|
||||
)
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
function onClick() {
|
||||
if (props.to) {
|
||||
props.replace ? router.replace(props.to) : router.push(props.to)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="breadcrumb-item text-foreground flex items-center">
|
||||
<span class="separator mx-2">
|
||||
{{ separator }}
|
||||
</span>
|
||||
<span
|
||||
class="text opacity-60 flex items-center"
|
||||
:class="{
|
||||
'is-link cursor-pointer transition-opacity hover-opacity-100': !!props.to,
|
||||
}" @click="onClick"
|
||||
>
|
||||
<slot />
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,253 @@
|
||||
<script setup lang="ts">
|
||||
import type { CSSProperties } from 'vue'
|
||||
|
||||
type SnapSide = 'left' | 'right'
|
||||
|
||||
const EDGE_OFFSET = 4
|
||||
const DRAG_THRESHOLD = 8
|
||||
const DEFAULT_BUTTON_SIZE = 40
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const buttonRef = useTemplateRef('buttonRef')
|
||||
|
||||
const buttonState = ref({
|
||||
initialized: false,
|
||||
width: DEFAULT_BUTTON_SIZE,
|
||||
height: DEFAULT_BUTTON_SIZE,
|
||||
left: EDGE_OFFSET,
|
||||
top: EDGE_OFFSET,
|
||||
snapSide: 'left' as SnapSide,
|
||||
})
|
||||
|
||||
const dragState = ref({
|
||||
pointerId: -1,
|
||||
active: false,
|
||||
moved: false,
|
||||
suppressClick: false,
|
||||
startX: 0,
|
||||
startY: 0,
|
||||
startLeft: 0,
|
||||
startTop: 0,
|
||||
})
|
||||
|
||||
const buttonStyle = computed<CSSProperties>(() => ({
|
||||
left: buttonState.value.initialized
|
||||
? `${buttonState.value.left}px`
|
||||
: `${EDGE_OFFSET}px`,
|
||||
right: buttonState.value.initialized
|
||||
? 'auto'
|
||||
: 'auto',
|
||||
top: buttonState.value.initialized
|
||||
? `${buttonState.value.top}px`
|
||||
: 'auto',
|
||||
bottom: buttonState.value.initialized
|
||||
? 'auto'
|
||||
: `${EDGE_OFFSET}px`,
|
||||
transition: dragState.value.active ? 'none' : 'left 200ms ease, top 200ms ease',
|
||||
willChange: 'left, top',
|
||||
}))
|
||||
|
||||
function getButtonElement() {
|
||||
const el = buttonRef.value?.$el
|
||||
return el instanceof HTMLElement ? el : null
|
||||
}
|
||||
|
||||
function clamp(value: number, min: number, max: number) {
|
||||
return Math.min(Math.max(value, min), max)
|
||||
}
|
||||
|
||||
function getViewportBounds() {
|
||||
return {
|
||||
minLeft: EDGE_OFFSET,
|
||||
maxLeft: Math.max(EDGE_OFFSET, window.innerWidth - buttonState.value.width - EDGE_OFFSET),
|
||||
minTop: EDGE_OFFSET,
|
||||
maxTop: Math.max(EDGE_OFFSET, window.innerHeight - buttonState.value.height - EDGE_OFFSET),
|
||||
}
|
||||
}
|
||||
|
||||
function syncButtonMetrics() {
|
||||
const rect = getButtonElement()?.getBoundingClientRect()
|
||||
if (!rect) {
|
||||
return
|
||||
}
|
||||
buttonState.value.width = rect.width || DEFAULT_BUTTON_SIZE
|
||||
buttonState.value.height = rect.height || DEFAULT_BUTTON_SIZE
|
||||
}
|
||||
|
||||
function setButtonPosition(left = buttonState.value.left, top = buttonState.value.top) {
|
||||
const bounds = getViewportBounds()
|
||||
buttonState.value.left = clamp(left, bounds.minLeft, bounds.maxLeft)
|
||||
buttonState.value.top = clamp(top, bounds.minTop, bounds.maxTop)
|
||||
}
|
||||
|
||||
function snapToSide(side: SnapSide) {
|
||||
const bounds = getViewportBounds()
|
||||
buttonState.value.snapSide = side
|
||||
buttonState.value.left = side === 'left' ? bounds.minLeft : bounds.maxLeft
|
||||
buttonState.value.top = clamp(buttonState.value.top, bounds.minTop, bounds.maxTop)
|
||||
}
|
||||
|
||||
function syncPositionToViewport() {
|
||||
syncButtonMetrics()
|
||||
const bounds = getViewportBounds()
|
||||
buttonState.value.top = clamp(buttonState.value.top, bounds.minTop, bounds.maxTop)
|
||||
buttonState.value.left = buttonState.value.snapSide === 'right'
|
||||
? bounds.maxLeft
|
||||
: clamp(buttonState.value.left, bounds.minLeft, bounds.maxLeft)
|
||||
}
|
||||
|
||||
async function initializeButtonPosition() {
|
||||
if (appSettingsStore.mode !== 'mobile') {
|
||||
return
|
||||
}
|
||||
|
||||
await nextTick()
|
||||
syncButtonMetrics()
|
||||
if (!getButtonElement()) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!buttonState.value.initialized) {
|
||||
const bounds = getViewportBounds()
|
||||
buttonState.value.snapSide = 'left'
|
||||
buttonState.value.left = bounds.minLeft
|
||||
buttonState.value.top = bounds.maxTop
|
||||
buttonState.value.initialized = true
|
||||
}
|
||||
|
||||
setButtonPosition()
|
||||
}
|
||||
|
||||
function handlePointerDown(event: PointerEvent) {
|
||||
if (!event.isPrimary || (event.pointerType === 'mouse' && event.button !== 0)) {
|
||||
return
|
||||
}
|
||||
|
||||
const target = event.currentTarget
|
||||
if (!(target instanceof HTMLElement)) {
|
||||
return
|
||||
}
|
||||
|
||||
syncButtonMetrics()
|
||||
dragState.value.pointerId = event.pointerId
|
||||
dragState.value.active = true
|
||||
dragState.value.moved = false
|
||||
dragState.value.startX = event.clientX
|
||||
dragState.value.startY = event.clientY
|
||||
dragState.value.startLeft = buttonState.value.left
|
||||
dragState.value.startTop = buttonState.value.top
|
||||
target.setPointerCapture?.(event.pointerId)
|
||||
}
|
||||
|
||||
function handlePointerMove(event: PointerEvent) {
|
||||
if (!dragState.value.active || dragState.value.pointerId !== event.pointerId) {
|
||||
return
|
||||
}
|
||||
|
||||
const deltaX = event.clientX - dragState.value.startX
|
||||
const deltaY = event.clientY - dragState.value.startY
|
||||
|
||||
if (!dragState.value.moved && Math.hypot(deltaX, deltaY) < DRAG_THRESHOLD) {
|
||||
return
|
||||
}
|
||||
|
||||
dragState.value.moved = true
|
||||
setButtonPosition(dragState.value.startLeft + deltaX, dragState.value.startTop + deltaY)
|
||||
}
|
||||
|
||||
function finishDrag(target?: EventTarget | null) {
|
||||
const pointerId = dragState.value.pointerId
|
||||
const shouldSuppressClick = dragState.value.moved
|
||||
|
||||
dragState.value.pointerId = -1
|
||||
dragState.value.active = false
|
||||
dragState.value.moved = false
|
||||
|
||||
if (target instanceof HTMLElement && pointerId >= 0 && target.hasPointerCapture?.(pointerId)) {
|
||||
target.releasePointerCapture(pointerId)
|
||||
}
|
||||
|
||||
if (shouldSuppressClick) {
|
||||
const nextSide: SnapSide = buttonState.value.left + buttonState.value.width / 2 <= window.innerWidth / 2 ? 'left' : 'right'
|
||||
snapToSide(nextSide)
|
||||
}
|
||||
|
||||
dragState.value.suppressClick = shouldSuppressClick
|
||||
}
|
||||
|
||||
function handlePointerUp(event: PointerEvent) {
|
||||
if (dragState.value.pointerId !== event.pointerId) {
|
||||
return
|
||||
}
|
||||
finishDrag(event.currentTarget)
|
||||
}
|
||||
|
||||
function handlePointerCancel(event: PointerEvent) {
|
||||
if (dragState.value.pointerId !== event.pointerId) {
|
||||
return
|
||||
}
|
||||
finishDrag(event.currentTarget)
|
||||
}
|
||||
|
||||
function handleLostPointerCapture(event: PointerEvent) {
|
||||
if (dragState.value.active && dragState.value.pointerId === event.pointerId) {
|
||||
finishDrag(event.currentTarget)
|
||||
}
|
||||
}
|
||||
|
||||
function handleClick() {
|
||||
if (dragState.value.suppressClick) {
|
||||
dragState.value.suppressClick = false
|
||||
return
|
||||
}
|
||||
appSettingsStore.toggleSidebarCollapse()
|
||||
}
|
||||
|
||||
function handleViewportResize() {
|
||||
if (appSettingsStore.mode !== 'mobile' || !buttonState.value.initialized) {
|
||||
return
|
||||
}
|
||||
syncPositionToViewport()
|
||||
}
|
||||
|
||||
watch(() => appSettingsStore.mode, async (mode) => {
|
||||
if (mode === 'mobile') {
|
||||
await initializeButtonPosition()
|
||||
return
|
||||
}
|
||||
|
||||
dragState.value.pointerId = -1
|
||||
dragState.value.active = false
|
||||
dragState.value.moved = false
|
||||
}, {
|
||||
immediate: true,
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('resize', handleViewportResize, { passive: true })
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', handleViewportResize)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FaButton
|
||||
v-if="appSettingsStore.mode === 'mobile' && !appSettingsStore.settings.topbar.toolbar"
|
||||
ref="buttonRef"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
class="rounded-full size-10 select-none shadow-sm fixed z-1008 touch-none"
|
||||
:class="{ 'cursor-grabbing': dragState.active, 'cursor-grab': !dragState.active }"
|
||||
:style="buttonStyle"
|
||||
@pointerdown="handlePointerDown"
|
||||
@pointermove="handlePointerMove"
|
||||
@pointerup="handlePointerUp"
|
||||
@pointercancel="handlePointerCancel"
|
||||
@lostpointercapture="handleLostPointerCapture"
|
||||
@click="handleClick"
|
||||
>
|
||||
<FaIcon name="app-toolbar-collapse" class="size-4 rotate-180" />
|
||||
</FaButton>
|
||||
</template>
|
||||
@@ -0,0 +1,152 @@
|
||||
<script setup lang="ts">
|
||||
import { useSlots } from '@/slots'
|
||||
import Logo from '../Logo/index.vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'LayoutHeader',
|
||||
})
|
||||
|
||||
defineProps<{
|
||||
enable: boolean
|
||||
}>()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appMenuStore = useAppMenuStore()
|
||||
|
||||
const { generateTitle, switchTo } = useAppMenu()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Transition name="header">
|
||||
<header v-if="enable">
|
||||
<div class="header-container">
|
||||
<Component :is="useSlots('header-start')" />
|
||||
<Logo class="title" />
|
||||
<Component :is="useSlots('header-after-logo')" />
|
||||
<FaScrollArea :scrollbar="false" mask horizontal class="menu-container overscroll-contain flex-1 h-full">
|
||||
<!-- 顶部模式 -->
|
||||
<div
|
||||
v-if="appSettingsStore.settings.menu.mode === 'head'" class="menu flex h-full transition-all of-hidden"
|
||||
>
|
||||
<template v-for="(item, index) in appMenuStore.allMenus" :key="index">
|
||||
<div
|
||||
class="menu-item mx-1 py-2 transition-all relative" :class="{
|
||||
active: index === appMenuStore.actived,
|
||||
}"
|
||||
>
|
||||
<FaTooltip v-if="item.children && item.children.length !== 0" :disabled="!generateTitle(item.meta?.title)" :text="generateTitle(item.meta?.title)" side="bottom">
|
||||
<div
|
||||
class="group menu-item-container text-[var(--g-header-menu-color)] px-3 rounded-lg flex gap-1 h-full w-full cursor-pointer transition-colors items-center justify-between relative hover-(text-[var(--g-header-menu-hover-color)] bg-[var(--g-header-menu-hover-bg)])" :class="{
|
||||
'text-[var(--g-header-menu-active-color)]! bg-[var(--g-header-menu-active-bg)]!': index === appMenuStore.actived,
|
||||
}" @click="switchTo(index)"
|
||||
>
|
||||
<div class="inline-flex flex-1 gap-1 items-center justify-center">
|
||||
<FaIcon v-if="item.meta?.icon" :name="item.meta.icon" class="menu-item-container-icon transition-transform group-hover-scale-120" />
|
||||
<span class="text-sm flex-1 w-full truncate transition-height transition-opacity transition-width empty:hidden">
|
||||
{{ generateTitle(item.meta?.title) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</FaTooltip>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</FaScrollArea>
|
||||
<Component :is="useSlots('header-after-menu')" />
|
||||
<div class="flex-center">
|
||||
<AppAccountButton only-avatar dropdown-side="bottom" class="p-2 size-12" />
|
||||
</div>
|
||||
<Component :is="useSlots('header-end')" />
|
||||
</div>
|
||||
</header>
|
||||
</Transition>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
header {
|
||||
position: fixed;
|
||||
top: var(--g-slots-layout-top-height);
|
||||
right: var(--scrollbar-width, 0);
|
||||
left: 0;
|
||||
z-index: 1020;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: calc(100% - var(--scrollbar-width, 0px));
|
||||
height: var(--g-header-height);
|
||||
margin: 0 auto;
|
||||
color: var(--g-header-color);
|
||||
background-color: var(--g-header-bg);
|
||||
box-shadow: inset 0 -1px 0 0 oklch(var(--border));
|
||||
transition: width 0.3s, background-color 0.15s, box-shadow 0.15s;
|
||||
|
||||
.header-container {
|
||||
display: flex;
|
||||
gap: 30px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
max-width: var(--g-header-width);
|
||||
height: 100%;
|
||||
padding: 0 12px;
|
||||
margin: 0 auto;
|
||||
|
||||
:deep(a.title) {
|
||||
position: relative;
|
||||
flex: 0;
|
||||
width: inherit;
|
||||
height: inherit;
|
||||
padding: 0;
|
||||
background-color: inherit;
|
||||
|
||||
.logo {
|
||||
width: initial;
|
||||
max-width: initial;
|
||||
height: min(70%, 50px);
|
||||
}
|
||||
|
||||
span {
|
||||
font-size: 20px;
|
||||
color: var(--g-header-color);
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-container {
|
||||
.menu {
|
||||
display: inline-flex;
|
||||
|
||||
:deep(.menu-item) {
|
||||
.menu-item-container {
|
||||
color: var(--g-header-menu-color);
|
||||
|
||||
&:hover {
|
||||
color: var(--g-header-menu-hover-color);
|
||||
background-color: var(--g-header-menu-hover-bg);
|
||||
}
|
||||
|
||||
.menu-item-container-icon {
|
||||
font-size: 20px !important;
|
||||
}
|
||||
}
|
||||
|
||||
&.active .menu-item-container {
|
||||
color: var(--g-header-menu-active-color) !important;
|
||||
background-color: var(--g-header-menu-active-bg) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 头部动画 */
|
||||
.header-enter-active,
|
||||
.header-leave-active {
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.header-enter-from,
|
||||
.header-leave-to {
|
||||
transform: translateY(calc(var(--g-header-height) * -1));
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,116 @@
|
||||
<script setup lang="ts">
|
||||
import { hotkeyBindings } from '@/hotkeys'
|
||||
import eventBus from '@/utils/eventBus'
|
||||
|
||||
defineOptions({
|
||||
name: 'HotkeysIntro',
|
||||
})
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const hotkeyContext = {
|
||||
settings: appSettingsStore.settings,
|
||||
}
|
||||
|
||||
const helpGroupMeta = {
|
||||
global: { title: '全局', order: 10 },
|
||||
nav: { title: '主导航', order: 20 },
|
||||
tabbar: { title: '标签栏', order: 30 },
|
||||
} as const
|
||||
|
||||
const itemTitleMap: Record<string, string> = {
|
||||
'global.system': '查看系统信息',
|
||||
'global.search': '唤起导航搜索',
|
||||
'nav.next': '激活下一个主导航',
|
||||
'nav.prev': '激活上一个主导航',
|
||||
'tabbar.prev': '切换到上一个标签页',
|
||||
'tabbar.next': '切换到下一个标签页',
|
||||
'tabbar.close': '关闭当前标签页',
|
||||
'tabbar.n': '切换到第 n 个标签页',
|
||||
'tabbar.last': '切换到最后一个标签页',
|
||||
} as const
|
||||
|
||||
const isShow = ref(false)
|
||||
|
||||
const helpGroups = computed(() => {
|
||||
const groups = new Map<string, {
|
||||
id: string
|
||||
title: string
|
||||
order: number
|
||||
items: {
|
||||
id: string
|
||||
title: string
|
||||
order: number
|
||||
displayKeys: string[]
|
||||
}[]
|
||||
}>()
|
||||
|
||||
hotkeyBindings.forEach((binding) => {
|
||||
const help = binding.help
|
||||
if (!help) {
|
||||
return
|
||||
}
|
||||
if (help.visible && !help.visible(hotkeyContext)) {
|
||||
return
|
||||
}
|
||||
|
||||
const meta = helpGroupMeta[help.group as keyof typeof helpGroupMeta]
|
||||
const group = groups.get(help.group) ?? {
|
||||
id: help.group,
|
||||
title: help.groupTitleKey ? itemTitleMap[help.groupTitleKey] ?? help.groupTitleKey : meta?.title ?? help.group,
|
||||
order: meta?.order ?? 100,
|
||||
items: [],
|
||||
}
|
||||
|
||||
group.items.push({
|
||||
id: binding.id,
|
||||
title: itemTitleMap[help.titleKey] ?? help.titleKey,
|
||||
order: help.order ?? 0,
|
||||
displayKeys: appSettingsStore.os === 'mac' && help.displayKeys.mac
|
||||
? help.displayKeys.mac
|
||||
: help.displayKeys.default,
|
||||
})
|
||||
groups.set(help.group, group)
|
||||
})
|
||||
|
||||
return Array.from(groups.values())
|
||||
.map(group => ({
|
||||
...group,
|
||||
items: [...group.items].sort((a, b) => a.order - b.order),
|
||||
}))
|
||||
.sort((a, b) => a.order - b.order)
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
eventBus.on('global-hotkeys-intro-toggle', () => {
|
||||
isShow.value = !isShow.value
|
||||
})
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
eventBus.off('global-hotkeys-intro-toggle')
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FaModal v-model="isShow" title="快捷键" :footer="false">
|
||||
<div class="px-4">
|
||||
<div class="gap-4 grid sm-grid-cols-2">
|
||||
<div v-for="group in helpGroups" :key="group.id">
|
||||
<h2 class="text-lg font-bold m-0">
|
||||
{{ group.title }}
|
||||
</h2>
|
||||
<ul class="text-sm ps-2 pt-2 list-none">
|
||||
<li v-for="item in group.items" :key="item.id" class="py-1 flex-baseline gap-2">
|
||||
<FaKbdGroup>
|
||||
<FaKbd v-for="key in item.displayKeys" :key="key">
|
||||
{{ key }}
|
||||
</FaKbd>
|
||||
</FaKbdGroup>
|
||||
{{ item.title }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</FaModal>
|
||||
</template>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
import imgLogo from '@/assets/images/logo.svg'
|
||||
|
||||
defineOptions({
|
||||
name: 'Logo',
|
||||
})
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
showLogo?: boolean
|
||||
showTitle?: boolean
|
||||
}>(),
|
||||
{
|
||||
showLogo: true,
|
||||
showTitle: true,
|
||||
},
|
||||
)
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
|
||||
const title = ref(import.meta.env.VITE_APP_TITLE)
|
||||
const logo = ref(imgLogo)
|
||||
|
||||
const to = computed(() => appSettingsStore.settings.app.home.enable ? appSettingsStore.settings.app.home.fullPath : '')
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<RouterLink :to class="text-primary px-3 no-underline flex-center gap-2 h-[var(--g-sidebar-logo-height)] w-inherit" :class="{ 'cursor-default': !appSettingsStore.settings.app.home.enable }" :title="title">
|
||||
<img v-if="showLogo" :src="logo" class="logo h-[30px] w-[30px] object-contain">
|
||||
<span v-if="showTitle" class="font-bold block truncate">{{ title }}</span>
|
||||
</RouterLink>
|
||||
</template>
|
||||
@@ -0,0 +1,125 @@
|
||||
<script setup lang="ts">
|
||||
import { useHotkeyBindings } from '@/hotkeys'
|
||||
import { useSlots } from '@/slots'
|
||||
import Logo from '../Logo/index.vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'MainSidebar',
|
||||
})
|
||||
|
||||
defineProps<{
|
||||
enable: boolean
|
||||
}>()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appMenuStore = useAppMenuStore()
|
||||
|
||||
const { generateTitle, switchTo } = useAppMenu()
|
||||
|
||||
useHotkeyBindings({
|
||||
'menu.next': () => {
|
||||
switchTo(appMenuStore.actived + 1 < appMenuStore.allMenus.length ? appMenuStore.actived + 1 : 0)
|
||||
},
|
||||
'menu.prev': () => {
|
||||
switchTo(appMenuStore.actived - 1 >= 0 ? appMenuStore.actived - 1 : appMenuStore.allMenus.length - 1)
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Transition name="main-sidebar">
|
||||
<div v-if="enable" class="main-sidebar-container">
|
||||
<Component :is="useSlots('main-sidebar-top')" />
|
||||
<Logo :show-title="false" class="sidebar-logo" />
|
||||
<Component :is="useSlots('main-sidebar-after-logo')" />
|
||||
<FaScrollArea :scrollbar="false" mask gradient-color="var(--g-main-sidebar-bg)" class="menu overscroll-contain flex-1">
|
||||
<!-- 侧边栏模式(含主导航) -->
|
||||
<div
|
||||
v-if="appSettingsStore.settings.menu.mode === 'side' || (appSettingsStore.mode === 'mobile' && appSettingsStore.settings.menu.mode !== 'single')" class="py-1 flex flex-col w-full transition-all of-hidden -mt-2"
|
||||
>
|
||||
<template v-for="(item, index) in appMenuStore.allMenus" :key="index">
|
||||
<div
|
||||
class="menu-item px-2 py-1 transition-all relative" :class="{
|
||||
active: index === appMenuStore.actived,
|
||||
}"
|
||||
>
|
||||
<FaTooltip v-if="item.children && item.children.length !== 0" :disabled="!generateTitle(item.meta?.title)" :text="generateTitle(item.meta?.title)" side="right">
|
||||
<div
|
||||
class="group menu-item-container text-[var(--g-main-sidebar-menu-color)] py-4 rounded-lg flex gap-1 h-full w-full cursor-pointer transition-colors items-center justify-between relative hover-(text-[var(--g-main-sidebar-menu-hover-color)] bg-[var(--g-main-sidebar-menu-hover-bg)]) px-2!" :class="{
|
||||
'text-[var(--g-main-sidebar-menu-active-color)]! bg-[var(--g-main-sidebar-menu-active-bg)]!': index === appMenuStore.actived,
|
||||
}" @click="switchTo(index)"
|
||||
>
|
||||
<div class="inline-flex flex-1 flex-col gap-1 w-full items-center justify-center">
|
||||
<FaIcon v-if="item.meta?.icon" :name="item.meta.icon" class="menu-item-container-icon transition-transform group-hover-scale-120" />
|
||||
<span class="text-sm text-center flex-1 w-full truncate transition-height transition-opacity transition-width empty:hidden">
|
||||
{{ generateTitle(item.meta?.title) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</FaTooltip>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</FaScrollArea>
|
||||
<Component :is="useSlots('main-sidebar-after-menu')" />
|
||||
<div class="px-4 py-3 flex-center">
|
||||
<AppAccountButton only-avatar :button-variant="appSettingsStore.settings.menu.mode === 'side' ? 'secondary' : 'ghost'" class="p-2 size-12" />
|
||||
</div>
|
||||
<Component :is="useSlots('main-sidebar-bottom')" />
|
||||
</div>
|
||||
</Transition>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.main-sidebar-container {
|
||||
position: relative;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: var(--g-main-sidebar-width);
|
||||
color: var(--g-main-sidebar-menu-color);
|
||||
background-color: var(--g-main-sidebar-bg);
|
||||
box-shadow: 1px 0 0 0 oklch(var(--border));
|
||||
transition: color 0.15s, background-color 0.15s, box-shadow 0.15s;
|
||||
|
||||
.sidebar-logo {
|
||||
background-color: var(--g-main-sidebar-bg);
|
||||
transition: background-color 0.15s;
|
||||
}
|
||||
|
||||
.menu {
|
||||
:deep(.menu-item) {
|
||||
.menu-item-container {
|
||||
aspect-ratio: 1 / 1;
|
||||
padding-block: 8px;
|
||||
color: var(--g-main-sidebar-menu-color);
|
||||
|
||||
&:hover {
|
||||
color: var(--g-main-sidebar-menu-hover-color);
|
||||
background-color: var(--g-main-sidebar-menu-hover-bg);
|
||||
}
|
||||
|
||||
.menu-item-container-icon {
|
||||
font-size: 20px !important;
|
||||
}
|
||||
}
|
||||
|
||||
&.active .menu-item-container {
|
||||
color: var(--g-main-sidebar-menu-active-color) !important;
|
||||
background-color: var(--g-main-sidebar-menu-active-bg) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 主侧边栏动画 */
|
||||
.main-sidebar-enter-active,
|
||||
.main-sidebar-leave-active {
|
||||
transition: 0.3s;
|
||||
}
|
||||
|
||||
.main-sidebar-enter-from,
|
||||
.main-sidebar-leave-to {
|
||||
transform: translateX(calc(var(--g-main-sidebar-width) * -1));
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,188 @@
|
||||
<script setup lang="ts">
|
||||
import type { MenuInjection, MenuProps } from './types'
|
||||
import { cn } from '@/utils'
|
||||
import Item from './item.vue'
|
||||
import SubMenu from './sub.vue'
|
||||
import { rootMenuInjectionKey } from './types'
|
||||
|
||||
defineOptions({
|
||||
name: 'MainMenu',
|
||||
})
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<MenuProps>(),
|
||||
{
|
||||
accordion: true,
|
||||
defaultExpandPaths: () => [],
|
||||
mode: 'vertical',
|
||||
collapse: false,
|
||||
},
|
||||
)
|
||||
|
||||
// 用于缓存对象到 ID 的映射
|
||||
const idMap = new WeakMap<object, string>()
|
||||
let idCounter = 0
|
||||
// 获取对象的唯一 ID,如果已存在则返回缓存的 ID,否则生成新的
|
||||
function getUseId(obj: object): string {
|
||||
if (!idMap.has(obj)) {
|
||||
idMap.set(obj, `menu-item-${++idCounter}`)
|
||||
}
|
||||
return idMap.get(obj)!
|
||||
}
|
||||
|
||||
const activeIndex = ref<MenuInjection['activeIndex']>(props.value)
|
||||
const items = ref<MenuInjection['items']>({})
|
||||
const subMenus = ref<MenuInjection['subMenus']>({})
|
||||
const expandMenus = ref<MenuInjection['expandMenus']>(props.defaultExpandPaths.slice(0))
|
||||
const mouseInMenu = ref<MenuInjection['mouseInMenu']>([])
|
||||
const isMenuPopup = computed<MenuInjection['isMenuPopup']>(() => {
|
||||
return props.mode === 'horizontal' || (props.mode === 'vertical' && props.collapse)
|
||||
})
|
||||
|
||||
// 解析传入的 menu 数据,并保存到 items 和 subMenus 对象中
|
||||
function initItems(menu: MenuProps['menu'], parentPaths: string[] = []) {
|
||||
menu.forEach((item) => {
|
||||
const index = item.path ?? getUseId(item)
|
||||
if (item.children?.some(item => item.meta?.menu !== false)) {
|
||||
const indexPath = [...parentPaths, index]
|
||||
subMenus.value[index] = {
|
||||
index,
|
||||
indexPath,
|
||||
active: false,
|
||||
}
|
||||
initItems(item.children, indexPath)
|
||||
}
|
||||
else {
|
||||
items.value[index] = {
|
||||
index,
|
||||
indexPath: parentPaths,
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const openMenu: MenuInjection['openMenu'] = (index, indexPath) => {
|
||||
if (expandMenus.value.includes(index)) {
|
||||
return
|
||||
}
|
||||
if (props.accordion) {
|
||||
expandMenus.value = expandMenus.value.filter(key => indexPath.includes(key))
|
||||
}
|
||||
expandMenus.value.push(index)
|
||||
}
|
||||
const closeMenu: MenuInjection['closeMenu'] = (index) => {
|
||||
if (Array.isArray(index)) {
|
||||
nextTick(() => {
|
||||
closeMenu(index.at(-1)!)
|
||||
if (index.length > 1) {
|
||||
closeMenu(index.slice(0, -1))
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
expandMenus.value = expandMenus.value.filter(item => item !== index)
|
||||
}
|
||||
|
||||
function setSubMenusActive(index: string) {
|
||||
for (const key in subMenus.value) {
|
||||
subMenus.value[key].active = false
|
||||
}
|
||||
subMenus.value[index]?.indexPath.forEach((idx) => {
|
||||
subMenus.value[idx].active = true
|
||||
})
|
||||
items.value[index]?.indexPath.forEach((idx) => {
|
||||
subMenus.value[idx].active = true
|
||||
})
|
||||
}
|
||||
|
||||
const handleMenuItemClick: MenuInjection['handleMenuItemClick'] = (index) => {
|
||||
if (props.mode === 'horizontal' || props.collapse) {
|
||||
expandMenus.value = []
|
||||
}
|
||||
setSubMenusActive(index)
|
||||
}
|
||||
const handleSubMenuClick: MenuInjection['handleSubMenuClick'] = (index, indexPath) => {
|
||||
if (expandMenus.value.includes(index)) {
|
||||
closeMenu(index)
|
||||
}
|
||||
else {
|
||||
openMenu(index, indexPath)
|
||||
}
|
||||
}
|
||||
|
||||
function initMenu() {
|
||||
const activeItem = activeIndex.value && items.value[activeIndex.value]
|
||||
setSubMenusActive(activeIndex.value)
|
||||
if (!activeItem || isMenuPopup.value || props.collapse) {
|
||||
return
|
||||
}
|
||||
// 展开该菜单项的路径上所有子菜单
|
||||
activeItem.indexPath.forEach((index) => {
|
||||
const subMenu = subMenus.value[index]
|
||||
subMenu && openMenu(index, subMenu.indexPath)
|
||||
})
|
||||
}
|
||||
|
||||
watch(() => props.menu, (val) => {
|
||||
initItems(val)
|
||||
initMenu()
|
||||
}, {
|
||||
deep: true,
|
||||
immediate: true,
|
||||
})
|
||||
|
||||
watch(() => props.value, (currentValue) => {
|
||||
if (!items.value[currentValue]) {
|
||||
activeIndex.value = ''
|
||||
}
|
||||
const item = items.value[currentValue] || (activeIndex.value && items.value[activeIndex.value]) || items.value[props.value]
|
||||
if (item) {
|
||||
activeIndex.value = item.index
|
||||
}
|
||||
else {
|
||||
activeIndex.value = currentValue
|
||||
}
|
||||
initMenu()
|
||||
})
|
||||
|
||||
watch(() => props.collapse, (value) => {
|
||||
if (value) {
|
||||
expandMenus.value = []
|
||||
}
|
||||
else {
|
||||
expandMenus.value = props.defaultExpandPaths.slice(0)
|
||||
}
|
||||
initMenu()
|
||||
})
|
||||
|
||||
provide(rootMenuInjectionKey, reactive({
|
||||
props,
|
||||
getUseId,
|
||||
items,
|
||||
subMenus,
|
||||
activeIndex,
|
||||
expandMenus,
|
||||
mouseInMenu,
|
||||
isMenuPopup,
|
||||
openMenu,
|
||||
closeMenu,
|
||||
handleMenuItemClick,
|
||||
handleSubMenuClick,
|
||||
}))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
:class="cn('h-full w-full flex flex-col of-hidden', {
|
||||
'flex-row w-auto': isMenuPopup && props.mode === 'horizontal',
|
||||
'py-1': props.mode === 'vertical',
|
||||
})"
|
||||
>
|
||||
<template v-for="item in menu" :key="item.path ?? getUseId(item)">
|
||||
<template v-if="item.meta?.menu !== false">
|
||||
<SubMenu v-if="item.children?.length" :menu="item" :unique-key="[item.path ?? (item.children.every(item => item.meta?.menu === false) ? item.children[0].path! : getUseId(item))]" />
|
||||
<Item v-else :item="item" :unique-key="[item.path ?? (item.children?.every(item => item.meta?.menu === false) ? item.children[0].path! : getUseId(item))]" @click="handleMenuItemClick(item.path ?? (item.children?.every(item => item.meta?.menu === false) ? item.children[0].path! : getUseId(item)))" />
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
<script setup lang="ts">
|
||||
import type { SubMenuItemProps } from './types'
|
||||
import { cn } from '@/utils'
|
||||
import { rootMenuInjectionKey } from './types'
|
||||
|
||||
defineOptions({
|
||||
name: 'SubMenuItem',
|
||||
})
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<SubMenuItemProps>(),
|
||||
{
|
||||
level: 0,
|
||||
subMenu: false,
|
||||
expand: false,
|
||||
},
|
||||
)
|
||||
|
||||
const { generateTitle } = useAppMenu()
|
||||
|
||||
const rootMenu = inject(rootMenuInjectionKey)!
|
||||
|
||||
const itemRef = ref<HTMLElement>()
|
||||
|
||||
const isActived = computed(() => {
|
||||
return props.subMenu
|
||||
? rootMenu.subMenus[props.uniqueKey.at(-1)!].active
|
||||
: rootMenu.activeIndex === props.uniqueKey.at(-1)!
|
||||
})
|
||||
|
||||
const isItemActive = computed(() => {
|
||||
return isActived.value && (!props.subMenu || rootMenu.isMenuPopup)
|
||||
})
|
||||
|
||||
const icon = computed(() => {
|
||||
return props.item.meta?.icon
|
||||
})
|
||||
|
||||
defineExpose({
|
||||
ref: itemRef,
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
ref="itemRef" :class="cn('menu-item relative', {
|
||||
'active': isItemActive,
|
||||
'py-1 px-2': (rootMenu.isMenuPopup && rootMenu.props.mode === 'vertical') || (rootMenu.isMenuPopup && level !== 0 && rootMenu.props.mode === 'horizontal') || !rootMenu.isMenuPopup,
|
||||
'px-1 py-2': rootMenu.isMenuPopup && level === 0 && rootMenu.props.mode === 'horizontal',
|
||||
})"
|
||||
>
|
||||
<router-link v-slot="{ href, navigate }" custom :to="uniqueKey.at(-1) ?? ''">
|
||||
<FaTooltip :disabled="!generateTitle(item.meta?.title) || !rootMenu.isMenuPopup || level !== 0 || subMenu" :text="generateTitle(item.meta?.title)" :side="rootMenu.props.mode === 'vertical' ? 'right' : 'bottom'" class="h-full w-full">
|
||||
<Component
|
||||
:is="subMenu ? 'div' : 'a'" v-bind="{
|
||||
...(!subMenu && {
|
||||
href: item.meta?.link ? item.meta.link : href,
|
||||
target: item.meta?.link ? '_blank' : '_self',
|
||||
class: 'no-underline',
|
||||
}),
|
||||
}" :class="cn('group menu-item-container relative h-full w-full min-w-0 flex items-center justify-between gap-1 rounded-lg', {
|
||||
'px-4 py-3': true,
|
||||
'cursor-pointer text-[var(--g-sub-sidebar-menu-color)] transition-colors hover-(bg-[var(--g-sub-sidebar-menu-hover-bg)] text-[var(--g-sub-sidebar-menu-hover-color)])': true,
|
||||
'text-[var(--g-sub-sidebar-menu-active-color)]! bg-[var(--g-sub-sidebar-menu-active-bg)]!': isItemActive,
|
||||
'px-3': rootMenu.isMenuPopup && level === 0,
|
||||
'py-3': rootMenu.isMenuPopup && level !== 0,
|
||||
})" :title="generateTitle(item.meta?.title)" v-on="{
|
||||
...(!subMenu && {
|
||||
click: navigate,
|
||||
}),
|
||||
}"
|
||||
>
|
||||
<div
|
||||
:class="cn('inline-flex min-w-0 flex-1 items-center justify-start', {
|
||||
'gap-[12px]': true,
|
||||
'ps-[calc(var(--indent-level)*20px)]': true,
|
||||
'flex-col': rootMenu.isMenuPopup && level === 0 && rootMenu.props.mode === 'vertical',
|
||||
})" :style="{
|
||||
'--indent-level': !rootMenu.isMenuPopup ? props.level ?? 0 : 0,
|
||||
}"
|
||||
>
|
||||
<FaIcon
|
||||
v-if="icon" :name="icon" :class="cn('menu-item-container-icon', {
|
||||
'size-5': true,
|
||||
'transition-transform group-hover-scale-120': true,
|
||||
})"
|
||||
/>
|
||||
<span
|
||||
v-if="!(rootMenu.isMenuPopup && level === 0)" :class="cn('block min-w-0 flex-1 truncate text-sm transition-height transition-opacity transition-width', {
|
||||
'empty:hidden': !generateTitle(item.meta?.title),
|
||||
})"
|
||||
>
|
||||
{{ generateTitle(item.meta?.title) }}
|
||||
</span>
|
||||
</div>
|
||||
<i
|
||||
v-if="
|
||||
subMenu
|
||||
&& (!rootMenu.isMenuPopup || level !== 0) // 非收起模式,非一级的子菜单
|
||||
" :class="cn('relative ms-1 w-[10px] after:absolute before:absolute after:h-[1.5px] after:w-[6px] before:h-[1.5px] before:w-[6px] after:bg-current before:bg-current after:transition-transform-200 before:transition-transform-200 after:content-empty before:content-empty after:-translate-y-[1px] before:-translate-y-[1px]', {
|
||||
[expand ? 'before:-rotate-45 before:-translate-x-[2px] after:rotate-45 after:translate-x-[2px]' : 'before:rotate-45 before:-translate-x-[2px] after:-rotate-45 after:translate-x-[2px]']: true,
|
||||
'opacity-0': rootMenu.isMenuPopup && level === 0,
|
||||
'-rotate-90 -top-[1.5px]': rootMenu.isMenuPopup && level !== 0,
|
||||
})"
|
||||
/>
|
||||
</component>
|
||||
</FaTooltip>
|
||||
</router-link>
|
||||
</div>
|
||||
</template>
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
<script setup lang="ts">
|
||||
import type { SubMenuProps } from './types'
|
||||
import { useTimeoutFn } from '@vueuse/core'
|
||||
import { cn } from '@/utils'
|
||||
import Item from './item.vue'
|
||||
import { rootMenuInjectionKey } from './types'
|
||||
|
||||
defineOptions({
|
||||
name: 'SubMenu',
|
||||
})
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<SubMenuProps>(),
|
||||
{
|
||||
level: 0,
|
||||
},
|
||||
)
|
||||
|
||||
const itemRef = useTemplateRef('itemRef')
|
||||
const subMenuRef = useTemplateRef('subMenuRef')
|
||||
const rootMenu = inject(rootMenuInjectionKey)!
|
||||
|
||||
const index = props.menu.path ?? rootMenu.getUseId(props.menu)
|
||||
|
||||
const expand = computed(() => rootMenu.expandMenus.includes(props.uniqueKey.at(-1)!))
|
||||
|
||||
const transitionEvent = computed(() => {
|
||||
if (rootMenu.isMenuPopup) {
|
||||
return {
|
||||
enter(el: HTMLElement) {
|
||||
if (el.offsetHeight > window.innerHeight) {
|
||||
el.style.height = `${window.innerHeight}px`
|
||||
}
|
||||
},
|
||||
afterEnter: () => {},
|
||||
beforeLeave: (el: HTMLElement) => {
|
||||
el.style.maxHeight = `${el.offsetHeight}px`
|
||||
el.style.overflow = 'hidden'
|
||||
},
|
||||
leave: (el: HTMLElement) => {
|
||||
el.style.maxHeight = '0'
|
||||
},
|
||||
afterLeave(el: HTMLElement) {
|
||||
el.style.maxHeight = ''
|
||||
el.style.overflow = ''
|
||||
},
|
||||
}
|
||||
}
|
||||
if (CSS.supports('height', 'calc-size(auto, size)')) {
|
||||
return {}
|
||||
}
|
||||
return {
|
||||
enter(el: HTMLElement) {
|
||||
el.dataset.height = el.offsetHeight.toString()
|
||||
el.style.maxHeight = '0'
|
||||
el.style.overflow = 'hidden'
|
||||
void el.offsetHeight // 强制重排,确保浏览器应用初始状态
|
||||
requestAnimationFrame(() => {
|
||||
el.style.maxHeight = `${el.dataset.height}px`
|
||||
})
|
||||
},
|
||||
afterEnter(el: HTMLElement) {
|
||||
el.style.maxHeight = ''
|
||||
el.style.overflow = ''
|
||||
},
|
||||
enterCancelled(el: HTMLElement) {
|
||||
el.style.maxHeight = ''
|
||||
el.style.overflow = ''
|
||||
},
|
||||
beforeLeave(el: HTMLElement) {
|
||||
el.style.maxHeight = `${el.offsetHeight}px`
|
||||
el.style.overflow = 'hidden'
|
||||
void el.offsetHeight // 强制重排,确保浏览器应用初始状态
|
||||
},
|
||||
leave(el: HTMLElement) {
|
||||
requestAnimationFrame(() => {
|
||||
el.style.maxHeight = '0'
|
||||
})
|
||||
},
|
||||
afterLeave(el: HTMLElement) {
|
||||
el.style.maxHeight = ''
|
||||
el.style.overflow = ''
|
||||
},
|
||||
leaveCancelled(el: HTMLElement) {
|
||||
el.style.maxHeight = ''
|
||||
el.style.overflow = ''
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
const transitionClass = computed(() => {
|
||||
if (rootMenu.isMenuPopup) {
|
||||
return {
|
||||
enterActiveClass: 'ease-in-out duration-300',
|
||||
enterFromClass: 'opacity-0 translate-x-4',
|
||||
enterToClass: 'opacity-100',
|
||||
leaveActiveClass: 'ease-in-out duration-300',
|
||||
leaveFromClass: 'opacity-100',
|
||||
leaveToClass: 'opacity-0',
|
||||
}
|
||||
}
|
||||
return {
|
||||
enterActiveClass: 'ease-in-out duration-200',
|
||||
enterFromClass: cn('opacity-0 translate-y-2', CSS.supports('height', 'calc-size(auto, size)') && 'h-0'),
|
||||
enterToClass: 'opacity-100 translate-y-0',
|
||||
leaveActiveClass: 'ease-in-out duration-200',
|
||||
leaveFromClass: 'opacity-100 translate-y-0',
|
||||
leaveToClass: cn('opacity-0 translate-y-2', CSS.supports('height', 'calc-size(auto, size)') && 'h-0'),
|
||||
}
|
||||
})
|
||||
|
||||
const hasChildren = computed(() => props.menu.children?.some((item: any) => item.meta?.menu !== false) ?? false)
|
||||
|
||||
function handleClick() {
|
||||
if (
|
||||
(rootMenu.isMenuPopup && hasChildren.value)
|
||||
|| props.menu.meta?.link
|
||||
) {
|
||||
return
|
||||
}
|
||||
if (hasChildren.value) {
|
||||
rootMenu.handleSubMenuClick(index, props.uniqueKey)
|
||||
}
|
||||
else {
|
||||
rootMenu.handleMenuItemClick(index)
|
||||
}
|
||||
}
|
||||
|
||||
let timeout: (() => void) | undefined
|
||||
|
||||
function handleMouseenter() {
|
||||
if (!rootMenu.isMenuPopup) {
|
||||
return
|
||||
}
|
||||
rootMenu.mouseInMenu = props.uniqueKey
|
||||
timeout?.()
|
||||
;({ stop: timeout } = useTimeoutFn(() => {
|
||||
if (hasChildren.value) {
|
||||
rootMenu.openMenu(index, props.uniqueKey)
|
||||
nextTick(() => {
|
||||
requestAnimationFrame(() => {
|
||||
const el = itemRef.value?.ref
|
||||
const subMenuEl = subMenuRef.value?.$el
|
||||
if (!el || !subMenuEl) {
|
||||
return
|
||||
}
|
||||
const rect = el.getBoundingClientRect()
|
||||
const { top, left, width, height } = rect
|
||||
let menuTop = 0
|
||||
let menuLeft = 0
|
||||
if (rootMenu.props.mode === 'vertical' || props.level !== 0) {
|
||||
menuTop = top + el.scrollTop - 5 // 4px padding + 1px border
|
||||
menuLeft = left + width + 4
|
||||
// 处理边界情况
|
||||
if (menuTop + subMenuEl.offsetHeight > window.innerHeight) {
|
||||
menuTop = Math.max(0, window.innerHeight - subMenuEl.offsetHeight)
|
||||
}
|
||||
}
|
||||
else {
|
||||
menuTop = top + height + 3
|
||||
menuLeft = left
|
||||
menuLeft -= 5 // 4px padding + 1px border
|
||||
// 处理边界情况
|
||||
if (menuTop + subMenuEl.offsetHeight > window.innerHeight) {
|
||||
subMenuEl.style.height = `${window.innerHeight - menuTop}px`
|
||||
}
|
||||
}
|
||||
// 处理边界情况
|
||||
if (menuLeft + subMenuEl.offsetWidth > document.documentElement.clientWidth) {
|
||||
menuLeft = left - width
|
||||
}
|
||||
// 设置样式
|
||||
Object.assign(subMenuEl.style, {
|
||||
top: `${menuTop}px`,
|
||||
insetInlineStart: `${menuLeft}px`,
|
||||
willChange: 'transform',
|
||||
transform: 'translateZ(0)',
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
else {
|
||||
const path = props.menu.children ? rootMenu.subMenus[index].indexPath.at(-1)! : rootMenu.items[index].indexPath.at(-1)!
|
||||
rootMenu.openMenu(path, rootMenu.subMenus[path].indexPath)
|
||||
}
|
||||
}, 300))
|
||||
}
|
||||
|
||||
function handleMouseleave() {
|
||||
if (!rootMenu.isMenuPopup) {
|
||||
return
|
||||
}
|
||||
rootMenu.mouseInMenu = []
|
||||
timeout?.()
|
||||
;({ stop: timeout } = useTimeoutFn(() => {
|
||||
requestAnimationFrame(() => {
|
||||
if (rootMenu.mouseInMenu.length === 0) {
|
||||
rootMenu.closeMenu(props.uniqueKey)
|
||||
}
|
||||
else {
|
||||
if (hasChildren.value) {
|
||||
!rootMenu.mouseInMenu.includes(props.uniqueKey.at(-1)!) && rootMenu.closeMenu(props.uniqueKey.at(-1)!)
|
||||
}
|
||||
}
|
||||
})
|
||||
}, 300))
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Item ref="itemRef" :unique-key="uniqueKey" :item="menu" :level="level" :sub-menu="hasChildren" :expand @click="handleClick" @mouseenter="handleMouseenter" @mouseleave="handleMouseleave" />
|
||||
<template v-if="hasChildren">
|
||||
<Teleport to="body" :disabled="!rootMenu.isMenuPopup">
|
||||
<Transition v-bind="transitionClass" v-on="transitionEvent">
|
||||
<FaScrollArea
|
||||
v-if="expand" ref="subMenuRef" :scrollbar="false" :mask="rootMenu.isMenuPopup"
|
||||
:class="cn('sub-menu static h-[calc-size(auto,size)] rounded-lg', {
|
||||
'bg-[var(--g-sub-sidebar-bg)]': rootMenu.isMenuPopup,
|
||||
'border shadow-xl fixed z-3000 w-[200px]': rootMenu.isMenuPopup,
|
||||
'py-1 overscroll-contain': rootMenu.isMenuPopup,
|
||||
})"
|
||||
>
|
||||
<template v-for="item in menu.children" :key="item.path ?? rootMenu.getUseId(item)">
|
||||
<SubMenu v-if="item.meta?.menu !== false" :unique-key="[...uniqueKey, item.path ?? rootMenu.getUseId(item)]" :menu="item" :level="level + 1" />
|
||||
</template>
|
||||
</FaScrollArea>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
</template>
|
||||
@@ -0,0 +1,47 @@
|
||||
import type { MenuRecordRaw } from '@fantastic-admin/types'
|
||||
|
||||
export interface MenuItem {
|
||||
index: string
|
||||
indexPath: string[]
|
||||
active?: boolean
|
||||
}
|
||||
|
||||
export interface MenuProps {
|
||||
menu: MenuRecordRaw[]
|
||||
value: string
|
||||
accordion?: boolean
|
||||
defaultExpandPaths?: string[]
|
||||
mode?: 'horizontal' | 'vertical'
|
||||
collapse?: boolean
|
||||
}
|
||||
|
||||
export interface MenuInjection {
|
||||
props: MenuProps
|
||||
getUseId: (obj: object) => string
|
||||
items: Record<string, MenuItem>
|
||||
subMenus: Record<string, MenuItem>
|
||||
activeIndex: MenuProps['value']
|
||||
expandMenus: string[]
|
||||
mouseInMenu: string[]
|
||||
isMenuPopup: boolean
|
||||
openMenu: (index: string, indexPath: string[]) => void
|
||||
closeMenu: (index: string | string[]) => void
|
||||
handleMenuItemClick: (index: string) => void
|
||||
handleSubMenuClick: (index: string, indexPath: string[]) => void
|
||||
}
|
||||
|
||||
export const rootMenuInjectionKey = Symbol('rootMenu') as InjectionKey<MenuInjection>
|
||||
|
||||
export interface SubMenuProps {
|
||||
uniqueKey: string[]
|
||||
menu: MenuRecordRaw
|
||||
level?: number
|
||||
}
|
||||
|
||||
export interface SubMenuItemProps {
|
||||
uniqueKey: string[]
|
||||
item: MenuRecordRaw
|
||||
level?: number
|
||||
subMenu?: boolean
|
||||
expand?: boolean
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
<script setup lang="ts">
|
||||
import { useSlots } from '@/slots'
|
||||
import Logo from '../Logo/index.vue'
|
||||
import Menu from '../Menu/index.vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'SubSidebar',
|
||||
})
|
||||
|
||||
defineProps<{
|
||||
enable: boolean
|
||||
}>()
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appMenuStore = useAppMenuStore()
|
||||
|
||||
const isCollapse = computed(() => appSettingsStore.settings.menu.subMenuCollapse)
|
||||
|
||||
const transitionName = ref('')
|
||||
watch(() => appMenuStore.actived, (val, oldVal) => {
|
||||
if (appSettingsStore.mode === 'mobile' || appSettingsStore.settings.menu.mode === 'side') {
|
||||
if (val > oldVal) {
|
||||
transitionName.value = 'sub-sidebar-y-start'
|
||||
}
|
||||
else {
|
||||
transitionName.value = 'sub-sidebar-y-end'
|
||||
}
|
||||
}
|
||||
else if (appSettingsStore.settings.menu.mode === 'head') {
|
||||
if (val > oldVal) {
|
||||
transitionName.value = 'sub-sidebar-x-start'
|
||||
}
|
||||
else {
|
||||
transitionName.value = 'sub-sidebar-x-end'
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Transition name="sub-sidebar">
|
||||
<div
|
||||
v-if="enable" class="sub-sidebar-container" :class="{
|
||||
'is-collapse': isCollapse,
|
||||
}"
|
||||
>
|
||||
<Component :is="useSlots('sub-sidebar-top')" />
|
||||
<Logo
|
||||
v-if="['side', 'single'].includes(appSettingsStore.settings.menu.mode) || appSettingsStore.mode === 'mobile'" :show-logo="appSettingsStore.settings.menu.mode === 'single'" class="sidebar-logo" :class="{
|
||||
single: appSettingsStore.settings.menu.mode === 'single',
|
||||
}"
|
||||
/>
|
||||
<Component :is="useSlots('sub-sidebar-after-logo')" />
|
||||
<FaScrollArea :scrollbar="false" mask class="overscroll-contain flex-1">
|
||||
<TransitionGroup :name="transitionName">
|
||||
<template v-for="(mainItem, mainIndex) in appMenuStore.allMenus" :key="mainIndex">
|
||||
<div v-show="mainIndex === appMenuStore.actived">
|
||||
<Menu
|
||||
:menu="mainItem.children" :value="route.meta.activeMenu || route.path" :default-expand-paths="appMenuStore.defaultExpandPaths" :accordion="appSettingsStore.settings.menu.subMenuUniqueExpand" :collapse="isCollapse" class="menu" :class="{
|
||||
'-mt-2': !(isCollapse || ['head', 'single'].includes(appSettingsStore.settings.menu.mode)),
|
||||
}"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</TransitionGroup>
|
||||
</FaScrollArea>
|
||||
<div
|
||||
v-if="appSettingsStore.mode === 'pc' && appSettingsStore.settings.menu.subMenuCollapseButton" class="px-4 py-3 flex items-center relative" :class="{
|
||||
'justify-center': isCollapse,
|
||||
'justify-end': !isCollapse,
|
||||
}"
|
||||
>
|
||||
<FaButton variant="secondary" size="icon-sm" @click="appSettingsStore.toggleSidebarCollapse()">
|
||||
<FaIcon name="app-toolbar-collapse" class="size-4 transition" :class="{ 'rotate-z--180': appSettingsStore.settings.menu.subMenuCollapse }" />
|
||||
</FaButton>
|
||||
</div>
|
||||
<Component :is="useSlots('sub-sidebar-after-menu')" />
|
||||
<div v-if="appSettingsStore.settings.menu.mode === 'single'" class="px-4 pb-3 flex-center">
|
||||
<AppAccountButton :only-avatar="isCollapse" dropdown-align="center" :dropdown-side="isCollapse ? 'right' : 'top'" button-variant="secondary" :class="{ 'w-full': !isCollapse }" />
|
||||
</div>
|
||||
<Component :is="useSlots('sub-sidebar-bottom')" />
|
||||
</div>
|
||||
</Transition>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.sub-sidebar-container {
|
||||
position: absolute;
|
||||
inset-inline-start: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: var(--g-sub-sidebar-width);
|
||||
background-color: var(--g-sub-sidebar-bg);
|
||||
box-shadow: 1px 0 0 0 oklch(var(--border));
|
||||
transition: inset-inline-start 0.3s, width 0.3s, background-color 0.15s, box-shadow 0.15s;
|
||||
|
||||
&.is-collapse {
|
||||
width: var(--g-sub-sidebar-collapse-width);
|
||||
|
||||
.sidebar-logo {
|
||||
&:not(.single) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
:deep(span) {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.menu {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
/* 次侧边栏动画 */
|
||||
.sub-sidebar-x-start-enter-active,
|
||||
.sub-sidebar-x-end-enter-active,
|
||||
.sub-sidebar-y-start-enter-active,
|
||||
.sub-sidebar-y-end-enter-active {
|
||||
transition: 0.2s;
|
||||
}
|
||||
|
||||
.sub-sidebar-x-start-enter-from,
|
||||
.sub-sidebar-x-start-leave-active {
|
||||
opacity: 0;
|
||||
transform: translateX(30px);
|
||||
}
|
||||
|
||||
.sub-sidebar-x-end-enter-from,
|
||||
.sub-sidebar-x-end-leave-active {
|
||||
opacity: 0;
|
||||
transform: translateX(-30px);
|
||||
}
|
||||
|
||||
.sub-sidebar-y-start-enter-from,
|
||||
.sub-sidebar-y-start-leave-active {
|
||||
opacity: 0;
|
||||
transform: translateY(30px);
|
||||
}
|
||||
|
||||
.sub-sidebar-y-end-enter-from,
|
||||
.sub-sidebar-y-end-leave-active {
|
||||
opacity: 0;
|
||||
transform: translateY(-30px);
|
||||
}
|
||||
|
||||
.sub-sidebar-x-start-leave-active,
|
||||
.sub-sidebar-x-end-leave-active,
|
||||
.sub-sidebar-y-start-leave-active,
|
||||
.sub-sidebar-y-end-leave-active {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
/* 次侧边栏动画 */
|
||||
.sub-sidebar-enter-active,
|
||||
.sub-sidebar-leave-active {
|
||||
transition: 0.3s;
|
||||
}
|
||||
|
||||
.sub-sidebar-enter-from,
|
||||
.sub-sidebar-leave-to {
|
||||
transform: translateX(calc(var(--g-sub-sidebar-width) * -1));
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,437 @@
|
||||
<script setup lang="ts">
|
||||
import type { TabbarRecordRaw } from '@fantastic-admin/types'
|
||||
import { useMagicKeys } from '@vueuse/core'
|
||||
import { useHotkeyBindings } from '@/hotkeys'
|
||||
import { useSlots } from '@/slots'
|
||||
|
||||
defineOptions({
|
||||
name: 'Tabbar',
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appTabbarStore = useAppTabbarStore()
|
||||
|
||||
const tabbar = useAppTabbar()
|
||||
const mainPage = useAppPage()
|
||||
|
||||
const keys = useMagicKeys({ reactive: true })
|
||||
|
||||
const { generateTitle } = useAppMenu()
|
||||
|
||||
const activedTabId = computed(() => tabbar.getId())
|
||||
|
||||
const tabsRef = useTemplateRef('tabsRef')
|
||||
const tabContainerRef = useTemplateRef('tabContainerRef')
|
||||
const tabRef = useTemplateRef<HTMLElement[]>('tabRef')
|
||||
|
||||
const isAnimating = ref(false)
|
||||
const isInit = ref(true)
|
||||
|
||||
function onBeforeLeave(el: Element) {
|
||||
isAnimating.value = true
|
||||
const htmlEl = el as HTMLElement
|
||||
htmlEl.style.left = `${htmlEl.offsetLeft}px`
|
||||
htmlEl.style.top = `${htmlEl.offsetTop}px`
|
||||
htmlEl.style.width = `${htmlEl.offsetWidth}px`
|
||||
}
|
||||
onMounted(() => {
|
||||
nextTick(() => {
|
||||
isInit.value = false
|
||||
})
|
||||
})
|
||||
|
||||
watch(() => route, (val) => {
|
||||
if (appSettingsStore.settings.topbar.tabbar) {
|
||||
appTabbarStore.add(val)
|
||||
nextTick(() => {
|
||||
const index = appTabbarStore.list.findIndex(item => item.tabId === activedTabId.value)
|
||||
if (index !== -1) {
|
||||
const tabEl = tabRef.value?.find(item => Number.parseInt(item.dataset.index!) === index)
|
||||
const containerEl = tabsRef.value?.ref?.$el
|
||||
if (tabEl && containerEl) {
|
||||
const tabLeft = tabEl.offsetLeft
|
||||
const tabWidth = tabEl.offsetWidth
|
||||
const containerWidth = containerEl.clientWidth
|
||||
// 计算滚动位置,使标签页居中
|
||||
const scrollLeft = tabLeft - (containerWidth - tabWidth) / 2
|
||||
// 首次加载时直接定位到指定位置
|
||||
tabsRef.value?.scrollTo(scrollLeft, !isInit.value ? 'smooth' : undefined)
|
||||
}
|
||||
tabbarScrollTip()
|
||||
}
|
||||
})
|
||||
}
|
||||
}, {
|
||||
immediate: true,
|
||||
deep: true,
|
||||
})
|
||||
|
||||
function tabbarScrollTip() {
|
||||
if (tabContainerRef.value?.$el.clientWidth > (tabsRef.value?.ref?.$el.clientWidth ?? 0) && !localStorage.has('tabbarScrollTip')) {
|
||||
localStorage.setItem('tabbarScrollTip', '')
|
||||
const tips = useFaToast().info('温馨提示', {
|
||||
description: '标签栏数量超过展示区域范围,可以将鼠标移到标签栏上,通过鼠标滚轮滑动浏览',
|
||||
position: 'top-center',
|
||||
duration: Infinity,
|
||||
action: {
|
||||
label: '知道了',
|
||||
onClick: () => useFaToast().dismiss(tips),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
function contextMenuItems(routeItem: TabbarRecordRaw) {
|
||||
return [
|
||||
[
|
||||
{
|
||||
label: '重新加载',
|
||||
icon: 'i-ri:refresh-line',
|
||||
disabled: routeItem.tabId !== activedTabId.value,
|
||||
handle: () => mainPage.reload(),
|
||||
},
|
||||
{
|
||||
label: '关闭标签页',
|
||||
icon: 'i-ri:close-line',
|
||||
disabled: !tabbar.checkClose(routeItem.tabId),
|
||||
handle: () => tabbar.closeById(routeItem.tabId),
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
label: '关闭其它标签页',
|
||||
icon: 'i-mdi:close',
|
||||
disabled: !tabbar.checkCloseOtherSide(routeItem.tabId),
|
||||
handle: () => {
|
||||
tabbar.closeOtherSide(routeItem.tabId)
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '关闭左侧标签页',
|
||||
icon: 'i-mdi:arrow-expand-left',
|
||||
disabled: !tabbar.checkCloseLeftSide(routeItem.tabId),
|
||||
handle: () => {
|
||||
tabbar.closeLeftSide(routeItem.tabId)
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '关闭右侧标签页',
|
||||
icon: 'i-mdi:arrow-expand-right',
|
||||
disabled: !tabbar.checkCloseRightSide(routeItem.tabId),
|
||||
handle: () => {
|
||||
tabbar.closeRightSide(routeItem.tabId)
|
||||
},
|
||||
},
|
||||
],
|
||||
]
|
||||
}
|
||||
|
||||
function iconName(icon: TabbarRecordRaw['icon']) {
|
||||
return icon
|
||||
}
|
||||
|
||||
const visibleTabIndex = ref<number[]>([])
|
||||
function getVisibleTabs() {
|
||||
const containerWidth = tabsRef.value?.ref?.$el.clientWidth ?? 0
|
||||
const scrollLeft = tabsRef.value?.ref?.el?.viewportElement?.scrollLeft ?? 0
|
||||
visibleTabIndex.value = []
|
||||
if (tabRef.value) {
|
||||
for (let i = 0; i < tabRef.value.length; i++) {
|
||||
const tab = tabRef.value[i]
|
||||
const tabLeft = tab.offsetLeft
|
||||
const tabRight = tabLeft + tab.offsetWidth
|
||||
// 检查标签页是否在可视区域内
|
||||
if (tabLeft < scrollLeft + containerWidth && tabRight > scrollLeft) {
|
||||
if (i >= 0 && i < appTabbarStore.list.length) {
|
||||
visibleTabIndex.value.push(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function getVisibleTabIndex(arrayIndex: number) {
|
||||
return visibleTabIndex.value.findIndex(visibleTab => visibleTab === arrayIndex) ?? -1
|
||||
}
|
||||
|
||||
useHotkeyBindings({
|
||||
'tabbar.prev': () => {
|
||||
if (appTabbarStore.list[0]?.tabId !== activedTabId.value) {
|
||||
const index = appTabbarStore.list.findIndex(item => item.tabId === activedTabId.value)
|
||||
index > 0 && router.push(appTabbarStore.list[index - 1].fullPath)
|
||||
}
|
||||
},
|
||||
'tabbar.next': () => {
|
||||
if (appTabbarStore.list.at(-1)?.tabId !== activedTabId.value) {
|
||||
const index = appTabbarStore.list.findIndex(item => item.tabId === activedTabId.value)
|
||||
index >= 0 && router.push(appTabbarStore.list[index + 1].fullPath)
|
||||
}
|
||||
},
|
||||
'tabbar.closeCurrent': () => {
|
||||
tabbar.closeById(activedTabId.value)
|
||||
},
|
||||
'tabbar.gotoVisibleIndex': ({ hotkey }) => {
|
||||
const number = Number(hotkey.split('+')[1])
|
||||
if (visibleTabIndex.value[number - 1] !== undefined) {
|
||||
router.push(appTabbarStore.list[visibleTabIndex.value[number - 1]].fullPath)
|
||||
}
|
||||
},
|
||||
'tabbar.gotoLast': () => {
|
||||
const last = appTabbarStore.list.at(-1)
|
||||
last && router.push(last.fullPath)
|
||||
},
|
||||
})
|
||||
|
||||
watch(() => keys.alt, (val) => {
|
||||
if (val) {
|
||||
getVisibleTabs()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="tabbar">
|
||||
<Component :is="useSlots('tabbar-start')" />
|
||||
<div class="tabbar-container">
|
||||
<FaScrollArea
|
||||
ref="tabsRef" :scrollbar="false" mask horizontal class="tabs overscroll-contain"
|
||||
>
|
||||
<TransitionGroup ref="tabContainerRef" :name="!isInit ? 'tabbar' : undefined" tag="div" class="tab-container" @before-leave="onBeforeLeave" @after-leave="isAnimating = false">
|
||||
<div
|
||||
v-for="(element, index) in appTabbarStore.list" :key="element.tabId"
|
||||
ref="tabRef" :data-index="index" class="tab" :class="{
|
||||
actived: element.tabId === activedTabId,
|
||||
}" @click="!isAnimating && element.tabId !== activedTabId && router.push(element.fullPath)"
|
||||
>
|
||||
<FaContextMenu :items="contextMenuItems(element)">
|
||||
<div class="size-full">
|
||||
<div class="tab-dividers" />
|
||||
<div class="tab-background" />
|
||||
<FaTooltip :delay="1000" side="bottom">
|
||||
<div class="tab-content">
|
||||
<div :key="element.tabId" class="title">
|
||||
<FaIcon v-if="appSettingsStore.settings.tabbar.icon && iconName(element.icon)" :name="iconName(element.icon)!" class="icon" />
|
||||
{{ generateTitle(element.title) }}
|
||||
</div>
|
||||
<div v-if="appTabbarStore.list.length > 1" class="action-icon" @click.stop="tabbar.closeById(element.tabId)">
|
||||
<FaIcon name="i-ri:close-fill" />
|
||||
</div>
|
||||
<div v-show="appSettingsStore.settings.tabbar.hotkeys && keys.alt && getVisibleTabIndex(index) >= 0 && getVisibleTabIndex(index) < 9" class="hotkey-number">
|
||||
{{ getVisibleTabIndex(index) + 1 }}
|
||||
</div>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="text-sm">
|
||||
{{ generateTitle(element.title) }}
|
||||
</div>
|
||||
<div class="text-accent/50">
|
||||
{{ element.fullPath }}
|
||||
</div>
|
||||
</template>
|
||||
</FaTooltip>
|
||||
</div>
|
||||
</FaContextMenu>
|
||||
</div>
|
||||
</TransitionGroup>
|
||||
</FaScrollArea>
|
||||
</div>
|
||||
<Component :is="useSlots('tabbar-end')" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.tabbar {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: var(--g-tabbar-height);
|
||||
background-color: var(--g-tabbar-bg);
|
||||
box-shadow: 0 1px 0 0 oklch(var(--border)), 0 -1px 0 0 oklch(var(--border));
|
||||
|
||||
.tabbar-container {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
height: 100%;
|
||||
|
||||
.tabs {
|
||||
flex: 1;
|
||||
align-items: end;
|
||||
white-space: nowrap;
|
||||
|
||||
.tab-container {
|
||||
position: relative;
|
||||
|
||||
.tab {
|
||||
&:not(.actived):hover {
|
||||
z-index: 3;
|
||||
|
||||
&::before,
|
||||
&::after {
|
||||
content: none;
|
||||
}
|
||||
|
||||
& + .tab .tab-dividers::before {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
.title,
|
||||
.action-icon {
|
||||
color: var(--g-tabbar-tab-hover-color);
|
||||
}
|
||||
}
|
||||
|
||||
.tab-background {
|
||||
background-color: var(--g-tabbar-tab-hover-bg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tab {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
min-width: 150px;
|
||||
max-width: 150px;
|
||||
height: var(--g-tabbar-height);
|
||||
font-size: 14px;
|
||||
line-height: calc(var(--g-tabbar-height) - 2px);
|
||||
vertical-align: bottom;
|
||||
pointer-events: none;
|
||||
cursor: pointer;
|
||||
|
||||
* {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
& + .tab:hover,
|
||||
& + .tab.actived {
|
||||
.tab-dividers::before {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.actived {
|
||||
z-index: 5;
|
||||
|
||||
&::before,
|
||||
&::after {
|
||||
content: none;
|
||||
}
|
||||
|
||||
& + .tab .tab-dividers::before {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
.title,
|
||||
.action-icon {
|
||||
color: var(--g-tabbar-tab-active-color);
|
||||
}
|
||||
}
|
||||
|
||||
.tab-background {
|
||||
background-color: var(--g-tabbar-tab-active-bg);
|
||||
}
|
||||
}
|
||||
|
||||
.tab-dividers {
|
||||
position: absolute;
|
||||
inset-inline: -1px;
|
||||
top: 50%;
|
||||
z-index: 0;
|
||||
height: 14px;
|
||||
transform: translateY(-50%);
|
||||
|
||||
&::before {
|
||||
position: absolute;
|
||||
inset-inline-start: 1px;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
display: block;
|
||||
width: 1px;
|
||||
content: "";
|
||||
background-color: oklch(var(--border));
|
||||
opacity: 1;
|
||||
transition: opacity 0.3s, background-color 0.15s;
|
||||
}
|
||||
}
|
||||
|
||||
&:first-child .tab-dividers::before {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.tab-background {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
transition: background-color 0.15s;
|
||||
}
|
||||
|
||||
.tab-content {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: all;
|
||||
|
||||
.title {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
gap: 5px;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
padding: 0 10px;
|
||||
margin-inline-end: 10px;
|
||||
overflow: hidden;
|
||||
color: var(--g-tabbar-tab-color);
|
||||
white-space: nowrap;
|
||||
mask-image: linear-gradient(to right, #000 calc(100% - 20px), transparent);
|
||||
transition: margin-inline-end 0.3s;
|
||||
|
||||
&:has(+ .action-icon) {
|
||||
margin-inline-end: 28px;
|
||||
}
|
||||
|
||||
.icon {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.action-icon {
|
||||
--uno: transition absolute inset-e-2 top-1/2 -translate-y-1/2 rounded-full z-10 w-5 h-5 flex-center text-xs "text-[var(--g-tabbar-tab-color)]" hover:(border bg-secondary);
|
||||
}
|
||||
|
||||
.hotkey-number {
|
||||
--uno: border bg-secondary absolute inset-e-2 top-1/2 -translate-y-1/2 rounded-full z-10 w-5 h-5 flex-center text-xs "text-[var(--g-tabbar-tab-color)]";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 标签栏动画 */
|
||||
.tabs {
|
||||
.tabbar-move,
|
||||
.tabbar-enter-active,
|
||||
.tabbar-leave-active {
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.tabbar-enter-from,
|
||||
.tabbar-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(30px);
|
||||
}
|
||||
|
||||
.tabbar-leave-active {
|
||||
position: absolute !important;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
<script setup lang="ts">
|
||||
import { compile } from 'path-to-regexp'
|
||||
import Breadcrumb from '../../../Breadcrumb/index.vue'
|
||||
import BreadcrumbItem from '../../../Breadcrumb/item.vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'ToolbarBreadcrumb',
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
|
||||
const { generateTitle } = useAppMenu()
|
||||
|
||||
interface BreadcrumbRecord {
|
||||
path: string
|
||||
title?: string | (() => string)
|
||||
}
|
||||
|
||||
let breadcrumbListBackup: BreadcrumbRecord[] = []
|
||||
const breadcrumbList = computed<BreadcrumbRecord[]>(() => {
|
||||
if (route.name === 'reload') {
|
||||
return breadcrumbListBackup
|
||||
}
|
||||
const list: BreadcrumbRecord[] = []
|
||||
if (appSettingsStore.settings.app.home.enable) {
|
||||
list.push({
|
||||
path: appSettingsStore.settings.app.home.fullPath,
|
||||
title: appSettingsStore.settings.app.home.title,
|
||||
})
|
||||
}
|
||||
route.matched.forEach((item) => {
|
||||
if (item.meta?.breadcrumb !== false) {
|
||||
list.push({
|
||||
path: item.path,
|
||||
title: item.meta?.title,
|
||||
})
|
||||
}
|
||||
})
|
||||
breadcrumbListBackup = list.filter(item => generateTitle(item.title))
|
||||
return breadcrumbListBackup
|
||||
})
|
||||
|
||||
function pathCompile(path: string) {
|
||||
const toPath = compile(path)
|
||||
return toPath(route.params)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Breadcrumb v-if="appSettingsStore.mode === 'pc'" class="breadcrumb px-2 whitespace-nowrap">
|
||||
<TransitionGroup name="breadcrumb">
|
||||
<BreadcrumbItem v-for="(item, index) in breadcrumbList" :key="`${index}_${item.path}_${item.title}`" :to="index < breadcrumbList.length - 1 && item.path !== '' ? pathCompile(item.path) : ''">
|
||||
{{ generateTitle(item.title) }}
|
||||
</BreadcrumbItem>
|
||||
</TransitionGroup>
|
||||
</Breadcrumb>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 面包屑动画 */
|
||||
.breadcrumb-enter-active {
|
||||
transition: transform 0.3s, opacity 0.3s;
|
||||
}
|
||||
|
||||
.breadcrumb-enter-from {
|
||||
opacity: 0;
|
||||
transform: translateX(30px) skewX(-50deg);
|
||||
}
|
||||
</style>
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<script setup lang="ts">
|
||||
defineOptions({
|
||||
name: 'ToolbarColorScheme',
|
||||
})
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
|
||||
function toggleColorScheme(event: MouseEvent) {
|
||||
if (!document.startViewTransition || window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
|
||||
appSettingsStore.currentColorScheme && appSettingsStore.setColorScheme(appSettingsStore.currentColorScheme === 'dark' ? 'light' : 'dark')
|
||||
return
|
||||
}
|
||||
const target = event.target as HTMLElement
|
||||
const { left, top, width, height } = target.getBoundingClientRect()
|
||||
const x = left + width / 2
|
||||
const y = top + height / 2
|
||||
const endRadius = Math.hypot(
|
||||
Math.max(x, innerWidth - x),
|
||||
Math.max(y, innerHeight - y),
|
||||
)
|
||||
const ratioX = (100 * x) / innerWidth
|
||||
const ratioY = (100 * y) / innerHeight
|
||||
const referR = Math.hypot(innerWidth, innerHeight) / Math.SQRT2
|
||||
const ratioR = (100 * endRadius) / referR
|
||||
const transition = document.startViewTransition(async () => {
|
||||
appSettingsStore.currentColorScheme && appSettingsStore.setColorScheme(appSettingsStore.currentColorScheme === 'dark' ? 'light' : 'dark')
|
||||
await nextTick()
|
||||
})
|
||||
transition.ready.then(() => {
|
||||
const clipPath = [
|
||||
`circle(0% at ${ratioX}% ${ratioY}%)`,
|
||||
`circle(${ratioR}% at ${ratioX}% ${ratioY}%)`,
|
||||
]
|
||||
document.documentElement.animate(
|
||||
{
|
||||
clipPath: appSettingsStore.currentColorScheme === 'light' ? clipPath : clipPath.toReversed(),
|
||||
},
|
||||
{
|
||||
duration: 500,
|
||||
easing: 'ease-in-out',
|
||||
fill: 'both',
|
||||
pseudoElement: appSettingsStore.currentColorScheme === 'light' ? '::view-transition-new(root)' : '::view-transition-old(root)',
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FaButton variant="ghost" size="icon-sm" @click="toggleColorScheme">
|
||||
<FaIcon
|
||||
:name="{
|
||||
light: 'i-ri:sun-line',
|
||||
dark: 'i-ri:moon-line',
|
||||
}[appSettingsStore.currentColorScheme!]" class="size-4"
|
||||
/>
|
||||
</FaButton>
|
||||
</template>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { useFullscreen } from '@vueuse/core'
|
||||
|
||||
defineOptions({
|
||||
name: 'ToolbarFullscreen',
|
||||
})
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
|
||||
const { isFullscreen, toggle } = useFullscreen()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FaButton v-if="appSettingsStore.mode === 'pc'" variant="ghost" size="icon-sm" @click="toggle">
|
||||
<FaIcon :name="isFullscreen ? 'i-ri:fullscreen-exit-line' : 'i-ri:fullscreen-line'" class="size-4" />
|
||||
</FaButton>
|
||||
</template>
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import { useHotkeyBindings } from '@/hotkeys'
|
||||
import Search from './search.vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'ToolbarMenuSearch',
|
||||
})
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
|
||||
const isShow = ref(false)
|
||||
|
||||
const useMobileStyle = computed(() => {
|
||||
return appSettingsStore.mode !== 'pc' || !appSettingsStore.settings.toolbar.menuSearch.hotkeys
|
||||
})
|
||||
|
||||
useHotkeyBindings({
|
||||
'menuSearch.open': () => {
|
||||
isShow.value = true
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FaButton :variant="useMobileStyle ? 'ghost' : 'outline'" :size="useMobileStyle ? 'icon-sm' : undefined" :class="{ 'mx-2 px-3 h-9': !useMobileStyle }" @click="isShow = true">
|
||||
<FaIcon name="i-ri:search-line" class="size-4" />
|
||||
<template v-if="!useMobileStyle">
|
||||
<FaKbdGroup v-if="appSettingsStore.settings.toolbar.menuSearch.hotkeys" class="-me-1">
|
||||
<FaKbd>{{ appSettingsStore.os === 'mac' ? '⌘' : 'Ctrl' }}</FaKbd>
|
||||
<FaKbd>K</FaKbd>
|
||||
</FaKbdGroup>
|
||||
</template>
|
||||
</FaButton>
|
||||
<Search v-model="isShow" />
|
||||
</template>
|
||||
+256
@@ -0,0 +1,256 @@
|
||||
<script setup lang="ts">
|
||||
import type { MenuRecordRaw } from '@fantastic-admin/types'
|
||||
import { match } from 'pinyin-pro'
|
||||
import { useHotkeyBindings } from '@/hotkeys'
|
||||
import Breadcrumb from '@/layouts/components/Breadcrumb/index.vue'
|
||||
import BreadcrumbItem from '@/layouts/components/Breadcrumb/item.vue'
|
||||
import { resolveRoutePath } from '@/utils'
|
||||
|
||||
defineOptions({
|
||||
name: 'ToolbarMenuSearchModal',
|
||||
})
|
||||
|
||||
const isShow = defineModel<boolean>({
|
||||
default: false,
|
||||
})
|
||||
|
||||
const router = useRouter()
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appRouteStore = useAppRouteStore()
|
||||
const appMenuStore = useAppMenuStore()
|
||||
|
||||
const { generateTitle } = useAppMenu()
|
||||
|
||||
interface listTypes {
|
||||
path: string
|
||||
icon?: string
|
||||
title?: string | (() => string)
|
||||
link?: string
|
||||
}
|
||||
|
||||
const searchInput = ref('')
|
||||
const sourceList = ref<listTypes[]>([])
|
||||
const actived = ref(0)
|
||||
|
||||
const searchResultRef = useTemplateRef('searchResultRef')
|
||||
const searchResultItemRef = useTemplateRef<HTMLElement[]>('searchResultItemRef')
|
||||
|
||||
const resultList = computed(() => {
|
||||
let result = []
|
||||
result = sourceList.value.filter((item) => {
|
||||
let flag = false
|
||||
if (searchInput.value !== '') {
|
||||
if (item.path.includes(searchInput.value)) {
|
||||
flag = true
|
||||
}
|
||||
if (
|
||||
generateTitle(item.title).toString().includes(searchInput.value)
|
||||
|| (match(generateTitle(item.title).toString(), searchInput.value, { continuous: true })?.length ?? 0) > 0
|
||||
) {
|
||||
flag = true
|
||||
}
|
||||
if (appRouteStore.getRouteMatchedByPath(item.path).some((b) => {
|
||||
return generateTitle(b.meta?.title).toString().includes(searchInput.value)
|
||||
|| (match(generateTitle(b.meta?.title).toString(), searchInput.value, { continuous: true })?.length ?? 0) > 0
|
||||
})) { flag = true }
|
||||
}
|
||||
return flag
|
||||
})
|
||||
return result
|
||||
})
|
||||
|
||||
useHotkeyBindings({
|
||||
'menuSearch.moveUp': () => {
|
||||
keyUp()
|
||||
},
|
||||
'menuSearch.moveDown': () => {
|
||||
keyDown()
|
||||
},
|
||||
'menuSearch.confirm': () => {
|
||||
keyEnter()
|
||||
},
|
||||
'menuSearch.close': () => {
|
||||
isShow.value = false
|
||||
},
|
||||
}, () => isShow.value)
|
||||
|
||||
watch(() => isShow.value, (val) => {
|
||||
if (val) {
|
||||
searchInput.value = ''
|
||||
actived.value = 0
|
||||
}
|
||||
})
|
||||
watch(() => resultList.value, () => {
|
||||
actived.value = 0
|
||||
handleScroll()
|
||||
})
|
||||
watch(() => actived.value, () => {
|
||||
handleScroll()
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
initSourceList()
|
||||
})
|
||||
|
||||
function initSourceList() {
|
||||
sourceList.value = []
|
||||
appMenuStore.allMenus.forEach((item) => {
|
||||
getSourceList(item.children)
|
||||
})
|
||||
}
|
||||
|
||||
function hasChildren(item: MenuRecordRaw) {
|
||||
let flag = true
|
||||
if (item.children?.every(i => i.meta?.menu === false)) {
|
||||
flag = false
|
||||
}
|
||||
return flag
|
||||
}
|
||||
function getSourceList(arr: MenuRecordRaw[], basePath?: string, icon?: string) {
|
||||
arr.forEach((item) => {
|
||||
if (item.meta?.menu !== false) {
|
||||
if (item.children && hasChildren(item)) {
|
||||
getSourceList(
|
||||
item.children,
|
||||
resolveRoutePath(basePath, item.path),
|
||||
item.meta?.icon ?? icon,
|
||||
)
|
||||
}
|
||||
else {
|
||||
sourceList.value.push({
|
||||
path: resolveRoutePath(basePath, item.path),
|
||||
icon: item.meta?.icon ?? icon,
|
||||
title: item.meta?.title,
|
||||
link: item.meta?.link,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function keyUp() {
|
||||
if (resultList.value.length) {
|
||||
actived.value -= 1
|
||||
if (actived.value < 0) {
|
||||
actived.value = resultList.value.length - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
function keyDown() {
|
||||
if (resultList.value.length) {
|
||||
actived.value += 1
|
||||
if (actived.value > resultList.value.length - 1) {
|
||||
actived.value = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
function keyEnter() {
|
||||
searchResultItemRef.value?.find(item => Number.parseInt(item.dataset.index!) === actived.value)?.click()
|
||||
}
|
||||
function handleScroll() {
|
||||
if (searchResultRef.value?.ref?.el?.viewportElement) {
|
||||
const contentDom = searchResultRef.value.ref.el.viewportElement
|
||||
let scrollTo = 0
|
||||
if (resultList.value.length > 0) {
|
||||
scrollTo = contentDom.scrollTop
|
||||
const activedOffsetTop = searchResultItemRef.value?.find(item => Number.parseInt(item.dataset.index!) === actived.value)?.offsetTop ?? 0
|
||||
const activedClientHeight = searchResultItemRef.value?.find(item => Number.parseInt(item.dataset.index!) === actived.value)?.clientHeight ?? 0
|
||||
const searchScrollTop = contentDom.scrollTop
|
||||
const searchClientHeight = contentDom.clientHeight
|
||||
if (activedOffsetTop + activedClientHeight > searchScrollTop + searchClientHeight) {
|
||||
scrollTo = activedOffsetTop + activedClientHeight - searchClientHeight
|
||||
}
|
||||
else if (activedOffsetTop <= searchScrollTop) {
|
||||
scrollTo = activedOffsetTop - 16
|
||||
}
|
||||
}
|
||||
contentDom.scrollTo({
|
||||
top: scrollTo,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function pageJump(path: listTypes['path'], link: listTypes['link']) {
|
||||
if (link) {
|
||||
window.open(link, '_blank')
|
||||
}
|
||||
else {
|
||||
router.push(path)
|
||||
}
|
||||
isShow.value = false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FaModal v-model="isShow" :footer="appSettingsStore.mode === 'pc'" :closable="false" open-auto-focus border class="w-full lg-max-w-2xl" content-class="flex flex-col p-0 min-h-auto" header-class="p-0" footer-class="p-0">
|
||||
<template #header>
|
||||
<div class="flex flex-shrink-0 h-12 items-center">
|
||||
<div class="flex-center h-full w-14">
|
||||
<FaIcon name="i-ri:search-line" class="text-foreground/30 size-4" />
|
||||
</div>
|
||||
<input v-model="searchInput" placeholder="支持标题、拼音(首字母)、URL模糊查询" class="text-base text-foreground border-0 rounded-md bg-transparent h-full w-full focus-outline-none placeholder-foreground/30" @keydown.esc.prevent="isShow = false" @keydown.up.prevent="keyUp" @keydown.down.prevent="keyDown" @keydown.enter.prevent="keyEnter">
|
||||
<div v-if="appSettingsStore.mode === 'mobile'" class="border-s flex-center h-full w-14">
|
||||
<FaIcon name="i-carbon:close" class="size-4" @click="isShow = false" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #footer>
|
||||
<div class="px-4 py-3 flex w-full justify-between">
|
||||
<div class="flex gap-8">
|
||||
<div class="text-xs inline-flex gap-1 items-center">
|
||||
<FaKbd>⏎</FaKbd>
|
||||
<span>访问</span>
|
||||
</div>
|
||||
<div class="text-xs inline-flex gap-1 items-center">
|
||||
<FaKbd>
|
||||
<FaIcon name="i-ant-design:caret-up-filled" />
|
||||
</FaKbd>
|
||||
<FaKbd>
|
||||
<FaIcon name="i-ant-design:caret-down-filled" />
|
||||
</FaKbd>
|
||||
<span>切换</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="appSettingsStore.settings.toolbar.menuSearch.hotkeys" class="text-xs inline-flex gap-1 items-center">
|
||||
<FaKbd>Esc</FaKbd>
|
||||
<span>退出</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<FaScrollArea ref="searchResultRef">
|
||||
<template v-if="resultList.length > 0">
|
||||
<div v-for="(item, index) in resultList" ref="searchResultItemRef" :key="item.path" class="p-4" :data-index="index" @click="pageJump(item.path, item.link)" @mouseover="actived = index">
|
||||
<a class="border rounded-lg flex cursor-pointer items-center" :class="{ '-mt-4': index !== 0, 'bg-accent border-primary shadow-[0_0_0_1px_oklch(var(--primary))]': index === actived, 'op-50': index !== actived }">
|
||||
<div class="flex-center basis-16 -me-4">
|
||||
<FaIcon v-if="item.icon" :name="item.icon" class="size-5 transition" :class="{ 'scale-120 text-primary': index === actived }" />
|
||||
</div>
|
||||
<div class="px-4 py-3 flex flex-1 flex-col gap-1 truncate">
|
||||
<div class="text-base font-bold text-start truncate">{{ generateTitle(item.title) }}</div>
|
||||
<Breadcrumb v-if="appRouteStore.getRouteMatchedByPath(item.path).length" class="truncate">
|
||||
<BreadcrumbItem v-for="(bc, bcIndex) in appRouteStore.getRouteMatchedByPath(item.path)" :key="bcIndex" class="text-xs">
|
||||
{{ generateTitle(bc.meta?.title) }}
|
||||
</BreadcrumbItem>
|
||||
</Breadcrumb>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="searchInput === ''">
|
||||
<div class="text-secondary-foreground/50 py-6 flex-col-center h-full">
|
||||
<FaIcon name="i-tabler:mood-smile" class="size-10" />
|
||||
<p class="text-base m-2">
|
||||
输入你要搜索的导航
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="text-secondary-foreground/50 py-6 flex-col-center h-full">
|
||||
<FaIcon name="i-tabler:mood-empty" class="size-10" />
|
||||
<p class="text-base m-2">
|
||||
没有找到你想要的
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
</FaScrollArea>
|
||||
</FaModal>
|
||||
</template>
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<script setup lang="ts">
|
||||
defineOptions({
|
||||
name: 'ToolbarPageReload',
|
||||
})
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const mainPage = useAppPage()
|
||||
|
||||
const isAnimating = ref(false)
|
||||
|
||||
function handleClick(event: MouseEvent) {
|
||||
if (event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey) {
|
||||
location.reload()
|
||||
return
|
||||
}
|
||||
if (!event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey) {
|
||||
isAnimating.value = true
|
||||
mainPage.reload()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FaTooltip side="bottom" :disabled="appSettingsStore.os === 'mac'">
|
||||
<template #content>
|
||||
<div class="flex-col-center gap-2">
|
||||
<p class="flex-center gap-1">
|
||||
按住 <FaKbd>Ctrl</FaKbd> 键并点击
|
||||
</p>
|
||||
<p>可切换为浏览器原生刷新</p>
|
||||
</div>
|
||||
</template>
|
||||
<FaButton variant="ghost" size="icon-sm" @click="handleClick" @animationend="isAnimating = false">
|
||||
<FaIcon name="i-iconoir:refresh-double" class="size-4" :class="{ animation: isAnimating }" />
|
||||
</FaButton>
|
||||
</FaTooltip>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.animation {
|
||||
animation: animation 1s;
|
||||
}
|
||||
|
||||
@keyframes animation {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { useSlots } from '@/slots'
|
||||
import Tools from './tools.vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'ToolbarRightSide',
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center">
|
||||
<Tools mode="right-side" />
|
||||
<Component :is="useSlots('toolbar-end')" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,25 @@
|
||||
<script setup lang="ts">
|
||||
import EndSide from './endSide.vue'
|
||||
import StartSide from './startSide.vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'Toolbar',
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="bg-[var(--g-toolbar-bg)] flex h-[var(--g-toolbar-height)] items-center justify-between">
|
||||
<div class="start-side pe-16 ps-2 flex h-full items-center of-hidden">
|
||||
<StartSide />
|
||||
</div>
|
||||
<div class="px-2 flex flex-shrink-0 h-full items-center justify-end">
|
||||
<EndSide />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.start-side {
|
||||
mask-image: linear-gradient(to right, #000 0%, #000 calc(100% - 50px), transparent);
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import { useSlots } from '@/slots'
|
||||
import Tools from './tools.vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'ToolbarLeftSide',
|
||||
})
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center">
|
||||
<FaButton v-if="appSettingsStore.mode === 'mobile'" variant="ghost" size="icon" class="size-9" @click="appSettingsStore.toggleSidebarCollapse()">
|
||||
<FaIcon name="app-toolbar-collapse" class="size-4" />
|
||||
</FaButton>
|
||||
<Component :is="useSlots('toolbar-start')" />
|
||||
<Tools mode="left-side" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,39 @@
|
||||
<script setup lang="ts">
|
||||
import type { ToolbarSettings } from '@fantastic-admin/settings'
|
||||
import { pascalCase } from 'scule'
|
||||
|
||||
defineOptions({
|
||||
name: 'ToolbarTools',
|
||||
})
|
||||
|
||||
const props = defineProps<{
|
||||
mode: 'left-side' | 'right-side'
|
||||
}>()
|
||||
|
||||
const modules = import.meta.glob('./*/index.vue', { import: 'default', eager: true })
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
|
||||
const toolbarTools = {
|
||||
'left-side': ['breadcrumb'],
|
||||
'right-side': ['menuSearch', 'fullscreen', 'pageReload', 'colorScheme'],
|
||||
} satisfies Record<typeof props.mode, (keyof ToolbarSettings)[]>
|
||||
|
||||
const tools = computed(() => toolbarTools[props.mode])
|
||||
|
||||
function checkVisible(item: boolean | { enable: boolean }) {
|
||||
if (typeof item === 'boolean') {
|
||||
return item
|
||||
}
|
||||
else if (typeof item === 'object' && item !== null) {
|
||||
return item.enable ?? false
|
||||
}
|
||||
return false
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-for="item in tools" :key="item">
|
||||
<Component :is="modules[`./${pascalCase(item)}/index.vue`]" v-if="checkVisible(appSettingsStore.settings.toolbar[item])" />
|
||||
</template>
|
||||
</template>
|
||||
@@ -0,0 +1,56 @@
|
||||
<script setup lang="ts">
|
||||
import { useElementSize, useScroll } from '@vueuse/core'
|
||||
import eventBus from '@/utils/eventBus'
|
||||
import Tabbar from './Tabbar/index.vue'
|
||||
import Toolbar from './Toolbar/index.vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'Topbar',
|
||||
})
|
||||
|
||||
defineProps<{
|
||||
enable: boolean
|
||||
enableTabbar: boolean
|
||||
enableToolbar: boolean
|
||||
}>()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
|
||||
const { height: topbarHeight } = useElementSize(useTemplateRef('topbarRef'))
|
||||
const { y } = useScroll(window)
|
||||
const scrollOnHide = ref(false)
|
||||
|
||||
watch(y, (val, oldVal) => {
|
||||
scrollOnHide.value = appSettingsStore.settings.topbar.mode === 'sticky' && val > (oldVal ?? 0) && val > topbarHeight.value
|
||||
})
|
||||
|
||||
watch(scrollOnHide, (val) => {
|
||||
eventBus.emit('topbar-scroll-visible-or-hidden', val)
|
||||
}, {
|
||||
immediate: true,
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Transition name="topbar">
|
||||
<div
|
||||
v-if="enable" ref="topbarRef" class="flex flex-col w-full shadow-[0_1px_0_0_oklch(var(--border))] transition-transform-300"
|
||||
>
|
||||
<Tabbar v-if="enableTabbar" class="z-2" />
|
||||
<Toolbar v-if="enableToolbar" class="z-1" />
|
||||
</div>
|
||||
</Transition>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 顶栏动画 */
|
||||
.topbar-enter-active,
|
||||
.topbar-leave-active {
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.topbar-enter-from,
|
||||
.topbar-leave-to {
|
||||
transform: translateY(calc(var(--g-topbar-height) * -1));
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,61 @@
|
||||
<script setup lang="ts">
|
||||
import { useClipboard } from '@vueuse/core'
|
||||
|
||||
defineOptions({
|
||||
name: 'LinkView',
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
const { copy, copied } = useClipboard()
|
||||
watch(copied, (val) => {
|
||||
val && useFaToast().success('复制成功')
|
||||
})
|
||||
|
||||
function open() {
|
||||
window.open(route.meta.link, '_blank')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col h-full w-full absolute">
|
||||
<Transition name="fade" mode="out-in" appear>
|
||||
<FaPageMain :key="route.meta.link" class="flex flex-1 flex-col justify-center">
|
||||
<div class="flex flex-col items-center">
|
||||
<FaIcon name="i-icon-park-twotone:planet" class="text-primary/80 size-30" />
|
||||
<div class="text-xl text-dark my-2 dark-text-white">
|
||||
是否访问此链接
|
||||
</div>
|
||||
<div class="text-[14px] text-secondary-foreground/50 my-2 text-center max-w-[300px] cursor-pointer" @click="route.meta.link && copy(route.meta.link)">
|
||||
<FaTooltip text="复制链接">
|
||||
<div class="line-clamp-3">
|
||||
{{ route.meta.link }}
|
||||
</div>
|
||||
</FaTooltip>
|
||||
</div>
|
||||
<FaButton class="my-4" @click="open">
|
||||
<FaIcon name="i-ri:external-link-fill" />
|
||||
立即访问
|
||||
</FaButton>
|
||||
</div>
|
||||
</FaPageMain>
|
||||
</Transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.fade-enter-active {
|
||||
transition: 0.2s;
|
||||
}
|
||||
|
||||
.fade-leave-active {
|
||||
transition: 0.15s;
|
||||
}
|
||||
|
||||
.fade-enter-from {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
Executable
+325
@@ -0,0 +1,325 @@
|
||||
<script setup lang="ts">
|
||||
import { useElementSize, useScroll } from '@vueuse/core'
|
||||
import { useHotkeyBindings } from '@/hotkeys'
|
||||
import { useSlots } from '@/slots'
|
||||
import { cn } from '@/utils'
|
||||
import eventBus from '@/utils/eventBus'
|
||||
import AppSetting from './components/AppSetting/index.vue'
|
||||
import FloatingSidebarMenuButton from './components/FloatingSidebarMenuButton/index.vue'
|
||||
import Header from './components/Header/index.vue'
|
||||
import Hotkeys from './components/Hotkeys/index.vue'
|
||||
import MainSidebar from './components/MainSidebar/index.vue'
|
||||
import SubSidebar from './components/SubSidebar/index.vue'
|
||||
import Topbar from './components/Topbar/index.vue'
|
||||
import LinkView from './components/views/link.vue'
|
||||
|
||||
defineOptions({
|
||||
name: 'Layout',
|
||||
})
|
||||
|
||||
const routeInfo = useRoute()
|
||||
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appKeepAliveStore = useAppKeepAliveStore()
|
||||
const appMenuStore = useAppMenuStore()
|
||||
const mainPage = useAppPage()
|
||||
|
||||
useHotkeyBindings({
|
||||
'system.info.open': () => {
|
||||
eventBus.emit('global-system-info-open')
|
||||
},
|
||||
'page.reload': () => {
|
||||
mainPage.reload()
|
||||
},
|
||||
})
|
||||
|
||||
const layoutTopRef = useTemplateRef('layoutTopRef')
|
||||
const { height: layoutTopHeight } = useElementSize(layoutTopRef)
|
||||
|
||||
const layoutBottomRef = useTemplateRef('layoutBottomRef')
|
||||
const { height: layoutBottomHeight } = useElementSize(layoutBottomRef)
|
||||
|
||||
// 头部是否显示
|
||||
const isHeaderEnable = computed(() => {
|
||||
return appSettingsStore.mode === 'pc'
|
||||
&& appSettingsStore.settings.menu.mode === 'head'
|
||||
})
|
||||
|
||||
// 侧边栏主导航是否显示
|
||||
const isMainSidebarEnable = computed(() => {
|
||||
return appSettingsStore.settings.menu.mode === 'side'
|
||||
|| (appSettingsStore.mode === 'mobile' && appSettingsStore.settings.menu.mode !== 'single')
|
||||
})
|
||||
|
||||
// 侧边栏次导航是否显示
|
||||
const isSubSidebarEnable = computed(() => {
|
||||
return appSettingsStore.mode === 'mobile'
|
||||
|| (
|
||||
['side', 'head'].includes(appSettingsStore.settings.menu.mode)
|
||||
&& appMenuStore.sidebarMenus.length !== 0
|
||||
&& (
|
||||
(
|
||||
appSettingsStore.settings.menu.mainMenuClickMode === 'switch'
|
||||
&& !appMenuStore.sidebarMenus.every(item => item.meta?.menu === false)
|
||||
)
|
||||
|| (
|
||||
appSettingsStore.settings.menu.mainMenuClickMode !== 'switch'
|
||||
&& appMenuStore.sidebarMenus.some(item => item.meta?.menu !== false)
|
||||
)
|
||||
)
|
||||
)
|
||||
|| (
|
||||
['single'].includes(appSettingsStore.settings.menu.mode)
|
||||
&& appMenuStore.sidebarMenus.length !== 0
|
||||
&& !appMenuStore.sidebarMenus.every(item => item.meta?.menu === false)
|
||||
)
|
||||
})
|
||||
|
||||
// 顶栏是否显示
|
||||
const isTopbarEnable = computed(() => true)
|
||||
|
||||
// 标签栏是否显示
|
||||
const isTabbarEnable = computed(() => {
|
||||
return appSettingsStore.settings.topbar.tabbar
|
||||
})
|
||||
|
||||
// 工具栏是否显示
|
||||
const isToolbarEnable = computed(() => {
|
||||
const { toolbar } = appSettingsStore.settings
|
||||
return appSettingsStore.settings.topbar.toolbar && [
|
||||
toolbar.breadcrumb,
|
||||
toolbar.menuSearch,
|
||||
toolbar.fullscreen,
|
||||
toolbar.pageReload,
|
||||
toolbar.colorScheme,
|
||||
].some((item) => {
|
||||
if (typeof item === 'boolean') {
|
||||
return item
|
||||
}
|
||||
return item?.enable ?? false
|
||||
})
|
||||
})
|
||||
|
||||
const isLink = computed(() => !!routeInfo.meta.link)
|
||||
|
||||
watch(() => appSettingsStore.settings.menu.subMenuCollapse, (val) => {
|
||||
if (appSettingsStore.mode === 'mobile') {
|
||||
if (!val) {
|
||||
document.body.classList.add('overflow-hidden')
|
||||
}
|
||||
else {
|
||||
document.body.classList.remove('overflow-hidden')
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
watch(() => routeInfo.path, () => {
|
||||
if (appSettingsStore.mode === 'mobile') {
|
||||
appSettingsStore.$patch((state) => {
|
||||
state.settings.menu.subMenuCollapse = true
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const { y } = useScroll(window)
|
||||
const { height: fixedContentBeforeAreaHeight } = useElementSize(useTemplateRef('fixedContentBeforeAreaRef'))
|
||||
const { height: fixedContentAfterAreaHeight } = useElementSize(useTemplateRef('fixedContentAfterAreaRef'))
|
||||
const topbarScrollVisibleOrHidden = ref(false)
|
||||
eventBus.on('topbar-scroll-visible-or-hidden', (val) => {
|
||||
topbarScrollVisibleOrHidden.value = val
|
||||
})
|
||||
|
||||
const enableAppSetting = import.meta.env.VITE_APP_SETTING
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="layout h-full" :style="{
|
||||
'--g-slots-layout-top-height': `${layoutTopHeight}px`,
|
||||
'--g-slots-layout-bottom-height': `${layoutBottomHeight}px`,
|
||||
'--g-header-actual-height': isHeaderEnable ? 'var(--g-header-height)' : '0px',
|
||||
'--g-main-sidebar-actual-width': isMainSidebarEnable ? 'var(--g-main-sidebar-width)' : '0px',
|
||||
'--g-sub-sidebar-actual-width': isSubSidebarEnable ? (appSettingsStore.settings.menu.subMenuCollapse && appSettingsStore.mode !== 'mobile' ? 'var(--g-sub-sidebar-collapse-width)' : 'var(--g-sub-sidebar-width)') : '0px',
|
||||
'--g-topbar-height': 'calc(var(--g-tabbar-actual-height) + var(--g-toolbar-actual-height))',
|
||||
'--g-topbar-actual-height': isTopbarEnable ? 'calc(var(--g-tabbar-actual-height) + var(--g-toolbar-actual-height))' : '0px',
|
||||
'--g-tabbar-actual-height': isTabbarEnable ? 'var(--g-tabbar-height)' : '0px',
|
||||
'--g-toolbar-actual-height': isToolbarEnable ? 'var(--g-toolbar-height)' : '0px',
|
||||
'--g-main-container-padding-top': `${fixedContentBeforeAreaHeight}px`,
|
||||
'--g-main-container-padding-bottom': `${fixedContentAfterAreaHeight}px`,
|
||||
}"
|
||||
>
|
||||
<div ref="layoutTopRef" class="slots-layout-top mx-auto bg-background w-full shadow-[-1px_0_0_0_oklch(var(--border)),1px_0_0_0_oklch(var(--border)),0_-1px_0_0_oklch(var(--border)),0_1px_0_0_oklch(var(--border))] transition-width-300 inset-t-0 fixed z-1030 empty:hidden">
|
||||
<Component :is="useSlots('layout-top')" />
|
||||
</div>
|
||||
<Header :enable="isHeaderEnable" />
|
||||
<div class="wrapper">
|
||||
<div class="sidebar-container" :class="{ show: appSettingsStore.mode === 'mobile' && !appSettingsStore.settings.menu.subMenuCollapse }">
|
||||
<MainSidebar :enable="isMainSidebarEnable" />
|
||||
<SubSidebar :enable="isSubSidebarEnable" />
|
||||
</div>
|
||||
<!-- 移动端下,展开侧边栏时的遮罩层 -->
|
||||
<div :class="cn('invisible fixed inset-0 z-1009 bg-black/50 op-0 backdrop-blur-sm transition-opacity', { 'op-100 visible': appSettingsStore.mode === 'mobile' && !appSettingsStore.settings.menu.subMenuCollapse })" @click="appSettingsStore.toggleSidebarCollapse()" />
|
||||
<FloatingSidebarMenuButton />
|
||||
<div class="main-container pb-[calc(var(--g-slots-layout-bottom-height)+var(--g-main-container-padding-bottom,0px))] pt-[calc(var(--g-slots-layout-top-height)+var(--g-header-actual-height)+var(--g-topbar-actual-height))]">
|
||||
<div
|
||||
class="fixed-content-around-area w-full inset-t-[calc(var(--g-slots-layout-top-height)+var(--g-header-actual-height))] inset-inline-1/2 fixed z-1005" :style="{
|
||||
...(appSettingsStore.settings.topbar.mode === 'static' && { marginTop: `calc(min(var(--g-topbar-actual-height), ${y}px) * -1)` }),
|
||||
...(topbarScrollVisibleOrHidden && { translate: '0 calc(var(--g-topbar-actual-height) * -1)' }),
|
||||
}"
|
||||
>
|
||||
<Topbar :enable="isTopbarEnable" :enable-tabbar="isTabbarEnable" :enable-toolbar="isToolbarEnable" />
|
||||
<div id="fixed-content-before-area" ref="fixedContentBeforeAreaRef" class="shadow-[0_1px_0_0_oklch(var(--border)),0_-1px_0_0_oklch(var(--border))] relative z-1 empty:hidden" />
|
||||
</div>
|
||||
<div id="app-content" class="main">
|
||||
<RouterView v-slot="{ Component, route }">
|
||||
<Transition :name="!appSettingsStore.isReloading ? 'fade' : ''" mode="out-in">
|
||||
<KeepAlive :include="appKeepAliveStore.list">
|
||||
<Component :is="Component" v-show="!isLink" :key="route.fullPath" />
|
||||
</KeepAlive>
|
||||
</Transition>
|
||||
</RouterView>
|
||||
<LinkView v-if="isLink" />
|
||||
</div>
|
||||
<div class="copyright">
|
||||
<AppCopyright />
|
||||
</div>
|
||||
<div class="fixed-content-around-area w-full inset-b-0 inset-inline-1/2 fixed z-1005">
|
||||
<div id="fixed-content-after-area" ref="fixedContentAfterAreaRef" class="shadow-[0_1px_0_0_oklch(var(--border)),0_-1px_0_0_oklch(var(--border))] relative z-1 empty:hidden" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div ref="layoutBottomRef" class="slots-layout-bottom mx-auto bg-background w-full shadow-[-1px_0_0_0_oklch(var(--border)),1px_0_0_0_oklch(var(--border)),0_-1px_0_0_oklch(var(--border)),0_1px_0_0_oklch(var(--border))] transition-width-300 inset-b-0 fixed z-1030 empty:hidden">
|
||||
<Component :is="useSlots('layout-bottom')" />
|
||||
</div>
|
||||
<Hotkeys />
|
||||
<template v-if="enableAppSetting">
|
||||
<div class="text-primary-foreground rounded-l-md bg-primary flex-center size-12 cursor-pointer inset-e-0 inset-t-[calc(50%+250px)] fixed z-10" @click="eventBus.emit('global-app-setting-toggle')">
|
||||
<FaIcon name="i-uiw:setting-o" class="size-6 animate-spin animate-duration-3000" />
|
||||
</div>
|
||||
<AppSetting />
|
||||
</template>
|
||||
<Component :is="useSlots('free-position')" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
[data-mode="mobile"] {
|
||||
.sidebar-container {
|
||||
transform: translateX(calc((var(--g-main-sidebar-width) + var(--g-sub-sidebar-width)) * -1));
|
||||
|
||||
&.show {
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
.main-container {
|
||||
padding-inline-start: 0 !important;
|
||||
}
|
||||
|
||||
&[data-menu-mode="single"] {
|
||||
.sidebar-container {
|
||||
transform: translateX(calc(var(--g-sub-sidebar-width) * -1));
|
||||
|
||||
&.show {
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.layout {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0 auto;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
.wrapper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
.sidebar-container {
|
||||
position: fixed;
|
||||
top: calc(var(--g-slots-layout-top-height) + var(--g-header-actual-height));
|
||||
bottom: var(--g-slots-layout-bottom-height);
|
||||
z-index: 1010;
|
||||
display: flex;
|
||||
width: calc(var(--g-main-sidebar-actual-width) + var(--g-sub-sidebar-actual-width));
|
||||
transition: width 0.3s, transform 0.3s, top 0.3s, box-shadow 0.15s;
|
||||
|
||||
&:has(> .main-sidebar-container.main-sidebar-enter-active),
|
||||
&:has(> .main-sidebar-container.main-sidebar-leave-active),
|
||||
&:has(> .sub-sidebar-container.sub-sidebar-enter-active),
|
||||
&:has(> .sub-sidebar-container.sub-sidebar-leave-active) {
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.main-sidebar-container:not(.main-sidebar-leave-active) + .sub-sidebar-container {
|
||||
inset-inline-start: var(--g-main-sidebar-width);
|
||||
}
|
||||
|
||||
.main-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100%;
|
||||
padding-inline-start: calc(var(--g-main-sidebar-actual-width) + var(--g-sub-sidebar-actual-width));
|
||||
overflow: auto;
|
||||
background-color: var(--g-main-area-bg);
|
||||
box-shadow: -1px 0 0 0 oklch(var(--border)), 1px 0 0 0 oklch(var(--border));
|
||||
transition: padding-inline-start 0.3s, padding 0.3s, background-color 0.15s, box-shadow 0.15s;
|
||||
|
||||
.fixed-content-around-area {
|
||||
width: calc(100% - var(--g-main-sidebar-actual-width) - var(--g-sub-sidebar-actual-width));
|
||||
padding-right: var(--scrollbar-width, 0);
|
||||
transform: translateX(-50%) translateX(calc(var(--g-main-sidebar-actual-width) / 2)) translateX(calc(var(--g-sub-sidebar-actual-width) / 2));
|
||||
transform-origin: left;
|
||||
transition: width 0.3s, transform 0.3s, translate 0.3s, top 0.3s;
|
||||
|
||||
[data-mode="mobile"] & {
|
||||
width: 100% !important;
|
||||
transform: translateX(-50%) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.main {
|
||||
position: relative;
|
||||
flex: auto;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding-top: var(--g-main-container-padding-top, 0);
|
||||
margin: 0 auto;
|
||||
overflow: hidden;
|
||||
background-color: var(--g-main-area-bg);
|
||||
box-shadow: -1px 0 0 0 oklch(var(--border)), 1px 0 0 0 oklch(var(--border));
|
||||
transition: padding-top 0.3s, width 0.3s, background-color 0.15s, box-shadow 0.15s;
|
||||
}
|
||||
|
||||
.copyright {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
margin-inline: auto;
|
||||
background-color: oklch(var(--background));
|
||||
box-shadow: -1px 0 0 0 oklch(var(--border)), 1px 0 0 0 oklch(var(--border)), 0 -1px 0 0 oklch(var(--border));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 主内容区动画 */
|
||||
.fade-enter-active {
|
||||
transition: 0.2s;
|
||||
}
|
||||
|
||||
.fade-leave-active {
|
||||
transition: 0.15s;
|
||||
}
|
||||
|
||||
.fade-enter-from {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
</style>
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
// 加载 iconify 图标
|
||||
import { downloadAndInstall } from '@/iconify'
|
||||
import icons from '@/iconify/index.json'
|
||||
// 自定义指令
|
||||
import directive from '@/utils/directive'
|
||||
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import pinia from './store'
|
||||
import uiProvider from './ui/provider'
|
||||
import '@/utils/storage'
|
||||
|
||||
// UnoCSS
|
||||
import 'virtual:uno.css'
|
||||
// 全局样式
|
||||
import '@/assets/styles/globals.css'
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(pinia)
|
||||
app.use(router)
|
||||
app.use(uiProvider)
|
||||
directive(app)
|
||||
if (icons.isOfflineUse) {
|
||||
for (const info of icons.collections) {
|
||||
downloadAndInstall(info)
|
||||
}
|
||||
}
|
||||
|
||||
app.mount('#app')
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
import type { NavigationFailure, RouteLocationRaw, Router } from 'vue-router'
|
||||
import pinia from '@/store'
|
||||
|
||||
function getId(router: Router) {
|
||||
return router.currentRoute.value.fullPath
|
||||
}
|
||||
|
||||
function extendPush(router: Router) {
|
||||
const originalPush = router.push
|
||||
router.push = function (to: RouteLocationRaw) {
|
||||
const appSettingsStore = useAppSettingsStore(pinia)
|
||||
if (appSettingsStore.settings.topbar.tabbar) {
|
||||
const appTabbarStore = useAppTabbarStore(pinia)
|
||||
const index = appTabbarStore.list.findIndex(item => item.tabId === getId(router))
|
||||
appTabbarStore.$patch({
|
||||
leaveIndex: index,
|
||||
})
|
||||
}
|
||||
return originalPush(to)
|
||||
}
|
||||
}
|
||||
|
||||
function extendReplace(router: Router) {
|
||||
const originalReplace = router.replace
|
||||
router.replace = function (to: RouteLocationRaw) {
|
||||
const appSettingsStore = useAppSettingsStore(pinia)
|
||||
if (appSettingsStore.settings.topbar.tabbar) {
|
||||
const tabId = getId(router)
|
||||
const appTabbarStore = useAppTabbarStore(pinia)
|
||||
return originalReplace(to).then(() => {
|
||||
appTabbarStore.remove(tabId)
|
||||
})
|
||||
}
|
||||
else {
|
||||
return originalReplace(to)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function extendGo(router: Router) {
|
||||
const originalGo = router.go
|
||||
router.go = function (delta: number) {
|
||||
const appSettingsStore = useAppSettingsStore(pinia)
|
||||
if (appSettingsStore.settings.topbar.tabbar) {
|
||||
const tabId = getId(router)
|
||||
const appTabbarStore = useAppTabbarStore(pinia)
|
||||
originalGo(delta)
|
||||
if (delta < 0) {
|
||||
appTabbarStore.remove(tabId)
|
||||
}
|
||||
}
|
||||
else {
|
||||
originalGo(delta)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function shouldUseHistoryBack(router: Router, to?: RouteLocationRaw) {
|
||||
const historyBack = window.history.state?.back
|
||||
if (typeof historyBack !== 'string' || !historyBack) {
|
||||
return false
|
||||
}
|
||||
if (!to) {
|
||||
return true
|
||||
}
|
||||
const backRoute = router.resolve(historyBack)
|
||||
const targetRoute = router.resolve(to)
|
||||
if (backRoute.name && targetRoute.name) {
|
||||
return backRoute.name === targetRoute.name
|
||||
}
|
||||
return (backRoute.matched.at(-1)?.path ?? backRoute.path) === (targetRoute.matched.at(-1)?.path ?? targetRoute.path)
|
||||
}
|
||||
|
||||
function extendBack(router: Router) {
|
||||
const originalBack = router.back
|
||||
router.back = function (to?: RouteLocationRaw) {
|
||||
const appSettingsStore = useAppSettingsStore(pinia)
|
||||
const tabId = getId(router)
|
||||
const fallbackTo = to ?? appSettingsStore.settings.app.home.fullPath
|
||||
if (shouldUseHistoryBack(router, to)) {
|
||||
originalBack()
|
||||
if (appSettingsStore.settings.topbar.tabbar) {
|
||||
const appTabbarStore = useAppTabbarStore(pinia)
|
||||
appTabbarStore.remove(tabId)
|
||||
}
|
||||
return Promise.resolve()
|
||||
}
|
||||
else {
|
||||
return router.replace(fallbackTo).then(() => {
|
||||
if (appSettingsStore.settings.topbar.tabbar) {
|
||||
const appTabbarStore = useAppTabbarStore(pinia)
|
||||
appTabbarStore.remove(tabId)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function extendClose(router: Router) {
|
||||
router.close = function (to: RouteLocationRaw) {
|
||||
const tabId = getId(router)
|
||||
return router.push(to).then(() => {
|
||||
const appSettingsStore = useAppSettingsStore(pinia)
|
||||
if (appSettingsStore.settings.topbar.tabbar) {
|
||||
const appTabbarStore = useAppTabbarStore(pinia)
|
||||
appTabbarStore.remove(tabId)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'vue-router' {
|
||||
interface _RouterClassic {
|
||||
/**
|
||||
* 本方法为框架扩展语法,会同时关闭当前标签页
|
||||
*
|
||||
* 如果上一条历史记录与传入目标页一致,则调用原生 `back` 方法
|
||||
* 如果没有历史记录,或者上一条历史记录不是目标页,则使用 `replace` 方法跳转到指定路径或首页
|
||||
*
|
||||
* @param to 可选的目标路由,当无法安全回退时使用此参数作为跳转目标
|
||||
*/
|
||||
back: (to?: RouteLocationRaw) => Promise<NavigationFailure | void | undefined>
|
||||
/**
|
||||
* 本方法为框架扩展语法,等同于 `push` 方法,并且同时会关闭当前标签页
|
||||
*/
|
||||
close: (to: RouteLocationRaw) => Promise<NavigationFailure | void | undefined>
|
||||
}
|
||||
}
|
||||
|
||||
export default function setupExtensions(router: Router) {
|
||||
extendPush(router)
|
||||
extendReplace(router)
|
||||
extendGo(router)
|
||||
extendBack(router)
|
||||
extendClose(router)
|
||||
}
|
||||
Executable
+182
@@ -0,0 +1,182 @@
|
||||
import type { Router } from 'vue-router'
|
||||
import { useNProgress } from '@vueuse/integrations/useNProgress'
|
||||
import { warnKeepAliveComponentNameMissing } from 'virtual:fantastic-admin/turbo-console'
|
||||
import { asyncRoutes } from './routes'
|
||||
import '@/assets/styles/nprogress.css'
|
||||
|
||||
function setupRoutes(router: Router) {
|
||||
router.beforeEach(async (to) => {
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appAccountStore = useAppAccountStore()
|
||||
const appRouteStore = useAppRouteStore()
|
||||
const appMenuStore = useAppMenuStore()
|
||||
// 是否已登录
|
||||
if (appAccountStore.isLogin) {
|
||||
// 是否已根据权限动态生成并注册路由
|
||||
if (appRouteStore.isGenerate) {
|
||||
// 导航菜单如果不是 single 模式,则需要根据 path 定位主导航菜单的选中状态
|
||||
appSettingsStore.settings.menu.mode !== 'single' && appMenuStore.setActived(to.path)
|
||||
// 如果已登录状态下,进入登录页会强制跳转到主页
|
||||
if (to.name === 'login') {
|
||||
return {
|
||||
path: appSettingsStore.settings.app.home.fullPath,
|
||||
replace: true,
|
||||
}
|
||||
}
|
||||
// 如果未开启主页,但进入的是主页,则会进入侧边栏导航第一个模块
|
||||
else if (!appSettingsStore.settings.app.home.enable && to.fullPath === appSettingsStore.settings.app.home.fullPath && appMenuStore.sidebarMenus.length > 0) {
|
||||
return {
|
||||
path: appMenuStore.sidebarMenusFirstDeepestPath,
|
||||
replace: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
// 获取用户权限
|
||||
appSettingsStore.settings.app.account.auth && await appAccountStore.getPermissions()
|
||||
// 生成动态路由
|
||||
switch (appSettingsStore.settings.app.routeBaseOn) {
|
||||
case 'frontend':
|
||||
appRouteStore.generateRoutesAtFront(asyncRoutes)
|
||||
break
|
||||
case 'backend':
|
||||
await appRouteStore.generateRoutesAtBack()
|
||||
break
|
||||
}
|
||||
// 注册并记录路由数据
|
||||
// 记录的数据会在登出时会使用到,不使用 router.removeRoute 是考虑配置的路由可能不一定有设置 name ,则通过调用 router.addRoute() 返回的回调进行删除
|
||||
const removeRoutes: (() => void)[] = []
|
||||
appRouteStore.routes.forEach((route) => {
|
||||
if (!/^(?:https?:|mailto:|tel:)/.test(route.path)) {
|
||||
removeRoutes.push(router.addRoute(route))
|
||||
}
|
||||
})
|
||||
appRouteStore.systemRoutes.forEach((route) => {
|
||||
removeRoutes.push(router.addRoute(route))
|
||||
})
|
||||
appRouteStore.setCurrentRemoveRoutes(removeRoutes)
|
||||
}
|
||||
catch {}
|
||||
// 动态路由生成并注册后,重新进入当前路由
|
||||
return {
|
||||
path: to.path,
|
||||
query: to.query,
|
||||
replace: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (to.name !== 'login') {
|
||||
return {
|
||||
name: 'login',
|
||||
query: {
|
||||
redirect: to.fullPath !== appSettingsStore.settings.app.home.fullPath ? to.fullPath : undefined,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 当父级路由未配置重定向时,自动重定向到有访问权限的子路由
|
||||
function setupRedirectAuthChildrenRoute(router: Router) {
|
||||
router.beforeEach((to) => {
|
||||
const { auth } = useAppAuth()
|
||||
const currentRoute = router.getRoutes().find(route => route.path === (to.matched.at(-1)?.path ?? ''))
|
||||
if (!currentRoute?.redirect) {
|
||||
const findAuthRoute = currentRoute?.children?.find(route => route.meta?.menu !== false && auth(route.meta?.auth ?? ''))
|
||||
if (findAuthRoute) {
|
||||
return findAuthRoute
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 进度条
|
||||
function setupProgress(router: Router) {
|
||||
const { isLoading } = useNProgress()
|
||||
router.beforeEach(() => {
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
if (appSettingsStore.settings.page.progress) {
|
||||
isLoading.value = true
|
||||
}
|
||||
})
|
||||
router.afterEach(() => {
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
if (appSettingsStore.settings.page.progress) {
|
||||
isLoading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
// 标题
|
||||
function setupTitle(router: Router) {
|
||||
router.afterEach((to) => {
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
appSettingsStore.setTitle(to.matched?.at(-1)?.meta?.title ?? to.meta.title)
|
||||
})
|
||||
}
|
||||
|
||||
// 页面保活
|
||||
function setupKeepAlive(router: Router) {
|
||||
router.afterEach(async (to, from) => {
|
||||
const appKeepAliveStore = useAppKeepAliveStore()
|
||||
if (to.meta.keepAlive) {
|
||||
const componentName = to.matched.at(-1)?.components?.default.name
|
||||
if (componentName) {
|
||||
// 保活当前页面前,先判断是否需要清除保活,判断依据:
|
||||
// 1. 如果 to.meta.keepAlive 为 boolean 类型,并且不为 true,则需要清除保活
|
||||
// 2. 如果 to.meta.keepAlive 为 string 类型,并且与 from.name 不一致,则需要清除保活
|
||||
// 3. 如果 to.meta.keepAlive 为 array 类型,并且不包含 from.name,则需要清除保活
|
||||
// 4. 如果 to.meta.noKeepAlive 为 string 类型,并且与 from.name 一致,则需要清除保活
|
||||
// 5. 如果 to.meta.noKeepAlive 为 array 类型,并且包含 from.name,则需要清除保活
|
||||
// 6. 如果是刷新页面,则需要清除保活
|
||||
let shouldClear = false
|
||||
if (typeof to.meta.keepAlive === 'boolean') {
|
||||
shouldClear = !to.meta.keepAlive
|
||||
}
|
||||
else if (typeof to.meta.keepAlive === 'string') {
|
||||
shouldClear = to.meta.keepAlive !== from.name
|
||||
}
|
||||
else if (Array.isArray(to.meta.keepAlive)) {
|
||||
shouldClear = !to.meta.keepAlive.includes(from.name as string)
|
||||
}
|
||||
if (to.meta.noKeepAlive) {
|
||||
if (typeof to.meta.noKeepAlive === 'string') {
|
||||
shouldClear = to.meta.noKeepAlive === from.name
|
||||
}
|
||||
else if (Array.isArray(to.meta.noKeepAlive)) {
|
||||
shouldClear = to.meta.noKeepAlive.includes(from.name as string)
|
||||
}
|
||||
}
|
||||
if (from.name === 'reload') {
|
||||
shouldClear = true
|
||||
}
|
||||
if (shouldClear) {
|
||||
appKeepAliveStore.remove(componentName)
|
||||
await nextTick()
|
||||
}
|
||||
appKeepAliveStore.add(componentName)
|
||||
}
|
||||
else if (import.meta.env.DEV) {
|
||||
warnKeepAliveComponentNameMissing((to.matched.at(-1)?.components?.default as any).__file)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 其他
|
||||
function setupOther(router: Router) {
|
||||
router.afterEach(() => {
|
||||
document.documentElement.scrollTop = 0
|
||||
})
|
||||
}
|
||||
|
||||
export default function setupGuards(router: Router) {
|
||||
setupRoutes(router)
|
||||
setupRedirectAuthChildrenRoute(router)
|
||||
setupProgress(router)
|
||||
setupTitle(router)
|
||||
setupKeepAlive(router)
|
||||
setupOther(router)
|
||||
}
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
import { loadingFadeOut } from 'virtual:app-loading'
|
||||
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
|
||||
import pinia from '@/store'
|
||||
import setupExtensions from './extensions'
|
||||
import setupGuards from './guards'
|
||||
// 路由相关数据
|
||||
import { constantRoutes } from './routes'
|
||||
|
||||
const router = createRouter({
|
||||
history: useAppSettingsStore(pinia).settings.app.routeMode === 'hash' ? createWebHashHistory() : createWebHistory(),
|
||||
routes: constantRoutes,
|
||||
strict: true,
|
||||
})
|
||||
|
||||
setupGuards(router)
|
||||
setupExtensions(router)
|
||||
|
||||
router.isReady().then(() => {
|
||||
loadingFadeOut()
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,69 @@
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
|
||||
function Layout() {
|
||||
return import('@/layouts/index.vue')
|
||||
}
|
||||
|
||||
const routes: RouteRecordRaw = {
|
||||
path: '/multilevel_menu_example',
|
||||
component: Layout,
|
||||
name: 'multilevelMenuExample',
|
||||
meta: {
|
||||
title: '多级导航',
|
||||
icon: 'i-heroicons-solid:menu-alt-3',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'page',
|
||||
name: 'multilevelMenuExample1',
|
||||
component: () => import('@/views/multilevel_menu_example/page.vue'),
|
||||
meta: {
|
||||
title: '导航1',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'level2',
|
||||
name: 'multilevelMenuExample2',
|
||||
meta: {
|
||||
title: '导航2',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'page',
|
||||
name: 'multilevelMenuExample2-1',
|
||||
component: () => import('@/views/multilevel_menu_example/level2/page.vue'),
|
||||
meta: {
|
||||
title: '导航2-1',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'level3',
|
||||
name: 'multilevelMenuExample2-2',
|
||||
meta: {
|
||||
title: '导航2-2',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'page1',
|
||||
name: 'multilevelMenuExample2-2-1',
|
||||
component: () => import('@/views/multilevel_menu_example/level2/level3/page1.vue'),
|
||||
meta: {
|
||||
title: '导航2-2-1',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'page2',
|
||||
name: 'multilevelMenuExample2-2-2',
|
||||
component: () => import('@/views/multilevel_menu_example/level2/level3/page2.vue'),
|
||||
meta: {
|
||||
title: '导航2-2-2',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
export default routes
|
||||
+5
-6
@@ -5,20 +5,19 @@ function Layout() {
|
||||
}
|
||||
|
||||
const routes: RouteRecordRaw = {
|
||||
path: '/tdesign_example',
|
||||
path: '/ui_example',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: 'TDesign',
|
||||
icon: 'https://static.tdesign.tencent.com/favicon.ico',
|
||||
title: 'UI',
|
||||
menu: false,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: 'tdesignExample',
|
||||
component: () => import('@/views/tdesign_example/index.vue'),
|
||||
name: 'uiExample',
|
||||
component: () => import('@/views/ui_example/index.vue'),
|
||||
meta: {
|
||||
title: 'TDesign',
|
||||
title: 'UI',
|
||||
menu: false,
|
||||
breadcrumb: false,
|
||||
},
|
||||
Executable
+84
@@ -0,0 +1,84 @@
|
||||
import type { RouteRecordMainRaw } from '@fantastic-admin/types'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import pinia from '@/store'
|
||||
import MultilevelMenuExample from './modules/multilevel.menu.example'
|
||||
import UiExample from './modules/ui.example'
|
||||
|
||||
// 固定路由(默认路由)
|
||||
const constantRoutes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: () => import('@/views/login.vue'),
|
||||
meta: {
|
||||
title: '登录',
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/:all(.*)*',
|
||||
name: 'notFound',
|
||||
component: () => import('@/views/[...all].vue'),
|
||||
meta: {
|
||||
title: '找不到页面',
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
// 系统路由
|
||||
const systemRoutes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/layouts/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: false,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
component: () => import('@/views/index.vue'),
|
||||
meta: {
|
||||
title: useAppSettingsStore(pinia).settings.app.home.title,
|
||||
icon: 'i-ant-design:home-twotone',
|
||||
breadcrumb: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'reload',
|
||||
name: 'reload',
|
||||
component: () => import('@/views/reload.vue'),
|
||||
meta: {
|
||||
title: '重新加载中...',
|
||||
breadcrumb: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
// 动态路由(异步路由、导航菜单路由)
|
||||
const asyncRoutes: RouteRecordMainRaw[] = [
|
||||
{
|
||||
meta: {
|
||||
title: '演示',
|
||||
icon: 'i-ri:function-ai-line',
|
||||
},
|
||||
children: [
|
||||
MultilevelMenuExample,
|
||||
],
|
||||
},
|
||||
{
|
||||
meta: {
|
||||
title: 'UI',
|
||||
icon: 'i-whh:jqueryui',
|
||||
},
|
||||
children: [
|
||||
UiExample,
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
export {
|
||||
asyncRoutes,
|
||||
constantRoutes,
|
||||
systemRoutes,
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
import { setSettings } from '@fantastic-admin/settings'
|
||||
|
||||
export default setSettings({
|
||||
// 请在此处编写或粘贴应用配置
|
||||
})
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
import { pascalCase } from 'scule'
|
||||
|
||||
type Slots
|
||||
= 'layout-top' | 'layout-bottom'
|
||||
| 'header-start' | 'header-after-logo' | 'header-after-menu' | 'header-end'
|
||||
| 'main-sidebar-top' | 'main-sidebar-after-logo' | 'main-sidebar-after-menu' | 'main-sidebar-bottom'
|
||||
| 'sub-sidebar-top' | 'sub-sidebar-after-logo' | 'sub-sidebar-after-menu' | 'sub-sidebar-bottom'
|
||||
| 'tabbar-start' | 'tabbar-end'
|
||||
| 'toolbar-start' | 'toolbar-end'
|
||||
| 'free-position'
|
||||
|
||||
function tryLoadComponent(name: Slots) {
|
||||
const componentMap = import.meta.glob('./*/index.vue', { eager: true })
|
||||
const path = `./${pascalCase(name as unknown as string)}/index.vue`
|
||||
const component = componentMap[path as keyof typeof componentMap]
|
||||
if (!component) {
|
||||
return {
|
||||
default: defineComponent({
|
||||
name: 'SlotsInvalidComponent',
|
||||
render: () => null,
|
||||
}),
|
||||
}
|
||||
}
|
||||
return component
|
||||
}
|
||||
|
||||
export function useSlots(name: Slots) {
|
||||
const component = tryLoadComponent(name)
|
||||
return defineComponent((component as any).default)
|
||||
}
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||||
|
||||
const pinia = createPinia()
|
||||
pinia.use(piniaPluginPersistedstate)
|
||||
|
||||
export default pinia
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
import apiApp from '@/api/modules/app'
|
||||
import router from '@/router'
|
||||
|
||||
export const useAppAccountStore = defineStore('appAccount', () => {
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appTabbarStore = useAppTabbarStore()
|
||||
const appRouteStore = useAppRouteStore()
|
||||
const appMenuStore = useAppMenuStore()
|
||||
|
||||
// 账号信息
|
||||
const token = ref(localStorage.getItem('token') ?? '')
|
||||
const account = ref(localStorage.getItem('account') ?? '')
|
||||
const avatar = ref(localStorage.getItem('avatar') ?? '')
|
||||
|
||||
// 权限信息
|
||||
const permissions = ref<string[]>([])
|
||||
|
||||
// 登录状态
|
||||
const isLogin = computed(() => {
|
||||
if (token.value) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
// 登录
|
||||
async function login(data: {
|
||||
account: string
|
||||
password: string
|
||||
}) {
|
||||
const res = await apiApp.login(data)
|
||||
localStorage.setItem('account', res.data.account)
|
||||
localStorage.setItem('token', res.data.token)
|
||||
localStorage.setItem('avatar', res.data.avatar)
|
||||
account.value = res.data.account
|
||||
token.value = res.data.token
|
||||
avatar.value = res.data.avatar
|
||||
}
|
||||
|
||||
// 手动登出
|
||||
function logout(redirect = router.currentRoute.value.fullPath) {
|
||||
localStorage.removeItem('token')
|
||||
token.value = ''
|
||||
router.push({
|
||||
name: 'login',
|
||||
query: {
|
||||
...(redirect !== appSettingsStore.settings.app.home.fullPath && router.currentRoute.value.name !== 'login' && { redirect }),
|
||||
},
|
||||
}).then(logoutCleanStatus)
|
||||
}
|
||||
|
||||
// 请求登出
|
||||
function requestLogout() {
|
||||
localStorage.removeItem('token')
|
||||
token.value = ''
|
||||
router.push({
|
||||
name: 'login',
|
||||
query: {
|
||||
...(
|
||||
router.currentRoute.value.fullPath !== appSettingsStore.settings.app.home.fullPath
|
||||
&& router.currentRoute.value.name !== 'login'
|
||||
&& {
|
||||
redirect: router.currentRoute.value.fullPath,
|
||||
}
|
||||
),
|
||||
},
|
||||
}).then(logoutCleanStatus)
|
||||
}
|
||||
|
||||
// 登出后清除状态
|
||||
function logoutCleanStatus() {
|
||||
localStorage.removeItem('account')
|
||||
localStorage.removeItem('avatar')
|
||||
account.value = ''
|
||||
avatar.value = ''
|
||||
permissions.value = []
|
||||
appSettingsStore.updateSettings({}, true)
|
||||
appTabbarStore.clean()
|
||||
appRouteStore.removeRoutes()
|
||||
appMenuStore.setActived(0)
|
||||
}
|
||||
|
||||
// 获取权限
|
||||
async function getPermissions() {
|
||||
const res = await apiApp.permission()
|
||||
permissions.value = res.data.permissions
|
||||
}
|
||||
|
||||
// 修改密码
|
||||
async function editPassword(data: {
|
||||
password: string
|
||||
newPassword: string
|
||||
}) {
|
||||
await apiApp.passwordEdit(data)
|
||||
}
|
||||
|
||||
return {
|
||||
token,
|
||||
account,
|
||||
avatar,
|
||||
permissions,
|
||||
isLogin,
|
||||
login,
|
||||
logout,
|
||||
requestLogout,
|
||||
getPermissions,
|
||||
editPassword,
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
export const useAppKeepAliveStore = defineStore(
|
||||
'appKeepAlive',
|
||||
() => {
|
||||
const list = ref<string[]>([])
|
||||
|
||||
function add(name: string | string[]) {
|
||||
if (typeof name === 'string') {
|
||||
!list.value.includes(name) && list.value.push(name)
|
||||
}
|
||||
else {
|
||||
name.forEach((v) => {
|
||||
v && !list.value.includes(v) && list.value.push(v)
|
||||
})
|
||||
}
|
||||
}
|
||||
function remove(name: string | string[]) {
|
||||
if (typeof name === 'string') {
|
||||
list.value = list.value.filter((v) => {
|
||||
return v !== name
|
||||
})
|
||||
}
|
||||
else {
|
||||
list.value = list.value.filter((v) => {
|
||||
return !name.includes(v)
|
||||
})
|
||||
}
|
||||
}
|
||||
function clean() {
|
||||
list.value = []
|
||||
}
|
||||
|
||||
return {
|
||||
list,
|
||||
add,
|
||||
remove,
|
||||
clean,
|
||||
}
|
||||
},
|
||||
)
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
import type { MenuRecordMainRaw, MenuRecordRaw, RouteRecordMainRaw } from '@fantastic-admin/types'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import { cloneDeep } from 'es-toolkit'
|
||||
import { resolveRoutePath } from '@/utils'
|
||||
|
||||
export const useAppMenuStore = defineStore(
|
||||
'appMenu',
|
||||
() => {
|
||||
const appSettingsStore = useAppSettingsStore()
|
||||
const appRouteStore = useAppRouteStore()
|
||||
|
||||
// 将原始路由转换成导航菜单
|
||||
function convertRouteToMenu(routes: RouteRecordMainRaw[]): MenuRecordMainRaw[] {
|
||||
const returnMenus: MenuRecordMainRaw[] = []
|
||||
routes.forEach((item) => {
|
||||
if (item.children.length > 0) {
|
||||
if (appSettingsStore.settings.menu.mode === 'single') {
|
||||
returnMenus.length === 0 && returnMenus.push({
|
||||
meta: {},
|
||||
children: [],
|
||||
})
|
||||
returnMenus[0].children.push(...convertRouteToMenuRecursive(item.children))
|
||||
}
|
||||
else {
|
||||
const menuItem: MenuRecordMainRaw = {
|
||||
meta: {
|
||||
title: item?.meta?.title,
|
||||
icon: item?.meta?.icon,
|
||||
auth: item?.meta?.auth,
|
||||
},
|
||||
children: [],
|
||||
}
|
||||
menuItem.children = convertRouteToMenuRecursive(item.children)
|
||||
returnMenus.push(menuItem)
|
||||
}
|
||||
}
|
||||
})
|
||||
return returnMenus
|
||||
}
|
||||
function convertRouteToMenuRecursive(routes: RouteRecordRaw[], basePath = ''): MenuRecordRaw[] {
|
||||
const returnMenus: MenuRecordRaw[] = []
|
||||
routes.forEach((item) => {
|
||||
const menuItem: MenuRecordRaw = {
|
||||
path: resolveRoutePath(basePath, item.path),
|
||||
meta: {
|
||||
auth: item?.meta?.auth,
|
||||
title: item?.meta?.title,
|
||||
icon: item?.meta?.icon,
|
||||
menu: item?.meta?.menu,
|
||||
expand: item?.meta?.expand,
|
||||
link: item?.meta?.link,
|
||||
},
|
||||
}
|
||||
if (item.children) {
|
||||
menuItem.children = convertRouteToMenuRecursive(item.children, menuItem.path)
|
||||
}
|
||||
returnMenus.push(menuItem)
|
||||
})
|
||||
return returnMenus
|
||||
}
|
||||
|
||||
// 完整导航数据
|
||||
const allMenus = computed(() => filterAsyncMenus(convertRouteToMenu(appRouteStore.routesRaw)))
|
||||
|
||||
function normalizeActivedIndex(index: number) {
|
||||
if (allMenus.value.length === 0) {
|
||||
return 0
|
||||
}
|
||||
if (Number.isNaN(index) || index < 0) {
|
||||
return 0
|
||||
}
|
||||
if (index >= allMenus.value.length) {
|
||||
return allMenus.value.length - 1
|
||||
}
|
||||
return index
|
||||
}
|
||||
// 原始记录值:保存最近一次被设置的主导航索引
|
||||
// 当 allMenus 变化后,它可能暂时变成过期值,因此不应该直接在外部使用
|
||||
const activedOriginal = ref(0)
|
||||
// 对外可用值:始终基于 allMenus 当前长度做安全修正
|
||||
// 外部读取 actived 时,拿到的一定是当前有效索引
|
||||
const actived = computed({
|
||||
get: () => normalizeActivedIndex(activedOriginal.value),
|
||||
set: value => activedOriginal.value = normalizeActivedIndex(value),
|
||||
})
|
||||
|
||||
// 次导航数据
|
||||
const sidebarMenus = computed<MenuRecordMainRaw['children']>(() => {
|
||||
return allMenus.value.length > 0
|
||||
? allMenus.value[normalizeActivedIndex(actived.value)].children
|
||||
: []
|
||||
})
|
||||
// 次导航第一层最深路径
|
||||
const sidebarMenusFirstDeepestPath = computed(() => {
|
||||
return sidebarMenus.value.length > 0
|
||||
? getDeepestPath(sidebarMenus.value[0])
|
||||
: appSettingsStore.settings.app.home.fullPath
|
||||
})
|
||||
function getDeepestPath(menu: MenuRecordRaw, rootPath = '') {
|
||||
let retnPath = ''
|
||||
if (menu.children?.some(item => item.meta?.menu !== false)) {
|
||||
const item = menu.children.find(item => item.meta?.menu !== false)
|
||||
if (item) {
|
||||
retnPath = getDeepestPath(item, resolveRoutePath(rootPath, menu.path))
|
||||
}
|
||||
else {
|
||||
retnPath = getDeepestPath(menu.children[0], resolveRoutePath(rootPath, menu.path))
|
||||
}
|
||||
}
|
||||
else {
|
||||
retnPath = resolveRoutePath(rootPath, menu.path)
|
||||
}
|
||||
return retnPath
|
||||
}
|
||||
// 次导航是否有且只有一个可访问的菜单
|
||||
const sidebarMenusHasOnlyMenu = computed(() => {
|
||||
return isSidebarMenusHasOnlyMenu(sidebarMenus.value)
|
||||
})
|
||||
function isSidebarMenusHasOnlyMenu(menus: MenuRecordRaw[]) {
|
||||
let count = 0
|
||||
let isOnly = true
|
||||
menus.forEach((menu) => {
|
||||
if (menu.meta?.menu !== false) {
|
||||
count++
|
||||
}
|
||||
if (menu.children) {
|
||||
isOnly = isSidebarMenusHasOnlyMenu(menu.children)
|
||||
}
|
||||
})
|
||||
return count <= 1 && isOnly
|
||||
}
|
||||
|
||||
function getExpandPaths(menus: MenuRecordRaw[], rootPath = '') {
|
||||
const expandPaths: string[] = []
|
||||
menus.forEach((item) => {
|
||||
if (item.children) {
|
||||
if (item.meta?.expand) {
|
||||
expandPaths.push(resolveRoutePath(rootPath, item.path))
|
||||
}
|
||||
const childrenExpandPaths = getExpandPaths(item.children, resolveRoutePath(rootPath, item.path))
|
||||
if (childrenExpandPaths.length > 0) {
|
||||
expandPaths.push(...childrenExpandPaths)
|
||||
}
|
||||
}
|
||||
})
|
||||
return expandPaths
|
||||
}
|
||||
// 默认展开的导航路径
|
||||
const defaultExpandPaths = computed(() => {
|
||||
const defaultExpandPaths: string[] = []
|
||||
allMenus.value.forEach((item) => {
|
||||
defaultExpandPaths.push(...getExpandPaths(item.children))
|
||||
})
|
||||
return defaultExpandPaths
|
||||
})
|
||||
|
||||
const auth = useAppAuth()
|
||||
// 根据权限过滤导航
|
||||
function filterAsyncMenus<T extends MenuRecordMainRaw[] | MenuRecordRaw[]>(menus: T): T {
|
||||
const res: any = []
|
||||
menus.forEach((menu) => {
|
||||
if (auth.auth(menu.meta?.auth ?? '')) {
|
||||
const tmpMenu = cloneDeep(menu)
|
||||
if (tmpMenu.children && tmpMenu.children.length > 0) {
|
||||
tmpMenu.children = filterAsyncMenus(tmpMenu.children) as MenuRecordRaw[]
|
||||
tmpMenu.children.length > 0 && res.push(tmpMenu)
|
||||
}
|
||||
else {
|
||||
delete tmpMenu.children
|
||||
res.push(tmpMenu)
|
||||
}
|
||||
}
|
||||
})
|
||||
return res
|
||||
}
|
||||
// 设置主导航
|
||||
function isPathInMenus(menus: MenuRecordRaw[], path: string) {
|
||||
let flag = false
|
||||
flag = menus.some((item) => {
|
||||
if (item.children) {
|
||||
return isPathInMenus(item.children, path)
|
||||
}
|
||||
return path.indexOf(`${item.path}/`) === 0 || path === item.path
|
||||
})
|
||||
return flag
|
||||
}
|
||||
function setActived(indexOrPath: number | string) {
|
||||
if (typeof indexOrPath === 'number') {
|
||||
// 如果是 number 类型,则认为是主导航的索引
|
||||
actived.value = indexOrPath
|
||||
}
|
||||
else {
|
||||
// 如果是 string 类型,则认为是路由,需要查找对应的主导航索引
|
||||
const findIndex = allMenus.value.findIndex(item => isPathInMenus(item.children, indexOrPath))
|
||||
if (findIndex >= 0) {
|
||||
actived.value = findIndex
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
actived,
|
||||
allMenus,
|
||||
sidebarMenus,
|
||||
sidebarMenusFirstDeepestPath,
|
||||
sidebarMenusHasOnlyMenu,
|
||||
defaultExpandPaths,
|
||||
setActived,
|
||||
}
|
||||
},
|
||||
)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user