完善文档

This commit is contained in:
xiangheng
2024-06-28 16:21:11 +08:00
parent 43a40d1a60
commit 5ada617e8b
16 changed files with 64 additions and 249 deletions

View File

@@ -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
```

View File

@@ -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' },
]
}
],

View File

@@ -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
```

View File

@@ -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;
}
```

View File

@@ -1,7 +1,7 @@
# nginx配置
```
## 前端页面使用history模式需要重定向
```nginx
location / {

View File

@@ -27,4 +27,6 @@ cd x_admin/admin
pnpm install
# 运行
pnpm run dev
```
```
<!-- <<< @/../admin/package.json#snippet{6-14} -->

9
docs/admin/路由.md Normal file
View File

@@ -0,0 +1,9 @@
# 路由
1. 扫描`/src/views/`目录下的所有`*.vue`文件,排除`edit.vue``/component/**`,生成组件列表供菜单管理选择。
2. 在菜单管理中添加
3. 在角色中绑定菜单
4. 在用户中绑定角色

View File

@@ -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
<script setup>
import { useData } from 'vitepress'
const { theme, page, frontmatter } = useData()
</script>
## Results
### Theme Data
<pre>{{ theme }}</pre>
### Page Data
<pre>{{ page }}</pre>
### Page Frontmatter
<pre>{{ frontmatter }}</pre>
```
<script setup>
import { useData } from 'vitepress'
const { site, theme, page, frontmatter } = useData()
</script>
## Results
### Theme Data
<pre>{{ theme }}</pre>
### Page Data
<pre>{{ page }}</pre>
### Page Frontmatter
<pre>{{ frontmatter }}</pre>
## More
Check out the documentation for the [full list of runtime APIs](https://vitepress.dev/reference/runtime-api#usedata).

View File

@@ -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).

View File

@@ -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

View File

@@ -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`

View File

@@ -0,0 +1,6 @@
# 环境变量.env
文件`/server/config/config.go`读取.env文件然后合并
`mapstructure`tag的名称以`mapstructure`为准
<<< @/../server/config/config.go#envConfig

View File

@@ -4,17 +4,20 @@
后台接口`api/admin`开头,后台权限及菜单设计以这个为主
前台接口`api/*`开头,无权限设计,需要自己实现
static目录映射为`api/static/*`,通过`go:embed`嵌入到了二进制文件中
前台接口`api/*`开头,无设计,需要自己实现
### 目录结构
```
├── server
│ ├── admin // 后台,可以参照添加webapp等模块
│ ├── 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
```

View File

@@ -14,6 +14,9 @@
},
{
"path": ".github"
},
{
"path": ".workflow"
}
]
}

View File

@@ -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", // 登录接口

View File

@@ -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