diff --git a/newdocs/docs/.vuepress/navbar.ts b/newdocs/docs/.vuepress/navbar.ts index e259fad9..dbc374bd 100644 --- a/newdocs/docs/.vuepress/navbar.ts +++ b/newdocs/docs/.vuepress/navbar.ts @@ -1,14 +1,15 @@ /* * @Author: yubaolee | ahfu~ <954478625@qq.com> * @Date: 2025-04-23 20:26:48 - * @LastEditTime: 2025-04-24 01:14:49 + * @LastEditTime: 2025-04-26 10:31:59 * @Description: 顶部超链接 * Copyright (c) 2025 by yubaolee | ahfu~ , All Rights Reserved. */ import { defineNavbarConfig } from 'vuepress-theme-plume' export const navbar = defineNavbarConfig([ - { text: '文档首页', link: '/', icon: 'material-symbols:home-outline' }, + { text: '首页', link: 'http://www.openauth.net.cn', icon: 'mdi:home' }, + { text: '文档首页', link: '/', icon: 'mdi:book-open-page-variant' }, { text: '开源版文档', link: '/notes/core/README.md', icon: 'logos:opensource' }, { text: 'vue3版文档', link: '/notes/pro/README.md', icon: 'material-icon-theme:vue' }, { text: 'vue2版文档', link: '/notes/vue2/README.md', icon: 'material-icon-theme:vue' } diff --git a/newdocs/docs/.vuepress/notes.ts b/newdocs/docs/.vuepress/notes.ts index ba7bc1c7..98739e88 100644 --- a/newdocs/docs/.vuepress/notes.ts +++ b/newdocs/docs/.vuepress/notes.ts @@ -1,7 +1,7 @@ /* * @Author: yubaolee | ahfu~ <954478625@qq.com> * @Date: 2025-04-23 20:26:48 - * @LastEditTime: 2025-04-24 10:21:45 + * @LastEditTime: 2025-04-26 10:22:46 * @Description: 笔记配置 * Copyright (c) 2025 by yubaolee | ahfu~ , All Rights Reserved. */ @@ -14,7 +14,7 @@ const coreNote = defineNoteConfig({ sidebar: [ '', { - text: '基础功能', + text: '基础开发', collapsed: false, items: [ 'start', 'specialist', 'deploy', 'deployapi', 'devnew', 'multidbs', 'multitenant', 'unitwork','sqlsugar', 'entity','dynamicapi', 'datavalidation', 'log', 'identity', 'job', 'cache', 'unittest','changesdk' @@ -76,19 +76,16 @@ const proNote = defineNoteConfig({ ] }) -// vue3版本 +// vue2版本 const vue2Note = defineNoteConfig({ dir: 'vue2', link: '/vue2', sidebar: [ '', - 'deploy', - 'structure', - 'devnew', { text: '基础开发', collapsed: false, - items: [ 'router','openurl','keepalive'] + items: [ 'deploy', 'structure', 'devnew','router','openurl','keepalive'] }, 'datapropertyrule', 'printerplan', diff --git a/newdocs/docs/notes/core/cache.md b/newdocs/docs/notes/core/cache.md index 667eebf6..7ebe25dd 100644 --- a/newdocs/docs/notes/core/cache.md +++ b/newdocs/docs/notes/core/cache.md @@ -34,12 +34,12 @@ public static void InitAutofac(ContainerBuilder builder) _cacheContext.Set(currentSession.Token, currentSession, DateTime.Now.AddDays(10)); ``` -::: warning 注意事项1 +::: warning 注意1 默认使用的是.net的内存Cache,在用IIS发布后,由于IIS本身存在自动回收的机制,会导致系统缓存20分钟就会失效。 ::: -::: warning 注意事项2 +::: warning 注意2 如果使用Redis缓存,注意调整配置文件中关于redis的配置 ```csharp diff --git a/newdocs/docs/notes/core/datavalidation.md b/newdocs/docs/notes/core/datavalidation.md index a8d135bf..16bdfc1a 100644 --- a/newdocs/docs/notes/core/datavalidation.md +++ b/newdocs/docs/notes/core/datavalidation.md @@ -1,13 +1,14 @@ --- -title: WebApi请求验证 +title: 接口数据验证 createTime: 2025/04/23 21:03:10 permalink: /core/datavalidation/ --- -# WebApi请求验证 -框架提供灵活的实体模型验证功能。可以方便地对实体进行验证。只需两步即可: +数据验证是做接口开发时一个非常重要的功能,它用来确保调用API时传入的数据完整和正确。框架提供灵活的实体模型验证功能。可以方便地对实体进行验证。只需两步即可: +1. 在实体类中使用特性(Attributes)来定义验证规则。 +2. 业务代码中执行验证 -## 增加注解 +## 定义验证规则 在请求参数中添加验证注解 @@ -42,7 +43,7 @@ namespace OpenAuth.App.Request } ``` -## 业务代码中验证 +## 执行验证 在OpenAuth.App中调用验证 diff --git a/newdocs/docs/notes/core/entity.md b/newdocs/docs/notes/core/entity.md index 819858a7..b635a61e 100644 --- a/newdocs/docs/notes/core/entity.md +++ b/newdocs/docs/notes/core/entity.md @@ -1,9 +1,11 @@ --- -title: 数据库实体 +title: 数据库主键 createTime: 2025/04/23 21:03:10 permalink: /core/entity/ --- +目前框架主键默认为`Id`,类型为String,如果需要修改主键名称或类型,可以参考本章节内容。 + ## 更换主键名称 系统默认的主键是以`Id`命名,如果数据库主键是其他名称,可以直接用注解进行更改: @@ -19,9 +21,9 @@ permalink: /core/entity/ - `StringEntity`:针对数据库主键为varchar类型的数据表,主键按guid方式生成; -- `LongEntity`:针对数据库主键为numberic(15)的数据表,主键按雪花算法生成;【新功能,官方推荐使用方式👍】 +- `LongEntity`:针对数据库主键为numberic(15)的数据表,主键按雪花算法生成; -- `IntAutoGenEntity`:针对数据库主键为numberic且为数据库自动生成的类型表,通常为SqlServer的自动增长类型和Oracle的Sequence生成;【新功能】 +- `IntAutoGenEntity`:针对数据库主键为numberic且为数据库自动生成的类型表,通常为SqlServer的自动增长类型和Oracle的Sequence生成; 这三个基类可以覆盖90%以上的业务场景。如果这两个不能满足需求,可以自己按需求扩展。参考代码如下: @@ -123,9 +125,3 @@ namespace OpenAuth.App 然后就可以像其他应用服务一样使用这个服务 -::: warning 注意 -最新版才支持,以前的版本(2.0或以前的版本)可以参考BaseEntity进行改造 - -::: - - diff --git a/newdocs/docs/notes/core/form.md b/newdocs/docs/notes/core/form.md index 985793ef..f992185f 100644 --- a/newdocs/docs/notes/core/form.md +++ b/newdocs/docs/notes/core/form.md @@ -10,7 +10,7 @@ OpenAuth.Net集成了表单设计的功能,目前表单仅用于流程审批 动态表单基于Ueditor富文本编辑器,适用于灵活设计界面,逻辑简单的表单。这种表单无需编码,即可直接集成到流程功能。 -::: warning 注意事项 +::: warning 注意 因Vform功能已经全面覆盖Ueditor,且用户体验更好,所以动态表单在vue3版本已废弃,目前开源版、vue2版本历史原因还保留。 ::: diff --git a/newdocs/docs/notes/core/identity.md b/newdocs/docs/notes/core/identity.md index e54142a0..fceb9deb 100644 --- a/newdocs/docs/notes/core/identity.md +++ b/newdocs/docs/notes/core/identity.md @@ -1,9 +1,11 @@ --- title: 登录认证 createTime: 2025/04/23 21:03:10 +headerDepth: 4 permalink: /core/identity/ --- +## 前言 OpenAuth.Net支持两种登录认证方式:token认证和自己搭建的OpenAuth.IdentityServer认证。 这两种方式通过配置webapi或mvc的appsettings.json可以自由切换: @@ -11,8 +13,13 @@ OpenAuth.Net支持两种登录认证方式:token认证和自己搭建的OpenAu ```json "IdentityServerUrl": "http://localhost:12796", //IdentityServer服务器地址。如果为空,则不启用OAuth认证 ``` +## token认证 -1. 当IdentityServerUrl为空时,采用普通的token认证,这时不需要OpenAuth.Identity启动支持。无论是OpenAuth.Mvc还是OpenAuth.WebApi,都会在请求头中添加X-Token字段,携带token值。以OpenAuth.WebApi为例,客户端在访问的接口时,先调用登录接口,得到授权token: +当我们启动OpenAuth.WebApi/Mvc时,如果IdentityServerUrl为空,则采用普通的token认证,这时不需要启动OpenAuth.Identity项目: +```json +"IdentityServerUrl": "", //如果为空,则采用普通的token认证 +``` +这时前端发出请求时会在请求头中添加X-Token字段,携带token值。以OpenAuth.WebApi为例,客户端在访问的接口时,先调用登录接口,得到授权token: ![20220119182845](http://img.openauth.net.cn/20220119182845.png) @@ -20,22 +27,27 @@ OpenAuth.Net支持两种登录认证方式:token认证和自己搭建的OpenAu ![20220119182853](http://img.openauth.net.cn/20220119182853.png) -2. 当IdentityServerUrl配置了地址时,则采用自己搭建的OpenAuth.IdentityServer认证方式。 +## OpenAuth.IdentityServer认证 -不同于其他项目的统一登录(如微信登录、支付宝登录等),OpenAuth.Net的统一登录指的是自己搭建一套OAuth登录服务,提供给其他项目使用。即OpenAuth.IdentityServer。这种模式下,无论是OpenAuth.Mvc还是OpenAuth.WebApi,都只是它的客户端。 +不同于其他项目的统一登录(如微信登录、支付宝登录等),OpenAuth.Net的统一登录指的是自己搭建一套OAuth登录服务,提供给其他项目使用。即OpenAuth.IdentityServer。 +当我们启动OpenAuth.WebApi/Mvc时,如果IdentityServerUrl为空,则采用OAuth认证: +```json +"IdentityServerUrl": "http://localhost:12796", //IdentityServer服务器地址。 +``` +这种模式下,需要先启动OpenAuth.Identity项目,OpenAuth.Mvc或OpenAuth.WebApi项目才能正常运行。 ![2025-03-18-23-12-18](http://img.openauth.net.cn/2025-03-18-23-12-18.png) -## OpenAuth.Mvc OAuth认证 +### OpenAuth.Mvc接入 -当启用了Identity时,系统启动后界面如下: +当启用了Identity时,mvc启动后界面如下: ![2025-04-24-00-24-28](http://img.openauth.net.cn/2025-04-24-00-24-28.png) 这时点击登录超链接,会跳转到OpenAuth.Identity登录界面。效果如下: ![2025-04-24-00-24-40](http://img.openauth.net.cn/2025-04-24-00-24-40.png) -## OpenAuth.WebApi OAuth +### OpenAuth.WebApi接入 当启用了Identity时,客户端调用API需要先通过OpenAuth.IdentityServer服务器的OAuth验证,才能调用接口。OpenAuth.Net调用API的客户端有两种: diff --git a/newdocs/docs/notes/core/multidbs.md b/newdocs/docs/notes/core/multidbs.md index 6e163e2e..6af67339 100644 --- a/newdocs/docs/notes/core/multidbs.md +++ b/newdocs/docs/notes/core/multidbs.md @@ -6,7 +6,7 @@ permalink: /core/multidbs/ 框架支持同时访问多个数据库。具体操作如下: -## 添加新数据库连接字符串 +## 添加新连接字符串 在配置文件appsettings.json中,添加新的连接字符串`OpenAuthDBContext2` @@ -23,7 +23,7 @@ permalink: /core/multidbs/ } ``` -## 添加新的数据上下文 +## 添加数据上下文 在OpenAuth.Repository中添加新的数据库上下文,比如`OpenAuthDBContext2` diff --git a/newdocs/docs/notes/core/sqlsugar.md b/newdocs/docs/notes/core/sqlsugar.md index 783df755..a56e5888 100644 --- a/newdocs/docs/notes/core/sqlsugar.md +++ b/newdocs/docs/notes/core/sqlsugar.md @@ -4,8 +4,16 @@ createTime: 2025/04/23 21:03:10 permalink: /core/sqlsugar/ --- -SqlSugar 是一款老牌.NET开源ORM框架,相对于EntityFramework复杂的Linq表达式,它拥有灵活的动态查询,如果你喜欢直接码Sql,那么它是你的不二之选。OpenAuth.Net 6.0及以后版本默认支持使用SqlSugar方式访问数据库。目前大多数模块都已使用SqlSugar的方式,这里以资源管理为例: +SqlSugar 是一款老牌.NET开源ORM框架,相对于EntityFramework复杂的Linq表达式,它拥有灵活的动态查询,如果你喜欢直接码Sql,那么它是你的不二之选。OpenAuth.Net 6.0及以后版本默认支持使用SqlSugar方式访问数据库。 +框架提供`SqlSugarBaseApp`基类,该基类定义了SqlSugar最常用的两个成员变量: +```csharp +protected ISqlSugarClient SugarClient; //SqlSugar基础数据库读写 +protected SqlSugarRepository Repository; //SqlSugar的仓储模式 +``` +只需要继承该基类,即可使用SqlSugar的强大功能。 + +目前框架大多数模块都已继承`SqlSugarBaseApp`基类,这里以资源管理为例: ```csharp public class ResourceApp:SqlSugarBaseApp { @@ -39,9 +47,10 @@ public class ResourceApp:SqlSugarBaseApp ## 使用方法 -如上所示代码,只需要继承`SqlSugarBaseApp`即可使用SqlSugar强大功能。其中 +当编写业务代码需要使用SqlSugar的模块时,只需要继承`SqlSugarBaseApp`即可使用SqlSugar强大功能。其中 -Repository:实现的是SqlSugar的仓储模式,详细Api请查看:[SqlSugar使用仓储](https://www.donet5.com/Home/Doc?typeId=1228)。在OpenAuth.Net中: +### Repository +实现的是SqlSugar的仓储模式,详细Api请查看:[SqlSugar使用仓储](https://www.donet5.com/Home/Doc?typeId=1228)。在OpenAuth.Net中: ```csharp public class ResourceApp:SqlSugarBaseApp { @@ -52,8 +61,8 @@ public class ResourceApp:SqlSugarBaseApp } } ``` - -SugarClient:即SqlSugar最基础的数据库读写用法。详细Api请查看:[SqlSugar入门必看](https://www.donet5.com/Home/Doc?typeId=1181)。在OpenAuth.Net中: +### SugarClient +SqlSugar基础数据库读写用法。详细Api请查看:[SqlSugar入门必看](https://www.donet5.com/Home/Doc?typeId=1181)。在OpenAuth.Net中: ```csharp public class ResourceApp:SqlSugarBaseApp { diff --git a/newdocs/docs/notes/core/unitwork.md b/newdocs/docs/notes/core/unitwork.md index 6b7fdae7..6a3ee148 100644 --- a/newdocs/docs/notes/core/unitwork.md +++ b/newdocs/docs/notes/core/unitwork.md @@ -1,10 +1,23 @@ --- -title: 数据库读写及事务处理 +title: EF操作数据库 createTime: 2025/04/23 21:03:10 permalink: /core/unitwork/ --- -OpenAuth.Net使用Repository和Unitwork两种方式访问数据库。 +OpenAuth.Net支持EF操作数据库,提供了IRepository和IUnitWork两个接口,分别用于单表操作和事务操作。框架自带的`BaseApp`、`BaseStringApp`、`BaseLongApp`等基类,都包含有这两个接口的实例: + +```csharp +/// +/// 用于普通的数据库操作 +/// +protected IRepository Repository; + +/// +/// 用于事务操作 +/// +protected IUnitWork UnitWork; +``` +因此,当我们编写应用层代码时,只要继承`BaseApp`、`BaseStringApp`、`BaseLongApp`等基类,就可以使用这两个接口。 ## 使用场景 diff --git a/newdocs/docs/notes/pro/README.md b/newdocs/docs/notes/pro/README.md index cf9fdad3..8cd9ed59 100644 --- a/newdocs/docs/notes/pro/README.md +++ b/newdocs/docs/notes/pro/README.md @@ -3,7 +3,7 @@ title: vue3版本介绍 createTime: 2025/04/23 23:43:26 permalink: /pro/ --- -::: warning 注意事项 +::: warning 注意 如果你使用的是vue2版本,请参考:[OpenAuth.Pro Vue2版本](/vue2/) ::: diff --git a/newdocs/docs/notes/pro/start.md b/newdocs/docs/notes/pro/start.md index 5beda607..6462632c 100644 --- a/newdocs/docs/notes/pro/start.md +++ b/newdocs/docs/notes/pro/start.md @@ -21,7 +21,7 @@ permalink: /pro/start/ VITE_BASE_API = http://localhost:52789/api VITE_BASE_IMG_URL = http://localhost:52789 ``` -::: warning 注意事项 +::: warning 注意 如果是发布打包,调整的文件为`.env.production` ::: 使用`npm install`命令安装程序运行所需的第三方包。再用`npm run dev`命令运行。如下图: diff --git a/newdocs/docs/notes/vue2/README.md b/newdocs/docs/notes/vue2/README.md index 283bbfd5..ae1d9e94 100644 --- a/newdocs/docs/notes/vue2/README.md +++ b/newdocs/docs/notes/vue2/README.md @@ -3,7 +3,7 @@ title: vue2版本介绍 createTime: 2025/04/23 23:43:26 permalink: /vue2/ --- -::: warning 注意事项 +::: warning 注意 如果你使用的是vue3版本,请参考:[OpenAuth.Pro Vue3版本](/pro/) ::: @@ -57,7 +57,7 @@ vue2版源代码获取方式:[http://old.openauth.net.cn/question/detail.html? 安装程序运行所需的第三方包。使用npm install 命令经行安装,如下图: ![20211214232207](http://img.openauth.net.cn/20211214232207.png) -::: warning 注意事项 +::: warning 注意 4.6.4及以后的版本默认Node 18进行编译,如果使用的是Node 18以前的版本,请尝试把package.json中scripts改为下面内容: ```javascript @@ -78,7 +78,7 @@ VUE_APP_BASE_API = http://localhost:52789/api VUE_APP_BASE_IMG_URL = http://localhost:52789 ``` -::: warning 注意事项 +::: warning 注意 如果是发布打包,调整的文件为`.env.prod` ::: diff --git a/newdocs/docs/notes/vue2/deploy.md b/newdocs/docs/notes/vue2/deploy.md index 6b69137f..7ccfc638 100644 --- a/newdocs/docs/notes/vue2/deploy.md +++ b/newdocs/docs/notes/vue2/deploy.md @@ -10,7 +10,7 @@ permalink: /vue2/deploy/ ![20211214232752](http://img.openauth.net.cn/20211214232752.png) -::: warning 注意事项 +::: warning 注意 前端部署时使用的配置文件为`.env.prod`,打包构建前请调整为自己的接口地址: ```javascript