mirror of
https://github.com/zclzone/vue-naive-admin.git
synced 2025-12-28 12:10:20 +08:00
Compare commits
108 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83b42bf6b8 | ||
|
|
fd08d25ccf | ||
|
|
76c3f0b64c | ||
|
|
a1db8273f5 | ||
|
|
f5ab04112f | ||
|
|
805b2e066f | ||
|
|
6979b245a9 | ||
|
|
dff8862c75 | ||
|
|
1da5e8d573 | ||
|
|
7f97dd2f5a | ||
|
|
1f69f07100 | ||
|
|
f97beeb54b | ||
|
|
57bc68e7b0 | ||
|
|
90aa54d4a4 | ||
|
|
7564f115d6 | ||
|
|
8d3753a80e | ||
|
|
a816028560 | ||
|
|
acde2c1004 | ||
|
|
cb5dd34e17 | ||
|
|
73c82520ca | ||
|
|
e465ee50bf | ||
|
|
2be3f095aa | ||
|
|
26ecafffdc | ||
|
|
7150d93394 | ||
|
|
6e26769679 | ||
|
|
b7ce7912a7 | ||
|
|
1fa9d4d472 | ||
|
|
fa11b1bc64 | ||
|
|
4bf8916fdc | ||
|
|
8496c08646 | ||
|
|
065868a40b | ||
|
|
dd4cd871ba | ||
|
|
a2b84d35f7 | ||
|
|
e128dfabc7 | ||
|
|
21c1d6d3aa | ||
|
|
3990d4da80 | ||
|
|
ac9ccbadf0 | ||
|
|
8ae4046285 | ||
|
|
f88b4f52a1 | ||
|
|
00ba77c15e | ||
|
|
39a80926bf | ||
|
|
16957a96b7 | ||
|
|
ef33b28492 | ||
|
|
ae43ffb94f | ||
|
|
f0b6ce7d20 | ||
|
|
c3354afa6c | ||
|
|
08ef914528 | ||
|
|
d86ee26ad6 | ||
|
|
c8495f7a5f | ||
|
|
0636ac4716 | ||
|
|
67d966e096 | ||
|
|
b5ac614943 | ||
|
|
9151b2d297 | ||
|
|
84f8431134 | ||
|
|
fdc49f6dcc | ||
|
|
d2b88a8300 | ||
|
|
ffc042167a | ||
|
|
85f9c91d6e | ||
|
|
21391b202f | ||
|
|
36ddb23db6 | ||
|
|
f3c391c031 | ||
|
|
df378f784b | ||
|
|
2154267615 | ||
|
|
3203a9a459 | ||
|
|
5ce2150706 | ||
|
|
5bd380037c | ||
|
|
e63e9f5cf2 | ||
|
|
74c244cf37 | ||
|
|
5cd85cf72d | ||
|
|
96d88a97f1 | ||
|
|
00c32a950a | ||
|
|
bfd048d40a | ||
|
|
1254a199d7 | ||
|
|
1190d08a87 | ||
|
|
958589edd0 | ||
|
|
2338ded165 | ||
|
|
4d6a58bfc8 | ||
|
|
f15e21b0a0 | ||
|
|
f88820b727 | ||
|
|
598d256be4 | ||
|
|
5b51cfb4f1 | ||
|
|
45c2e3aebe | ||
|
|
c2249d531f | ||
|
|
44c6b420d0 | ||
|
|
117a46a251 | ||
|
|
d8569a4eb1 | ||
|
|
c268b3c75d | ||
|
|
21e0d86fcd | ||
|
|
76bd414941 | ||
|
|
894b87426a | ||
|
|
f9c2362cd8 | ||
|
|
d922dcc224 | ||
|
|
7c8a17bbb2 | ||
|
|
321e19a3a5 | ||
|
|
bf2d45416f | ||
|
|
cf1b83d3f1 | ||
|
|
bf63fb5ab7 | ||
|
|
a6f86ee315 | ||
|
|
b2cf78b36d | ||
|
|
c9c0c35343 | ||
|
|
3c46d2c159 | ||
|
|
585bf4a4c4 | ||
|
|
2bd85e6e60 | ||
|
|
967ae1c483 | ||
|
|
238bceb500 | ||
|
|
c2145c0ddb | ||
|
|
d759c9b9ae | ||
|
|
3fdba613d3 |
42
.cz-config.js
Normal file
42
.cz-config.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
module.exports = {
|
||||||
|
types: [
|
||||||
|
{ value: 'feat', name:'feat: 新增功能' },
|
||||||
|
{ value: 'fix', name:'fix: 修复bug' },
|
||||||
|
{ value: 'docs', name:'docs: 文档变更' },
|
||||||
|
{ value: 'style', name:'style: 代码格式(不影响功能,例如空格、分号等格式修正)' },
|
||||||
|
{ value: 'refactor', name:'refactor: 代码重构(不包括 bug 修复、功能新增)' },
|
||||||
|
{ value: 'perf', name:'perf: 性能优化' },
|
||||||
|
{ value: 'test', name:'test: 添加、修改测试用例' },
|
||||||
|
{ value: 'build', name:'build: 构建流程、外部依赖变更(如升级 npm 包、修改 脚手架 配置等)' },
|
||||||
|
{ value: 'ci', name:'ci: 修改 CI 配置、脚本' },
|
||||||
|
{ value: 'chore', name:'chore: 对构建过程或辅助工具和库的更改(不影响源文件、测试用例)' },
|
||||||
|
{ value: 'revert', name:'revert: 回滚 commit' },
|
||||||
|
],
|
||||||
|
scopes: [
|
||||||
|
['custom', '自定义3'],
|
||||||
|
['projects', '项目搭建'],
|
||||||
|
['components', '组件相关'],
|
||||||
|
['utils', 'utils 相关'],
|
||||||
|
['styles', '样式相关'],
|
||||||
|
['deps', '项目依赖'],
|
||||||
|
['other', '其他修改'],
|
||||||
|
].map(([value, description]) => {
|
||||||
|
return {
|
||||||
|
value,
|
||||||
|
name: `${value.padEnd(30)} (${description})`
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
messages: {
|
||||||
|
type: '确保本次提交遵循 Angular 规范!选择你要提交的类型:\n',
|
||||||
|
scope: '选择一个 scope(可选):',
|
||||||
|
customScope: '请输入自定义的 scope:',
|
||||||
|
subject: '填写简短精炼的变更描述:',
|
||||||
|
body: '填写更加详细的变更描述(可选)。使用 "|" 换行:',
|
||||||
|
breaking: '列举非兼容性重大的变更(可选):',
|
||||||
|
footer: '列举出所有变更的 Issues Closed(可选)。 例如: #31, #34:',
|
||||||
|
confirmCommit: '确认提交?'
|
||||||
|
},
|
||||||
|
allowBreakingChanges: ['feat', 'fix'],
|
||||||
|
subjectLimit: 100,
|
||||||
|
breaklineChar: '|'
|
||||||
|
}
|
||||||
3
.env
3
.env
@@ -1,6 +1,3 @@
|
|||||||
VITE_APP_TITLE = 'Vue Naive Admin'
|
VITE_APP_TITLE = 'Vue Naive Admin'
|
||||||
|
|
||||||
VITE_PORT = 3100
|
VITE_PORT = 3100
|
||||||
|
|
||||||
# 打包时自动生成CNAME文件,用于配置github pages自定义域名,如不需要可注释或者直接删除
|
|
||||||
# VITE_APP_GLOB_CNAME = 'template.qszone.com'
|
|
||||||
@@ -8,7 +8,7 @@ VITE_APP_USE_MOCK = true
|
|||||||
VITE_PROXY = [["/api","http://localhost:8080"],["/api-test","localhost:8080"]]
|
VITE_PROXY = [["/api","http://localhost:8080"],["/api-test","localhost:8080"]]
|
||||||
|
|
||||||
# base api
|
# base api
|
||||||
VITE_APP_GLOB_BASE_API = '/api'
|
VITE_APP_BASE_API = '/api'
|
||||||
|
|
||||||
# test base api
|
# test base api
|
||||||
VITE_APP_GLOB_BASE_API_TEST = '/api-test'
|
VITE_APP_BASE_API_TEST = '/api-test'
|
||||||
@@ -10,7 +10,7 @@ VITE_APP_USE_HASH = true
|
|||||||
VITE_APP_USE_MOCK = true
|
VITE_APP_USE_MOCK = true
|
||||||
|
|
||||||
# base api
|
# base api
|
||||||
VITE_APP_GLOB_BASE_API = '/api'
|
VITE_APP_BASE_API = '/api'
|
||||||
|
|
||||||
# test base api
|
# test base api
|
||||||
VITE_APP_GLOB_BASE_API_TEST = '/api-test'
|
VITE_APP_BASE_API_TEST = '/api-test'
|
||||||
@@ -5,7 +5,7 @@ VITE_PUBLIC_PATH = '/'
|
|||||||
VITE_APP_USE_MOCK = true
|
VITE_APP_USE_MOCK = true
|
||||||
|
|
||||||
# base api
|
# base api
|
||||||
VITE_APP_GLOB_BASE_API = '/api'
|
VITE_APP_BASE_API = '/api'
|
||||||
|
|
||||||
# test base api
|
# test base api
|
||||||
VITE_APP_GLOB_BASE_API_TEST = '/api-test'
|
VITE_APP_BASE_API_TEST = '/api-test'
|
||||||
@@ -4,7 +4,7 @@ VITE_PUBLIC_PATH = '/'
|
|||||||
VITE_APP_USE_MOCK = true
|
VITE_APP_USE_MOCK = true
|
||||||
|
|
||||||
# base api
|
# base api
|
||||||
VITE_APP_GLOB_BASE_API = '/api'
|
VITE_APP_BASE_API = '/api'
|
||||||
|
|
||||||
# test base api
|
# test base api
|
||||||
VITE_APP_GLOB_BASE_API_TEST = '/api-test'
|
VITE_APP_BASE_API_TEST = '/api-test'
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
public
|
public
|
||||||
|
package.json
|
||||||
11
.eslintrc.js
11
.eslintrc.js
@@ -1,17 +1,6 @@
|
|||||||
// * https://zhuanlan.zhihu.com/p/388703150
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
root: true,
|
root: true,
|
||||||
env: {
|
|
||||||
browser: true, // browser global variables
|
|
||||||
node: true,
|
|
||||||
es2021: true, // adds all ECMAScript 2021 globals and automatically sets the ecmaVersion parser option to 12.
|
|
||||||
},
|
|
||||||
parserOptions: {
|
|
||||||
ecmaVersion: 2020,
|
|
||||||
},
|
|
||||||
parser: 'vue-eslint-parser',
|
|
||||||
extends: ['plugin:vue/vue3-recommended', 'plugin:prettier/recommended'],
|
extends: ['plugin:vue/vue3-recommended', 'plugin:prettier/recommended'],
|
||||||
plugins: ['prettier'],
|
|
||||||
rules: {
|
rules: {
|
||||||
'prettier/prettier': 'error',
|
'prettier/prettier': 'error',
|
||||||
'vue/valid-template-root': 'off',
|
'vue/valid-template-root': 'off',
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
*.local
|
*.local
|
||||||
|
stats.html
|
||||||
|
|||||||
36
.husky/_/husky.sh
Normal file
36
.husky/_/husky.sh
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
if [ -z "$husky_skip_init" ]; then
|
||||||
|
debug () {
|
||||||
|
if [ "$HUSKY_DEBUG" = "1" ]; then
|
||||||
|
echo "husky (debug) - $1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly hook_name="$(basename -- "$0")"
|
||||||
|
debug "starting $hook_name..."
|
||||||
|
|
||||||
|
if [ "$HUSKY" = "0" ]; then
|
||||||
|
debug "HUSKY env variable is set to 0, skipping hook"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f ~/.huskyrc ]; then
|
||||||
|
debug "sourcing ~/.huskyrc"
|
||||||
|
. ~/.huskyrc
|
||||||
|
fi
|
||||||
|
|
||||||
|
readonly husky_skip_init=1
|
||||||
|
export husky_skip_init
|
||||||
|
sh -e "$0" "$@"
|
||||||
|
exitCode="$?"
|
||||||
|
|
||||||
|
if [ $exitCode != 0 ]; then
|
||||||
|
echo "husky - $hook_name hook exited with code $exitCode (error)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $exitCode = 127 ]; then
|
||||||
|
echo "husky - command not found in PATH=$PATH"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $exitCode
|
||||||
|
fi
|
||||||
4
.husky/commit-msg
Normal file
4
.husky/commit-msg
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
npx --no-install commitlint --edit "$1"
|
||||||
4
.husky/pre-commit
Normal file
4
.husky/pre-commit
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
npm run lint
|
||||||
12
.vscode/extensions.json
vendored
12
.vscode/extensions.json
vendored
@@ -1,13 +1,9 @@
|
|||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": [
|
||||||
"dbaeumer.vscode-eslint",
|
"vue.volar",
|
||||||
"esbenp.prettier-vscode",
|
"antfu.iconify",
|
||||||
"johnsoncodehk.volar",
|
|
||||||
"hollowtree.vue-snippets",
|
|
||||||
"esbenp.prettier-vscode",
|
|
||||||
"mikestead.dotenv",
|
"mikestead.dotenv",
|
||||||
"wayou.vscode-todo-highlight",
|
"sdras.vue-vscode-snippets",
|
||||||
"aaron-bond.better-comments",
|
"cipchk.cssrem",
|
||||||
"antfu.iconify"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
27
.vscode/settings.json
vendored
27
.vscode/settings.json
vendored
@@ -1,30 +1,9 @@
|
|||||||
{
|
{
|
||||||
"files.eol": "\n",
|
"files.eol": "\n",
|
||||||
"path-intellisense.mappings": {
|
"editor.formatOnSave": false,
|
||||||
"@/": "${workspaceRoot}/src"
|
"eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"],
|
||||||
},
|
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
||||||
"[jsonc]": {
|
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
||||||
},
|
|
||||||
"[html]": {
|
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
||||||
},
|
|
||||||
"[javascript]": {
|
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
||||||
},
|
|
||||||
"[css]": {
|
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
||||||
},
|
|
||||||
"[vue]": {
|
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
|
||||||
},
|
|
||||||
"[markdown]": {
|
|
||||||
"editor.defaultFormatter": "yzhang.markdown-all-in-one"
|
|
||||||
},
|
|
||||||
"eslint.validate": ["javascript", "javascriptreact", "typescript"],
|
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": true
|
"source.fixAll.eslint": true
|
||||||
},
|
},
|
||||||
"editor.formatOnSave": true
|
"cssrem.rootFontSize": 4, // 适配unocss,1rem = 4px ==> 0.25rem = 1px
|
||||||
}
|
}
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -7,14 +7,13 @@
|
|||||||
<a href="https://github.com/zclzone/vue-naive-admin/actions"><img allt="checks" src="https://badgen.net/github/checks/zclzone/vue-naive-admin"/></a>
|
<a href="https://github.com/zclzone/vue-naive-admin/actions"><img allt="checks" src="https://badgen.net/github/checks/zclzone/vue-naive-admin"/></a>
|
||||||
<a href="https://github.com/zclzone/vue-naive-admin"><img allt="stars" src="https://badgen.net/github/stars/zclzone/vue-naive-admin"/></a>
|
<a href="https://github.com/zclzone/vue-naive-admin"><img allt="stars" src="https://badgen.net/github/stars/zclzone/vue-naive-admin"/></a>
|
||||||
<a href="https://github.com/zclzone/vue-naive-admin"><img allt="forks" src="https://badgen.net/github/forks/zclzone/vue-naive-admin"/></a>
|
<a href="https://github.com/zclzone/vue-naive-admin"><img allt="forks" src="https://badgen.net/github/forks/zclzone/vue-naive-admin"/></a>
|
||||||
<a href="https://github.com/zclzone/vue-naive-admin/releases"><img allt="releases" src="https://badgen.net/github/releases/zclzone/vue-naive-admin"/></a>
|
|
||||||
<a href="./LICENSE"><img allt="MIT License" src="https://badgen.net/github/license/zclzone/vue-naive-admin"/></a>
|
<a href="./LICENSE"><img allt="MIT License" src="https://badgen.net/github/license/zclzone/vue-naive-admin"/></a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
### 简介
|
### 简介
|
||||||
|
|
||||||
[Vue Naive Admin](https://github.com/zclzone/vue-naive-admin),一个基于 Vue3.0、Vite、Naive UI 的后台管理模板,相较于其他比较流行的后台管理模板,此项目相对简洁、轻量,学习成本非常低,对新手极其友好。不过麻雀虽小五脏俱全,权限、Mock、菜单、axios 封装、pinia、项目配置、样式配置、环境配置,以及一些经常用的基础组件封装等等这些该有的都有,非常适用于中小型项目或者个人项目,也可此模板进行二次封装改造用于大型项目。
|
[Vue Naive Admin](https://github.com/zclzone/vue-naive-admin)是一个 **完全开源免费且允许商用** 的后台管理模板,基于 Vue3、Vite2、Pinia 和 Naive UI等前端最新技术栈。相较于其他比较流行的后台管理模板,此项目相对简洁、轻量,学习成本非常低。麻雀虽小,五脏俱全,权限、Mock、菜单、axios 封装、pinia、项目配置、样式配置、环境配置,以及一些经常用的基础组件封装等等这些该有的都有,非常适合中小型项目或者个人项目。
|
||||||
|
|
||||||
### 为什么要开发这个模板
|
### 为什么要开发这个模板
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@
|
|||||||
- 🍍 集成 Pinia,Vuex 的替代方案,轻量、简单、易用(尤大已表示不会有Vuex5,或者说pinia就是Vuex5)
|
- 🍍 集成 Pinia,Vuex 的替代方案,轻量、简单、易用(尤大已表示不会有Vuex5,或者说pinia就是Vuex5)
|
||||||
- 📦 集成 Vite 自动导入插件unplugin-vue-components,解放双手,开发效率直接起飞
|
- 📦 集成 Vite 自动导入插件unplugin-vue-components,解放双手,开发效率直接起飞
|
||||||
- 🤹 集成 unplugin-icons插件,优雅使用iconify图标
|
- 🤹 集成 unplugin-icons插件,优雅使用iconify图标
|
||||||
- 🍏 二次封装 Axios,支持多 axios 实例,支持线上环境免重新打包修改 baseURL
|
- 🍏 二次封装 Axios,支持多 axios 实例
|
||||||
- 🍌 二次封装全局 Dialog、Message、LoadingBar 组件
|
- 🍌 二次封装全局 Dialog、Message、LoadingBar 组件
|
||||||
- 🍋 二次封装 localStorage 和 sessionStorage,支持设置过期时间
|
- 🍋 二次封装 localStorage 和 sessionStorage,支持设置过期时间
|
||||||
|
|
||||||
@@ -112,4 +111,12 @@ npm run preview
|
|||||||
- `types` 类型定义文件更改
|
- `types` 类型定义文件更改
|
||||||
- `wip` 开发中
|
- `wip` 开发中
|
||||||
- `mod` 不确定分类的修改
|
- `mod` 不确定分类的修改
|
||||||
|
- `release` 发布
|
||||||
|
|
||||||
|
### 入群交流
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<img src="https://assets.qszone.com/image/入群.png" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1 @@
|
|||||||
export const GLOB_CONFIG_FILE_NAME = 'app.config.js'
|
|
||||||
export const GLOB_CONFIG_NAME = '__APP__GLOB__CONF__'
|
|
||||||
export const OUTPUT_DIR = 'dist'
|
export const OUTPUT_DIR = 'dist'
|
||||||
|
|||||||
15
build/plugin/html.js
Normal file
15
build/plugin/html.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { createHtmlPlugin } from 'vite-plugin-html'
|
||||||
|
|
||||||
|
export function configHtmlPlugin(viteEnv, isBuild) {
|
||||||
|
const { VITE_APP_TITLE } = viteEnv
|
||||||
|
|
||||||
|
const htmlPlugin = createHtmlPlugin({
|
||||||
|
minify: isBuild,
|
||||||
|
inject: {
|
||||||
|
data: {
|
||||||
|
title: VITE_APP_TITLE,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return htmlPlugin
|
||||||
|
}
|
||||||
40
build/plugin/index.js
Normal file
40
build/plugin/index.js
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 扩展setup插件,支持在script标签中使用name属性
|
||||||
|
* usage: <script setup name="MyComp"></script>
|
||||||
|
*/
|
||||||
|
import vueSetupExtend from 'vite-plugin-vue-setup-extend-plus'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * unocss插件,原子css
|
||||||
|
* https://github.com/antfu/unocss
|
||||||
|
*/
|
||||||
|
import Unocss from 'unocss/vite'
|
||||||
|
|
||||||
|
// rollup打包分析插件
|
||||||
|
import visualizer from 'rollup-plugin-visualizer'
|
||||||
|
|
||||||
|
import { configHtmlPlugin } from './html'
|
||||||
|
import { configMockPlugin } from './mock'
|
||||||
|
import unplugin from './unplugin'
|
||||||
|
|
||||||
|
export function createVitePlugins(viteEnv, isBuild) {
|
||||||
|
const plugins = [vue(), vueSetupExtend(), ...unplugin, configHtmlPlugin(viteEnv, isBuild), Unocss()]
|
||||||
|
|
||||||
|
if (viteEnv?.VITE_APP_USE_MOCK) {
|
||||||
|
plugins.push(configMockPlugin(isBuild))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isBuild) {
|
||||||
|
plugins.push(
|
||||||
|
visualizer({
|
||||||
|
open: true,
|
||||||
|
gzipSize: true,
|
||||||
|
brotliSize: true,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugins
|
||||||
|
}
|
||||||
@@ -2,12 +2,11 @@ import { viteMockServe } from 'vite-plugin-mock'
|
|||||||
|
|
||||||
export function configMockPlugin(isBuild) {
|
export function configMockPlugin(isBuild) {
|
||||||
return viteMockServe({
|
return viteMockServe({
|
||||||
ignore: /^\_/,
|
mockPath: 'mock/modules',
|
||||||
mockPath: 'mock',
|
|
||||||
localEnabled: !isBuild,
|
localEnabled: !isBuild,
|
||||||
prodEnabled: isBuild,
|
prodEnabled: isBuild,
|
||||||
injectCode: `
|
injectCode: `
|
||||||
import { setupProdMockServer } from '../mock/_create-prod-server';
|
import { setupProdMockServer } from '../mock';
|
||||||
setupProdMockServer();
|
setupProdMockServer();
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
32
build/plugin/unplugin.js
Normal file
32
build/plugin/unplugin.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import AutoImport from 'unplugin-auto-import/vite'
|
||||||
|
import Components from 'unplugin-vue-components/vite'
|
||||||
|
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
|
||||||
|
import { FileSystemIconLoader } from 'unplugin-icons/loaders'
|
||||||
|
import IconsResolver from 'unplugin-icons/resolver'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * unplugin-icons插件,自动引入iconify图标
|
||||||
|
* usage: https://github.com/antfu/unplugin-icons
|
||||||
|
* 图标库: https://icones.js.org/
|
||||||
|
*/
|
||||||
|
import Icons from 'unplugin-icons/vite'
|
||||||
|
|
||||||
|
import { getRootPath } from '../utils'
|
||||||
|
|
||||||
|
const customIconPath = getRootPath('src', 'assets/icons')
|
||||||
|
export default [
|
||||||
|
AutoImport({
|
||||||
|
imports: ['vue', 'vue-router'],
|
||||||
|
}),
|
||||||
|
Icons({
|
||||||
|
compiler: 'vue3',
|
||||||
|
customCollections: {
|
||||||
|
custom: FileSystemIconLoader(customIconPath),
|
||||||
|
},
|
||||||
|
scale: 1,
|
||||||
|
defaultClass: 'inline-block',
|
||||||
|
}),
|
||||||
|
Components({
|
||||||
|
resolvers: [NaiveUiResolver(), IconsResolver({ customCollections: ['custom'], componentPrefix: 'icon' })],
|
||||||
|
}),
|
||||||
|
]
|
||||||
@@ -4,10 +4,10 @@ import { OUTPUT_DIR } from '../constant'
|
|||||||
import { getEnvConfig, getRootPath } from '../utils'
|
import { getEnvConfig, getRootPath } from '../utils'
|
||||||
|
|
||||||
export function runBuildCNAME() {
|
export function runBuildCNAME() {
|
||||||
const { VITE_APP_GLOB_CNAME } = getEnvConfig()
|
const { VITE_APP_CNAME } = getEnvConfig()
|
||||||
if (!VITE_APP_GLOB_CNAME) return
|
if (!VITE_APP_CNAME) return
|
||||||
try {
|
try {
|
||||||
writeFileSync(getRootPath(`${OUTPUT_DIR}/CNAME`), VITE_APP_GLOB_CNAME)
|
writeFileSync(getRootPath(`${OUTPUT_DIR}/CNAME`), VITE_APP_CNAME)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(chalk.red('CNAME file failed to package:\n' + error))
|
console.log(chalk.red('CNAME file failed to package:\n' + error))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
import { GLOB_CONFIG_FILE_NAME, GLOB_CONFIG_NAME, OUTPUT_DIR } from '../constant'
|
|
||||||
import fs, { writeFileSync } from 'fs-extra'
|
|
||||||
import chalk from 'chalk'
|
|
||||||
import { getEnvConfig, getRootPath } from '../utils'
|
|
||||||
|
|
||||||
function createConfig(option) {
|
|
||||||
const { config, configName, configFileName } = option
|
|
||||||
try {
|
|
||||||
const windowConf = `window.${configName}`
|
|
||||||
const configStr = `${windowConf}=${JSON.stringify(config)};
|
|
||||||
Object.freeze(${windowConf});
|
|
||||||
Object.defineProperty(window, "${configName}", {
|
|
||||||
configurable: false,
|
|
||||||
writable: false,
|
|
||||||
});
|
|
||||||
`.replace(/\s/g, '')
|
|
||||||
fs.mkdirp(getRootPath(OUTPUT_DIR))
|
|
||||||
writeFileSync(getRootPath(`${OUTPUT_DIR}/${configFileName}`), configStr)
|
|
||||||
} catch (error) {
|
|
||||||
console.log(chalk.red('configuration file configuration file failed to package:\n' + error))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function runBuildConfig() {
|
|
||||||
const config = getEnvConfig()
|
|
||||||
const configName = GLOB_CONFIG_NAME
|
|
||||||
const configFileName = GLOB_CONFIG_FILE_NAME
|
|
||||||
createConfig({ config, configName, configFileName })
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
import chalk from 'chalk'
|
import chalk from 'chalk'
|
||||||
import { runBuildConfig } from './build-config'
|
|
||||||
import { runBuildCNAME } from './build-cname'
|
import { runBuildCNAME } from './build-cname'
|
||||||
|
|
||||||
export const runBuild = async () => {
|
export const runBuild = async () => {
|
||||||
try {
|
try {
|
||||||
runBuildConfig()
|
|
||||||
runBuildCNAME()
|
runBuildCNAME()
|
||||||
console.log(`✨ ${chalk.cyan('build successfully!')}`)
|
console.log(`✨ ${chalk.cyan('build successfully!')}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import fs from 'fs'
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import dotenv from 'dotenv'
|
import dotenv from 'dotenv'
|
||||||
|
|
||||||
|
const httpsReg = /^https:\/\//
|
||||||
|
|
||||||
export function wrapperEnv(envOptions) {
|
export function wrapperEnv(envOptions) {
|
||||||
if (!envOptions) return {}
|
if (!envOptions) return {}
|
||||||
const ret = {}
|
const ret = {}
|
||||||
@@ -14,7 +16,7 @@ export function wrapperEnv(envOptions) {
|
|||||||
if (['VITE_PORT'].includes(key)) {
|
if (['VITE_PORT'].includes(key)) {
|
||||||
val = +val
|
val = +val
|
||||||
}
|
}
|
||||||
if (key === 'VITE_PROXY' && val) {
|
if (key === 'VITE_PROXY' && val && typeof val === 'string') {
|
||||||
try {
|
try {
|
||||||
val = JSON.parse(val.replace(/'/g, '"'))
|
val = JSON.parse(val.replace(/'/g, '"'))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -22,15 +24,33 @@ export function wrapperEnv(envOptions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret[key] = val
|
ret[key] = val
|
||||||
if (typeof key === 'string') {
|
if (typeof val === 'string') {
|
||||||
process.env[key] = val
|
process.env[key] = val
|
||||||
} else if (typeof key === 'object') {
|
} else if (typeof val === 'object') {
|
||||||
process.env[key] = JSON.stringify(val)
|
process.env[key] = JSON.stringify(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function createProxy(list = []) {
|
||||||
|
const ret = {}
|
||||||
|
for (const [prefix, target] of list) {
|
||||||
|
const isHttps = httpsReg.test(target)
|
||||||
|
|
||||||
|
// https://github.com/http-party/node-http-proxy#options
|
||||||
|
ret[prefix] = {
|
||||||
|
target: target,
|
||||||
|
changeOrigin: true,
|
||||||
|
ws: true,
|
||||||
|
rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
|
||||||
|
// https is require secure=false
|
||||||
|
...(isHttps ? { secure: false } : {}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前环境下生效的配置文件名
|
* 获取当前环境下生效的配置文件名
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
import html from 'vite-plugin-html'
|
|
||||||
import { version } from '../../../package.json'
|
|
||||||
import { GLOB_CONFIG_FILE_NAME } from '../../constant'
|
|
||||||
|
|
||||||
export function configHtmlPlugin(viteEnv, isBuild) {
|
|
||||||
const { VITE_APP_TITLE, VITE_PUBLIC_PATH } = viteEnv
|
|
||||||
const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`
|
|
||||||
|
|
||||||
const getAppConfigSrc = () => {
|
|
||||||
return `${path}${GLOB_CONFIG_FILE_NAME}?v=${version}-${new Date().getTime()}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const htmlPlugin = html({
|
|
||||||
minify: isBuild,
|
|
||||||
inject: {
|
|
||||||
data: {
|
|
||||||
title: VITE_APP_TITLE,
|
|
||||||
},
|
|
||||||
tags: isBuild
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
tag: 'script',
|
|
||||||
attrs: {
|
|
||||||
src: getAppConfigSrc(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return htmlPlugin
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import vue from '@vitejs/plugin-vue'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* * 扩展setup插件,支持在script标签中使用name属性
|
|
||||||
* usage: <script setup name="MyComp"></script>
|
|
||||||
*/
|
|
||||||
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* * 组件库按需引入插件
|
|
||||||
* usage: 直接使用组件,无需在任何地方导入组件
|
|
||||||
*/
|
|
||||||
import Components from 'unplugin-vue-components/vite'
|
|
||||||
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* * unplugin-icons插件,自动引入iconify图标
|
|
||||||
* usage: https://github.com/antfu/unplugin-icons
|
|
||||||
* 图标库: https://icones.js.org/
|
|
||||||
*/
|
|
||||||
import Icons from 'unplugin-icons/vite'
|
|
||||||
|
|
||||||
import { unocss } from './unocss'
|
|
||||||
import { configHtmlPlugin } from './html'
|
|
||||||
import { configMockPlugin } from './mock'
|
|
||||||
|
|
||||||
export function createVitePlugins(viteEnv, isBuild) {
|
|
||||||
const plugins = [
|
|
||||||
vue(),
|
|
||||||
VueSetupExtend(),
|
|
||||||
Components({
|
|
||||||
resolvers: [NaiveUiResolver()],
|
|
||||||
}),
|
|
||||||
Icons({ compiler: 'vue3', autoInstall: true }),
|
|
||||||
unocss(),
|
|
||||||
configHtmlPlugin(viteEnv, isBuild),
|
|
||||||
]
|
|
||||||
|
|
||||||
viteEnv?.VITE_APP_USE_MOCK && plugins.push(configMockPlugin(isBuild))
|
|
||||||
|
|
||||||
return plugins
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import Unocss from 'unocss/vite'
|
|
||||||
import { presetUno, presetAttributify, presetIcons } from 'unocss'
|
|
||||||
|
|
||||||
// https://github.com/antfu/unocss
|
|
||||||
export function unocss() {
|
|
||||||
return Unocss({
|
|
||||||
presets: [presetUno(), presetAttributify(), presetIcons()],
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
const httpsRE = /^https:\/\//
|
|
||||||
export function createProxy(list = []) {
|
|
||||||
const ret = {}
|
|
||||||
for (const [prefix, target] of list) {
|
|
||||||
const isHttps = httpsRE.test(target)
|
|
||||||
|
|
||||||
// https://github.com/http-party/node-http-proxy#options
|
|
||||||
ret[prefix] = {
|
|
||||||
target: target,
|
|
||||||
changeOrigin: true,
|
|
||||||
ws: true,
|
|
||||||
rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
|
|
||||||
// https is require secure=false
|
|
||||||
...(isHttps ? { secure: false } : {}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
4
commitlint.config.js
Normal file
4
commitlint.config.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = {
|
||||||
|
ignores: [(commit) => commit.includes('init')],
|
||||||
|
extends: ['@commitlint/config-conventional'],
|
||||||
|
}
|
||||||
21
index.html
21
index.html
@@ -8,11 +8,30 @@
|
|||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<link rel="icon" href="/favicon.svg" />
|
<link rel="icon" href="/favicon.svg" />
|
||||||
|
<link rel="stylesheet" href="/resource/loading.css" />
|
||||||
|
|
||||||
<title><%= title %></title>
|
<title><%= title %></title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app">
|
||||||
|
|
||||||
|
<!-- 白屏时的loading效果 -->
|
||||||
|
<div class="loading-container">
|
||||||
|
<div id="loadingLogo" class="loading-svg"></div>
|
||||||
|
<div class="loading-spin__container">
|
||||||
|
<div class="loading-spin">
|
||||||
|
<div class="left-0 top-0 loading-spin-item"></div>
|
||||||
|
<div class="left-0 bottom-0 loading-spin-item loading-delay-500"></div>
|
||||||
|
<div class="right-0 top-0 loading-spin-item loading-delay-1000"></div>
|
||||||
|
<div class="right-0 bottom-0 loading-spin-item loading-delay-1500"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="loading-title"><%= title %></div>
|
||||||
|
</div>
|
||||||
|
<script src="/resource/loading.js"></script>
|
||||||
|
|
||||||
|
</div>
|
||||||
<script type="module" src="/src/main.js"></script>
|
<script type="module" src="/src/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer'
|
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer'
|
||||||
|
|
||||||
const modules = import.meta.globEager('./**/*.js')
|
const modules = import.meta.globEager('./modules/*.js')
|
||||||
const mockModules = []
|
const mockModules = []
|
||||||
Object.keys(modules).forEach((key) => {
|
Object.keys(modules).forEach((key) => {
|
||||||
if (key.includes('/_')) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
mockModules.push(...modules[key].default)
|
mockModules.push(...modules[key].default)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { resolveToken } from '../_utils'
|
import { resolveToken } from '../utils'
|
||||||
|
|
||||||
const token = {
|
const token = {
|
||||||
admin: 'admin',
|
admin: 'admin',
|
||||||
87
mock/modules/post.js
Normal file
87
mock/modules/post.js
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
export default [
|
||||||
|
{
|
||||||
|
url: '/api/posts',
|
||||||
|
method: 'get',
|
||||||
|
response: () => {
|
||||||
|
return {
|
||||||
|
code: 0,
|
||||||
|
message: 'ok',
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
id: 36,
|
||||||
|
title: '使用纯css优雅配置移动端rem布局',
|
||||||
|
author: 'Ronnie',
|
||||||
|
category: '移动端,Css',
|
||||||
|
description: '通常配置rem布局会使用js进行处理,比如750的设计稿会这样...',
|
||||||
|
content: '通常配置rem布局会使用js进行处理,比如750的设计稿会这样',
|
||||||
|
isRecommend: true,
|
||||||
|
isPublish: true,
|
||||||
|
createDate: '2021-11-04T04:03:36.000Z',
|
||||||
|
updateDate: '2021-11-04T04:03:36.000Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 35,
|
||||||
|
title: 'Vue2&Vue3项目风格指南',
|
||||||
|
author: 'Ronnie',
|
||||||
|
category: 'Vue',
|
||||||
|
description: '总结的Vue2和Vue3的项目风格',
|
||||||
|
content: '### 1. 命名风格\n\n> 文件夹如果是由多个单词组成,应该始终是横线连接 ',
|
||||||
|
isRecommend: true,
|
||||||
|
isPublish: true,
|
||||||
|
createDate: '2021-10-25T08:57:47.000Z',
|
||||||
|
updateDate: '2022-02-28T04:02:39.000Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 28,
|
||||||
|
title: '如何优雅的给图片添加水印',
|
||||||
|
author: '张传龙',
|
||||||
|
category: 'JavaScript',
|
||||||
|
description: '优雅的给图片添加水印',
|
||||||
|
content: '我之前写过一篇文章记录了一次上传图片的优化史',
|
||||||
|
isRecommend: true,
|
||||||
|
isPublish: true,
|
||||||
|
createDate: '2021-06-24T18:46:19.000Z',
|
||||||
|
updateDate: '2021-09-23T07:51:22.000Z',
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
id: 26,
|
||||||
|
title: '前端缓存的理解',
|
||||||
|
author: '张传龙',
|
||||||
|
category: 'Http',
|
||||||
|
description: '谈谈前端缓存的理解',
|
||||||
|
content: '> 背景\n\n公司有个vue-cli3移动端web项目发版更新后发现部分用户手机在钉钉内置浏览器打开出现了缓存',
|
||||||
|
isRecommend: true,
|
||||||
|
isPublish: true,
|
||||||
|
createDate: '2021-06-10T18:51:19.000Z',
|
||||||
|
updateDate: '2021-09-17T09:33:24.000Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 24,
|
||||||
|
title: '使用jQuery的load方法帮女朋友实现套娃Html',
|
||||||
|
author: '张传龙',
|
||||||
|
category: 'JavaScript',
|
||||||
|
description: '最近女朋友刚入职新公司,接到的第一个任务就是将一个网站所有的页面合并成一个页面',
|
||||||
|
content: '最近女朋友刚入职新公司,接到的第一个任务就是将一个网站所有的页面合并成一个页面',
|
||||||
|
isRecommend: true,
|
||||||
|
isPublish: true,
|
||||||
|
createDate: '2021-05-26T15:26:06.000Z',
|
||||||
|
updateDate: '2021-09-17T09:33:24.000Z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 18,
|
||||||
|
title: 'Promise的五个静态方法',
|
||||||
|
author: '张传龙',
|
||||||
|
category: 'JavaScript',
|
||||||
|
description: '简单介绍下在 Promise 类中,有5 种静态方法及它们的使用场景',
|
||||||
|
content: '## 1. Promise.all\n\n并行执行多个 promise,并等待所有 promise 都准备就绪。再对它们进行处理。',
|
||||||
|
isRecommend: true,
|
||||||
|
isPublish: true,
|
||||||
|
createDate: '2021-02-22T22:37:06.000Z',
|
||||||
|
updateDate: '2021-09-17T09:33:24.000Z',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { resolveToken } from '../_utils'
|
import { resolveToken } from '../utils'
|
||||||
|
|
||||||
const users = {
|
const users = {
|
||||||
admin: {
|
admin: {
|
||||||
File diff suppressed because one or more lines are too long
44
package.json
44
package.json
@@ -1,34 +1,38 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-naive-admin",
|
"name": "vue-naive-admin",
|
||||||
"version": "0.3.2",
|
"version": "0.4.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"lint": "eslint --ext .js,.vue .",
|
"lint": "eslint --ext .js,.vue .",
|
||||||
"lint:fix": "eslint --fix --ext .js,.vue .",
|
"lint:fix": "eslint --fix --ext .js,.vue .",
|
||||||
"build": "vite build && esno ./build/script",
|
"build": "vite build",
|
||||||
"build:test": "vite build --mode test && esno ./build/script",
|
"build:test": "vite build --mode test",
|
||||||
"build:github": "vite build --mode github && esno ./build/script",
|
"build:github": "vite build --mode github && esno ./build/script",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview",
|
||||||
|
"prepare": "husky install",
|
||||||
|
"cz": "cz"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@vueuse/core": "^8.4.2",
|
||||||
"axios": "^0.21.4",
|
"axios": "^0.21.4",
|
||||||
"dayjs": "^1.11.0",
|
"dayjs": "^1.11.0",
|
||||||
"lodash-es": "^4.17.21",
|
|
||||||
"md-editor-v3": "^1.11.4",
|
"md-editor-v3": "^1.11.4",
|
||||||
"mockjs": "^1.1.0",
|
"mockjs": "^1.1.0",
|
||||||
"pinia": "^2.0.13",
|
"pinia": "^2.0.13",
|
||||||
"vue": "^3.2.31",
|
"vue": "^3.2.31",
|
||||||
"vue-router": "^4.0.14"
|
"vue-router": "^4.0.15"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@iconify-json/mdi": "^1.1.9",
|
"@commitlint/cli": "^17.0.3",
|
||||||
"@iconify-json/simple-icons": "^1.1.7",
|
"@commitlint/config-conventional": "^17.0.3",
|
||||||
"@unocss/preset-attributify": "^0.16.4",
|
"@iconify/json": "^2.1.63",
|
||||||
"@unocss/preset-icons": "^0.16.4",
|
"@iconify/vue": "^3.2.1",
|
||||||
"@unocss/preset-uno": "^0.16.4",
|
|
||||||
"@vitejs/plugin-vue": "^1.10.2",
|
"@vitejs/plugin-vue": "^1.10.2",
|
||||||
"@vue/compiler-sfc": "^3.2.31",
|
"@vue/compiler-sfc": "^3.2.31",
|
||||||
"chalk": "^5.0.1",
|
"chalk": "^5.0.1",
|
||||||
|
"commitizen": "^4.2.4",
|
||||||
|
"cz-conventional-changelog": "^3.3.0",
|
||||||
|
"cz-customizable": "^6.9.0",
|
||||||
"dotenv": "^10.0.0",
|
"dotenv": "^10.0.0",
|
||||||
"eslint": "^8.12.0",
|
"eslint": "^8.12.0",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^8.5.0",
|
||||||
@@ -36,15 +40,23 @@
|
|||||||
"eslint-plugin-vue": "^8.5.0",
|
"eslint-plugin-vue": "^8.5.0",
|
||||||
"esno": "^0.13.0",
|
"esno": "^0.13.0",
|
||||||
"fs-extra": "^10.0.1",
|
"fs-extra": "^10.0.1",
|
||||||
"naive-ui": "^2.27.0",
|
"husky": "^8.0.1",
|
||||||
|
"naive-ui": "^2.30.3",
|
||||||
"prettier": "^2.6.1",
|
"prettier": "^2.6.1",
|
||||||
|
"rollup-plugin-visualizer": "^5.6.0",
|
||||||
"sass": "^1.49.10",
|
"sass": "^1.49.10",
|
||||||
"unocss": "^0.16.4",
|
"unocss": "^0.43.2",
|
||||||
|
"unplugin-auto-import": "^0.8.8",
|
||||||
"unplugin-icons": "^0.14.1",
|
"unplugin-icons": "^0.14.1",
|
||||||
"unplugin-vue-components": "^0.17.21",
|
"unplugin-vue-components": "^0.17.21",
|
||||||
"vite": "^2.9.1",
|
"vite": "^2.9.9",
|
||||||
"vite-plugin-html": "^2.1.2",
|
"vite-plugin-html": "^3.2.0",
|
||||||
"vite-plugin-mock": "^2.9.6",
|
"vite-plugin-mock": "^2.9.6",
|
||||||
"vite-plugin-vue-setup-extend": "^0.3.0"
|
"vite-plugin-vue-setup-extend-plus": "^0.1.0"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"commitizen": {
|
||||||
|
"path": "node_modules/cz-customizable"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2363
pnpm-lock.yaml
generated
2363
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -3,4 +3,5 @@ module.exports = {
|
|||||||
singleQuote: true,
|
singleQuote: true,
|
||||||
semi: false,
|
semi: false,
|
||||||
endOfLine: 'lf',
|
endOfLine: 'lf',
|
||||||
|
bracketSameLine: true,
|
||||||
}
|
}
|
||||||
|
|||||||
91
public/resource/loading.css
Normal file
91
public/resource/loading.css
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
.loading-container {
|
||||||
|
position: fixed;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-svg {
|
||||||
|
width: 128px;
|
||||||
|
height: 128px;
|
||||||
|
color: var(--primaryColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spin__container {
|
||||||
|
width: 56px;
|
||||||
|
height: 56px;
|
||||||
|
margin: 36px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spin {
|
||||||
|
position: relative;
|
||||||
|
height: 100%;
|
||||||
|
animation: loadingSpin 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.left-0 {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
.right-0 {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
.top-0 {
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
|
.bottom-0 {
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-spin-item {
|
||||||
|
position: absolute;
|
||||||
|
height: 16px;
|
||||||
|
width: 16px;
|
||||||
|
background-color: var(--primaryColor);
|
||||||
|
border-radius: 8px;
|
||||||
|
-webkit-animation: loadingPulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
||||||
|
animation: loadingPulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes loadingSpin {
|
||||||
|
from {
|
||||||
|
-webkit-transform: rotate(0deg);
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
-webkit-transform: rotate(360deg);
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes loadingPulse {
|
||||||
|
0%, 100% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
opacity: .5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-delay-500 {
|
||||||
|
-webkit-animation-delay: 500ms;
|
||||||
|
animation-delay: 500ms;
|
||||||
|
}
|
||||||
|
.loading-delay-1000 {
|
||||||
|
-webkit-animation-delay: 1000ms;
|
||||||
|
animation-delay: 1000ms;
|
||||||
|
}
|
||||||
|
.loading-delay-1500 {
|
||||||
|
-webkit-animation-delay: 1500ms;
|
||||||
|
animation-delay: 1500ms;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading-title {
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #6a6a6a;
|
||||||
|
}
|
||||||
25
public/resource/loading.js
Normal file
25
public/resource/loading.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* 初始化加载效果的svg格式logo
|
||||||
|
* @param {string} id - 元素id
|
||||||
|
*/
|
||||||
|
function initSvgLogo(id) {
|
||||||
|
const svgStr = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 448 512" data-v-fba6e5d0=""><path d="M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48zm-92.2 312.9c-63.4 0-85.4-28.6-97.1-64.1c-16.3-51-21.5-84.3-63-84.3c-22.4 0-45.1 16.1-45.1 61.2c0 35.2 18 57.2 43.3 57.2c28.6 0 47.6-21.3 47.6-21.3l11.7 31.9s-19.8 19.4-61.2 19.4c-51.3 0-79.9-30.1-79.9-85.8c0-57.9 28.6-92 82.5-92c73.5 0 80.8 41.4 100.8 101.9c8.8 26.8 24.2 46.2 61.2 46.2c24.9 0 38.1-5.5 38.1-19.1c0-19.9-21.8-22-49.9-28.6c-30.4-7.3-42.5-23.1-42.5-48c0-40 32.3-52.4 65.2-52.4c37.4 0 60.1 13.6 63 46.6l-36.7 4.4c-1.5-15.8-11-22.4-28.6-22.4c-16.1 0-26 7.3-26 19.8c0 11 4.8 17.6 20.9 21.3c32.7 7.1 71.8 12 71.8 57.5c.1 36.7-30.7 50.6-76.1 50.6z" style="fill:currentColor"></path></svg>`;
|
||||||
|
const appEl = document.querySelector(id);
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.innerHTML = svgStr;
|
||||||
|
if (appEl) {
|
||||||
|
appEl.appendChild(div);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addThemeColorCssVars() {
|
||||||
|
const key = '__THEME_COLOR__'
|
||||||
|
const defaultColor = '#316c72';
|
||||||
|
const themeColor = window.localStorage.getItem(key) || defaultColor;
|
||||||
|
const cssVars = `--primaryColor: ${themeColor}`;
|
||||||
|
document.documentElement.style.cssText = cssVars;
|
||||||
|
}
|
||||||
|
|
||||||
|
addThemeColorCssVars();
|
||||||
|
|
||||||
|
initSvgLogo('#loadingLogo');
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import AppProvider from '@/components/AppProvider/index.vue'
|
import AppProvider from '@/components/common/AppProvider.vue'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { defAxios as request } from '@/utils/http'
|
import { defAxios as request } from '@/utils/http'
|
||||||
|
|
||||||
export function getPosts(data = {}) {
|
export function getPosts(params = {}) {
|
||||||
return request({
|
return request({
|
||||||
url: '/posts',
|
url: '/posts',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
data,
|
params,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { defAxios as request } from '@/utils/http'
|
import { defAxios as request } from '@/utils/http'
|
||||||
|
|
||||||
export function getUsers(data = {}) {
|
export function getUsers(params = {}) {
|
||||||
return request({
|
return request({
|
||||||
url: '/users',
|
url: '/users',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
data,
|
params,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 825 B After Width: | Height: | Size: 825 B |
Binary file not shown.
|
Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 46 KiB |
@@ -1,9 +0,0 @@
|
|||||||
<template>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 448 512">
|
|
||||||
<path
|
|
||||||
d="M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48zm-92.2 312.9c-63.4 0-85.4-28.6-97.1-64.1c-16.3-51-21.5-84.3-63-84.3c-22.4 0-45.1 16.1-45.1 61.2c0 35.2 18 57.2 43.3 57.2c28.6 0 47.6-21.3 47.6-21.3l11.7 31.9s-19.8 19.4-61.2 19.4c-51.3 0-79.9-30.1-79.9-85.8c0-57.9 28.6-92 82.5-92c73.5 0 80.8 41.4 100.8 101.9c8.8 26.8 24.2 46.2 61.2 46.2c24.9 0 38.1-5.5 38.1-19.1c0-19.9-21.8-22-49.9-28.6c-30.4-7.3-42.5-23.1-42.5-48c0-40 32.3-52.4 65.2-52.4c37.4 0 60.1 13.6 63 46.6l-36.7 4.4c-1.5-15.8-11-22.4-28.6-22.4c-16.1 0-26 7.3-26 19.8c0 11 4.8 17.6 20.9 21.3c32.7 7.1 71.8 12 71.8 57.5c.1 36.7-30.7 50.6-76.1 50.6z"
|
|
||||||
></path>
|
|
||||||
</svg>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup name="IconLogo"></script>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
export { default as IconGitee } from '~icons/simple-icons/gitee'
|
|
||||||
|
|
||||||
export { default as IconChart } from '~icons/mdi/chart-bar'
|
|
||||||
export { default as IconGithub } from '~icons/mdi/github'
|
|
||||||
export { default as IconVue } from '~icons/mdi/vuejs'
|
|
||||||
export { default as IconHome } from '~icons/mdi/home'
|
|
||||||
export { default as IconLink } from '~icons/mdi/link-variant'
|
|
||||||
export { default as IconAlert } from '~icons/mdi/alert-circle-outline'
|
|
||||||
export { default as IconCircle } from '~icons/mdi/circle-outline'
|
|
||||||
export { default as IconMenu } from '~icons/mdi/menu'
|
|
||||||
|
|
||||||
export { default as IconLogo } from './IconLogo.vue'
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<template></template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { isNullOrUndef } from '@/utils/is'
|
|
||||||
import { useDialog } from 'naive-ui'
|
|
||||||
|
|
||||||
const NDialog = useDialog()
|
|
||||||
|
|
||||||
class Dialog {
|
|
||||||
success(title, option) {
|
|
||||||
return this.showDialog('success', { title, ...option })
|
|
||||||
}
|
|
||||||
|
|
||||||
warning(title, option) {
|
|
||||||
return this.showDialog('warning', { title, ...option })
|
|
||||||
}
|
|
||||||
|
|
||||||
error(title, option) {
|
|
||||||
return this.showDialog('error', { title, ...option })
|
|
||||||
}
|
|
||||||
|
|
||||||
showDialog(type = 'success', option) {
|
|
||||||
if (isNullOrUndef(option.title)) {
|
|
||||||
// ! 没有title的情况
|
|
||||||
option.showIcon = false
|
|
||||||
}
|
|
||||||
return NDialog[type]({
|
|
||||||
positiveText: 'OK',
|
|
||||||
closable: false,
|
|
||||||
...option,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
confirm(option = {}) {
|
|
||||||
return this.showDialog(option.type || 'error', {
|
|
||||||
positiveText: '确定',
|
|
||||||
negativeText: '取消',
|
|
||||||
onPositiveClick: option.confirm,
|
|
||||||
onNegativeClick: option.cancel,
|
|
||||||
onMaskClick: option.cancel,
|
|
||||||
...option,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window['$dialog'] = new Dialog()
|
|
||||||
Object.freeze(window.$dialog)
|
|
||||||
Object.defineProperty(window, '$dialog', {
|
|
||||||
configurable: false,
|
|
||||||
writable: false,
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<template></template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { useLoadingBar } from 'naive-ui'
|
|
||||||
window['$loadingBar'] = useLoadingBar()
|
|
||||||
Object.defineProperty(window, '$loadingBar', {
|
|
||||||
configurable: false,
|
|
||||||
writable: false,
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
<template></template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { useMessage } from 'naive-ui'
|
|
||||||
|
|
||||||
const NMessage = useMessage()
|
|
||||||
|
|
||||||
let loadingMessage = null
|
|
||||||
|
|
||||||
class Message {
|
|
||||||
/**
|
|
||||||
* 规则:
|
|
||||||
* * loading message只显示一个,新的message会替换正在显示的loading message
|
|
||||||
* * loading message不会自动清除,除非被替换成非loading message,非loading message默认2秒后自动清除
|
|
||||||
*/
|
|
||||||
|
|
||||||
removeMessage(message, duration = 2000) {
|
|
||||||
setTimeout(() => {
|
|
||||||
if (message) {
|
|
||||||
message.destroy()
|
|
||||||
message = null
|
|
||||||
}
|
|
||||||
}, duration)
|
|
||||||
}
|
|
||||||
|
|
||||||
showMessage(type, content, option = {}) {
|
|
||||||
if (loadingMessage && loadingMessage.type === 'loading') {
|
|
||||||
// 如果存在则替换正在显示的loading message
|
|
||||||
loadingMessage.type = type
|
|
||||||
loadingMessage.content = content
|
|
||||||
|
|
||||||
if (type !== 'loading') {
|
|
||||||
// 非loading message需设置自动清除
|
|
||||||
this.removeMessage(loadingMessage, option.duration)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 不存在正在显示的loading则新建一个message,如果新建的message是loading message则将message赋值存储下来
|
|
||||||
let message = NMessage[type](content, option)
|
|
||||||
if (type === 'loading') {
|
|
||||||
loadingMessage = message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loading(content) {
|
|
||||||
this.showMessage('loading', content, { duration: 0 })
|
|
||||||
}
|
|
||||||
|
|
||||||
success(content, option = {}) {
|
|
||||||
this.showMessage('success', content, option)
|
|
||||||
}
|
|
||||||
|
|
||||||
error(content, option = {}) {
|
|
||||||
this.showMessage('error', content, option)
|
|
||||||
}
|
|
||||||
|
|
||||||
info(content, option = {}) {
|
|
||||||
this.showMessage('info', content, option)
|
|
||||||
}
|
|
||||||
|
|
||||||
warning(content, option = {}) {
|
|
||||||
this.showMessage('warning', content, option)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
window['$message'] = new Message()
|
|
||||||
|
|
||||||
Object.defineProperty(window, '$message', {
|
|
||||||
configurable: false,
|
|
||||||
writable: false,
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<template>
|
|
||||||
<n-config-provider :theme-overrides="useTheme.naiveThemeOverrides">
|
|
||||||
<n-loading-bar-provider>
|
|
||||||
<LoadingBar />
|
|
||||||
<n-dialog-provider>
|
|
||||||
<DialogContent />
|
|
||||||
<n-message-provider>
|
|
||||||
<MessageContent />
|
|
||||||
<slot></slot>
|
|
||||||
</n-message-provider>
|
|
||||||
</n-dialog-provider>
|
|
||||||
</n-loading-bar-provider>
|
|
||||||
</n-config-provider>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import MessageContent from './MessageContent.vue'
|
|
||||||
import DialogContent from './DialogContent.vue'
|
|
||||||
import LoadingBar from './LoadingBar.vue'
|
|
||||||
import { useThemeStore } from '@/store/modules/theme'
|
|
||||||
|
|
||||||
const useTheme = useThemeStore()
|
|
||||||
</script>
|
|
||||||
55
src/components/common/AppProvider.vue
Normal file
55
src/components/common/AppProvider.vue
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<template>
|
||||||
|
<n-config-provider :theme-overrides="themStore.naiveThemeOverrides">
|
||||||
|
<n-loading-bar-provider>
|
||||||
|
<n-dialog-provider>
|
||||||
|
<n-notification-provider>
|
||||||
|
<n-message-provider>
|
||||||
|
<slot></slot>
|
||||||
|
<NaiveProviderContent />
|
||||||
|
</n-message-provider>
|
||||||
|
</n-notification-provider>
|
||||||
|
</n-dialog-provider>
|
||||||
|
</n-loading-bar-provider>
|
||||||
|
</n-config-provider>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { defineComponent, h } from 'vue'
|
||||||
|
import { useLoadingBar, useDialog, useMessage, useNotification } from 'naive-ui'
|
||||||
|
|
||||||
|
import { useCssVar } from '@vueuse/core'
|
||||||
|
import { useThemeStore } from '@/store/modules/theme'
|
||||||
|
import { setupMessage, setupDialog } from '@/utils/common/naiveTools'
|
||||||
|
|
||||||
|
const themStore = useThemeStore()
|
||||||
|
watch(
|
||||||
|
() => themStore.naiveThemeOverrides.common,
|
||||||
|
(vars) => {
|
||||||
|
for (const key in vars) {
|
||||||
|
useCssVar(`--${key}`, document.documentElement).value = vars[key]
|
||||||
|
if (key === 'primaryColor') {
|
||||||
|
window.localStorage.setItem('__THEME_COLOR__', vars[key])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
// 挂载naive组件的方法至window, 以便在全局使用
|
||||||
|
function setupNaiveTools() {
|
||||||
|
window.$loadingBar = useLoadingBar()
|
||||||
|
window.$notification = useNotification()
|
||||||
|
|
||||||
|
window.$message = setupMessage(useMessage())
|
||||||
|
window.$dialog = setupDialog(useDialog())
|
||||||
|
}
|
||||||
|
|
||||||
|
const NaiveProviderContent = defineComponent({
|
||||||
|
setup() {
|
||||||
|
setupNaiveTools()
|
||||||
|
},
|
||||||
|
render() {
|
||||||
|
return h('div')
|
||||||
|
},
|
||||||
|
})
|
||||||
|
</script>
|
||||||
139
src/components/common/ScrollX.vue
Normal file
139
src/components/common/ScrollX.vue
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
<template>
|
||||||
|
<div ref="wrapper" class="wrapper" @mousewheel.prevent="handleMouseWheel">
|
||||||
|
<template v-if="showArrow && isOverflow">
|
||||||
|
<div class="left" @click="handleMouseWheel({ wheelDelta: 120 })">
|
||||||
|
<icon-ic:baseline-keyboard-arrow-left />
|
||||||
|
</div>
|
||||||
|
<div class="right" @click="handleMouseWheel({ wheelDelta: -120 })">
|
||||||
|
<icon-ic:baseline-keyboard-arrow-right />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<div
|
||||||
|
ref="content"
|
||||||
|
class="content"
|
||||||
|
:class="{ overflow: isOverflow && showArrow }"
|
||||||
|
:style="{
|
||||||
|
transform: `translateX(${translateX}px)`,
|
||||||
|
}">
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { debounce } from '@/utils'
|
||||||
|
|
||||||
|
defineProps({
|
||||||
|
showArrow: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const translateX = ref(0)
|
||||||
|
const content = ref(null)
|
||||||
|
const wrapper = ref(null)
|
||||||
|
const isOverflow = ref(false)
|
||||||
|
|
||||||
|
const refreshIsOverflow = debounce(() => {
|
||||||
|
const wrapperWidth = wrapper.value.offsetWidth
|
||||||
|
const contentWidth = content.value.offsetWidth
|
||||||
|
isOverflow.value = contentWidth > wrapperWidth
|
||||||
|
resetTranslateX(wrapperWidth, contentWidth)
|
||||||
|
}, 200)
|
||||||
|
|
||||||
|
function handleMouseWheel(e) {
|
||||||
|
const { wheelDelta } = e
|
||||||
|
const wrapperWidth = wrapper.value.offsetWidth
|
||||||
|
const contentWidth = content.value.offsetWidth
|
||||||
|
/**
|
||||||
|
* @wheelDelta 平行滚动的值 >0: 右移 <0: 左移
|
||||||
|
* @translateX 内容translateX的值
|
||||||
|
* @wrapperWidth 容器的宽度
|
||||||
|
* @contentWidth 内容的宽度
|
||||||
|
*/
|
||||||
|
if (wheelDelta < 0) {
|
||||||
|
if (wrapperWidth > contentWidth && translateX.value < -10) return
|
||||||
|
if (wrapperWidth <= contentWidth && contentWidth + translateX.value - wrapperWidth < -10) return
|
||||||
|
}
|
||||||
|
if (wheelDelta > 0 && translateX.value > 10) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
translateX.value += wheelDelta
|
||||||
|
resetTranslateX(wrapperWidth, contentWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
const resetTranslateX = debounce(function (wrapperWidth, contentWidth) {
|
||||||
|
if (!isOverflow.value) {
|
||||||
|
translateX.value = 0
|
||||||
|
} else if (-translateX.value > contentWidth - wrapperWidth) {
|
||||||
|
translateX.value = wrapperWidth - contentWidth
|
||||||
|
} else if (translateX.value > 0) {
|
||||||
|
translateX.value = 0
|
||||||
|
}
|
||||||
|
}, 200)
|
||||||
|
|
||||||
|
const observer = new MutationObserver(refreshIsOverflow)
|
||||||
|
onMounted(() => {
|
||||||
|
refreshIsOverflow()
|
||||||
|
|
||||||
|
window.addEventListener('resize', refreshIsOverflow)
|
||||||
|
// 监听内容宽度刷新是否超出
|
||||||
|
observer.observe(content.value, { childList: true })
|
||||||
|
})
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.removeEventListener('resize', refreshIsOverflow)
|
||||||
|
observer.disconnect()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.wrapper {
|
||||||
|
display: flex;
|
||||||
|
background-color: #fff;
|
||||||
|
|
||||||
|
z-index: 9;
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
.content {
|
||||||
|
padding: 0 10px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
transition: transform 0.5s;
|
||||||
|
&.overflow {
|
||||||
|
padding-left: 30px;
|
||||||
|
padding-right: 30px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.left,
|
||||||
|
.right {
|
||||||
|
background-color: #fff;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
margin: auto;
|
||||||
|
|
||||||
|
width: 20px;
|
||||||
|
height: 35px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
font-size: 18px;
|
||||||
|
border: 1px solid #e0e0e6;
|
||||||
|
border-radius: 2px;
|
||||||
|
|
||||||
|
z-index: 2;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.left {
|
||||||
|
left: 0;
|
||||||
|
}
|
||||||
|
.right {
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -2,15 +2,16 @@
|
|||||||
<router-view v-slot="{ Component, route }">
|
<router-view v-slot="{ Component, route }">
|
||||||
<transition name="fade-slide" mode="out-in" appear>
|
<transition name="fade-slide" mode="out-in" appear>
|
||||||
<keep-alive :include="keepAliveRouteNames">
|
<keep-alive :include="keepAliveRouteNames">
|
||||||
<component :is="Component" :key="route.path" />
|
<component :is="Component" v-if="appStore.reloadFlag" :key="route.path" />
|
||||||
</keep-alive>
|
</keep-alive>
|
||||||
</transition>
|
</transition>
|
||||||
</router-view>
|
</router-view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { computed } from 'vue'
|
import { useAppStore } from '@/store/modules/app'
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
|
const appStore = useAppStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const allRoutes = router.getRoutes()
|
const allRoutes = router.getRoutes()
|
||||||
const keepAliveRouteNames = computed(() => {
|
const keepAliveRouteNames = computed(() => {
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
<template>
|
|
||||||
<n-breadcrumb>
|
|
||||||
<n-breadcrumb-item v-for="item in currentRoute.matched" :key="item.path" @click="handleBreadClick(item.path)">
|
|
||||||
{{ item.meta.title }}
|
|
||||||
</n-breadcrumb-item>
|
|
||||||
</n-breadcrumb>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
const router = useRouter()
|
|
||||||
const { currentRoute } = router
|
|
||||||
|
|
||||||
function handleBreadClick(path) {
|
|
||||||
if (path === currentRoute.value.path) return
|
|
||||||
router.push(path)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
<template>
|
|
||||||
<n-dropdown :options="options" @select="handleSelect">
|
|
||||||
<div class="avatar">
|
|
||||||
<img :src="userStore.avatar" />
|
|
||||||
<span>{{ userStore.name }}</span>
|
|
||||||
</div>
|
|
||||||
</n-dropdown>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { useUserStore } from '@/store/modules/user'
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
import { resetRouter } from '@/router'
|
|
||||||
import { usePermissionStore } from '@/store/modules/permission'
|
|
||||||
import { NOT_FOUND_ROUTE } from '@/router/routes'
|
|
||||||
|
|
||||||
const userStore = useUserStore()
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const options = [
|
|
||||||
{
|
|
||||||
label: '切换角色',
|
|
||||||
key: 'switchRole',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: '退出登录',
|
|
||||||
key: 'logout',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
function handleSelect(key) {
|
|
||||||
if (key === 'logout') {
|
|
||||||
logout()
|
|
||||||
} else if (key === 'switchRole') {
|
|
||||||
switchRole()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function logout() {
|
|
||||||
userStore.logout()
|
|
||||||
$message.success('已退出登录')
|
|
||||||
router.push({ path: '/login' })
|
|
||||||
}
|
|
||||||
|
|
||||||
function switchRole() {
|
|
||||||
const permissionStore = usePermissionStore()
|
|
||||||
|
|
||||||
const users = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: '大脸怪(admin)',
|
|
||||||
avatar: 'https://assets.qszone.com/images/avatar.jpg',
|
|
||||||
email: 'Ronnie@123.com',
|
|
||||||
role: ['admin'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: '大脸怪(editor)',
|
|
||||||
avatar: 'https://assets.qszone.com/images/avatar.jpg',
|
|
||||||
email: 'Ronnie@123.com',
|
|
||||||
role: ['editor'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
name: '访客(guest)',
|
|
||||||
avatar: 'https://assets.qszone.com/images/avatar.jpg',
|
|
||||||
role: [],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const switchUser = users[+userStore.userId % users.length]
|
|
||||||
resetRouter()
|
|
||||||
userStore.setUserInfo(switchUser)
|
|
||||||
const accessRoutes = permissionStore.generateRoutes(switchUser.role)
|
|
||||||
accessRoutes.forEach((route) => {
|
|
||||||
!router.hasRoute(route.name) && router.addRoute(route)
|
|
||||||
})
|
|
||||||
router.addRoute(NOT_FOUND_ROUTE)
|
|
||||||
$message.success(`${switchUser.name}`)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.avatar {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
cursor: pointer;
|
|
||||||
img {
|
|
||||||
width: 100%;
|
|
||||||
width: 25px;
|
|
||||||
height: 25px;
|
|
||||||
border-radius: 50%;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
20
src/layout/components/header/components/BreadCrumb.vue
Normal file
20
src/layout/components/header/components/BreadCrumb.vue
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<template>
|
||||||
|
<n-breadcrumb>
|
||||||
|
<n-breadcrumb-item v-for="item in route.matched" :key="item.path" @click="handleBreadClick(item.path)">
|
||||||
|
<component :is="renderIcon(item.meta?.icon, { size: 16 })" v-if="item.meta?.icon" />
|
||||||
|
{{ item.meta.title }}
|
||||||
|
</n-breadcrumb-item>
|
||||||
|
</n-breadcrumb>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { renderIcon } from '@/utils/icon'
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
function handleBreadClick(path) {
|
||||||
|
if (path === route.path) return
|
||||||
|
router.push(path)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
12
src/layout/components/header/components/FullScreen.vue
Normal file
12
src/layout/components/header/components/FullScreen.vue
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<template>
|
||||||
|
<n-icon mr20 size="18" style="cursor: pointer" @click="toggle">
|
||||||
|
<icon-ant-design:fullscreen-outlined v-if="isFullscreen" />
|
||||||
|
<icon-ant-design:fullscreen-outlined v-else />
|
||||||
|
</n-icon>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { useFullscreen } from '@vueuse/core'
|
||||||
|
|
||||||
|
const { isFullscreen, toggle } = useFullscreen()
|
||||||
|
</script>
|
||||||
13
src/layout/components/header/components/GithubSite.vue
Normal file
13
src/layout/components/header/components/GithubSite.vue
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<template>
|
||||||
|
<n-icon mr20 size="18" style="cursor: pointer" @click="handleLinkClick">
|
||||||
|
<icon-mdi:github />
|
||||||
|
</n-icon>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
function handleLinkClick() {
|
||||||
|
window.open('https://github.com/zclzone/vue-naive-admin')
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped></style>
|
||||||
12
src/layout/components/header/components/MenuCollapse.vue
Normal file
12
src/layout/components/header/components/MenuCollapse.vue
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<template>
|
||||||
|
<n-icon size="20" style="cursor: pointer" @click="appStore.switchCollapsed">
|
||||||
|
<icon-mdi:format-indent-increase v-if="appStore.collapsed" />
|
||||||
|
<icon-mdi:format-indent-decrease v-else />
|
||||||
|
</n-icon>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { useAppStore } from '@/store/modules/app'
|
||||||
|
|
||||||
|
const appStore = useAppStore()
|
||||||
|
</script>
|
||||||
52
src/layout/components/header/components/UserAvatar.vue
Normal file
52
src/layout/components/header/components/UserAvatar.vue
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<template>
|
||||||
|
<n-dropdown :options="options" @select="handleSelect">
|
||||||
|
<div class="avatar">
|
||||||
|
<img :src="userStore.avatar" />
|
||||||
|
<span>{{ userStore.name }}</span>
|
||||||
|
</div>
|
||||||
|
</n-dropdown>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { useUserStore } from '@/store/modules/user'
|
||||||
|
import { renderIcon } from '@/utils/icon'
|
||||||
|
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
|
const options = [
|
||||||
|
{
|
||||||
|
label: '退出登录',
|
||||||
|
key: 'logout',
|
||||||
|
icon: renderIcon('mdi:exit-to-app', { size: '14px' }),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
function handleSelect(key) {
|
||||||
|
if (key === 'logout') {
|
||||||
|
$dialog.confirm({
|
||||||
|
title: '提示',
|
||||||
|
type: 'info',
|
||||||
|
content: '确认退出?',
|
||||||
|
confirm() {
|
||||||
|
userStore.logout()
|
||||||
|
$message.success('已退出登录')
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.avatar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
img {
|
||||||
|
width: 100%;
|
||||||
|
width: 35px;
|
||||||
|
height: 35px;
|
||||||
|
border-radius: 50%;
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,21 +1,39 @@
|
|||||||
<template>
|
<template>
|
||||||
<header class="header">
|
<header class="header">
|
||||||
<BreadCrumb />
|
<div class="h-left">
|
||||||
<HeaderAction />
|
<MenuCollapse />
|
||||||
|
<BreadCrumb ml-15 />
|
||||||
|
</div>
|
||||||
|
<div class="h-right">
|
||||||
|
<GithubSite />
|
||||||
|
<FullScreen />
|
||||||
|
<UserAvatar />
|
||||||
|
</div>
|
||||||
</header>
|
</header>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import BreadCrumb from './BreadCrumb.vue'
|
import BreadCrumb from './components/BreadCrumb.vue'
|
||||||
import HeaderAction from './HeaderAction.vue'
|
import MenuCollapse from './components/MenuCollapse.vue'
|
||||||
|
import FullScreen from './components/FullScreen.vue'
|
||||||
|
import UserAvatar from './components/UserAvatar.vue'
|
||||||
|
import GithubSite from './components/GithubSite.vue'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.header {
|
.header {
|
||||||
padding: 0 24px;
|
padding: 0 15px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
.h-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
.h-right {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="logo">
|
|
||||||
<n-icon size="36" color="#316c72">
|
|
||||||
<IconLogo />
|
|
||||||
</n-icon>
|
|
||||||
<router-link to="/">
|
|
||||||
<n-gradient-text type="primary">{{ title }}</n-gradient-text>
|
|
||||||
</router-link>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { IconLogo } from '@/components/AppIcons'
|
|
||||||
const title = import.meta.env.VITE_APP_TITLE
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.logo {
|
|
||||||
height: 64px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
a {
|
|
||||||
margin-left: 5px;
|
|
||||||
.n-gradient-text {
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,134 +0,0 @@
|
|||||||
<template>
|
|
||||||
<n-menu
|
|
||||||
class="side-menu"
|
|
||||||
accordion
|
|
||||||
:indent="12"
|
|
||||||
:root-indent="12"
|
|
||||||
:options="menuOptions"
|
|
||||||
:value="(currentRoute.meta && currentRoute.meta.activeMenu) || currentRoute.name"
|
|
||||||
@update:value="handleMenuSelect"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup>
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
import { computed, h } from 'vue'
|
|
||||||
import { usePermissionStore } from '@/store/modules/permission'
|
|
||||||
|
|
||||||
import { NIcon } from 'naive-ui'
|
|
||||||
import { IconCircle, IconMenu } from '@/components/AppIcons'
|
|
||||||
|
|
||||||
import { isExternal } from '@/utils/is'
|
|
||||||
|
|
||||||
const router = useRouter()
|
|
||||||
const permissionStore = usePermissionStore()
|
|
||||||
const { currentRoute } = router
|
|
||||||
|
|
||||||
const menuOptions = computed(() => {
|
|
||||||
return generateOptions(permissionStore.routes, '')
|
|
||||||
})
|
|
||||||
|
|
||||||
function resolvePath(basePath, path) {
|
|
||||||
if (isExternal(path)) return path
|
|
||||||
return (
|
|
||||||
'/' +
|
|
||||||
[basePath, path]
|
|
||||||
.filter((path) => !!path && path !== '/')
|
|
||||||
.map((path) => path.replace(/(^\/)|(\/$)/g, ''))
|
|
||||||
.join('/')
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderIcon(icon, props = { size: 12 }) {
|
|
||||||
return () => h(NIcon, { ...props }, { default: () => h(icon) })
|
|
||||||
}
|
|
||||||
|
|
||||||
function isSingleRoute(route) {
|
|
||||||
let isSingle = true
|
|
||||||
let curRoute = route
|
|
||||||
while (curRoute.children && curRoute.children.length) {
|
|
||||||
if (curRoute.children.length > 1) {
|
|
||||||
isSingle = false
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if (curRoute.children.length === 1) {
|
|
||||||
curRoute = curRoute.children[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return isSingle
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateOptions(routes, basePath) {
|
|
||||||
let options = []
|
|
||||||
routes.forEach((route) => {
|
|
||||||
if (route.name && !route.isHidden) {
|
|
||||||
let curOption = {
|
|
||||||
label: (route.meta && route.meta.title) || route.name,
|
|
||||||
key: route.name,
|
|
||||||
path: resolvePath(basePath, route.path),
|
|
||||||
}
|
|
||||||
if (route.children && route.children.length) {
|
|
||||||
curOption.icon = renderIcon(route.meta?.icon || IconMenu, { size: 16 })
|
|
||||||
curOption.children = generateOptions(route.children, resolvePath(basePath, route.path))
|
|
||||||
} else {
|
|
||||||
curOption.icon = (route.meta?.icon && renderIcon(route.meta?.icon)) || renderIcon(IconCircle, { size: 8 })
|
|
||||||
}
|
|
||||||
options.push(curOption)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return options
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleMenuSelect(key, item) {
|
|
||||||
if (isExternal(item.path)) {
|
|
||||||
window.open(item.path)
|
|
||||||
} else {
|
|
||||||
router.push(item.path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 通过path重定向
|
|
||||||
// router.push({
|
|
||||||
// path: '/redirect',
|
|
||||||
// query: { redirect: item.path },
|
|
||||||
// })
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
.n-menu {
|
|
||||||
margin-top: 10px;
|
|
||||||
padding-left: 10px;
|
|
||||||
.n-menu-item-content {
|
|
||||||
&::before {
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
border-radius: 0;
|
|
||||||
background-color: unset !important;
|
|
||||||
}
|
|
||||||
&:hover,
|
|
||||||
&.n-menu-item-content--selected {
|
|
||||||
border-radius: 0 !important;
|
|
||||||
|
|
||||||
&::before {
|
|
||||||
border-right: 3px solid $primaryColor;
|
|
||||||
background-color: #16243a;
|
|
||||||
background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba($primaryColor, 0.3) 100%);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.n-menu-item-content-header {
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.n-submenu-children {
|
|
||||||
.n-menu-item-content-header {
|
|
||||||
font-size: 14px;
|
|
||||||
font-weight: normal;
|
|
||||||
position: relative;
|
|
||||||
overflow: visible !important;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
15
src/layout/components/sidebar/components/SideLogo.vue
Normal file
15
src/layout/components/sidebar/components/SideLogo.vue
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<template>
|
||||||
|
<router-link h-60 f-c-c to="/">
|
||||||
|
<icon-custom-logo text-36></icon-custom-logo>
|
||||||
|
<h2 v-show="!appStore.collapsed" ml-10 color-primary text-16 font-bold max-w-140 flex-shrink-0>
|
||||||
|
{{ title }}
|
||||||
|
</h2>
|
||||||
|
</router-link>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { useAppStore } from '@/store/modules/app'
|
||||||
|
const title = import.meta.env.VITE_APP_TITLE
|
||||||
|
|
||||||
|
const appStore = useAppStore()
|
||||||
|
</script>
|
||||||
109
src/layout/components/sidebar/components/SideMenu.vue
Normal file
109
src/layout/components/sidebar/components/SideMenu.vue
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
<template>
|
||||||
|
<n-menu
|
||||||
|
class="side-menu"
|
||||||
|
accordion
|
||||||
|
:indent="18"
|
||||||
|
:collapsed-icon-size="22"
|
||||||
|
:collapsed-width="64"
|
||||||
|
:options="menuOptions"
|
||||||
|
:value="(currentRoute.meta && currentRoute.meta.activeMenu) || currentRoute.name"
|
||||||
|
@update:value="handleMenuSelect" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { usePermissionStore } from '@/store/modules/permission'
|
||||||
|
|
||||||
|
import { isExternal } from '@/utils/is'
|
||||||
|
import { useAppStore } from '@/store/modules/app'
|
||||||
|
import { renderIcon } from '@/utils/icon'
|
||||||
|
|
||||||
|
const router = useRouter()
|
||||||
|
const permissionStore = usePermissionStore()
|
||||||
|
const appStore = useAppStore()
|
||||||
|
const { currentRoute } = router
|
||||||
|
|
||||||
|
const menuOptions = computed(() => {
|
||||||
|
return permissionStore.menus.map((item) => getMenuItem(item)).sort((a, b) => a.index - b.index)
|
||||||
|
})
|
||||||
|
|
||||||
|
function resolvePath(basePath, path) {
|
||||||
|
if (isExternal(path)) return path
|
||||||
|
return (
|
||||||
|
'/' +
|
||||||
|
[basePath, path]
|
||||||
|
.filter((path) => !!path && path !== '/')
|
||||||
|
.map((path) => path.replace(/(^\/)|(\/$)/g, ''))
|
||||||
|
.join('/')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMenuItem(route, basePath = '') {
|
||||||
|
let menuItem = {
|
||||||
|
label: (route.meta && route.meta.title) || route.name,
|
||||||
|
key: route.name,
|
||||||
|
path: resolvePath(basePath, route.path),
|
||||||
|
icon: route.meta?.icon ? renderIcon(route.meta?.icon, { size: 16 }) : renderIcon('mdi:circle-outline', { size: 8 }),
|
||||||
|
index: route.meta?.index || 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
const visibleChildren = route.children ? route.children.filter((item) => item.name && !item.isHidden) : []
|
||||||
|
|
||||||
|
if (!visibleChildren.length) return menuItem
|
||||||
|
|
||||||
|
if (visibleChildren.length === 1) {
|
||||||
|
// 单个子路由处理
|
||||||
|
const singleRoute = visibleChildren[0]
|
||||||
|
menuItem = {
|
||||||
|
label: singleRoute.meta?.title || singleRoute.name,
|
||||||
|
key: singleRoute.name,
|
||||||
|
path: resolvePath(menuItem.path, singleRoute.path),
|
||||||
|
icon: singleRoute.meta?.icon
|
||||||
|
? renderIcon(singleRoute.meta?.icon, { size: 16 })
|
||||||
|
: renderIcon('mdi:circle-outline', { size: 8 }),
|
||||||
|
index: menuItem.index,
|
||||||
|
}
|
||||||
|
const visibleItems = singleRoute.children ? singleRoute.children.filter((item) => item.name && !item.isHidden) : []
|
||||||
|
|
||||||
|
if (visibleItems.length === 1) {
|
||||||
|
menuItem = getMenuItem(visibleItems[0], menuItem.path)
|
||||||
|
} else if (visibleItems.length > 1) {
|
||||||
|
menuItem.children = visibleItems.map((item) => getMenuItem(item, menuItem.path)).sort((a, b) => a.index - b.index)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
menuItem.children = visibleChildren
|
||||||
|
.map((item) => getMenuItem(item, menuItem.path))
|
||||||
|
.sort((a, b) => a.index - b.index)
|
||||||
|
}
|
||||||
|
|
||||||
|
return menuItem
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleMenuSelect(key, item) {
|
||||||
|
if (isExternal(item.path)) {
|
||||||
|
window.open(item.path)
|
||||||
|
} else {
|
||||||
|
if (item.path === currentRoute.value.path && !currentRoute.value.meta?.keepAlive) {
|
||||||
|
appStore.reloadPage()
|
||||||
|
} else {
|
||||||
|
router.push(item.path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.side-menu:not(.n-menu--collapsed) {
|
||||||
|
.n-menu-item-content {
|
||||||
|
&::before {
|
||||||
|
left: 5px;
|
||||||
|
right: 5px;
|
||||||
|
}
|
||||||
|
&.n-menu-item-content--selected,
|
||||||
|
&:hover {
|
||||||
|
&::before {
|
||||||
|
border-left: 4px solid var(--primaryColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import SideLogo from './SideLogo.vue'
|
import SideLogo from './components/SideLogo.vue'
|
||||||
import SideMenu from './SideMenu.vue'
|
import SideMenu from './components/SideMenu.vue'
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
125
src/layout/components/tags/ContextMenu.vue
Normal file
125
src/layout/components/tags/ContextMenu.vue
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
<template>
|
||||||
|
<n-dropdown
|
||||||
|
:show="dropdownShow"
|
||||||
|
:options="options"
|
||||||
|
:x="x"
|
||||||
|
:y="y"
|
||||||
|
placement="bottom-start"
|
||||||
|
@clickoutside="handleHideDropdown"
|
||||||
|
@select="handleSelect" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import { useTagsStore } from '@/store/modules/tags'
|
||||||
|
import { renderIcon } from '@/utils/icon'
|
||||||
|
import { useAppStore } from '@/store/modules/app'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
show: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
currentPath: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
x: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
y: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const emit = defineEmits(['update:show'])
|
||||||
|
|
||||||
|
const tagsStore = useTagsStore()
|
||||||
|
const appStore = useAppStore()
|
||||||
|
|
||||||
|
const options = computed(() => [
|
||||||
|
{
|
||||||
|
label: '重新加载',
|
||||||
|
key: 'reload',
|
||||||
|
disabled: props.currentPath !== tagsStore.activeTag,
|
||||||
|
icon: renderIcon('mdi:refresh', { size: '14px' }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '关闭',
|
||||||
|
key: 'close',
|
||||||
|
disabled: tagsStore.tags.length <= 1,
|
||||||
|
icon: renderIcon('mdi:close', { size: '14px' }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '关闭其他',
|
||||||
|
key: 'close-other',
|
||||||
|
disabled: tagsStore.tags.length <= 1,
|
||||||
|
icon: renderIcon('mdi:arrow-expand-horizontal', { size: '14px' }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '关闭左侧',
|
||||||
|
key: 'close-left',
|
||||||
|
disabled: tagsStore.tags.length <= 1 || props.currentPath === tagsStore.tags[0].path,
|
||||||
|
icon: renderIcon('mdi:arrow-expand-left', { size: '14px' }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '关闭右侧',
|
||||||
|
key: 'close-right',
|
||||||
|
disabled: tagsStore.tags.length <= 1 || props.currentPath === tagsStore.tags[tagsStore.tags.length - 1].path,
|
||||||
|
icon: renderIcon('mdi:arrow-expand-right', { size: '14px' }),
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
const dropdownShow = computed({
|
||||||
|
get() {
|
||||||
|
return props.show
|
||||||
|
},
|
||||||
|
set(show) {
|
||||||
|
emit('update:show', show)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const actionMap = new Map([
|
||||||
|
[
|
||||||
|
'reload',
|
||||||
|
() => {
|
||||||
|
appStore.reloadPage()
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'close',
|
||||||
|
() => {
|
||||||
|
tagsStore.removeTag(props.currentPath)
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'close-other',
|
||||||
|
() => {
|
||||||
|
tagsStore.removeOther(props.currentPath)
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'close-left',
|
||||||
|
() => {
|
||||||
|
tagsStore.removeLeft(props.currentPath)
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'close-right',
|
||||||
|
() => {
|
||||||
|
tagsStore.removeRight(props.currentPath)
|
||||||
|
},
|
||||||
|
],
|
||||||
|
])
|
||||||
|
|
||||||
|
function handleHideDropdown() {
|
||||||
|
dropdownShow.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleSelect(key) {
|
||||||
|
const actionFn = actionMap.get(key)
|
||||||
|
actionFn && actionFn()
|
||||||
|
handleHideDropdown()
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,87 +1,96 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="tags-wrapper" :style="{ height: useTheme.tags.height + 'px' }">
|
<ScrollX :class="`h-${useTheme.tags.height}`">
|
||||||
<n-space>
|
<n-tag
|
||||||
<n-tag
|
v-for="tag in tagsStore.tags"
|
||||||
v-for="tag in useTags.tags"
|
:key="tag.path"
|
||||||
:key="tag.path"
|
:type="tagsStore.activeTag === tag.path ? 'primary' : 'default'"
|
||||||
:type="useTags.activeTag === tag.path ? 'primary' : 'default'"
|
:closable="tagsStore.tags.length > 1"
|
||||||
:closable="useTags.tags.length > 1"
|
@click="handleTagClick(tag.path)"
|
||||||
@click="handleTagClick(tag.path)"
|
@close.stop="tagsStore.removeTag(tag.path)"
|
||||||
@close.stop="handleClose(tag.path)"
|
@contextmenu.prevent="handleContextMenu($event, tag)">
|
||||||
>
|
{{ tag.title }}
|
||||||
{{ tag.title }}
|
</n-tag>
|
||||||
</n-tag>
|
</ScrollX>
|
||||||
</n-space>
|
|
||||||
</div>
|
<ContextMenu
|
||||||
|
v-model:show="contextMenuOption.show"
|
||||||
|
:current-path="contextMenuOption.currentPath"
|
||||||
|
:x="contextMenuOption.x"
|
||||||
|
:y="contextMenuOption.y" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="Tags">
|
<script setup name="Tags">
|
||||||
import { watch } from 'vue'
|
import ContextMenu from './ContextMenu.vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
|
||||||
import { useTagsStore } from '@/store/modules/tags'
|
import { useTagsStore } from '@/store/modules/tags'
|
||||||
import { useThemeStore } from '@/store/modules/theme'
|
import { useThemeStore } from '@/store/modules/theme'
|
||||||
|
import ScrollX from '@/components/common/ScrollX.vue'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const useTags = useTagsStore()
|
const tagsStore = useTagsStore()
|
||||||
const useTheme = useThemeStore()
|
const useTheme = useThemeStore()
|
||||||
|
|
||||||
|
const contextMenuOption = reactive({
|
||||||
|
show: false,
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
currentPath: '',
|
||||||
|
})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => route.path,
|
() => route.path,
|
||||||
() => {
|
() => {
|
||||||
const { name, path } = route
|
const { name, path } = route
|
||||||
const title = route.meta?.title
|
const title = route.meta?.title
|
||||||
useTags.addTag({ name, path, title })
|
tagsStore.addTag({ name, path, title })
|
||||||
useTags.setActiveTag(path)
|
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleTagClick = (path) => {
|
const handleTagClick = (path) => {
|
||||||
useTags.setActiveTag(path)
|
tagsStore.setActiveTag(path)
|
||||||
router.push(path)
|
router.push(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleClose = (path) => {
|
function showContextMenu() {
|
||||||
if (path === useTags.activeTag) {
|
contextMenuOption.show = true
|
||||||
const activeIndex = useTags.tags.findIndex((item) => item.path === path)
|
}
|
||||||
if (activeIndex > 0) {
|
function hideContextMenu() {
|
||||||
router.push(useTags.tags[activeIndex - 1].path)
|
contextMenuOption.show = false
|
||||||
} else {
|
}
|
||||||
router.push(useTags.tags[activeIndex + 1].path)
|
function setContextMenu(x, y, currentPath) {
|
||||||
}
|
Object.assign(contextMenuOption, { x, y, currentPath })
|
||||||
}
|
}
|
||||||
useTags.removeTag(path)
|
|
||||||
|
// 右击菜单
|
||||||
|
async function handleContextMenu(e, tagItem) {
|
||||||
|
const { clientX, clientY } = e
|
||||||
|
hideContextMenu()
|
||||||
|
setContextMenu(clientX, clientY, tagItem.path)
|
||||||
|
await nextTick()
|
||||||
|
showContextMenu()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.tags-wrapper {
|
.n-tag {
|
||||||
display: flex;
|
padding: 0 15px;
|
||||||
align-items: center;
|
margin: 0 5px;
|
||||||
background-color: #fff;
|
cursor: pointer;
|
||||||
padding: 0 10px;
|
.n-tag__close {
|
||||||
position: sticky;
|
margin-left: 5px;
|
||||||
top: 0;
|
box-sizing: content-box;
|
||||||
z-index: 9;
|
font-size: 12px;
|
||||||
.n-tag {
|
padding: 2px;
|
||||||
padding: 0 15px;
|
border-radius: 50%;
|
||||||
cursor: pointer;
|
transition: all 0.7s;
|
||||||
.n-tag__close {
|
|
||||||
margin-left: 5px;
|
|
||||||
box-sizing: content-box;
|
|
||||||
font-size: 12px;
|
|
||||||
padding: 2px;
|
|
||||||
border-radius: 50%;
|
|
||||||
transition: all 0.7s;
|
|
||||||
&:hover {
|
|
||||||
color: #fff;
|
|
||||||
background-color: $primaryColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&:hover {
|
&:hover {
|
||||||
color: $primaryColor;
|
color: #fff;
|
||||||
|
background-color: var(--primaryColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
&:hover {
|
||||||
|
color: var(--primaryColor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,26 +1,30 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="layout">
|
<n-layout has-sider style="height: 100%">
|
||||||
<n-layout has-sider position="absolute">
|
<n-layout-sider
|
||||||
<n-layout-sider bordered :width="200" :collapsed-width="0" :native-scrollbar="false">
|
bordered
|
||||||
<SideBar />
|
collapse-mode="width"
|
||||||
</n-layout-sider>
|
:collapsed-width="64"
|
||||||
<n-layout>
|
:width="220"
|
||||||
<n-layout-header :style="{ height: useTheme.header.height + 'px' }" style="border-left: none">
|
:native-scrollbar="false"
|
||||||
<AppHeader />
|
:collapsed="appStore.collapsed">
|
||||||
</n-layout-header>
|
<SideBar />
|
||||||
|
</n-layout-sider>
|
||||||
|
<n-layout>
|
||||||
|
<n-layout-header :style="{ height: useTheme.header.height + 'px' }">
|
||||||
|
<AppHeader />
|
||||||
|
</n-layout-header>
|
||||||
|
|
||||||
<n-layout
|
<n-layout style="background-color: #f5f6fb" :style="`height: calc(100% - ${useTheme.header.height}px)`">
|
||||||
position="absolute"
|
<AppTags v-if="useTheme.tags.visible" />
|
||||||
style="background-color: #f5f6fb"
|
<AppMain
|
||||||
:style="{ top: useTheme.header.height + 'px' }"
|
class="cur-scroll border-t bc-eee"
|
||||||
:native-scrollbar="false"
|
:style="{
|
||||||
>
|
height: `calc(100% - ${useTheme.tags.visible ? useTheme.tags.height : 0}px)`,
|
||||||
<AppTags v-if="useTheme.tags.visible" />
|
overflow: 'auto',
|
||||||
<AppMain />
|
}" />
|
||||||
</n-layout>
|
|
||||||
</n-layout>
|
</n-layout>
|
||||||
</n-layout>
|
</n-layout>
|
||||||
</div>
|
</n-layout>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@@ -29,8 +33,10 @@ import SideBar from './components/sidebar/index.vue'
|
|||||||
import AppMain from './components/AppMain.vue'
|
import AppMain from './components/AppMain.vue'
|
||||||
import AppTags from './components/tags/index.vue'
|
import AppTags from './components/tags/index.vue'
|
||||||
import { useThemeStore } from '@/store/modules/theme'
|
import { useThemeStore } from '@/store/modules/theme'
|
||||||
|
import { useAppStore } from '@/store/modules/app'
|
||||||
|
|
||||||
const useTheme = useThemeStore()
|
const useTheme = useThemeStore()
|
||||||
|
const appStore = useAppStore()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
@@ -38,6 +44,5 @@ const useTheme = useThemeStore()
|
|||||||
height: 60px;
|
height: 60px;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
border-bottom: 1px solid #eee;
|
border-bottom: 1px solid #eee;
|
||||||
border-left: 1px solid #eee;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import '@/styles/reset.css'
|
||||||
|
import '@/styles/variables.css'
|
||||||
import '@/styles/index.scss'
|
import '@/styles/index.scss'
|
||||||
import 'uno.css'
|
import 'uno.css'
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useUserStore } from '@/store/modules/user'
|
|||||||
import { usePermissionStore } from '@/store/modules/permission'
|
import { usePermissionStore } from '@/store/modules/permission'
|
||||||
import { NOT_FOUND_ROUTE } from '@/router/routes'
|
import { NOT_FOUND_ROUTE } from '@/router/routes'
|
||||||
import { getToken, refreshAccessToken, removeToken } from '@/utils/token'
|
import { getToken, refreshAccessToken, removeToken } from '@/utils/token'
|
||||||
|
import { toLogin } from '@/utils/auth'
|
||||||
|
|
||||||
const WHITE_LIST = ['/login', '/redirect']
|
const WHITE_LIST = ['/login', '/redirect']
|
||||||
export function createPermissionGuard(router) {
|
export function createPermissionGuard(router) {
|
||||||
@@ -18,19 +19,18 @@ export function createPermissionGuard(router) {
|
|||||||
refreshAccessToken()
|
refreshAccessToken()
|
||||||
next()
|
next()
|
||||||
} else {
|
} else {
|
||||||
try {
|
await userStore.getUserInfo().catch((error) => {
|
||||||
await userStore.getUserInfo()
|
|
||||||
const accessRoutes = permissionStore.generateRoutes(userStore.role)
|
|
||||||
accessRoutes.forEach((route) => {
|
|
||||||
!router.hasRoute(route.name) && router.addRoute(route)
|
|
||||||
})
|
|
||||||
router.addRoute(NOT_FOUND_ROUTE)
|
|
||||||
next({ ...to, replace: true })
|
|
||||||
} catch (error) {
|
|
||||||
removeToken()
|
removeToken()
|
||||||
$message.error(error)
|
toLogin()
|
||||||
next({ path: '/login', query: { ...to.query, redirect: to.path } })
|
$message.error(error.message || '获取用户信息失败!')
|
||||||
}
|
return
|
||||||
|
})
|
||||||
|
const accessRoutes = permissionStore.generateRoutes(userStore.role)
|
||||||
|
accessRoutes.forEach((route) => {
|
||||||
|
!router.hasRoute(route.name) && router.addRoute(route)
|
||||||
|
})
|
||||||
|
router.addRoute(NOT_FOUND_ROUTE)
|
||||||
|
next({ ...to, replace: true })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { basicRoutes } from './routes'
|
|||||||
const isHash = !!import.meta.env.VITE_APP_USE_HASH
|
const isHash = !!import.meta.env.VITE_APP_USE_HASH
|
||||||
export const router = createRouter({
|
export const router = createRouter({
|
||||||
history: isHash ? createWebHashHistory('/') : createWebHistory('/'),
|
history: isHash ? createWebHashHistory('/') : createWebHistory('/'),
|
||||||
routes: basicRoutes,
|
routes: [],
|
||||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -20,6 +20,9 @@ export function resetRouter() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function setupRouter(app) {
|
export function setupRouter(app) {
|
||||||
|
basicRoutes.forEach((route) => {
|
||||||
|
!router.hasRoute(route.name) && router.addRoute(route)
|
||||||
|
})
|
||||||
app.use(router)
|
app.use(router)
|
||||||
setupRouterGuard(router)
|
setupRouterGuard(router)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import Layout from '@/layout/index.vue'
|
import Layout from '@/layout/index.vue'
|
||||||
import Home from '@/views/dashboard/index.vue'
|
import Home from '@/views/dashboard/index.vue'
|
||||||
|
|
||||||
import { IconAlert, IconChart, IconGitee, IconGithub, IconHome, IconLink, IconVue } from '@/components/AppIcons'
|
|
||||||
|
|
||||||
export const basicRoutes = [
|
export const basicRoutes = [
|
||||||
{
|
{
|
||||||
name: '404',
|
name: '404',
|
||||||
@@ -34,64 +32,88 @@ export const basicRoutes = [
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: 'DASHBOARD',
|
name: 'Dashboard',
|
||||||
path: '/',
|
path: '/',
|
||||||
component: Layout,
|
component: Layout,
|
||||||
redirect: '/home',
|
redirect: '/home',
|
||||||
meta: {
|
meta: {
|
||||||
title: 'Dashboard',
|
title: 'Dashboard',
|
||||||
icon: IconChart,
|
icon: 'mdi:chart-bar',
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: 'HOME',
|
name: 'Home',
|
||||||
path: 'home',
|
path: 'home',
|
||||||
component: Home,
|
component: Home,
|
||||||
meta: {
|
meta: {
|
||||||
title: '首页',
|
title: '首页',
|
||||||
icon: IconHome,
|
icon: 'mdi:home',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: 'TEST',
|
name: 'ErrorPage',
|
||||||
|
path: '/error-page',
|
||||||
|
component: Layout,
|
||||||
|
redirect: '/error-page/404',
|
||||||
|
meta: {
|
||||||
|
title: '错误页',
|
||||||
|
icon: 'mdi:alert-circle-outline',
|
||||||
|
index: 4,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
name: 'ERROR-404',
|
||||||
|
path: '404',
|
||||||
|
component: () => import('@/views/error-page/404.vue'),
|
||||||
|
meta: {
|
||||||
|
title: '404',
|
||||||
|
icon: 'mdi:alert-circle-outline',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'Test',
|
||||||
path: '/test',
|
path: '/test',
|
||||||
component: Layout,
|
component: Layout,
|
||||||
redirect: '/test/unocss',
|
redirect: '/test/unocss',
|
||||||
meta: {
|
meta: {
|
||||||
title: '基础功能测试',
|
title: '基础功能测试',
|
||||||
|
icon: 'mdi:menu',
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: 'UNOCSS',
|
name: 'Unocss',
|
||||||
path: 'unocss',
|
path: 'unocss',
|
||||||
component: () => import('@/views/test-page/TestUnocss.vue'),
|
component: () => import('@/views/test-page/unocss/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: '测试unocss',
|
title: '测试unocss',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'MESSAGE',
|
name: 'Message',
|
||||||
path: 'message',
|
path: 'message',
|
||||||
component: () => import('@/views/test-page/TestMessage.vue'),
|
component: () => import('@/views/test-page/message/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: '测试Message',
|
title: '测试Message',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'DIALOG',
|
name: 'Dialog',
|
||||||
path: 'dialog',
|
path: 'dialog',
|
||||||
component: () => import('@/views/test-page/TestDialog.vue'),
|
component: () => import('@/views/test-page/dialog/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: '测试Dialog',
|
title: '测试Dialog',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'TEST-KEEP-ALIVE',
|
name: 'TestKeepAlive',
|
||||||
path: 'keep-alive',
|
path: 'keep-alive',
|
||||||
component: () => import('@/views/test-page/TestKeepAlive.vue'),
|
component: () => import('@/views/test-page/keep-alive/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: '测试Keep-Alive',
|
title: '测试Keep-Alive',
|
||||||
keepAlive: true,
|
keepAlive: true,
|
||||||
@@ -101,57 +123,36 @@ export const basicRoutes = [
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
name: 'ERROR-PAGE',
|
name: 'ExternalLink',
|
||||||
path: '/error-page',
|
|
||||||
component: Layout,
|
|
||||||
redirect: '/error-page/404',
|
|
||||||
meta: {
|
|
||||||
title: '错误页',
|
|
||||||
icon: IconAlert,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'ERROR-404',
|
|
||||||
path: '404',
|
|
||||||
component: () => import('@/views/error-page/404.vue'),
|
|
||||||
meta: {
|
|
||||||
title: '404',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
name: 'EXTERNAL-LINK',
|
|
||||||
path: '/external-link',
|
path: '/external-link',
|
||||||
component: Layout,
|
component: Layout,
|
||||||
meta: {
|
meta: {
|
||||||
title: '外部链接',
|
title: '外部链接',
|
||||||
icon: IconLink,
|
icon: 'mdi:link-variant',
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: 'LINK-GITHUB-SRC',
|
name: 'LinkGithubSrc',
|
||||||
path: 'https://github.com/zclzone/vue-naive-admin',
|
path: 'https://github.com/zclzone/vue-naive-admin',
|
||||||
meta: {
|
meta: {
|
||||||
title: '源码 - github',
|
title: '源码 - github',
|
||||||
icon: IconGithub,
|
icon: 'mdi:github',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'LINK-GITEE-SRC',
|
name: 'LinkGiteeSrc',
|
||||||
path: 'https://gitee.com/zclzone/vue-naive-admin',
|
path: 'https://gitee.com/zclzone/vue-naive-admin',
|
||||||
meta: {
|
meta: {
|
||||||
title: '源码 - gitee',
|
title: '源码 - gitee',
|
||||||
icon: IconGitee,
|
icon: 'simple-icons:gitee',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'LINK-DOCS',
|
name: 'LinkDocs',
|
||||||
path: 'https://zclzone.github.io/vue-naive-admin-docs',
|
path: 'https://zclzone.github.io/vue-naive-admin-docs',
|
||||||
meta: {
|
meta: {
|
||||||
title: '文档 - vuepress',
|
title: '文档 - vuepress',
|
||||||
icon: IconVue,
|
icon: 'mdi:vuejs',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -159,7 +160,7 @@ export const basicRoutes = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
export const NOT_FOUND_ROUTE = {
|
export const NOT_FOUND_ROUTE = {
|
||||||
name: 'NOT_FOUND',
|
name: 'NotFound',
|
||||||
path: '/:pathMatch(.*)*',
|
path: '/:pathMatch(.*)*',
|
||||||
redirect: '/404',
|
redirect: '/404',
|
||||||
isHidden: true,
|
isHidden: true,
|
||||||
|
|||||||
@@ -2,27 +2,29 @@ import Layout from '@/layout/index.vue'
|
|||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
name: 'EXAMPLE',
|
name: 'Example',
|
||||||
path: '/example',
|
path: '/example',
|
||||||
component: Layout,
|
component: Layout,
|
||||||
redirect: '/example/table',
|
redirect: '/example/table',
|
||||||
meta: {
|
meta: {
|
||||||
title: '组件示例',
|
title: '组件示例',
|
||||||
role: ['admin'],
|
role: ['admin'],
|
||||||
|
icon: 'mdi:menu',
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: 'EXAMPLE-TABLE',
|
name: 'Table',
|
||||||
path: 'table',
|
path: 'table',
|
||||||
component: () => import('@/views/examples/table/index.vue'),
|
component: () => import('@/views/examples/table/index.vue'),
|
||||||
redirect: '/example/table/post',
|
redirect: '/example/table/post',
|
||||||
meta: {
|
meta: {
|
||||||
title: '表格',
|
title: '表格',
|
||||||
role: ['admin'],
|
role: ['admin'],
|
||||||
|
icon: 'mdi:table',
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
name: 'POST-LIST',
|
name: 'PostList',
|
||||||
path: 'post',
|
path: 'post',
|
||||||
component: () => import('@/views/examples/table/post/index.vue'),
|
component: () => import('@/views/examples/table/post/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
@@ -31,9 +33,9 @@ export default [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'POST-CREATE',
|
name: 'PostCreate',
|
||||||
path: 'post-create',
|
path: 'post-create',
|
||||||
component: () => import('@/views/examples/table/post/post-create.vue'),
|
component: () => import('@/views/examples/table/post/PostCreate.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: '创建文章',
|
title: '创建文章',
|
||||||
role: ['admin'],
|
role: ['admin'],
|
||||||
|
|||||||
@@ -11,11 +11,7 @@
|
|||||||
"primaryColor": "#316C72FF",
|
"primaryColor": "#316C72FF",
|
||||||
"primaryColorHover": "#316C72E3",
|
"primaryColorHover": "#316C72E3",
|
||||||
"primaryColorPressed": "#2B4C59FF",
|
"primaryColorPressed": "#2B4C59FF",
|
||||||
"primaryColorSuppl": "#316C7263",
|
"primaryColorSuppl": "#316C7263"
|
||||||
"successColor": "#316C72FF",
|
|
||||||
"successColorHover": "#316C72E3",
|
|
||||||
"successColorPressed": "#2B4C59FF",
|
|
||||||
"successColorSuppl": "#316C7263"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
src/store/modules/app.js
Normal file
29
src/store/modules/app.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
|
||||||
|
export const useAppStore = defineStore('app', {
|
||||||
|
state() {
|
||||||
|
return {
|
||||||
|
reloadFlag: true,
|
||||||
|
collapsed: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
async reloadPage() {
|
||||||
|
$loadingBar.start()
|
||||||
|
this.reloadFlag = false
|
||||||
|
await nextTick()
|
||||||
|
this.reloadFlag = true
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
document.documentElement.scrollTo({ left: 0, top: 0 })
|
||||||
|
$loadingBar.finish()
|
||||||
|
}, 100)
|
||||||
|
},
|
||||||
|
switchCollapsed() {
|
||||||
|
this.collapsed = !this.collapsed
|
||||||
|
},
|
||||||
|
setCollapsed(collapsed) {
|
||||||
|
this.collapsed = collapsed
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
@@ -38,6 +38,9 @@ export const usePermissionStore = defineStore('permission', {
|
|||||||
routes() {
|
routes() {
|
||||||
return basicRoutes.concat(this.accessRoutes)
|
return basicRoutes.concat(this.accessRoutes)
|
||||||
},
|
},
|
||||||
|
menus() {
|
||||||
|
return this.routes.filter((route) => route.name && !route.isHidden)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
generateRoutes(role = []) {
|
generateRoutes(role = []) {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { createSessionStorage } from '@/utils/cache'
|
import { sStorage } from '@/utils/cache'
|
||||||
|
|
||||||
export const tagsSS = createSessionStorage({ prefixKey: 'tag_' })
|
export const activeTag = sStorage.get('activeTag')
|
||||||
export const activeTag = tagsSS.get('activeTag')
|
export const tags = sStorage.get('tags')
|
||||||
export const tags = tagsSS.get('tags')
|
|
||||||
|
|
||||||
export const WITHOUT_TAG_PATHS = ['/404', '/login', '/redirect']
|
export const WITHOUT_TAG_PATHS = ['/404', '/login', '/redirect']
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { tagsSS, activeTag, tags, WITHOUT_TAG_PATHS } from './helpers'
|
import { activeTag, tags, WITHOUT_TAG_PATHS } from './helpers'
|
||||||
|
import { router } from '@/router'
|
||||||
|
import { sStorage } from '@/utils/cache'
|
||||||
|
|
||||||
export const useTagsStore = defineStore('tag', {
|
export const useTagsStore = defineStore('tag', {
|
||||||
state() {
|
state() {
|
||||||
@@ -11,16 +13,49 @@ export const useTagsStore = defineStore('tag', {
|
|||||||
actions: {
|
actions: {
|
||||||
setActiveTag(path) {
|
setActiveTag(path) {
|
||||||
this.activeTag = path
|
this.activeTag = path
|
||||||
tagsSS.set('activeTag', path)
|
sStorage.set('activeTag', path)
|
||||||
|
},
|
||||||
|
setTags(tags) {
|
||||||
|
this.tags = tags
|
||||||
|
sStorage.set('tags', tags)
|
||||||
},
|
},
|
||||||
addTag(tag = {}) {
|
addTag(tag = {}) {
|
||||||
|
this.setActiveTag(tag.path)
|
||||||
if (WITHOUT_TAG_PATHS.includes(tag.path) || this.tags.some((item) => item.path === tag.path)) return
|
if (WITHOUT_TAG_PATHS.includes(tag.path) || this.tags.some((item) => item.path === tag.path)) return
|
||||||
this.tags.push(tag)
|
this.setTags([...this.tags, tag])
|
||||||
tagsSS.set('tags', this.tags)
|
|
||||||
},
|
},
|
||||||
removeTag(path) {
|
removeTag(path) {
|
||||||
this.tags = this.tags.filter((tag) => tag.path !== path)
|
if (path === this.activeTag) {
|
||||||
tagsSS.set('tags', this.tags)
|
const activeIndex = this.tags.findIndex((item) => item.path === path)
|
||||||
|
if (activeIndex > 0) {
|
||||||
|
router.push(this.tags[activeIndex - 1].path)
|
||||||
|
} else {
|
||||||
|
router.push(this.tags[activeIndex + 1].path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.setTags(this.tags.filter((tag) => tag.path !== path))
|
||||||
|
},
|
||||||
|
removeOther(curPath = this.activeTag) {
|
||||||
|
this.setTags(this.tags.filter((tag) => tag.path === curPath))
|
||||||
|
if (curPath !== this.activeTag) {
|
||||||
|
router.push(this.tags[this.tags.length - 1].path)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeLeft(curPath) {
|
||||||
|
const curIndex = this.tags.findIndex((item) => item.path === curPath)
|
||||||
|
const filterTags = this.tags.filter((item, index) => index >= curIndex)
|
||||||
|
this.setTags(filterTags)
|
||||||
|
if (!filterTags.find((item) => item.path === this.activeTag)) {
|
||||||
|
router.push(filterTags[filterTags.length - 1].path)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeRight(curPath) {
|
||||||
|
const curIndex = this.tags.findIndex((item) => item.path === curPath)
|
||||||
|
const filterTags = this.tags.filter((item, index) => index <= curIndex)
|
||||||
|
this.setTags(filterTags)
|
||||||
|
if (!filterTags.find((item) => item.path === this.activeTag)) {
|
||||||
|
router.push(filterTags[filterTags.length - 1].path)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,9 +2,19 @@ import { defineStore } from 'pinia'
|
|||||||
import { themeSettings } from '@/settings'
|
import { themeSettings } from '@/settings'
|
||||||
export const useThemeStore = defineStore('theme', {
|
export const useThemeStore = defineStore('theme', {
|
||||||
state() {
|
state() {
|
||||||
return themeSettings
|
return {
|
||||||
|
tags: themeSettings.tag || { visible: true, height: 50 },
|
||||||
|
header: themeSettings.header || { height: 60 },
|
||||||
|
naiveThemeOverrides: themeSettings.naiveThemeOverrides || {
|
||||||
|
common: {
|
||||||
|
primaryColor: '#316C72FF',
|
||||||
|
primaryColorHover: '#316C72E3',
|
||||||
|
primaryColorPressed: '#2B4C59FF',
|
||||||
|
primaryColorSuppl: '#316C7263',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
getters: {},
|
|
||||||
actions: {
|
actions: {
|
||||||
setTabVisible(visible) {
|
setTabVisible(visible) {
|
||||||
this.tags.visible = visible
|
this.tags.visible = visible
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { getUser } from '@/api/user'
|
import { getUser } from '@/api/user'
|
||||||
import { removeToken } from '@/utils/token'
|
import { removeToken } from '@/utils/token'
|
||||||
|
import { toLogin } from '@/utils/auth'
|
||||||
|
|
||||||
export const useUserStore = defineStore('user', {
|
export const useUserStore = defineStore('user', {
|
||||||
state() {
|
state() {
|
||||||
@@ -31,16 +32,16 @@ export const useUserStore = defineStore('user', {
|
|||||||
this.userInfo = { id, name, avatar, role }
|
this.userInfo = { id, name, avatar, role }
|
||||||
return Promise.resolve(res.data)
|
return Promise.resolve(res.data)
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(res.message)
|
return Promise.reject(res)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
return Promise.reject(error)
|
||||||
return Promise.reject(error.message)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
logout() {
|
async logout() {
|
||||||
removeToken()
|
removeToken()
|
||||||
this.userInfo = {}
|
this.userInfo = {}
|
||||||
|
toLogin()
|
||||||
},
|
},
|
||||||
setUserInfo(userInfo = {}) {
|
setUserInfo(userInfo = {}) {
|
||||||
this.userInfo = { ...this.userInfo, ...userInfo }
|
this.userInfo = { ...this.userInfo, ...userInfo }
|
||||||
|
|||||||
@@ -1,2 +1,54 @@
|
|||||||
@import './reset.scss';
|
html {
|
||||||
@import './public.scss';
|
font-size: 4px; // * 1rem = 4px 方便unocss计算:在unocss中 1字体单位 = 0.25rem,相当于 1等份 = 1px
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
font-family: 'Encode Sans Condensed', sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* router view transition fade-slide */
|
||||||
|
.fade-slide-leave-active,
|
||||||
|
.fade-slide-enter-active {
|
||||||
|
transition: all 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-slide-enter-from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(-30px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-slide-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(30px);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 自定义滚动条样式 */
|
||||||
|
.cur-scroll {
|
||||||
|
&::-webkit-scrollbar{
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
}
|
||||||
|
&::-webkit-scrollbar-thumb{
|
||||||
|
background-color: transparent;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::-webkit-scrollbar-corner{
|
||||||
|
background: #f6f6f6;
|
||||||
|
}
|
||||||
|
&:hover {
|
||||||
|
&::-webkit-scrollbar-thumb {
|
||||||
|
background: #bfbfbf;
|
||||||
|
}
|
||||||
|
&::-webkit-scrollbar-thumb:hover{
|
||||||
|
background: #999999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
html {
|
|
||||||
font-size: 4px; // * 1rem = 4px 方便unocss计算:在unocss中 1字体单位 = 0.25rem,相当于 1等份 = 1px
|
|
||||||
}
|
|
||||||
|
|
||||||
html,
|
|
||||||
body {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
overflow: hidden;
|
|
||||||
background-color: #f2f2f2;
|
|
||||||
font-family: 'Encode Sans Condensed', sans-serif;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* router view transition fade-slide */
|
|
||||||
.fade-slide-leave-active,
|
|
||||||
.fade-slide-enter-active {
|
|
||||||
transition: all 0.3s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.fade-slide-enter-from {
|
|
||||||
opacity: 0;
|
|
||||||
transform: translateX(-30px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.fade-slide-leave-to {
|
|
||||||
opacity: 0;
|
|
||||||
transform: translateX(30px);
|
|
||||||
}
|
|
||||||
3
src/styles/variables.css
Normal file
3
src/styles/variables.css
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
:root {
|
||||||
|
--primaryColor: #316c72;
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
$primaryColor: #316c72;
|
|
||||||
|
|
||||||
:root {
|
|
||||||
--vh100: 100vh;
|
|
||||||
}
|
|
||||||
8
src/utils/auth.js
Normal file
8
src/utils/auth.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { router } from '@/router'
|
||||||
|
|
||||||
|
export function toLogin() {
|
||||||
|
router.replace({
|
||||||
|
path: '/login',
|
||||||
|
query: { ...router.currentRoute.query, redirect: router.currentRoute.path },
|
||||||
|
})
|
||||||
|
}
|
||||||
18
src/utils/cache/index.js
vendored
18
src/utils/cache/index.js
vendored
@@ -1,9 +1,21 @@
|
|||||||
import { createWebStorage } from './web-storage'
|
import { createStorage } from './storage'
|
||||||
|
|
||||||
|
const prefixKey = 'Vue_Naive_Admin_'
|
||||||
|
|
||||||
export const createLocalStorage = function (option = {}) {
|
export const createLocalStorage = function (option = {}) {
|
||||||
return createWebStorage({ prefixKey: option.prefixKey || '', storage: localStorage })
|
return createStorage({
|
||||||
|
prefixKey: option.prefixKey || '',
|
||||||
|
storage: localStorage,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createSessionStorage = function (option = {}) {
|
export const createSessionStorage = function (option = {}) {
|
||||||
return createWebStorage({ prefixKey: option.prefixKey || '', storage: sessionStorage })
|
return createStorage({
|
||||||
|
prefixKey: option.prefixKey || '',
|
||||||
|
storage: sessionStorage,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const lStorage = createLocalStorage({ prefixKey })
|
||||||
|
|
||||||
|
export const sStorage = createSessionStorage({ prefixKey })
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { isNullOrUndef } from '@/utils/is'
|
import { isNullOrUndef } from '@/utils/is'
|
||||||
|
|
||||||
class WebStorage {
|
class Storage {
|
||||||
constructor(option) {
|
constructor(option) {
|
||||||
this.storage = option.storage
|
this.storage = option.storage
|
||||||
this.prefixKey = option.prefixKey
|
this.prefixKey = option.prefixKey
|
||||||
@@ -50,6 +50,6 @@ class WebStorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createWebStorage({ prefixKey = '', storage = sessionStorage }) {
|
export function createStorage({ prefixKey = '', storage = sessionStorage }) {
|
||||||
return new WebStorage({ prefixKey, storage })
|
return new Storage({ prefixKey, storage })
|
||||||
}
|
}
|
||||||
79
src/utils/common/naiveTools.js
Normal file
79
src/utils/common/naiveTools.js
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import { isNullOrUndef } from '@/utils/is'
|
||||||
|
|
||||||
|
export function setupMessage(NMessage) {
|
||||||
|
let loadingMessage = null
|
||||||
|
class Message {
|
||||||
|
/**
|
||||||
|
* 规则:
|
||||||
|
* * loading message只显示一个,新的message会替换正在显示的loading message
|
||||||
|
* * loading message不会自动清除,除非被替换成非loading message,非loading message默认2秒后自动清除
|
||||||
|
*/
|
||||||
|
|
||||||
|
removeMessage(message, duration = 2000) {
|
||||||
|
setTimeout(() => {
|
||||||
|
if (message) {
|
||||||
|
message.destroy()
|
||||||
|
message = null
|
||||||
|
}
|
||||||
|
}, duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
showMessage(type, content, option = {}) {
|
||||||
|
if (loadingMessage && loadingMessage.type === 'loading') {
|
||||||
|
// 如果存在则替换正在显示的loading message
|
||||||
|
loadingMessage.type = type
|
||||||
|
loadingMessage.content = content
|
||||||
|
|
||||||
|
if (type !== 'loading') {
|
||||||
|
// 非loading message需设置自动清除
|
||||||
|
this.removeMessage(loadingMessage, option.duration)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 不存在正在显示的loading则新建一个message,如果新建的message是loading message则将message赋值存储下来
|
||||||
|
let message = NMessage[type](content, option)
|
||||||
|
if (type === 'loading') {
|
||||||
|
loadingMessage = message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loading(content) {
|
||||||
|
this.showMessage('loading', content, { duration: 0 })
|
||||||
|
}
|
||||||
|
|
||||||
|
success(content, option = {}) {
|
||||||
|
this.showMessage('success', content, option)
|
||||||
|
}
|
||||||
|
|
||||||
|
error(content, option = {}) {
|
||||||
|
this.showMessage('error', content, option)
|
||||||
|
}
|
||||||
|
|
||||||
|
info(content, option = {}) {
|
||||||
|
this.showMessage('info', content, option)
|
||||||
|
}
|
||||||
|
|
||||||
|
warning(content, option = {}) {
|
||||||
|
this.showMessage('warning', content, option)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Message()
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setupDialog(NDialog) {
|
||||||
|
NDialog.confirm = function (option = {}) {
|
||||||
|
const showIcon = !isNullOrUndef(option.title)
|
||||||
|
return NDialog[option.type || 'warning']({
|
||||||
|
showIcon,
|
||||||
|
positiveText: '确定',
|
||||||
|
negativeText: '取消',
|
||||||
|
onPositiveClick: option.confirm,
|
||||||
|
onNegativeClick: option.cancel,
|
||||||
|
onMaskClick: option.cancel,
|
||||||
|
...option,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return NDialog
|
||||||
|
}
|
||||||
@@ -1,18 +1,22 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { setupInterceptor } from './interceptors'
|
import { repReject, repResolve, reqReject, reqResolve } from './interceptors'
|
||||||
|
|
||||||
function createAxios(option = {}) {
|
export function createAxios(options = {}) {
|
||||||
const defBaseURL = window.__APP__GLOB__CONF__?.VITE_APP_GLOB_BASE_API || import.meta.env.VITE_APP_GLOB_BASE_API
|
const defaultOptions = {
|
||||||
|
baseURL: import.meta.env.VITE_APP_BASE_API,
|
||||||
|
timeout: 12000,
|
||||||
|
}
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
timeout: option.timeout || 120000,
|
...defaultOptions,
|
||||||
baseURL: option.baseURL || defBaseURL,
|
...options,
|
||||||
})
|
})
|
||||||
setupInterceptor(service)
|
service.interceptors.request.use(reqResolve, reqReject)
|
||||||
|
service.interceptors.response.use(repResolve, repReject)
|
||||||
return service
|
return service
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defAxios = createAxios()
|
export const defAxios = createAxios()
|
||||||
|
|
||||||
export const testAxios = createAxios({
|
export const testAxios = createAxios({
|
||||||
baseURL: window.__APP__GLOB__CONF__?.VITE_APP_GLOB_BASE_API_TEST || import.meta.env.VITE_APP_GLOB_BASE_API_TEST,
|
baseURL: import.meta.env.VITE_APP_BASE_API_TEST,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,82 +1,74 @@
|
|||||||
import { router } from '@/router'
|
import { getToken } from '@/utils/token'
|
||||||
import { getToken, removeToken } from '@/utils/token'
|
import { toLogin } from '@/utils/auth'
|
||||||
|
import { isNullOrUndef } from '@/utils/is'
|
||||||
import { isWithoutToken } from './helpers'
|
import { isWithoutToken } from './helpers'
|
||||||
|
|
||||||
export function setupInterceptor(service) {
|
export function reqResolve(config) {
|
||||||
service.interceptors.request.use(
|
// 防止缓存,给get请求加上时间戳
|
||||||
async (config) => {
|
if (config.method === 'get') {
|
||||||
// 防止缓存,给get请求加上时间戳
|
config.params = { ...config.params, t: new Date().getTime() }
|
||||||
if (config.method === 'get') {
|
}
|
||||||
config.params = { ...config.params, t: new Date().getTime() }
|
|
||||||
}
|
|
||||||
|
|
||||||
// 处理不需要token的请求
|
// 处理不需要token的请求
|
||||||
if (isWithoutToken(config)) {
|
if (isWithoutToken(config)) {
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = getToken()
|
const token = getToken()
|
||||||
if (token) {
|
if (!token) {
|
||||||
/**
|
/**
|
||||||
* * jwt token
|
* * 未登录或者token过期的情况下
|
||||||
* ! 认证方案: Bearer
|
* * 跳转登录页重新登录,携带当前路由及参数,登录成功会回到原来的页面
|
||||||
*/
|
*/
|
||||||
config.headers.Authorization = 'Bearer ' + token
|
toLogin()
|
||||||
|
return Promise.reject({ code: '-1', message: '未登录' })
|
||||||
|
}
|
||||||
|
|
||||||
return config
|
/**
|
||||||
}
|
* * jwt token
|
||||||
/**
|
* ! 认证方案: Bearer
|
||||||
* * 未登录或者token过期的情况下
|
*/
|
||||||
* * 跳转登录页重新登录,携带当前路由及参数,登录成功会回到原来的页面
|
config.headers.Authorization = config.headers.Authorization || 'Bearer ' + token
|
||||||
*/
|
|
||||||
const { currentRoute } = router
|
|
||||||
router.replace({
|
|
||||||
path: '/login',
|
|
||||||
query: { ...currentRoute.query, redirect: currentRoute.path },
|
|
||||||
})
|
|
||||||
return Promise.reject({ code: '-1', message: '未登录' })
|
|
||||||
},
|
|
||||||
(error) => Promise.reject(error)
|
|
||||||
)
|
|
||||||
|
|
||||||
service.interceptors.response.use(
|
return config
|
||||||
(response) => response?.data,
|
}
|
||||||
(error) => {
|
|
||||||
let { code, message } = error.response?.data
|
export function reqReject(error) {
|
||||||
return Promise.reject({ code, message })
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
/**
|
|
||||||
* TODO 此处可以根据后端返回的错误码自定义框架层面的错误处理
|
export function repResolve(response) {
|
||||||
*/
|
return response?.data
|
||||||
switch (code) {
|
}
|
||||||
case 401:
|
|
||||||
// 未登录(可能是token过期或者无效了)
|
export function repReject(error) {
|
||||||
console.error(message)
|
let { code, message } = error.response?.data || {}
|
||||||
removeToken()
|
if (isNullOrUndef(code)) {
|
||||||
const { currentRoute } = router
|
// 未知错误
|
||||||
router.replace({
|
code = -1
|
||||||
path: '/login',
|
message = '接口异常!'
|
||||||
query: { ...currentRoute.query, redirect: currentRoute.path },
|
} else {
|
||||||
})
|
/**
|
||||||
break
|
* TODO 此处可以根据后端返回的错误码自定义框架层面的错误处理
|
||||||
case 403:
|
*/
|
||||||
// 没有权限
|
switch (code) {
|
||||||
console.error(message)
|
case 400:
|
||||||
break
|
message = message || '请求参数错误'
|
||||||
case 404:
|
break
|
||||||
// 资源不存在
|
case 401:
|
||||||
console.error(message)
|
message = message || '登录已过期'
|
||||||
break
|
break
|
||||||
default:
|
case 403:
|
||||||
break
|
message = message || '没有权限'
|
||||||
}
|
break
|
||||||
// 已知错误resolve,在业务代码中作提醒,未知错误reject,捕获错误统一提示接口异常(9000以上为业务类型错误,需要跟后端确定好)
|
case 404:
|
||||||
if ([401, 403, 404].includes(code) || code >= 9000) {
|
message = message || '资源或接口不存在'
|
||||||
return Promise.resolve({ code, message })
|
break
|
||||||
} else {
|
default:
|
||||||
console.error('【err】' + error)
|
message = message || '未知异常'
|
||||||
return Promise.reject({ message: '接口异常,请稍后重试!' })
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
console.error(`【${code}】 ${error}`)
|
||||||
|
return Promise.resolve({ code, message, error })
|
||||||
}
|
}
|
||||||
|
|||||||
7
src/utils/icon.js
Normal file
7
src/utils/icon.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { h } from 'vue'
|
||||||
|
import { Icon } from '@iconify/vue'
|
||||||
|
import { NIcon } from 'naive-ui'
|
||||||
|
|
||||||
|
export function renderIcon(icon, props = { size: 12 }) {
|
||||||
|
return () => h(NIcon, props, { default: () => h(Icon, { icon }) })
|
||||||
|
}
|
||||||
@@ -16,6 +16,10 @@ export function isNull(val) {
|
|||||||
return val === null
|
return val === null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isWhitespace(val) {
|
||||||
|
return val === ''
|
||||||
|
}
|
||||||
|
|
||||||
export function isObject(val) {
|
export function isObject(val) {
|
||||||
return !isNull(val) && is(val, 'Object')
|
return !isNull(val) && is(val, 'Object')
|
||||||
}
|
}
|
||||||
@@ -64,6 +68,10 @@ export function isNullOrUndef(val) {
|
|||||||
return isNull(val) || isUndef(val)
|
return isNull(val) || isUndef(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isNullOrWhitespace(val) {
|
||||||
|
return isNullOrUndef(val) || isWhitespace(val)
|
||||||
|
}
|
||||||
|
|
||||||
export function isEmpty(val) {
|
export function isEmpty(val) {
|
||||||
if (isArray(val) || isString(val)) {
|
if (isArray(val) || isString(val)) {
|
||||||
return val.length === 0
|
return val.length === 0
|
||||||
@@ -81,14 +89,14 @@ export function isEmpty(val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* * 类似sql的isnull函数
|
* * 类似mysql的IFNULL函数
|
||||||
* * 第一个参数为null/undefined/''则返回第二个参数作为默认值,否则返回第一个参数
|
* * 第一个参数为null/undefined/'' 则返回第二个参数作为备用值,否则返回第一个参数
|
||||||
* @param {Number|Boolean|String} val
|
* @param {Number|Boolean|String} val
|
||||||
* @param {Number|Boolean|String} replaceVal
|
* @param {Number|Boolean|String} def
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function isNullReplace(val, replaceVal = '') {
|
export function ifNull(val, def = '') {
|
||||||
return isNullOrUndef(val) || val === '' ? replaceVal : val
|
return isNullOrWhitespace(val) ? def : val
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isUrl(path) {
|
export function isUrl(path) {
|
||||||
|
|||||||
@@ -1,37 +1,33 @@
|
|||||||
import { createLocalStorage } from './cache'
|
import { lStorage } from './cache'
|
||||||
import { refreshToken } from '@/api/auth'
|
import { refreshToken } from '@/api/auth'
|
||||||
|
|
||||||
const TOKEN_CODE = 'access_token'
|
const TOKEN_CODE = 'access_token'
|
||||||
const DURATION = 6 * 60 * 60
|
const DURATION = 6 * 60 * 60
|
||||||
|
|
||||||
export const lsToken = createLocalStorage()
|
|
||||||
|
|
||||||
export function getToken() {
|
export function getToken() {
|
||||||
return lsToken.get(TOKEN_CODE)
|
return lStorage.get(TOKEN_CODE)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setToken(token) {
|
export function setToken(token) {
|
||||||
lsToken.set(TOKEN_CODE, token, DURATION)
|
lStorage.set(TOKEN_CODE, token, DURATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeToken() {
|
export function removeToken() {
|
||||||
lsToken.remove(TOKEN_CODE)
|
lStorage.remove(TOKEN_CODE)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function refreshAccessToken() {
|
export async function refreshAccessToken() {
|
||||||
const tokenItem = lsToken.getItem(TOKEN_CODE)
|
const tokenItem = lStorage.getItem(TOKEN_CODE)
|
||||||
if (!tokenItem) {
|
if (!tokenItem) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const { time } = tokenItem
|
const { time } = tokenItem
|
||||||
if (new Date().getTime() - time > 1000 * 60 * 30) {
|
// token生成或者刷新后30分钟内不执行刷新
|
||||||
try {
|
if (new Date().getTime() - time <= 1000 * 60 * 30) return
|
||||||
const res = await refreshToken()
|
try {
|
||||||
if (res.code === 0) {
|
const res = await refreshToken()
|
||||||
setToken(res.data.token)
|
if (res.code === 0) {
|
||||||
}
|
setToken(res.data.token)
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
}
|
}
|
||||||
}
|
} catch (error) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +1,50 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div p-15>
|
||||||
<n-card>
|
<n-card rounded-10>
|
||||||
<div flex items-center>
|
<div flex items-center>
|
||||||
<img width="60" style="border-radius: 50%" :src="userStore.avatar" />
|
<img rounded-full width="60" :src="userStore.avatar" />
|
||||||
<div ml20>
|
<div ml-20>
|
||||||
<p text-16>Hello, {{ userStore.name }}</p>
|
<p text-16>Hello, {{ userStore.name }}</p>
|
||||||
<p op80 text-12 mt5>今天又是元气满满的一天</p>
|
<p mt-5 text-12 op-60>今天又是元气满满的一天</p>
|
||||||
</div>
|
</div>
|
||||||
<div flex ml-auto>
|
<div ml-auto flex items-center>
|
||||||
<n-statistic label="待办" :value="4">
|
<n-statistic label="待办" :value="4">
|
||||||
<template #suffix> / 10 </template>
|
<template #suffix> / 10 </template>
|
||||||
</n-statistic>
|
</n-statistic>
|
||||||
<n-statistic ml80 label="Stars">
|
<n-statistic label="Stars" w-100 ml-80>
|
||||||
<n-number-animation ref="starsNumberRef" show-separator :from="0" :to="999" />
|
<a href="https://github.com/zclzone/vue-naive-admin">
|
||||||
|
<img allt="stars" src="https://badgen.net/github/stars/zclzone/vue-naive-admin" />
|
||||||
|
</a>
|
||||||
</n-statistic>
|
</n-statistic>
|
||||||
<n-statistic ml80 label="Forks">
|
<n-statistic label="Forks" w-100 ml-80>
|
||||||
<n-number-animation ref="starsNumberRef" show-separator :from="0" :to="299" />
|
<a href="https://github.com/zclzone/vue-naive-admin">
|
||||||
|
<img allt="forks" src="https://badgen.net/github/forks/zclzone/vue-naive-admin" />
|
||||||
|
</a>
|
||||||
</n-statistic>
|
</n-statistic>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</n-card>
|
</n-card>
|
||||||
|
|
||||||
<div p15 flex>
|
<n-card title="项目" size="small" :segmented="true" mt-15 rounded-10>
|
||||||
<n-card title="项目" size="small" :segmented="true">
|
<template #header-extra>
|
||||||
<template #header-extra>
|
<n-button text type="primary">更多</n-button>
|
||||||
<n-button text type="primary">更多</n-button>
|
</template>
|
||||||
</template>
|
<div flex flex-wrap justify-between>
|
||||||
<div class="card-list">
|
<n-card
|
||||||
<n-card v-for="i in 10" :key="i" title="Vue Naive Admin" size="small">
|
v-for="i in 10"
|
||||||
<p op60>一个基于 Vue3.0、Vite、Naive UI 的轻量级后台管理模板</p>
|
:key="i"
|
||||||
</n-card>
|
class="w-300 flex-shrink-0 mt-10 mb-10 cursor-pointer"
|
||||||
<div class="blank"></div>
|
hover:card-shadow
|
||||||
<div class="blank"></div>
|
title="Vue Naive Admin"
|
||||||
<div class="blank"></div>
|
size="small">
|
||||||
<div class="blank"></div>
|
<p op-60>一个基于 Vue3.0、Vite、Naive UI 的轻量级后台管理模板</p>
|
||||||
</div>
|
</n-card>
|
||||||
</n-card>
|
<div w-300 h-0></div>
|
||||||
</div>
|
<div w-300 h-0></div>
|
||||||
|
<div w-300 h-0></div>
|
||||||
|
<div w-300 h-0></div>
|
||||||
|
</div>
|
||||||
|
</n-card>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -45,24 +53,3 @@ import { useUserStore } from '@/store/modules/user'
|
|||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.card-list {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
justify-content: space-between;
|
|
||||||
.n-card {
|
|
||||||
width: 300px;
|
|
||||||
flex-shrink: 0;
|
|
||||||
margin: 10px 0;
|
|
||||||
cursor: pointer;
|
|
||||||
&:hover {
|
|
||||||
box-shadow: 0 1px 2px -2px #00000029, 0 3px 6px #0000001f, 0 5px 12px 4px #00000017;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.blank {
|
|
||||||
width: 300px;
|
|
||||||
height: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -1,31 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page-404">
|
<div h-full flex>
|
||||||
<n-result status="404" description="抱歉,您访问的页面不存在。">
|
<n-result m-auto status="404" description="抱歉,您访问的页面不存在。">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<img src="@/assets/images/404.png" width="300" />
|
<img src="@/assets/images/404.png" width="500" />
|
||||||
</template>
|
</template>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<n-button strong secondary type="primary" @click="replace('/')">返回首页</n-button>
|
<n-button @click="replace('/')">返回首页</n-button>
|
||||||
</template>
|
</template>
|
||||||
</n-result>
|
</n-result>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
const { replace } = useRouter()
|
const { replace } = useRouter()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.page-404 {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
|
|
||||||
position: absolute;
|
|
||||||
top: 50px;
|
|
||||||
bottom: 50px;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
<template>
|
<template>
|
||||||
<div pb-20>
|
<div p-24>
|
||||||
<div class="header">
|
<div h-60 pl-20 pr-20 flex items-center bg-white>
|
||||||
<input v-model="post.title" type="text" placeholder="输入文章标题..." class="title" />
|
<input
|
||||||
|
v-model="post.title"
|
||||||
|
class="flex-1 pt-15 pb-15 mr-20 text-20 font-bold color-primary"
|
||||||
|
type="text"
|
||||||
|
placeholder="输入文章标题..." />
|
||||||
<n-button type="primary" style="width: 80px" :loading="btnLoading" @click="handleSavePost">保存</n-button>
|
<n-button type="primary" style="width: 80px" :loading="btnLoading" @click="handleSavePost">保存</n-button>
|
||||||
</div>
|
</div>
|
||||||
<MdEditor v-model="post.content" style="height: calc(100vh - 200px)" />
|
<MdEditor v-model="post.content" style="height: calc(100vh - 220px)" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from 'vue'
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
|
|
||||||
import MdEditor from 'md-editor-v3'
|
import MdEditor from 'md-editor-v3'
|
||||||
import 'md-editor-v3/lib/style.css'
|
import 'md-editor-v3/lib/style.css'
|
||||||
|
|
||||||
@@ -40,21 +41,3 @@ function handleSavePost(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.header {
|
|
||||||
background-color: #fff;
|
|
||||||
height: 60px;
|
|
||||||
padding: 0 20px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
.title {
|
|
||||||
flex: 1;
|
|
||||||
padding: 15px 0;
|
|
||||||
margin-right: 20px;
|
|
||||||
font-size: 20px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: $primaryColor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user