Compare commits

...

58 Commits
v0.9.4 ... main

Author SHA1 Message Date
chansee97
a5c3697a6b chore: bump version to 0.9.12 and update dependencies 2025-04-05 17:43:46 +08:00
chansee97
d97306d5b5 chore: bump version to 0.9.11 2025-03-27 22:08:06 +08:00
chenxin
99840ed604 style: add cursor pointer style to user avatar 2025-03-14 14:52:43 +08:00
chansee97
75dd7b0c83 chore: update dependencies to latest versions 2025-03-05 21:28:54 +08:00
chansee97
2f2d8726d4 Merge branch 'main' of https://github.com/chansee97/nova-admin 2025-01-20 22:47:46 +08:00
chansee97
30f0ac0904 feat: remove support single role permission 2025-01-20 22:47:43 +08:00
Rock Chen
5cb0ca39dd feat: add draggable tab bar items and refactor tab rendering 2025-01-16 13:12:24 +00:00
chansee97
e5222bbbc6 docs: update WeChat group information and clarify adding purpose 2025-01-08 17:07:52 +08:00
chansee97
52614819e8 chore: update version to 0.9.10 2025-01-06 11:50:26 +08:00
chansee97
4f31476cf8 chore: updata deps 2025-01-05 12:35:41 +08:00
chansee97
85b0826eea feat: file collpse 2024-12-24 10:59:19 +08:00
chansee97
5975d05437 fix: copy i18n 2024-12-24 10:45:44 +08:00
AnsonCar
aa9aece0ca
feat: Add docker support to enhance project scalability and deployment efficiency (#43)
* docs: update readme Install and use

* feat: add docker

* feat: add nginx.conf

* fix: change Traditional Chinese to Simplified Chinese
2024-11-23 20:47:56 +08:00
chansee97
a487141cfb chore: updata deps 2024-11-06 22:56:31 +08:00
chansee97
e7148081a9 modify: support multi tabs 2024-10-08 12:37:27 +08:00
chansee97
308e0b4bf9 fix: rich editor error type 2024-09-26 22:44:44 +08:00
Ray.D.Song
367406258c
fix: Sass legacy JS API warn (#39)
* feat: draggable list & useTableDrag hook

* fix: sass deprecated legacy JS API
2024-09-25 12:33:57 +08:00
Ray.D.Song
aee3e52f15
feat: draggable list & useTableDrag hook (#38) 2024-09-24 11:23:52 +08:00
chansee97
89d78b7ec7 fix: useEcharts updata error 2024-09-22 23:23:15 +08:00
chansee97
242c94723b fix: dict function error 2024-09-19 00:50:10 +08:00
chansee97
dc3563969b fix: import error 2024-09-16 00:03:06 +08:00
chansee97
7da454563b fix: import order 2024-09-14 08:09:20 +08:00
chenxin
e450a029ac feat: adapt vue3.5 feat 2024-09-05 17:05:55 +08:00
chenxin
c14ebc2343 refactor: organize file dir 2024-09-05 16:02:24 +08:00
chansee97
5e88b8d01f fix: map name error 2024-08-31 00:35:39 +08:00
chansee97
5fb8881763 fix: modify echart bg color 2024-08-24 00:43:31 +08:00
chansee97
efc1ccbc9a fix: remove DemoList type 2024-08-21 00:21:57 +08:00
chansee97
f20d2a5fb6 fix:typo 2024-08-21 00:07:17 +08:00
chansee97
fad054e8df fix: chart & qrcode demo error 2024-08-19 08:26:37 +08:00
chansee97
df0cf9f72b chore: update deps 2024-08-14 22:33:01 +08:00
chansee97
d69bd796a4 refactor: env var 2024-08-09 00:49:55 +08:00
TianQian
a9c7708119
fix: 为 createServerTokenAuthentication 添加 statesHook 类型 (#32) 2024-08-08 23:48:09 +08:00
chansee97
de4cd17548 chore: update alova version 2024-08-03 07:02:28 +08:00
chansee97
70c43a276c fix: type error 2024-07-29 22:31:48 +08:00
chansee97
5cc410c7b4 fix: type error & local icon error 2024-07-25 22:40:12 +08:00
chansee97
5c24fa1502 fix: readme error mock url 2024-07-20 01:04:51 +08:00
chansee97
4d82a24d22 chore: update deps 2024-07-20 00:54:13 +08:00
chansee97
20d9fbef2e fix: close i18n warn 2024-07-20 00:28:43 +08:00
chansee97
4b1d3f2912 fix: typo 2024-07-16 18:44:50 +08:00
chansee97
6c03ef53a3 fix: header style error 2024-07-15 13:13:55 +08:00
chansee97
23afe39c65 feat: add content full screen 2024-07-12 14:41:48 +08:00
chansee97
309d723e43 fix: dict error import 2024-07-12 13:35:11 +08:00
chansee97
0e9bf396f3 feat: move dict to utils 2024-07-12 13:31:56 +08:00
chansee97
2c0b2fb26c Merge branch 'main' of https://github.com/chansee97/nova-admin 2024-07-09 14:34:18 +08:00
chansee97
daf3cf9ca7 docs: modify site url 2024-07-09 14:20:18 +08:00
chansee97
48054e04f9 fix: perfect dict menu 2024-07-07 00:29:04 +08:00
chansee97
6b40f45ae3 feat: add dict utils 2024-07-06 02:53:57 +08:00
chansee97
0741c564dd fix: init rich-text fail 2024-06-30 14:40:55 +08:00
chansee97
2305fff569 fix: required dictValue 2024-06-27 00:28:41 +08:00
chansee97
cf76ef71f7 feat: add dict page 2024-06-27 00:24:34 +08:00
chansee97
e7c6f7c177 Merge branch 'main' of https://github.com/chansee97/nova-admin 2024-06-26 21:00:36 +08:00
chansee97
eb82842fad fix: perfect copy componet 2024-06-26 21:00:08 +08:00
chansee97
e1d440b45a fix: perfect copy componet 2024-06-26 20:41:39 +08:00
chansee97
1a1ffcb9aa chore: remove pinia-plugin-persist 2024-06-26 19:28:25 +08:00
chansee97
8981f42571 fix: layout typo 2024-06-26 19:19:29 +08:00
chansee97
21544139df fix: update vue-devtools 2024-06-25 00:51:56 +08:00
chansee97
9ce6bd3b86 feat: add mix layout 2024-06-25 00:27:37 +08:00
chansee97
8f5f11f4d3 chore: update dps 2024-06-17 10:30:40 +08:00
116 changed files with 1954 additions and 6433 deletions

8
.dockerignore Normal file
View File

@ -0,0 +1,8 @@
/node_modules
/.git
/.gitignore
/.vscode
/.DS_Store
/*.md
/dist

22
.env
View File

@ -1,20 +1,26 @@
# 项目根目录 # 项目根目录
VITE_BASE_URL=/ VITE_BASE_URL = /
# 项目名称 # 项目名称
VITE_APP_NAME=Nova - Admin VITE_APP_NAME = Nova - Admin
# 路由模式
# 路由模式 web hash
VITE_ROUTE_MODE = web VITE_ROUTE_MODE = web
# 权限路由模式: static dynamic
VITE_AUTH_ROUTE_MODE=dynamic # 路由加载模式 static dynamic
VITE_ROUTE_LOAD_MODE = static
# 设置登陆后跳转地址 # 设置登陆后跳转地址
VITE_HOME_PATH = /dashboard/workbench VITE_HOME_PATH = /dashboard/workbench
# 本地存储前缀 # 本地存储前缀
VITE_STORAGE_PREFIX= VITE_STORAGE_PREFIX =
# 版权信息 # 版权信息
VITE_COPYRIGHT_INFO= Copyright © 2024 chansee97 VITE_COPYRIGHT_INFO = Copyright © 2024 chansee97
# 自动刷新token # 自动刷新token
VITE_AUTO_REFRESH_TOKEN=Y VITE_AUTO_REFRESH_TOKEN = Y
# 默认多语言 enUS | zhCN
VITE_DEFAULT_LANG = enUS

1
.github/FUNDING.yml vendored
View File

@ -1 +0,0 @@
custom: ['https://cdn.jsdelivr.net/gh/chansee97/static/sponsor-wechat.png', 'https://cdn.jsdelivr.net/gh/chansee97/static/sponsor-alipay.png']

View File

@ -36,7 +36,7 @@ body:
options: options:
- label: Ensure this issue not a bug proposal. - label: Ensure this issue not a bug proposal.
required: true required: true
- label: Read the [docs](https://nova-admin-docs.netlify.app/). - label: Read the [docs](https://nova-admin-docs.pages.dev/).
required: true required: true
- label: Check that there isn't [already an issue](https://github.com/chansee97/nova-admin/issues) that descript the same thing to avoid creating a duplicate. - label: Check that there isn't [already an issue](https://github.com/chansee97/nova-admin/issues) that descript the same thing to avoid creating a duplicate.
required: true required: true

View File

@ -39,7 +39,7 @@ body:
options: options:
- label: Ensure this issue not a feature proposal. - label: Ensure this issue not a feature proposal.
required: true required: true
- label: Read the [docs](https://nova-admin-docs.netlify.app/). - label: Read the [docs](https://nova-admin-docs.pages.dev/).
required: true required: true
- label: Check that there isn't [already an issue](https://github.com/chansee97/nova-admin/issues) that descript the same thing to avoid creating a duplicate. - label: Check that there isn't [already an issue](https://github.com/chansee97/nova-admin/issues) that descript the same thing to avoid creating a duplicate.
required: true required: true

View File

@ -25,7 +25,7 @@ body:
options: options:
- label: Ensure this issue neither a bug report nor a feature proposal. - label: Ensure this issue neither a bug report nor a feature proposal.
required: true required: true
- label: Read the [docs](https://nova-admin-docs.netlify.app/). - label: Read the [docs](https://nova-admin-docs.pages.dev/).
required: true required: true
- label: Check that there isn't [already an issue](https://github.com/chansee97/nova-admin/issues) that descript the same thing to avoid creating a duplicate. - label: Check that there isn't [already an issue](https://github.com/chansee97/nova-admin/issues) that descript the same thing to avoid creating a duplicate.
required: true required: true

3
.gitignore vendored
View File

@ -27,3 +27,6 @@ stats.html
components.d.ts components.d.ts
auto-imports.d.ts auto-imports.d.ts
# Lock files
*-lock.yaml

76
.vscode/settings.json vendored
View File

@ -1,6 +1,4 @@
{ {
// Enable the ESlint flat config support
"eslint.experimental.useFlatConfig": true,
// Disable the default formatter, use eslint instead // Disable the default formatter, use eslint instead
"prettier.enable": false, "prettier.enable": false,
"editor.formatOnSave": false, "editor.formatOnSave": false,
@ -11,46 +9,16 @@
}, },
// Silent the stylistic rules in you IDE, but still auto fix them // Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [ "eslint.rules.customizations": [
{ { "rule": "style/*", "severity": "off" },
"rule": "style/*", { "rule": "format/*", "severity": "off" },
"severity": "off" { "rule": "*-indent", "severity": "off" },
}, { "rule": "*-spacing", "severity": "off" },
{ { "rule": "*-spaces", "severity": "off" },
"rule": "format/*", { "rule": "*-order", "severity": "off" },
"severity": "off" { "rule": "*-dangle", "severity": "off" },
}, { "rule": "*-newline", "severity": "off" },
{ { "rule": "*quotes", "severity": "off" },
"rule": "*-indent", { "rule": "*semi", "severity": "off" }
"severity": "off"
},
{
"rule": "*-spacing",
"severity": "off"
},
{
"rule": "*-spaces",
"severity": "off"
},
{
"rule": "*-order",
"severity": "off"
},
{
"rule": "*-dangle",
"severity": "off"
},
{
"rule": "*-newline",
"severity": "off"
},
{
"rule": "*quotes",
"severity": "off"
},
{
"rule": "*semi",
"severity": "off"
}
], ],
// Enable eslint for all supported languages // Enable eslint for all supported languages
"eslint.validate": [ "eslint.validate": [
@ -64,7 +32,16 @@
"json", "json",
"jsonc", "jsonc",
"yaml", "yaml",
"toml" "toml",
"xml",
"gql",
"graphql",
"astro",
"css",
"less",
"scss",
"pcss",
"postcss"
], ],
"i18n-ally.sourceLanguage": "zh_CN", "i18n-ally.sourceLanguage": "zh_CN",
"i18n-ally.displayLanguage": "zh_CN", "i18n-ally.displayLanguage": "zh_CN",
@ -74,5 +51,16 @@
"i18n-ally.localesPaths": [ "i18n-ally.localesPaths": [
"locales" "locales"
], ],
"commentTranslate.source": "Google" // File collapse
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.expand": false,
"explorer.fileNesting.patterns": {
"*.ts": "$(capture).test.ts, $(capture).test.tsx, $(capture).spec.ts, $(capture).spec.tsx, $(capture).d.ts",
"*.tsx": "$(capture).test.ts, $(capture).test.tsx, $(capture).spec.ts, $(capture).spec.tsx,$(capture).d.ts",
"*.env": "$(capture).env.*",
"README.md": "README*,CHANGELOG*,LICENSE,CNAME",
"package.json": "pnpm-lock.yaml,pnpm-workspace.yaml,.gitattributes,.gitignore,.gitpod.yml,.npmrc,.browserslistrc,.node-version,.git*,.tazerc.json",
"eslint.config.js": ".eslintignore,.prettierignore,.stylelintignore,.commitlintrc.*,.prettierrc.*,stylelint.config.*,.lintstagedrc.mjs,cspell.json",
"docker-compose.product.yml": ".dockerignore,nginx.conf"
}
} }

View File

@ -19,8 +19,8 @@
[Nova-admin](https://github.com/chansee97/nova-admin) is a clean and concise back-end management template based on Vue3, Vite5, Typescript, and Naive UI. It implements complete functionality in a simple way, while also considering code standards, readability, and avoiding excessive encapsulation to facilitate secondary development. [Nova-admin](https://github.com/chansee97/nova-admin) is a clean and concise back-end management template based on Vue3, Vite5, Typescript, and Naive UI. It implements complete functionality in a simple way, while also considering code standards, readability, and avoiding excessive encapsulation to facilitate secondary development.
- [Nova-Admin preview](https://nova-admin-site.netlify.app/) - [Nova-Admin preview](https://nova-admin.pages.dev/)
- [Nova-Admin docs](https://nova-admin-docs.netlify.app/) - [Nova-Admin docs](https://nova-admin-docs.pages.dev/)
## Features ## Features
@ -51,7 +51,7 @@
## Interface document ## Interface document
This project uses ApiFox for interface mock, check the online documentation for more interface details This project uses ApiFox for interface mock, check the online documentation for more interface details
[online aipfox docs](https://apifox.com/apidoc/shared-2b1abeb5-6e78-425e-a4ff-d7277ae83bf0) [online aipfox docs](https://nova-admin.apifox.cn)
## Install and use ## Install and use
@ -71,6 +71,13 @@ pnpm build
``` ```
You can deploy **nova-admin** in a production environment using docker-compose.
```bash
# Build product
docker compose -f docker-compose.product.yml up --build -d
```
> The nginx.conf provided is for reference only. You can adjust it according to your own needs.
## Related projects ## Related projects
- [Nova-admin-nest](https://github.com/chansee97/nove-admin-nest) (under development) Nova-Admin supporting background project based on TS, NestJs, typeorm - [Nova-admin-nest](https://github.com/chansee97/nove-admin-nest) (under development) Nova-Admin supporting background project based on TS, NestJs, typeorm
@ -79,11 +86,11 @@ pnpm build
Nova-Admin is a completely open-source and free project. It is still being optimized and iterated. It is designed to help developers more conveniently develop medium and large management systems. If you have any questions, please ask questions in the QQ exchange group. Nova-Admin is a completely open-source and free project. It is still being optimized and iterated. It is designed to help developers more conveniently develop medium and large management systems. If you have any questions, please ask questions in the QQ exchange group.
| Q-Group | wechat-Group |wechat | | Q-Group | wechat-Group |
| :--: |:--: |:--: | | :--: |:--: |
| <img src="https://cdn.jsdelivr.net/gh/chansee97/static/nova-admin/q-group.png" width=170> | <img src="https://cdn.jsdelivr.net/gh/chansee97/static/nova-admin/wx-group.png" width=170>|<img src="https://cdn.jsdelivr.net/gh/chansee97/static/wechat.png" width=170>| | <img src="https://cdn.jsdelivr.net/gh/chansee97/static/nova-admin/q-group.png" width=170> |<img src="https://cdn.jsdelivr.net/gh/chansee97/static/wechat.png" width=170>|
> The WeChat group QR code is invalid, please add me as a friend. > Please indicate the purpose of adding WeChat.
## Contribution ## Contribution

View File

@ -19,8 +19,8 @@
[Nova-admin](https://github.com/chansee97/nova-admin)是一个基于Vue3、Vite5、Typescript、Naive UI, 简洁干净后台管理模板,用简单的方式实现完整功能,并尽可能的考虑代码规范,易读易理解无过度封装,方便二次开发。 [Nova-admin](https://github.com/chansee97/nova-admin)是一个基于Vue3、Vite5、Typescript、Naive UI, 简洁干净后台管理模板,用简单的方式实现完整功能,并尽可能的考虑代码规范,易读易理解无过度封装,方便二次开发。
- [Nova-Admin 预览](https://nova-admin-site.netlify.app/) - [Nova-Admin 预览](https://nova-admin.pages.dev/)
- [Nova-Admin 文档](https://nova-admin-docs.netlify.app/) - [Nova-Admin 文档](https://nova-admin-docs.pages.dev/)
## 特性 ## 特性
@ -51,7 +51,7 @@
## 接口文档 ## 接口文档
本项目使用ApiFox进行接口mock查看在线文档以了解更多接口详情 本项目使用ApiFox进行接口mock查看在线文档以了解更多接口详情
[在线apifox文档](https://apifox.com/apidoc/shared-2b1abeb5-6e78-425e-a4ff-d7277ae83bf0) [在线apifox文档](https://nova-admin.apifox.cn)
## 安装使用 ## 安装使用
@ -71,6 +71,13 @@ pnpm build
``` ```
在生产环境也可以使用 docker-compose 部署 **nova-admin**
```bash
# Build product
docker compose -f docker-compose.product.yml up --build -d
```
> 关于 nginx.conf 只供参考,你可以根据自己的需求进行调整。
## 相关项目 ## 相关项目
- [Nova-admin-nest](https://github.com/chansee97/nove-admin-nest) (开发中)基于TS, NestJs, typeorm的Nova-Admin配套后台项目 - [Nova-admin-nest](https://github.com/chansee97/nove-admin-nest) (开发中)基于TS, NestJs, typeorm的Nova-Admin配套后台项目
@ -79,11 +86,11 @@ pnpm build
Nova-Admin 是完全开源免费的项目,目前仍然在优化迭代中,旨在帮助开发者更方便地进行中大型管理系统开发,有使用问题欢迎在交流群内提问。 Nova-Admin 是完全开源免费的项目,目前仍然在优化迭代中,旨在帮助开发者更方便地进行中大型管理系统开发,有使用问题欢迎在交流群内提问。
| Q群 | 微信群 | 个人微信 | | Q群 | 微信群 |
| :--: |:--: |:--: | | :--: |:--: |
| <img src="https://cdn.jsdelivr.net/gh/chansee97/static/nova-admin/q-group.png" width=170> | <img src="https://cdn.jsdelivr.net/gh/chansee97/static/nova-admin/wx-group.png" width=170>|<img src="https://cdn.jsdelivr.net/gh/chansee97/static/wechat.png" width=170>| | <img src="https://cdn.jsdelivr.net/gh/chansee97/static/nova-admin/q-group.png" width=170> |<img src="https://cdn.jsdelivr.net/gh/chansee97/static/wechat.png" width=170>|
> 微信群二维码失效请加我为好友 > 添加微信请注明来意
## 贡献 ## 贡献

View File

@ -1,16 +1,16 @@
import UnoCSS from '@unocss/vite' import UnoCSS from '@unocss/vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx' import vueJsx from '@vitejs/plugin-vue-jsx'
import VueDevTools from 'vite-plugin-vue-devtools'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite' import AutoImport from 'unplugin-auto-import/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import viteCompression from 'vite-plugin-compression'
import Icons from 'unplugin-icons/vite'
import { FileSystemIconLoader } from 'unplugin-icons/loaders' import { FileSystemIconLoader } from 'unplugin-icons/loaders'
// https://github.com/antfu/unplugin-icons // https://github.com/antfu/unplugin-icons
import IconsResolver from 'unplugin-icons/resolver' import IconsResolver from 'unplugin-icons/resolver'
import Icons from 'unplugin-icons/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
import viteCompression from 'vite-plugin-compression'
import VueDevTools from 'vite-plugin-vue-devtools'
/** /**
* @description: vite插件配置 * @description: vite插件配置

View File

@ -0,0 +1,8 @@
services:
nove-admin:
build:
context: .
dockerfile: ./docker/dockerfile.product
container_name: nove-admin
ports:
- 80:80

23
docker/dockerfile.product Normal file
View File

@ -0,0 +1,23 @@
FROM node:20-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
COPY . /app
WORKDIR /app
FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
FROM base AS builder
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run build
FROM nginx:1.23.1-alpine
WORKDIR /www
COPY --from=builder /app/dist/ .
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

View File

@ -2,4 +2,21 @@
import antfu from '@antfu/eslint-config' import antfu from '@antfu/eslint-config'
// https://github.com/antfu/eslint-config // https://github.com/antfu/eslint-config
export default antfu() export default antfu(
{
typescript: {
overrides: {
'perfectionist/sort-exports': 'off',
'perfectionist/sort-imports': 'off',
'ts/no-unused-expressions': ['error', { allowShortCircuit: true }],
},
},
vue: {
overrides: {
'vue/no-unused-refs': 'off', // 暂时关闭等待vue-lint的分支合并
'vue/no-reserved-component-names': 'off',
'vue/component-definition-name-casing': 'off',
},
},
},
)

View File

@ -14,7 +14,7 @@
"loginOutContent": "Confirm to log out of current account?", "loginOutContent": "Confirm to log out of current account?",
"loginOutTitle": "Sign out", "loginOutTitle": "Sign out",
"userCenter": "Personal center", "userCenter": "Personal center",
"lignt": "Light", "light": "Light",
"dark": "Dark", "dark": "Dark",
"system": "System", "system": "System",
"backTop": "Back to top", "backTop": "Back to top",
@ -42,6 +42,7 @@
"themeSetting": "Theme settings", "themeSetting": "Theme settings",
"todos": "Todos", "todos": "Todos",
"toggleFullScreen": "Toggle full screen", "toggleFullScreen": "Toggle full screen",
"togglContentFullScreen": "Toggle content full screen",
"topProgress": "Top progress", "topProgress": "Top progress",
"transitionFadeBottom": "Bottom fade", "transitionFadeBottom": "Bottom fade",
"transitionFadeScale": "Scale fade", "transitionFadeScale": "Scale fade",
@ -59,7 +60,8 @@
"getRouteError": "Failed to obtain route, please try again later.", "getRouteError": "Failed to obtain route, please try again later.",
"layoutSetting": "Layout settings", "layoutSetting": "Layout settings",
"leftMenu": "Left menu", "leftMenu": "Left menu",
"topMenu": "Top menu" "topMenu": "Top menu",
"mixMenu": "Mix menu"
}, },
"login": { "login": {
"signInTitle": "Login", "signInTitle": "Login",
@ -87,17 +89,18 @@
"route": { "route": {
"appRoot": "Home", "appRoot": "Home",
"cardList": "Card list", "cardList": "Card list",
"draggableList": "Draggable list",
"commonList": "Common list", "commonList": "Common list",
"dashboard": "Dashboard", "dashboard": "Dashboard",
"demo": "Function example", "demo": "Function example",
"fetch": "Request example", "fetch": "Request example",
"list": "List", "list": "List",
"monitor": "Monitoring", "monitor": "Monitoring",
"test": "Multi-level menu", "multi": "Multi-level menu",
"test2": "Multi-level menu subpage", "multi2": "Multi-level menu subpage",
"test2Detail": "Details page of multi-level menu", "multi2Detail": "Details page of multi-level menu",
"test3": "multi-level menu", "multi3": "multi-level menu",
"test4": "Multi-level menu 3-1", "multi4": "Multi-level menu 3-1",
"workbench": "Workbench", "workbench": "Workbench",
"QRCode": "QR code", "QRCode": "QR code",
"about": "About", "about": "About",
@ -106,10 +109,11 @@
"demo404": "404", "demo404": "404",
"demo500": "500", "demo500": "500",
"dictionarySetting": "Dictionary settings", "dictionarySetting": "Dictionary settings",
"docments": "Document", "documents": "Document",
"docmentsVite": "Vite", "documentsVite": "Vite",
"docmentsVue": "Vue", "documentsVue": "Vue",
"docmentsVueuse": "VueUse (external link)", "documentsVueuse": "VueUse (external link)",
"documentsNova": "Nova docs",
"echarts": "Echarts", "echarts": "Echarts",
"editor": "Editor", "editor": "Editor",
"editorMd": "MarkDown editor", "editorMd": "MarkDown editor",
@ -124,7 +128,8 @@
"setting": "System settings", "setting": "System settings",
"userCenter": "Personal Center", "userCenter": "Personal Center",
"accountSetting": "User settings", "accountSetting": "User settings",
"cascader": "Administrative region selection" "cascader": "Administrative region selection",
"dict": "Dictionary example"
}, },
"http": { "http": {
"400": "Syntax error in the request", "400": "Syntax error in the request",
@ -147,6 +152,12 @@
"searchPlaceholder": "Search icon", "searchPlaceholder": "Search icon",
"clearIcon": "Clear icon", "clearIcon": "Clear icon",
"selectorTitle": "Icon selection" "selectorTitle": "Icon selection"
},
"copyText": {
"message": "Copied successfully",
"tooltip": "Copy",
"unsupportedError": "Your browser does not support Clipboard API",
"unpermittedError": "Crrently not permitted to use Clipboard API"
} }
} }
} }

View File

@ -14,12 +14,13 @@
"loginOutTitle": "退出登录", "loginOutTitle": "退出登录",
"loginOutContent": "确认退出当前账号?", "loginOutContent": "确认退出当前账号?",
"userCenter": "个人中心", "userCenter": "个人中心",
"lignt": "浅色", "light": "浅色",
"dark": "深色", "dark": "深色",
"system": "跟随系统", "system": "跟随系统",
"backTop": "返回顶部", "backTop": "返回顶部",
"toggleSider": "切换侧边栏", "toggleSider": "切换侧边栏",
"toggleFullScreen": "切换全屏", "toggleFullScreen": "切换全屏",
"togglContentFullScreen": "切换内容全屏",
"notificationsTips": "消息通知", "notificationsTips": "消息通知",
"notifications": "通知", "notifications": "通知",
"messages": "消息", "messages": "消息",
@ -59,7 +60,8 @@
"getRouteError": "获取路由失败,请稍后再试", "getRouteError": "获取路由失败,请稍后再试",
"layoutSetting": "布局设置", "layoutSetting": "布局设置",
"leftMenu": "左侧菜单", "leftMenu": "左侧菜单",
"topMenu": "顶部菜单" "topMenu": "顶部菜单",
"mixMenu": "混合菜单"
}, },
"http": { "http": {
"400": "请求出现语法错误", "400": "请求出现语法错误",
@ -82,6 +84,12 @@
"inputPlaceholder": "选择目标图标", "inputPlaceholder": "选择目标图标",
"searchPlaceholder": "搜索图标", "searchPlaceholder": "搜索图标",
"clearIcon": "清除图标" "clearIcon": "清除图标"
},
"copyText": {
"tooltip": "复制",
"message": "复制成功",
"unsupportedError": "您的浏览器不支持剪贴板API",
"unpermittedError": "目前不允许使用剪贴板API"
} }
}, },
"login": { "login": {
@ -112,14 +120,15 @@
"dashboard": "仪表盘", "dashboard": "仪表盘",
"workbench": "工作台", "workbench": "工作台",
"monitor": "监控页", "monitor": "监控页",
"test": "多级菜单演示", "multi": "多级菜单演示",
"test2": "多级菜单子页", "multi2": "多级菜单子页",
"test2Detail": "多级菜单的详情页", "multi2Detail": "多级菜单的详情页",
"test3": "多级菜单", "multi3": "多级菜单",
"test4": "多级菜单3-1", "multi4": "多级菜单3-1",
"list": "列表页", "list": "列表页",
"commonList": "常用列表", "commonList": "常用列表",
"cardList": "卡片列表", "cardList": "卡片列表",
"draggableList": "拖拽列表",
"demo": "功能示例", "demo": "功能示例",
"fetch": "请求示例", "fetch": "请求示例",
"echarts": "Echarts示例", "echarts": "Echarts示例",
@ -130,10 +139,11 @@
"clipboard": "剪贴板", "clipboard": "剪贴板",
"icons": "图标", "icons": "图标",
"QRCode": "二维码", "QRCode": "二维码",
"docments": "文档", "documents": "文档",
"docmentsVue": "Vue", "documentsVue": "Vue",
"docmentsVite": "Vite", "documentsVite": "Vite",
"docmentsVueuse": "VueUse外链", "documentsVueuse": "VueUse外链",
"documentsNova": "Nova 文档",
"permission": "权限", "permission": "权限",
"permissionDemo": "权限示例", "permissionDemo": "权限示例",
"justSuper": "super可见", "justSuper": "super可见",
@ -147,6 +157,7 @@
"menuSetting": "菜单设置", "menuSetting": "菜单设置",
"userCenter": "个人中心", "userCenter": "个人中心",
"about": "关于", "about": "关于",
"cascader": "省市区联动" "cascader": "省市区联动",
"dict": "字典示例"
} }
} }

66
nginx.conf Normal file
View File

@ -0,0 +1,66 @@
server {
listen 80;
listen [::]:80;
# 启用 gzip 压缩
gzip on;
gzip_vary on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml application/javascript;
gzip_disable "MSIE [1-6]\.";
# 设定 MIME types
include /etc/nginx/mime.types;
# 基本安全设定
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
# 增加伺服器效能的配置
client_max_body_size 100M;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
location / {
root /www;
index index.html;
try_files $uri $uri/ /index.html;
# 设定快取控制
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 30d;
add_header Cache-Control "public, no-transform";
}
# 动态内容不快取
location = /index.html {
add_header Cache-Control "no-store, no-cache, must-revalidate";
add_header Pragma "no-cache";
expires -1;
}
# 错误处理
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_intercept_errors on;
# 基本的代理设定
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 禁止访问隐藏文件
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}

View File

@ -1,7 +1,7 @@
{ {
"name": "nova-admin", "name": "nova-admin",
"type": "module", "type": "module",
"version": "0.9.4", "version": "0.9.12",
"private": true, "private": true,
"description": "a clean and concise back-end management template based on Vue3, Vite5, Typescript, and Naive UI.", "description": "a clean and concise back-end management template based on Vue3, Vite5, Typescript, and Naive UI.",
"author": { "author": {
@ -40,52 +40,52 @@
"dev": "vite --mode dev --port 9980", "dev": "vite --mode dev --port 9980",
"dev:test": "vite --mode test", "dev:test": "vite --mode test",
"dev:prod": "vite --mode prod", "dev:prod": "vite --mode prod",
"build": "vue-tsc --noEmit && vite build --mode prod", "build": "vite build --mode prod",
"build:dev": "vue-tsc --noEmit && vite build --mode dev", "build:dev": "vite build --mode dev",
"build:test": "vue-tsc --noEmit && vite build --mode test", "build:test": "vite build --mode test",
"preview": "vite preview --port 9981", "preview": "vite preview --port 9981",
"lint": "eslint .", "lint": "eslint . && vue-tsc --noEmit",
"lint:fix": "eslint . --fix", "lint:fix": "eslint . --fix",
"lint:check": "npx @eslint/config-inspector", "lint:check": "npx @eslint/config-inspector",
"sizecheck": "npx vite-bundle-visualizer" "sizecheck": "npx vite-bundle-visualizer"
}, },
"dependencies": { "dependencies": {
"@alova/scene-vue": "^1.5.0", "@vueuse/core": "^13.0.0",
"@vueuse/core": "^10.9.0", "alova": "^3.2.10",
"alova": "^2.20.5",
"colord": "^2.9.3", "colord": "^2.9.3",
"echarts": "^5.5.0", "echarts": "^5.6.0",
"md-editor-v3": "^4.15.2", "md-editor-v3": "^5.4.5",
"pinia": "^2.1.7", "pinia": "^3.0.1",
"pinia-plugin-persist": "^1.0.0", "pinia-plugin-persistedstate": "^4.2.0",
"quill": "^2.0.2", "quill": "^2.0.3",
"radash": "^12.1.0", "radash": "^12.1.0",
"vue": "^3.4.27", "vue": "^3.5.13",
"vue-i18n": "^9.13.1", "vue-draggable-plus": "^0.6.0",
"vue-router": "^4.3.2" "vue-i18n": "^11.1.2",
"vue-router": "^4.5.0"
}, },
"devDependencies": { "devDependencies": {
"@antfu/eslint-config": "^2.18.1", "@antfu/eslint-config": "^4.11.0",
"@iconify-json/icon-park-outline": "^1.1.15", "@iconify-json/icon-park-outline": "^1.2.2",
"@iconify/vue": "^4.1.2", "@iconify/vue": "^4.3.0",
"@types/node": "^20.12.12", "@types/node": "^22.14.0",
"@vitejs/plugin-vue": "^5.0.4", "@vitejs/plugin-vue": "^5.2.3",
"@vitejs/plugin-vue-jsx": "^3.1.0", "@vitejs/plugin-vue-jsx": "^4.1.2",
"eslint": "^9.3.0", "eslint": "^9.24.0",
"lint-staged": "^15.2.4", "lint-staged": "^15.5.0",
"naive-ui": "^2.38.2", "naive-ui": "^2.41.0",
"sass": "^1.77.2", "sass": "^1.86.3",
"simple-git-hooks": "^2.11.1", "simple-git-hooks": "^2.12.1",
"typescript": "^5.4.5", "typescript": "^5.8.3",
"unocss": "^0.60.3", "unocss": "^0.65.4",
"unplugin-auto-import": "^0.17.6", "unplugin-auto-import": "^19.1.2",
"unplugin-icons": "^0.19.0", "unplugin-icons": "^22.1.0",
"unplugin-vue-components": "^0.27.0", "unplugin-vue-components": "^28.4.1",
"vite": "^5.2.11", "vite": "^6.2.5",
"vite-bundle-visualizer": "^1.2.1", "vite-bundle-visualizer": "^1.2.1",
"vite-plugin-compression": "^0.5.1", "vite-plugin-compression": "^0.5.1",
"vite-plugin-vue-devtools": "7.2.1", "vite-plugin-vue-devtools": "7.7.2",
"vue-tsc": "^2.0.19" "vue-tsc": "^2.2.8"
}, },
"simple-git-hooks": { "simple-git-hooks": {
"pre-commit": "pnpm lint-staged" "pre-commit": "pnpm lint-staged"

5732
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { naiveI18nOptions } from '@/utils'
import { darkTheme } from 'naive-ui' import { darkTheme } from 'naive-ui'
import { useAppStore } from './store' import { useAppStore } from './store'
import { naiveI18nOptions } from '@/utils'
const appStore = useAppStore() const appStore = useAppStore()

View File

@ -1,9 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import { NFlex } from 'naive-ui'
import { useAppStore } from '@/store' import { useAppStore } from '@/store'
import IconSun from '~icons/icon-park-outline/sun-one'
import IconMoon from '~icons/icon-park-outline/moon'
import IconAuto from '~icons/icon-park-outline/laptop-computer' import IconAuto from '~icons/icon-park-outline/laptop-computer'
import IconMoon from '~icons/icon-park-outline/moon'
import IconSun from '~icons/icon-park-outline/sun-one'
import { NFlex } from 'naive-ui'
const { t } = useI18n() const { t } = useI18n()
@ -12,7 +12,7 @@ const appStore = useAppStore()
const options = computed(() => { const options = computed(() => {
return [ return [
{ {
label: t('app.lignt'), label: t('app.light'),
value: 'light', value: 'light',
icon: IconSun, icon: IconSun,
}, },

View File

@ -3,14 +3,14 @@ interface Props {
message: string message: string
} }
const props = defineProps<Props>() const { message } = defineProps<Props>()
</script> </script>
<template> <template>
<n-tooltip :show-arrow="false" trigger="hover"> <n-tooltip :show-arrow="false" trigger="hover">
<template #trigger> <template #trigger>
<icon-park-outline-help /> <icon-park-outline-help class="op-50 cursor-help" />
</template> </template>
{{ props.message }} {{ message }}
</n-tooltip> </n-tooltip>
</template> </template>

View File

@ -5,9 +5,9 @@ interface Props {
disabled?: boolean disabled?: boolean
} }
const props = withDefaults(defineProps<Props>(), { const {
disabled: false, disabled = false,
}) } = defineProps<Props>()
interface IconList { interface IconList {
prefix: string prefix: string
@ -39,6 +39,16 @@ async function fetchIconAllList(nameList: string[]) {
return i return i
}) })
} }
// svg
function getSvgName(path: string) {
const regex = /\/([^/]+)\.svg$/
const match = path.match(regex)
if (match) {
const fileName = match[1]
return fileName
}
return path
}
// //
function generateLocalIconList() { function generateLocalIconList() {
@ -48,15 +58,6 @@ function generateLocalIconList() {
eager: true, eager: true,
}) })
function getSvgName(path: string) {
const regex = /\/([^/]+)\.svg$/
const match = path.match(regex)
if (match) {
const fileName = match[1]
return fileName
}
return path
}
return mapEntries(localSvgList, (key, value) => { return mapEntries(localSvgList, (key, value) => {
return [getSvgName(key), value] return [getSvgName(key), value]
}) })
@ -103,9 +104,8 @@ const icons = computed(() => {
// //
const visibleIcons = computed(() => { const visibleIcons = computed(() => {
return icons.value return icons.value?.filter(i => i
?.filter(i => i.includes(searchValue.value)) .includes(searchValue.value))?.slice((currentPage.value - 1) * 200, (currentPage.value) * 200)
?.slice((currentPage.value - 1) * 200, (currentPage.value) * 200)
}) })
const showModal = ref(false) const showModal = ref(false)
@ -125,13 +125,13 @@ function clearIcon() {
<template> <template>
<n-input-group disabled> <n-input-group disabled>
<n-button v-if="value" :disabled="props.disabled" type="primary"> <n-button v-if="value" :disabled="disabled" type="primary">
<template #icon> <template #icon>
<nova-icon :icon="value" /> <nova-icon :icon="value" />
</template> </template>
</n-button> </n-button>
<n-input :value="value" readonly :placeholder="$t('components.iconSelector.inputPlaceholder')" /> <n-input :value="value" readonly :placeholder="$t('components.iconSelector.inputPlaceholder')" />
<n-button type="primary" ghost :disabled="props.disabled" @click="showModal = true"> <n-button type="primary" ghost :disabled="disabled" @click="showModal = true">
{{ $t('common.choose') }} {{ $t('common.choose') }}
</n-button> </n-button>
</n-input-group> </n-input-group>

View File

@ -11,42 +11,36 @@ interface iconPorps {
/* 图标深度 */ /* 图标深度 */
depth?: 1 | 2 | 3 | 4 | 5 depth?: 1 | 2 | 3 | 4 | 5
} }
const props = withDefaults(defineProps<iconPorps>(), { const { size = 18, icon } = defineProps<iconPorps>()
size: 18,
isLocal: false,
})
const isLocal = computed(() => { const isLocal = computed(() => {
return props.icon && props.icon.startsWith('local:') return icon && icon.startsWith('local:')
}) })
function getLocalIcon(icon: string) { function getLocalIcon(icon: string) {
const svgName = icon.replace('local:', '') const svgName = icon.replace('local:', '')
const svg = import.meta.glob('@/assets/svg-icons/*.svg', { const svg = import.meta.glob<string>('@/assets/svg-icons/*.svg', {
query: '?raw', query: '?raw',
import: 'default', import: 'default',
eager: true, eager: true,
}) })
return svg[`/src/assets/svg-icons/${svgName}.svg`] return svg[`/src/assets/svg-icons/${svgName}.svg`]
} }
</script> </script>
<template> <template>
<n-icon <n-icon
v-if="icon && !isLocal" v-if="icon"
:size="size" :size="size"
:depth="depth" :depth="depth"
:color="color" :color="color"
> >
<template v-if="isLocal">
<i v-html="getLocalIcon(icon)" />
</template>
<template v-else>
<Icon :icon="icon" /> <Icon :icon="icon" />
</template>
</n-icon> </n-icon>
<n-icon
v-if="icon && isLocal"
:size="size"
:depth="depth"
:color="color"
v-html="getLocalIcon(icon)"
/>
</template> </template>
<style scoped></style>

View File

@ -1,10 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
const props = defineProps({ interface Props {
count: { count?: number
type: Number, }
default: 0, const {
}, count = 0,
}) } = defineProps<Props>()
const emit = defineEmits<{ const emit = defineEmits<{
change: [page: number, pageSize: number] // change: [page: number, pageSize: number] //
@ -21,11 +21,11 @@ function changePage() {
<template> <template>
<n-pagination <n-pagination
v-if="props.count > 0" v-if="count > 0"
v-model:page="page" v-model:page="page"
v-model:page-size="pageSize" v-model:page-size="pageSize"
:page-sizes="[10, 20, 30, 50]" :page-sizes="[10, 20, 30, 50]"
:item-count="props.count" :item-count="count"
:display-order="displayOrder" :display-order="displayOrder"
show-size-picker show-size-picker
@update-page="changePage" @update-page="changePage"

View File

@ -3,16 +3,15 @@ interface Props {
showWatermark: boolean showWatermark: boolean
text?: string text?: string
} }
const props = withDefaults(defineProps<Props>(), { const {
showWatermark: false, text = 'Watermark',
text: 'Watermark', } = defineProps<Props>()
})
</script> </script>
<template> <template>
<n-watermark <n-watermark
v-if="props.showWatermark" v-if="showWatermark"
:content="props.text" :content="text"
cross cross
fullscreen fullscreen
:font-size="16" :font-size="16"

View File

@ -1,17 +1,23 @@
<script setup lang="ts"> <script setup lang="ts">
const props = defineProps<{ interface Props {
maxLength?: string maxLength?: string
}>() }
const { maxLength } = defineProps<Props>()
const modelValue = defineModel<string>('value') const modelValue = defineModel<string>('value')
</script> </script>
<template> <template>
<div v-if="modelValue" class="inline-flex items-center gap-0.5em"> <div v-if="modelValue" class="inline-flex items-center gap-0.5em">
<n-ellipsis :style="{ 'max-width': props.maxLength || '12em' }"> <n-ellipsis :style="{ 'max-width': maxLength || '12em' }">
{{ modelValue }} {{ modelValue }}
</n-ellipsis> </n-ellipsis>
<n-tooltip trigger="hover">
<template #trigger>
<span v-copy="modelValue" class="cursor-pointer"> <span v-copy="modelValue" class="cursor-pointer">
<icon-park-outline-copy /> <icon-park-outline-copy />
</span> </span>
</template>
{{ $t('components.copyText.tooltip') }}
</n-tooltip>
</div> </div>
</template> </template>

View File

@ -1,26 +1,16 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ToolbarNames } from 'md-editor-v3' import type { ToolbarNames } from 'md-editor-v3'
import { MdEditor } from 'md-editor-v3'
// https://imzbf.github.io/md-editor-v3/zh-CN/docs
import 'md-editor-v3/lib/style.css'
import { useAppStore } from '@/store' import { useAppStore } from '@/store'
const props = defineProps<{ import { MdEditor } from 'md-editor-v3'
modelValue: string // https://imzbf.github.io/md-editor-v3/zh-CN/docs
}>() import 'md-editor-v3/lib/style.css'
const emit = defineEmits(['update:modelValue']) const model = defineModel<string>()
const appStore = useAppStore() const appStore = useAppStore()
const data = useVModel(props, 'modelValue', emit)
const theme = computed(() => {
return appStore.colorMode ? 'dark' : 'light'
})
const toolbarsExclude: ToolbarNames[] = [ const toolbarsExclude: ToolbarNames[] = [
'mermaid', 'mermaid',
'katex', 'katex',
@ -32,7 +22,7 @@ const toolbarsExclude: ToolbarNames[] = [
<template> <template>
<MdEditor <MdEditor
v-model="data" :theme="theme" :toolbars-exclude="toolbarsExclude" v-model="model" :theme="appStore.colorMode" :toolbars-exclude="toolbarsExclude"
/> />
</template> </template>

View File

@ -1,16 +1,17 @@
<script setup lang="ts"> <script setup lang="ts">
import Quill from 'quill' import Quill from 'quill'
import { useTemplateRef } from 'vue'
import 'quill/dist/quill.snow.css' import 'quill/dist/quill.snow.css'
defineOptions({ defineOptions({
name: 'RichTextEditor', name: 'RichTextEditor',
}) })
const props = defineProps<{ const { disabled } = defineProps<Props>()
interface Props {
disabled?: boolean disabled?: boolean
}>() }
const model = defineModel<string>()
const model = defineModel()
let editorInst = null let editorInst = null
@ -20,7 +21,7 @@ onMounted(() => {
initEditor() initEditor()
}) })
const editorRef = ref() const editorRef = useTemplateRef<HTMLElement>('editorRef')
function initEditor() { function initEditor() {
const options = { const options = {
modules: { modules: {
@ -52,28 +53,33 @@ function initEditor() {
placeholder: 'Insert text here ...', placeholder: 'Insert text here ...',
theme: 'snow', theme: 'snow',
} }
const quill = new Quill(editorRef.value, options) const quill = new Quill(editorRef.value!, options)
quill.on('text-change', (_delta, _oldDelta, _source) => { quill.on('text-change', (_delta, _oldDelta, _source) => {
editorModel.value = quill.getSemanticHTML() editorModel.value = quill.getSemanticHTML()
}) })
if (props.disabled) if (disabled)
quill.enable(false) quill.enable(false)
editorInst = quill editorInst = quill
if (model.value)
setContents(model.value)
}
function setContents(html: string) {
editorInst!.setContents(editorInst!.clipboard.convert({ html }))
} }
watch( watch(
() => model.value, () => model.value,
(newValue, _oldValue) => { (newValue, _oldValue) => {
if (newValue && newValue !== editorModel.value) { if (newValue && newValue !== editorModel.value) {
editorInst!.setContents(editorInst!.clipboard.convert({ setContents(newValue)
html: newValue,
}))
} }
else if (!newValue) { else if (!newValue) {
editorInst!.setContents([]) setContents('')
} }
}, },
) )
@ -87,7 +93,7 @@ watch(editorModel, (newValue, oldValue) => {
}) })
watch( watch(
() => props.disabled, () => disabled,
(newValue, _oldValue) => { (newValue, _oldValue) => {
editorInst!.enable(!newValue) editorInst!.enable(!newValue)
}, },

View File

@ -1,4 +1,5 @@
import type { App, Directive } from 'vue' import type { App, Directive } from 'vue'
import { $t } from '@/utils'
interface CopyHTMLElement extends HTMLElement { interface CopyHTMLElement extends HTMLElement {
_copyText: string _copyText: string
@ -10,12 +11,12 @@ export function install(app: App) {
function clipboardEnable() { function clipboardEnable() {
if (!isSupported.value) { if (!isSupported.value) {
window.$message.error('Your browser does not support Clipboard API') window.$message.error($t('components.copyText.unsupportedError'))
return false return false
} }
if (permissionWrite.value !== 'granted') { if (permissionWrite.value !== 'granted') {
window.$message.error('Currently not permitted to use Clipboard API') window.$message.error($t('components.copyText.unpermittedError'))
return false return false
} }
return true return true
@ -25,7 +26,7 @@ export function install(app: App) {
if (!clipboardEnable()) if (!clipboardEnable())
return return
copy(this._copyText) copy(this._copyText)
window.$message.success('复制成功') window.$message.success($t('components.copyText.message'))
} }
function updataClipboard(el: CopyHTMLElement, text: string) { function updataClipboard(el: CopyHTMLElement, text: string) {

View File

@ -1,6 +1,3 @@
import * as echarts from 'echarts/core'
import { BarChart, LineChart, PieChart, RadarChart } from 'echarts/charts'
// 系列类型的定义后缀都为 SeriesOption // 系列类型的定义后缀都为 SeriesOption
import type { import type {
BarSeriesOption, BarSeriesOption,
@ -8,7 +5,6 @@ import type {
PieSeriesOption, PieSeriesOption,
RadarSeriesOption, RadarSeriesOption,
} from 'echarts/charts' } from 'echarts/charts'
// 组件类型的定义后缀都为 ComponentOption // 组件类型的定义后缀都为 ComponentOption
import type { import type {
DatasetComponentOption, DatasetComponentOption,
@ -18,6 +14,9 @@ import type {
ToolboxComponentOption, ToolboxComponentOption,
TooltipComponentOption, TooltipComponentOption,
} from 'echarts/components' } from 'echarts/components'
import { useAppStore } from '@/store'
import { BarChart, LineChart, PieChart, RadarChart } from 'echarts/charts'
import { import {
DatasetComponent, // 数据集组件 DatasetComponent, // 数据集组件
GridComponent, GridComponent,
@ -27,10 +26,11 @@ import {
TooltipComponent, TooltipComponent,
TransformComponent, // 内置数据转换器组件 (filter, sort) TransformComponent, // 内置数据转换器组件 (filter, sort)
} from 'echarts/components' } from 'echarts/components'
import * as echarts from 'echarts/core'
import { LabelLayout, UniversalTransition } from 'echarts/features' import { LabelLayout, UniversalTransition } from 'echarts/features'
import { CanvasRenderer } from 'echarts/renderers' import { CanvasRenderer } from 'echarts/renderers'
import { useAppStore } from '@/store' import { useTemplateRef } from 'vue'
// 通过 ComposeOption 来组合出一个只有必须组件和图表的 Option 类型 // 通过 ComposeOption 来组合出一个只有必须组件和图表的 Option 类型
export type ECOption = echarts.ComposeOption< export type ECOption = echarts.ComposeOption<
@ -68,16 +68,22 @@ echarts.use([
* Echarts hooks函数 * Echarts hooks函数
* @description * @description
*/ */
export function useEcharts(el: Ref<HTMLElement | null>, chartOptions: Ref<ECOption>) { export function useEcharts(ref: string, chartOptions: Ref<ECOption>) {
const el = useTemplateRef<HTMLLIElement>(ref)
const appStore = useAppStore() const appStore = useAppStore()
let chart: echarts.ECharts | null = null let chart: echarts.ECharts | null = null
const { width, height } = useElementSize(el) const { width, height } = useElementSize(el)
const isRendered = computed(() => Boolean(el && chart)) const isRendered = () => Boolean(el && chart)
async function render() { async function render() {
// 宽或高不存在时不渲染
if (!width || !height)
return
const chartTheme = appStore.colorMode ? 'dark' : 'light' const chartTheme = appStore.colorMode ? 'dark' : 'light'
await nextTick() await nextTick()
if (el) { if (el) {
@ -86,9 +92,10 @@ export function useEcharts(el: Ref<HTMLElement | null>, chartOptions: Ref<ECOpti
} }
} }
function update(updateOptions: ECOption) { async function update(updateOptions: ECOption) {
if (isRendered.value) if (isRendered()) {
chart!.setOption({ ...updateOptions, backgroundColor: 'transparent' }) chart!.setOption({ backgroundColor: 'transparent', ...updateOptions })
}
} }
function destroy() { function destroy() {
@ -97,7 +104,7 @@ export function useEcharts(el: Ref<HTMLElement | null>, chartOptions: Ref<ECOpti
} }
watch([width, height], async ([newWidth, newHeight]) => { watch([width, height], async ([newWidth, newHeight]) => {
if (isRendered.value && newWidth && newHeight) if (isRendered() && newWidth && newHeight)
chart?.resize() chart?.resize()
}) })

View File

@ -1,4 +1,3 @@
import { isArray, isString } from 'radash'
import { useAuthStore } from '@/store' import { useAuthStore } from '@/store'
/** 权限判断 */ /** 权限判断 */
@ -6,7 +5,7 @@ export function usePermission() {
const authStore = useAuthStore() const authStore = useAuthStore()
function hasPermission( function hasPermission(
permission: Entity.RoleType | Entity.RoleType[] | undefined, permission?: Entity.RoleType[],
) { ) {
if (!permission) if (!permission)
return true return true
@ -15,13 +14,9 @@ export function usePermission() {
return false return false
const { role } = authStore.userInfo const { role } = authStore.userInfo
let has = role === 'super' let has = role.includes('super')
if (!has) { if (!has) {
if (isArray(permission)) has = permission.every(i => role.includes(i))
has = permission.includes(role)
if (isString(permission))
has = permission === role
} }
return has return has
} }

35
src/hooks/useTableDrag.ts Normal file
View File

@ -0,0 +1,35 @@
import type { NDataTable } from 'naive-ui'
import { useDraggable } from 'vue-draggable-plus'
export function useTableDrag<T = unknown>(params: {
tableRef: Ref<InstanceType<typeof NDataTable> | undefined>
data: Ref<T[]>
onRowDrag: (rows: T[]) => void
}) {
const tableEl = computed(() => params.tableRef?.value?.$el as HTMLElement)
const tableBodyRef = ref<HTMLElement | undefined>(undefined)
const { start } = useDraggable(tableBodyRef, params.data, {
immediate: false,
animation: 150,
handle: '.drag-handle',
onEnd: (event) => {
const { oldIndex, newIndex } = event
const start = Math.min(oldIndex!, newIndex!)
const end = Math.max(oldIndex!, newIndex!) - start + 1
const changedRows = [...params.data.value].splice(start, end)
params.onRowDrag(unref([...changedRows]))
},
})
onMounted(async () => {
while (!tableBodyRef.value) {
tableBodyRef.value = tableEl.value?.querySelector('tbody') || undefined
await new Promise(resolve => setTimeout(resolve, 100))
}
})
watchOnce(() => tableBodyRef.value, (el) => {
el && start()
})
}

View File

@ -12,11 +12,10 @@ const value = defineModel<LayoutMode>('value', { required: true })
:class="{ :class="{
'outline outline-2': value === 'leftMenu', 'outline outline-2': value === 'leftMenu',
}" }"
class="grid grid-cols-[20%_1fr] grid-rows-[20%_1fr] outline-[var(--primary-color)] hover:(outline outline-2) cursor-pointer" class="grid grid-cols-[20%_1fr] outline-[var(--primary-color)] hover:(outline outline-2) cursor-pointer"
@click="value = 'leftMenu'" @click="value = 'leftMenu'"
> >
<div class="bg-[var(--primary-color)] row-span-2" /> <div class="bg-[var(--primary-color)]" />
<div class="bg-[var(--primary-color-suppl)]" />
<div class="bg-[var(--divider-color)]" /> <div class="bg-[var(--divider-color)]" />
</n-el> </n-el>
</template> </template>
@ -38,6 +37,23 @@ const value = defineModel<LayoutMode>('value', { required: true })
</template> </template>
<span> {{ $t('app.topMenu') }} </span> <span> {{ $t('app.topMenu') }} </span>
</n-tooltip> </n-tooltip>
<n-tooltip placement="bottom" trigger="hover">
<template #trigger>
<n-el
:class="{
'outline outline-2': value === 'mixMenu',
}"
class="grid grid-cols-[20%_1fr] grid-rows-[20%_1fr] outline-[var(--primary-color)] hover:(outline outline-2) cursor-pointer"
@click="value = 'mixMenu'"
>
<div class="bg-[var(--primary-color)] row-span-2" />
<div class="bg-[var(--primary-color)]" />
<div class="bg-[var(--divider-color)]" />
</n-el>
</template>
<span> {{ $t('app.mixMenu') }} </span>
</n-tooltip>
</div> </div>
</template> </template>

View File

@ -2,7 +2,7 @@
interface Props { interface Props {
list?: Entity.Message[] list?: Entity.Message[]
} }
const props = defineProps<Props>() const { list } = defineProps<Props>()
const emit = defineEmits<Emits>() const emit = defineEmits<Emits>()
interface Emits { interface Emits {
@ -13,7 +13,7 @@ interface Emits {
<template> <template>
<n-scrollbar style="height: 400px"> <n-scrollbar style="height: 400px">
<n-list hoverable clickable> <n-list hoverable clickable>
<n-list-item v-for="(item) in props.list" :key="item.id" @click="emit('read', item.id)"> <n-list-item v-for="(item) in list" :key="item.id" @click="emit('read', item.id)">
<n-thing content-indented :class="{ 'opacity-30': item.isRead }"> <n-thing content-indented :class="{ 'opacity-30': item.isRead }">
<template #header> <template #header>
<n-ellipsis :line-clamp="1"> <n-ellipsis :line-clamp="1">

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import LayoutSelector from './LayoutSelector.vue'
import { useAppStore } from '@/store' import { useAppStore } from '@/store'
import LayoutSelector from './LayoutSelector.vue'
const appStore = useAppStore() const appStore = useAppStore()

View File

@ -18,8 +18,8 @@ useMagicKeys({
<n-tooltip placement="bottom" trigger="hover"> <n-tooltip placement="bottom" trigger="hover">
<template #trigger> <template #trigger>
<CommonWrapper @click="appStore.toggleFullScreen"> <CommonWrapper @click="appStore.toggleFullScreen">
<icon-park-outline-off-screen-two v-if="appStore.fullScreen" /> <icon-park-outline-off-screen v-if="appStore.fullScreen" />
<icon-park-outline-full-screen-two v-else /> <icon-park-outline-full-screen v-else />
</CommonWrapper> </CommonWrapper>
</template> </template>
<span>{{ $t('app.toggleFullScreen') }}</span> <span>{{ $t('app.toggleFullScreen') }}</span>

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { useRouteStore } from '@/store'
import { useBoolean } from '@/hooks' import { useBoolean } from '@/hooks'
import { useRouteStore } from '@/store'
const routeStore = useRouteStore() const routeStore = useRouteStore()

View File

@ -1,10 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { renderIcon } from '@/utils/icon'
import { useAuthStore } from '@/store' import { useAuthStore } from '@/store'
import IconGithub from '~icons/icon-park-outline/github' import { renderIcon } from '@/utils/icon'
import IconUser from '~icons/icon-park-outline/user'
import IconLogout from '~icons/icon-park-outline/logout'
import IconBookOpen from '~icons/icon-park-outline/book-open' import IconBookOpen from '~icons/icon-park-outline/book-open'
import IconGithub from '~icons/icon-park-outline/github'
import IconLogout from '~icons/icon-park-outline/logout'
import IconUser from '~icons/icon-park-outline/user'
const { t } = useI18n() const { t } = useI18n()
@ -70,7 +70,7 @@ function handleSelect(key: string | number) {
window.open('https://gitee.com/chansee97/nova-admin') window.open('https://gitee.com/chansee97/nova-admin')
if (key === 'docs') if (key === 'docs')
window.open('https://nova-admin-docs.netlify.app/') window.open('https://nova-admin-docs.pages.dev/')
} }
</script> </script>
@ -82,7 +82,7 @@ function handleSelect(key: string | number) {
> >
<n-avatar <n-avatar
round round
class="cursor-pointer"
:src="userInfo?.avatar" :src="userInfo?.avatar"
> >
<template #fallback> <template #fallback>

View File

@ -1,30 +1,30 @@
import Logo from './sider/Logo.vue' import BackTop from './common/BackTop.vue'
import Menu from './sider/Menu.vue' import Setting from './common/Setting.vue'
import SettingDrawer from './common/SettingDrawer.vue'
import Breadcrumb from './header/Breadcrumb.vue' import Breadcrumb from './header/Breadcrumb.vue'
import CollapaseButton from './header/CollapaseButton.vue' import CollapaseButton from './header/CollapaseButton.vue'
import FullScreen from './header/FullScreen.vue' import FullScreen from './header/FullScreen.vue'
import Notices from './header/Notices.vue' import Notices from './header/Notices.vue'
import UserCenter from './header/UserCenter.vue'
import Search from './header/Search.vue' import Search from './header/Search.vue'
import UserCenter from './header/UserCenter.vue'
import Logo from './sider/Logo.vue'
import Menu from './sider/Menu.vue'
import TabBar from './tab/TabBar.vue' import TabBar from './tab/TabBar.vue'
import BackTop from './common/BackTop.vue'
import Setting from './common/Setting.vue'
import SettingDrawer from './common/SettingDrawer.vue'
export { export {
BackTop,
Breadcrumb, Breadcrumb,
CollapaseButton, CollapaseButton,
Menu,
Logo,
FullScreen, FullScreen,
Logo,
Menu,
Notices,
Search,
Setting, Setting,
SettingDrawer, SettingDrawer,
Notices,
UserCenter,
Search,
TabBar, TabBar,
BackTop, UserCenter,
} }

View File

@ -4,13 +4,13 @@ import { useAppStore, useRouteStore } from '@/store'
const route = useRoute() const route = useRoute()
const appStore = useAppStore() const appStore = useAppStore()
const routesStore = useRouteStore() const routeStore = useRouteStore()
const menuInstRef = ref<MenuInst | null>(null) const menuInstRef = ref<MenuInst | null>(null)
watch( watch(
() => route.path, () => route.path,
() => { () => {
menuInstRef.value?.showOption(routesStore.activeMenu as string) menuInstRef.value?.showOption(routeStore.activeMenu as string)
}, },
{ immediate: true }, { immediate: true },
) )
@ -22,7 +22,7 @@ watch(
:collapsed="appStore.collapsed" :collapsed="appStore.collapsed"
:indent="20" :indent="20"
:collapsed-width="64" :collapsed-width="64"
:options="routesStore.menus" :options="routeStore.menus"
:value="routesStore.activeMenu" :value="routeStore.activeMenu"
/> />
</template> </template>

View File

@ -0,0 +1,17 @@
<script setup lang="ts">
import { useAppStore } from '@/store'
const appStore = useAppStore()
</script>
<template>
<n-tooltip placement="bottom" trigger="hover">
<template #trigger>
<CommonWrapper @click="appStore.contentFullScreen = !appStore.contentFullScreen">
<icon-park-outline-off-screen-one v-if="appStore.contentFullScreen" />
<icon-park-outline-full-screen-one v-else />
</CommonWrapper>
</template>
<span>{{ $t('app.togglContentFullScreen') }}</span>
</n-tooltip>
</template>

View File

@ -1,24 +1,24 @@
<script setup lang="ts"> <script setup lang="ts">
import type { RouteLocationNormalized } from 'vue-router' import type { RouteLocationNormalized } from 'vue-router'
import Reload from './Reload.vue'
import DropTabs from './DropTabs.vue'
import { useAppStore, useTabStore } from '@/store' import { useAppStore, useTabStore } from '@/store'
import IconRedo from '~icons/icon-park-outline/redo' import { useDraggable } from 'vue-draggable-plus'
import IconClose from '~icons/icon-park-outline/close' import IconClose from '~icons/icon-park-outline/close'
import IconDelete from '~icons/icon-park-outline/delete-four' import IconDelete from '~icons/icon-park-outline/delete-four'
import IconFullwith from '~icons/icon-park-outline/fullwidth'
import IconRedo from '~icons/icon-park-outline/redo'
import IconLeft from '~icons/icon-park-outline/to-left' import IconLeft from '~icons/icon-park-outline/to-left'
import IconRight from '~icons/icon-park-outline/to-right' import IconRight from '~icons/icon-park-outline/to-right'
import IconFullwith from '~icons/icon-park-outline/fullwidth' import ContentFullScreen from './ContentFullScreen.vue'
import DropTabs from './DropTabs.vue'
import Reload from './Reload.vue'
import TabBarItem from './TabBarItem.vue'
const tabStore = useTabStore() const tabStore = useTabStore()
const appStore = useAppStore() const appStore = useAppStore()
const router = useRouter() const router = useRouter()
function handleTab(route: RouteLocationNormalized) { function handleTab(route: RouteLocationNormalized) {
router.push(route.path) router.push(route.fullPath)
}
function handleClose(path: string) {
tabStore.closeTab(path)
} }
const { t } = useI18n() const { t } = useI18n()
const options = computed(() => { const options = computed(() => {
@ -70,16 +70,16 @@ function handleSelect(key: string) {
appStore.reloadPage() appStore.reloadPage()
}, },
closeCurrent() { closeCurrent() {
tabStore.closeTab(currentRoute.value.path) tabStore.closeTab(currentRoute.value.fullPath)
}, },
closeOther() { closeOther() {
tabStore.closeOtherTabs(currentRoute.value.path) tabStore.closeOtherTabs(currentRoute.value.fullPath)
}, },
closeLeft() { closeLeft() {
tabStore.closeLeftTabs(currentRoute.value.path) tabStore.closeLeftTabs(currentRoute.value.fullPath)
}, },
closeRight() { closeRight() {
tabStore.closeRightTabs(currentRoute.value.path) tabStore.closeRightTabs(currentRoute.value.fullPath)
}, },
closeAll() { closeAll() {
tabStore.closeAllTabs() tabStore.closeAllTabs()
@ -100,53 +100,49 @@ function handleContextMenu(e: MouseEvent, route: RouteLocationNormalized) {
function onClickoutside() { function onClickoutside() {
showDropdown.value = false showDropdown.value = false
} }
// const [DefineTabItem, ReuseTabItem] = createReusableTemplate<{ route: RouteLocationNormalized }>()
const el = ref()
useDraggable(el, tabStore.tabs, {
animation: 150,
ghostClass: 'ghost',
})
</script> </script>
<template> <template>
<div class="wh-full flex items-end"> <div class="p-l-2 flex w-full relative">
<n-tabs <div class="flex items-end">
type="card" <TabBarItem
size="small" v-for="item in tabStore.pinTabs" :key="item.fullPath" :value="tabStore.currentTabPath" :route="item"
:tabs-padding="10"
:value="tabStore.currentTabPath"
@close="handleClose"
>
<n-tab
v-for="item in tabStore.pinTabs"
:key="item.path"
:name="item.path"
@click="router.push(item.path)"
>
<div class="flex-x-center gap-2">
<nova-icon :icon="item.meta.icon" /> {{ $t(`route.${String(item.name)}`, item.meta.title) }}
</div>
</n-tab>
<n-tab
v-for="item in tabStore.tabs"
:key="item.path"
closable
:name="item.path"
@click="handleTab(item)" @click="handleTab(item)"
@contextmenu="handleContextMenu($event, item)"
>
<div class="flex-x-center gap-2">
<nova-icon :icon="item.meta.icon" /> {{ $t(`route.${String(item.name)}`, item.meta.title) }}
</div>
</n-tab>
<template #suffix>
<Reload />
<DropTabs />
</template>
</n-tabs>
<n-dropdown
placement="bottom-start"
trigger="manual"
:x="x"
:y="y"
:options="options"
:show="showDropdown"
:on-clickoutside="onClickoutside"
@select="handleSelect"
/> />
</div> </div>
<div ref="el" class="flex items-end flex-1">
<TabBarItem
v-for="item in tabStore.tabs" :key="item.fullPath" :value="tabStore.currentTabPath" :route="item" closable
@close="tabStore.closeTab"
@click="handleTab(item)"
@contextmenu="handleContextMenu($event, item)"
/>
<n-dropdown
placement="bottom-start" trigger="manual" :x="x" :y="y" :options="options" :show="showDropdown"
:on-clickoutside="onClickoutside" @select="handleSelect"
/>
</div>
<!-- <span class="m-l-auto" /> -->
<n-el class="absolute right-0 flex items-center gap-1 bg-[var(--base-color)] h-full">
<Reload />
<ContentFullScreen />
<DropTabs />
</n-el>
</div>
</template> </template>
<style scoped>
.ghost {
opacity: 0.5;
background: #c4f6d5;
}
</style>

View File

@ -0,0 +1,41 @@
<script setup lang="ts">
import type { RouteLocationNormalized } from 'vue-router'
const { route, value, closable = false } = defineProps<{
route: RouteLocationNormalized
value: string
closable?: boolean
}>()
const emit = defineEmits<{
close: [string]
}>()
</script>
<template>
<n-el
class="cursor-pointer p-x-4 p-y-2 m-x-2px b b-[--divider-color] b-b-[#0000] rounded-[--border-radius]"
:class="[
value === route.fullPath ? 'c-[--primary-color]' : 'c-[--text-color-2]',
value === route.fullPath ? 'bg-[#0000]' : 'bg-[--tab-color]',
closable && 'p-r-2',
]"
style="transition: box-shadow .3s var(--n-bezier), color .3s var(--n-bezier), background-color .3s var(--n-bezier), border-color .3s var(--n-bezier);"
>
<div class="flex-center gap-2 text-nowrap">
<nova-icon :icon="route.meta.icon" />
<span>{{ $t(`route.${String(route.name)}`, route.meta.title) }}</span>
<button
v-if="closable"
type="button"
class="bg-transparent h-18px w-18px flex-center text-[var(--close-icon-color)] hover:bg-[var(--close-color-hover)] rounded-3px"
style="transition: background-color .3s var(--n-bezier), color .3s var(--n-bezier);"
@click.stop="emit('close', route.fullPath)"
>
<n-icon size="14">
<svg viewBox="0 0 12 12" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g fill="currentColor" fill-rule="nonzero"><path d="M2.08859116,2.2156945 L2.14644661,2.14644661 C2.32001296,1.97288026 2.58943736,1.95359511 2.7843055,2.08859116 L2.85355339,2.14644661 L6,5.293 L9.14644661,2.14644661 C9.34170876,1.95118446 9.65829124,1.95118446 9.85355339,2.14644661 C10.0488155,2.34170876 10.0488155,2.65829124 9.85355339,2.85355339 L6.707,6 L9.85355339,9.14644661 C10.0271197,9.32001296 10.0464049,9.58943736 9.91140884,9.7843055 L9.85355339,9.85355339 C9.67998704,10.0271197 9.41056264,10.0464049 9.2156945,9.91140884 L9.14644661,9.85355339 L6,6.707 L2.85355339,9.85355339 C2.65829124,10.0488155 2.34170876,10.0488155 2.14644661,9.85355339 C1.95118446,9.65829124 1.95118446,9.34170876 2.14644661,9.14644661 L5.293,6 L2.14644661,2.85355339 C1.97288026,2.67998704 1.95359511,2.41056264 2.08859116,2.2156945 L2.14644661,2.14644661 L2.08859116,2.2156945 Z" /></g></g></svg>
</n-icon>
</button>
</div>
</n-el>
</template>

View File

@ -1,13 +1,15 @@
<script setup lang="ts"> <script setup lang="ts">
import leftMenu from './leftMenu.layout.vue'
import topMenu from './topMenu.layout.vue'
import { SettingDrawer } from './components'
import { useAppStore } from '@/store/app' import { useAppStore } from '@/store/app'
import { SettingDrawer } from './components'
import leftMenu from './leftMenu.layout.vue'
import mixMenu from './mixMenu.layout.vue'
import topMenu from './topMenu.layout.vue'
const appStore = useAppStore() const appStore = useAppStore()
const layoutMap = { const layoutMap = {
leftMenu, leftMenu,
topMenu, topMenu,
mixMenu,
} }
</script> </script>

View File

@ -1,4 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useAppStore, useRouteStore } from '@/store'
import { import {
BackTop, BackTop,
Breadcrumb, Breadcrumb,
@ -12,7 +13,6 @@ import {
TabBar, TabBar,
UserCenter, UserCenter,
} from './components' } from './components'
import { useAppStore, useRouteStore } from '@/store'
const routeStore = useRouteStore() const routeStore = useRouteStore()
const appStore = useAppStore() const appStore = useAppStore()
@ -25,6 +25,7 @@ const appStore = useAppStore()
embedded embedded
> >
<n-layout-sider <n-layout-sider
v-if="!appStore.contentFullScreen"
bordered bordered
:collapsed="appStore.collapsed" :collapsed="appStore.collapsed"
collapse-mode="width" collapse-mode="width"
@ -43,8 +44,8 @@ const appStore = useAppStore()
embedded embedded
:native-scrollbar="false" :native-scrollbar="false"
> >
<n-layout-header bordered position="absolute" class="z-1"> <n-layout-header bordered position="absolute" class="z-999">
<div class="h-60px flex-y-center justify-between"> <div v-if="!appStore.contentFullScreen" class="h-60px flex-y-center justify-between">
<div class="flex-y-center h-full"> <div class="flex-y-center h-full">
<CollapaseButton /> <CollapaseButton />
<Breadcrumb /> <Breadcrumb />
@ -61,9 +62,17 @@ const appStore = useAppStore()
</div> </div>
<TabBar v-if="appStore.showTabs" class="h-45px" /> <TabBar v-if="appStore.showTabs" class="h-45px" />
</n-layout-header> </n-layout-header>
<div class="flex-1 p-16px flex flex-col"> <!-- 121 = 16 + 45 + 60 45是面包屑高度 60是标签栏高度 -->
<div class="h-60px" /> <!-- 56 = 16 + 40 40是页脚高度 -->
<div v-if="appStore.showTabs" class="h-45px" /> <div
class="flex-1 p-16px flex flex-col"
:class="{
'p-t-121px': appStore.showTabs,
'p-b-56px': appStore.showFooter && !appStore.contentFullScreen,
'p-t-76px': !appStore.showTabs,
'p-t-61px': appStore.contentFullScreen,
}"
>
<router-view v-slot="{ Component, route }" class="flex-1"> <router-view v-slot="{ Component, route }" class="flex-1">
<transition <transition
:name="appStore.transitionAnimation" :name="appStore.transitionAnimation"
@ -78,10 +87,9 @@ const appStore = useAppStore()
</keep-alive> </keep-alive>
</transition> </transition>
</router-view> </router-view>
<div v-if="appStore.showFooter" class="h-40px" />
</div> </div>
<n-layout-footer <n-layout-footer
v-if="appStore.showFooter" v-if="appStore.showFooter && !appStore.contentFullScreen"
bordered bordered
position="absolute" position="absolute"
class="h-40px flex-center" class="h-40px flex-center"

View File

@ -0,0 +1,160 @@
<script lang="ts" setup>
import type { MenuInst, MenuOption } from 'naive-ui'
import { useAppStore, useRouteStore } from '@/store'
import {
BackTop,
CollapaseButton,
FullScreen,
Logo,
Notices,
Search,
Setting,
TabBar,
UserCenter,
} from './components'
const routeStore = useRouteStore()
const appStore = useAppStore()
const pageRoute = useRoute()
const router = useRouter()
const menuInstRef = ref<MenuInst | null>(null)
watch(
() => pageRoute.path,
() => {
menuInstRef.value?.showOption(routeStore.activeMenu as string)
},
{ immediate: true },
)
const topMenu = ref<MenuOption[]>([])
const activeTopMenu = ref<string>('')
function handleTopMenu(rowMenu: MenuOption[]) {
topMenu.value = rowMenu.map((i) => {
const { icon, label, key } = i
return {
icon,
label,
key,
}
})
}
onMounted(() => {
handleTopMenu(routeStore.menus)
//
const currentMenuKey = pageRoute.matched[1].path
handleSideMenu(currentMenuKey)
activeTopMenu.value = currentMenuKey
})
const sideMenu = ref<MenuOption[]>([])
function handleSideMenu(key: string) {
const routeMenu = routeStore.menus as MenuOption[]
const targetMenu = routeMenu.find(i => i.key === key)
if (targetMenu) {
sideMenu.value = targetMenu.children ? targetMenu.children : [targetMenu]
}
}
function updateTopMenu(key: string) {
handleSideMenu(key)
activeTopMenu.value = key
router.push(key)
}
</script>
<template>
<n-layout
has-sider
class="wh-full"
embedded
>
<n-layout-sider
v-if="!appStore.contentFullScreen"
bordered
:collapsed="appStore.collapsed"
collapse-mode="width"
:collapsed-width="64"
:width="240"
content-style="display: flex;flex-direction: column;min-height:100%;"
>
<Logo v-if="appStore.showLogo" />
<n-scrollbar class="flex-1">
<n-menu
ref="menuInstRef"
:collapsed="appStore.collapsed"
:indent="20"
:collapsed-width="64"
:options="sideMenu"
:value="routeStore.activeMenu"
/>
</n-scrollbar>
</n-layout-sider>
<n-layout
class="h-full flex flex-col"
content-style="display: flex;flex-direction: column;min-height:100%;"
embedded
:native-scrollbar="false"
>
<n-layout-header bordered position="absolute" class="z-999">
<div v-if="!appStore.contentFullScreen" class="h-60px flex-y-center justify-between">
<CollapaseButton />
<n-menu
ref="menuInstRef"
mode="horizontal"
responsive
:options="topMenu"
:value="activeTopMenu"
@update:value="updateTopMenu"
/>
<div class="flex-y-center gap-1 h-full p-x-xl">
<Search />
<Notices />
<FullScreen />
<DarkModeSwitch />
<LangsSwitch />
<Setting />
<UserCenter />
</div>
</div>
<TabBar v-if="appStore.showTabs" class="h-45px" />
</n-layout-header>
<div
class="flex-1 p-16px flex flex-col"
:class="{
'p-t-121px': appStore.showTabs,
'p-b-56px': appStore.showFooter && !appStore.contentFullScreen,
'p-t-76px': !appStore.showTabs,
'p-t-61px': appStore.contentFullScreen,
}"
>
<router-view v-slot="{ Component, route }" class="flex-1">
<transition
:name="appStore.transitionAnimation"
mode="out-in"
>
<keep-alive :include="routeStore.cacheRoutes">
<component
:is="Component"
v-if="appStore.loadFlag"
:key="route.fullPath"
/>
</keep-alive>
</transition>
</router-view>
</div>
<n-layout-footer
v-if="appStore.showFooter && !appStore.contentFullScreen"
bordered
position="absolute"
class="h-40px flex-center"
>
{{ appStore.footerText }}
</n-layout-footer>
<BackTop />
</n-layout>
</n-layout>
</template>

View File

@ -1,4 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useAppStore, useRouteStore } from '@/store'
import { import {
BackTop, BackTop,
FullScreen, FullScreen,
@ -10,7 +11,6 @@ import {
TabBar, TabBar,
UserCenter, UserCenter,
} from './components' } from './components'
import { useAppStore, useRouteStore } from '@/store'
const routeStore = useRouteStore() const routeStore = useRouteStore()
const appStore = useAppStore() const appStore = useAppStore()
@ -22,8 +22,8 @@ const appStore = useAppStore()
class="h-full flex flex-col" content-style="display: flex;flex-direction: column;min-height:100%;" class="h-full flex flex-col" content-style="display: flex;flex-direction: column;min-height:100%;"
embedded :native-scrollbar="false" embedded :native-scrollbar="false"
> >
<n-layout-header bordered position="absolute" class="z-1"> <n-layout-header bordered position="absolute" class="z-999">
<div class="h-60px flex-y-center justify-between shrink-0"> <div v-if="!appStore.contentFullScreen" class="h-60px flex-y-center justify-between shrink-0">
<Logo v-if="appStore.showLogo" /> <Logo v-if="appStore.showLogo" />
<Menu mode="horizontal" responsive /> <Menu mode="horizontal" responsive />
<div class="flex-y-center gap-1 h-full p-x-xl"> <div class="flex-y-center gap-1 h-full p-x-xl">
@ -38,9 +38,15 @@ const appStore = useAppStore()
</div> </div>
<TabBar v-if="appStore.showTabs" class="h-45px" /> <TabBar v-if="appStore.showTabs" class="h-45px" />
</n-layout-header> </n-layout-header>
<div class="flex-1 p-16px flex flex-col"> <div
<div class="h-60px" /> class="flex-1 p-16px flex flex-col"
<div v-if="appStore.showTabs" class="h-45px" /> :class="{
'p-t-121px': appStore.showTabs,
'p-b-56px': appStore.showFooter && !appStore.contentFullScreen,
'p-t-76px': !appStore.showTabs,
'p-t-61px': appStore.contentFullScreen,
}"
>
<router-view v-slot="{ Component, route }" class="flex-1"> <router-view v-slot="{ Component, route }" class="flex-1">
<transition :name="appStore.transitionAnimation" mode="out-in"> <transition :name="appStore.transitionAnimation" mode="out-in">
<keep-alive :include="routeStore.cacheRoutes"> <keep-alive :include="routeStore.cacheRoutes">
@ -48,9 +54,11 @@ const appStore = useAppStore()
</keep-alive> </keep-alive>
</transition> </transition>
</router-view> </router-view>
<div v-if="appStore.showFooter" class="h-40px" />
</div> </div>
<n-layout-footer v-if="appStore.showFooter" bordered position="absolute" class="h-40px flex-center"> <n-layout-footer
v-if="appStore.showFooter && !appStore.contentFullScreen"
bordered position="absolute" class="h-40px flex-center"
>
{{ appStore.footerText }} {{ appStore.footerText }}
</n-layout-footer> </n-layout-footer>
<BackTop /> <BackTop />

View File

@ -1,8 +1,8 @@
import type { App } from 'vue' import type { App } from 'vue'
import AppVue from './App.vue'
import AppLoading from './components/common/AppLoading.vue'
import { installRouter } from '@/router' import { installRouter } from '@/router'
import { installPinia } from '@/store' import { installPinia } from '@/store'
import AppVue from './App.vue'
import AppLoading from './components/common/AppLoading.vue'
async function setupApp() { async function setupApp() {
// 载入全局loading加载状态 // 载入全局loading加载状态

View File

@ -1,17 +1,24 @@
import { createI18n } from 'vue-i18n'
import type { App } from 'vue' import type { App } from 'vue'
import { local } from '@/utils'
import { createI18n } from 'vue-i18n'
import enUS from '../../locales/en_US.json' import enUS from '../../locales/en_US.json'
import zhCN from '../../locales/zh_CN.json' import zhCN from '../../locales/zh_CN.json'
import { local } from '@/utils'
const { VITE_DEFAULT_LANG } = import.meta.env
export const i18n = createI18n({ export const i18n = createI18n({
legacy: false, legacy: false,
locale: local.get('lang') || 'enUS', // 默认显示语言 locale: local.get('lang') || VITE_DEFAULT_LANG, // 默认显示语言
fallbackLocale: 'enUS', fallbackLocale: VITE_DEFAULT_LANG,
messages: { messages: {
zhCN, zhCN,
enUS, enUS,
}, },
// 缺失国际化键警告
// missingWarn: false,
// 缺失回退内容警告
fallbackWarn: false,
}) })
export function install(app: App) { export function install(app: App) {

View File

@ -61,7 +61,7 @@ export function setupRouterGuard(router: Router) {
// 添加tabs // 添加tabs
tabStore.addTab(to) tabStore.addTab(to)
// 设置高亮标签; // 设置高亮标签;
tabStore.setCurrentTab(to.path as string) tabStore.setCurrentTab(to.fullPath as string)
}) })
router.afterEach((to) => { router.afterEach((to) => {

View File

@ -1,7 +1,7 @@
import type { App } from 'vue' import type { App } from 'vue'
import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router' import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import { routes } from './routes.inner'
import { setupRouterGuard } from './guard' import { setupRouterGuard } from './guard'
import { routes } from './routes.inner'
const { VITE_ROUTE_MODE = 'hash', VITE_BASE_URL } = import.meta.env const { VITE_ROUTE_MODE = 'hash', VITE_BASE_URL } = import.meta.env
export const router = createRouter({ export const router = createRouter({

View File

@ -34,8 +34,8 @@ export const staticRoutes: AppRoute.RowRoute[] = [
pid: 1, pid: 1,
}, },
{ {
name: 'test', name: 'multi',
path: '/test', path: '/multi',
title: '多级菜单演示', title: '多级菜单演示',
requiresAuth: true, requiresAuth: true,
icon: 'icon-park-outline:list', icon: 'icon-park-outline:list',
@ -45,32 +45,32 @@ export const staticRoutes: AppRoute.RowRoute[] = [
pid: null, pid: null,
}, },
{ {
name: 'test2', name: 'multi2',
path: '/test/test2', path: '/multi/multi2',
title: '多级菜单子页', title: '多级菜单子页',
requiresAuth: true, requiresAuth: true,
icon: 'icon-park-outline:list', icon: 'icon-park-outline:list',
menuType: 'page', menuType: 'page',
componentPath: '/test/test2/index.vue', componentPath: '/demo/multi/multi2/index.vue',
id: 6, id: 6,
pid: 4, pid: 4,
}, },
{ {
name: 'test2Detail', name: 'multi2Detail',
path: '/test/test2/detail', path: '/multi/multi2/detail',
title: '多级菜单详情页', title: '菜单详情页',
requiresAuth: true, requiresAuth: true,
icon: 'icon-park-outline:list', icon: 'icon-park-outline:list',
hide: true, hide: true,
activeMenu: '/test/test2', activeMenu: '/multi/multi2',
menuType: 'page', menuType: 'page',
componentPath: '/test/test2/detail/index.vue', componentPath: '/demo/multi/multi2/detail/index.vue',
id: 7, id: 7,
pid: 4, pid: 4,
}, },
{ {
name: 'test3', name: 'multi3',
path: '/test/test3', path: '/multi/multi3',
title: '多级菜单', title: '多级菜单',
requiresAuth: true, requiresAuth: true,
icon: 'icon-park-outline:list', icon: 'icon-park-outline:list',
@ -80,12 +80,12 @@ export const staticRoutes: AppRoute.RowRoute[] = [
pid: 4, pid: 4,
}, },
{ {
name: 'test4', name: 'multi4',
path: '/test/test3/test4', path: '/multi/multi3/multi4',
title: '多级菜单3-1', title: '多级菜单3-1',
requiresAuth: true, requiresAuth: true,
icon: 'icon-park-outline:list', icon: 'icon-park-outline:list',
componentPath: '/test/test3/test4/index.vue', componentPath: '/demo/multi/multi3/multi4/index.vue',
id: 9, id: 9,
pid: 8, pid: 8,
}, },
@ -106,7 +106,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [
title: '常用列表', title: '常用列表',
requiresAuth: true, requiresAuth: true,
icon: 'icon-park-outline:list-view', icon: 'icon-park-outline:list-view',
componentPath: '/list/commonList/index.vue', componentPath: '/demo/list/commonList/index.vue',
id: 11, id: 11,
pid: 10, pid: 10,
}, },
@ -116,7 +116,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [
title: '卡片列表', title: '卡片列表',
requiresAuth: true, requiresAuth: true,
icon: 'icon-park-outline:view-grid-list', icon: 'icon-park-outline:view-grid-list',
componentPath: '/list/cardList/index.vue', componentPath: '/demo/list/cardList/index.vue',
id: 12, id: 12,
pid: 10, pid: 10,
}, },
@ -224,8 +224,8 @@ export const staticRoutes: AppRoute.RowRoute[] = [
pid: 13, pid: 13,
}, },
{ {
name: 'docments', name: 'documents',
path: '/docments', path: '/documents',
title: '外链文档', title: '外链文档',
requiresAuth: true, requiresAuth: true,
icon: 'icon-park-outline:file-doc', icon: 'icon-park-outline:file-doc',
@ -235,28 +235,28 @@ export const staticRoutes: AppRoute.RowRoute[] = [
pid: null, pid: null,
}, },
{ {
name: 'docmentsVue', name: 'documentsVue',
path: '/docments/vue', path: '/documents/vue',
title: 'Vue', title: 'Vue',
requiresAuth: true, requiresAuth: true,
icon: 'logos:vue', icon: 'logos:vue',
componentPath: '/docments/vue/index.vue', componentPath: '/demo/documents/vue/index.vue',
id: 25, id: 25,
pid: 24, pid: 24,
}, },
{ {
name: 'docmentsVite', name: 'documentsVite',
path: '/docments/vite', path: '/documents/vite',
title: 'Vite', title: 'Vite',
requiresAuth: true, requiresAuth: true,
icon: 'logos:vitejs', icon: 'logos:vitejs',
componentPath: '/docments/vite/index.vue', componentPath: '/demo/documents/vite/index.vue',
id: 26, id: 26,
pid: 24, pid: 24,
}, },
{ {
name: 'docmentsVueuse', name: 'documentsVueuse',
path: '/docments/vueuse', path: '/documents/vueuse',
title: 'VueUse外链', title: 'VueUse外链',
requiresAuth: true, requiresAuth: true,
icon: 'logos:vueuse', icon: 'logos:vueuse',
@ -282,7 +282,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [
title: '权限示例', title: '权限示例',
requiresAuth: true, requiresAuth: true,
icon: 'icon-park-outline:right-user', icon: 'icon-park-outline:right-user',
componentPath: '/permission/permission/index.vue', componentPath: '/demo/permission/permission/index.vue',
id: 29, id: 29,
pid: 28, pid: 28,
}, },
@ -295,7 +295,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [
'super', 'super',
], ],
icon: 'icon-park-outline:wrong-user', icon: 'icon-park-outline:wrong-user',
componentPath: '/permission/justSuper/index.vue', componentPath: '/demo/permission/justSuper/index.vue',
id: 30, id: 30,
pid: 28, pid: 28,
}, },
@ -390,7 +390,7 @@ export const staticRoutes: AppRoute.RowRoute[] = [
title: '个人中心', title: '个人中心',
requiresAuth: true, requiresAuth: true,
icon: 'carbon:user-avatar-filled-alt', icon: 'carbon:user-avatar-filled-alt',
componentPath: '/userCenter/index.vue', componentPath: '/demo/userCenter/index.vue',
id: 39, id: 39,
pid: null, pid: null,
}, },
@ -400,8 +400,49 @@ export const staticRoutes: AppRoute.RowRoute[] = [
title: '关于', title: '关于',
requiresAuth: true, requiresAuth: true,
icon: 'icon-park-outline:info', icon: 'icon-park-outline:info',
componentPath: '/about/index.vue', componentPath: '/demo/about/index.vue',
id: 40, id: 40,
pid: null, pid: null,
}, },
{
name: 'cascader',
path: '/demo/cascader',
title: '省市区联动',
requiresAuth: true,
icon: 'icon-park-outline:add-subset',
componentPath: '/demo/cascader/index.vue',
id: 41,
pid: 13,
},
{
name: 'documentsNova',
path: '/documents/nova',
title: 'Nova docs',
requiresAuth: true,
icon: 'local:logo',
href: 'https://nova-admin-docs.netlify.app/',
componentPath: '2333333',
id: 42,
pid: 24,
},
{
name: 'dict',
path: '/demo/dict',
title: '字典示例',
requiresAuth: true,
icon: 'icon-park-outline:book-one',
componentPath: '/demo/dict/index.vue',
id: 43,
pid: 13,
},
{
name: 'draggableList',
path: '/list/draggableList',
title: '拖拽列表',
requiresAuth: true,
icon: 'icon-park-outline:menu-fold',
componentPath: '/demo/list/draggableList/index.vue',
id: 44,
pid: 10,
},
] ]

View File

@ -5,8 +5,8 @@ interface Ilogin {
password: string password: string
} }
export function fetchLogin(params: Ilogin) { export function fetchLogin(data: Ilogin) {
const methodInstance = request.Post<Service.ResponseResult<Api.Login.Info>>('/login', params) const methodInstance = request.Post<Service.ResponseResult<Api.Login.Info>>('/login', data)
methodInstance.meta = { methodInstance.meta = {
authRole: null, authRole: null,
} }

View File

@ -2,14 +2,25 @@ import { request } from '../http'
// 获取所有路由信息 // 获取所有路由信息
export function fetchAllRoutes() { export function fetchAllRoutes() {
return request.Get<Service.ResponseResult<AppRoute.RowRoute[]> >('/getUserRoutes') return request.Get<Service.ResponseResult<AppRoute.RowRoute[]>>('/getUserRoutes')
} }
// 获取所有用户信息 // 获取所有用户信息
export function fetchUserPage() { export function fetchUserPage() {
return request.Get<Service.ResponseResult<Entity.User[]> >('/userPage') return request.Get<Service.ResponseResult<Entity.User[]>>('/userPage')
} }
// 获取所有角色列表 // 获取所有角色列表
export function fetchRoleList() { export function fetchRoleList() {
return request.Get<Service.ResponseResult<Entity.Role[]> >('/role/list') return request.Get<Service.ResponseResult<Entity.Role[]>>('/role/list')
}
/**
*
*
* @param code -
* @returns
*/
export function fetchDictList(code?: string) {
const params = { code }
return request.Get<Service.ResponseResult<Entity.Dict[]>>('/dict/list', { params })
} }

View File

@ -36,7 +36,7 @@ export function withoutToken() {
/* 接口数据转换 */ /* 接口数据转换 */
export function dictData() { export function dictData() {
return request.Get('/getDictData', { return request.Get('/getDictData', {
transformData(rawData, _headers) { transform(rawData, _headers) {
const response = rawData as any const response = rawData as any
return { return {
...response, ...response,
@ -61,10 +61,7 @@ export function getBlob(url: string) {
/* 带进度的下载文件 */ /* 带进度的下载文件 */
export function downloadFile(url: string) { export function downloadFile(url: string) {
const methodInstance = blankInstance.Get<Blob>(url, { const methodInstance = blankInstance.Get<Blob>(url)
// 开启下载进度
enableDownload: true,
})
methodInstance.meta = { methodInstance.meta = {
// 标识为blob数据 // 标识为blob数据
isBlob: true, isBlob: true,

View File

@ -1,20 +1,20 @@
import { local } from '@/utils'
import { createAlova } from 'alova' import { createAlova } from 'alova'
import VueHook from 'alova/vue' import { createServerTokenAuthentication } from 'alova/client'
import GlobalFetch from 'alova/GlobalFetch' import adapterFetch from 'alova/fetch'
import { createServerTokenAuthentication } from '@alova/scene-vue' import VueHook, { type VueHookType } from 'alova/vue'
import {
DEFAULT_ALOVA_OPTIONS,
DEFAULT_BACKEND_OPTIONS,
} from './config'
import { import {
handleBusinessError, handleBusinessError,
handleRefreshToken, handleRefreshToken,
handleResponseError, handleResponseError,
handleServiceResult, handleServiceResult,
} from './handle' } from './handle'
import {
DEFAULT_ALOVA_OPTIONS,
DEFAULT_BACKEND_OPTIONS,
} from './config'
import { local } from '@/utils'
const { onAuthRequired, onResponseRefreshToken } = createServerTokenAuthentication({ const { onAuthRequired, onResponseRefreshToken } = createServerTokenAuthentication<VueHookType>({
// 服务端判定token过期 // 服务端判定token过期
refreshTokenOnSuccess: { refreshTokenOnSuccess: {
// 当服务端返回401时表示token过期 // 当服务端返回401时表示token过期
@ -50,8 +50,8 @@ export function createAlovaInstance(
return createAlova({ return createAlova({
statesHook: VueHook, statesHook: VueHook,
requestAdapter: GlobalFetch(), requestAdapter: adapterFetch(),
localCache: null, cacheFor: null,
baseURL: _alovaConfig.baseURL, baseURL: _alovaConfig.baseURL,
timeout: _alovaConfig.timeout, timeout: _alovaConfig.timeout,

View File

@ -1,10 +1,10 @@
import { fetchUpdateToken } from '@/service'
import { useAuthStore } from '@/store'
import { local } from '@/utils'
import { import {
ERROR_NO_TIP_STATUS, ERROR_NO_TIP_STATUS,
ERROR_STATUS, ERROR_STATUS,
} from './config' } from './config'
import { useAuthStore } from '@/store'
import { fetchUpdateToken } from '@/service'
import { local } from '@/utils'
type ErrorStatus = keyof typeof ERROR_STATUS type ErrorStatus = keyof typeof ERROR_STATUS

View File

@ -1,6 +1,6 @@
import { createAlovaInstance } from './alova'
import { serviceConfig } from '@/../service.config'
import { generateProxyPattern } from '@/../build/proxy' import { generateProxyPattern } from '@/../build/proxy'
import { serviceConfig } from '@/../service.config'
import { createAlovaInstance } from './alova'
const isHttpProxy = import.meta.env.DEV && import.meta.env.VITE_HTTP_PROXY === 'Y' const isHttpProxy = import.meta.env.DEV && import.meta.env.VITE_HTTP_PROXY === 'Y'

View File

@ -1,4 +1,4 @@
export * from './api/system'
export * from './api/login'
export * from './api/list' export * from './api/list'
export * from './api/login'
export * from './api/system'
export * from './api/test' export * from './api/test'

View File

@ -1,11 +1,13 @@
import type { GlobalThemeOverrides } from 'naive-ui' import type { GlobalThemeOverrides } from 'naive-ui'
import { local, setLocale } from '@/utils'
import { colord } from 'colord' import { colord } from 'colord'
import { set } from 'radash' import { set } from 'radash'
import themeConfig from './theme.json' import themeConfig from './theme.json'
import { local, setLocale } from '@/utils'
type TransitionAnimation = '' | 'fade-slide' | 'fade-bottom' | 'fade-scale' | 'zoom-fade' | 'zoom-out' export type TransitionAnimation = '' | 'fade-slide' | 'fade-bottom' | 'fade-scale' | 'zoom-fade' | 'zoom-out'
export type LayoutMode = 'leftMenu' | 'topMenu' export type LayoutMode = 'leftMenu' | 'topMenu' | 'mixMenu'
const { VITE_DEFAULT_LANG, VITE_COPYRIGHT_INFO } = import.meta.env
const docEle = ref(document.documentElement) const docEle = ref(document.documentElement)
@ -18,8 +20,8 @@ const { system, store } = useColorMode({
export const useAppStore = defineStore('app-store', { export const useAppStore = defineStore('app-store', {
state: () => { state: () => {
return { return {
footerText: import.meta.env.VITE_COPYRIGHT_INFO, footerText: VITE_COPYRIGHT_INFO,
lang: 'enUS' as App.lang, lang: VITE_DEFAULT_LANG,
theme: themeConfig as GlobalThemeOverrides, theme: themeConfig as GlobalThemeOverrides,
primaryColor: themeConfig.common.primaryColor, primaryColor: themeConfig.common.primaryColor,
collapsed: false, collapsed: false,
@ -36,6 +38,7 @@ export const useAppStore = defineStore('app-store', {
showSetting: false, showSetting: false,
transitionAnimation: 'fade-slide' as TransitionAnimation, transitionAnimation: 'fade-slide' as TransitionAnimation,
layoutMode: 'leftMenu' as LayoutMode, layoutMode: 'leftMenu' as LayoutMode,
contentFullScreen: false,
} }
}, },
getters: { getters: {
@ -66,6 +69,7 @@ export const useAppStore = defineStore('app-store', {
this.showWatermark = false this.showWatermark = false
this.transitionAnimation = 'fade-slide' this.transitionAnimation = 'fade-slide'
this.layoutMode = 'leftMenu' this.layoutMode = 'leftMenu'
this.contentFullScreen = false
// 重置所有配色 // 重置所有配色
this.setPrimaryColor(this.primaryColor) this.setPrimaryColor(this.primaryColor)
@ -124,11 +128,6 @@ export const useAppStore = defineStore('app-store', {
}, },
}, },
persist: { persist: {
enabled: true,
strategies: [
{
storage: localStorage, storage: localStorage,
}, },
],
},
}) })

View File

@ -1,8 +1,8 @@
import { router } from '@/router'
import { fetchLogin } from '@/service'
import { local } from '@/utils'
import { useRouteStore } from './router' import { useRouteStore } from './router'
import { useTabStore } from './tab' import { useTabStore } from './tab'
import { fetchLogin } from '@/service'
import { router } from '@/router'
import { local } from '@/utils'
interface AuthStatus { interface AuthStatus {
userInfo: Api.Login.Info | null userInfo: Api.Login.Info | null
@ -62,6 +62,7 @@ export const useAuthStore = defineStore('auth-store', {
await this.handleLoginInfo(data) await this.handleLoginInfo(data)
} }
catch (e) { catch (e) {
console.warn('[Login Error]:', e)
} }
}, },

58
src/store/dict.ts Normal file
View File

@ -0,0 +1,58 @@
import { fetchDictList } from '@/service'
import { session } from '@/utils'
export const useDictStore = defineStore('dict-store', {
state: () => {
return {
dictMap: {} as DictMap,
isInitDict: false,
}
},
actions: {
async dict(code: string) {
// 调用前初始化
if (!this.dictMap) {
this.initDict()
}
const targetDict = await this.getDict(code)
return {
data: () => targetDict,
enum: () => Object.fromEntries(targetDict.map(({ value, label }) => [value, label])),
valueMap: () => Object.fromEntries(targetDict.map(({ value, ...data }) => [value, data])),
labelMap: () => Object.fromEntries(targetDict.map(({ label, ...data }) => [label, data])),
}
},
async getDict(code: string) {
const isExist = Reflect.has(this.dictMap, code)
if (isExist) {
return this.dictMap[code]
}
else {
return await this.getDictByNet(code)
}
},
async getDictByNet(code: string) {
const { data, isSuccess } = await fetchDictList(code)
if (isSuccess) {
Reflect.set(this.dictMap, code, data)
// 同步至session
session.set('dict', this.dictMap)
return data
}
else {
throw new Error(`Failed to get ${code} dictionary from network, check ${code} field or network`)
}
},
initDict() {
const dict = session.get('dict')
if (dict) {
Object.assign(this.dictMap, dict)
}
this.isInitDict = true
},
},
})

View File

@ -1,14 +1,15 @@
import type { App } from 'vue' import type { App } from 'vue'
import piniaPluginPersist from 'pinia-plugin-persist' import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
export * from './app/index' export * from './app/index'
export * from './auth' export * from './auth'
export * from './dict'
export * from './router' export * from './router'
export * from './tab' export * from './tab'
// 安装pinia全局状态库 // 安装pinia全局状态库
export function installPinia(app: App) { export function installPinia(app: App) {
const pinia = createPinia() const pinia = createPinia()
pinia.use(piniaPluginPersist) pinia.use(piniaPluginPersistedstate)
app.use(pinia) app.use(pinia)
} }

View File

@ -1,10 +1,10 @@
import { clone, min, omit, pick } from 'radash'
import type { RouteRecordRaw } from 'vue-router'
import type { MenuOption } from 'naive-ui' import type { MenuOption } from 'naive-ui'
import { RouterLink } from 'vue-router' import type { RouteRecordRaw } from 'vue-router'
import Layout from '@/layouts/index.vue'
import { usePermission } from '@/hooks' import { usePermission } from '@/hooks'
import Layout from '@/layouts/index.vue'
import { $t, arrayToTree, renderIcon } from '@/utils' import { $t, arrayToTree, renderIcon } from '@/utils'
import { clone, min, omit, pick } from 'radash'
import { RouterLink } from 'vue-router'
const metaFields: AppRoute.MetaKeys[] const metaFields: AppRoute.MetaKeys[]
= ['title', 'icon', 'requiresAuth', 'roles', 'keepAlive', 'hide', 'order', 'href', 'activeMenu', 'withoutTab', 'pinTab', 'menuType'] = ['title', 'icon', 'requiresAuth', 'roles', 'keepAlive', 'hide', 'order', 'href', 'activeMenu', 'withoutTab', 'pinTab', 'menuType']
@ -104,8 +104,9 @@ export function createMenus(userRoutes: AppRoute.RowRoute[]) {
// render the returned routing table as a sidebar // render the returned routing table as a sidebar
function transformAuthRoutesToMenus(userRoutes: AppRoute.Route[]) { function transformAuthRoutesToMenus(userRoutes: AppRoute.Route[]) {
const { hasPermission } = usePermission() const { hasPermission } = usePermission()
return userRoutes
// Filter out side menus without permission // Filter out side menus without permission
return userRoutes.filter(i => hasPermission(i.meta.roles)) .filter(i => hasPermission(i.meta.roles))
// Sort the menu according to the order size // Sort the menu according to the order size
.sort((a, b) => { .sort((a, b) => {
if (a.meta && a.meta.order && b.meta && b.meta.order) if (a.meta && a.meta.order && b.meta && b.meta.order)
@ -116,7 +117,6 @@ function transformAuthRoutesToMenus(userRoutes: AppRoute.Route[]) {
return 1 return 1
else return 0 else return 0
}) })
// Convert to side menu data structure // Convert to side menu data structure
.map((item) => { .map((item) => {
const target: MenuOption = { const target: MenuOption = {

View File

@ -1,13 +1,14 @@
import { createMenus, createRoutes, generateCacheRoutes } from './helper' import type { MenuOption } from 'naive-ui'
import { $t, local } from '@/utils'
import { router } from '@/router' import { router } from '@/router'
import { fetchUserRoutes } from '@/service'
import { staticRoutes } from '@/router/routes.static' import { staticRoutes } from '@/router/routes.static'
import { fetchUserRoutes } from '@/service'
import { useAuthStore } from '@/store/auth' import { useAuthStore } from '@/store/auth'
import { $t, local } from '@/utils'
import { createMenus, createRoutes, generateCacheRoutes } from './helper'
interface RoutesStatus { interface RoutesStatus {
isInitAuthRoute: boolean isInitAuthRoute: boolean
menus: AppRoute.Route[] menus: MenuOption[]
rowRoutes: AppRoute.RowRoute[] rowRoutes: AppRoute.RowRoute[]
activeMenu: string | null activeMenu: string | null
cacheRoutes: string[] cacheRoutes: string[]
@ -37,7 +38,7 @@ export const useRouteStore = defineStore('route-store', {
}, },
async initRouteInfo() { async initRouteInfo() {
if (import.meta.env.VITE_AUTH_ROUTE_MODE === 'dynamic') { if (import.meta.env.VITE_ROUTE_LOAD_MODE === 'dynamic') {
const userInfo = local.get('userInfo') const userInfo = local.get('userInfo')
if (!userInfo || !userInfo.id) { if (!userInfo || !userInfo.id) {

View File

@ -24,7 +24,7 @@ export const useTabStore = defineStore('tab-store', {
return return
// 如果标签名称已存在则不添加 // 如果标签名称已存在则不添加
if (this.hasExistTab(route.path as string)) if (this.hasExistTab(route.fullPath as string))
return return
// 根据meta.pinTab传递到不同的分组中 // 根据meta.pinTab传递到不同的分组中
@ -33,42 +33,42 @@ export const useTabStore = defineStore('tab-store', {
else else
this.tabs.push(route) this.tabs.push(route)
}, },
async closeTab(path: string) { async closeTab(fullPath: string) {
const tabsLength = this.tabs.length const tabsLength = this.tabs.length
// 如果动态标签大于一个,才会标签跳转 // 如果动态标签大于一个,才会标签跳转
if (this.tabs.length > 1) { if (this.tabs.length > 1) {
// 获取关闭的标签索引 // 获取关闭的标签索引
const index = this.getTabIndex(path) const index = this.getTabIndex(fullPath)
const isLast = index + 1 === tabsLength const isLast = index + 1 === tabsLength
// 如果是关闭的当前页面,路由跳转到原先标签的后一个标签 // 如果是关闭的当前页面,路由跳转到原先标签的后一个标签
if (this.currentTabPath === path && !isLast) { if (this.currentTabPath === fullPath && !isLast) {
// 跳转到后一个标签 // 跳转到后一个标签
router.push(this.tabs[index + 1].path) router.push(this.tabs[index + 1].fullPath)
} }
else if (this.currentTabPath === path && isLast) { else if (this.currentTabPath === fullPath && isLast) {
// 已经是最后一个了,就跳转前一个 // 已经是最后一个了,就跳转前一个
router.push(this.tabs[index - 1].path) router.push(this.tabs[index - 1].fullPath)
} }
} }
// 删除标签 // 删除标签
this.tabs = this.tabs.filter((item) => { this.tabs = this.tabs.filter((item) => {
return item.path !== path return item.fullPath !== fullPath
}) })
// 删除后如果清空了,就跳转到默认首页 // 删除后如果清空了,就跳转到默认首页
if (tabsLength - 1 === 0) if (tabsLength - 1 === 0)
router.push('/') router.push('/')
}, },
closeOtherTabs(path: string) { closeOtherTabs(fullPath: string) {
const index = this.getTabIndex(path) const index = this.getTabIndex(fullPath)
this.tabs = this.tabs.filter((item, i) => i === index) this.tabs = this.tabs.filter((item, i) => i === index)
}, },
closeLeftTabs(path: string) { closeLeftTabs(fullPath: string) {
const index = this.getTabIndex(path) const index = this.getTabIndex(fullPath)
this.tabs = this.tabs.filter((item, i) => i >= index) this.tabs = this.tabs.filter((item, i) => i >= index)
}, },
closeRightTabs(path: string) { closeRightTabs(fullPath: string) {
const index = this.getTabIndex(path) const index = this.getTabIndex(fullPath)
this.tabs = this.tabs.filter((item, i) => i <= index) this.tabs = this.tabs.filter((item, i) => i <= index)
}, },
clearAllTabs() { clearAllTabs() {
@ -80,28 +80,27 @@ export const useTabStore = defineStore('tab-store', {
router.push('/') router.push('/')
}, },
hasExistTab(path: string) { hasExistTab(fullPath: string) {
const _tabs = [...this.tabs, ...this.pinTabs] const _tabs = [...this.tabs, ...this.pinTabs]
return _tabs.some((item) => { return _tabs.some((item) => {
return item.path === path return item.fullPath === fullPath
}) })
}, },
/* 设置当前激活的标签 */ /* 设置当前激活的标签 */
setCurrentTab(path: string) { setCurrentTab(fullPath: string) {
this.currentTabPath = path this.currentTabPath = fullPath
}, },
getTabIndex(path: string) { getTabIndex(fullPath: string) {
return this.tabs.findIndex((item) => { return this.tabs.findIndex((item) => {
return item.path === path return item.fullPath === fullPath
}) })
}, },
modifyTab(fullPath: string, modifyFn: (route: RouteLocationNormalized) => void) {
const index = this.getTabIndex(fullPath)
modifyFn(this.tabs[index])
},
}, },
persist: { persist: {
enabled: true,
strategies: [
{
storage: sessionStorage, storage: sessionStorage,
}, },
],
},
}) })

View File

@ -14,3 +14,7 @@ body,
.gray-mode { .gray-mode {
filter: grayscale(100%); filter: grayscale(100%);
} }
.drag-handle {
cursor: move;
}

View File

@ -6,3 +6,9 @@
.v-x-scroll { .v-x-scroll {
height: 100%; height: 100%;
} }
/* 解决二维码尺寸问题 */
.n-qr-code{
height: unset !important;
width: unset !important;;
}

View File

@ -7,7 +7,7 @@ namespace Api {
/** 用户id */ /** 用户id */
id: number id: number
/** 用户角色类型 */ /** 用户角色类型 */
role: Entity.RoleType role: Entity.RoleType[]
/** 访问toekn */ /** 访问toekn */
accessToken: string accessToken: string
/** 刷新toekn */ /** 刷新toekn */

View File

@ -1,15 +0,0 @@
/// <reference path="../global.d.ts"/>
/* 角色数据库表字段 */
namespace Entity {
interface DemoList {
id: number
name: string
age: number
gender: '0' | '1' | null
email: string
address: string
role: Entity.RoleType
disabled: boolean
}
}

13
src/typings/entities/dict.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
/// <reference path="../global.d.ts"/>
/* 字典数据库表字段 */
namespace Entity {
interface Dict {
id?: number
isRoot?: 0 | 1
code: string
label: string
value?: number
}
}

View File

@ -21,17 +21,18 @@ interface ImportMetaEnv {
| 'brotliCompress' | 'brotliCompress'
| 'deflate' | 'deflate'
| 'deflateRaw' | 'deflateRaw'
/** hash路由模式 */ /** 路由模式 */
readonly VITE_ROUTE_MODE?: 'hash' | 'web' readonly VITE_ROUTE_MODE?: 'hash' | 'web'
/** 路由加载模式 */ /** 路由加载模式 */
readonly VITE_AUTH_ROUTE_MODE: 'static' | 'dynamic' readonly VITE_ROUTE_LOAD_MODE: 'static' | 'dynamic'
/** 首次加载页面 */ /** 首次加载页面 */
readonly VITE_HOME_PATH: string readonly VITE_HOME_PATH: string
/** 版权信息 */ /** 版权信息 */
readonly VITE_COPYRIGHT_INFO: string readonly VITE_COPYRIGHT_INFO: string
/** 是否自动刷新token */ /** 是否自动刷新token */
readonly VITE_AUTO_REFRESH_TOKEN: 'Y' | 'N' readonly VITE_AUTO_REFRESH_TOKEN: 'Y' | 'N'
/** 默认语言 */
readonly VITE_DEFAULT_LANG: App.lang
/** 后端服务的环境类型 */ /** 后端服务的环境类型 */
readonly MODE: ServiceEnvType readonly MODE: ServiceEnvType
} }

View File

@ -30,7 +30,7 @@ declare namespace NaiveUI {
declare namespace Storage { declare namespace Storage {
interface Session { interface Session {
demoKey: string dict: DictMap
} }
interface Local { interface Local {
@ -50,3 +50,7 @@ declare namespace Storage {
declare namespace App { declare namespace App {
type lang = 'zhCN' | 'enUS' type lang = 'zhCN' | 'enUS'
} }
interface DictMap {
[key: string]: Entity.Dict[]
}

View File

@ -1,20 +1,37 @@
/**
*
* @param arr - id和pid属性pid表示父级id
* @returns
*/
export function arrayToTree(arr: any[]) { export function arrayToTree(arr: any[]) {
// 初始化结果数组
const res: any = [] const res: any = []
// 使用Map存储数组元素以id为键元素本身为值
const map = new Map() const map = new Map()
// 遍历数组将每个元素以id为键存储到Map中
arr.forEach((item) => { arr.forEach((item) => {
map.set(item.id, item) map.set(item.id, item)
}) })
// 再次遍历数组根据pid将元素组织成树形结构
arr.forEach((item) => { arr.forEach((item) => {
// 获取当前元素的父级元素
const parent = item.pid && map.get(item.pid) const parent = item.pid && map.get(item.pid)
// 如果有父级元素
if (parent) { if (parent) {
// 如果父级元素已有子元素,则将当前元素追加到子元素数组中
if (parent?.children) if (parent?.children)
parent.children.push(item) parent.children.push(item)
// 如果父级元素没有子元素,则创建子元素数组,并将当前元素作为第一个元素
else else
parent.children = [item] parent.children = [item]
} }
// 如果没有父级元素,则将当前元素直接添加到结果数组中
else { else {
res.push(item) res.push(item)
} }
}) })
// 返回组织好的树形结构数组
return res return res
} }

View File

@ -1,6 +1,6 @@
import type { NDateLocale, NLocale } from 'naive-ui' import type { NDateLocale, NLocale } from 'naive-ui'
import { dateZhCN, zhCN } from 'naive-ui'
import { i18n } from '@/modules/i18n' import { i18n } from '@/modules/i18n'
import { dateZhCN, zhCN } from 'naive-ui'
export function setLocale(locale: App.lang) { export function setLocale(locale: App.lang) {
i18n.global.locale.value = locale i18n.global.locale.value = locale

View File

@ -1,4 +1,4 @@
export * from './icon'
export * from './storage' export * from './storage'
export * from './array' export * from './array'
export * from './i18n' export * from './i18n'
export * from './icon'

View File

@ -39,9 +39,8 @@ function createLocalStorage<T extends Storage.Local>() {
window.localStorage.removeItem(`${STORAGE_PREFIX}${String(key)}`) window.localStorage.removeItem(`${STORAGE_PREFIX}${String(key)}`)
} }
function clear() { const clear = window.localStorage.clear
window.localStorage.clear()
}
return { return {
set, set,
get, get,
@ -73,9 +72,7 @@ function createSessionStorage<T extends Storage.Session>() {
function remove(key: keyof T) { function remove(key: keyof T) {
window.sessionStorage.removeItem(`${STORAGE_PREFIX}${String(key)}`) window.sessionStorage.removeItem(`${STORAGE_PREFIX}${String(key)}`)
} }
function clear() { const clear = window.sessionStorage.clear
window.sessionStorage.clear()
}
return { return {
set, set,

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { graphic } from 'echarts'
import { type ECOption, useEcharts } from '@/hooks' import { type ECOption, useEcharts } from '@/hooks'
import { graphic } from 'echarts'
const lineOptions = ref<ECOption>({ const lineOptions = ref<ECOption>({
tooltip: { tooltip: {
@ -114,8 +114,7 @@ const lineOptions = ref<ECOption>({
}], }],
}) as Ref<ECOption> }) as Ref<ECOption>
const lineRef = ref<HTMLElement | null>(null) useEcharts('lineRef', lineOptions)
useEcharts(lineRef, lineOptions)
</script> </script>
<template> <template>

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { graphic } from 'echarts'
import { type ECOption, useEcharts } from '@/hooks' import { type ECOption, useEcharts } from '@/hooks'
import { graphic } from 'echarts'
const chartData = [ const chartData = [
{ name: '1', value: 300 }, { name: '1', value: 300 },
@ -91,8 +91,7 @@ const option = ref<ECOption>({
}], }],
}) as Ref<ECOption> }) as Ref<ECOption>
const lineRef = ref<HTMLElement | null>(null) useEcharts('lineRef', option)
useEcharts(lineRef, option)
</script> </script>
<template> <template>

View File

@ -50,8 +50,7 @@ const option = ref<ECOption>({
}, },
], ],
}) as Ref<ECOption> }) as Ref<ECOption>
const lineRef = ref<HTMLElement | null>(null) useEcharts('lineRef', option)
useEcharts(lineRef, option)
</script> </script>
<template> <template>

View File

@ -99,8 +99,7 @@ const lineOptions = ref<ECOption>({
}, },
], ],
}) as Ref<ECOption> }) as Ref<ECOption>
const lineRef = ref<HTMLElement | null>(null) useEcharts('lineRef', lineOptions)
useEcharts(lineRef, lineOptions)
</script> </script>
<template> <template>

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import Chart from './components/chart.vue'
import { useAuthStore } from '@/store' import { useAuthStore } from '@/store'
import Chart from './components/chart.vue'
const { userInfo } = useAuthStore() const { userInfo } = useAuthStore()
</script> </script>

View File

@ -33,19 +33,19 @@ function handleValidateClick() {
<div> <div>
<n-h2>回调value</n-h2> <n-h2>回调value</n-h2>
<pre class="bg-#eee"> <pre class="bg-#eee:30">
{{ cbValue }} {{ cbValue }}
</pre> </pre>
</div> </div>
<div> <div>
<n-h2>回调option</n-h2> <n-h2>回调option</n-h2>
<pre class="bg-#eee"> <pre class="bg-#eee:30">
{{ cbOption }} {{ cbOption }}
</pre> </pre>
</div> </div>
<div> <div>
<n-h2>回调pathValues</n-h2> <n-h2>回调pathValues</n-h2>
<pre class="bg-#eee"> <pre class="bg-#eee:30">
{{ cbPathValues }} {{ cbPathValues }}
</pre> </pre>
</div> </div>

View File

@ -0,0 +1,113 @@
<script setup lang="ts">
import { fetchDictList } from '@/service'
import { useDictStore } from '@/store'
const { dict } = useDictStore()
const dictKey = ref('')
const options = ref()
const subOptions = ref()
const currentDict = ref()
async function getAlldict() {
const { data, isSuccess } = await fetchDictList()
if (isSuccess) {
options.value = data.map((item) => {
return {
label: item.label,
value: item.code,
}
})
}
}
function changeSelect(v: string) {
dict(v).then((data) => {
currentDict.value = data
subOptions.value = data.data()
})
}
onMounted(() => {
getAlldict()
})
const data = ref()
async function getDict() {
data.value = currentDict.value.data()
}
async function getEnum() {
data.value = currentDict.value.enum()
}
async function getValueMap() {
data.value = currentDict.value.valueMap()
}
async function getLabelMap() {
data.value = currentDict.value.labelMap()
}
const dictValue = ref()
const dictLabel = computed(() => {
if (data.value && data.value[dictValue.value]) {
return data.value[dictValue.value].label
}
return '--'
})
const enumValue = ref()
const enumLabel = computed(() => {
if (data.value && data.value[enumValue.value]) {
return data.value[enumValue.value]
}
return '--'
})
</script>
<template>
<n-card title="字典示例">
<n-flex vertical>
<n-flex>
<n-select v-model:value="dictKey" class="w-1/3" :options="options" @update:value="changeSelect" />
子字典下拉框
<n-select class="w-1/3" :options="subOptions" />
</n-flex>
<n-flex>
<n-button @click="getDict">
获取当前字典数据
</n-button>
<n-button @click="getEnum">
获取当前字典枚举
</n-button>
<n-button @click="getValueMap">
获取当前字典ValueMap
</n-button>
<n-button @click="getLabelMap">
获取当前字典LabelMap
</n-button>
</n-flex>
<pre class="bg-#eee:30">
{{ data }}
</pre>
<n-flex align="center">
<n-input-number v-model:value="dictValue" :min="0" />
<n-text type="info">
Map回显结果 {{ dictLabel }}
</n-text>
</n-flex>
<n-flex align="center">
<n-input-number v-model:value="enumValue" :min="0" />
<n-text type="info">
Enum回显结果 {{ enumLabel }}
</n-text>
</n-flex>
</n-flex>
</n-card>
</template>
<style scoped></style>

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { graphic } from 'echarts'
import { type ECOption, useEcharts } from '@/hooks' import { type ECOption, useEcharts } from '@/hooks'
import { graphic } from 'echarts'
// //
const pieOptions = ref<ECOption>({ const pieOptions = ref<ECOption>({
@ -53,9 +53,28 @@ const pieOptions = ref<ECOption>({
], ],
}, },
], ],
}) as Ref<ECOption> })
const pieRef = ref<HTMLElement | null>(null) const { update } = useEcharts('pieRef', pieOptions)
useEcharts(pieRef, pieOptions)
const randomValue = () => Math.round(Math.random() * 100)
function updatePieChart() {
pieOptions.value.series = [
{
data: [
{ value: randomValue(), name: 'rose1' },
{ value: randomValue(), name: 'rose2' },
{ value: randomValue(), name: 'rose3' },
{ value: randomValue(), name: 'rose4' },
{ value: randomValue(), name: 'rose5' },
{ value: randomValue(), name: 'rose6' },
{ value: randomValue(), name: 'rose7' },
{ value: randomValue(), name: 'rose8' },
],
},
]
update(pieOptions.value)
}
// 线 // 线
const lineOptions = ref<ECOption>({ const lineOptions = ref<ECOption>({
@ -245,9 +264,8 @@ const lineOptions = ref<ECOption>({
data: [820, 932, 901, 934, 1290, 1330, 1320], data: [820, 932, 901, 934, 1290, 1330, 1320],
}, },
], ],
}) as Ref<ECOption> })
const lineRef = ref<HTMLElement | null>(null) useEcharts('lineRef', lineOptions)
useEcharts(lineRef, lineOptions)
// //
const barOptions = ref<ECOption>({ const barOptions = ref<ECOption>({
@ -386,9 +404,8 @@ const barOptions = ref<ECOption>({
data: [200, 382, 102, 267, 186, 315, 316], data: [200, 382, 102, 267, 186, 315, 316],
}, },
], ],
}) as Ref<ECOption> })
const barRef = ref<HTMLElement | null>(null) useEcharts('barRef', barOptions)
useEcharts(barRef, barOptions)
// //
const radarOptions = ref<ECOption>({ const radarOptions = ref<ECOption>({
@ -480,9 +497,8 @@ const radarOptions = ref<ECOption>({
], ],
}, },
], ],
}) as Ref<ECOption> })
const radarRef = ref<HTMLElement | null>(null) useEcharts('radarRef', radarOptions)
useEcharts(radarRef, radarOptions)
</script> </script>
<template> <template>
@ -491,6 +507,9 @@ useEcharts(radarRef, radarOptions)
:size="16" :size="16"
> >
<n-card> <n-card>
<n-button @click="updatePieChart">
手动更新图表
</n-button>
<div <div
ref="pieRef" ref="pieRef"
class="h-400px" class="h-400px"

View File

@ -1,8 +1,8 @@
<script setup lang="ts"> <script setup lang="ts">
import { useRequest } from 'alova'
import { import {
downloadFile, downloadFile,
} from '@/service' } from '@/service'
import { useRequest } from 'alova/client'
const emit = defineEmits<{ const emit = defineEmits<{
update: [data: any] update: [data: any]

View File

@ -15,6 +15,7 @@ async function expiredToken() {
<template> <template>
<n-card title="Token Expiration" size="small"> <n-card title="Token Expiration" size="small">
注意观察第二次的请求token已刷新
<n-button type="error" @click="expiredToken"> <n-button type="error" @click="expiredToken">
click click
</n-button> </n-button>

View File

@ -1,9 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import { useRequest } from 'alova'
import { import {
fetchGet, fetchGet,
} from '@/service' } from '@/service'
import { useRequest } from 'alova/client'
const emit = defineEmits<{ const emit = defineEmits<{
update: [data: any] // update: [data: any] //
}>() }>()

View File

@ -1,20 +1,20 @@
<script setup lang="ts"> <script setup lang="ts">
import Env from './components/Env.vue'
import Get from './components/Get.vue'
import Post from './components/Post.vue'
import FormPost from './components/FormPost.vue'
import Delete from './components/Delete.vue' import Delete from './components/Delete.vue'
import Put from './components/Put.vue'
import UseRequest from './components/UseRequest.vue'
import NoToken from './components/NoToken.vue'
import DownLoad from './components/DownLoad.vue' import DownLoad from './components/DownLoad.vue'
import DownLoadWithProgress from './components/DownLoadWithProgress.vue' import DownLoadWithProgress from './components/DownLoadWithProgress.vue'
import Env from './components/Env.vue'
import FailedRequest from './components/FailedRequest.vue' import FailedRequest from './components/FailedRequest.vue'
import FailedResponse from './components/FailedResponse.vue' import FailedResponse from './components/FailedResponse.vue'
import FailedResponseWithoutTip from './components/FailedResponseWithoutTip.vue' import FailedResponseWithoutTip from './components/FailedResponseWithoutTip.vue'
import Transform from './components/Transform.vue' import FormPost from './components/FormPost.vue'
import Get from './components/Get.vue'
import NoToken from './components/NoToken.vue'
import Post from './components/Post.vue'
import Put from './components/Put.vue'
import RefreshToken from './components/RefreshToken.vue' import RefreshToken from './components/RefreshToken.vue'
import TokenExpiration from './components/TokenExpiration.vue' import TokenExpiration from './components/TokenExpiration.vue'
import Transform from './components/Transform.vue'
import UseRequest from './components/UseRequest.vue'
const msg = ref() const msg = ref()
function handleUpdate(data: any) { function handleUpdate(data: any) {
@ -46,7 +46,7 @@ function handleUpdate(data: any) {
</div> </div>
</template> </template>
<template #2> <template #2>
<pre class="bg-#eee"> <pre class="bg-#eee:30">
{{ msg }} {{ msg }}
</pre> </pre>
</template> </template>

View File

@ -24,6 +24,9 @@
<div> <div>
大大大<svg-icons-cool class="text-4em" /> 大大大<svg-icons-cool class="text-4em" />
</div> </div>
<div>
nova-icon组件加载<nova-icon icon="local:cool" />
</div>
</n-card> </n-card>
</n-space> </n-space>
</template> </template>

View File

@ -1,33 +1,31 @@
<script setup lang="ts"> <script setup lang="ts">
type FormModel = Pick<Entity.DemoList, 'name' | 'age' | 'gender' | 'address' | 'email' | 'role' | 'disabled'>
const props = withDefaults(defineProps<Props>(), {
type: 'add',
modalData: null,
})
const emit = defineEmits<Emits>()
const defaultFormModal: FormModel = {
name: '',
age: 0,
gender: null,
email: '',
address: '',
role: 'user',
disabled: true,
}
const formModel = ref({ ...defaultFormModal })
interface Props { interface Props {
visible: boolean visible: boolean
type?: ModalType type?: ModalType
modalData?: any modalData?: any
} }
const {
visible,
type = 'add',
modalData = null,
} = defineProps<Props>()
const emit = defineEmits<Emits>()
const defaultFormModal: Entity.User = {
userName: '',
gender: 0,
email: '',
role: [],
}
const formModel = ref({ ...defaultFormModal })
interface Emits { interface Emits {
(e: 'update:visible', visible: boolean): void (e: 'update:visible', visible: boolean): void
} }
const modalVisible = computed({ const modalVisible = computed({
get() { get() {
return props.visible return visible
}, },
set(visible) { set(visible) {
closeModal(visible) closeModal(visible)
@ -42,7 +40,7 @@ const title = computed(() => {
add: '添加用户', add: '添加用户',
edit: '编辑用户', edit: '编辑用户',
} }
return titles[props.type] return titles[type]
}) })
function UpdateFormModelByModalType() { function UpdateFormModelByModalType() {
@ -51,14 +49,14 @@ function UpdateFormModelByModalType() {
formModel.value = { ...defaultFormModal } formModel.value = { ...defaultFormModal }
}, },
edit: () => { edit: () => {
if (props.modalData) if (modalData)
formModel.value = { ...props.modalData } formModel.value = { ...modalData }
}, },
} }
handlers[props.type]() handlers[type]()
} }
watch( watch(
() => props.visible, () => visible,
(newValue) => { (newValue) => {
if (newValue) if (newValue)
UpdateFormModelByModalType() UpdateFormModelByModalType()
@ -81,26 +79,26 @@ watch(
<n-form label-placement="left" :model="formModel" label-align="left" :label-width="80"> <n-form label-placement="left" :model="formModel" label-align="left" :label-width="80">
<n-grid :cols="24" :x-gap="18"> <n-grid :cols="24" :x-gap="18">
<n-form-item-grid-item :span="12" label="用户名" path="name"> <n-form-item-grid-item :span="12" label="用户名" path="name">
<n-input v-model:value="formModel.name" /> <n-input v-model:value="formModel.userName" />
</n-form-item-grid-item> </n-form-item-grid-item>
<n-form-item-grid-item :span="12" label="年龄" path="age"> <n-form-item-grid-item :span="12" label="年龄" path="age">
<n-input-number v-model:value="formModel.age" /> <n-input-number v-model:value="formModel.gender" />
</n-form-item-grid-item> </n-form-item-grid-item>
<n-form-item-grid-item :span="12" label="性别" path="gender"> <n-form-item-grid-item :span="12" label="性别" path="gender">
<n-input v-model:value="formModel.gender" /> <n-radio-group v-model:value="formModel.gender">
<n-space>
<n-radio :value="1">
</n-radio>
<n-radio :value="0">
</n-radio>
</n-space>
</n-radio-group>
</n-form-item-grid-item> </n-form-item-grid-item>
<n-form-item-grid-item :span="12" label="邮箱" path="email"> <n-form-item-grid-item :span="12" label="邮箱" path="email">
<n-input v-model:value="formModel.email" /> <n-input v-model:value="formModel.email" />
</n-form-item-grid-item> </n-form-item-grid-item>
<n-form-item-grid-item :span="12" label="地址" path="address">
<n-input v-model:value="formModel.address" />
</n-form-item-grid-item>
<n-form-item-grid-item :span="12" label="角色" path="role">
<n-input v-model:value="formModel.role" />
</n-form-item-grid-item>
<n-form-item-grid-item :span="12" label="状态" path="disabled">
<n-switch v-model:value="formModel.disabled" />
</n-form-item-grid-item>
</n-grid> </n-grid>
</n-form> </n-form>
<template #action> <template #action>

View File

@ -1,10 +1,10 @@
<script setup lang="tsx"> <script setup lang="tsx">
import type { DataTableColumns, FormInst } from 'naive-ui' import type { DataTableColumns, FormInst } from 'naive-ui'
import { Gender } from '@/constants'
import { useBoolean } from '@/hooks'
import { fetchUserPage } from '@/service'
import { NButton, NPopconfirm, NSpace, NSwitch, NTag } from 'naive-ui' import { NButton, NPopconfirm, NSpace, NSwitch, NTag } from 'naive-ui'
import TableModal from './components/TableModal.vue' import TableModal from './components/TableModal.vue'
import { fetchUserList } from '@/service'
import { useBoolean } from '@/hooks'
import { Gender } from '@/constants'
const { bool: loading, setTrue: startLoading, setFalse: endLoading } = useBoolean(false) const { bool: loading, setTrue: startLoading, setFalse: endLoading } = useBoolean(false)
const { bool: visible, setTrue: openModal } = useBoolean(false) const { bool: visible, setTrue: openModal } = useBoolean(false)
@ -18,14 +18,14 @@ const initialModel = {
const model = ref({ ...initialModel }) const model = ref({ ...initialModel })
const formRef = ref<FormInst | null>() const formRef = ref<FormInst | null>()
function sendMail(id: number) { function sendMail(id?: number) {
window.$message.success(`删除用户id:${id}`) window.$message.success(`删除用户id:${id}`)
} }
const columns: DataTableColumns<Entity.DemoList> = [ const columns: DataTableColumns<Entity.User> = [
{ {
title: '姓名', title: '姓名',
align: 'center', align: 'center',
key: 'name', key: 'userName',
}, },
{ {
title: '年龄', title: '年龄',
@ -55,34 +55,18 @@ const columns: DataTableColumns<Entity.DemoList> = [
align: 'center', align: 'center',
key: 'email', key: 'email',
}, },
{
title: '地址',
align: 'center',
key: 'address',
},
{
title: '角色',
align: 'center',
key: 'role',
render: (row) => {
const tagType: Record<Entity.RoleType, NaiveUI.ThemeColor> = {
super: 'primary',
admin: 'warning',
user: 'success',
}
return <NTag type={tagType[row.role]}>{row.role}</NTag>
},
},
{ {
title: '状态', title: '状态',
align: 'center', align: 'center',
key: 'disabled', key: 'status',
render: (row) => { render: (row) => {
return ( return (
<NSwitch <NSwitch
value={row.disabled} value={row.status}
onUpdateValue={disabled => checked-value={1}
handleUpdateDisabled(disabled, row.id)} unchecked-value={0}
onUpdateValue={(value: 0 | 1) =>
handleUpdateDisabled(value, row.id!)}
> >
{{ checked: () => '启用', unchecked: () => '禁用' }} {{ checked: () => '启用', unchecked: () => '禁用' }}
</NSwitch> </NSwitch>
@ -114,11 +98,11 @@ const columns: DataTableColumns<Entity.DemoList> = [
}, },
] ]
const listData = ref<Entity.DemoList[]>([]) const listData = ref<Entity.User[]>([])
function handleUpdateDisabled(disabled: boolean, id: number) { function handleUpdateDisabled(value: 0 | 1, id: number) {
const index = listData.value.findIndex(item => item.id === id) const index = listData.value.findIndex(item => item.id === id)
if (index > -1) if (index > -1)
listData.value[index].disabled = disabled listData.value[index].status = value
} }
onMounted(() => { onMounted(() => {
@ -126,7 +110,7 @@ onMounted(() => {
}) })
async function getUserList() { async function getUserList() {
startLoading() startLoading()
await fetchUserList().then((res: any) => { await fetchUserPage().then((res: any) => {
listData.value = res.data.list listData.value = res.data.list
endLoading() endLoading()
}) })
@ -144,12 +128,12 @@ function setModalType(type: ModalType) {
modalType.value = type modalType.value = type
} }
const editData = ref<Entity.DemoList | null>(null) const editData = ref<Entity.User | null>(null)
function setEditData(data: Entity.DemoList | null) { function setEditData(data: Entity.User | null) {
editData.value = data editData.value = data
} }
function handleEditTable(row: Entity.DemoList) { function handleEditTable(row: Entity.User) {
setEditData(row) setEditData(row)
setModalType('edit') setModalType('edit')
openModal() openModal()

View File

@ -0,0 +1,170 @@
<script setup lang="tsx">
import type { DataTableColumns, FormInst, NDataTable } from 'naive-ui'
import { Gender } from '@/constants'
import { useBoolean } from '@/hooks'
import { useTableDrag } from '@/hooks/useTableDrag'
import { fetchUserPage } from '@/service'
import { NButton, NPopconfirm, NSpace, NSwitch, NTag } from 'naive-ui'
const { bool: loading, setTrue: startLoading, setFalse: endLoading } = useBoolean(false)
const initialModel = {
condition_1: '',
condition_2: '',
condition_3: '',
condition_4: '',
}
const model = ref({ ...initialModel })
const formRef = ref<FormInst | null>()
function sendMail(id?: number) {
window.$message.success(`删除用户id:${id}`)
}
const columns: DataTableColumns<Entity.User> = [
{
title: '姓名',
align: 'center',
key: 'userName',
},
{
title: '年龄',
align: 'center',
key: 'age',
},
{
title: '性别',
align: 'center',
key: 'gender',
render: (row) => {
const tagType = {
0: 'primary',
1: 'success',
} as const
if (row.gender) {
return (
<NTag type={tagType[row.gender]}>
{Gender[row.gender]}
</NTag>
)
}
},
},
{
title: '邮箱',
align: 'center',
key: 'email',
},
{
title: '状态',
align: 'center',
key: 'status',
render: (row) => {
return (
<NSwitch
value={row.status}
checked-value={1}
unchecked-value={0}
onUpdateValue={(value: 0 | 1) =>
handleUpdateDisabled(value, row.id!)}
>
{{ checked: () => '启用', unchecked: () => '禁用' }}
</NSwitch>
)
},
},
{
title: '操作',
align: 'center',
key: 'actions',
render: (row) => {
return (
<NSpace justify="center">
<NPopconfirm onPositiveClick={() => sendMail(row.id)}>
{{
default: () => '确认删除',
trigger: () => <NButton size="small">删除</NButton>,
}}
</NPopconfirm>
</NSpace>
)
},
},
]
const listData = ref<Entity.User[]>([])
function handleUpdateDisabled(value: 0 | 1, id: number) {
const index = listData.value.findIndex(item => item.id === id)
if (index > -1)
listData.value[index].status = value
}
const tableRef = ref<InstanceType<typeof NDataTable>>()
useTableDrag({
tableRef,
data: listData,
onRowDrag(data) {
const target = data[data.length - 1]
window.$message.success(`拖拽数据 id: ${target.id} name: ${target.userName}`)
},
})
onMounted(() => {
getUserList()
})
async function getUserList() {
startLoading()
await fetchUserPage().then((res: any) => {
listData.value = res.data.list
endLoading()
})
}
function changePage(page: number, size: number) {
window.$message.success(`分页器:${page},${size}`)
}
function handleResetSearch() {
model.value = { ...initialModel }
}
</script>
<template>
<NSpace vertical size="large">
<n-card>
<n-form ref="formRef" :model="model" label-placement="left" inline :show-feedback="false">
<n-flex>
<n-form-item label="姓名" path="condition_1">
<n-input v-model:value="model.condition_1" placeholder="请输入" />
</n-form-item>
<n-form-item label="年龄" path="condition_2">
<n-input v-model:value="model.condition_2" placeholder="请输入" />
</n-form-item>
<n-form-item label="性别" path="condition_3">
<n-input v-model:value="model.condition_3" placeholder="请输入" />
</n-form-item>
<n-form-item label="地址" path="condition_4">
<n-input v-model:value="model.condition_4" placeholder="请输入" />
</n-form-item>
<n-flex class="ml-auto">
<NButton type="primary" @click="getUserList">
<template #icon>
<icon-park-outline-search />
</template>
搜索
</NButton>
<NButton strong secondary @click="handleResetSearch">
<template #icon>
<icon-park-outline-redo />
</template>
重置
</NButton>
</n-flex>
</n-flex>
</n-form>
</n-card>
<n-card>
<NSpace vertical size="large">
<n-data-table ref="tableRef" row-class-name="drag-handle" :columns="columns" :data="listData" :loading="loading" />
<Pagination :count="100" @change="changePage" />
</NSpace>
</n-card>
</NSpace>
</template>

View File

@ -6,20 +6,20 @@ import AMap from './components/AMap.vue'
import BMap from './components/BMap.vue' import BMap from './components/BMap.vue'
defineOptions({ defineOptions({
name: 'PluginMap', name: 'map',
}) })
const maps = [ const maps = [
{
id: 'AMap',
label: '高德地图',
component: AMap,
},
{ {
id: 'BMap', id: 'BMap',
label: '百度地图', label: '百度地图',
component: BMap, component: BMap,
}, },
{
id: 'AMap',
label: '高德地图',
component: AMap,
},
] ]
</script> </script>

View File

@ -0,0 +1,25 @@
<script setup lang="ts">
import { useTabStore } from '@/store'
const { modifyTab } = useTabStore()
const { fullPath, query } = useRoute()
modifyTab(fullPath, (target) => {
target.meta.title = `详情页${query.id}`
})
</script>
<template>
<n-space vertical>
<n-alert title="目前可公开的情报" type="warning">
这是详情子页他不会出现在侧边栏,他其实是上个页面的同级并不是下级这个要注意
</n-alert>
<n-h2>
详情页id:{{ query.id }}
</n-h2>
</n-space>
</template>
<style scoped></style>

Some files were not shown because too many files have changed in this diff Show More