diff --git a/admin/README.md b/admin/README.md deleted file mode 100644 index 22ee8f4..0000000 --- a/admin/README.md +++ /dev/null @@ -1,27 +0,0 @@ -## vite configuration - -See [Vite Configuration Reference](https://vitejs.dev/config/). - -## Project Setup - -```sh -npm install -``` - -### Development - -```sh -npm run dev -``` - -### Production - -```sh -npm run build -``` - -### Lint with [ESLint](https://eslint.org/) - -```sh -npm run lint -``` diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 602de0f..f27625e 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -5,6 +5,10 @@ export default defineConfig({ base:'/x_admin/', title: "x_admin", description: "x_admin 开发文档", + + markdown: { + lineNumbers: true + }, themeConfig: { // https://vitepress.dev/reference/default-theme-config nav: [ @@ -23,6 +27,10 @@ export default defineConfig({ { text: '准备', link: '/server/准备.md' }, { text: 'Go打包', link: '/server/部署Go.md' }, { text: 'nginx配置', link: '/server/nginx配置.md' }, + { text: '.env配置选项', link: '/server/环境变量.md' }, + { text: '权限验证', link: '/server/权限验证.md' }, + { text: '结构说明', link: '/server/结构说明.md' }, + { text: '注意事项', link: '/server/注意事项.md' }, ] }, { @@ -31,6 +39,8 @@ export default defineConfig({ { text: '准备', link: '/admin/准备.md' }, { text: 'nginx配置', link: '/admin/nginx配置.md' }, + + { text: '路由', link: '/admin/路由.md' }, ] } ], diff --git a/docs/0.使用.md b/docs/0.使用.md deleted file mode 100644 index 9e704ea..0000000 --- a/docs/0.使用.md +++ /dev/null @@ -1,48 +0,0 @@ -# 前期准备 - -后端 -1. 安装 go -2. 安装 mysql -3. 安装 redis -4. 安装 git -5. 安装 swag: `go install github.com/swaggo/swag/cmd/swag@latest` - -前端 -1. 安装 node -2. 安装 pnpm(可选) -3. 安装 git - - -# 使用 - -### 1.下载项目 - -``` -git clone git@gitee.com:xiangheng/x_admin.git -``` - -### 2.创建数据库并导入`x_admin/sql/`目录下 sql 文件 - -### 3.运行后端 -1. 复制并重命名`x_admin/server/.env.example`为`x_admin/server/.env`文件, -2. `.env`必须配置 `mysql` 和 `redis` 信息。 -```bash -cd x_admin/server -# 生成接口文档 -swag init -# 运行, 在vscode中打开server目录中的文件,按F5即可运行 -go run . - -``` - -### 4.运行前端 -1. 复制并重命名`x_admin/admin/.env.development.example`为`x_admin/admin/.env.development`文件, -2. `.env.development`必须配置 `VITE_APP_BASE_URL`后端地址信息。 - -```bash -cd x_admin/admin -# 安装依赖 -pnpm install -# 运行 -pnpm run dev -``` \ No newline at end of file diff --git a/docs/2.nginx配置.md b/docs/2.nginx配置.md deleted file mode 100644 index 0d31d0f..0000000 --- a/docs/2.nginx配置.md +++ /dev/null @@ -1,27 +0,0 @@ - -# nginx配置 -## 反向代理接口 -```nginx -location ^~ /api -{ - proxy_pass http://127.0.0.1:8001; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header REMOTE-HOST $remote_addr; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection $connection_upgrade; - proxy_http_version 1.1; - # proxy_hide_header Upgrade; - - add_header X-Cache $upstream_cache_status; - -} -``` -## 前端页面使用history模式需要重定向 -```nginx -location / { - index /index.html; - try_files $uri $uri/ /index.html; -} -``` \ No newline at end of file diff --git a/docs/admin/nginx配置.md b/docs/admin/nginx配置.md index c14cb53..10f7902 100644 --- a/docs/admin/nginx配置.md +++ b/docs/admin/nginx配置.md @@ -1,7 +1,7 @@ # nginx配置 -``` + ## 前端页面使用history模式需要重定向 ```nginx location / { diff --git a/docs/admin/准备.md b/docs/admin/准备.md index ed86d6d..f6ab036 100644 --- a/docs/admin/准备.md +++ b/docs/admin/准备.md @@ -27,4 +27,6 @@ cd x_admin/admin pnpm install # 运行 pnpm run dev -``` \ No newline at end of file +``` + + diff --git a/docs/admin/路由.md b/docs/admin/路由.md new file mode 100644 index 0000000..7734b0b --- /dev/null +++ b/docs/admin/路由.md @@ -0,0 +1,9 @@ +# 路由 + +1. 扫描`/src/views/`目录下的所有`*.vue`文件,排除`edit.vue`和`/component/**`,生成组件列表供菜单管理选择。 + +2. 在菜单管理中添加 + +3. 在角色中绑定菜单 + +4. 在用户中绑定角色 \ No newline at end of file diff --git a/docs/api-examples.md b/docs/api-examples.md deleted file mode 100644 index 6bd8bb5..0000000 --- a/docs/api-examples.md +++ /dev/null @@ -1,49 +0,0 @@ ---- -outline: deep ---- - -# Runtime API Examples - -This page demonstrates usage of some of the runtime APIs provided by VitePress. - -The main `useData()` API can be used to access site, theme, and page data for the current page. It works in both `.md` and `.vue` files: - -```md - - -## Results - -### Theme Data -
{{ theme }}- -### Page Data -
{{ page }}- -### Page Frontmatter -
{{ frontmatter }}-``` - - - -## Results - -### Theme Data -
{{ theme }}- -### Page Data -
{{ page }}- -### Page Frontmatter -
{{ frontmatter }}- -## More - -Check out the documentation for the [full list of runtime APIs](https://vitepress.dev/reference/runtime-api#usedata). diff --git a/docs/markdown-examples.md b/docs/markdown-examples.md deleted file mode 100644 index f9258a5..0000000 --- a/docs/markdown-examples.md +++ /dev/null @@ -1,85 +0,0 @@ -# Markdown Extension Examples - -This page demonstrates some of the built-in markdown extensions provided by VitePress. - -## Syntax Highlighting - -VitePress provides Syntax Highlighting powered by [Shiki](https://github.com/shikijs/shiki), with additional features like line-highlighting: - -**Input** - -````md -```js{4} -export default { - data () { - return { - msg: 'Highlighted!' - } - } -} -``` -```` - -**Output** - -```js{4} -export default { - data () { - return { - msg: 'Highlighted!' - } - } -} -``` - -## Custom Containers - -**Input** - -```md -::: info -This is an info box. -::: - -::: tip -This is a tip. -::: - -::: warning -This is a warning. -::: - -::: danger -This is a dangerous warning. -::: - -::: details -This is a details block. -::: -``` - -**Output** - -::: info -This is an info box. -::: - -::: tip -This is a tip. -::: - -::: warning -This is a warning. -::: - -::: danger -This is a dangerous warning. -::: - -::: details -This is a details block. -::: - -## More - -Check out the documentation for the [full list of markdown extensions](https://vitepress.dev/guide/markdown). diff --git a/docs/server/权限验证.md b/docs/server/权限验证.md new file mode 100644 index 0000000..8a896fc --- /dev/null +++ b/docs/server/权限验证.md @@ -0,0 +1,14 @@ +# 权限验证 + +路由添加`TokenAuth`中间件,可实现登录验证, + +接口路径就是权限标识,例如:`/api/admin/user`,标识位为`admin:user` +``` +r := rg.Group("/", middleware.TokenAuth()) +``` + +对于路由组下不需要验证的路由 +1. 调整路由顺序,白名单路由在验证路由之前 +2. `server/config/admin.go`添加白名单 + +<<< @/../server/config/admin.go#NotAuth diff --git a/docs/server/注意事项.md b/docs/server/注意事项.md new file mode 100644 index 0000000..4f9c193 --- /dev/null +++ b/docs/server/注意事项.md @@ -0,0 +1,7 @@ + +### Go应该注意的问题 +1. 循环依赖:go不允许循环依赖 +2. Gorm零值不更新:避免数据库出现值0,这能避免很多工作 +3. 软删除,本系统需要IsDelete和DeleteTime字段,https://gorm.io/zh_CN/docs/delete.html#%E6%B7%B7%E5%90%88%E6%A8%A1%E5%BC%8F + +4. 时间:统一用自定义的`core.TsTime` \ No newline at end of file diff --git a/docs/server/环境变量.md b/docs/server/环境变量.md index e69de29..9d979e9 100644 --- a/docs/server/环境变量.md +++ b/docs/server/环境变量.md @@ -0,0 +1,6 @@ +# 环境变量.env +文件`/server/config/config.go`读取.env文件然后合并 + +有`mapstructure`tag的,名称以`mapstructure`为准 + +<<< @/../server/config/config.go#envConfig \ No newline at end of file diff --git a/server/README.md b/docs/server/结构说明.md similarity index 69% rename from server/README.md rename to docs/server/结构说明.md index 7976779..e561dd6 100644 --- a/server/README.md +++ b/docs/server/结构说明.md @@ -4,17 +4,20 @@ 后台接口`api/admin`开头,后台权限及菜单设计以这个为主 -前台接口`api/*`开头,无权限设计,需要自己实现 +static目录:映射为`api/static/*`,通过`go:embed`嵌入到了二进制文件中 + +前台接口`api/*`开头,无设计,需要自己实现 ### 目录结构 ``` ├── server -│ ├── admin // 后台,可以参照添加web,app等模块 +│ ├── admin // 后台 │ │ ├──** //模块 │ │ ├──────/*_ctl.go // 模块控制器 │ │ ├──────/*_schema.go // 模块schema │ │ ├──────/*_service.go // 模块服务 +│ │ ├──generator // 代码生成器 │ ├── config // 配置 │ ├── middleware // 中间件 │ ├── model // 数据库模型 @@ -24,10 +27,4 @@ │ ├── static // 静态文件,访问路由`/api/static/*` │ ├── main.go // 入口 │ ├── .env // 配置文件,注意不提交git -``` - - -### Go应该注意的问题 -1. 循环依赖 -2. 零值更新,避免数据库默认值为0 -3. 软删除,本系统需要IsDelete和DeleteTime字段,https://gorm.io/zh_CN/docs/delete.html#%E6%B7%B7%E5%90%88%E6%A8%A1%E5%BC%8F \ No newline at end of file +``` \ No newline at end of file diff --git a/server.code-workspace b/server.code-workspace index a337fe3..e2a99ed 100644 --- a/server.code-workspace +++ b/server.code-workspace @@ -14,6 +14,9 @@ }, { "path": ".github" + }, + { + "path": ".workflow" } ] } \ No newline at end of file diff --git a/server/config/admin.go b/server/config/admin.go index 092eb8c..10baf1e 100644 --- a/server/config/admin.go +++ b/server/config/admin.go @@ -12,7 +12,7 @@ var AdminConfig = adminConfig{ BackstageTokenKey: "backstage:token:", // 令牌的集合 BackstageTokenSet: "backstage:token:set:", - + // #region NotAuth // 免登录验证 NotLoginUri: []string{ "admin:system:login", // 登录接口 @@ -33,7 +33,7 @@ var AdminConfig = adminConfig{ "admin:setting:dict:data:all", // 所有字典数据 "admin:article:cate:all", // 所有文章分类 }, - + // #endregion NotAuth // 演示模式白名单 ShowWhitelistUri: []string{ "admin:system:login", // 登录接口 diff --git a/server/config/config.go b/server/config/config.go index 72cc4cd..e8750ba 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -11,6 +11,7 @@ import ( var Config = loadConfig(".") +// #region envConfig // envConfig 环境配置 type envConfig struct { RootPath string // 项目根目录 @@ -39,6 +40,8 @@ type envConfig struct { UploadVideoExt []string // 上传视频扩展 } +// #endregion envConfig + // loadConfig 加载配置 func loadConfig(envPath string) envConfig { var cfgPath string