mirror of
https://gitee.com/xiangheng/x_admin.git
synced 2025-12-24 08:12:55 +08:00
文档优化
This commit is contained in:
@@ -3,7 +3,7 @@ import { MenuEnum } from '@/enums/appEnums'
|
||||
import { isExternal } from '@/utils/validate'
|
||||
import { constantRoutes, INDEX_ROUTE_NAME, LAYOUT, Empty } from './routes'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
|
||||
import qs from 'query-string'
|
||||
// 匹配views里面所有的.vue文件,动态引入
|
||||
const modules = import.meta.glob('/src/views/**/*.vue')
|
||||
|
||||
@@ -27,6 +27,18 @@ export function filterAsyncRoutes(routes: any[], firstRoute = true) {
|
||||
|
||||
// 创建一条路由记录
|
||||
export function createRouteRecord(route: any, firstRoute: boolean): RouteRecordRaw {
|
||||
let query = route.params
|
||||
|
||||
try {
|
||||
if (route.params) {
|
||||
// console.log(route.params)
|
||||
// query =
|
||||
query = qs.stringify(JSON.parse(route.params))
|
||||
// console.log(query)
|
||||
}
|
||||
} catch (error) {
|
||||
// console.error(error)
|
||||
}
|
||||
//@ts-ignore
|
||||
const routeRecord: RouteRecordRaw = {
|
||||
path: isExternal(route.paths) ? route.paths : firstRoute ? `/${route.paths}` : route.paths,
|
||||
@@ -35,8 +47,8 @@ export function createRouteRecord(route: any, firstRoute: boolean): RouteRecordR
|
||||
hidden: !route.isShow,
|
||||
keepAlive: !!route.isCache,
|
||||
title: route.menuName,
|
||||
perms: route.perms, //逗号分隔的字符串
|
||||
query: route.params,
|
||||
perms: route.perms, //
|
||||
query: query,
|
||||
icon: route.menuIcon,
|
||||
type: route.menuType,
|
||||
activeMenu: route.selected
|
||||
|
||||
23
admin/src/views/IframeComponent.vue
Normal file
23
admin/src/views/IframeComponent.vue
Normal file
@@ -0,0 +1,23 @@
|
||||
vue
|
||||
<template>
|
||||
<div class="h-full">
|
||||
<!-- {{ url }} -->
|
||||
<iframe :src="url" frameborder="0" width="100%" height="100%"></iframe>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
const route = useRoute()
|
||||
const url = computed(() => {
|
||||
return route.query.url as string
|
||||
})
|
||||
|
||||
// const props = defineProps({
|
||||
// url: {
|
||||
// type: String,
|
||||
// default: ''
|
||||
// }
|
||||
// })
|
||||
</script>
|
||||
@@ -108,8 +108,8 @@ export default ({ mode }) => {
|
||||
host: '0.0.0.0',
|
||||
port: 5180,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: env.VITE_APP_BASE_URL,
|
||||
'/api/': {
|
||||
target: env.VITE_APP_BASE_URL + '/',
|
||||
changeOrigin: true,
|
||||
ws: true
|
||||
}
|
||||
|
||||
@@ -45,6 +45,8 @@ export default defineConfig({
|
||||
{ text: 'nginx配置', link: '/admin/nginx配置.md' },
|
||||
|
||||
{ text: '路由', link: '/admin/路由.md' },
|
||||
{ text: '嵌入iframe', link: '/admin/嵌入iframe.md' },
|
||||
|
||||
{ text: '自定义hooks', link: '/admin/自定义hooks.md' },
|
||||
]
|
||||
}
|
||||
|
||||
7
docs/admin/嵌入iframe.md
Normal file
7
docs/admin/嵌入iframe.md
Normal file
@@ -0,0 +1,7 @@
|
||||
## 嵌入iframe
|
||||
1. 添加菜单
|
||||
2. 选择组件路径:IframeComponent
|
||||
3. 路由参数:
|
||||
```
|
||||
{"url": "/api/static/api/index.html"}或者 url=/api/static/api/index.html
|
||||
```
|
||||
@@ -479,7 +479,7 @@ type Foo struct {
|
||||
| minLength | `integer` | 参看 https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2. |
|
||||
| enums | [\*] | 参看 https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.1. |
|
||||
| format | `string` | 上面提到的[类型](#parameterType)的扩展格式。有关更多详细信息,请参见[数据类型格式](https://swagger.io/specification/v2/#dataTypeFormat)。 |
|
||||
| collectionFormat | `string` | 指定query数组参数的格式。 可能的值为: <ul><li>`csv` - 逗号分隔值 `foo,bar`. <li>`ssv` - 空格分隔值 `foo bar`. <li>`tsv` - 制表符分隔值 `foo\tbar`. <li>`pipes` - 管道符分隔值 <code>foo|bar</code>. <li>`multi` - 对应于多个参数实例,而不是单个实例 `foo=bar&foo=baz` 的多个值。这仅对“`query`”或“`formData`”中的参数有效。 </ul> 默认值是 `csv`。 |
|
||||
| collectionFormat | `string` | 指定query数组参数的格式。 可能的值为: <ul><li>`csv` - 逗号分隔值 `foo,bar`.</li> <li>`ssv` - 空格分隔值 `foo bar`. </li><li>`tsv` - 制表符分隔值 `foo\tbar`. </li><li>`pipes` - 管道符分隔值 <code>foo|bar</code>. </li><li>`multi` - 对应于多个参数实例,而不是单个实例 `foo=bar&foo=baz` 的多个值。这仅对“`query`”或“`formData`”中的参数有效。</li> </ul> 默认值是 `csv`。 |
|
||||
|
||||
### 进一步的
|
||||
|
||||
@@ -714,15 +714,4 @@ type Resp struct {
|
||||
// @scope.write Grants write access
|
||||
// @scope.admin Grants read and write access to administrative information
|
||||
```
|
||||
|
||||
每个API操作。
|
||||
|
||||
```go
|
||||
// @Security ApiKeyAuth
|
||||
```
|
||||
|
||||
使用AND条件。
|
||||
|
||||
```go
|
||||
// @Security ApiKeyAuth && OAuth2Application[write, admin]
|
||||
```
|
||||
|
||||
@@ -1,51 +1,38 @@
|
||||
# 数据库null值
|
||||
## 数据库null值
|
||||
|
||||
问题点:数据库在int,string等类型时,同时可能允许null值,但是go中int不允许null值,读取等操作可能报错。
|
||||
问题点:数据库在int,string等类型时,同时可能允许null值,但是go中int,string等类型不允许null值,数据类型不一致就会报错。
|
||||
|
||||
注:数据库应尽量避免允许null值,避免不了时使用:https://github.com/guregu/null
|
||||
|
||||
相关解读:https://blog.csdn.net/qq_15437667/article/details/78780945
|
||||
|
||||
第三方库:https://pkg.go.dev/database/sql#NullInt64
|
||||
```go
|
||||
// 示例
|
||||
type NullInt64 struct {
|
||||
Int64 int64
|
||||
Valid bool // Valid is true if Int64 is not NULL
|
||||
}
|
||||
func (n *NullInt64) Scan(value any) error
|
||||
func (n NullInt64) Value() (driver.Value, error)
|
||||
## 解决方法,自定义结构体实现以下接口
|
||||
用于Gorm等数据库插件的扫描和写入数据库。
|
||||
```
|
||||
func (i *NullString) Scan(value any) error
|
||||
func (i NullString) Value() (driver.Value, error)
|
||||
```
|
||||
可以实现JSON序列化和反序列化。
|
||||
```
|
||||
func (i NullString) MarshalJSON() ([]byte, error)
|
||||
func (i *NullString) UnmarshalJSON(data []byte) error
|
||||
```
|
||||
用于gin框架的地址栏param参数绑定接口
|
||||
```
|
||||
func (i *NullString) UnmarshalParam(param string) error
|
||||
```
|
||||
用于fmt等格式化输出(可选)
|
||||
```
|
||||
func (i NullString) String() string
|
||||
```
|
||||
|
||||
第三方库(继承database/sql并补充json等):https://github.com/guregu/null
|
||||
```go
|
||||
// 示例
|
||||
type Int struct {
|
||||
sql.NullInt64
|
||||
}
|
||||
func (i *Int) UnmarshalJSON(data []byte) error {
|
||||
err := internal.UnmarshalIntJSON(data, &i.Int64, &i.Valid, 64, strconv.ParseInt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i.Valid = i.Int64 != 0
|
||||
return nil
|
||||
}
|
||||
func (i Int) MarshalJSON() ([]byte, error) {
|
||||
n := i.Int64
|
||||
if !i.Valid {
|
||||
n = 0
|
||||
}
|
||||
return []byte(strconv.FormatInt(n, 10)), nil
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### 自带了三个可为null类型:
|
||||
1. 相对于guregu/null的优点
|
||||
2. NullFloat、NullInt:支持前端传递null、字符串数字、数字
|
||||
### 扩展了四个可为null类型:
|
||||
1. NullFloat、NullInt:支持前端传递null、字符串数字、数字
|
||||
```go
|
||||
core.NullFloat
|
||||
core.NullInt
|
||||
core.NullString
|
||||
core.NullTime
|
||||
```
|
||||
```
|
||||
|
||||
### 参考:
|
||||
1. https://blog.csdn.net/qq_15437667/article/details/78780945
|
||||
2. https://pkg.go.dev/database/sql#NullInt64
|
||||
3. https://github.com/guregu/null
|
||||
@@ -1,9 +1,12 @@
|
||||
# 权限验证
|
||||
路由添加`LoginAuth`中间件,可实现登录验证,
|
||||
|
||||
路由添加`TokenAuth`中间件,可实现登录验证,
|
||||
路由添加`TokenAuth`中间件,可实现登录、菜单授权验证, `权限标识`由`接口路径`确定,例如:`/api/admin/user`,标识位为`admin:user`
|
||||
```go
|
||||
// 表示该路由下的所有接口都需要登录
|
||||
r := rg.Group("/", middleware.LoginAuth())
|
||||
|
||||
接口路径就是权限标识,例如:`/api/admin/user`,标识位为`admin:user`
|
||||
```
|
||||
// 表示该路由下的所有接口都需要登录、菜单授权
|
||||
r := rg.Group("/", middleware.TokenAuth())
|
||||
```
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 环境变量.env
|
||||
文件`/server/config/config.go`读取.env文件然后合并
|
||||
文件`/server/config/init.go`读取.env文件然后合并
|
||||
|
||||
有`mapstructure`tag的,名称以`mapstructure`为准
|
||||
有`mapstructure`tag的,名称以`mapstructure`为准,尽量以大驼峰命名
|
||||
|
||||
<<< @/../server/config/config.go#envConfig
|
||||
<<< @/../server/config/init.go#envConfig
|
||||
@@ -16,6 +16,7 @@ static目录:映射为`api/static/*`,通过`go:embed`嵌入到了二进制
|
||||
│ │ ├──────controller //控制器
|
||||
│ │ ├──────service // 服务
|
||||
│ │ ├──────schema // 结构体
|
||||
│ │ ├──────cron // 定时任务
|
||||
│ ├── config // 配置
|
||||
│ ├── core // core
|
||||
│ ├── middleware // 中间件
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# 打包
|
||||
## 方式一:直接打包
|
||||
```bash
|
||||
# linux
|
||||
# 在linux打包
|
||||
go build -o x_admin .
|
||||
# window
|
||||
# 在window打包
|
||||
go build -o x_admin.exe .
|
||||
```
|
||||
|
||||
@@ -15,20 +15,25 @@ go install github.com/goreleaser/goreleaser@latest
|
||||
goreleaser release --snapshot --clean
|
||||
```
|
||||
|
||||
|
||||
## 方式三:运行pack.bat文件打包
|
||||
```
|
||||
在window运行pack.bat文件, 可以夸平台打包,压缩打包后产物;请按需取消注释
|
||||
```
|
||||
# 部署
|
||||
|
||||
## 上传所有需要的文件
|
||||
- 打包后的二进制文件.exe
|
||||
- resources/*
|
||||
- public/*
|
||||
- .env
|
||||
|
||||
|
||||
|
||||
## 管理进程
|
||||
我是前端er,所以我推荐使用pm2管理进程
|
||||
https://pm2.io/
|
||||
1. 推荐使用pm2管理进程,因为我是前端
|
||||
|
||||
```bash
|
||||
# https://pm2.io/
|
||||
|
||||
# 需要node环境
|
||||
npm install pm2 -g
|
||||
# 之前有一种不依赖node直接安装,好像不能用了,没找见
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# 属性大驼峰命名,不使用全大写
|
||||
# 具体配置项参考:config\config.go的config结构体
|
||||
|
||||
# APP.GIN_MODE='debug'
|
||||
# APP.GinMode='debug'
|
||||
|
||||
# 项目端口
|
||||
APP.Port=8001
|
||||
|
||||
1
server/.gitignore
vendored
1
server/.gitignore
vendored
@@ -1,6 +1,7 @@
|
||||
### Go ###
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
!upx.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
|
||||
@@ -13,9 +13,9 @@ xcopy ".env" ".\dist\bin\windows\" /Y /I
|
||||
@REM # 1 目标平台的体系架构(386、amd64、arm)
|
||||
set GOARCH=amd64
|
||||
@REM #2 目标平台的操作系统(darwin、freebsd、linux、windows)
|
||||
@REM set GOOS=linux
|
||||
@REM go build -ldflags "-s -w" -o ./dist/bin/linux/x-admin
|
||||
@REM .\upx.exe ./dist/bin/linux/x-admin
|
||||
set GOOS=linux
|
||||
go build -ldflags "-s -w" -o ./dist/bin/linux/x-admin
|
||||
.\upx.exe ./dist/bin/linux/x-admin
|
||||
|
||||
@REM 打包window
|
||||
set GOOS=windows
|
||||
|
||||
BIN
server/upx.exe
Normal file
BIN
server/upx.exe
Normal file
Binary file not shown.
Reference in New Issue
Block a user