mirror of
https://github.com/jekip/naive-ui-admin.git
synced 2026-02-04 21:52:27 +08:00
Compare commits
231 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee8aed2f62 | ||
|
|
260397f3ae | ||
|
|
fa983a9b64 | ||
|
|
4c49e28596 | ||
|
|
9a5fe5249c | ||
|
|
02235bf6fc | ||
|
|
0656035857 | ||
|
|
81e8222461 | ||
|
|
09411a927e | ||
|
|
347cd91735 | ||
|
|
9b2effbc55 | ||
|
|
d72f42dcd8 | ||
|
|
165c358ef5 | ||
|
|
fc181ce543 | ||
|
|
f04b9ba7f9 | ||
|
|
ee0e507e47 | ||
|
|
9d18715e90 | ||
|
|
74f0e4764e | ||
|
|
4cbdd9bc66 | ||
|
|
e03b1bdfca | ||
|
|
b6a350e1be | ||
|
|
503437a433 | ||
|
|
d4518849bf | ||
|
|
39178761b1 | ||
|
|
934de6b1e6 | ||
|
|
58d13a242d | ||
|
|
5d891c1f44 | ||
|
|
e1528823f7 | ||
|
|
1fa35db71b | ||
|
|
80729d925e | ||
|
|
e228184b72 | ||
|
|
2f541106f2 | ||
|
|
5f81f4cc77 | ||
|
|
b4f32f50c5 | ||
|
|
5d180b6fd5 | ||
|
|
3d6465346c | ||
|
|
dc98b96ce2 | ||
|
|
3f84af912f | ||
|
|
8dcd66b654 | ||
|
|
4bdc54a77f | ||
|
|
0ceb7437a4 | ||
|
|
b984828f33 | ||
|
|
1d10826760 | ||
|
|
74334de7e0 | ||
|
|
e153837497 | ||
|
|
d0ec44b48c | ||
|
|
e9efbb5e67 | ||
|
|
aa90e0a468 | ||
|
|
9049f743a8 | ||
|
|
1f858929d6 | ||
|
|
5a50bc0dc4 | ||
|
|
a35318f808 | ||
|
|
7a18f58f4a | ||
|
|
3fb8c85112 | ||
|
|
921dd91eda | ||
|
|
bcd2480f69 | ||
|
|
590d1615cb | ||
|
|
23dcfe000b | ||
|
|
47e47c8a59 | ||
|
|
719ad34a94 | ||
|
|
a0deba504a | ||
|
|
25d6134923 | ||
|
|
a646de72e2 | ||
|
|
e63963cf08 | ||
|
|
c43ec3ef1c | ||
|
|
4f0a7967f7 | ||
|
|
1c594b49c0 | ||
|
|
b68103455b | ||
|
|
724af94c08 | ||
|
|
af68d4bc67 | ||
|
|
2fb36695db | ||
|
|
32116be1f2 | ||
|
|
4a47fa2f7d | ||
|
|
89f68789ff | ||
|
|
4c0de9d5c2 | ||
|
|
1e72351dea | ||
|
|
da24659944 | ||
|
|
eb21a99df1 | ||
|
|
c598d3f7bc | ||
|
|
fa0163a385 | ||
|
|
57fef38bfe | ||
|
|
d62ca84328 | ||
|
|
c504e61d70 | ||
|
|
c0d3e11346 | ||
|
|
4c27623a0f | ||
|
|
0107c5f035 | ||
|
|
6134a4c125 | ||
|
|
00dd7409b1 | ||
|
|
a7ad4a3634 | ||
|
|
327f8de00b | ||
|
|
026e4c1acd | ||
|
|
9ba51e4a34 | ||
|
|
bc2d2b4e94 | ||
|
|
e2f90cbf88 | ||
|
|
2da9b8a465 | ||
|
|
f99ecea202 | ||
|
|
e3326a0f11 | ||
|
|
775f5b63af | ||
|
|
874fd3437d | ||
|
|
7644c59799 | ||
|
|
f8ed3d1607 | ||
|
|
0c8bb030de | ||
|
|
41a6f59617 | ||
|
|
1a7eaf7efb | ||
|
|
5714233d57 | ||
|
|
5e2452f2df | ||
|
|
e9d3e1affe | ||
|
|
f6d419b94f | ||
|
|
cc0d1824f2 | ||
|
|
299f8c89a5 | ||
|
|
9e40480b9b | ||
|
|
c20ee24cd8 | ||
|
|
eb27f19087 | ||
|
|
3cbb6061c5 | ||
|
|
e07e36ce5d | ||
|
|
0f8b0d3557 | ||
|
|
28d2696061 | ||
|
|
b2c22996ce | ||
|
|
f616852053 | ||
|
|
92316285bb | ||
|
|
1077a20cbd | ||
|
|
7b9b391adc | ||
|
|
88ada7ebee | ||
|
|
a7257568cf | ||
|
|
403a844668 | ||
|
|
197e63cb51 | ||
|
|
6c3273e214 | ||
|
|
71be58fc1f | ||
|
|
e3e14b8259 | ||
|
|
5f625aa305 | ||
|
|
8167d4165b | ||
|
|
873e0d3e43 | ||
|
|
f20f4209a3 | ||
|
|
363ed7ae9e | ||
|
|
a21cc8aec8 | ||
|
|
0f229aea13 | ||
|
|
89151afce3 | ||
|
|
ffac6c0d78 | ||
|
|
c257ca0948 | ||
|
|
9bcd6d9700 | ||
|
|
a66f56b9ce | ||
|
|
9e58578706 | ||
|
|
9e3ebd62b2 | ||
|
|
5b852506a6 | ||
|
|
f42857884f | ||
|
|
9ad5ba18a9 | ||
|
|
536e16f166 | ||
|
|
42f2256ea1 | ||
|
|
bf0d294322 | ||
|
|
51f5c64755 | ||
|
|
b49d9e8bd2 | ||
|
|
12e62d1179 | ||
|
|
6558e1597c | ||
|
|
7bf1e1265a | ||
|
|
1213de598e | ||
|
|
20c9dbbfe1 | ||
|
|
6dab2ab35b | ||
|
|
a424788c45 | ||
|
|
b31d5c2bd6 | ||
|
|
b979d9db32 | ||
|
|
a53c86e41b | ||
|
|
b16b5c8992 | ||
|
|
58dadbb95a | ||
|
|
4ebdbc7203 | ||
|
|
0729e56ed4 | ||
|
|
a50cbfa44d | ||
|
|
65d6d4d21e | ||
|
|
c5bb818f13 | ||
|
|
9e255da5d7 | ||
|
|
e2b5086be3 | ||
|
|
caaca83f78 | ||
|
|
91de971636 | ||
|
|
5fb005d5ae | ||
|
|
b42e0a2fef | ||
|
|
097dda5aa1 | ||
|
|
16714d4bdb | ||
|
|
a5438b4f50 | ||
|
|
4f5bbb0673 | ||
|
|
24cbde8b95 | ||
|
|
7222398cf0 | ||
|
|
261e27c139 | ||
|
|
8288f0a84b | ||
|
|
c0ff8985ea | ||
|
|
a8400ac475 | ||
|
|
d4b173e3c8 | ||
|
|
1ab8b5b221 | ||
|
|
fc5e138ed8 | ||
|
|
b9b2c6a07e | ||
|
|
3503569dfe | ||
|
|
125b7f44e3 | ||
|
|
3307b927a4 | ||
|
|
97de86eacb | ||
|
|
cb92f6e87b | ||
|
|
4f81743f90 | ||
|
|
7837c87392 | ||
|
|
17a5d08d94 | ||
|
|
19e5e5fc4a | ||
|
|
822e69deec | ||
|
|
3bf1e941d4 | ||
|
|
ef4912636e | ||
|
|
7929a74d20 | ||
|
|
45862d4f9d | ||
|
|
8e6471060c | ||
|
|
30c0cd5c95 | ||
|
|
259e73c056 | ||
|
|
8eaa889399 | ||
|
|
d1635add5f | ||
|
|
531a31ee5d | ||
|
|
3b64fc1563 | ||
|
|
229fc72cda | ||
|
|
900954d757 | ||
|
|
fca4dddaf6 | ||
|
|
4add3c3eaa | ||
|
|
21e80f8041 | ||
|
|
a63c34dbb5 | ||
|
|
e02e96d4e0 | ||
|
|
70c2b75f17 | ||
|
|
b186e045bc | ||
|
|
742749a838 | ||
|
|
82dc7d2589 | ||
|
|
f11af4fc76 | ||
|
|
85f1dbd5e9 | ||
|
|
ae001fc7bd | ||
|
|
be770016bf | ||
|
|
1bf722bed0 | ||
|
|
8c7dd14004 | ||
|
|
e6505c88b7 | ||
|
|
a0490e3b97 | ||
|
|
905984367c | ||
|
|
d3f7fa0f9e | ||
|
|
55ee389184 |
@@ -15,7 +15,7 @@ VITE_DROP_CONSOLE = true
|
||||
|
||||
# 跨域代理,可以配置多个,请注意不要换行
|
||||
#VITE_PROXY = [["/appApi","http://localhost:8001"],["/upload","http://localhost:8001/upload"]]
|
||||
# VITE_PROXY=[["/api","https://naive-ui-admin"]]
|
||||
#VITE_PROXY=[["/api","https://naive-ui-admin"]]
|
||||
|
||||
# API 接口地址
|
||||
VITE_GLOB_API_URL =
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
*.sh
|
||||
node_modules
|
||||
*.md
|
||||
@@ -13,3 +12,5 @@ dist
|
||||
.local
|
||||
/bin
|
||||
Dockerfile
|
||||
components.d.ts
|
||||
components.d.ts
|
||||
|
||||
19
.eslintrc.js
19
.eslintrc.js
@@ -22,9 +22,10 @@ module.exports = defineConfig({
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'prettier',
|
||||
'plugin:prettier/recommended',
|
||||
'plugin:jest/recommended',
|
||||
],
|
||||
rules: {
|
||||
'vue/script-setup-uses-vars': 'error',
|
||||
'vue/multi-word-component-names': 'off',
|
||||
'@typescript-eslint/ban-ts-ignore': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
@@ -37,19 +38,12 @@ module.exports = defineConfig({
|
||||
'@typescript-eslint/ban-types': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
argsIgnorePattern: '^_',
|
||||
varsIgnorePattern: '^_',
|
||||
},
|
||||
],
|
||||
'@typescript-eslint/no-unused-vars': ['error', { varsIgnorePattern: '.*', args: 'none' }],
|
||||
'no-unused-vars': [
|
||||
'error',
|
||||
{
|
||||
argsIgnorePattern: '^_',
|
||||
varsIgnorePattern: '^_',
|
||||
},
|
||||
// we are only using this rule to check for unused arguments since TS
|
||||
// catches unused variables but not args.
|
||||
{ varsIgnorePattern: '.*', args: 'none' },
|
||||
],
|
||||
'space-before-function-paren': 'off',
|
||||
|
||||
@@ -61,7 +55,6 @@ module.exports = defineConfig({
|
||||
'vue/singleline-html-element-content-newline': 'off',
|
||||
'vue/attribute-hyphenation': 'off',
|
||||
'vue/require-default-prop': 'off',
|
||||
'vue/script-setup-uses-vars': 'off',
|
||||
'vue/html-self-closing': [
|
||||
'error',
|
||||
{
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -23,3 +23,5 @@ pnpm-debug.log*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
/components.d.ts
|
||||
/components.d.ts
|
||||
|
||||
104
CHANGELOG.md
104
CHANGELOG.md
@@ -1,5 +1,105 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 1.9.1
|
||||
|
||||
- 优化 `typeSctipt` 类型定义
|
||||
- 优化 `setup` 语法
|
||||
- 依赖升级
|
||||
|
||||
## 1.9.0
|
||||
|
||||
- 新增 `BasicForm` 组件,支持 `setLoading`, `setSchema` 方法
|
||||
- 新增 `countField` 总数字段名配置
|
||||
- 优化 `yarn` 切换至 `pnpm`
|
||||
- 优化 `BasicForm` 组件,验证返回值
|
||||
- 优化 `BasicTable` 组件
|
||||
- 修复 `TableAction组件,左右间隔不生效` 关闭[253](https://github.com/jekip/naive-ui-admin/issues/253)
|
||||
- 修复 `BasicTable组件没有数据会一直请求接口` 关闭[#251](https://github.com/jekip/naive-ui-admin/issues/251)
|
||||
- 修复 `useModal+useForm组件的bug` 关闭[#250](https://github.com/jekip/naive-ui-admin/issues/250)
|
||||
- 修复 `手机端侧边导航风格不一致bug` 关闭[#247](https://github.com/jekip/naive-ui-admin/issues/247
|
||||
- 移除 `yarn.lock` 文件
|
||||
- 依赖升级
|
||||
## 1.8.2
|
||||
|
||||
- ### ✨ Features
|
||||
- 新增 `directive` 示例
|
||||
- 依赖升级
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
- 修复 `样式异常` 图片
|
||||
|
||||
## 1.8.1
|
||||
|
||||
- ### ✨ Features
|
||||
- 新增 `clean:cache` 删除缓存命令
|
||||
- 新增 `clean:lib` 删除 `node_modules` 命令
|
||||
- 依赖升级
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
- 修复 `开发环境` 运行控制台错误提示
|
||||
|
||||
## 1.8.0 (2022-04-01)
|
||||
|
||||
- ### ✨ Features
|
||||
- 新增 `多页签` 支持配置 `affix` 固定属性
|
||||
- 新增 `usePage` Hooks
|
||||
- 表格列支持 `draggable` 配置拖拽 合并 [#114](https://github.com/jekip/naive-ui-admin/pull/114)
|
||||
- 依赖升级
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
- 修复 `多页签` 关闭全部缺陷
|
||||
- 修复 `多页签` 跳转缺陷(记得清空多页签缓存)
|
||||
## 1.7.0 (2022-02-14)
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
- 移除 `登录页面` 滑动验证组件
|
||||
- 修复 `BasicUpload` 组件,回显问题
|
||||
- 修复 `ts类型` 配置缺陷
|
||||
- 修复 `登录页面` message 交互缺陷
|
||||
- 修复 `表格编辑` 时间格式化异常 [#92](https://github.com/jekip/naive-ui-admin/issues/92)
|
||||
|
||||
- ### ✨ Features
|
||||
- 依赖升级
|
||||
|
||||
## 1.6.1 (2022-01-06)
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
- 修复 `项目配置` 打开空白
|
||||
- 修复 `多标签` 背景和字体色变量丢失
|
||||
|
||||
- ### ✨ Features
|
||||
- 依赖升级
|
||||
|
||||
## 1.6.0 (2021-12-24)
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
- 修复 `低版本浏览器` 报 globalThis 未定义
|
||||
- 修复 `Axios` api地址拼接异常
|
||||
- 修复 `createStorage存在prefixKey` 会出bug
|
||||
|
||||
- ### ✨ Features
|
||||
- 破坏 `Axios` 取消默认导出 `http` 可支持多个请求导出
|
||||
- 搜索 `import http from '@/utils/http/axios'` 替换为 `import { http } from '@/utils/http/axios`
|
||||
- 新增 `Axios` 多项配置 `urlPrefix`,`joinTime`,`ignoreCancelToken`,`withToken`,`uploadFile方法`
|
||||
- 依赖升级
|
||||
|
||||
## 1.5.5 (2021-08-14)
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
- 修复路由只存在一个子路由,图标不显示问题
|
||||
- UI样式美化
|
||||
|
||||
- ### ✨ Features
|
||||
- 支持 Vue 3.2.x
|
||||
- 代码全部按 `script setup` 语法重写(完成80%)
|
||||
- 新增 `回到顶部` 功能
|
||||
- 新增 `拖拽` 示例页面
|
||||
- 新增 `富文本` 组件
|
||||
- 新增 `路由切换动画` 可在项目设置切换
|
||||
- 依赖升级
|
||||
|
||||
# CHANGELOG
|
||||
|
||||
## 1.5.4 (2021-08-10)
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
@@ -8,10 +108,12 @@
|
||||
- `表格设置列,重复添加action列样式错乱问题` 合并 [#24](https://github.com/jekip/naive-ui-admin/pull/24) 感谢 [@CasbaL](https://github.com/CasbaL)
|
||||
|
||||
- ### ✨ Features
|
||||
- 新增 `路由支持(内联外部地址)`配置
|
||||
- 新增 `顶部菜单` logo展示
|
||||
-(破坏性更新)
|
||||
- 优化 `动态路由配置` 取消`constantRouterComponents.ts`,中组件映射配置,更名为 `router-icons.ts`
|
||||
- 优化 `admin_info接口结构`,roles 更名为:permissions,roles.roleName,更名为:label
|
||||
- 优化 多级路由,当没有配置时,`redirect` ,`redirect` 默认为第一个子路由,配置则优先按配置
|
||||
- 优化 多级路由,当没有配置`redirect`时,默认为第一个子路由,配置则优先按配置
|
||||
- 依赖升级
|
||||
|
||||
# 1.5.3 (2021-08-09)
|
||||
|
||||
69
README.md
69
README.md
@@ -1,24 +1,58 @@
|
||||
## 简介
|
||||
|
||||
[Naive Ui Admin](https://github.com/jekip/naive-ui-admin) 是一个基于 [Vue3.0](https://github.com/vuejs/vue-next)、[Vite](https://github.com/vitejs/vite)、 [Naive UI](https://www.naiveui.com/)、[TypeScript](https://www.typescriptlang.org/) 的中后台解决方案,它使用了最新的前端技术栈,并提炼了典型的业务模型,页面,包括二次封装组件、动态菜单、权限校验、粒子化权限控制等功能,它可以帮助你快速搭建企业级中后台项目,相信不管是从新技术使用还是其他方面,都能帮助到你。
|
||||
[Naive Ui Admin](https://github.com/jekip/naive-ui-admin) 完全免费,且可商用,基于 [Vue3.0](https://github.com/vuejs/vue-next)、[Vite](https://github.com/vitejs/vite)、 [Naive UI](https://www.naiveui.com/)、[TypeScript](https://www.typescriptlang.org/) 的中后台解决方案,它使用了最新的前端技术栈,并提炼了典型的业务模型,页面,包括二次封装组件、动态菜单、权限校验、粒子化权限控制等功能,它可以帮助你快速搭建企业级中后台项目, 相信不管是从新技术使用还是其他方面,都能帮助到你。
|
||||
|
||||
## 特性
|
||||
- **最新技术栈**:使用 Vue3/vite2 等前端前沿技术开发
|
||||
- **TypeScript**: 应用程序级 JavaScript 的语言
|
||||
- **主题**:可配置的主题
|
||||
- **Mock 数据** 内置 Mock 数据方案
|
||||
- **权限** 内置完善的动态路由权限生成方案
|
||||
- **组件** 二次封装了多个常用的组件
|
||||
- 二次封装实用高扩展性组件
|
||||
- 响应式、多主题,多配置,快速集成,开箱即用
|
||||
- 最新技术栈,使用 `Vue3`、`Typescript`、`Pinia`、`Vite` 等前端前沿技术
|
||||
- 强大的鉴权系统,对路由、菜单、功能点等支持`三种鉴权模式`,满足不同的业务鉴权需求
|
||||
- 持续更新,实用性页面模板功能和交互,随意搭配组合,让构建页面变得简单化
|
||||
|
||||
|
||||
## 在线预览
|
||||
- [naive-ui-admin](https://naive-ui-admin.vercel.app)
|
||||
## 预览
|
||||
- [naive-ui-admin](https://jekip.github.io)
|
||||
|
||||
账号:admin,密码:123456(随意)
|
||||
|
||||
## 提示
|
||||
|
||||
如果开源版本的功能和组件,并不能满足您的需求,不妨看看,我们全新 `NaiveAdmin` 他或许能让您眼前一亮O(∩_∩)O哈哈~
|
||||
|
||||
[NaiveAdmin 官网](https://www.naiveadmin.com)
|
||||
|
||||
[NaiveAdmin 变更日志](https://www.yuque.com/u5825/zaqu0e)
|
||||
|
||||
[为什么选我们?](https://www.naiveadmin.com/choose/we)
|
||||
### Plus
|
||||
|
||||
基于 `NaiveUi` 全新设计版本,新增众多特性,强烈推荐
|
||||
|
||||
[NaiveAdmin Plus 预览](https://plus.naiveadmin.com)
|
||||
|
||||
### Arco vue
|
||||
|
||||
智能设计体系,连接轻盈体验
|
||||
|
||||
[NaiveAdmin Arco 预览](https://arco.naiveadmin.com)
|
||||
|
||||
### Element Plus
|
||||
|
||||
面向设计师和开发者的组件库
|
||||
|
||||
[Element Plus Admin 预览](https://element.naiveadmin.com)
|
||||
|
||||
以上版本同时具备 `NaiveAdmin` 功能/组件/页面,一如既往、开箱即用,欢迎前往查看。
|
||||
|
||||
### Antd vue
|
||||
|
||||
新产品,如果您选的技术栈是 `Antd` 的话,不妨看看
|
||||
|
||||
[NaiveAdmin Antd 预览](https://antd.naiveadmin.com)
|
||||
|
||||
## 文档
|
||||
|
||||
[文档地址](https://naive-ui-admin-docs.vercel.app)
|
||||
[文档地址](https://jekip.github.io/docs)
|
||||
|
||||
## 准备
|
||||
|
||||
@@ -31,7 +65,7 @@
|
||||
- [Naive-ui-admin](https://www.naiveui.com/) - ui 基本使用
|
||||
- [Mock.js](https://github.com/nuysoft/Mock) - mockjs 基本语法
|
||||
|
||||
## 安装使用
|
||||
## 使用
|
||||
|
||||
- 获取项目代码
|
||||
|
||||
@@ -64,9 +98,6 @@ yarn build
|
||||
|
||||
[CHANGELOG](./CHANGELOG.md)
|
||||
|
||||
## 感谢
|
||||
[@Vben](https://github.com/anncwb/vue-vben-admin) 借鉴 vue-vben-admin 实现的骨架,同时也使用作者开发的 vite 插件,再次感谢作者。
|
||||
|
||||
|
||||
## 如何贡献
|
||||
|
||||
@@ -113,7 +144,13 @@ yarn build
|
||||
|
||||
## 交流
|
||||
|
||||
`Naive Ui Admin` 是完全开源免费的项目,在帮助开发者更方便地进行中大型管理系统开发,同时也提供 QQ 交流群使用问题欢迎在群内提问。
|
||||
`Naive Ui Admin` 使用或者其他问题,都可以在群内讨论或提问。
|
||||
|
||||
- QQ 群 `328347666`
|
||||

|
||||
|
||||
## 赞助
|
||||
#### 如果你觉得这个项目帮助到了你,你可以帮作者买一杯果汁表示鼓励 🍹。
|
||||
|
||||

|
||||
|
||||
[Paypal Me](https://www.paypal.com/paypalme/majunping)
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* Plugin to minimize and use ejs template syntax in index.html.
|
||||
* https://github.com/anncwb/vite-plugin-html
|
||||
*/
|
||||
import type { Plugin } from 'vite';
|
||||
import type { PluginOption } from 'vite';
|
||||
|
||||
import html from 'vite-plugin-html';
|
||||
import { createHtmlPlugin } from 'vite-plugin-html';
|
||||
|
||||
import pkg from '../../../package.json';
|
||||
import { GLOB_CONFIG_FILE_NAME } from '../../constant';
|
||||
@@ -18,11 +18,11 @@ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
|
||||
return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`;
|
||||
};
|
||||
|
||||
const htmlPlugin: Plugin[] = html({
|
||||
const htmlPlugin: PluginOption[] = createHtmlPlugin({
|
||||
minify: isBuild,
|
||||
inject: {
|
||||
// Inject data into ejs template
|
||||
injectData: {
|
||||
data: {
|
||||
title: VITE_GLOB_APP_TITLE,
|
||||
},
|
||||
// Embed the generated app.config.js file
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import type { Plugin } from 'vite';
|
||||
import type { Plugin,PluginOption } from 'vite';
|
||||
import Components from 'unplugin-vue-components/vite';
|
||||
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
|
||||
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx';
|
||||
@@ -10,11 +12,17 @@ import { configCompressPlugin } from './compress';
|
||||
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean, prodMock) {
|
||||
const { VITE_USE_MOCK, VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv;
|
||||
|
||||
const vitePlugins: (Plugin | Plugin[])[] = [
|
||||
const vitePlugins: (Plugin | Plugin[] | PluginOption[])[] = [
|
||||
// have to
|
||||
vue(),
|
||||
// have to
|
||||
vueJsx(),
|
||||
|
||||
// 按需引入NaiveUi且自动创建组件声明
|
||||
Components({
|
||||
dts: true,
|
||||
resolvers: [NaiveUiResolver()],
|
||||
}),
|
||||
];
|
||||
|
||||
// vite-plugin-html
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
/**
|
||||
* Introduces component library styles on demand.
|
||||
* https://github.com/anncwb/vite-plugin-style-import
|
||||
*/
|
||||
|
||||
import styleImport from 'vite-plugin-style-import';
|
||||
|
||||
export function configStyleImportPlugin(isBuild: boolean) {
|
||||
if (!isBuild) return [];
|
||||
const styleImportPlugin = styleImport({
|
||||
libs: [
|
||||
{
|
||||
libraryName: 'ant-design-vue',
|
||||
esModule: true,
|
||||
resolveStyle: (name) => {
|
||||
return `ant-design-vue/es/${name}/style/index`;
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
return styleImportPlugin;
|
||||
}
|
||||
@@ -14,7 +14,7 @@ module.exports = {
|
||||
'fixed',
|
||||
'resolve',
|
||||
'resolves',
|
||||
'resolved'
|
||||
'resolved',
|
||||
],
|
||||
issuePrefixes: ['#'],
|
||||
noteKeywords: ['BREAKING CHANGE'],
|
||||
@@ -23,8 +23,8 @@ module.exports = {
|
||||
revertCorrespondence: ['header', 'hash'],
|
||||
warn() {},
|
||||
mergePattern: null,
|
||||
mergeCorrespondence: null
|
||||
}
|
||||
mergeCorrespondence: null,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'body-leading-blank': [2, 'always'],
|
||||
@@ -50,8 +50,8 @@ module.exports = {
|
||||
'wip',
|
||||
'workflow',
|
||||
'types',
|
||||
'release'
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
'release',
|
||||
],
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
116
index.html
116
index.html
@@ -1,26 +1,122 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-cmn-Hans">
|
||||
<html lang="zh-cmn-Hans" id="htmlRoot" data-theme="light">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||
<meta name="renderer" content="webkit"/>
|
||||
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible"/>
|
||||
<meta content="webkit" name="renderer"/>
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0"
|
||||
name="viewport"
|
||||
/>
|
||||
<link rel="icon" href="/favicon.ico"/>
|
||||
<link href="/favicon.ico" rel="icon"/>
|
||||
<title><%= title %></title>
|
||||
<style>.first-loading-wrp{display:flex;justify-content:center;align-items:center;flex-direction:column;min-height:420px;height:100%}.first-loading-wrp>h1{font-size:128px}.first-loading-wrp .loading-wrp{padding:98px;display:flex;justify-content:center;align-items:center}.dot{animation:antRotate 1.2s infinite linear;transform:rotate(45deg);position:relative;display:inline-block;font-size:32px;width:32px;height:32px;box-sizing:border-box}.dot i{width:14px;height:14px;position:absolute;display:block;background-color:#1890ff;border-radius:100%;transform:scale(.75);transform-origin:50% 50%;opacity:.3;animation:antSpinMove 1s infinite linear alternate}.dot i:nth-child(1){top:0;left:0}.dot i:nth-child(2){top:0;right:0;-webkit-animation-delay:.4s;animation-delay:.4s}.dot i:nth-child(3){right:0;bottom:0;-webkit-animation-delay:.8s;animation-delay:.8s}.dot i:nth-child(4){bottom:0;left:0;-webkit-animation-delay:1.2s;animation-delay:1.2s}@keyframes antRotate{to{-webkit-transform:rotate(405deg);transform:rotate(405deg)}}@-webkit-keyframes antRotate{to{-webkit-transform:rotate(405deg);transform:rotate(405deg)}}@keyframes antSpinMove{to{opacity:1}}@-webkit-keyframes antSpinMove{to{opacity:1}}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="appProvider" style="display: none"></div>
|
||||
<div id="app">
|
||||
<div class="first-loading-wrp">
|
||||
<div class="loading-wrp">
|
||||
<span class="dot dot-spin"><i></i><i></i><i></i><i></i></span>
|
||||
<style>
|
||||
.first-loading-wrap {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100vh;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.first-loading-wrap > h1 {
|
||||
font-size: 128px
|
||||
}
|
||||
|
||||
.first-loading-wrap .loading-wrap {
|
||||
padding: 98px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center
|
||||
}
|
||||
|
||||
.dot {
|
||||
animation: antRotate 1.2s infinite linear;
|
||||
transform: rotate(45deg);
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
font-size: 32px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
box-sizing: border-box
|
||||
}
|
||||
|
||||
.dot i {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
position: absolute;
|
||||
display: block;
|
||||
background-color: #1890ff;
|
||||
border-radius: 100%;
|
||||
transform: scale(.75);
|
||||
transform-origin: 50% 50%;
|
||||
opacity: .3;
|
||||
animation: antSpinMove 1s infinite linear alternate
|
||||
}
|
||||
|
||||
.dot i:nth-child(1) {
|
||||
top: 0;
|
||||
left: 0
|
||||
}
|
||||
|
||||
.dot i:nth-child(2) {
|
||||
top: 0;
|
||||
right: 0;
|
||||
-webkit-animation-delay: .4s;
|
||||
animation-delay: .4s
|
||||
}
|
||||
|
||||
.dot i:nth-child(3) {
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
-webkit-animation-delay: .8s;
|
||||
animation-delay: .8s
|
||||
}
|
||||
|
||||
.dot i:nth-child(4) {
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
-webkit-animation-delay: 1.2s;
|
||||
animation-delay: 1.2s
|
||||
}
|
||||
|
||||
@keyframes antRotate {
|
||||
to {
|
||||
-webkit-transform: rotate(405deg);
|
||||
transform: rotate(405deg)
|
||||
}
|
||||
}
|
||||
|
||||
@-webkit-keyframes antRotate {
|
||||
to {
|
||||
-webkit-transform: rotate(405deg);
|
||||
transform: rotate(405deg)
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes antSpinMove {
|
||||
to {
|
||||
opacity: 1
|
||||
}
|
||||
}
|
||||
|
||||
@-webkit-keyframes antSpinMove {
|
||||
to {
|
||||
opacity: 1
|
||||
}
|
||||
}</style>
|
||||
<div class="first-loading-wrap">
|
||||
<div class="loading-wrap">
|
||||
<span class="dot dot-spin"><i></i><i></i><i></i><i></i></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
<script>var globalThis = window;</script>
|
||||
<script src="/src/main.ts" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer';
|
||||
|
||||
const modules = import.meta.globEager('./**/*.ts');
|
||||
interface IModuleType {
|
||||
default: any[];
|
||||
}
|
||||
|
||||
const modules = import.meta.glob<IModuleType>('./**/*.ts', { eager: true });
|
||||
|
||||
const mockModules: any[] = [];
|
||||
Object.keys(modules).forEach((key) => {
|
||||
|
||||
@@ -27,12 +27,15 @@ export default [
|
||||
timeout: 1000,
|
||||
method: 'get',
|
||||
response: ({ query }) => {
|
||||
const { page = 1, pageSize = 10 } = query;
|
||||
const { page = 1, pageSize = 10, name } = query;
|
||||
const list = tableList(Number(pageSize));
|
||||
//并非真实,只是为了模拟搜索结果
|
||||
const count = name ? 30 : 60;
|
||||
return resultSuccess({
|
||||
page: Number(page),
|
||||
pageSize: Number(pageSize),
|
||||
pageCount: 60,
|
||||
pageCount: count,
|
||||
itemCount: count * Number(pageSize),
|
||||
list,
|
||||
});
|
||||
},
|
||||
|
||||
143
package.json
143
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "naive-ui-admin",
|
||||
"version": "1.5.4",
|
||||
"version": "1.9.1",
|
||||
"author": {
|
||||
"name": "Ahjung",
|
||||
"email": "735878602@qq.com",
|
||||
@@ -8,13 +8,16 @@
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"bootstrap": "yarn install",
|
||||
"serve": "npm run dev",
|
||||
"bootstrap": "pnpm install",
|
||||
"serve": "pnpm run dev",
|
||||
"dev": "vite",
|
||||
"build": "vite build && esno ./build/script/postBuild.ts",
|
||||
"build:no-cache": "yarn clean:cache && npm run build",
|
||||
"build:no-cache": "pnpm clean:cache && npm run build",
|
||||
"report": "cross-env REPORT=true npm run build",
|
||||
"preview": "vite preview",
|
||||
"preview": "npm run build && vite preview",
|
||||
"preview:dist": "vite preview",
|
||||
"clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite",
|
||||
"clean:lib": "rimraf node_modules",
|
||||
"build typecheck": "vuedx-typecheck . && vite build",
|
||||
"deploy": "gh-pages -d dist",
|
||||
"lint:eslint": "eslint \"{src,mock}/**/*.{vue,ts,tsx}\" --fix",
|
||||
@@ -25,74 +28,76 @@
|
||||
"test prod gzip": "http-server dist --cors --gzip -c-1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vicons/antd": "^0.10.0",
|
||||
"@vicons/ionicons5": "^0.10.0",
|
||||
"@vueuse/core": "^5.0.3",
|
||||
"axios": "^0.21.1",
|
||||
"blueimp-md5": "^2.18.0",
|
||||
"date-fns": "^2.23.0",
|
||||
"echarts": "^5.1.2",
|
||||
"element-resize-detector": "^1.2.3",
|
||||
"lodash": "^4.17.21",
|
||||
"@vicons/antd": "^0.12.0",
|
||||
"@vicons/ionicons5": "^0.12.0",
|
||||
"@vueup/vue-quill": "^1.2.0",
|
||||
"@vueuse/core": "^9.13.0",
|
||||
"axios": "^1.6.8",
|
||||
"blueimp-md5": "^2.19.0",
|
||||
"date-fns": "^2.30.0",
|
||||
"echarts": "^5.5.0",
|
||||
"element-resize-detector": "^1.2.4",
|
||||
"lodash-es": "^4.17.21",
|
||||
"makeit-captcha": "^1.2.5",
|
||||
"mitt": "^2.1.0",
|
||||
"mitt": "^3.0.1",
|
||||
"mockjs": "^1.1.0",
|
||||
"naive-ui": "^2.16.2",
|
||||
"pinia": "^2.0.0-beta.3",
|
||||
"qs": "^6.10.1",
|
||||
"vfonts": "^0.1.0",
|
||||
"vue": "^3.1.2",
|
||||
"vue-router": "^4.0.10",
|
||||
"vue-types": "^4.0.0",
|
||||
"vuedraggable": "^4.0.3",
|
||||
"vuex": "^4.0.2"
|
||||
"naive-ui": "^2.38.1",
|
||||
"pinia": "^2.1.7",
|
||||
"qs": "^6.12.0",
|
||||
"vfonts": "^0.0.3",
|
||||
"vue": "^3.4.21",
|
||||
"vue-router": "^4.3.0",
|
||||
"vue-types": "^4.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "^12.1.4",
|
||||
"@commitlint/config-conventional": "^12.1.4",
|
||||
"@types/lodash": "^4.14.170",
|
||||
"@types/node": "^15.12.2",
|
||||
"@typescript-eslint/eslint-plugin": "^4.26.1",
|
||||
"@typescript-eslint/parser": "^4.26.1",
|
||||
"@vitejs/plugin-vue": "^1.2.3",
|
||||
"@vitejs/plugin-vue-jsx": "^1.1.5",
|
||||
"@vue/compiler-sfc": "3.1.1",
|
||||
"@vue/eslint-config-typescript": "^7.0.0",
|
||||
"autoprefixer": "^10.3.1",
|
||||
"commitizen": "^4.2.4",
|
||||
"core-js": "^3.14.0",
|
||||
"dotenv": "^10.0.0",
|
||||
"eslint": "^7.28.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-define-config": "^1.0.9",
|
||||
"eslint-plugin-jest": "^24.4.0",
|
||||
"eslint-plugin-prettier": "^3.4.0",
|
||||
"eslint-plugin-vue": "^7.11.1",
|
||||
"esno": "^0.7.3",
|
||||
"gh-pages": "^3.2.0",
|
||||
"husky": "^6.0.0",
|
||||
"jest": "^27.0.6",
|
||||
"less": "^4.1.1",
|
||||
"less-loader": "^9.0.0",
|
||||
"lint-staged": "^11.0.0",
|
||||
"postcss": "^8.3.5",
|
||||
"prettier": "^2.3.1",
|
||||
"pretty-quick": "^3.1.0",
|
||||
"@commitlint/cli": "^17.8.1",
|
||||
"@commitlint/config-conventional": "^17.8.1",
|
||||
"@types/lodash": "^4.17.0",
|
||||
"@types/node": "^18.19.31",
|
||||
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
||||
"@typescript-eslint/parser": "^5.62.0",
|
||||
"@vitejs/plugin-vue": "^3.2.0",
|
||||
"@vitejs/plugin-vue-jsx": "^2.1.1",
|
||||
"@vue/compiler-sfc": "^3.4.21",
|
||||
"@vue/eslint-config-typescript": "^11.0.3",
|
||||
"autoprefixer": "^10.4.19",
|
||||
"commitizen": "^4.3.0",
|
||||
"core-js": "^3.36.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"dotenv": "^16.4.5",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^8.10.0",
|
||||
"eslint-define-config": "1.12.0",
|
||||
"eslint-plugin-jest": "^27.9.0",
|
||||
"eslint-plugin-prettier": "^4.2.1",
|
||||
"eslint-plugin-vue": "^9.24.1",
|
||||
"esno": "^0.16.3",
|
||||
"gh-pages": "^4.0.0",
|
||||
"husky": "^8.0.3",
|
||||
"jest": "^29.7.0",
|
||||
"less": "^4.2.0",
|
||||
"less-loader": "^11.1.4",
|
||||
"lint-staged": "^13.3.0",
|
||||
"postcss": "^8.4.38",
|
||||
"prettier": "^2.8.8",
|
||||
"pretty-quick": "^3.3.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"stylelint": "^13.13.1",
|
||||
"stylelint-config-prettier": "^8.0.2",
|
||||
"stylelint-config-standard": "^22.0.0",
|
||||
"stylelint-order": "^4.1.0",
|
||||
"stylelint-scss": "^3.19.0",
|
||||
"tailwindcss": "^2.2.7",
|
||||
"typescript": "^4.3.5",
|
||||
"vite": "2.4.4",
|
||||
"vite-plugin-compression": "^0.3.1",
|
||||
"vite-plugin-html": "^2.0.7",
|
||||
"vite-plugin-mock": "^2.9.3",
|
||||
"vite-plugin-style-import": "^1.0.1",
|
||||
"vue-eslint-parser": "^7.8.0"
|
||||
"stylelint": "^14.16.1",
|
||||
"stylelint-config-prettier": "^9.0.5",
|
||||
"stylelint-config-standard": "^29.0.0",
|
||||
"stylelint-order": "^5.0.0",
|
||||
"stylelint-scss": "^4.7.0",
|
||||
"tailwindcss": "^3.4.3",
|
||||
"typescript": "^4.9.5",
|
||||
"unplugin-vue-components": "^0.22.12",
|
||||
"vite": "^3.2.10",
|
||||
"vite-plugin-compression": "^0.5.1",
|
||||
"vite-plugin-html": "^3.2.2",
|
||||
"vite-plugin-mock": "^2.9.8",
|
||||
"vite-plugin-style-import": "^2.0.0",
|
||||
"vue-demi": "^0.13.11",
|
||||
"vue-draggable-next": "^2.2.1",
|
||||
"vue-eslint-parser": "^9.4.2",
|
||||
"vuedraggable": "^4.1.0"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{vue,js,ts,tsx}": "eslint --fix"
|
||||
@@ -122,6 +127,6 @@
|
||||
},
|
||||
"homepage": "https://github.com/jekip/naive-ui-admin",
|
||||
"engines": {
|
||||
"node": "^12 || >=14"
|
||||
"node": ">=16"
|
||||
}
|
||||
}
|
||||
|
||||
8215
pnpm-lock.yaml
generated
Normal file
8215
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -3,4 +3,4 @@ module.exports = {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="renderer" content="webkit"/>
|
||||
<meta name="force-rendering" content="webkit"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||
<meta name="referrer" content="no-referrer" />
|
||||
<link rel="icon" href="/favicon.ico">
|
||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||
<script src="<%= BASE_URL %>iconfont.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
|
||||
Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
<!-- IE 浏览器跳转提示升级页面 start -->
|
||||
<script>
|
||||
if (/*@cc_on!@*/false || (!!window.MSInputMethodContext && !!document.documentMode)) {
|
||||
window.open("https://support.dmeng.net/upgrade-your-browser.html?referrer="+encodeURIComponent(window.location.href));
|
||||
};
|
||||
</script>
|
||||
<!-- IE 浏览器跳转提示升级页面 end -->
|
||||
<script>
|
||||
function isIE() {
|
||||
if (!!window.ActiveXObject || "ActiveXObject" in window){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
130
src/App.vue
130
src/App.vue
@@ -16,96 +16,68 @@
|
||||
</transition>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, computed, onMounted, onUnmounted } from 'vue';
|
||||
import { zhCN, dateZhCN, createTheme, inputDark, datePickerDark, darkTheme } from 'naive-ui';
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, onUnmounted } from 'vue';
|
||||
import { zhCN, dateZhCN, darkTheme } from 'naive-ui';
|
||||
import { LockScreen } from '@/components/Lockscreen';
|
||||
import { AppProvider } from '@/components/Application';
|
||||
import { useLockscreenStore } from '@/store/modules/lockscreen';
|
||||
import { useScreenLockStore } from '@/store/modules/screenLock.js';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useDesignSettingStore } from '@/store/modules/designSetting';
|
||||
import { lighten } from '@/utils/index';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'App',
|
||||
components: { LockScreen, AppProvider },
|
||||
setup() {
|
||||
const route = useRoute();
|
||||
const useLockscreen = useLockscreenStore();
|
||||
const designStore = useDesignSettingStore();
|
||||
const isLock = computed(() => useLockscreen.isLock);
|
||||
const lockTime = computed(() => useLockscreen.lockTime);
|
||||
const route = useRoute();
|
||||
const useScreenLock = useScreenLockStore();
|
||||
const designStore = useDesignSettingStore();
|
||||
const isLock = computed(() => useScreenLock.isLocked);
|
||||
const lockTime = computed(() => useScreenLock.lockTime);
|
||||
|
||||
/**
|
||||
* @type import('naive-ui').GlobalThemeOverrides
|
||||
*/
|
||||
const getThemeOverrides = computed(() => {
|
||||
const appTheme = designStore.appTheme;
|
||||
const lightenStr = lighten(designStore.appTheme, 6);
|
||||
return {
|
||||
common: {
|
||||
primaryColor: appTheme,
|
||||
primaryColorHover: lightenStr,
|
||||
primaryColorPressed: lightenStr,
|
||||
},
|
||||
LoadingBar: {
|
||||
colorLoading: appTheme,
|
||||
},
|
||||
};
|
||||
});
|
||||
/**
|
||||
* @type import('naive-ui').GlobalThemeOverrides
|
||||
*/
|
||||
const getThemeOverrides = computed(() => {
|
||||
const appTheme = designStore.appTheme;
|
||||
const lightenStr = lighten(designStore.appTheme, 6);
|
||||
return {
|
||||
common: {
|
||||
primaryColor: appTheme,
|
||||
primaryColorHover: lightenStr,
|
||||
primaryColorPressed: lightenStr,
|
||||
primaryColorSuppl: appTheme,
|
||||
},
|
||||
LoadingBar: {
|
||||
colorLoading: appTheme,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const getDarkTheme = computed(() => (designStore.darkTheme ? darkTheme : undefined));
|
||||
const getDarkTheme = computed(() => (designStore.darkTheme ? darkTheme : undefined));
|
||||
|
||||
let timer;
|
||||
let timer: NodeJS.Timer;
|
||||
|
||||
const timekeeping = () => {
|
||||
clearInterval(timer);
|
||||
if (route.name == 'login' || isLock.value) return;
|
||||
// 设置不锁屏
|
||||
useLockscreen.setLock(false);
|
||||
// 重置锁屏时间
|
||||
useLockscreen.setLockTime();
|
||||
timer = setInterval(() => {
|
||||
// 锁屏倒计时递减
|
||||
useLockscreen.setLockTime(lockTime.value - 1);
|
||||
if (lockTime.value <= 0) {
|
||||
// 设置锁屏
|
||||
useLockscreen.setLock(true);
|
||||
return clearInterval(timer);
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
const timekeeping = () => {
|
||||
clearInterval(timer);
|
||||
if (route.name == 'login' || isLock.value) return;
|
||||
// 设置不锁屏
|
||||
useScreenLock.setLock(false);
|
||||
// 重置锁屏时间
|
||||
useScreenLock.setLockTime();
|
||||
timer = setInterval(() => {
|
||||
// 锁屏倒计时递减
|
||||
useScreenLock.setLockTime(lockTime.value - 1);
|
||||
if (lockTime.value <= 0) {
|
||||
// 设置锁屏
|
||||
useScreenLock.setLock(true);
|
||||
return clearInterval(timer);
|
||||
}
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
document.addEventListener('mousedown', timekeeping);
|
||||
});
|
||||
onMounted(() => {
|
||||
document.addEventListener('mousedown', timekeeping);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('mousedown', timekeeping);
|
||||
});
|
||||
|
||||
return {
|
||||
darkTheme: createTheme([inputDark, datePickerDark]),
|
||||
getDarkTheme,
|
||||
zhCN,
|
||||
dateZhCN,
|
||||
isLock,
|
||||
getThemeOverrides,
|
||||
};
|
||||
},
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('mousedown', timekeeping);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
@import 'styles/common.less';
|
||||
|
||||
.slide-up-enter-active,
|
||||
.slide-up-leave-active {
|
||||
transition: transform 0.35s ease-in;
|
||||
}
|
||||
|
||||
.slide-up-enter-form,
|
||||
.slide-up-leave-to {
|
||||
transform: translateY(-100%);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import http from '@/utils/http/axios';
|
||||
import { http } from '@/utils/http/axios';
|
||||
|
||||
//获取主控台信息
|
||||
export function getConsoleInfo() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import http from '@/utils/http/axios';
|
||||
import { http } from '@/utils/http/axios';
|
||||
|
||||
/**
|
||||
* @description: 根据用户id获取用户菜单
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import http from '@/utils/http/axios';
|
||||
import { http } from '@/utils/http/axios';
|
||||
|
||||
/**
|
||||
* @description: 角色列表
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import http from '@/utils/http/axios';
|
||||
import { http } from '@/utils/http/axios';
|
||||
|
||||
export interface BasicResponseModel<T = any> {
|
||||
code: number;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import http from '@/utils/http/axios';
|
||||
import { http } from '@/utils/http/axios';
|
||||
|
||||
//获取table
|
||||
export function getTableList(params) {
|
||||
|
||||
@@ -1,27 +1,16 @@
|
||||
<template>
|
||||
<n-loading-bar-provider>
|
||||
<n-dialog-provider>
|
||||
<DialogContent />
|
||||
<n-notification-provider>
|
||||
<n-message-provider>
|
||||
<MessageContent />
|
||||
<slot slot="default"></slot>
|
||||
</n-message-provider>
|
||||
</n-notification-provider>
|
||||
</n-dialog-provider>
|
||||
</n-loading-bar-provider>
|
||||
<n-dialog-provider>
|
||||
<n-notification-provider>
|
||||
<n-message-provider>
|
||||
<slot name="default"></slot>
|
||||
</n-message-provider>
|
||||
</n-notification-provider>
|
||||
</n-dialog-provider>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import {
|
||||
NDialogProvider,
|
||||
NNotificationProvider,
|
||||
NMessageProvider,
|
||||
NLoadingBarProvider,
|
||||
} from 'naive-ui';
|
||||
import { MessageContent } from '@/components/MessageContent';
|
||||
import { DialogContent } from '@/components/DialogContent';
|
||||
import { NDialogProvider, NNotificationProvider, NMessageProvider } from 'naive-ui';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Application',
|
||||
@@ -29,9 +18,6 @@
|
||||
NDialogProvider,
|
||||
NNotificationProvider,
|
||||
NMessageProvider,
|
||||
NLoadingBarProvider,
|
||||
MessageContent,
|
||||
DialogContent,
|
||||
},
|
||||
setup() {
|
||||
return {};
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import DialogContent from './index.vue';
|
||||
|
||||
export { DialogContent };
|
||||
@@ -1,12 +0,0 @@
|
||||
<template></template>
|
||||
<script lang="ts">
|
||||
import { useDialog } from 'naive-ui';
|
||||
|
||||
export default {
|
||||
name: 'DialogContent',
|
||||
setup() {
|
||||
//挂载在 window 方便与在js中使用
|
||||
window['$dialog'] = useDialog();
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -8,7 +8,7 @@
|
||||
{{ schema.label }}
|
||||
<n-tooltip trigger="hover" :style="schema.labelMessageStyle">
|
||||
<template #trigger>
|
||||
<n-icon size="18" class="cursor-pointer text-gray-400">
|
||||
<n-icon size="18" class="text-gray-400 cursor-pointer">
|
||||
<QuestionCircleOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
@@ -90,6 +90,7 @@
|
||||
v-bind="getSubmitBtnOptions"
|
||||
@click="handleSubmit"
|
||||
:loading="loadingSub"
|
||||
attr-type="submit"
|
||||
>{{ getProps.submitButtonText }}</n-button
|
||||
>
|
||||
<n-button
|
||||
@@ -102,7 +103,7 @@
|
||||
type="primary"
|
||||
text
|
||||
icon-placement="right"
|
||||
v-if="overflow && isInline && getProps.showAdvancedButton"
|
||||
v-if="isInline && getProps.showAdvancedButton"
|
||||
@click="unfoldToggle"
|
||||
>
|
||||
<template #icon>
|
||||
@@ -138,7 +139,7 @@
|
||||
import { deepMerge } from '@/utils';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'BasicUpload',
|
||||
name: 'BasicForm',
|
||||
components: { DownOutlined, UpOutlined, QuestionCircleOutlined },
|
||||
props: {
|
||||
...basicProps,
|
||||
@@ -230,7 +231,6 @@
|
||||
});
|
||||
|
||||
const { handleFormValues, initDefault } = useFormValues({
|
||||
getProps,
|
||||
defaultFormModel,
|
||||
getSchema,
|
||||
formModel,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ComponentType } from '/types/index';
|
||||
import { ComponentType } from './types/index';
|
||||
|
||||
/**
|
||||
* @description: 生成placeholder
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { FormProps, FormActionType, UseFormReturnType } from '../types/form';
|
||||
// @ts-ignore
|
||||
import type { DynamicProps } from '/#/utils';
|
||||
|
||||
import { ref, onUnmounted, unref, nextTick, watch } from 'vue';
|
||||
@@ -81,6 +80,15 @@ export function useForm(props?: Props): UseFormReturnType {
|
||||
const form = await getForm();
|
||||
return form.validate(nameList);
|
||||
},
|
||||
|
||||
setLoading: (value: boolean) => {
|
||||
loadedRef.value = value;
|
||||
},
|
||||
|
||||
setSchema: async (values) => {
|
||||
const form = await getForm();
|
||||
form.setSchema(values);
|
||||
},
|
||||
};
|
||||
|
||||
return [register, methods];
|
||||
|
||||
@@ -32,23 +32,27 @@ export function useFormEvents({
|
||||
}
|
||||
|
||||
// 提交
|
||||
async function handleSubmit(e?: Event): Promise<void> {
|
||||
async function handleSubmit(e?: Event): Promise<object | boolean> {
|
||||
e && e.preventDefault();
|
||||
loadingSub.value = true;
|
||||
const { submitFunc } = unref(getProps);
|
||||
if (submitFunc && isFunction(submitFunc)) {
|
||||
await submitFunc();
|
||||
return;
|
||||
loadingSub.value = false;
|
||||
return false;
|
||||
}
|
||||
const formEl = unref(formElRef);
|
||||
if (!formEl) return;
|
||||
if (!formEl) return false;
|
||||
try {
|
||||
await validate();
|
||||
const values = getFieldsValue();
|
||||
loadingSub.value = false;
|
||||
emit('submit', formModel);
|
||||
return true;
|
||||
} catch (error) {
|
||||
emit('submit', values);
|
||||
return values;
|
||||
} catch (error: any) {
|
||||
emit('submit', false);
|
||||
loadingSub.value = false;
|
||||
console.error(error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -96,6 +100,10 @@ export function useFormEvents({
|
||||
});
|
||||
}
|
||||
|
||||
function setLoading(value: boolean): void {
|
||||
loadingSub.value = value;
|
||||
}
|
||||
|
||||
return {
|
||||
handleSubmit,
|
||||
validate,
|
||||
@@ -103,5 +111,6 @@ export function useFormEvents({
|
||||
getFieldsValue,
|
||||
clearValidate,
|
||||
setFieldsValue,
|
||||
setLoading,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,16 +41,19 @@ export interface FormProps {
|
||||
submitFunc?: () => Promise<void>;
|
||||
submitOnReset?: boolean;
|
||||
baseGridStyle?: CSSProperties;
|
||||
collapsedRows?: number;
|
||||
}
|
||||
|
||||
export interface FormActionType {
|
||||
submit: () => Promise<any>;
|
||||
setProps: (formProps: Partial<FormProps>) => Promise<void>;
|
||||
setFieldsValue: <T>(values: T) => Promise<void>;
|
||||
setSchema: (schemaProps: Partial<FormSchema[]>) => Promise<void>;
|
||||
setFieldsValue: (values: Recordable) => void;
|
||||
clearValidate: (name?: string | string[]) => Promise<void>;
|
||||
getFieldsValue: () => Recordable;
|
||||
resetFields: () => Promise<void>;
|
||||
validate: (nameList?: any[]) => Promise<any>;
|
||||
setLoading: (status: boolean) => void;
|
||||
}
|
||||
|
||||
export type RegisterFn = (formInstance: FormActionType) => void;
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import LoadingContent from './index.vue';
|
||||
|
||||
export { LoadingContent };
|
||||
@@ -1,12 +0,0 @@
|
||||
<template></template>
|
||||
<script lang="ts">
|
||||
import { useLoadingBar } from 'naive-ui';
|
||||
|
||||
export default {
|
||||
name: 'LoadingContent',
|
||||
setup() {
|
||||
//挂载在 window 方便与在js中使用
|
||||
window['$loading'] = useLoadingBar();
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -60,11 +60,11 @@
|
||||
</template>
|
||||
</n-input>
|
||||
|
||||
<div class="w-full flex" v-if="isLoginError">
|
||||
<div class="flex w-full" v-if="isLoginError">
|
||||
<span class="text-red-500">{{ errorMsg }}</span>
|
||||
</div>
|
||||
|
||||
<div class="w-full mt-1 flex justify-around">
|
||||
<div class="flex justify-around w-full mt-1">
|
||||
<div><a @click="showLogin = false">返回</a></div>
|
||||
<div><a @click="goLogin">重新登录</a></div>
|
||||
<div><a @click="onLogin">进入系统</a></div>
|
||||
@@ -91,11 +91,11 @@
|
||||
import { useOnline } from '@/hooks/useOnline';
|
||||
import { useTime } from '@/hooks/useTime';
|
||||
import { useBattery } from '@/hooks/useBattery';
|
||||
import { useLockscreenStore } from '@/store/modules/lockscreen';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import { useScreenLockStore } from '@/store/modules/screenLock';
|
||||
import { UserInfoType, useUserStore } from '@/store/modules/user';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Lockscreen',
|
||||
name: 'ScreenLock',
|
||||
components: {
|
||||
LockOutlined,
|
||||
LoadingOutlined,
|
||||
@@ -106,7 +106,7 @@
|
||||
recharge,
|
||||
},
|
||||
setup() {
|
||||
const useLockscreen = useLockscreenStore();
|
||||
const useScreenLock = useScreenLockStore();
|
||||
const userStore = useUserStore();
|
||||
|
||||
// 获取时间
|
||||
@@ -117,7 +117,7 @@
|
||||
const route = useRoute();
|
||||
|
||||
const { battery, batteryStatus, calcDischargingTime, calcChargingTime } = useBattery();
|
||||
const userInfo: object = userStore.getUserInfo || {};
|
||||
const userInfo: UserInfoType = userStore.getUserInfo || {};
|
||||
const username = userInfo['username'] || '';
|
||||
const state = reactive({
|
||||
showLogin: false,
|
||||
@@ -146,7 +146,7 @@
|
||||
const { code, message } = await userStore.login(params);
|
||||
if (code === ResultEnum.SUCCESS) {
|
||||
onLockLogin(false);
|
||||
useLockscreen.setLock(false);
|
||||
useScreenLock.setLock(false);
|
||||
} else {
|
||||
state.errorMsg = message;
|
||||
state.isLoginError = true;
|
||||
@@ -157,7 +157,7 @@
|
||||
//重新登录
|
||||
const goLogin = () => {
|
||||
onLockLogin(false);
|
||||
useLockscreen.setLock(false);
|
||||
useScreenLock.setLock(false);
|
||||
router.replace({
|
||||
path: '/login',
|
||||
query: {
|
||||
|
||||
@@ -135,22 +135,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
@width: ~`Math.round(Math.random() * 100) ` px;
|
||||
@left: calc(15px + `Math.round(Math.random(70)) `);
|
||||
each(range(15), {
|
||||
.xiaoma-@{value} {
|
||||
height: (@value * 50px);
|
||||
}
|
||||
li:nth-child(@{index}) {
|
||||
top: 50%;
|
||||
left: @left;
|
||||
width: @width;
|
||||
height: @width;
|
||||
transform: translate(-50%, -50%);
|
||||
/*animation: moveToTop (Math.random(6) + 3s) ease-in-out -(Math.random(5000) / 1000s) infinite;*/
|
||||
}
|
||||
});
|
||||
|
||||
@keyframes rotate {
|
||||
50% {
|
||||
border-radius: 45% / 42% 38% 58% 49%;
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import MessageContent from './index.vue';
|
||||
|
||||
export { MessageContent };
|
||||
@@ -1,12 +0,0 @@
|
||||
<template></template>
|
||||
<script lang="ts">
|
||||
import { useMessage } from 'naive-ui';
|
||||
|
||||
export default {
|
||||
name: 'MessageContent',
|
||||
setup() {
|
||||
//挂载在 window 方便与在js中使用
|
||||
window['$message'] = useMessage();
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -20,104 +20,84 @@
|
||||
</n-modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import {
|
||||
defineComponent,
|
||||
getCurrentInstance,
|
||||
ref,
|
||||
nextTick,
|
||||
unref,
|
||||
toRefs,
|
||||
reactive,
|
||||
computed,
|
||||
} from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { getCurrentInstance, ref, nextTick, unref, computed, useAttrs } from 'vue';
|
||||
import { basicProps } from './props';
|
||||
import startDrag from '@/utils/Drag';
|
||||
import { deepMerge } from '@/utils';
|
||||
import { FormProps } from '@/components/Form';
|
||||
export default defineComponent({
|
||||
name: 'BasicModal',
|
||||
components: {},
|
||||
props: {
|
||||
...basicProps,
|
||||
},
|
||||
emits: ['on-close', 'on-ok', 'register'],
|
||||
setup(props, { emit, attrs }) {
|
||||
const propsRef = ref<Partial>({});
|
||||
import { ModalProps, ModalMethods } from './type';
|
||||
|
||||
const state = reactive({
|
||||
isModal: false,
|
||||
subLoading: false,
|
||||
});
|
||||
const attrs = useAttrs();
|
||||
const props = defineProps({ ...basicProps });
|
||||
const emit = defineEmits(['on-close', 'on-ok', 'register']);
|
||||
|
||||
const getProps = computed((): FormProps => {
|
||||
const modalProps = { ...props, ...unref(propsRef) };
|
||||
return { ...modalProps };
|
||||
});
|
||||
const propsRef = ref<Partial<ModalProps> | null>(null);
|
||||
|
||||
async function setProps(modalProps: Partial): Promise<void> {
|
||||
propsRef.value = deepMerge(unref(propsRef) || {}, modalProps);
|
||||
}
|
||||
const isModal = ref(false);
|
||||
const subLoading = ref(false);
|
||||
|
||||
const getBindValue = computed(() => {
|
||||
return {
|
||||
...attrs,
|
||||
...unref(getProps),
|
||||
};
|
||||
});
|
||||
|
||||
function setSubLoading(status: boolean) {
|
||||
state.subLoading = status;
|
||||
}
|
||||
|
||||
function openModal() {
|
||||
state.isModal = true;
|
||||
nextTick(() => {
|
||||
const oBox = document.getElementById('basic-modal');
|
||||
const oBar = document.getElementById('basic-modal-bar');
|
||||
startDrag(oBar, oBox);
|
||||
});
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
state.isModal = false;
|
||||
state.subLoading = false;
|
||||
emit('on-close');
|
||||
}
|
||||
|
||||
function onCloseModal() {
|
||||
state.isModal = false;
|
||||
emit('on-close');
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
state.subLoading = true;
|
||||
emit('on-ok');
|
||||
}
|
||||
|
||||
const modalMethods: ModalMethods = {
|
||||
setProps,
|
||||
openModal,
|
||||
closeModal,
|
||||
setSubLoading,
|
||||
};
|
||||
|
||||
const instance = getCurrentInstance();
|
||||
if (instance) {
|
||||
emit('register', modalMethods);
|
||||
}
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
getBindValue,
|
||||
openModal,
|
||||
closeModal,
|
||||
onCloseModal,
|
||||
handleSubmit,
|
||||
setProps,
|
||||
};
|
||||
},
|
||||
const getProps = computed((): FormProps => {
|
||||
return { ...props, ...(unref(propsRef) as any) };
|
||||
});
|
||||
|
||||
const subBtuText = computed(() => {
|
||||
const { subBtuText } = propsRef.value as any;
|
||||
return subBtuText || props.subBtuText;
|
||||
});
|
||||
|
||||
async function setProps(modalProps: Partial<ModalProps>): Promise<void> {
|
||||
propsRef.value = deepMerge(unref(propsRef) || ({} as any), modalProps);
|
||||
}
|
||||
|
||||
const getBindValue = computed(() => {
|
||||
return {
|
||||
...attrs,
|
||||
...unref(getProps),
|
||||
...unref(propsRef),
|
||||
};
|
||||
});
|
||||
|
||||
function setSubLoading(status: boolean) {
|
||||
subLoading.value = status;
|
||||
}
|
||||
|
||||
function openModal() {
|
||||
isModal.value = true;
|
||||
nextTick(() => {
|
||||
const oBox = document.getElementById('basic-modal');
|
||||
const oBar = document.getElementById('basic-modal-bar');
|
||||
startDrag(oBar, oBox);
|
||||
});
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
isModal.value = false;
|
||||
subLoading.value = false;
|
||||
emit('on-close');
|
||||
}
|
||||
|
||||
function onCloseModal() {
|
||||
isModal.value = false;
|
||||
emit('on-close');
|
||||
}
|
||||
|
||||
function handleSubmit() {
|
||||
subLoading.value = true;
|
||||
emit('on-ok');
|
||||
}
|
||||
|
||||
const modalMethods: ModalMethods = {
|
||||
setProps,
|
||||
openModal,
|
||||
closeModal,
|
||||
setSubLoading,
|
||||
};
|
||||
|
||||
const instance = getCurrentInstance();
|
||||
if (instance) {
|
||||
emit('register', modalMethods);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
|
||||
@@ -1,46 +1,41 @@
|
||||
import { ref, onUnmounted, unref, getCurrentInstance, watch } from 'vue';
|
||||
import { ref, unref, getCurrentInstance, watch } from 'vue';
|
||||
import { isProdMode } from '@/utils/env';
|
||||
import { ReturnMethods } from '../type';
|
||||
import { ModalMethods, UseModalReturnType } from '../type';
|
||||
import { getDynamicProps } from '@/utils';
|
||||
export function useModal(props): (((modalMethod: ReturnMethods) => any) | ReturnMethods)[] {
|
||||
const modal = ref<Nullable<ReturnMethods>>(null);
|
||||
const loaded = ref<Nullable<boolean>>(false);
|
||||
|
||||
function register(modalMethod: ReturnMethods) {
|
||||
if (!getCurrentInstance()) {
|
||||
throw new Error('useModal() can only be used inside setup() or functional components!');
|
||||
}
|
||||
isProdMode() &&
|
||||
onUnmounted(() => {
|
||||
modal.value = null;
|
||||
loaded.value = false;
|
||||
});
|
||||
if (unref(loaded) && isProdMode() && modalMethod === unref(modal)) return;
|
||||
modal.value = modalMethod;
|
||||
|
||||
watch(
|
||||
() => props,
|
||||
() => {
|
||||
// @ts-ignore
|
||||
const { setProps } = modal.value;
|
||||
props && setProps(getDynamicProps(props));
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
deep: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
import { tryOnUnmounted } from '@vueuse/core';
|
||||
export function useModal(props): UseModalReturnType {
|
||||
const modalRef = ref<Nullable<ModalMethods>>(null);
|
||||
const currentInstance = getCurrentInstance();
|
||||
|
||||
const getInstance = () => {
|
||||
const instance = unref(modal);
|
||||
const instance = unref(modalRef.value);
|
||||
if (!instance) {
|
||||
console.error('useModal instance is undefined!');
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
|
||||
const methods: ReturnMethods = {
|
||||
const register = (modalInstance: ModalMethods) => {
|
||||
isProdMode() &&
|
||||
tryOnUnmounted(() => {
|
||||
modalRef.value = null;
|
||||
});
|
||||
modalRef.value = modalInstance;
|
||||
currentInstance?.emit('register', modalInstance);
|
||||
|
||||
watch(
|
||||
() => props,
|
||||
() => {
|
||||
props && modalInstance.setProps(getDynamicProps(props));
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
deep: true,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const methods: ModalMethods = {
|
||||
setProps: (props): void => {
|
||||
getInstance()?.setProps(props);
|
||||
},
|
||||
@@ -54,5 +49,6 @@ export function useModal(props): (((modalMethod: ReturnMethods) => any) | Return
|
||||
getInstance()?.setSubLoading(status);
|
||||
},
|
||||
};
|
||||
|
||||
return [register, methods];
|
||||
}
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
import type { DialogOptions } from 'naive-ui/lib/dialog';
|
||||
/**
|
||||
* @description: 弹窗对外暴露的方法
|
||||
*/
|
||||
export interface ReturnMethods {
|
||||
export interface ModalMethods {
|
||||
setProps: (props) => void;
|
||||
openModal: () => void;
|
||||
closeModal: () => void;
|
||||
setSubLoading: (status) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支持修改,DialogOptions 參數
|
||||
*/
|
||||
export type ModalProps = DialogOptions;
|
||||
|
||||
export type RegisterFn = (ModalInstance: ModalMethods) => void;
|
||||
|
||||
export type UseModalReturnType = [RegisterFn, ModalMethods];
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
{{ title }}
|
||||
<n-tooltip trigger="hover" v-if="titleTooltip">
|
||||
<template #trigger>
|
||||
<n-icon size="18" class="ml-1 cursor-pointer text-gray-400">
|
||||
<n-icon size="18" class="ml-1 text-gray-400 cursor-pointer">
|
||||
<QuestionCircleOutlined />
|
||||
</n-icon>
|
||||
</template>
|
||||
@@ -22,6 +22,17 @@
|
||||
<!--顶部右侧区域-->
|
||||
<slot name="toolbar"></slot>
|
||||
|
||||
<!--斑马纹-->
|
||||
<n-tooltip trigger="hover">
|
||||
<template #trigger>
|
||||
<div class="mr-2 table-toolbar-right-icon">
|
||||
<n-switch v-model:value="isStriped" @update:value="setStriped" />
|
||||
</div>
|
||||
</template>
|
||||
<span>表格斑马纹</span>
|
||||
</n-tooltip>
|
||||
<n-divider vertical />
|
||||
|
||||
<!--刷新-->
|
||||
<n-tooltip trigger="hover">
|
||||
<template #trigger>
|
||||
@@ -61,6 +72,7 @@
|
||||
<n-data-table
|
||||
ref="tableElRef"
|
||||
v-bind="getBindValues"
|
||||
:striped="isStriped"
|
||||
:pagination="pagination"
|
||||
@update:page="updatePage"
|
||||
@update:page-size="updatePageSize"
|
||||
@@ -144,7 +156,7 @@
|
||||
const tableElRef = ref<ComponentRef>(null);
|
||||
const wrapRef = ref<Nullable<HTMLDivElement>>(null);
|
||||
let paginationEl: HTMLElement | null;
|
||||
|
||||
const isStriped = ref(false);
|
||||
const tableData = ref<Recordable[]>([]);
|
||||
const innerPropsRef = ref<Partial<BasicTableProps>>();
|
||||
|
||||
@@ -156,7 +168,7 @@
|
||||
|
||||
const { getPaginationInfo, setPagination } = usePagination(getProps);
|
||||
|
||||
const { getDataSourceRef, getRowKey, reload } = useDataSource(
|
||||
const { getDataSourceRef, getDataSource, getRowKey, reload } = useDataSource(
|
||||
getProps,
|
||||
{
|
||||
getPaginationInfo,
|
||||
@@ -171,7 +183,7 @@
|
||||
useColumns(getProps);
|
||||
|
||||
const state = reactive({
|
||||
tableSize: 'medium',
|
||||
tableSize: unref(getProps as any).size || 'medium',
|
||||
isColumnSetting: false,
|
||||
});
|
||||
|
||||
@@ -223,6 +235,8 @@
|
||||
innerPropsRef.value = { ...unref(innerPropsRef), ...props };
|
||||
}
|
||||
|
||||
const setStriped = (value: boolean) => (isStriped.value = value);
|
||||
|
||||
const tableAction = {
|
||||
reload,
|
||||
setColumns,
|
||||
@@ -250,7 +264,7 @@
|
||||
const headerH = 64;
|
||||
let paginationH = 2;
|
||||
let marginH = 24;
|
||||
if (!isBoolean(pagination)) {
|
||||
if (!isBoolean(unref(pagination))) {
|
||||
paginationEl = tableEl.querySelector('.n-data-table__pagination') as HTMLElement;
|
||||
if (paginationEl) {
|
||||
const offsetHeight = paginationEl.offsetHeight;
|
||||
@@ -280,6 +294,7 @@
|
||||
...toRefs(state),
|
||||
tableElRef,
|
||||
getBindValues,
|
||||
getDataSource,
|
||||
densityOptions,
|
||||
reload,
|
||||
densitySelect,
|
||||
@@ -287,6 +302,8 @@
|
||||
updatePageSize,
|
||||
pagination,
|
||||
tableAction,
|
||||
setStriped,
|
||||
isStriped,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
<div class="tableAction">
|
||||
<div class="flex items-center justify-center">
|
||||
<template v-for="(action, index) in getActions" :key="`${index}-${action.label}`">
|
||||
<n-button v-bind="action" class="mx-2">{{ action.label }}</n-button>
|
||||
<n-button v-bind="action" class="mx-1">
|
||||
{{ action.label }}
|
||||
<template #icon v-if="action.hasOwnProperty('icon')">
|
||||
<n-icon :component="action.icon" />
|
||||
</template>
|
||||
</n-button>
|
||||
</template>
|
||||
<n-dropdown
|
||||
v-if="dropDownActions && getDropdownList.length"
|
||||
@@ -11,7 +16,7 @@
|
||||
@select="select"
|
||||
>
|
||||
<slot name="more"></slot>
|
||||
<n-button v-bind="getMoreProps" class="mx-2" v-if="!$slots.more" icon-placement="right">
|
||||
<n-button v-bind="getMoreProps" class="mx-1" v-if="!$slots.more" icon-placement="right">
|
||||
<div class="flex items-center">
|
||||
<span>更多</span>
|
||||
<n-icon size="14" class="ml-1">
|
||||
@@ -75,7 +80,7 @@
|
||||
const getDropdownList = computed(() => {
|
||||
return (toRaw(props.dropDownActions) || [])
|
||||
.filter((action) => {
|
||||
return hasPermission(action.auth) && isIfShow(action);
|
||||
return hasPermission(action.auth as string[]) && isIfShow(action);
|
||||
})
|
||||
.map((action) => {
|
||||
const { popConfirm } = action;
|
||||
@@ -108,7 +113,7 @@
|
||||
const getActions = computed(() => {
|
||||
return (toRaw(props.actions) || [])
|
||||
.filter((action) => {
|
||||
return hasPermission(action.auth) && isIfShow(action);
|
||||
return hasPermission(action.auth as string[]) && isIfShow(action);
|
||||
})
|
||||
.map((action) => {
|
||||
const { popConfirm } = action;
|
||||
|
||||
@@ -7,23 +7,24 @@
|
||||
</n-icon>
|
||||
</div>
|
||||
<div class="flex editable-cell-content" v-show="isEdit" v-click-outside="onClickOutside">
|
||||
<CellComponent
|
||||
v-bind="getComponentProps"
|
||||
:component="getComponent"
|
||||
:style="getWrapperStyle"
|
||||
:popoverVisible="getRuleVisible"
|
||||
:ruleMessage="ruleMessage"
|
||||
:rule="getRule"
|
||||
:class="getWrapperClass"
|
||||
ref="elRef"
|
||||
@options-change="handleOptionsChange"
|
||||
@pressEnter="handleEnter"
|
||||
/>
|
||||
<div class="editable-cell-content-comp">
|
||||
<CellComponent
|
||||
v-bind="getComponentProps"
|
||||
:component="getComponent"
|
||||
:popoverVisible="getRuleVisible"
|
||||
:ruleMessage="ruleMessage"
|
||||
:rule="getRule"
|
||||
:class="getWrapperClass"
|
||||
ref="elRef"
|
||||
@options-change="handleOptionsChange"
|
||||
@press-enter="handleEnter"
|
||||
/>
|
||||
</div>
|
||||
<div class="editable-cell-action" v-if="!getRowEditable">
|
||||
<n-icon class="cursor-pointer mx-2">
|
||||
<n-icon class="mx-2 cursor-pointer">
|
||||
<CheckOutlined @click="handleSubmit" />
|
||||
</n-icon>
|
||||
<n-icon class="cursor-pointer mx-2">
|
||||
<n-icon class="mx-2 cursor-pointer">
|
||||
<CloseOutlined @click="handleCancel" />
|
||||
</n-icon>
|
||||
</div>
|
||||
@@ -31,7 +32,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import type { CSSProperties, PropType } from 'vue';
|
||||
import type { PropType } from 'vue';
|
||||
import type { BasicColumn } from '../../types/table';
|
||||
import type { EditRecordRow } from './index';
|
||||
|
||||
@@ -49,7 +50,7 @@
|
||||
import { set, omit } from 'lodash-es';
|
||||
import { EventEnum } from '@/components/Table/src/componentMap';
|
||||
|
||||
import { milliseconds } from 'date-fns';
|
||||
import { parseISO, format } from 'date-fns';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'EditableCell',
|
||||
@@ -92,7 +93,7 @@
|
||||
|
||||
const getIsCheckComp = computed(() => {
|
||||
const component = unref(getComponent);
|
||||
return ['NCheckbox', 'NSwitch'].includes(component);
|
||||
return ['NCheckbox', 'NRadio'].includes(component);
|
||||
});
|
||||
|
||||
const getComponentProps = computed(() => {
|
||||
@@ -103,16 +104,28 @@
|
||||
|
||||
const isCheckValue = unref(getIsCheckComp);
|
||||
|
||||
const valueField = isCheckValue ? 'checked' : 'value';
|
||||
let valueField = isCheckValue ? 'checked' : 'value';
|
||||
const val = unref(currentValueRef);
|
||||
|
||||
let value = isCheckValue ? (isNumber(val) && isBoolean(val) ? val : !!val) : val;
|
||||
|
||||
if (isString(value) && component === 'NDatePicker') {
|
||||
value = milliseconds(value as Duration);
|
||||
} else if (isArray(value) && component === 'NDatePicker') {
|
||||
value = value.map((item) => milliseconds(item));
|
||||
//TODO 特殊处理 NDatePicker 可能要根据项目 规范自行调整代码
|
||||
if (component === 'NDatePicker') {
|
||||
if (isString(value)) {
|
||||
if (compProps.valueFormat) {
|
||||
valueField = 'formatted-value';
|
||||
} else {
|
||||
value = parseISO(value as any).getTime();
|
||||
}
|
||||
} else if (isArray(value)) {
|
||||
if (compProps.valueFormat) {
|
||||
valueField = 'formatted-value';
|
||||
} else {
|
||||
value = value.map((item) => parseISO(item).getTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const onEvent: any = editComponent ? EventEnum[editComponent] : undefined;
|
||||
|
||||
return {
|
||||
@@ -144,15 +157,6 @@
|
||||
return option?.label ?? value;
|
||||
});
|
||||
|
||||
const getWrapperStyle = computed((): CSSProperties => {
|
||||
// if (unref(getIsCheckComp) || unref(getRowEditable)) {
|
||||
// return {};
|
||||
// }
|
||||
return {
|
||||
width: 'calc(100% - 48px)',
|
||||
};
|
||||
});
|
||||
|
||||
const getWrapperClass = computed(() => {
|
||||
const { align = 'center' } = props.column;
|
||||
return `edit-cell-align-${align}`;
|
||||
@@ -186,6 +190,7 @@
|
||||
|
||||
async function handleChange(e: any) {
|
||||
const component = unref(getComponent);
|
||||
const compProps = props.column?.editComponentProps ?? {};
|
||||
if (!e) {
|
||||
currentValueRef.value = e;
|
||||
} else if (e?.target && Reflect.has(e.target, 'value')) {
|
||||
@@ -196,13 +201,20 @@
|
||||
currentValueRef.value = e;
|
||||
}
|
||||
|
||||
//TODO 这里组件参数格式,和dayjs格式不一致
|
||||
// if (component === 'NDatePicker') {
|
||||
// let format = (props.column.editComponentProps?.format)
|
||||
// .replace(/yyyy/g, 'YYYY')
|
||||
// .replace(/dd/g, 'DD');
|
||||
// currentValueRef.value = dayjs(currentValueRef.value).format(format);
|
||||
// }
|
||||
//TODO 特殊处理 NDatePicker 可能要根据项目 规范自行调整代码
|
||||
if (component === 'NDatePicker') {
|
||||
if (isNumber(currentValueRef.value)) {
|
||||
if (compProps.valueFormat) {
|
||||
currentValueRef.value = format(currentValueRef.value, compProps.valueFormat);
|
||||
}
|
||||
} else if (isArray(currentValueRef.value)) {
|
||||
if (compProps.valueFormat) {
|
||||
currentValueRef.value = currentValueRef.value.map((item) => {
|
||||
format(item, compProps.valueFormat);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const onChange = props.column?.editComponentProps?.onChange;
|
||||
if (onChange && isFunction(onChange)) onChange(...arguments);
|
||||
@@ -304,100 +316,103 @@
|
||||
function initCbs(cbs: 'submitCbs' | 'validCbs' | 'cancelCbs', handle: Fn) {
|
||||
if (props.record) {
|
||||
/* eslint-disable */
|
||||
isArray(props.record[cbs])
|
||||
? props.record[cbs]?.push(handle)
|
||||
: (props.record[cbs] = [handle]);
|
||||
}
|
||||
}
|
||||
|
||||
if (props.record) {
|
||||
initCbs('submitCbs', handleSubmit);
|
||||
initCbs('validCbs', handleSubmiRule);
|
||||
initCbs('cancelCbs', handleCancel);
|
||||
|
||||
if (props.column.key) {
|
||||
if (!props.record.editValueRefs) props.record.editValueRefs = {};
|
||||
props.record.editValueRefs[props.column.key] = currentValueRef;
|
||||
}
|
||||
/* eslint-disable */
|
||||
props.record.onCancelEdit = () => {
|
||||
isArray(props.record?.cancelCbs) && props.record?.cancelCbs.forEach((fn) => fn());
|
||||
};
|
||||
/* eslint-disable */
|
||||
props.record.onSubmitEdit = async() => {
|
||||
if (isArray(props.record?.submitCbs)) {
|
||||
const validFns = (props.record?.validCbs || []).map((fn) => fn());
|
||||
|
||||
const res = await Promise.all(validFns);
|
||||
|
||||
const pass = res.every((item) => !!item);
|
||||
|
||||
if (!pass) return;
|
||||
const submitFns = props.record?.submitCbs || [];
|
||||
submitFns.forEach((fn) => fn(false, false));
|
||||
table.emit?.('edit-row-end');
|
||||
return true;
|
||||
isArray(props.record[cbs])
|
||||
? props.record[cbs]?.push(handle)
|
||||
: (props.record[cbs] = [handle]);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
isEdit,
|
||||
handleEdit,
|
||||
currentValueRef,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
handleCancel,
|
||||
elRef,
|
||||
getComponent,
|
||||
getRule,
|
||||
onClickOutside,
|
||||
ruleMessage,
|
||||
getRuleVisible,
|
||||
getComponentProps,
|
||||
handleOptionsChange,
|
||||
getWrapperStyle,
|
||||
getWrapperClass,
|
||||
getRowEditable,
|
||||
getValues,
|
||||
handleEnter,
|
||||
// getSize,
|
||||
};
|
||||
},
|
||||
if (props.record) {
|
||||
initCbs('submitCbs', handleSubmit);
|
||||
initCbs('validCbs', handleSubmiRule);
|
||||
initCbs('cancelCbs', handleCancel);
|
||||
|
||||
if (props.column.key) {
|
||||
if (!props.record.editValueRefs) props.record.editValueRefs = {};
|
||||
props.record.editValueRefs[props.column.key] = currentValueRef;
|
||||
}
|
||||
/* eslint-disable */
|
||||
props.record.onCancelEdit = () => {
|
||||
isArray(props.record?.cancelCbs) && props.record?.cancelCbs.forEach((fn) => fn());
|
||||
};
|
||||
/* eslint-disable */
|
||||
props.record.onSubmitEdit = async () => {
|
||||
if (isArray(props.record?.submitCbs)) {
|
||||
const validFns = (props.record?.validCbs || []).map((fn) => fn());
|
||||
|
||||
const res = await Promise.all(validFns);
|
||||
|
||||
const pass = res.every((item) => !!item);
|
||||
|
||||
if (!pass) return;
|
||||
const submitFns = props.record?.submitCbs || [];
|
||||
submitFns.forEach((fn) => fn(false, false));
|
||||
table.emit?.('edit-row-end');
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
isEdit,
|
||||
handleEdit,
|
||||
currentValueRef,
|
||||
handleSubmit,
|
||||
handleChange,
|
||||
handleCancel,
|
||||
elRef,
|
||||
getComponent,
|
||||
getRule,
|
||||
onClickOutside,
|
||||
ruleMessage,
|
||||
getRuleVisible,
|
||||
getComponentProps,
|
||||
handleOptionsChange,
|
||||
getWrapperClass,
|
||||
getRowEditable,
|
||||
getValues,
|
||||
handleEnter,
|
||||
// getSize,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.editable-cell {
|
||||
&-content {
|
||||
position: relative;
|
||||
overflow-wrap: break-word;
|
||||
word-break: break-word;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
.editable-cell {
|
||||
&-content {
|
||||
position: relative;
|
||||
overflow-wrap: break-word;
|
||||
word-break: break-word;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
.edit-icon {
|
||||
font-size: 14px;
|
||||
//position: absolute;
|
||||
//top: 4px;
|
||||
//right: 0;
|
||||
display: none;
|
||||
width: 20px;
|
||||
cursor: pointer;
|
||||
&-comp {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.edit-icon {
|
||||
font-size: 14px;
|
||||
//position: absolute;
|
||||
//top: 4px;
|
||||
//right: 0;
|
||||
display: none;
|
||||
width: 20px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
.edit-icon {
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&-action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
&:hover {
|
||||
.edit-icon {
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&-action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -25,13 +25,26 @@
|
||||
</template>
|
||||
<div class="table-toolbar-inner">
|
||||
<n-checkbox-group v-model:value="checkList" @update:value="onChange">
|
||||
<Draggable v-model="columnsList" animation="300" item-key="key" @end="draggableEnd">
|
||||
<Draggable
|
||||
v-model="columnsList"
|
||||
animation="300"
|
||||
item-key="key"
|
||||
filter=".no-draggable"
|
||||
:move="onMove"
|
||||
@end="draggableEnd"
|
||||
>
|
||||
<template #item="{ element }">
|
||||
<div
|
||||
class="table-toolbar-inner-checkbox"
|
||||
:class="{ 'table-toolbar-inner-checkbox-dark': getDarkTheme === true }"
|
||||
:class="{
|
||||
'table-toolbar-inner-checkbox-dark': getDarkTheme === true,
|
||||
'no-draggable': element.draggable === false,
|
||||
}"
|
||||
>
|
||||
<span class="drag-icon">
|
||||
<span
|
||||
class="drag-icon"
|
||||
:class="{ 'drag-icon-hidden': element.draggable === false }"
|
||||
>
|
||||
<n-icon size="18">
|
||||
<DragOutlined />
|
||||
</n-icon>
|
||||
@@ -88,8 +101,7 @@
|
||||
VerticalRightOutlined,
|
||||
VerticalLeftOutlined,
|
||||
} from '@vicons/antd';
|
||||
// @ts-ignore
|
||||
import Draggable from 'vuedraggable/src/vuedraggable';
|
||||
import Draggable from 'vuedraggable';
|
||||
import { useDesignSetting } from '@/hooks/setting/useDesignSetting';
|
||||
|
||||
interface Options {
|
||||
@@ -212,6 +224,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function onMove(e) {
|
||||
if (e.draggedContext.element.draggable === false) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
//固定
|
||||
function fixedColumn(item, fixed) {
|
||||
if (!state.checkList.includes(item.key)) return;
|
||||
@@ -233,6 +250,7 @@
|
||||
onChange,
|
||||
onCheckAll,
|
||||
onSelection,
|
||||
onMove,
|
||||
resetColumns,
|
||||
fixedColumn,
|
||||
draggableEnd,
|
||||
@@ -276,6 +294,10 @@
|
||||
display: inline-flex;
|
||||
margin-right: 8px;
|
||||
cursor: move;
|
||||
&-hidden {
|
||||
visibility: hidden;
|
||||
cursor: default;
|
||||
}
|
||||
}
|
||||
|
||||
.fixed-item {
|
||||
|
||||
@@ -48,8 +48,7 @@ export function useColumns(propsRef: ComputedRef<BasicTableProps>) {
|
||||
const columns = cloneDeep(pageColumns);
|
||||
return columns
|
||||
.filter((column) => {
|
||||
// @ts-ignore
|
||||
return hasPermission(column.auth) && isIfShow(column);
|
||||
return hasPermission(column.auth as string[]) && isIfShow(column);
|
||||
})
|
||||
.map((column) => {
|
||||
//默认 ellipsis 为true
|
||||
@@ -93,10 +92,10 @@ export function useColumns(propsRef: ComputedRef<BasicTableProps>) {
|
||||
function handleActionColumn(propsRef: ComputedRef<BasicTableProps>, columns: BasicColumn[]) {
|
||||
const { actionColumn } = unref(propsRef);
|
||||
if (!actionColumn) return;
|
||||
// @ts-ignore
|
||||
!columns.find((col) => col.key === 'action') && columns.push({
|
||||
...actionColumn,
|
||||
});
|
||||
!columns.find((col) => col.key === 'action') &&
|
||||
columns.push({
|
||||
...(actionColumn as any),
|
||||
});
|
||||
}
|
||||
|
||||
//设置
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ref, ComputedRef, unref, computed, onMounted, watchEffect, watch } from 'vue';
|
||||
import type { BasicTableProps } from '../types/table';
|
||||
import type { PaginationProps } from '../types/pagination';
|
||||
import { isBoolean } from '@/utils/is';
|
||||
import { isBoolean, isFunction, isArray } from '@/utils/is';
|
||||
import { APISETTING } from '../const';
|
||||
|
||||
export function useDataSource(
|
||||
@@ -9,7 +9,7 @@ export function useDataSource(
|
||||
{ getPaginationInfo, setPagination, setLoading, tableData },
|
||||
emit
|
||||
) {
|
||||
const dataSourceRef = ref([]);
|
||||
const dataSourceRef = ref<Recordable[]>([]);
|
||||
|
||||
watchEffect(() => {
|
||||
tableData.value = unref(dataSourceRef);
|
||||
@@ -46,13 +46,14 @@ export function useDataSource(
|
||||
async function fetch(opt?) {
|
||||
try {
|
||||
setLoading(true);
|
||||
const { request, pagination }: any = unref(propsRef);
|
||||
const { request, pagination, beforeRequest, afterRequest }: any = unref(propsRef);
|
||||
if (!request) return;
|
||||
//组装分页信息
|
||||
const pageField = APISETTING.pageField;
|
||||
const sizeField = APISETTING.sizeField;
|
||||
const totalField = APISETTING.totalField;
|
||||
const listField = APISETTING.listField;
|
||||
|
||||
const itemCount = APISETTING.countField;
|
||||
let pageParams = {};
|
||||
const { page = 1, pageSize = 10 } = unref(getPaginationInfo) as PaginationProps;
|
||||
|
||||
@@ -63,32 +64,45 @@ export function useDataSource(
|
||||
pageParams[sizeField] = pageSize;
|
||||
}
|
||||
|
||||
const params = {
|
||||
let params = {
|
||||
...pageParams,
|
||||
...opt,
|
||||
};
|
||||
if (beforeRequest && isFunction(beforeRequest)) {
|
||||
// The params parameter can be modified by outsiders
|
||||
params = (await beforeRequest(params)) || params;
|
||||
}
|
||||
const res = await request(params);
|
||||
|
||||
const resultTotal = res[totalField] || 0;
|
||||
const resultTotal = res[totalField];
|
||||
const currentPage = res[pageField];
|
||||
const total = res[itemCount];
|
||||
const results = res[listField] ? res[listField] : [];
|
||||
|
||||
// 如果数据异常,需获取正确的页码再次执行
|
||||
if (resultTotal) {
|
||||
if (page > resultTotal) {
|
||||
const currentTotalPage = Math.ceil(total / pageSize);
|
||||
if (page > currentTotalPage) {
|
||||
setPagination({
|
||||
[pageField]: resultTotal,
|
||||
page: currentTotalPage,
|
||||
itemCount: total,
|
||||
});
|
||||
fetch(opt);
|
||||
return await fetch(opt);
|
||||
}
|
||||
}
|
||||
const resultInfo = res[listField] ? res[listField] : [];
|
||||
let resultInfo = res[listField] ? res[listField] : [];
|
||||
if (afterRequest && isFunction(afterRequest)) {
|
||||
// can modify the data returned by the interface for processing
|
||||
resultInfo = (await afterRequest(resultInfo)) || resultInfo;
|
||||
}
|
||||
dataSourceRef.value = resultInfo;
|
||||
setPagination({
|
||||
[pageField]: currentPage,
|
||||
[totalField]: resultTotal,
|
||||
page: currentPage,
|
||||
pageCount: resultTotal,
|
||||
itemCount: total,
|
||||
});
|
||||
if (opt && opt[pageField]) {
|
||||
setPagination({
|
||||
[pageField]: opt[pageField] || 1,
|
||||
page: opt[pageField] || 1,
|
||||
});
|
||||
}
|
||||
emit('fetch-success', {
|
||||
@@ -99,9 +113,9 @@ export function useDataSource(
|
||||
console.error(error);
|
||||
emit('fetch-error', error);
|
||||
dataSourceRef.value = [];
|
||||
// setPagination({
|
||||
// pageCount: 0,
|
||||
// });
|
||||
setPagination({
|
||||
pageCount: 0,
|
||||
});
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { PaginationProps } from '../types/pagination';
|
||||
import type { BasicTableProps } from '../types/table';
|
||||
import { computed, unref, ref, ComputedRef } from 'vue';
|
||||
import { computed, unref, ref, ComputedRef, watch } from 'vue';
|
||||
|
||||
import { isBoolean } from '@/utils/is';
|
||||
import { DEFAULTPAGESIZE, PAGESIZES } from '../const';
|
||||
@@ -9,16 +9,30 @@ export function usePagination(refProps: ComputedRef<BasicTableProps>) {
|
||||
const configRef = ref<PaginationProps>({});
|
||||
const show = ref(true);
|
||||
|
||||
watch(
|
||||
() => unref(refProps).pagination,
|
||||
(pagination) => {
|
||||
if (!isBoolean(pagination) && pagination) {
|
||||
configRef.value = {
|
||||
...unref(configRef),
|
||||
...(pagination ?? {}),
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const getPaginationInfo = computed((): PaginationProps | boolean => {
|
||||
const { pagination } = unref(refProps);
|
||||
if (!unref(show) || (isBoolean(pagination) && !pagination)) {
|
||||
return false;
|
||||
}
|
||||
return {
|
||||
pageSize: DEFAULTPAGESIZE,
|
||||
pageSizes: PAGESIZES,
|
||||
page: 1, //当前页
|
||||
pageSize: DEFAULTPAGESIZE, //分页大小
|
||||
pageSizes: PAGESIZES, // 每页条数
|
||||
showSizePicker: true,
|
||||
showQuickJumper: true,
|
||||
prefix: (pagingInfo) => `共 ${pagingInfo.itemCount} 条`, // 不需要可以通过 pagination 重置或者删除
|
||||
...(isBoolean(pagination) ? {} : pagination),
|
||||
...unref(configRef),
|
||||
};
|
||||
|
||||
@@ -16,7 +16,7 @@ export const basicProps = {
|
||||
type: String,
|
||||
default: 'medium',
|
||||
},
|
||||
tableData: {
|
||||
dataSource: {
|
||||
type: [Object],
|
||||
default: () => [],
|
||||
},
|
||||
@@ -25,10 +25,17 @@ export const basicProps = {
|
||||
default: () => [],
|
||||
required: true,
|
||||
},
|
||||
beforeRequest: {
|
||||
type: Function as PropType<(...arg: any[]) => void | Promise<any>>,
|
||||
default: null,
|
||||
},
|
||||
request: {
|
||||
type: Function as PropType<(...arg: any[]) => Promise<any>>,
|
||||
default: null,
|
||||
required: true,
|
||||
},
|
||||
afterRequest: {
|
||||
type: Function as PropType<(...arg: any[]) => void | Promise<any>>,
|
||||
default: null,
|
||||
},
|
||||
rowKey: {
|
||||
type: [String, Function] as PropType<string | ((record) => string)>,
|
||||
|
||||
@@ -5,4 +5,5 @@ export type ComponentType =
|
||||
| 'NCheckbox'
|
||||
| 'NSwitch'
|
||||
| 'NDatePicker'
|
||||
| 'NTimePicker';
|
||||
| 'NTimePicker'
|
||||
| 'NCascader';
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
export interface PaginationProps {
|
||||
page?: number;
|
||||
pageCount?: number;
|
||||
pageSize?: number;
|
||||
pageSizes?: number[];
|
||||
showSizePicker?: boolean;
|
||||
showQuickJumper?: boolean;
|
||||
page?: number; //受控模式下的当前页
|
||||
itemCount?: number; //总条数
|
||||
pageCount?: number; //总页数
|
||||
pageSize?: number; //受控模式下的分页大小
|
||||
pageSizes?: number[]; //每页条数, 可自定义
|
||||
showSizePicker?: boolean; //是否显示每页条数的选择器
|
||||
showQuickJumper?: boolean; //是否显示快速跳转
|
||||
prefix?: any; //分页前缀
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { TableBaseColumn } from 'naive-ui/lib/data-table/src/interface';
|
||||
import type { InternalRowData, TableBaseColumn } from 'naive-ui/lib/data-table/src/interface';
|
||||
import { ComponentType } from './componentType';
|
||||
export interface BasicColumn extends TableBaseColumn {
|
||||
export interface BasicColumn<T = InternalRowData> extends TableBaseColumn<T> {
|
||||
//编辑表格
|
||||
edit?: boolean;
|
||||
editRow?: boolean;
|
||||
@@ -14,6 +14,8 @@ export interface BasicColumn extends TableBaseColumn {
|
||||
auth?: string[];
|
||||
// 业务控制是否显示
|
||||
ifShow?: boolean | ((column: BasicColumn) => boolean);
|
||||
// 控制是否支持拖拽,默认支持
|
||||
draggable?: boolean;
|
||||
}
|
||||
|
||||
export interface TableActionType {
|
||||
@@ -32,4 +34,5 @@ export interface BasicTableProps {
|
||||
actionColumn: any[];
|
||||
canResize: boolean;
|
||||
resizeHeightOffset: number;
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
// @ts-ignore
|
||||
import { NButton } from 'naive-ui';
|
||||
import type { Component } from 'vue';
|
||||
import { PermissionsEnum } from '@/enums/permissionsEnum';
|
||||
// @ts-ignore
|
||||
export interface ActionItem extends NButton.props {
|
||||
export interface ActionItem extends Partial<InstanceType<typeof NButton>> {
|
||||
onClick?: Fn;
|
||||
label?: string;
|
||||
color?: 'success' | 'error' | 'warning';
|
||||
icon?: string;
|
||||
type?: 'success' | 'error' | 'warning' | 'info' | 'primary' | 'default';
|
||||
// 设定 color 后会覆盖 type 的样式
|
||||
color?: string;
|
||||
icon?: Component;
|
||||
popConfirm?: PopConfirm;
|
||||
disabled?: boolean;
|
||||
divider?: boolean;
|
||||
@@ -22,5 +23,5 @@ export interface PopConfirm {
|
||||
cancelText?: string;
|
||||
confirm: Fn;
|
||||
cancel?: Fn;
|
||||
icon?: string;
|
||||
icon?: Component;
|
||||
}
|
||||
|
||||
@@ -14,10 +14,10 @@
|
||||
<img :src="item" />
|
||||
</div>
|
||||
<div class="img-box-actions">
|
||||
<n-icon size="18" class="action-icon mx-2" @click="preview(item)">
|
||||
<n-icon size="18" class="mx-2 action-icon" @click="preview(item)">
|
||||
<EyeOutlined />
|
||||
</n-icon>
|
||||
<n-icon size="18" class="action-icon mx-2" @click="remove(index)">
|
||||
<n-icon size="18" class="mx-2 action-icon" @click="remove(index)">
|
||||
<DeleteOutlined />
|
||||
</n-icon>
|
||||
</div>
|
||||
@@ -31,12 +31,13 @@
|
||||
v-if="imgList.length < maxNumber"
|
||||
>
|
||||
<n-upload
|
||||
class="w-auto"
|
||||
v-bind="$props"
|
||||
:file-list-style="{ display: 'none' }"
|
||||
@before-upload="beforeUpload"
|
||||
@finish="finish"
|
||||
>
|
||||
<div class="flex justify-center flex-col">
|
||||
<div class="flex flex-col justify-center">
|
||||
<n-icon size="18" class="m-auto">
|
||||
<PlusOutlined />
|
||||
</n-icon>
|
||||
@@ -68,7 +69,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, toRefs, reactive, computed } from 'vue';
|
||||
import { defineComponent, toRefs, reactive, computed, watch } from 'vue';
|
||||
import { EyeOutlined, DeleteOutlined, PlusOutlined } from '@vicons/antd';
|
||||
import { basicProps } from './props';
|
||||
import { useMessage, useDialog } from 'naive-ui';
|
||||
@@ -106,11 +107,15 @@
|
||||
});
|
||||
|
||||
//赋值默认图片显示
|
||||
if (props.value.length) {
|
||||
state.imgList = props.value.map((item) => {
|
||||
return getImgUrl(item);
|
||||
});
|
||||
}
|
||||
watch(
|
||||
() => props.value,
|
||||
() => {
|
||||
state.imgList = props.value.map((item) => {
|
||||
return getImgUrl(item);
|
||||
});
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
//预览
|
||||
function preview(url: string) {
|
||||
@@ -233,6 +238,7 @@
|
||||
&-info {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
|
||||
|
||||
9
src/config/website.config.ts
Normal file
9
src/config/website.config.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import logoImage from '@/assets/images/logo.png';
|
||||
import loginImage from '@/assets/images/account-logo.png';
|
||||
|
||||
export const websiteConfig = Object.freeze({
|
||||
title: 'NaiveUiAdmin',
|
||||
logo: logoImage,
|
||||
loginImage: loginImage,
|
||||
loginDesc: 'Naive Ui Admin中后台前端/设计解决方案',
|
||||
});
|
||||
34
src/directives/copy.ts
Normal file
34
src/directives/copy.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* v-copy
|
||||
* 复制某个值至剪贴板
|
||||
* 接收参数:string类型/Ref<string>类型/Reactive<string>类型
|
||||
*/
|
||||
import type { Directive, DirectiveBinding } from 'vue';
|
||||
|
||||
interface ElType extends HTMLElement {
|
||||
copyData: string | number;
|
||||
__handleClick__: any;
|
||||
}
|
||||
const copy: Directive = {
|
||||
mounted(el: ElType, binding: DirectiveBinding) {
|
||||
el.copyData = binding.value;
|
||||
el.addEventListener('click', handleClick);
|
||||
},
|
||||
updated(el: ElType, binding: DirectiveBinding) {
|
||||
el.copyData = binding.value;
|
||||
},
|
||||
beforeUnmount(el: ElType) {
|
||||
el.removeEventListener('click', el.__handleClick__);
|
||||
},
|
||||
};
|
||||
function handleClick(this: any) {
|
||||
const input = document.createElement('input');
|
||||
input.value = this.copyData.toLocaleString();
|
||||
document.body.appendChild(input);
|
||||
input.select();
|
||||
document.execCommand('Copy');
|
||||
document.body.removeChild(input);
|
||||
console.log('复制成功', this.copyData);
|
||||
}
|
||||
|
||||
export default copy;
|
||||
31
src/directives/debounce.ts
Normal file
31
src/directives/debounce.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* v-debounce
|
||||
* 按钮防抖指令,可自行扩展至input
|
||||
* 接收参数:function类型
|
||||
*/
|
||||
import type { Directive, DirectiveBinding } from 'vue';
|
||||
interface ElType extends HTMLElement {
|
||||
__handleClick__: () => any;
|
||||
}
|
||||
const debounce: Directive = {
|
||||
mounted(el: ElType, binding: DirectiveBinding) {
|
||||
if (typeof binding.value !== 'function') {
|
||||
throw 'callback must be a function';
|
||||
}
|
||||
let timer: NodeJS.Timeout | null = null;
|
||||
el.__handleClick__ = function () {
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
binding.value();
|
||||
}, 500);
|
||||
};
|
||||
el.addEventListener('click', el.__handleClick__);
|
||||
},
|
||||
beforeUnmount(el: ElType) {
|
||||
el.removeEventListener('click', el.__handleClick__);
|
||||
},
|
||||
};
|
||||
|
||||
export default debounce;
|
||||
49
src/directives/draggable.ts
Normal file
49
src/directives/draggable.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
需求:实现一个拖拽指令,可在父元素区域任意拖拽元素。
|
||||
|
||||
思路:
|
||||
1、设置需要拖拽的元素为absolute,其父元素为relative。
|
||||
2、鼠标按下(onmousedown)时记录目标元素当前的 left 和 top 值。
|
||||
3、鼠标移动(onmousemove)时计算每次移动的横向距离和纵向距离的变化值,并改变元素的 left 和 top 值
|
||||
4、鼠标松开(onmouseup)时完成一次拖拽
|
||||
|
||||
使用:在 Dom 上加上 v-draggable 即可
|
||||
<div class="dialog-model" v-draggable></div>
|
||||
*/
|
||||
import type { Directive } from 'vue';
|
||||
interface ElType extends HTMLElement {
|
||||
parentNode: any;
|
||||
}
|
||||
const draggable: Directive = {
|
||||
mounted: function (el: ElType) {
|
||||
el.style.cursor = 'move';
|
||||
el.style.position = 'absolute';
|
||||
el.onmousedown = function (e) {
|
||||
const disX = e.pageX - el.offsetLeft;
|
||||
const disY = e.pageY - el.offsetTop;
|
||||
document.onmousemove = function (e) {
|
||||
let x = e.pageX - disX;
|
||||
let y = e.pageY - disY;
|
||||
const maxX = el.parentNode.offsetWidth - el.offsetWidth;
|
||||
const maxY = el.parentNode.offsetHeight - el.offsetHeight;
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
} else if (x > maxX) {
|
||||
x = maxX;
|
||||
}
|
||||
|
||||
if (y < 0) {
|
||||
y = 0;
|
||||
} else if (y > maxY) {
|
||||
y = maxY;
|
||||
}
|
||||
el.style.left = x + 'px';
|
||||
el.style.top = y + 'px';
|
||||
};
|
||||
document.onmouseup = function () {
|
||||
document.onmousemove = document.onmouseup = null;
|
||||
};
|
||||
};
|
||||
},
|
||||
};
|
||||
export default draggable;
|
||||
49
src/directives/longpress.ts
Normal file
49
src/directives/longpress.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* v-longpress
|
||||
* 长按指令,长按时触发事件
|
||||
*/
|
||||
import type { Directive, DirectiveBinding } from 'vue';
|
||||
|
||||
const directive: Directive = {
|
||||
mounted(el: HTMLElement, binding: DirectiveBinding) {
|
||||
if (typeof binding.value !== 'function') {
|
||||
throw 'callback must be a function';
|
||||
}
|
||||
// 定义变量
|
||||
let pressTimer: any = null;
|
||||
// 创建计时器( 2秒后执行函数 )
|
||||
const start = (e: any) => {
|
||||
if (e.button) {
|
||||
if (e.type === 'click' && e.button !== 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (pressTimer === null) {
|
||||
pressTimer = setTimeout(() => {
|
||||
handler(e);
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
// 取消计时器
|
||||
const cancel = () => {
|
||||
if (pressTimer !== null) {
|
||||
clearTimeout(pressTimer);
|
||||
pressTimer = null;
|
||||
}
|
||||
};
|
||||
// 运行函数
|
||||
const handler = (e: MouseEvent | TouchEvent) => {
|
||||
binding.value(e);
|
||||
};
|
||||
// 添加事件监听器
|
||||
el.addEventListener('mousedown', start);
|
||||
el.addEventListener('touchstart', start);
|
||||
// 取消计时器
|
||||
el.addEventListener('click', cancel);
|
||||
el.addEventListener('mouseout', cancel);
|
||||
el.addEventListener('touchend', cancel);
|
||||
el.addEventListener('touchcancel', cancel);
|
||||
},
|
||||
};
|
||||
|
||||
export default directive;
|
||||
41
src/directives/throttle.ts
Normal file
41
src/directives/throttle.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
需求:防止按钮在短时间内被多次点击,使用节流函数限制规定时间内只能点击一次。
|
||||
|
||||
思路:
|
||||
1、第一次点击,立即调用方法并禁用按钮,等延迟结束再次激活按钮
|
||||
2、将需要触发的方法绑定在指令上
|
||||
|
||||
使用:给 Dom 加上 v-throttle 及回调函数即可
|
||||
<button v-throttle="debounceClick">节流提交</button>
|
||||
*/
|
||||
import type { Directive, DirectiveBinding } from 'vue';
|
||||
interface ElType extends HTMLElement {
|
||||
__handleClick__: () => any;
|
||||
disabled: boolean;
|
||||
}
|
||||
const throttle: Directive = {
|
||||
mounted(el: ElType, binding: DirectiveBinding) {
|
||||
if (typeof binding.value !== 'function') {
|
||||
throw 'callback must be a function';
|
||||
}
|
||||
let timer: NodeJS.Timeout | null = null;
|
||||
el.__handleClick__ = function () {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
if (!el.disabled) {
|
||||
el.disabled = true;
|
||||
binding.value();
|
||||
timer = setTimeout(() => {
|
||||
el.disabled = false;
|
||||
}, 1000);
|
||||
}
|
||||
};
|
||||
el.addEventListener('click', el.__handleClick__);
|
||||
},
|
||||
beforeUnmount(el: ElType) {
|
||||
el.removeEventListener('click', el.__handleClick__);
|
||||
},
|
||||
};
|
||||
|
||||
export default throttle;
|
||||
4
src/enums/permissionsEnum.ts
Normal file
4
src/enums/permissionsEnum.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface PermissionsEnum {
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
import { useAsync } from './use-async';
|
||||
import { useAsync } from './useAsync';
|
||||
|
||||
export { useAsync };
|
||||
|
||||
@@ -4,30 +4,39 @@ import { useProjectSettingStore } from '@/store/modules/projectSetting';
|
||||
export function useProjectSetting() {
|
||||
const projectStore = useProjectSettingStore();
|
||||
|
||||
const getNavMode = computed(() => projectStore.navMode);
|
||||
const navMode = computed(() => projectStore.navMode);
|
||||
|
||||
const getNavTheme = computed(() => projectStore.navTheme);
|
||||
const navTheme = computed(() => projectStore.navTheme);
|
||||
|
||||
const getHeaderSetting = computed(() => projectStore.headerSetting);
|
||||
const isMobile = computed(() => projectStore.isMobile);
|
||||
|
||||
const getMultiTabsSetting = computed(() => projectStore.multiTabsSetting);
|
||||
const headerSetting = computed(() => projectStore.headerSetting);
|
||||
|
||||
const getMenuSetting = computed(() => projectStore.menuSetting);
|
||||
const multiTabsSetting = computed(() => projectStore.multiTabsSetting);
|
||||
|
||||
const getCrumbsSetting = computed(() => projectStore.crumbsSetting);
|
||||
const menuSetting = computed(() => projectStore.menuSetting);
|
||||
|
||||
const getPermissionMode = computed(() => projectStore.permissionMode);
|
||||
const crumbsSetting = computed(() => projectStore.crumbsSetting);
|
||||
|
||||
const getShowFooter = computed(() => projectStore.showFooter);
|
||||
const permissionMode = computed(() => projectStore.permissionMode);
|
||||
|
||||
const showFooter = computed(() => projectStore.showFooter);
|
||||
|
||||
const isPageAnimate = computed(() => projectStore.isPageAnimate);
|
||||
|
||||
const pageAnimateType = computed(() => projectStore.pageAnimateType);
|
||||
|
||||
return {
|
||||
getNavMode,
|
||||
getNavTheme,
|
||||
getHeaderSetting,
|
||||
getMultiTabsSetting,
|
||||
getMenuSetting,
|
||||
getCrumbsSetting,
|
||||
getPermissionMode,
|
||||
getShowFooter,
|
||||
navMode,
|
||||
navTheme,
|
||||
isMobile,
|
||||
headerSetting,
|
||||
multiTabsSetting,
|
||||
menuSetting,
|
||||
crumbsSetting,
|
||||
permissionMode,
|
||||
showFooter,
|
||||
isPageAnimate,
|
||||
pageAnimateType,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ref, onMounted, onUnmounted } from 'vue';
|
||||
import { debounce } from 'lodash';
|
||||
import { debounce } from 'lodash-es';
|
||||
|
||||
/**
|
||||
* description: 获取页面宽度
|
||||
|
||||
@@ -10,23 +10,27 @@ import { useBreakpoint } from '@/hooks/event/useBreakpoint';
|
||||
|
||||
import echarts from '@/utils/lib/echarts';
|
||||
|
||||
// import { useRootSetting } from '@/hooks/setting/useRootSetting';
|
||||
import { useDesignSetting } from '@/hooks/setting/useDesignSetting';
|
||||
|
||||
export function useECharts(
|
||||
elRef: Ref<HTMLDivElement>,
|
||||
theme: 'light' | 'dark' | 'default' = 'light'
|
||||
theme: 'light' | 'dark' | 'default' = 'default'
|
||||
) {
|
||||
// const { getDarkMode } = useRootSetting();
|
||||
const getDarkMode = 'light';
|
||||
const { getDarkTheme: getSysDarkTheme } = useDesignSetting();
|
||||
|
||||
const getDarkTheme = computed(() => {
|
||||
const sysTheme: string = getSysDarkTheme.value ? 'dark' : 'light';
|
||||
return theme === 'default' ? sysTheme : theme;
|
||||
});
|
||||
|
||||
let chartInstance: echarts.ECharts | null = null;
|
||||
let resizeFn: Fn = resize;
|
||||
const cacheOptions = ref<EChartsOption>({});
|
||||
const cacheOptions = ref({});
|
||||
let removeResizeFn: Fn = () => {};
|
||||
|
||||
resizeFn = useDebounceFn(resize, 200);
|
||||
|
||||
const getOptions = computed((): EChartsOption => {
|
||||
if (getDarkMode !== 'dark') {
|
||||
if (getDarkTheme.value !== 'dark') {
|
||||
return cacheOptions.value;
|
||||
}
|
||||
return {
|
||||
@@ -67,7 +71,7 @@ export function useECharts(
|
||||
nextTick(() => {
|
||||
useTimeoutFn(() => {
|
||||
if (!chartInstance) {
|
||||
initCharts(getDarkMode.value as 'default');
|
||||
initCharts(getDarkTheme.value as 'default');
|
||||
|
||||
if (!chartInstance) return;
|
||||
}
|
||||
@@ -83,7 +87,7 @@ export function useECharts(
|
||||
}
|
||||
|
||||
watch(
|
||||
() => getDarkMode.value,
|
||||
() => getDarkTheme.value,
|
||||
(theme) => {
|
||||
if (chartInstance) {
|
||||
chartInstance.dispose();
|
||||
@@ -93,18 +97,20 @@ export function useECharts(
|
||||
}
|
||||
);
|
||||
|
||||
tryOnUnmounted(() => {
|
||||
tryOnUnmounted(disposeInstance);
|
||||
|
||||
function getInstance(): echarts.ECharts | null {
|
||||
if (!chartInstance) {
|
||||
initCharts(getDarkTheme.value as 'default');
|
||||
}
|
||||
return chartInstance;
|
||||
}
|
||||
|
||||
function disposeInstance() {
|
||||
if (!chartInstance) return;
|
||||
removeResizeFn();
|
||||
chartInstance.dispose();
|
||||
chartInstance = null;
|
||||
});
|
||||
|
||||
function getInstance(): echarts.ECharts | null {
|
||||
if (!chartInstance) {
|
||||
initCharts(getDarkMode.value as 'default');
|
||||
}
|
||||
return chartInstance;
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -112,5 +118,6 @@ export function useECharts(
|
||||
resize,
|
||||
echarts,
|
||||
getInstance,
|
||||
disposeInstance,
|
||||
};
|
||||
}
|
||||
|
||||
62
src/hooks/web/usePage.ts
Normal file
62
src/hooks/web/usePage.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import type { RouteLocationRaw, Router } from 'vue-router';
|
||||
|
||||
import { PageEnum } from '@/enums/pageEnum';
|
||||
import { RedirectName } from '@/router/constant';
|
||||
|
||||
import { useRouter } from 'vue-router';
|
||||
import { isString } from '@/utils/is';
|
||||
import { unref } from 'vue';
|
||||
|
||||
export type RouteLocationRawEx = Omit<RouteLocationRaw, 'path'> & { path: PageEnum };
|
||||
|
||||
function handleError(e: Error) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* 页面切换
|
||||
*/
|
||||
export function useGo(_router?: Router) {
|
||||
let router;
|
||||
if (!_router) {
|
||||
router = useRouter();
|
||||
}
|
||||
const { push, replace } = _router || router;
|
||||
function go(opt: PageEnum | RouteLocationRawEx | string = PageEnum.BASE_HOME, isReplace = false) {
|
||||
if (!opt) {
|
||||
return;
|
||||
}
|
||||
if (isString(opt)) {
|
||||
isReplace ? replace(opt).catch(handleError) : push(opt).catch(handleError);
|
||||
} else {
|
||||
const o = opt as RouteLocationRaw;
|
||||
isReplace ? replace(o).catch(handleError) : push(o).catch(handleError);
|
||||
}
|
||||
}
|
||||
return go;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重做当前页面
|
||||
*/
|
||||
export const useRedo = (_router?: Router) => {
|
||||
const { push, currentRoute } = _router || useRouter();
|
||||
const { query, params = {}, name, fullPath } = unref(currentRoute.value);
|
||||
function redo(): Promise<boolean> {
|
||||
return new Promise((resolve) => {
|
||||
if (name === RedirectName) {
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
if (name && Object.keys(params).length > 0) {
|
||||
params['_redirect_type'] = 'name';
|
||||
params['path'] = String(name);
|
||||
} else {
|
||||
params['_redirect_type'] = 'path';
|
||||
params['path'] = fullPath;
|
||||
}
|
||||
push({ name: RedirectName, params, query }).then(() => resolve(true));
|
||||
});
|
||||
}
|
||||
return redo;
|
||||
};
|
||||
@@ -30,7 +30,7 @@ export function usePermission() {
|
||||
function hasEveryPermission(accesses: string[]): boolean {
|
||||
const permissionsList = userStore.getPermissions;
|
||||
if (Array.isArray(accesses)) {
|
||||
return accesses.every((access) => !!permissionsList[access]);
|
||||
return permissionsList.every((access: any) => accesses.includes(access.value));
|
||||
}
|
||||
throw new Error(`[hasEveryPermission]: ${accesses} should be a array !`);
|
||||
}
|
||||
@@ -43,7 +43,7 @@ export function usePermission() {
|
||||
function hasSomePermission(accesses: string[]): boolean {
|
||||
const permissionsList = userStore.getPermissions;
|
||||
if (Array.isArray(accesses)) {
|
||||
return accesses.some((access) => !!permissionsList[access]);
|
||||
return permissionsList.some((access: any) => accesses.includes(access.value));
|
||||
}
|
||||
throw new Error(`[hasSomePermission]: ${accesses} should be a array !`);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<template>
|
||||
<n-drawer v-model:show="isDrawer" :width="width" :placement="placement" :native-scrollbar="false">
|
||||
<n-drawer-content :title="title">
|
||||
<n-drawer v-model:show="isDrawer" :width="width" :placement="placement">
|
||||
<n-drawer-content :title="title" :native-scrollbar="false">
|
||||
<div class="drawer">
|
||||
<n-divider title-placement="center">主题</n-divider>
|
||||
|
||||
<div class="drawer-setting-item justify-center dark-switch">
|
||||
<div class="justify-center drawer-setting-item dark-switch">
|
||||
<n-tooltip placement="bottom">
|
||||
<template #trigger>
|
||||
<n-switch v-model:value="designStore.darkTheme" class="dark-theme-switch">
|
||||
@@ -20,7 +20,7 @@
|
||||
</template>
|
||||
</n-switch>
|
||||
</template>
|
||||
<span>深色主题</span>
|
||||
<span>{{ designStore.darkTheme ? '深' : '浅' }}色主题</span>
|
||||
</n-tooltip>
|
||||
</div>
|
||||
|
||||
@@ -116,9 +116,7 @@
|
||||
</n-tooltip>
|
||||
<n-badge dot color="#19be6b" v-if="settingStore.navTheme === 'light'" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="drawer-setting-item align-items-top">
|
||||
<div class="drawer-setting-item-style">
|
||||
<n-tooltip placement="top">
|
||||
<template #trigger>
|
||||
@@ -133,14 +131,13 @@
|
||||
<n-badge dot color="#19be6b" v-if="settingStore.navTheme === 'header-dark'" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<n-divider title-placement="center">界面功能</n-divider>
|
||||
|
||||
<div class="drawer-setting-item">
|
||||
<div class="drawer-setting-item-title"> 分割菜单 </div>
|
||||
<div class="drawer-setting-item-action">
|
||||
<n-switch
|
||||
:disabled="settingStore.navMode === 'horizontal-mix' ? false : true"
|
||||
:disabled="settingStore.navMode !== 'horizontal-mix'"
|
||||
v-model:value="settingStore.menuSetting.mixMenu"
|
||||
/>
|
||||
</div>
|
||||
@@ -206,6 +203,22 @@
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
|
||||
<n-divider title-placement="center">动画</n-divider>
|
||||
|
||||
<div class="drawer-setting-item">
|
||||
<div class="drawer-setting-item-title"> 禁用动画 </div>
|
||||
<div class="drawer-setting-item-action">
|
||||
<n-switch v-model:value="settingStore.isPageAnimate" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="drawer-setting-item">
|
||||
<div class="drawer-setting-item-title"> 动画类型 </div>
|
||||
<div class="drawer-setting-item-select">
|
||||
<n-select v-model:value="settingStore.pageAnimateType" :options="animateOptions" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="drawer-setting-item">
|
||||
<n-alert type="warning" :showIcon="false">
|
||||
<p>{{ alertText }}</p>
|
||||
@@ -217,12 +230,13 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, reactive, toRefs, watch } from 'vue';
|
||||
import { defineComponent, reactive, toRefs, unref, watch, computed } from 'vue';
|
||||
import { useProjectSettingStore } from '@/store/modules/projectSetting';
|
||||
import { useDesignSettingStore } from '@/store/modules/designSetting';
|
||||
import { CheckOutlined } from '@vicons/antd';
|
||||
import { Moon, SunnySharp } from '@vicons/ionicons5';
|
||||
import { darkTheme } from 'naive-ui';
|
||||
import { animates as animateOptions } from '@/settings/animateSetting';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ProjectSetting',
|
||||
@@ -245,8 +259,7 @@
|
||||
title: props.title,
|
||||
isDrawer: false,
|
||||
placement: 'right',
|
||||
alertText:
|
||||
'该功能主要实时预览各种布局效果,更多完整配置在 projectSetting.ts 中设置,建议在生产环境关闭该布局预览功能。',
|
||||
alertText: '该功能主要实时预览各种布局效果,更多完整配置在 projectSetting.ts 中设置',
|
||||
appThemeList: designStore.appThemeList,
|
||||
});
|
||||
|
||||
@@ -257,6 +270,10 @@
|
||||
}
|
||||
);
|
||||
|
||||
const directionsOptions = computed(() => {
|
||||
return animateOptions.find((item) => item.value == unref(settingStore.pageAnimateType));
|
||||
});
|
||||
|
||||
function openDrawer() {
|
||||
state.isDrawer = true;
|
||||
}
|
||||
@@ -291,6 +308,8 @@
|
||||
darkTheme,
|
||||
openDrawer,
|
||||
closeDrawer,
|
||||
animateOptions,
|
||||
directionsOptions,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -325,6 +344,10 @@
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
&-select {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.theme-item {
|
||||
width: 20px;
|
||||
min-width: 20px;
|
||||
@@ -334,6 +357,7 @@
|
||||
border-radius: 2px;
|
||||
margin: 0 5px 5px 0;
|
||||
text-align: center;
|
||||
line-height: 14px;
|
||||
|
||||
.n-icon {
|
||||
color: #fff;
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
class="layout-header-left"
|
||||
v-if="navMode === 'horizontal' || (navMode === 'horizontal-mix' && mixMenu)"
|
||||
>
|
||||
<div class="logo">
|
||||
<img src="~@/assets/images/logo.png" alt="" />
|
||||
<h2 v-show="!collapsed" class="title">NaiveUiAdmin</h2>
|
||||
<div class="logo" v-if="navMode === 'horizontal'">
|
||||
<img :src="websiteConfig.logo" alt="" />
|
||||
<h2 v-show="!collapsed" class="title">{{ websiteConfig.title }}</h2>
|
||||
</div>
|
||||
<AsideMenu
|
||||
v-model:collapsed="collapsed"
|
||||
:collapsed="collapsed"
|
||||
v-model:location="getMenuLocation"
|
||||
:inverted="getInverted"
|
||||
mode="horizontal"
|
||||
@@ -21,7 +21,7 @@
|
||||
<!-- 菜单收起 -->
|
||||
<div
|
||||
class="ml-1 layout-header-trigger layout-header-trigger-min"
|
||||
@click="() => $emit('update:collapsed', !collapsed)"
|
||||
@click="handleMenuCollapsed"
|
||||
>
|
||||
<n-icon size="18" v-if="collapsed">
|
||||
<MenuUnfoldOutlined />
|
||||
@@ -42,8 +42,11 @@
|
||||
</div>
|
||||
<!-- 面包屑 -->
|
||||
<n-breadcrumb v-if="crumbsSetting.show">
|
||||
<template v-for="routeItem in breadcrumbList" :key="routeItem.name">
|
||||
<n-breadcrumb-item>
|
||||
<template
|
||||
v-for="routeItem in breadcrumbList"
|
||||
:key="routeItem.name === 'Redirect' ? void 0 : routeItem.name"
|
||||
>
|
||||
<n-breadcrumb-item v-if="routeItem.meta.title">
|
||||
<n-dropdown
|
||||
v-if="routeItem.children.length"
|
||||
:options="routeItem.children"
|
||||
@@ -72,7 +75,7 @@
|
||||
<div
|
||||
class="layout-header-trigger layout-header-trigger-min"
|
||||
v-for="item in iconList"
|
||||
:key="item.icon.name"
|
||||
:key="item.icon"
|
||||
>
|
||||
<n-tooltip placement="bottom">
|
||||
<template #trigger>
|
||||
@@ -98,12 +101,14 @@
|
||||
<div class="layout-header-trigger layout-header-trigger-min">
|
||||
<n-dropdown trigger="hover" @select="avatarSelect" :options="avatarOptions">
|
||||
<div class="avatar">
|
||||
<n-avatar round>
|
||||
{{ username }}
|
||||
<n-avatar round :src="websiteConfig.logo">
|
||||
|
||||
<template #icon>
|
||||
<UserOutlined />
|
||||
</template>
|
||||
</n-avatar>
|
||||
<n-divider vertical />
|
||||
<span>{{ username }}</span>
|
||||
</div>
|
||||
</n-dropdown>
|
||||
</div>
|
||||
@@ -131,10 +136,11 @@
|
||||
import { NDialogProvider, useDialog, useMessage } from 'naive-ui';
|
||||
import { TABS_ROUTES } from '@/store/mutation-types';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import { useLockscreenStore } from '@/store/modules/lockscreen';
|
||||
import { useScreenLockStore } from '@/store/modules/screenLock';
|
||||
import ProjectSetting from './ProjectSetting.vue';
|
||||
import { AsideMenu } from '@/layout/components/Menu';
|
||||
import { useProjectSetting } from '@/hooks/setting/useProjectSetting';
|
||||
import { websiteConfig } from '@/config/website.config';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'PageHeader',
|
||||
@@ -147,39 +153,38 @@
|
||||
type: Boolean,
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
emits: ['update:collapsed'],
|
||||
setup(props, { emit }) {
|
||||
const userStore = useUserStore();
|
||||
const useLockscreen = useLockscreenStore();
|
||||
const useLockscreen = useScreenLockStore();
|
||||
const message = useMessage();
|
||||
const dialog = useDialog();
|
||||
const { getNavMode, getNavTheme, getHeaderSetting, getMenuSetting, getCrumbsSetting } =
|
||||
useProjectSetting();
|
||||
|
||||
const { username } = userStore?.info || {};
|
||||
const { navMode, navTheme, headerSetting, menuSetting, crumbsSetting } = useProjectSetting();
|
||||
|
||||
const drawerSetting = ref();
|
||||
|
||||
const state = reactive({
|
||||
username: username || '',
|
||||
username: userStore?.info?.username ?? '',
|
||||
fullscreenIcon: 'FullscreenOutlined',
|
||||
navMode: getNavMode,
|
||||
navTheme: getNavTheme,
|
||||
headerSetting: getHeaderSetting,
|
||||
crumbsSetting: getCrumbsSetting,
|
||||
navMode,
|
||||
navTheme,
|
||||
headerSetting,
|
||||
crumbsSetting,
|
||||
});
|
||||
|
||||
const getInverted = computed(() => {
|
||||
const navTheme = unref(getNavTheme);
|
||||
return ['light', 'header-dark'].includes(navTheme) ? props.inverted : !props.inverted;
|
||||
return ['light', 'header-dark'].includes(unref(navTheme))
|
||||
? props.inverted
|
||||
: !props.inverted;
|
||||
});
|
||||
|
||||
const mixMenu = computed(() => {
|
||||
return unref(getMenuSetting).mixMenu;
|
||||
return unref(menuSetting).mixMenu;
|
||||
});
|
||||
|
||||
const getChangeStyle = computed(() => {
|
||||
const { collapsed } = props;
|
||||
const { minMenuWidth, menuWidth }: any = unref(getMenuSetting);
|
||||
const { minMenuWidth, menuWidth } = unref(menuSetting);
|
||||
return {
|
||||
left: collapsed ? `${minMenuWidth}px` : `${menuWidth}px`,
|
||||
width: `calc(100% - ${collapsed ? `${minMenuWidth}px` : `${menuWidth}px`})`,
|
||||
@@ -319,6 +324,10 @@
|
||||
openDrawer();
|
||||
}
|
||||
|
||||
function handleMenuCollapsed() {
|
||||
emit('update:collapsed', !props.collapsed);
|
||||
}
|
||||
|
||||
return {
|
||||
...toRefs(state),
|
||||
iconList,
|
||||
@@ -336,6 +345,8 @@
|
||||
getInverted,
|
||||
getMenuLocation,
|
||||
mixMenu,
|
||||
websiteConfig,
|
||||
handleMenuCollapsed,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -347,7 +358,7 @@
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 0;
|
||||
height: @header-height;
|
||||
height: 64px;
|
||||
box-shadow: 0 1px 4px rgb(0 21 41 / 8%);
|
||||
transition: all 0.2s ease-in-out;
|
||||
width: 100%;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<template>
|
||||
<div class="logo">
|
||||
<img src="~@/assets/images/logo.png" alt="" />
|
||||
<h2 v-show="!collapsed" class="title">NaiveUiAdmin</h2>
|
||||
<img :src="websiteConfig.logo" alt="" :class="{ 'mr-2': !collapsed }" />
|
||||
<h2 v-show="!collapsed" class="title">{{ websiteConfig.title }}</h2>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import { websiteConfig } from '@/config/website.config';
|
||||
export default {
|
||||
name: 'Index',
|
||||
props: {
|
||||
@@ -13,6 +14,11 @@
|
||||
type: Boolean,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
websiteConfig,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -29,11 +35,10 @@
|
||||
img {
|
||||
width: auto;
|
||||
height: 32px;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
.title {
|
||||
margin-bottom: 0;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
<template>
|
||||
<RouterView>
|
||||
<template #default="{ Component, route }">
|
||||
<transition name="zoom-fade" mode="out-in" appear>
|
||||
<keep-alive v-if="keepAliveComponents" :include="keepAliveComponents">
|
||||
<template v-if="mode === 'production'">
|
||||
<transition :name="getTransitionName" mode="out-in" appear>
|
||||
<keep-alive v-if="keepAliveComponents.length" :include="keepAliveComponents">
|
||||
<component :is="Component" :key="route.fullPath" />
|
||||
</keep-alive>
|
||||
<component v-else :is="Component" :key="route.fullPath" />
|
||||
</transition>
|
||||
</template>
|
||||
<template v-else>
|
||||
<keep-alive v-if="keepAliveComponents.length" :include="keepAliveComponents">
|
||||
<component :is="Component" :key="route.fullPath" />
|
||||
</keep-alive>
|
||||
<component v-else :is="Component" :key="route.fullPath" />
|
||||
</transition>
|
||||
</template>
|
||||
</template>
|
||||
</RouterView>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent, computed } from 'vue';
|
||||
import { defineComponent, computed, unref } from 'vue';
|
||||
import { useAsyncRouteStore } from '@/store/modules/asyncRoute';
|
||||
import { useProjectSetting } from '@/hooks/setting/useProjectSetting';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MainView',
|
||||
@@ -29,11 +38,20 @@
|
||||
},
|
||||
},
|
||||
setup() {
|
||||
const { isPageAnimate, pageAnimateType } = useProjectSetting();
|
||||
const asyncRouteStore = useAsyncRouteStore();
|
||||
// 需要缓存的路由组件
|
||||
const keepAliveComponents = computed(() => asyncRouteStore.keepAliveComponents);
|
||||
|
||||
const getTransitionName = computed(() => {
|
||||
return unref(isPageAnimate) ? unref(pageAnimateType) : '';
|
||||
});
|
||||
|
||||
const mode = import.meta.env.MODE;
|
||||
return {
|
||||
keepAliveComponents,
|
||||
getTransitionName,
|
||||
mode,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
import { useProjectSetting } from '@/hooks/setting/useProjectSetting';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Menu',
|
||||
name: 'AppMenu',
|
||||
components: {},
|
||||
props: {
|
||||
mode: {
|
||||
@@ -41,7 +41,7 @@
|
||||
default: 'left',
|
||||
},
|
||||
},
|
||||
emits: ['update:collapsed'],
|
||||
emits: ['update:collapsed', 'clickMenuItem'],
|
||||
setup(props, { emit }) {
|
||||
// 当前路由
|
||||
const currentRoute = useRoute();
|
||||
@@ -52,9 +52,7 @@
|
||||
const selectedKeys = ref<string>(currentRoute.name as string);
|
||||
const headerMenuSelectKey = ref<string>('');
|
||||
|
||||
const { getNavMode } = useProjectSetting();
|
||||
|
||||
const navMode = getNavMode;
|
||||
const { navMode } = useProjectSetting();
|
||||
|
||||
// 获取当前打开的子菜单
|
||||
const matched = currentRoute.matched;
|
||||
@@ -88,26 +86,27 @@
|
||||
);
|
||||
|
||||
// 监听菜单收缩状态
|
||||
watch(
|
||||
() => props.collapsed,
|
||||
(newVal) => {
|
||||
state.openKeys = newVal ? [] : getOpenKeys;
|
||||
selectedKeys.value = currentRoute.name as string;
|
||||
}
|
||||
);
|
||||
// watch(
|
||||
// () => props.collapsed,
|
||||
// (newVal) => {
|
||||
// }
|
||||
// );
|
||||
|
||||
// 跟随页面路由变化,切换菜单选中状态
|
||||
watch(
|
||||
() => currentRoute.fullPath,
|
||||
() => {
|
||||
updateMenu();
|
||||
const matched = currentRoute.matched;
|
||||
state.openKeys = matched.map((item) => item.name);
|
||||
const activeMenu: string = (currentRoute.meta?.activeMenu as string) || '';
|
||||
selectedKeys.value = activeMenu ? (activeMenu as string) : (currentRoute.name as string);
|
||||
}
|
||||
);
|
||||
|
||||
function updateSelectedKeys() {
|
||||
const matched = currentRoute.matched;
|
||||
state.openKeys = matched.map((item) => item.name);
|
||||
const activeMenu: string = (currentRoute.meta?.activeMenu as string) || '';
|
||||
selectedKeys.value = activeMenu ? (activeMenu as string) : (currentRoute.name as string);
|
||||
}
|
||||
|
||||
function updateMenu() {
|
||||
if (!settingStore.menuSetting.mixMenu) {
|
||||
menus.value = generatorMenu(asyncRouteStore.getMenus);
|
||||
@@ -118,6 +117,7 @@
|
||||
const activeMenu: string = currentRoute?.matched[0].meta?.activeMenu as string;
|
||||
headerMenuSelectKey.value = (activeMenu ? activeMenu : firstRouteName) || '';
|
||||
}
|
||||
updateSelectedKeys();
|
||||
}
|
||||
|
||||
// 点击菜单
|
||||
@@ -127,6 +127,7 @@
|
||||
} else {
|
||||
router.push({ name: key });
|
||||
}
|
||||
emit('clickMenuItem' as any, key);
|
||||
}
|
||||
|
||||
//展开菜单
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
import {
|
||||
DownOutlined,
|
||||
ReloadOutlined,
|
||||
CloseOutlined,
|
||||
VerticalRightOutlined,
|
||||
VerticalLeftOutlined,
|
||||
ColumnWidthOutlined,
|
||||
MinusOutlined,
|
||||
} from '@ant-design/icons-vue';
|
||||
import { Dropdown, Tabs, Card } from 'ant-design-vue';
|
||||
|
||||
export default {
|
||||
[Tabs.name]: Tabs,
|
||||
[Tabs.TabPane.name]: Tabs.TabPane,
|
||||
[Dropdown.name]: Dropdown,
|
||||
[Card.name]: Card,
|
||||
MinusOutlined,
|
||||
DownOutlined,
|
||||
ReloadOutlined,
|
||||
CloseOutlined,
|
||||
VerticalRightOutlined,
|
||||
VerticalLeftOutlined,
|
||||
ColumnWidthOutlined,
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div
|
||||
class="tabs-view"
|
||||
class="box-border tabs-view"
|
||||
:class="{
|
||||
'tabs-view-fix': multiTabsSetting.fixed,
|
||||
'tabs-view-fixed-header': isMultiHeaderFixed,
|
||||
@@ -30,27 +30,22 @@
|
||||
</n-icon>
|
||||
</span>
|
||||
<div ref="navScroll" class="tabs-card-scroll">
|
||||
<div ref="navRef" class="tabs-card-nav" :style="getNavStyle">
|
||||
<Draggable :list="tabsList" animation="300" item-key="fullPath" class="flex">
|
||||
<template #item="{ element }">
|
||||
<div
|
||||
class="tabs-card-scroll-item"
|
||||
:class="{ 'active-item': activeKey === element.path }"
|
||||
@click.stop="goPage(element)"
|
||||
@contextmenu="handleContextMenu($event, element)"
|
||||
>
|
||||
<span>{{ element.meta.title }}</span>
|
||||
<n-icon
|
||||
size="14"
|
||||
@click.stop="closeTabItem(element)"
|
||||
v-if="element.path != baseHome"
|
||||
>
|
||||
<CloseOutlined />
|
||||
</n-icon>
|
||||
</div>
|
||||
</template>
|
||||
</Draggable>
|
||||
</div>
|
||||
<Draggable :list="tabsList" animation="300" item-key="fullPath" class="flex">
|
||||
<template #item="{ element }">
|
||||
<div
|
||||
:id="`tag${element.fullPath.split('/').join('\/')}`"
|
||||
class="tabs-card-scroll-item"
|
||||
:class="{ 'active-item': activeKey === element.fullPath }"
|
||||
@click.stop="goPage(element)"
|
||||
@contextmenu="handleContextMenu($event, element)"
|
||||
>
|
||||
<span>{{ element.meta.title }}</span>
|
||||
<n-icon size="14" @click.stop="closeTabItem(element)" v-if="!element.meta.affix">
|
||||
<CloseOutlined />
|
||||
</n-icon>
|
||||
</div>
|
||||
</template>
|
||||
</Draggable>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tabs-close">
|
||||
@@ -87,8 +82,6 @@
|
||||
computed,
|
||||
ref,
|
||||
toRefs,
|
||||
toRaw,
|
||||
unref,
|
||||
provide,
|
||||
watch,
|
||||
onMounted,
|
||||
@@ -102,8 +95,7 @@
|
||||
import { RouteItem } from '@/store/modules/tabsView';
|
||||
import { useProjectSetting } from '@/hooks/setting/useProjectSetting';
|
||||
import { useMessage } from 'naive-ui';
|
||||
// @ts-ignore
|
||||
import Draggable from 'vuedraggable/src/vuedraggable';
|
||||
import Draggable from 'vuedraggable';
|
||||
import { PageEnum } from '@/enums/pageEnum';
|
||||
import {
|
||||
DownOutlined,
|
||||
@@ -114,10 +106,12 @@
|
||||
LeftOutlined,
|
||||
RightOutlined,
|
||||
} from '@vicons/antd';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
import { renderIcon } from '@/utils';
|
||||
import elementResizeDetectorMaker from 'element-resize-detector';
|
||||
import { useDesignSetting } from '@/hooks/setting/useDesignSetting';
|
||||
import { useProjectSettingStore } from '@/store/modules/projectSetting';
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
import { useGo } from '@/hooks/web/usePage';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'TabsView',
|
||||
@@ -134,8 +128,8 @@
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const { getDarkTheme } = useDesignSetting();
|
||||
const { getNavMode, getHeaderSetting, getMenuSetting, getMultiTabsSetting } =
|
||||
const { getDarkTheme, getAppTheme } = useDesignSetting();
|
||||
const { navMode, headerSetting, menuSetting, multiTabsSetting, isMobile } =
|
||||
useProjectSetting();
|
||||
const settingStore = useProjectSettingStore();
|
||||
|
||||
@@ -144,22 +138,29 @@
|
||||
const router = useRouter();
|
||||
const tabsViewStore = useTabsViewStore();
|
||||
const asyncRouteStore = useAsyncRouteStore();
|
||||
const navRef: any = ref(null);
|
||||
const navScroll: any = ref(null);
|
||||
const navWrap: any = ref(null);
|
||||
const isCurrent = ref(false);
|
||||
const go = useGo();
|
||||
|
||||
const themeVars = useThemeVars();
|
||||
|
||||
const getCardColor = computed(() => {
|
||||
return themeVars.value.cardColor;
|
||||
});
|
||||
|
||||
const getBaseColor = computed(() => {
|
||||
return themeVars.value.textColor1;
|
||||
});
|
||||
|
||||
const state = reactive({
|
||||
activeKey: route.fullPath,
|
||||
scrollable: false,
|
||||
navStyle: {
|
||||
transform: '',
|
||||
},
|
||||
dropdownX: 0,
|
||||
dropdownY: 0,
|
||||
showDropdown: false,
|
||||
isMultiHeaderFixed: false,
|
||||
multiTabsSetting: getMultiTabsSetting,
|
||||
multiTabsSetting: multiTabsSetting,
|
||||
});
|
||||
|
||||
// 获取简易的路由对象
|
||||
@@ -171,26 +172,28 @@
|
||||
const isMixMenuNoneSub = computed(() => {
|
||||
const mixMenu = settingStore.menuSetting.mixMenu;
|
||||
const currentRoute = useRoute();
|
||||
const navMode = unref(getNavMode);
|
||||
if (unref(navMode) != 'horizontal-mix') return true;
|
||||
if (unref(navMode) === 'horizontal-mix' && mixMenu && currentRoute.meta.isRoot) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (navMode.value != 'horizontal-mix') return true;
|
||||
return !(navMode.value === 'horizontal-mix' && mixMenu && currentRoute.meta.isRoot);
|
||||
});
|
||||
|
||||
//动态组装样式 菜单缩进
|
||||
const getChangeStyle = computed(() => {
|
||||
const { collapsed } = props;
|
||||
const navMode = unref(getNavMode);
|
||||
const { minMenuWidth, menuWidth }: any = unref(getMenuSetting);
|
||||
const { fixed }: any = unref(getMultiTabsSetting);
|
||||
const { minMenuWidth, menuWidth }: any = menuSetting.value;
|
||||
const { fixed }: any = multiTabsSetting.value;
|
||||
let lenNum =
|
||||
navMode === 'horizontal' || !isMixMenuNoneSub.value
|
||||
navMode.value === 'horizontal' || !isMixMenuNoneSub.value
|
||||
? '0px'
|
||||
: collapsed
|
||||
? `${minMenuWidth}px`
|
||||
: `${menuWidth}px`;
|
||||
|
||||
if (isMobile.value) {
|
||||
return {
|
||||
left: '0px',
|
||||
width: '100%',
|
||||
};
|
||||
}
|
||||
return {
|
||||
left: lenNum,
|
||||
width: `calc(100% - ${!fixed ? '0px' : lenNum})`,
|
||||
@@ -199,7 +202,7 @@
|
||||
|
||||
//tags 右侧下拉菜单
|
||||
const TabsMenuOptions = computed(() => {
|
||||
const isDisabled = unref(tabsList).length <= 1 ? true : false;
|
||||
const isDisabled = tabsList.value.length <= 1;
|
||||
return [
|
||||
{
|
||||
label: '刷新当前',
|
||||
@@ -209,7 +212,7 @@
|
||||
{
|
||||
label: `关闭当前`,
|
||||
key: '2',
|
||||
disabled: unref(isCurrent) || isDisabled,
|
||||
disabled: isCurrent.value || isDisabled,
|
||||
icon: renderIcon(CloseOutlined),
|
||||
},
|
||||
{
|
||||
@@ -227,17 +230,27 @@
|
||||
];
|
||||
});
|
||||
|
||||
let routes: RouteItem[] = [];
|
||||
|
||||
let cacheRoutes: RouteItem[] = [];
|
||||
const simpleRoute = getSimpleRoute(route);
|
||||
try {
|
||||
const routesStr = storage.get(TABS_ROUTES) as string | null | undefined;
|
||||
routes = routesStr ? JSON.parse(routesStr) : [getSimpleRoute(route)];
|
||||
cacheRoutes = routesStr ? JSON.parse(routesStr) : [simpleRoute];
|
||||
} catch (e) {
|
||||
routes = [getSimpleRoute(route)];
|
||||
cacheRoutes = [simpleRoute];
|
||||
}
|
||||
|
||||
// 将最新的路由信息同步到 localStorage 中
|
||||
const routes = router.getRoutes();
|
||||
cacheRoutes.forEach((cacheRoute) => {
|
||||
const route = routes.find((route) => route.path === cacheRoute.path);
|
||||
if (route) {
|
||||
cacheRoute.meta = route.meta || cacheRoute.meta;
|
||||
cacheRoute.name = (route.name || cacheRoute.name) as string;
|
||||
}
|
||||
});
|
||||
|
||||
// 初始化标签页
|
||||
tabsViewStore.initTabs(routes);
|
||||
tabsViewStore.initTabs(cacheRoutes);
|
||||
|
||||
//监听滚动条
|
||||
function onScroll(e) {
|
||||
@@ -246,11 +259,11 @@
|
||||
document.documentElement.scrollTop ||
|
||||
window.pageYOffset ||
|
||||
document.body.scrollTop; // 滚动条偏移量
|
||||
if (!getHeaderSetting.fixed && getMultiTabsSetting.fixed && scrollTop >= 64) {
|
||||
state.isMultiHeaderFixed = true;
|
||||
} else {
|
||||
state.isMultiHeaderFixed = false;
|
||||
}
|
||||
state.isMultiHeaderFixed = !!(
|
||||
!headerSetting.value.fixed &&
|
||||
multiTabsSetting.value.fixed &&
|
||||
scrollTop >= 64
|
||||
);
|
||||
}
|
||||
|
||||
window.addEventListener('scroll', onScroll, true);
|
||||
@@ -281,8 +294,8 @@
|
||||
(to) => {
|
||||
if (whiteList.includes(route.name as string)) return;
|
||||
state.activeKey = to;
|
||||
tabsViewStore.addTabs(getSimpleRoute(route));
|
||||
updateNavScroll();
|
||||
tabsViewStore.addTab(getSimpleRoute(route));
|
||||
updateNavScroll(true);
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
@@ -312,7 +325,7 @@
|
||||
const reloadPage = () => {
|
||||
delKeepAliveCompName();
|
||||
router.push({
|
||||
path: '/redirect' + unref(route).fullPath,
|
||||
path: '/redirect' + route.fullPath,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -345,7 +358,6 @@
|
||||
|
||||
// 关闭全部
|
||||
const closeAll = () => {
|
||||
localStorage.removeItem('routes');
|
||||
tabsViewStore.closeAllTabs();
|
||||
router.replace(PageEnum.BASE_HOME);
|
||||
updateNavScroll();
|
||||
@@ -375,64 +387,73 @@
|
||||
state.showDropdown = false;
|
||||
};
|
||||
|
||||
function getCurrentScrollOffset() {
|
||||
const { navStyle } = state;
|
||||
const transform: any = toRaw(navStyle.transform);
|
||||
return transform ? Number(transform.match(/translateX\(-(\d+(\.\d+)*)px\)/)[1]) : 0;
|
||||
}
|
||||
|
||||
function setOffset(value) {
|
||||
state.navStyle.transform = `translateX(-${value}px)`;
|
||||
/**
|
||||
* @param value 要滚动到的位置
|
||||
* @param amplitude 每次滚动的长度
|
||||
*/
|
||||
function scrollTo(value: number, amplitude: number) {
|
||||
const currentScroll = navScroll.value.scrollLeft;
|
||||
const scrollWidth =
|
||||
(amplitude > 0 && currentScroll + amplitude >= value) ||
|
||||
(amplitude < 0 && currentScroll + amplitude <= value)
|
||||
? value
|
||||
: currentScroll + amplitude;
|
||||
navScroll.value && navScroll.value.scrollTo(scrollWidth, 0);
|
||||
if (scrollWidth === value) return;
|
||||
return window.requestAnimationFrame(() => scrollTo(value, amplitude));
|
||||
}
|
||||
|
||||
function scrollPrev() {
|
||||
const containerWidth = navScroll.value.offsetWidth;
|
||||
const currentOffset = getCurrentScrollOffset();
|
||||
if (!currentOffset) return;
|
||||
let newOffset = currentOffset > containerWidth ? currentOffset - containerWidth : 0;
|
||||
setOffset(newOffset);
|
||||
const currentScroll = navScroll.value.scrollLeft;
|
||||
|
||||
if (!currentScroll) return;
|
||||
const scrollLeft = currentScroll > containerWidth ? currentScroll - containerWidth : 0;
|
||||
scrollTo(scrollLeft, (scrollLeft - currentScroll) / 20);
|
||||
}
|
||||
|
||||
function scrollNext() {
|
||||
const navWidth = navRef.value.scrollWidth;
|
||||
const containerWidth = navScroll.value.offsetWidth;
|
||||
const currentOffset = getCurrentScrollOffset();
|
||||
if (navWidth - currentOffset <= containerWidth) return;
|
||||
const navWidth = navScroll.value.scrollWidth;
|
||||
const currentScroll = navScroll.value.scrollLeft;
|
||||
|
||||
let newOffset =
|
||||
navWidth - currentOffset > containerWidth * 2
|
||||
? currentOffset + containerWidth
|
||||
if (navWidth - currentScroll <= containerWidth) return;
|
||||
const scrollLeft =
|
||||
navWidth - currentScroll > containerWidth * 2
|
||||
? currentScroll + containerWidth
|
||||
: navWidth - containerWidth;
|
||||
|
||||
setOffset(newOffset);
|
||||
scrollTo(scrollLeft, (scrollLeft - currentScroll) / 20);
|
||||
}
|
||||
|
||||
function updateNavScroll() {
|
||||
if (!navRef.value) return;
|
||||
let navWidth = navRef.value.scrollWidth;
|
||||
let containerWidth = navScroll.value.offsetWidth;
|
||||
const currentOffset = getCurrentScrollOffset();
|
||||
/**
|
||||
* @param autoScroll 是否开启自动滚动功能
|
||||
*/
|
||||
async function updateNavScroll(autoScroll?: boolean) {
|
||||
await nextTick();
|
||||
if (!navScroll.value) return;
|
||||
const containerWidth = navScroll.value.offsetWidth;
|
||||
const navWidth = navScroll.value.scrollWidth;
|
||||
|
||||
if (containerWidth < navWidth) {
|
||||
state.scrollable = true;
|
||||
if (navWidth - currentOffset < containerWidth) {
|
||||
setOffset(navWidth - containerWidth);
|
||||
if (autoScroll) {
|
||||
let tagList = navScroll.value.querySelectorAll('.tabs-card-scroll-item') || [];
|
||||
[...tagList].forEach((tag: HTMLElement) => {
|
||||
// fix SyntaxError
|
||||
if (tag.id === `tag${state.activeKey.split('/').join('\/')}`) {
|
||||
tag.scrollIntoView && tag.scrollIntoView();
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
state.scrollable = false;
|
||||
if (currentOffset > 0) {
|
||||
setOffset(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleResize() {
|
||||
updateNavScroll();
|
||||
updateNavScroll(true);
|
||||
}
|
||||
|
||||
const getNavStyle = computed(() => {
|
||||
return state.navStyle;
|
||||
});
|
||||
|
||||
function handleContextMenu(e, item) {
|
||||
e.preventDefault();
|
||||
isCurrent.value = PageEnum.BASE_HOME_REDIRECT === item.path;
|
||||
@@ -453,7 +474,7 @@
|
||||
const { fullPath } = e;
|
||||
if (fullPath === route.fullPath) return;
|
||||
state.activeKey = fullPath;
|
||||
router.push({ path: fullPath });
|
||||
go(e, true);
|
||||
}
|
||||
|
||||
//删除tab
|
||||
@@ -476,11 +497,9 @@
|
||||
return {
|
||||
...toRefs(state),
|
||||
navWrap,
|
||||
navRef,
|
||||
navScroll,
|
||||
route,
|
||||
tabsList,
|
||||
baseHome: PageEnum.BASE_HOME_REDIRECT,
|
||||
goPage,
|
||||
closeTabItem,
|
||||
closeLeft,
|
||||
@@ -493,10 +512,12 @@
|
||||
closeHandleSelect,
|
||||
scrollNext,
|
||||
scrollPrev,
|
||||
getNavStyle,
|
||||
handleContextMenu,
|
||||
onClickOutside,
|
||||
getDarkTheme,
|
||||
getAppTheme,
|
||||
getCardColor,
|
||||
getBaseColor,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -553,22 +574,12 @@
|
||||
}
|
||||
|
||||
&-scroll {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
|
||||
.tabs-card-nav {
|
||||
padding-left: 0;
|
||||
margin: 0;
|
||||
float: left;
|
||||
list-style: none;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
transition: transform 0.5s ease-in-out;
|
||||
}
|
||||
overflow: hidden;
|
||||
|
||||
&-item {
|
||||
background: var(--color);
|
||||
color: var(--text-color);
|
||||
background: v-bind(getCardColor);
|
||||
color: v-bind(getBaseColor);
|
||||
height: 32px;
|
||||
padding: 6px 16px 4px;
|
||||
border-radius: 3px;
|
||||
@@ -608,7 +619,7 @@
|
||||
}
|
||||
|
||||
.active-item {
|
||||
color: #2d8cf0;
|
||||
color: v-bind(getAppTheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -628,7 +639,6 @@
|
||||
background: var(--color);
|
||||
border-radius: 2px;
|
||||
cursor: pointer;
|
||||
//margin-right: 10px;
|
||||
|
||||
&-btn {
|
||||
color: var(--color);
|
||||
@@ -643,15 +653,15 @@
|
||||
.tabs-view-default-background {
|
||||
background: #f5f7f9;
|
||||
}
|
||||
|
||||
|
||||
.tabs-view-dark-background {
|
||||
background: #101014;
|
||||
}
|
||||
|
||||
|
||||
.tabs-view-fix {
|
||||
position: fixed;
|
||||
z-index: 5;
|
||||
padding: 6px 19px 6px 10px;
|
||||
padding: 6px 10px 6px 10px;
|
||||
left: 200px;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
<template>
|
||||
<NLayout class="layout" :position="fixedMenu" has-sider>
|
||||
<NLayoutSider
|
||||
v-if="isMixMenuNoneSub && (navMode === 'vertical' || navMode === 'horizontal-mix')"
|
||||
show-trigger
|
||||
<n-layout class="layout" :position="fixedMenu" has-sider>
|
||||
<n-layout-sider
|
||||
v-if="
|
||||
!isMobile && isMixMenuNoneSub && (navMode === 'vertical' || navMode === 'horizontal-mix')
|
||||
"
|
||||
show-trigger="bar"
|
||||
@collapse="collapsed = true"
|
||||
:position="fixedMenu"
|
||||
@expand="collapsed = false"
|
||||
@@ -16,14 +18,33 @@
|
||||
>
|
||||
<Logo :collapsed="collapsed" />
|
||||
<AsideMenu v-model:collapsed="collapsed" v-model:location="getMenuLocation" />
|
||||
</NLayoutSider>
|
||||
</n-layout-sider>
|
||||
|
||||
<NLayout :inverted="inverted">
|
||||
<NLayoutHeader :inverted="getHeaderInverted" :position="fixedHeader">
|
||||
<n-drawer
|
||||
v-model:show="showSideDrawer"
|
||||
:width="menuWidth"
|
||||
:placement="'left'"
|
||||
class="layout-side-drawer"
|
||||
>
|
||||
<n-layout-sider
|
||||
:position="fixedMenu"
|
||||
:collapsed="false"
|
||||
:width="menuWidth"
|
||||
:native-scrollbar="false"
|
||||
:inverted="inverted"
|
||||
class="layout-sider"
|
||||
>
|
||||
<Logo :collapsed="collapsed" />
|
||||
<AsideMenu v-model:location="getMenuLocation" />
|
||||
</n-layout-sider>
|
||||
</n-drawer>
|
||||
|
||||
<n-layout :inverted="inverted">
|
||||
<n-layout-header :inverted="getHeaderInverted" :position="fixedHeader">
|
||||
<PageHeader v-model:collapsed="collapsed" :inverted="inverted" />
|
||||
</NLayoutHeader>
|
||||
</n-layout-header>
|
||||
|
||||
<NLayoutContent
|
||||
<n-layout-content
|
||||
class="layout-content"
|
||||
:class="{ 'layout-default-background': getDarkTheme === false }"
|
||||
>
|
||||
@@ -50,13 +71,14 @@
|
||||
<!-- <NLayoutFooter v-if="getShowFooter">-->
|
||||
<!-- <PageFooter />-->
|
||||
<!-- </NLayoutFooter>-->
|
||||
</NLayoutContent>
|
||||
</NLayout>
|
||||
</NLayout>
|
||||
</n-layout-content>
|
||||
<n-back-top :right="100" />
|
||||
</n-layout>
|
||||
</n-layout>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, ref, unref, computed, onMounted } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { ref, unref, computed, onMounted } from 'vue';
|
||||
import { Logo } from './components/Logo';
|
||||
import { TabsView } from './components/TagsView';
|
||||
import { MainView } from './components/Main';
|
||||
@@ -64,123 +86,119 @@
|
||||
import { PageHeader } from './components/Header';
|
||||
import { useProjectSetting } from '@/hooks/setting/useProjectSetting';
|
||||
import { useDesignSetting } from '@/hooks/setting/useDesignSetting';
|
||||
import { useLoadingBar } from 'naive-ui';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useProjectSettingStore } from '@/store/modules/projectSetting';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Layout',
|
||||
components: {
|
||||
TabsView,
|
||||
MainView,
|
||||
PageHeader,
|
||||
AsideMenu,
|
||||
Logo,
|
||||
},
|
||||
setup() {
|
||||
const { getDarkTheme } = useDesignSetting();
|
||||
const {
|
||||
getShowFooter,
|
||||
getNavMode,
|
||||
getNavTheme,
|
||||
getHeaderSetting,
|
||||
getMenuSetting,
|
||||
getMultiTabsSetting,
|
||||
} = useProjectSetting();
|
||||
const { getDarkTheme } = useDesignSetting();
|
||||
const {
|
||||
// showFooter,
|
||||
navMode,
|
||||
navTheme,
|
||||
headerSetting,
|
||||
menuSetting,
|
||||
multiTabsSetting,
|
||||
} = useProjectSetting();
|
||||
|
||||
const settingStore = useProjectSettingStore();
|
||||
const settingStore = useProjectSettingStore();
|
||||
|
||||
const navMode = getNavMode;
|
||||
const collapsed = ref<boolean>(false);
|
||||
|
||||
const collapsed = ref<boolean>(false);
|
||||
const { mobileWidth, menuWidth } = unref(menuSetting);
|
||||
|
||||
const fixedHeader = computed(() => {
|
||||
const { fixed } = unref(getHeaderSetting);
|
||||
return fixed ? 'absolute' : 'static';
|
||||
});
|
||||
const isMobile = computed<boolean>({
|
||||
get: () => settingStore.getIsMobile,
|
||||
set: (val) => settingStore.setIsMobile(val),
|
||||
});
|
||||
|
||||
const isMixMenuNoneSub = computed(() => {
|
||||
const mixMenu = settingStore.menuSetting.mixMenu;
|
||||
const currentRoute = useRoute();
|
||||
if (unref(navMode) != 'horizontal-mix') return true;
|
||||
if (unref(navMode) === 'horizontal-mix' && mixMenu && currentRoute.meta.isRoot) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
const fixedHeader = computed(() => {
|
||||
const { fixed } = unref(headerSetting);
|
||||
return fixed ? 'absolute' : 'static';
|
||||
});
|
||||
|
||||
const fixedMenu = computed(() => {
|
||||
const { fixed } = unref(getHeaderSetting);
|
||||
return fixed ? 'absolute' : 'static';
|
||||
});
|
||||
const isMixMenuNoneSub = computed(() => {
|
||||
const mixMenu = unref(menuSetting).mixMenu;
|
||||
const currentRoute = useRoute();
|
||||
if (unref(navMode) != 'horizontal-mix') return true;
|
||||
if (unref(navMode) === 'horizontal-mix' && mixMenu && currentRoute.meta.isRoot) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const isMultiTabs = computed(() => {
|
||||
return unref(getMultiTabsSetting).show;
|
||||
});
|
||||
const fixedMenu = computed(() => {
|
||||
const { fixed } = unref(headerSetting);
|
||||
return fixed ? 'absolute' : 'static';
|
||||
});
|
||||
|
||||
const fixedMulti = computed(() => {
|
||||
return unref(getMultiTabsSetting).fixed;
|
||||
});
|
||||
const isMultiTabs = computed(() => {
|
||||
return unref(multiTabsSetting).show;
|
||||
});
|
||||
|
||||
const inverted = computed(() => {
|
||||
return ['dark', 'header-dark'].includes(unref(getNavTheme));
|
||||
});
|
||||
const fixedMulti = computed(() => {
|
||||
return unref(multiTabsSetting).fixed;
|
||||
});
|
||||
|
||||
const getHeaderInverted = computed(() => {
|
||||
const navTheme = unref(getNavTheme);
|
||||
return ['light', 'header-dark'].includes(navTheme) ? unref(inverted) : !unref(inverted);
|
||||
});
|
||||
const inverted = computed(() => {
|
||||
return ['dark', 'header-dark'].includes(unref(navTheme));
|
||||
});
|
||||
|
||||
const leftMenuWidth = computed(() => {
|
||||
const { minMenuWidth, menuWidth } = unref(getMenuSetting);
|
||||
return collapsed.value ? minMenuWidth : menuWidth;
|
||||
});
|
||||
const getHeaderInverted = computed(() => {
|
||||
return ['light', 'header-dark'].includes(unref(navTheme)) ? unref(inverted) : !unref(inverted);
|
||||
});
|
||||
|
||||
const getChangeStyle = computed(() => {
|
||||
const { minMenuWidth, menuWidth } = unref(getMenuSetting);
|
||||
return {
|
||||
'padding-left': collapsed.value ? `${minMenuWidth}px` : `${menuWidth}px`,
|
||||
};
|
||||
});
|
||||
const leftMenuWidth = computed(() => {
|
||||
const { minMenuWidth, menuWidth } = unref(menuSetting);
|
||||
return collapsed.value ? minMenuWidth : menuWidth;
|
||||
});
|
||||
|
||||
const getMenuLocation = computed(() => {
|
||||
return 'left';
|
||||
});
|
||||
const getMenuLocation = computed(() => {
|
||||
return 'left';
|
||||
});
|
||||
|
||||
function watchWidth() {
|
||||
const Width = document.body.clientWidth;
|
||||
if (Width <= 950) {
|
||||
collapsed.value = true;
|
||||
} else collapsed.value = false;
|
||||
}
|
||||
// 控制显示或隐藏移动端侧边栏
|
||||
const showSideDrawer = computed({
|
||||
get: () => isMobile.value && collapsed.value,
|
||||
set: (val) => (collapsed.value = val),
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
window.addEventListener('resize', watchWidth);
|
||||
//挂载在 window 方便与在js中使用
|
||||
window['$loading'] = useLoadingBar();
|
||||
window['$loading'].finish();
|
||||
});
|
||||
//判断是否触发移动端模式
|
||||
const checkMobileMode = () => {
|
||||
if (document.body.clientWidth <= mobileWidth) {
|
||||
isMobile.value = true;
|
||||
} else {
|
||||
isMobile.value = false;
|
||||
}
|
||||
collapsed.value = false;
|
||||
};
|
||||
|
||||
return {
|
||||
fixedMenu,
|
||||
fixedMulti,
|
||||
fixedHeader,
|
||||
collapsed,
|
||||
inverted,
|
||||
isMultiTabs,
|
||||
leftMenuWidth,
|
||||
getChangeStyle,
|
||||
navMode,
|
||||
getShowFooter,
|
||||
getDarkTheme,
|
||||
getHeaderInverted,
|
||||
getMenuLocation,
|
||||
isMixMenuNoneSub,
|
||||
};
|
||||
},
|
||||
const watchWidth = () => {
|
||||
const Width = document.body.clientWidth;
|
||||
if (Width <= 950) {
|
||||
collapsed.value = true;
|
||||
} else collapsed.value = false;
|
||||
|
||||
checkMobileMode();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
checkMobileMode();
|
||||
window.addEventListener('resize', watchWidth);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="less">
|
||||
.layout-side-drawer {
|
||||
background-color: rgb(0, 20, 40);
|
||||
|
||||
.layout-sider {
|
||||
min-height: 100vh;
|
||||
box-shadow: 2px 0 8px 0 rgb(29 35 41 / 5%);
|
||||
position: relative;
|
||||
z-index: 13;
|
||||
transition: all 0.2s ease-in-out;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<style lang="less" scoped>
|
||||
.layout {
|
||||
display: flex;
|
||||
@@ -241,7 +259,7 @@
|
||||
}
|
||||
|
||||
.fluid-header {
|
||||
padding-top: 0px;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
.main-view-fix {
|
||||
|
||||
30
src/main.ts
30
src/main.ts
@@ -1,23 +1,23 @@
|
||||
import './styles/tailwind.css';
|
||||
import './styles/index.less';
|
||||
import { createApp } from 'vue';
|
||||
import { setupNaiveDiscreteApi, setupNaive, setupDirectives } from '@/plugins';
|
||||
import App from './App.vue';
|
||||
import router, { setupRouter } from './router';
|
||||
import { setupStore } from '@/store';
|
||||
import MakeitCaptcha from 'makeit-captcha';
|
||||
import 'makeit-captcha/dist/captcha.min.css';
|
||||
import { setupNaive, setupDirectives } from '@/plugins';
|
||||
import { AppProvider } from '@/components/Application';
|
||||
|
||||
async function bootstrap() {
|
||||
const appProvider = createApp(AppProvider);
|
||||
|
||||
const app = createApp(App);
|
||||
|
||||
app.use(MakeitCaptcha);
|
||||
// 挂载状态管理
|
||||
setupStore(app);
|
||||
|
||||
// 注册全局常用的 naive-ui 组件
|
||||
setupNaive(app);
|
||||
|
||||
// 挂载 naive-ui 脱离上下文的 Api
|
||||
setupNaiveDiscreteApi();
|
||||
|
||||
// 注册全局自定义组件
|
||||
//setupCustomComponents();
|
||||
|
||||
@@ -27,18 +27,18 @@ async function bootstrap() {
|
||||
// 注册全局方法,如:app.config.globalProperties.$message = message
|
||||
//setupGlobalMethods(app);
|
||||
|
||||
// 挂载状态管理
|
||||
setupStore(app);
|
||||
|
||||
//优先挂载一下 Provider 解决路由守卫,Axios中可使用,Dialog,Message 等之类组件
|
||||
appProvider.mount('#appProvider', true);
|
||||
|
||||
// 挂载路由
|
||||
await setupRouter(app);
|
||||
setupRouter(app);
|
||||
|
||||
// 路由准备就绪后挂载APP实例
|
||||
// 路由准备就绪后挂载 APP 实例
|
||||
// https://router.vuejs.org/api/interfaces/router.html#isready
|
||||
await router.isReady();
|
||||
|
||||
// https://www.naiveui.com/en-US/os-theme/docs/style-conflict#About-Tailwind's-Preflight-Style-Override
|
||||
const meta = document.createElement('meta');
|
||||
meta.name = 'naive-ui-style';
|
||||
document.head.appendChild(meta);
|
||||
|
||||
app.mount('#app', true);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { App } from 'vue';
|
||||
|
||||
import { permission } from '@/directives/permission';
|
||||
import copy from '@/directives/copy';
|
||||
import debounce from '@/directives/debounce';
|
||||
import throttle from '@/directives/throttle';
|
||||
import draggable from '@/directives/draggable';
|
||||
|
||||
/**
|
||||
* 注册全局自定义指令
|
||||
@@ -9,4 +13,12 @@ import { permission } from '@/directives/permission';
|
||||
export function setupDirectives(app: App) {
|
||||
// 权限控制指令(演示)
|
||||
app.directive('permission', permission);
|
||||
// 复制指令
|
||||
app.directive('copy', copy);
|
||||
// 防抖指令
|
||||
app.directive('debounce', debounce);
|
||||
// 节流指令
|
||||
app.directive('throttle', throttle);
|
||||
// 拖拽指令
|
||||
app.directive('draggable', draggable);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export { setupNaive } from '@/plugins/naive';
|
||||
export { setupNaiveDiscreteApi } from '@/plugins/naiveDiscreteApi';
|
||||
export { setupDirectives } from '@/plugins/directives';
|
||||
export { setupCustomComponents } from '@/plugins/customComponents';
|
||||
export { setupGlobalMethods } from '@/plugins/globalMethods';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { App } from 'vue';
|
||||
import {
|
||||
create,
|
||||
NConfigProvider,
|
||||
NMessageProvider,
|
||||
NDialogProvider,
|
||||
NConfigProvider,
|
||||
NInput,
|
||||
NButton,
|
||||
NForm,
|
||||
@@ -65,8 +65,11 @@ import {
|
||||
NSpin,
|
||||
NTimePicker,
|
||||
NBackTop,
|
||||
NSkeleton,
|
||||
NCascader,
|
||||
} from 'naive-ui';
|
||||
|
||||
// https://www.naiveui.com/en-US/os-theme/docs/import-on-demand
|
||||
const naive = create({
|
||||
components: [
|
||||
NMessageProvider,
|
||||
@@ -133,6 +136,8 @@ const naive = create({
|
||||
NSpin,
|
||||
NTimePicker,
|
||||
NBackTop,
|
||||
NSkeleton,
|
||||
NCascader,
|
||||
],
|
||||
});
|
||||
|
||||
|
||||
39
src/plugins/naiveDiscreteApi.ts
Normal file
39
src/plugins/naiveDiscreteApi.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import * as NaiveUI from 'naive-ui';
|
||||
import { computed } from 'vue';
|
||||
import { useDesignSetting } from '@/store/modules/designSetting';
|
||||
import { lighten } from '@/utils/index';
|
||||
|
||||
/**
|
||||
* 挂载 Naive-ui 脱离上下文的 API
|
||||
* 如果你想在 setup 外使用 useDialog、useMessage、useNotification、useLoadingBar,可以通过 createDiscreteApi 来构建对应的 API。
|
||||
* https://www.naiveui.com/zh-CN/dark/components/discrete
|
||||
*/
|
||||
|
||||
export function setupNaiveDiscreteApi() {
|
||||
const designStore = useDesignSetting();
|
||||
|
||||
const configProviderPropsRef = computed(() => ({
|
||||
theme: designStore.darkTheme ? NaiveUI.darkTheme : undefined,
|
||||
themeOverrides: {
|
||||
common: {
|
||||
primaryColor: designStore.appTheme,
|
||||
primaryColorHover: lighten(designStore.appTheme, 6),
|
||||
primaryColorPressed: lighten(designStore.appTheme, 6),
|
||||
},
|
||||
LoadingBar: {
|
||||
colorLoading: designStore.appTheme,
|
||||
},
|
||||
},
|
||||
}));
|
||||
const { message, dialog, notification, loadingBar } = NaiveUI.createDiscreteApi(
|
||||
['message', 'dialog', 'notification', 'loadingBar'],
|
||||
{
|
||||
configProviderProps: configProviderPropsRef,
|
||||
}
|
||||
);
|
||||
|
||||
window['$message'] = message;
|
||||
window['$dialog'] = dialog;
|
||||
window['$notification'] = notification;
|
||||
window['$loading'] = loadingBar;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { AppRouteRecordRaw } from '@/router/types';
|
||||
import { ErrorPage, RedirectName, Layout } from '@/router/constant';
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
// 404 on a page
|
||||
export const ErrorPageRoute: AppRouteRecordRaw = {
|
||||
export const ErrorPageRoute: RouteRecordRaw = {
|
||||
path: '/:path(.*)*',
|
||||
name: 'ErrorPage',
|
||||
component: Layout,
|
||||
@@ -23,7 +23,7 @@ export const ErrorPageRoute: AppRouteRecordRaw = {
|
||||
],
|
||||
};
|
||||
|
||||
export const RedirectRoute: AppRouteRecordRaw = {
|
||||
export const RedirectRoute: RouteRecordRaw = {
|
||||
path: '/redirect',
|
||||
name: RedirectName,
|
||||
component: Layout,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { adminMenus } from '@/api/system/menu';
|
||||
import { constantRouterIcon } from './router-icons';
|
||||
import router from '@/router/index';
|
||||
import { constantRouter } from '@/router/index';
|
||||
import { constantRouterIcon } from './icons';
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout, ParentLayout } from '@/router/constant';
|
||||
import type { AppRouteRecordRaw } from '@/router/types';
|
||||
@@ -18,13 +16,13 @@ LayoutMap.set('IFRAME', Iframe);
|
||||
* @param parent
|
||||
* @returns {*}
|
||||
*/
|
||||
export const routerGenerator = (routerMap, parent?): any[] => {
|
||||
export const generateRoutes = (routerMap, parent?): any[] => {
|
||||
return routerMap.map((item) => {
|
||||
const currentRouter: any = {
|
||||
const currentRoute: any = {
|
||||
// 路由地址 动态拼接生成如 /dashboard/workplace
|
||||
path: `${(parent && parent.path) || ''}/${item.path}`,
|
||||
path: `${(parent && parent.path) ?? ''}/${item.path}`,
|
||||
// 路由名称,建议唯一
|
||||
name: item.name || '',
|
||||
name: item.name ?? '',
|
||||
// 该路由对应页面的 组件
|
||||
component: item.component,
|
||||
// meta: 页面标题, 菜单图标, 页面权限(供指令权限用,可去掉)
|
||||
@@ -37,17 +35,17 @@ export const routerGenerator = (routerMap, parent?): any[] => {
|
||||
};
|
||||
|
||||
// 为了防止出现后端返回结果不规范,处理有可能出现拼接出两个 反斜杠
|
||||
currentRouter.path = currentRouter.path.replace('//', '/');
|
||||
currentRoute.path = currentRoute.path.replace('//', '/');
|
||||
// 重定向
|
||||
item.redirect && (currentRouter.redirect = item.redirect);
|
||||
item.redirect && (currentRoute.redirect = item.redirect);
|
||||
// 是否有子菜单,并递归处理
|
||||
if (item.children && item.children.length > 0) {
|
||||
//如果未定义 redirect 默认第一个子路由为 redirect
|
||||
!item.redirect && (currentRouter.redirect = `${item.path}/${item.children[0].path}`);
|
||||
!item.redirect && (currentRoute.redirect = `${item.path}/${item.children[0].path}`);
|
||||
// Recursion
|
||||
currentRouter.children = routerGenerator(item.children, currentRouter);
|
||||
currentRoute.children = generateRoutes(item.children, currentRoute);
|
||||
}
|
||||
return currentRouter;
|
||||
return currentRoute;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -55,22 +53,11 @@ export const routerGenerator = (routerMap, parent?): any[] => {
|
||||
* 动态生成菜单
|
||||
* @returns {Promise<Router>}
|
||||
*/
|
||||
export const generatorDynamicRouter = (): Promise<RouteRecordRaw[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
adminMenus()
|
||||
.then((result) => {
|
||||
const routeList = routerGenerator(result);
|
||||
asyncImportRoute(routeList);
|
||||
const asyncRoutesList = [...routeList, ...constantRouter];
|
||||
asyncRoutesList.forEach((item) => {
|
||||
router.addRoute(item);
|
||||
});
|
||||
resolve(asyncRoutesList);
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
export const generateDynamicRoutes = async (): Promise<RouteRecordRaw[]> => {
|
||||
const result = await adminMenus();
|
||||
const router = generateRoutes(result);
|
||||
asyncImportRoute(router);
|
||||
return router;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import { isNavigationFailure, Router } from 'vue-router';
|
||||
import { useUserStoreWidthOut } from '@/store/modules/user';
|
||||
import { useAsyncRouteStoreWidthOut } from '@/store/modules/asyncRoute';
|
||||
import { useUser } from '@/store/modules/user';
|
||||
import { useAsyncRoute } from '@/store/modules/asyncRoute';
|
||||
import { ACCESS_TOKEN } from '@/store/mutation-types';
|
||||
import { storage } from '@/utils/Storage';
|
||||
import { PageEnum } from '@/enums/pageEnum';
|
||||
@@ -12,8 +12,8 @@ const LOGIN_PATH = PageEnum.BASE_LOGIN;
|
||||
const whitePathList = [LOGIN_PATH]; // no redirect whitelist
|
||||
|
||||
export function createRouterGuards(router: Router) {
|
||||
const userStore = useUserStoreWidthOut();
|
||||
const asyncRouteStore = useAsyncRouteStoreWidthOut();
|
||||
const userStore = useUser();
|
||||
const asyncRouteStore = useAsyncRoute();
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
const Loading = window['$loading'] || null;
|
||||
Loading && Loading.start();
|
||||
@@ -51,12 +51,12 @@ export function createRouterGuards(router: Router) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (asyncRouteStore.getIsDynamicAddedRoute) {
|
||||
if (asyncRouteStore.getIsDynamicRouteAdded) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const userInfo = await userStore.GetInfo();
|
||||
const userInfo = await userStore.getInfo();
|
||||
|
||||
const routes = await asyncRouteStore.generateRoutes(userInfo);
|
||||
|
||||
@@ -74,7 +74,7 @@ export function createRouterGuards(router: Router) {
|
||||
const redirectPath = (from.query.redirect || to.path) as string;
|
||||
const redirect = decodeURIComponent(redirectPath);
|
||||
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect };
|
||||
asyncRouteStore.setDynamicAddedRoute(true);
|
||||
asyncRouteStore.setDynamicRouteAdded(true);
|
||||
next(nextData);
|
||||
Loading && Loading.finish();
|
||||
});
|
||||
@@ -84,7 +84,7 @@ export function createRouterGuards(router: Router) {
|
||||
if (isNavigationFailure(failure)) {
|
||||
//console.log('failed navigation', failure)
|
||||
}
|
||||
const asyncRouteStore = useAsyncRouteStoreWidthOut();
|
||||
const asyncRouteStore = useAsyncRoute();
|
||||
// 在这里设置需要缓存的组件名称
|
||||
const keepAliveComponents = asyncRouteStore.keepAliveComponents;
|
||||
const currentComName: any = to.matched.find((item) => item.name == to.name)?.name;
|
||||
@@ -1,22 +1,20 @@
|
||||
import { App } from 'vue';
|
||||
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
|
||||
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
|
||||
import { RedirectRoute } from '@/router/base';
|
||||
import { PageEnum } from '@/enums/pageEnum';
|
||||
import { createRouterGuards } from './router-guards';
|
||||
import { createRouterGuards } from './guards';
|
||||
import type { IModuleType } from './types';
|
||||
|
||||
// @ts-ignore
|
||||
const modules = import.meta.globEager('./modules/**/*.ts');
|
||||
const modules = import.meta.glob<IModuleType>('./modules/**/*.ts', { eager: true });
|
||||
|
||||
const routeModuleList: RouteRecordRaw[] = [];
|
||||
|
||||
Object.keys(modules).forEach((key) => {
|
||||
const mod = modules[key].default || {};
|
||||
const routeModuleList: RouteRecordRaw[] = Object.keys(modules).reduce((list, key) => {
|
||||
const mod = modules[key].default ?? {};
|
||||
const modList = Array.isArray(mod) ? [...mod] : [mod];
|
||||
routeModuleList.push(...modList);
|
||||
});
|
||||
return [...list, ...modList];
|
||||
}, []);
|
||||
|
||||
function sortRoute(a, b) {
|
||||
return (a.meta?.sort || 0) - (b.meta?.sort || 0);
|
||||
return (a.meta?.sort ?? 0) - (b.meta?.sort ?? 0);
|
||||
}
|
||||
|
||||
routeModuleList.sort(sortRoute);
|
||||
@@ -43,10 +41,10 @@ export const LoginRoute: RouteRecordRaw = {
|
||||
export const asyncRoutes = [...routeModuleList];
|
||||
|
||||
//普通路由 无需验证权限
|
||||
export const constantRouter: any[] = [LoginRoute, RootRoute, RedirectRoute];
|
||||
export const constantRouter: RouteRecordRaw[] = [LoginRoute, RootRoute, RedirectRoute];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHashHistory(''),
|
||||
history: createWebHistory(),
|
||||
routes: constantRouter,
|
||||
strict: true,
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { ProjectOutlined } from '@vicons/antd';
|
||||
import { renderIcon, renderNew } from '@/utils/index';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
@@ -12,15 +12,14 @@ const routes: Array<RouteRecordRaw> = [
|
||||
sort: 10,
|
||||
isRoot: true,
|
||||
activeMenu: 'about_index',
|
||||
icon: renderIcon(ProjectOutlined),
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'index',
|
||||
name: `about_index`,
|
||||
meta: {
|
||||
title: '关于',
|
||||
icon: renderIcon(ProjectOutlined),
|
||||
extra: renderNew(),
|
||||
title: '关于项目',
|
||||
activeMenu: 'about_index',
|
||||
},
|
||||
component: () => import('@/views/about/index.vue'),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout, ParentLayout } from '@/router/constant';
|
||||
import { WalletOutlined } from '@vicons/antd';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
import { renderIcon, renderNew } from '@/utils';
|
||||
|
||||
const routeName = 'comp';
|
||||
|
||||
@@ -106,6 +106,24 @@ const routes: Array<RouteRecordRaw> = [
|
||||
},
|
||||
component: () => import('@/views/comp/modal/index.vue'),
|
||||
},
|
||||
{
|
||||
path: 'richtext',
|
||||
name: `richtext`,
|
||||
meta: {
|
||||
title: '富文本',
|
||||
extra: renderNew(),
|
||||
},
|
||||
component: () => import('@/views/comp/richtext/vue-quill.vue'),
|
||||
},
|
||||
{
|
||||
path: 'drag',
|
||||
name: `Drag`,
|
||||
meta: {
|
||||
title: '拖拽',
|
||||
extra: renderNew(),
|
||||
},
|
||||
component: () => import('@/views/comp/drag/index.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -34,6 +34,7 @@ const routes: Array<RouteRecordRaw> = [
|
||||
meta: {
|
||||
title: '主控台',
|
||||
permissions: ['dashboard_console'],
|
||||
affix: true,
|
||||
},
|
||||
component: () => import('@/views/dashboard/console/console.vue'),
|
||||
},
|
||||
|
||||
31
src/router/modules/directive.ts
Normal file
31
src/router/modules/directive.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { BorderOuterOutlined } from '@vicons/antd';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/directive',
|
||||
name: 'directive',
|
||||
component: Layout,
|
||||
meta: {
|
||||
sort: 9,
|
||||
isRoot: true,
|
||||
activeMenu: 'directive_index',
|
||||
icon: renderIcon(BorderOuterOutlined),
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'index',
|
||||
name: `directive_index`,
|
||||
meta: {
|
||||
title: '指令示例',
|
||||
activeMenu: 'directive_index',
|
||||
},
|
||||
component: () => import('@/views/directive/index.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
@@ -6,12 +6,12 @@ import { renderIcon } from '@/utils/index';
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/external',
|
||||
name: 'https://naive-ui-admin-docs.vercel.app',
|
||||
name: 'https://docs.naiveadmin.com',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: '项目文档',
|
||||
icon: renderIcon(DocumentTextOutline),
|
||||
sort: 9,
|
||||
sort: 11,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -17,12 +17,21 @@ const routes: Array<RouteRecordRaw> = [
|
||||
icon: renderIcon(DesktopOutline),
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'naive-admin',
|
||||
name: 'naive-admin',
|
||||
meta: {
|
||||
title: 'NaiveAdmin',
|
||||
frameSrc: 'https://www.naiveadmin.com',
|
||||
},
|
||||
component: IFrame,
|
||||
},
|
||||
{
|
||||
path: 'docs',
|
||||
name: 'frame-docs',
|
||||
meta: {
|
||||
title: '项目文档(内嵌)',
|
||||
frameSrc: 'https://naive-ui-admin-docs.vercel.app',
|
||||
frameSrc: 'https://jekip.github.io/docs',
|
||||
},
|
||||
component: IFrame,
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { TableOutlined } from '@vicons/antd';
|
||||
import { renderIcon, renderNew } from '@/utils/index';
|
||||
import { renderIcon } from '@/utils/index';
|
||||
|
||||
/**
|
||||
* @param name 路由名称, 必须设置,且不能重名
|
||||
@@ -31,7 +31,6 @@ const routes: Array<RouteRecordRaw> = [
|
||||
name: 'basic-list',
|
||||
meta: {
|
||||
title: '基础列表',
|
||||
extra: renderNew(),
|
||||
},
|
||||
component: () => import('@/views/list/basicList/index.vue'),
|
||||
},
|
||||
|
||||
20
src/router/modules/newVersion.ts
Normal file
20
src/router/modules/newVersion.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { Layout } from '@/router/constant';
|
||||
import { SketchOutlined } from '@vicons/antd';
|
||||
import { renderIcon, renderNew } from '@/utils/index';
|
||||
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/newversion',
|
||||
name: 'https://www.naiveadmin.com',
|
||||
component: Layout,
|
||||
meta: {
|
||||
title: 'Pro 版本',
|
||||
extra: renderNew(),
|
||||
icon: renderIcon(SketchOutlined),
|
||||
sort: 12,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
@@ -1,13 +1,12 @@
|
||||
import type { RouteRecordRaw, RouteMeta } from 'vue-router';
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
export type Component<T extends any = any> =
|
||||
export type Component<T = any> =
|
||||
| ReturnType<typeof defineComponent>
|
||||
| (() => Promise<typeof import('*.vue')>)
|
||||
| (() => Promise<T>);
|
||||
|
||||
// @ts-ignore
|
||||
export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
|
||||
export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta' | 'children'> {
|
||||
name: string;
|
||||
meta: RouteMeta;
|
||||
component?: Component | string;
|
||||
@@ -33,4 +32,28 @@ export interface Meta {
|
||||
frameSrc?: string;
|
||||
// 外链跳转地址
|
||||
externalLink?: string;
|
||||
//隐藏
|
||||
hidden?: boolean;
|
||||
}
|
||||
|
||||
export interface Menu {
|
||||
title: string;
|
||||
label: string;
|
||||
key: string;
|
||||
meta: RouteMeta;
|
||||
name: string;
|
||||
component?: Component | string;
|
||||
components?: Component;
|
||||
children?: AppRouteRecordRaw[];
|
||||
props?: Recordable;
|
||||
fullPath?: string;
|
||||
icon?: any;
|
||||
path: string;
|
||||
permissions?: string[];
|
||||
redirect?: string;
|
||||
sort?: number;
|
||||
}
|
||||
|
||||
export interface IModuleType {
|
||||
default: Array<RouteRecordRaw> | RouteRecordRaw;
|
||||
}
|
||||
|
||||
8
src/settings/animateSetting.ts
Normal file
8
src/settings/animateSetting.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export const animates = [
|
||||
{ value: 'zoom-fade', label: '渐变' },
|
||||
{ value: 'zoom-out', label: '闪现' },
|
||||
{ value: 'fade-slide', label: '滑动' },
|
||||
{ value: 'fade', label: '消退' },
|
||||
{ value: 'fade-bottom', label: '底部消退' },
|
||||
{ value: 'fade-scale', label: '缩放消退' },
|
||||
];
|
||||
@@ -9,6 +9,8 @@ export default {
|
||||
listField: 'list',
|
||||
// 接口返回总页数字段名
|
||||
totalField: 'pageCount',
|
||||
//总数字段名
|
||||
countField: 'itemCount',
|
||||
},
|
||||
//默认分页数量
|
||||
defaultPageSize: 10,
|
||||
|
||||
@@ -3,6 +3,8 @@ const setting = {
|
||||
navMode: 'vertical',
|
||||
//导航风格 dark 暗色侧边栏 light 白色侧边栏 header-dark 暗色顶栏
|
||||
navTheme: 'dark',
|
||||
// 是否处于移动端模式
|
||||
isMobile: false,
|
||||
//顶部
|
||||
headerSetting: {
|
||||
//背景色
|
||||
@@ -33,6 +35,10 @@ const setting = {
|
||||
fixed: true,
|
||||
//分割菜单
|
||||
mixMenu: false,
|
||||
//触发移动端侧边栏的宽度
|
||||
mobileWidth: 800,
|
||||
// 折叠菜单
|
||||
collapsed: false,
|
||||
},
|
||||
//面包屑
|
||||
crumbsSetting: {
|
||||
@@ -43,5 +49,9 @@ const setting = {
|
||||
},
|
||||
//菜单权限模式 FIXED 前端固定路由 BACK 动态获取
|
||||
permissionMode: 'FIXED',
|
||||
//是否开启路由动画
|
||||
isPageAnimate: true,
|
||||
//路由动画类型
|
||||
pageAnimateType: 'zoom-fade',
|
||||
};
|
||||
export default setting;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { defineStore } from 'pinia';
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import { store } from '@/store';
|
||||
import { asyncRoutes, constantRouter } from '@/router/index';
|
||||
import { generatorDynamicRouter } from '@/router/generator-routers';
|
||||
import { generateDynamicRoutes } from '@/router/generator';
|
||||
import { useProjectSetting } from '@/hooks/setting/useProjectSetting';
|
||||
|
||||
interface TreeHelperConfig {
|
||||
@@ -23,9 +23,9 @@ const getConfig = (config: Partial<TreeHelperConfig>) => Object.assign({}, DEFAU
|
||||
export interface IAsyncRouteState {
|
||||
menus: RouteRecordRaw[];
|
||||
routers: any[];
|
||||
addRouters: any[];
|
||||
routersAdded: any[];
|
||||
keepAliveComponents: string[];
|
||||
isDynamicAddedRoute: boolean;
|
||||
isDynamicRouteAdded: boolean;
|
||||
}
|
||||
|
||||
function filter<T = any>(
|
||||
@@ -53,61 +53,60 @@ export const useAsyncRouteStore = defineStore({
|
||||
state: (): IAsyncRouteState => ({
|
||||
menus: [],
|
||||
routers: constantRouter,
|
||||
addRouters: [],
|
||||
routersAdded: [],
|
||||
keepAliveComponents: [],
|
||||
// Whether the route has been dynamically added
|
||||
isDynamicAddedRoute: false,
|
||||
isDynamicRouteAdded: false,
|
||||
}),
|
||||
getters: {
|
||||
getMenus(): RouteRecordRaw[] {
|
||||
return this.menus;
|
||||
},
|
||||
getIsDynamicAddedRoute(): boolean {
|
||||
return this.isDynamicAddedRoute;
|
||||
getIsDynamicRouteAdded(): boolean {
|
||||
return this.isDynamicRouteAdded;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
getRouters() {
|
||||
return toRaw(this.addRouters);
|
||||
return toRaw(this.routersAdded);
|
||||
},
|
||||
setDynamicAddedRoute(added: boolean) {
|
||||
this.isDynamicAddedRoute = added;
|
||||
setDynamicRouteAdded(added: boolean) {
|
||||
this.isDynamicRouteAdded = added;
|
||||
},
|
||||
// 设置动态路由
|
||||
setRouters(routers) {
|
||||
this.addRouters = routers;
|
||||
setRouters(routers: RouteRecordRaw[]) {
|
||||
this.routersAdded = routers;
|
||||
this.routers = constantRouter.concat(routers);
|
||||
},
|
||||
setMenus(menus) {
|
||||
setMenus(menus: RouteRecordRaw[]) {
|
||||
// 设置动态路由
|
||||
this.menus = menus;
|
||||
},
|
||||
setKeepAliveComponents(compNames) {
|
||||
setKeepAliveComponents(compNames: string[]) {
|
||||
// 设置需要缓存的组件
|
||||
this.keepAliveComponents = compNames;
|
||||
},
|
||||
async generateRoutes(data) {
|
||||
let accessedRouters;
|
||||
const permissionsList = data.permissions || [];
|
||||
const permissionsList = data.permissions ?? [];
|
||||
const routeFilter = (route) => {
|
||||
const { meta } = route;
|
||||
const { permissions } = meta || {};
|
||||
if (!permissions) return true;
|
||||
return permissionsList.some((item) => permissions.includes(item.value));
|
||||
};
|
||||
const { getPermissionMode } = useProjectSetting();
|
||||
const permissionMode = unref(getPermissionMode);
|
||||
if (permissionMode === 'BACK') {
|
||||
const { permissionMode } = useProjectSetting();
|
||||
if (unref(permissionMode) === 'BACK') {
|
||||
// 动态获取菜单
|
||||
try {
|
||||
accessedRouters = await generatorDynamicRouter();
|
||||
accessedRouters = await generateDynamicRoutes();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
//过滤账户是否拥有某一个权限,并将菜单从加载列表移除
|
||||
accessedRouters = filter([...asyncRoutes, ...constantRouter], routeFilter);
|
||||
accessedRouters = filter(asyncRoutes, routeFilter);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
@@ -121,6 +120,6 @@ export const useAsyncRouteStore = defineStore({
|
||||
});
|
||||
|
||||
// Need to be used outside the setup
|
||||
export function useAsyncRouteStoreWidthOut() {
|
||||
export function useAsyncRoute() {
|
||||
return useAsyncRouteStore(store);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,6 @@ export const useDesignSettingStore = defineStore({
|
||||
});
|
||||
|
||||
// Need to be used outside the setup
|
||||
export function useDesignSettingWithOut() {
|
||||
export function useDesignSetting() {
|
||||
return useDesignSettingStore(store);
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
const allModules = import.meta.globEager('./*/index.ts');
|
||||
const modules = {} as any;
|
||||
Object.keys(allModules).forEach((path) => {
|
||||
const fileName = path.split('/')[1];
|
||||
modules[fileName] = allModules[path][fileName] || allModules[path].default || allModules[path];
|
||||
});
|
||||
|
||||
// export default modules
|
||||
import asyncRoute from './async-route';
|
||||
import user from './user';
|
||||
import tabsView from './tabs-view';
|
||||
import lockscreen from './lockscreen';
|
||||
|
||||
export default {
|
||||
asyncRoute,
|
||||
user,
|
||||
tabsView,
|
||||
lockscreen,
|
||||
};
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user