提交 e787c007 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

Merge branch 'gva_gormv2_dev' of https://github.com/flipped-aurora/gin-vue-admin into gva_workflow

 Conflicts:
	server/gva/init_data/init_data.go
...@@ -24,6 +24,7 @@ yarn-error.log* ...@@ -24,6 +24,7 @@ yarn-error.log*
go.sum go.sum
/server/log/ /server/log/
/server/gva
/server/latest_log /server/latest_log
*.iml *.iml
...@@ -70,7 +70,7 @@ We are excited that you are interested in contributing to gin-vue-admin. Before ...@@ -70,7 +70,7 @@ We are excited that you are interested in contributing to gin-vue-admin. Before
``` ```
- node version > v8.6.0 - node version > v8.6.0
- golang version >= v1.11 - golang version >= v1.14
- IDE recommendation: Goland - IDE recommendation: Goland
- We recommend you to apply for your own cloud service in QINIU. Replace the public key, private key, warehouse name and default url address with your own, so as not to mess up the test database. - We recommend you to apply for your own cloud service in QINIU. Replace the public key, private key, warehouse name and default url address with your own, so as not to mess up the test database.
``` ```
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
[English](./README-en.md) | 简体中文 [English](./README-en.md) | 简体中文
[国内仓库地址](https://gitee.com/FLIPPED-AURORA/gin-vue-admin)
# 项目文档 # 项目文档
[在线文档](https://www.gin-vue-admin.com/) : https://www.gin-vue-admin.com/ [在线文档](https://www.gin-vue-admin.com/) : https://www.gin-vue-admin.com/
...@@ -65,7 +67,7 @@ Gin-vue-admin 的成长离不开大家的支持,如果你愿意为 gin-vue-adm ...@@ -65,7 +67,7 @@ Gin-vue-admin 的成长离不开大家的支持,如果你愿意为 gin-vue-adm
``` ```
- node版本 > v8.6.0 - node版本 > v8.6.0
- golang版本 >= v1.11 - golang版本 >= v1.14
- IDE推荐:Goland - IDE推荐:Goland
- gormv2版本初始化数据库可以利用批量创建功能,这里已经写好初始化代码,需要在main.go内打开 initialize.Data() 的注释即可 - gormv2版本初始化数据库可以利用批量创建功能,这里已经写好初始化代码,需要在main.go内打开 initialize.Data() 的注释即可
- 替换掉项目中的七牛云公钥,私钥,仓名和默认url地址,以免发生测试文件数据错乱 - 替换掉项目中的七牛云公钥,私钥,仓名和默认url地址,以免发生测试文件数据错乱
......
.PHONY: all build run gotool clean help
BINARY="server"
GVA = "gva"
all: check gva initdb run
gva:
go build -o ${GVA} cmd/main.go
initdb:
@if [ -f ${GVA} ] ; then ./gva initdb && rm ${GVA} ; fi
linux-build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build
windows-build:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ${BINARY}.exe
mac-build:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ${BINARY}
run:
@go run main.go
check:
go fmt ./
go vet ./
clean:
@if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi
@if [ -f ${GVA} ] ; then rm ${GVA} ; fi
help:
@echo "make - 格式化 Go 代码, 并编译生成二进制文件"
@echo "make linux-build - 编译 Go 代码, 生成Linux系统的二进制文件"
@echo "make windows-build - 编译 Go 代码, 生成Windows系统的exe文件"
@echo "make mac-build - 编译 Go 代码, 生成Mac系统的二进制文件"
@echo "make run - 直接运行 main.go"
@echo "make clean - 移除二进制文件"
@echo "make check - 运行 Go 工具 'fmt' and 'vet'"
\ No newline at end of file
...@@ -22,7 +22,7 @@ import ( ...@@ -22,7 +22,7 @@ import (
// @Produce application/json // @Produce application/json
// @Param data body model.SysUser true "用户注册接口" // @Param data body model.SysUser true "用户注册接口"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}"
// @Router /base/register [post] // @Router /user/register [post]
func Register(c *gin.Context) { func Register(c *gin.Context) {
var R request.RegisterStruct var R request.RegisterStruct
_ = c.ShouldBindJSON(&R) _ = c.ShouldBindJSON(&R)
......
@echo ##########Formatting code#########################################
go fmt ./ && go vet ./
@echo ##########Format the code successfully############################
@echo ##########Compiling gva.exe#######################################
go build -o gva.exe cmd/main.go
@echo ##########Successfully compiled gva.exe###########################
@echo ##########Initializing data using gva.exe#########################
gva.exe initdb
@echo ##########Use gva.exe to initialize data successfully#############
@echo ##########Deleting gva.exe########################################
del gva.exe
@echo ##########Deleting gva.exe successfully###########################
\ No newline at end of file
package datas
import "gorm.io/gorm"
func InitAuthorityMenu(db *gorm.DB) (err error) {
return db.Exec("CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `authority_menu` AS select `sys_base_menus`.`id` AS `id`,`sys_base_menus`.`created_at` AS `created_at`, `sys_base_menus`.`updated_at` AS `updated_at`, `sys_base_menus`.`deleted_at` AS `deleted_at`, `sys_base_menus`.`menu_level` AS `menu_level`,`sys_base_menus`.`parent_id` AS `parent_id`,`sys_base_menus`.`path` AS `path`,`sys_base_menus`.`name` AS `name`,`sys_base_menus`.`hidden` AS `hidden`,`sys_base_menus`.`component` AS `component`, `sys_base_menus`.`title` AS `title`,`sys_base_menus`.`icon` AS `icon`,`sys_base_menus`.`sort` AS `sort`,`sys_authority_menus`.`sys_authority_authority_id` AS `authority_id`,`sys_authority_menus`.`sys_base_menu_id` AS `menu_id`,`sys_base_menus`.`keep_alive` AS `keep_alive`,`sys_base_menus`.`default_menu` AS `default_menu` from (`sys_authority_menus` join `sys_base_menus` on ((`sys_authority_menus`.`sys_base_menu_id` = `sys_base_menus`.`id`)))").Error
}
package datas
import (
"gin-vue-admin/model"
"time"
"gorm.io/gorm"
)
var Apis = []model.SysApi{
{gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/login", "用户登录", "base", "POST"},
{gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/base/register", "用户注册", "base", "POST"},
{gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/createApi", "创建api", "api", "POST"},
{gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiList", "获取api列表", "api", "POST"},
{gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getApiById", "获取api详细信息", "api", "POST"},
{gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/deleteApi", "删除Api", "api", "POST"},
{gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/updateApi", "更新Api", "api", "POST"},
{gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/api/getAllApis", "获取所有api", "api", "POST"},
{gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/createAuthority", "创建角色", "authority", "POST"},
{gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/deleteAuthority", "删除角色", "authority", "POST"},
{gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/getAuthorityList", "获取角色列表", "authority", "POST"},
{gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenu", "获取菜单树", "menu", "POST"},
{gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenuList", "分页获取基础menu列表", "menu", "POST"},
{gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/addBaseMenu", "新增菜单", "menu", "POST"},
{gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuTree", "获取用户动态路由", "menu", "POST"},
{gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/addMenuAuthority", "增加menu和角色关联关系", "menu", "POST"},
{gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getMenuAuthority", "获取指定角色menu", "menu", "POST"},
{gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/deleteBaseMenu", "删除菜单", "menu", "POST"},
{gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/updateBaseMenu", "更新菜单", "menu", "POST"},
{gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/menu/getBaseMenuById", "根据id获取菜单", "menu", "POST"},
{gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/changePassword", "修改密码", "user", "POST"},
{gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/getUserList", "获取用户列表", "user", "POST"},
{gorm.Model{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserAuthority", "修改用户角色", "user", "POST"},
{gorm.Model{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/upload", "文件上传示例", "fileUploadAndDownload", "POST"},
{gorm.Model{ID: 26, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/getFileList", "获取上传文件列表", "fileUploadAndDownload", "POST"},
{gorm.Model{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/updateCasbin", "更改角色api权限", "casbin", "POST"},
{gorm.Model{ID: 28, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/getPolicyPathByAuthorityId", "获取权限列表", "casbin", "POST"},
{gorm.Model{ID: 29, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/fileUploadAndDownload/deleteFile", "删除文件", "fileUploadAndDownload", "POST"},
{gorm.Model{ID: 30, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/jwt/jsonInBlacklist", "jwt加入黑名单", "jwt", "POST"},
{gorm.Model{ID: 31, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/setDataAuthority", "设置角色资源权限", "authority", "POST"},
{gorm.Model{ID: 32, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getSystemConfig", "获取配置文件内容", "system", "POST"},
{gorm.Model{ID: 33, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/setSystemConfig", "设置配置文件内容", "system", "POST"},
{gorm.Model{ID: 34, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "创建客户", "customer", "POST"},
{gorm.Model{ID: 35, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "更新客户", "customer", "PUT"},
{gorm.Model{ID: 36, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "删除客户", "customer", "DELETE"},
{gorm.Model{ID: 37, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customer", "获取单一客户", "customer", "GET"},
{gorm.Model{ID: 38, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/customer/customerList", "获取客户列表", "customer", "GET"},
{gorm.Model{ID: 39, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/casbin/casbinTest/:pathParam", "RESTFUL模式测试", "casbin", "GET"},
{gorm.Model{ID: 40, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/createTemp", "自动化代码", "autoCode", "POST"},
{gorm.Model{ID: 41, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/updateAuthority", "更新角色信息", "authority", "PUT"},
{gorm.Model{ID: 42, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/authority/copyAuthority", "拷贝角色", "authority", "POST"},
{gorm.Model{ID: 43, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/deleteUser", "删除用户", "user", "DELETE"},
{gorm.Model{ID: 44, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/createSysDictionaryDetail", "新增字典内容", "sysDictionaryDetail", "POST"},
{gorm.Model{ID: 45, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/deleteSysDictionaryDetail", "删除字典内容", "sysDictionaryDetail", "DELETE"},
{gorm.Model{ID: 46, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/updateSysDictionaryDetail", "更新字典内容", "sysDictionaryDetail", "PUT"},
{gorm.Model{ID: 47, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/findSysDictionaryDetail", "根据ID获取字典内容", "sysDictionaryDetail", "GET"},
{gorm.Model{ID: 48, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionaryDetail/getSysDictionaryDetailList", "获取字典内容列表", "sysDictionaryDetail", "GET"},
{gorm.Model{ID: 49, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/createSysDictionary", "新增字典", "sysDictionary", "POST"},
{gorm.Model{ID: 50, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/deleteSysDictionary", "删除字典", "sysDictionary", "DELETE"},
{gorm.Model{ID: 51, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/updateSysDictionary", "更新字典", "sysDictionary", "PUT"},
{gorm.Model{ID: 52, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/findSysDictionary", "根据ID获取字典", "sysDictionary", "GET"},
{gorm.Model{ID: 53, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysDictionary/getSysDictionaryList", "获取字典列表", "sysDictionary", "GET"},
{gorm.Model{ID: 54, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/createSysOperationRecord", "新增操作记录", "sysOperationRecord", "POST"},
{gorm.Model{ID: 55, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecord", "删除操作记录", "sysOperationRecord", "DELETE"},
{gorm.Model{ID: 56, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/findSysOperationRecord", "根据ID获取操作记录", "sysOperationRecord", "GET"},
{gorm.Model{ID: 57, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/getSysOperationRecordList", "获取操作记录列表", "sysOperationRecord", "GET"},
{gorm.Model{ID: 58, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getTables", "获取数据库表", "autoCode", "GET"},
{gorm.Model{ID: 59, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getDB", "获取所有数据库", "autoCode", "GET"},
{gorm.Model{ID: 60, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getColume", "获取所选table的所有字段", "autoCode", "GET"},
{gorm.Model{ID: 61, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecordByIds", "批量删除操作历史", "sysOperationRecord", "DELETE"},
{gorm.Model{ID: 62, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/upload", "插件版分片上传", "simpleUploader", "POST"},
{gorm.Model{ID: 63, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/checkFileMd5", "文件完整度验证", "simpleUploader", "GET"},
{gorm.Model{ID: 64, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/mergeFileMd5", "上传完成合并文件", "simpleUploader", "GET"},
{gorm.Model{ID: 65, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/user/setUserInfo", "设置用户信息", "user", "PUT"},
{gorm.Model{ID: 66, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/system/getServerInfo", "获取服务器信息", "system", "POST"},
{gorm.Model{ID: 67, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/email/emailTest", "发送测试邮件", "email", "POST"},
}
func InitSysApi(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error {
if tx.Create(&Apis).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
}
package datas
import (
"time"
"gin-vue-admin/model"
"gorm.io/gorm"
)
var Authorities = []model.SysAuthority{
{CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "888", AuthorityName: "普通用户", ParentId: "0"},
{CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "8881", AuthorityName: "普通用户子角色", ParentId: "888"},
{CreatedAt: time.Now(), UpdatedAt: time.Now(), AuthorityId: "9528", AuthorityName: "测试角色", ParentId: "0"},
}
func InitSysAuthority(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error {
if tx.Create(&Authorities).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
}
package datas
import (
"gorm.io/gorm"
)
type SysDataAuthorityId struct {
SysAuthorityAuthorityId string
DataAuthorityIdAuthorityId string
}
var DataAuthorityId = []SysDataAuthorityId{
{"888", "888"},
{"888", "8881"},
{"888", "9528"},
{"9528", "8881"},
{"9528", "9528"},
}
func InitSysDataAuthorityId(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error {
if tx.Create(&DataAuthorityId).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
}
package datas
import (
"gorm.io/gorm"
)
type SysAuthorityMenus struct {
SysAuthorityAuthorityId string
SysBaseMenuId uint
}
var AuthorityMenus = []SysAuthorityMenus{
{"888", 1},
{"888", 2},
{"888", 3},
{"888", 4},
{"888", 5},
{"888", 6},
{"888", 7},
{"888", 8},
{"888", 9},
{"888", 10},
{"888", 11},
{"888", 12},
{"888", 13},
{"888", 14},
{"888", 15},
{"888", 16},
{"888", 17},
{"888", 18},
{"888", 19},
{"888", 20},
{"888", 21},
{"888", 22},
{"888", 23},
{"888", 24},
{"888", 25},
{"888", 26},
{"888", 27},
{"8881", 1},
{"8881", 2},
{"8881", 8},
{"8881", 17},
{"8881", 18},
{"8881", 19},
{"8881", 20},
{"9528", 1},
{"9528", 2},
{"9528", 3},
{"9528", 4},
{"9528", 5},
{"9528", 6},
{"9528", 7},
{"9528", 8},
{"9528", 9},
{"9528", 10},
{"9528", 11},
{"9528", 12},
{"9528", 13},
{"9528", 14},
{"9528", 15},
{"9528", 17},
{"9528", 18},
{"9528", 19},
{"9528", 20},
}
func InitSysAuthorityMenus(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error {
if tx.Create(&AuthorityMenus).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
}
package datas
import (
gormadapter "github.com/casbin/gorm-adapter/v3"
"gorm.io/gorm"
)
var Carbines = []gormadapter.CasbinRule{
{PType: "p", V0: "888", V1: "/base/login", V2: "POST"},
{PType: "p", V0: "888", V1: "/base/register", V2: "POST"},
{PType: "p", V0: "888", V1: "/api/createApi", V2: "POST"},
{PType: "p", V0: "888", V1: "/api/getApiList", V2: "POST"},
{PType: "p", V0: "888", V1: "/api/getApiById", V2: "POST"},
{PType: "p", V0: "888", V1: "/api/deleteApi", V2: "POST"},
{PType: "p", V0: "888", V1: "/api/updateApi", V2: "POST"},
{PType: "p", V0: "888", V1: "/api/getAllApis", V2: "POST"},
{PType: "p", V0: "888", V1: "/authority/createAuthority", V2: "POST"},
{PType: "p", V0: "888", V1: "/authority/deleteAuthority", V2: "POST"},
{PType: "p", V0: "888", V1: "/authority/getAuthorityList", V2: "POST"},
{PType: "p", V0: "888", V1: "/authority/setDataAuthority", V2: "POST"},
{PType: "p", V0: "888", V1: "/authority/updateAuthority", V2: "PUT"},
{PType: "p", V0: "888", V1: "/authority/copyAuthority", V2: "POST"},
{PType: "p", V0: "888", V1: "/menu/getMenu", V2: "POST"},
{PType: "p", V0: "888", V1: "/menu/getMenuList", V2: "POST"},
{PType: "p", V0: "888", V1: "/menu/addBaseMenu", V2: "POST"},
{PType: "p", V0: "888", V1: "/menu/getBaseMenuTree", V2: "POST"},
{PType: "p", V0: "888", V1: "/menu/addMenuAuthority", V2: "POST"},
{PType: "p", V0: "888", V1: "/menu/getMenuAuthority", V2: "POST"},
{PType: "p", V0: "888", V1: "/menu/deleteBaseMenu", V2: "POST"},
{PType: "p", V0: "888", V1: "/menu/updateBaseMenu", V2: "POST"},
{PType: "p", V0: "888", V1: "/menu/getBaseMenuById", V2: "POST"},
{PType: "p", V0: "888", V1: "/user/changePassword", V2: "POST"},
{PType: "p", V0: "888", V1: "/user/getUserList", V2: "POST"},
{PType: "p", V0: "888", V1: "/user/setUserAuthority", V2: "POST"},
{PType: "p", V0: "888", V1: "/user/deleteUser", V2: "DELETE"},
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/upload", V2: "POST"},
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
{PType: "p", V0: "888", V1: "/casbin/updateCasbin", V2: "POST"},
{PType: "p", V0: "888", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
{PType: "p", V0: "888", V1: "/casbin/casbinTest/:pathParam", V2: "GET"},
{PType: "p", V0: "888", V1: "/jwt/jsonInBlacklist", V2: "POST"},
{PType: "p", V0: "888", V1: "/system/getSystemConfig", V2: "POST"},
{PType: "p", V0: "888", V1: "/system/setSystemConfig", V2: "POST"},
{PType: "p", V0: "888", V1: "/customer/customer", V2: "POST"},
{PType: "p", V0: "888", V1: "/customer/customer", V2: "PUT"},
{PType: "p", V0: "888", V1: "/customer/customer", V2: "DELETE"},
{PType: "p", V0: "888", V1: "/customer/customer", V2: "GET"},
{PType: "p", V0: "888", V1: "/customer/customerList", V2: "GET"},
{PType: "p", V0: "888", V1: "/autoCode/createTemp", V2: "POST"},
{PType: "p", V0: "888", V1: "/autoCode/getTables", V2: "GET"},
{PType: "p", V0: "888", V1: "/autoCode/getDB", V2: "GET"},
{PType: "p", V0: "888", V1: "/autoCode/getColume", V2: "GET"},
{PType: "p", V0: "888", V1: "/sysDictionaryDetail/createSysDictionaryDetail", V2: "POST"},
{PType: "p", V0: "888", V1: "/sysDictionaryDetail/deleteSysDictionaryDetail", V2: "DELETE"},
{PType: "p", V0: "888", V1: "/sysDictionaryDetail/updateSysDictionaryDetail", V2: "PUT"},
{PType: "p", V0: "888", V1: "/sysDictionaryDetail/findSysDictionaryDetail", V2: "GET"},
{PType: "p", V0: "888", V1: "/sysDictionaryDetail/getSysDictionaryDetailList", V2: "GET"},
{PType: "p", V0: "888", V1: "/sysDictionary/createSysDictionary", V2: "POST"},
{PType: "p", V0: "888", V1: "/sysDictionary/deleteSysDictionary", V2: "DELETE"},
{PType: "p", V0: "888", V1: "/sysDictionary/updateSysDictionary", V2: "PUT"},
{PType: "p", V0: "888", V1: "/sysDictionary/findSysDictionary", V2: "GET"},
{PType: "p", V0: "888", V1: "/sysDictionary/getSysDictionaryList", V2: "GET"},
{PType: "p", V0: "888", V1: "/sysOperationRecord/createSysOperationRecord", V2: "POST"},
{PType: "p", V0: "888", V1: "/sysOperationRecord/deleteSysOperationRecord", V2: "DELETE"},
{PType: "p", V0: "888", V1: "/sysOperationRecord/updateSysOperationRecord", V2: "PUT"},
{PType: "p", V0: "888", V1: "/sysOperationRecord/findSysOperationRecord", V2: "GET"},
{PType: "p", V0: "888", V1: "/sysOperationRecord/getSysOperationRecordList", V2: "GET"},
{PType: "p", V0: "888", V1: "/sysOperationRecord/deleteSysOperationRecordByIds", V2: "DELETE"},
{PType: "p", V0: "888", V1: "/user/setUserInfo", V2: "PUT"},
{PType: "p", V0: "888", V1: "/email/emailTest", V2: "POST"},
{PType: "p", V0: "8881", V1: "/base/login", V2: "POST"},
{PType: "p", V0: "8881", V1: "/base/register", V2: "POST"},
{PType: "p", V0: "8881", V1: "/api/createApi", V2: "POST"},
{PType: "p", V0: "8881", V1: "/api/getApiList", V2: "POST"},
{PType: "p", V0: "8881", V1: "/api/getApiById", V2: "POST"},
{PType: "p", V0: "8881", V1: "/api/deleteApi", V2: "POST"},
{PType: "p", V0: "8881", V1: "/api/updateApi", V2: "POST"},
{PType: "p", V0: "8881", V1: "/api/getAllApis", V2: "POST"},
{PType: "p", V0: "8881", V1: "/authority/createAuthority", V2: "POST"},
{PType: "p", V0: "8881", V1: "/authority/deleteAuthority", V2: "POST"},
{PType: "p", V0: "8881", V1: "/authority/getAuthorityList", V2: "POST"},
{PType: "p", V0: "8881", V1: "/authority/setDataAuthority", V2: "POST"},
{PType: "p", V0: "8881", V1: "/menu/getMenu", V2: "POST"},
{PType: "p", V0: "8881", V1: "/menu/getMenuList", V2: "POST"},
{PType: "p", V0: "8881", V1: "/menu/addBaseMenu", V2: "POST"},
{PType: "p", V0: "8881", V1: "/menu/getBaseMenuTree", V2: "POST"},
{PType: "p", V0: "8881", V1: "/menu/addMenuAuthority", V2: "POST"},
{PType: "p", V0: "8881", V1: "/menu/getMenuAuthority", V2: "POST"},
{PType: "p", V0: "8881", V1: "/menu/deleteBaseMenu", V2: "POST"},
{PType: "p", V0: "8881", V1: "/menu/updateBaseMenu", V2: "POST"},
{PType: "p", V0: "8881", V1: "/menu/getBaseMenuById", V2: "POST"},
{PType: "p", V0: "8881", V1: "/user/changePassword", V2: "POST"},
{PType: "p", V0: "8881", V1: "/user/getUserList", V2: "POST"},
{PType: "p", V0: "8881", V1: "/user/setUserAuthority", V2: "POST"},
{PType: "p", V0: "8881", V1: "/fileUploadAndDownload/upload", V2: "POST"},
{PType: "p", V0: "8881", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
{PType: "p", V0: "8881", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
{PType: "p", V0: "8881", V1: "/casbin/updateCasbin", V2: "POST"},
{PType: "p", V0: "8881", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
{PType: "p", V0: "8881", V1: "/jwt/jsonInBlacklist", V2: "POST"},
{PType: "p", V0: "8881", V1: "/system/getSystemConfig", V2: "POST"},
{PType: "p", V0: "8881", V1: "/system/setSystemConfig", V2: "POST"},
{PType: "p", V0: "8881", V1: "/customer/customer", V2: "POST"},
{PType: "p", V0: "8881", V1: "/customer/customer", V2: "PUT"},
{PType: "p", V0: "8881", V1: "/customer/customer", V2: "DELETE"},
{PType: "p", V0: "8881", V1: "/customer/customer", V2: "GET"},
{PType: "p", V0: "8881", V1: "/customer/customerList", V2: "GET"},
{PType: "p", V0: "9528", V1: "/base/login", V2: "POST"},
{PType: "p", V0: "9528", V1: "/base/register", V2: "POST"},
{PType: "p", V0: "9528", V1: "/api/createApi", V2: "POST"},
{PType: "p", V0: "9528", V1: "/api/getApiList", V2: "POST"},
{PType: "p", V0: "9528", V1: "/api/getApiById", V2: "POST"},
{PType: "p", V0: "9528", V1: "/api/deleteApi", V2: "POST"},
{PType: "p", V0: "9528", V1: "/api/updateApi", V2: "POST"},
{PType: "p", V0: "9528", V1: "/api/getAllApis", V2: "POST"},
{PType: "p", V0: "9528", V1: "/authority/createAuthority", V2: "POST"},
{PType: "p", V0: "9528", V1: "/authority/deleteAuthority", V2: "POST"},
{PType: "p", V0: "9528", V1: "/authority/getAuthorityList", V2: "POST"},
{PType: "p", V0: "9528", V1: "/authority/setDataAuthority", V2: "POST"},
{PType: "p", V0: "9528", V1: "/menu/getMenu", V2: "POST"},
{PType: "p", V0: "9528", V1: "/menu/getMenuList", V2: "POST"},
{PType: "p", V0: "9528", V1: "/menu/addBaseMenu", V2: "POST"},
{PType: "p", V0: "9528", V1: "/menu/getBaseMenuTree", V2: "POST"},
{PType: "p", V0: "9528", V1: "/menu/addMenuAuthority", V2: "POST"},
{PType: "p", V0: "9528", V1: "/menu/getMenuAuthority", V2: "POST"},
{PType: "p", V0: "9528", V1: "/menu/deleteBaseMenu", V2: "POST"},
{PType: "p", V0: "9528", V1: "/menu/updateBaseMenu", V2: "POST"},
{PType: "p", V0: "9528", V1: "/menu/getBaseMenuById", V2: "POST"},
{PType: "p", V0: "9528", V1: "/user/changePassword", V2: "POST"},
{PType: "p", V0: "9528", V1: "/user/getUserList", V2: "POST"},
{PType: "p", V0: "9528", V1: "/user/setUserAuthority", V2: "POST"},
{PType: "p", V0: "9528", V1: "/fileUploadAndDownload/upload", V2: "POST"},
{PType: "p", V0: "9528", V1: "/fileUploadAndDownload/getFileList", V2: "POST"},
{PType: "p", V0: "9528", V1: "/fileUploadAndDownload/deleteFile", V2: "POST"},
{PType: "p", V0: "9528", V1: "/casbin/updateCasbin", V2: "POST"},
{PType: "p", V0: "9528", V1: "/casbin/getPolicyPathByAuthorityId", V2: "POST"},
{PType: "p", V0: "9528", V1: "/jwt/jsonInBlacklist", V2: "POST"},
{PType: "p", V0: "9528", V1: "/system/getSystemConfig", V2: "POST"},
{PType: "p", V0: "9528", V1: "/system/setSystemConfig", V2: "POST"},
{PType: "p", V0: "9528", V1: "/customer/customer", V2: "POST"},
{PType: "p", V0: "9528", V1: "/customer/customer", V2: "PUT"},
{PType: "p", V0: "9528", V1: "/customer/customer", V2: "DELETE"},
{PType: "p", V0: "9528", V1: "/customer/customer", V2: "GET"},
{PType: "p", V0: "9528", V1: "/customer/customerList", V2: "GET"},
{PType: "p", V0: "9528", V1: "/autoCode/createTemp", V2: "POST"},
}
func InitCasbinModel(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error {
if !tx.Migrator().HasTable("casbin_rule") {
if err := tx.Migrator().CreateTable(&gormadapter.CasbinRule{}); err != nil {
return err
}
}
if tx.Create(&Carbines).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
}
package datas
import (
"time"
"gin-vue-admin/model"
"gorm.io/gorm"
)
var Customers = []model.ExaCustomer{
{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, CustomerName: "测试客户", CustomerPhoneData: "1761111111", SysUserID: 1, SysUserAuthorityID: "888"},
}
func InitExaCustomer(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error {
if tx.Create(&Customers).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
}
package datas
import (
"time"
"gin-vue-admin/model"
"gorm.io/gorm"
)
type SysDictionaryToPostgresql struct {
gorm.Model
Name string `json:"name" form:"name" gorm:"column:name;comment:字典名(中)"`
Type string `json:"type" form:"type" gorm:"column:type;comment:字典名(英)"`
Status *bool `json:"status" form:"status" gorm:"column:status;comment:状态"`
Description string `json:"description" form:"description" gorm:"column:description;comment:'描述'"`
SysDictionaryDetails []model.SysDictionaryDetail `json:"sysDictionaryDetails" form:"sysDictionaryDetails"`
}
func InitSysDictionary(db *gorm.DB) (err error) {
var status = new(bool)
*status = true
Dictionaries := []model.SysDictionary{
{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Desc: "性别字典"},
{Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Desc: "int类型对应的数据库类型"},
{Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Desc: "数据库时间日期类型"},
{Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库浮点型", Type: "float64", Status: status, Desc: "数据库浮点型"},
{Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Desc: "数据库字符串"},
{Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Desc: "数据库bool类型"},
}
return db.Transaction(func(tx *gorm.DB) error {
if tx.Create(&Dictionaries).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
}
func InitSysDictionaryToPostgresql(db *gorm.DB) (err error) {
status := new(bool)
*status = true
tx := db.Begin() // 开始事务
insert := []SysDictionaryToPostgresql{
{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "性别", Type: "sex", Status: status, Description: "性别字典"},
{Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库int类型", Type: "int", Status: status, Description: "int类型对应的数据库类型"},
{Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库时间日期类型", Type: "time.Time", Status: status, Description: "数据库时间日期类型"},
{Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库浮点型", Type: "float64", Status: status, Description: "数据库浮点型"},
{Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库字符串", Type: "string", Status: status, Description: "数据库字符串"},
{Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, Name: "数据库bool类型", Type: "bool", Status: status, Description: "数据库bool类型"},
}
if tx.Create(&insert).Error != nil { // 遇到错误时回滚事务
tx.Rollback()
}
return tx.Commit().Error
}
package datas
import (
"time"
"gin-vue-admin/model"
"gorm.io/gorm"
)
func InitSysDictionaryDetail(db *gorm.DB) (err error) {
status := new(bool)
*status = true
DictionaryDetail := []model.SysDictionaryDetail{
{gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "smallint", 1, status, 1, 2},
{gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumint", 2, status, 2, 2},
{gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "int", 3, status, 3, 2},
{gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "bigint", 4, status, 4, 2},
{gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "data", 0, status, 0, 3},
{gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "time", 1, status, 1, 3},
{gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "year", 2, status, 2, 3},
{gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "datetime", 3, status, 3, 3},
{gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "timestamp", 5, status, 5, 3},
{gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "float", 0, status, 0, 4},
{gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "double", 1, status, 1, 4},
{gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "decimal", 2, status, 2, 4},
{gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "char", 0, status, 0, 5},
{gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "varchar", 1, status, 1, 5},
{gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyblob", 2, status, 2, 5},
{gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinytext", 3, status, 3, 5},
{gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "text", 4, status, 4, 5},
{gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "blob", 5, status, 5, 5},
{gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumblob", 6, status, 6, 5},
{gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "mediumtext", 7, status, 7, 5},
{gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longblob", 8, status, 8, 5},
{gorm.Model{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "longtext", 9, status, 9, 5},
{gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "tinyint", 0, status, 0, 6},
}
return db.Transaction(func(tx *gorm.DB) error {
if tx.Create(&DictionaryDetail).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
}
package datas
import (
"time"
"gin-vue-admin/model"
"gorm.io/gorm"
)
var Files = []model.ExaFileUploadAndDownload{
{gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "10.png", "http://qmplusimg.henrongyi.top/gvalogo.png", "png", "158787308910.png"},
{gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "logo.png", "http://qmplusimg.henrongyi.top/1576554439myAvatar.png", "png", "1587973709logo.png"},
}
func InitExaFileUploadAndDownload(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error {
if tx.Create(&Files).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
}
package datas
import (
"gin-vue-admin/model"
gormadapter "github.com/casbin/gorm-adapter/v3"
"github.com/gookit/color"
"gorm.io/gorm"
"os"
)
func InitMysqlData(db *gorm.DB) {
var err error
err = InitSysApi(db)
err = InitSysUser(db)
err = InitExaCustomer(db)
err = InitCasbinModel(db)
err = InitSysAuthority(db)
err = InitSysBaseMenus(db)
err = InitAuthorityMenu(db)
err = InitSysDictionary(db)
err = InitSysAuthorityMenus(db)
err = InitSysDataAuthorityId(db)
err = InitSysDictionaryDetail(db)
err = InitExaFileUploadAndDownload(db)
if err != nil {
color.Warn.Printf("[Mysql]-->初始化数据失败,err: %v\n", err)
os.Exit(0)
}
color.Info.Println("[Mysql]-->初始化数据成功")
}
func InitMysqlTables(db *gorm.DB) {
var err error
err = db.AutoMigrate(
model.SysApi{},
model.SysUser{},
model.ExaFile{},
model.ExaCustomer{},
model.SysBaseMenu{},
model.SysWorkflow{},
model.SysAuthority{},
model.JwtBlacklist{},
model.ExaFileChunk{},
model.SysDictionary{},
model.ExaSimpleUploader{},
model.SysOperationRecord{},
model.SysWorkflowStepInfo{},
model.SysDictionaryDetail{},
model.SysBaseMenuParameter{},
model.ExaFileUploadAndDownload{},
)
if err != nil {
color.Warn.Printf("[Mysql]-->初始化数据表失败,err: %v\n", err)
os.Exit(0)
}
color.Info.Println("[Mysql]-->初始化数据表成功")
}
func InitPostgresqlData(db *gorm.DB) {
var err error
err = InitSysApi(db)
err = InitSysUser(db)
err = InitExaCustomer(db)
err = InitCasbinModel(db)
err = InitSysAuthority(db)
err = InitSysBaseMenus(db)
err = InitAuthorityMenu(db)
err = InitSysAuthorityMenus(db)
err = InitSysDataAuthorityId(db)
err = InitSysDictionaryDetail(db)
err = InitExaFileUploadAndDownload(db)
err = InitSysDictionaryToPostgresql(db)
if err != nil {
color.Error.Printf("[Postgresql]-->初始化数据失败,err: %v\n", err)
os.Exit(0)
}
color.Info.Println("[Postgresql]-->初始化数据成功")
}
func InitPostgresqlTables(db *gorm.DB) {
var err error
if !db.Migrator().HasTable("casbin_rule") {
err = db.Migrator().CreateTable(&gormadapter.CasbinRule{})
}
err = db.AutoMigrate(
model.SysApi{},
model.SysUser{},
model.ExaFile{},
model.ExaCustomer{},
model.SysBaseMenu{},
model.SysWorkflow{},
model.SysAuthority{},
model.JwtBlacklist{},
model.ExaFileChunk{},
model.ExaSimpleUploader{},
model.SysOperationRecord{},
model.SysWorkflowStepInfo{},
model.SysDictionaryDetail{},
model.SysBaseMenuParameter{},
model.ExaFileUploadAndDownload{},
SysDictionaryToPostgresql{},
)
if err != nil {
color.Error.Printf("[Postgresql]-->初始化数据表失败,err: %v\n", err)
os.Exit(0)
}
color.Info.Println("[Postgresql]-->初始化数据表成功")
}
package datas
import (
"time"
"gin-vue-admin/model"
"gorm.io/gorm"
)
var BaseMenus = []model.SysBaseMenu{
{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "dashboard", Name: "dashboard", Hidden: false, Component: "view/dashboard/index.vue", Sort: 1, Meta: model.Meta{Title: "仪表盘", Icon: "setting"}},
{Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "about", Name: "about", Component: "view/about/index.vue", Sort: 7, Meta: model.Meta{Title: "关于我们", Icon: "info"}},
{Model: gorm.Model{ID: 3, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "admin", Name: "superAdmin", Component: "view/superAdmin/index.vue", Sort: 3, Meta: model.Meta{Title: "超级管理员", Icon: "user-solid"}},
{Model: gorm.Model{ID: 4, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "authority", Name: "authority", Component: "view/superAdmin/authority/authority.vue", Sort: 1, Meta: model.Meta{Title: "角色管理", Icon: "s-custom"}},
{Model: gorm.Model{ID: 5, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "menu", Name: "menu", Component: "view/superAdmin/menu/menu.vue", Sort: 2, Meta: model.Meta{Title: "菜单管理", Icon: "s-order", KeepAlive: true}},
{Model: gorm.Model{ID: 6, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "api", Name: "api", Component: "view/superAdmin/api/api.vue", Sort: 3, Meta: model.Meta{Title: "api管理", Icon: "s-platform", KeepAlive: true}},
{Model: gorm.Model{ID: 7, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "user", Name: "user", Component: "view/superAdmin/user/user.vue", Sort: 4, Meta: model.Meta{Title: "用户管理", Icon: "coordinate"}},
{Model: gorm.Model{ID: 8, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "0", Path: "person", Name: "person", Component: "view/person/person.vue", Sort: 4, Meta: model.Meta{Title: "个人信息", Icon: "message-solid"}},
{Model: gorm.Model{ID: 9, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "example", Name: "example", Component: "view/example/index.vue", Sort: 6, Meta: model.Meta{Title: "示例文件", Icon: "s-management"}},
{Model: gorm.Model{ID: 10, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "table", Name: "table", Component: "view/example/table/table.vue", Sort: 1, Meta: model.Meta{Title: "表格示例", Icon: "s-order"}},
{Model: gorm.Model{ID: 11, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "form", Name: "form", Component: "view/example/form/form.vue", Sort: 2, Meta: model.Meta{Title: "表单示例", Icon: "document"}},
{Model: gorm.Model{ID: 12, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "rte", Name: "rte", Component: "view/example/rte/rte.vue", Sort: 3, Meta: model.Meta{Title: "富文本编辑器", Icon: "reading"}},
{Model: gorm.Model{ID: 13, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "excel", Name: "excel", Component: "view/example/excel/excel.vue", Sort: 4, Meta: model.Meta{Title: "excel导入导出", Icon: "s-marketing"}},
{Model: gorm.Model{ID: 14, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "upload", Name: "upload", Component: "view/example/upload/upload.vue", Sort: 5, Meta: model.Meta{Title: "上传下载", Icon: "upload"}},
{Model: gorm.Model{ID: 15, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "breakpoint", Name: "breakpoint", Component: "view/example/breakpoint/breakpoint.vue", Sort: 6, Meta: model.Meta{Title: "断点续传", Icon: "upload"}},
{Model: gorm.Model{ID: 16, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "customer", Name: "customer", Component: "view/example/customer/customer.vue", Sort: 7, Meta: model.Meta{Title: "客户列表(资源示例)", Icon: "s-custom"}},
{Model: gorm.Model{ID: 17, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "systemTools", Name: "systemTools", Component: "view/systemTools/index.vue", Sort: 5, Meta: model.Meta{Title: "系统工具", Icon: "s-cooperation"}},
{Model: gorm.Model{ID: 18, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "autoCode", Name: "autoCode", Component: "view/systemTools/autoCode/index.vue", Sort: 1, Meta: model.Meta{Title: "代码生成器", Icon: "cpu", KeepAlive: true}},
{Model: gorm.Model{ID: 19, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "formCreate", Name: "formCreate", Component: "view/systemTools/formCreate/index.vue", Sort: 2, Meta: model.Meta{Title: "表单生成器", Icon: "magic-stick", KeepAlive: true}},
{Model: gorm.Model{ID: 20, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "17", Path: "system", Name: "system", Component: "view/systemTools/system/system.vue", Sort: 3, Meta: model.Meta{Title: "系统配置", Icon: "s-operation"}},
{Model: gorm.Model{ID: 21, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "0", Path: "iconList", Name: "iconList", Component: "view/iconList/index.vue", Sort: 2, Meta: model.Meta{Title: "图标集合", Icon: "star-on"}},
{Model: gorm.Model{ID: 22, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "dictionary", Name: "dictionary", Component: "view/superAdmin/dictionary/sysDictionary.vue", Sort: 5, Meta: model.Meta{Title: "字典管理", Icon: "notebook-2"}},
{Model: gorm.Model{ID: 23, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: true, ParentId: "3", Path: "dictionaryDetail/:id", Name: "dictionaryDetail", Component: "view/superAdmin/dictionary/sysDictionaryDetail.vue", Sort: 1, Meta: model.Meta{Title: "字典详情", Icon: "s-order"}},
{Model: gorm.Model{ID: 24, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "3", Path: "operation", Name: "operation", Component: "view/superAdmin/operation/sysOperationRecord.vue", Sort: 6, Meta: model.Meta{Title: "操作历史", Icon: "time"}},
{Model: gorm.Model{ID: 25, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, Hidden: false, ParentId: "9", Path: "simpleUploader", Name: "simpleUploader", Component: "view/example/simpleUploader/simpleUploader", Sort: 6, Meta: model.Meta{Title: "断点续传(插件版)", Icon: "upload"}},
{Model: gorm.Model{ID: 26, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "https://www.gin-vue-admin.com", Name: "https://www.gin-vue-admin.com", Hidden: false, Component: "/", Sort: 0, Meta: model.Meta{Title: "官方网站", Icon: "s-home"}},
{Model: gorm.Model{ID: 27, CreatedAt: time.Now(), UpdatedAt: time.Now()}, MenuLevel: 0, ParentId: "0", Path: "state", Name: "state", Hidden: false, Component: "view/system/state.vue", Sort: 6, Meta: model.Meta{Title: "服务器状态", Icon: "cloudy"}},
}
func InitSysBaseMenus(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error {
if tx.Create(&BaseMenus).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
}
package datas
import (
"time"
"gin-vue-admin/model"
uuid "github.com/satori/go.uuid"
"gorm.io/gorm"
)
var Users = []model.SysUser{
{Model: gorm.Model{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "admin", Password: "e10adc3949ba59abbe56e057f20f883e", NickName: "超级管理员", HeaderImg: "http://qmplusimg.henrongyi.top/1571627762timg.jpg", AuthorityId: "888"},
{Model: gorm.Model{ID: 2, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "a303176530", Password: "3ec063004a6f31642261936a379fde3d", NickName: "QMPlusUser", HeaderImg: "http://qmplusimg.henrongyi.top/1572075907logo.png", AuthorityId: "9528"},
}
func InitSysUser(db *gorm.DB) (err error) {
return db.Transaction(func(tx *gorm.DB) error {
if tx.Create(&Users).Error != nil { // 遇到错误时回滚事务
return err
}
return nil
})
}
/*
Copyright © 2020 SliverHorn
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package gva
import (
"gin-vue-admin/cmd/datas"
"gin-vue-admin/core"
"gin-vue-admin/initialize"
"github.com/gookit/color"
_ "gin-vue-admin/core"
"gin-vue-admin/global"
"github.com/spf13/cobra"
)
// initdbCmd represents the initdb command
var initdbCmd = &cobra.Command{
Use: "initdb",
Short: "gin-vue-admin初始化数据",
Long: `gin-vue-admin初始化数据适配数据库情况:
1. mysql完美适配,
2. postgresql不能保证完美适配,
3. sqlite未适配,
4. sqlserver未适配`,
Run: func(cmd *cobra.Command, args []string) {
path, _ := cmd.Flags().GetString("path")
core.Viper(path)
db := initialize.GormMysql()
switch global.GVA_CONFIG.System.DbType {
case "mysql":
datas.InitMysqlTables(db)
datas.InitMysqlData(db)
case "postgresql":
datas.InitPostgresqlTables(db)
datas.InitPostgresqlData(db)
case "sqlite":
color.Info.Println("sqlite功能开发中")
case "sqlserver":
color.Info.Println("sqlserver功能开发中")
default:
datas.InitMysqlTables(db)
datas.InitMysqlData(db)
color.Info.Println("sqlserver功能开发中")
}
frame, _ := cmd.Flags().GetString("frame")
if frame == "gf" {
color.Info.Println("gf功能开发中")
return
} else {
return
}
},
}
func init() {
rootCmd.AddCommand(initdbCmd)
initdbCmd.Flags().StringP("path", "p", "./config.yaml", "自定配置文件路径(绝对路径)")
initdbCmd.Flags().StringP("frame", "f", "gin", "可选参数为gin,gf")
initdbCmd.Flags().StringP("type", "t", "mysql", "可选参数为mysql,postgresql,sqlite,sqlserver")
}
/*
Copyright © 2020 SliverHorn
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package gva
import (
"github.com/mitchellh/go-homedir"
"os"
"github.com/gookit/color"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var cfgFile string
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "gva",
Short: "这是一款amazing的终端工具",
Long: `欢迎使用gva终端工具
________ ____ ____ _____
/ _____/ \ \ / / / _ \
/ \ ___ \ Y / / /_\ \
\ \_\ \ \ / / | \
\______ / \___/ \____|__ /
\/ \/
`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
color.Warn.Println(err)
os.Exit(1)
}
}
func init() {
cobra.OnInitialize(initConfig)
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.gva.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
// initConfig reads in config file and ENV variables if set.
func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
color.Warn.Println(err)
os.Exit(1)
}
// Search config in home directory with name ".gva" (without extension).
viper.AddConfigPath(home)
viper.SetConfigName(".gva")
}
viper.AutomaticEnv() // read in environment variables that match
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
color.Warn.Println("Using config file:", viper.ConfigFileUsed())
}
}
/*
Copyright © 2020 SliverHorn
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package gva
import (
"github.com/gookit/color"
"github.com/spf13/cobra"
)
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "版本信息",
Long: `版本的长信息`,
Run: func(cmd *cobra.Command, args []string) {
color.Green.Println("v0.0.2")
},
}
func init() {
rootCmd.AddCommand(versionCmd)
}
/*
Copyright © 2020 SliverHorn
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import "gin-vue-admin/cmd/gva"
func main() {
gva.Execute()
}
...@@ -42,8 +42,6 @@ system: ...@@ -42,8 +42,6 @@ system:
addr: 8888 addr: 8888
db-type: 'mysql' db-type: 'mysql'
oss-type: 'local' oss-type: 'local'
config-env: 'GVA_CONFIG'
need-init-data: false
use-multipoint: false use-multipoint: false
# captcha configuration # captcha configuration
...@@ -63,36 +61,6 @@ mysql: ...@@ -63,36 +61,6 @@ mysql:
max-open-conns: 10 max-open-conns: 10
log-mode: false log-mode: false
# sqlite connect configuration (sqlite需要gcc支持 windows用户需要自行安装gcc)
sqlite:
path: 'db.db'
max-idle-conns: 10
max-open-conns: 10
logger: true
# Sqlserver connect configuration
sqlserver:
path: 'localhost:9930'
db-name: 'gorm'
username: 'gorm'
password: 'LoremIpsum86'
max-idle-conns: 10
max-open-conns: 10
logger: true
# Postgresql connect configuration
postgresql:
host: '127.0.0.1'
port: '9920'
config: 'sslmode=disable TimeZone=Asia/Shanghai'
db-name: 'gorm'
username: 'gorm'
password: 'gorm'
max-idle-conns: 10
max-open-conns: 10
prefer-simple-protocol: true
logger: false
# local configuration # local configuration
local: local:
path: 'uploads/file' path: 'uploads/file'
......
...@@ -10,9 +10,6 @@ type Server struct { ...@@ -10,9 +10,6 @@ type Server struct {
Captcha Captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"` Captcha Captcha `mapstructure:"captcha" json:"captcha" yaml:"captcha"`
// gorm // gorm
Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"` Mysql Mysql `mapstructure:"mysql" json:"mysql" yaml:"mysql"`
Sqlite Sqlite `mapstructure:"sqlite" json:"sqlite" yaml:"sqlite"`
Sqlserver Sqlserver `mapstructure:"sqlserver" json:"sqlserver" yaml:"sqlserver"`
Postgresql Postgresql `mapstructure:"postgresql" json:"postgresql" yaml:"postgresql"`
// oss // oss
Local Local `mapstructure:"local" json:"local" yaml:"local"` Local Local `mapstructure:"local" json:"local" yaml:"local"`
Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"` Qiniu Qiniu `mapstructure:"qiniu" json:"qiniu" yaml:"qiniu"`
......
...@@ -10,34 +10,3 @@ type Mysql struct { ...@@ -10,34 +10,3 @@ type Mysql struct {
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"`
LogMode bool `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"` LogMode bool `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"`
} }
type Sqlite struct {
Path string `mapstructure:"path" json:"path" yaml:"path"`
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"`
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"`
Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"`
}
type Sqlserver struct {
Path string `mapstructure:"path" json:"path" yaml:"path"`
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"`
Username string `mapstructure:"username" json:"username" yaml:"username"`
Password string `mapstructure:"password" json:"password" yaml:"password"`
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"`
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"`
Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"`
}
type Postgresql struct {
Host string `mapstructure:"host" json:"host" yaml:"host"`
Port string `mapstructure:"port" json:"port" yaml:"port"`
Config string `mapstructure:"config" json:"config" yaml:"config"`
Dbname string `mapstructure:"db-name" json:"dbname" yaml:"db-name"`
Username string `mapstructure:"username" json:"username" yaml:"username"`
Password string `mapstructure:"password" json:"password" yaml:"password"`
MaxIdleConns int `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"`
MaxOpenConns int `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"`
PreferSimpleProtocol bool `mapstructure:"prefer-simple-protocol" json:"preferSimpleProtocol" yaml:"prefer-simple-protocol"`
Logger bool `mapstructure:"logger" json:"logger" yaml:"logger"`
}
...@@ -5,7 +5,5 @@ type System struct { ...@@ -5,7 +5,5 @@ type System struct {
Addr int `mapstructure:"addr" json:"addr" yaml:"addr"` Addr int `mapstructure:"addr" json:"addr" yaml:"addr"`
DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"` DbType string `mapstructure:"db-type" json:"dbType" yaml:"db-type"`
OssType string `mapstructure:"oss-type" json:"ossType" yaml:"oss-type"` OssType string `mapstructure:"oss-type" json:"ossType" yaml:"oss-type"`
ConfigEnv string `mapstructure:"config-env" json:"configEnv" yaml:"config-env"`
NeedInitData bool `mapstructure:"need-init-data" json:"needInitData" yaml:"need-init-data"`
UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint" yaml:"use-multipoint"` UseMultipoint bool `mapstructure:"use-multipoint" json:"useMultipoint" yaml:"use-multipoint"`
} }
...@@ -5,29 +5,33 @@ import ( ...@@ -5,29 +5,33 @@ import (
"fmt" "fmt"
"gin-vue-admin/global" "gin-vue-admin/global"
_ "gin-vue-admin/packfile" _ "gin-vue-admin/packfile"
"gin-vue-admin/utils"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/spf13/viper" "github.com/spf13/viper"
"os" "os"
) )
var config string func Viper(path ...string) *viper.Viper {
var config string
const defaultConfigFile = "config.yaml" if len(path) == 0 {
flag.StringVar(&config, "c", "", "choose config file.")
func init() { flag.Parse()
flag.StringVar(&config, "c", "", "choose config file.") if config == "" { // 优先级: 命令行 > 环境变量 > 默认值
flag.Parse() if configEnv := os.Getenv(utils.ConfigEnv); configEnv == "" {
if config == "" { // 优先级: 命令行 > 环境变量 > 默认值 config = utils.ConfigFile
if configEnv := os.Getenv(global.GVA_CONFIG.System.ConfigEnv); configEnv == "" { fmt.Printf("您正在使用config的默认值,config的路径为%v\n", utils.ConfigFile)
config = defaultConfigFile } else {
fmt.Printf("您正在使用config的默认值,config的路径为%v\n", defaultConfigFile) config = configEnv
fmt.Printf("您正在使用GVA_CONFIG环境变量,config的路径为%v\n", config)
}
} else { } else {
config = configEnv fmt.Printf("您正在使用命令行的-c参数传递的值,config的路径为%v\n", config)
fmt.Printf("您正在使用GVA_CONFIG环境变量,config的路径为%v\n", config)
} }
} else { } else {
fmt.Printf("您正在使用命令行的-c参数传递的值,config的路径为%v\n", config) config = path[0]
fmt.Printf("您正在使用func Viper()传递的值,config的路径为%v\n", config)
} }
v := viper.New() v := viper.New()
v.SetConfigFile(config) v.SetConfigFile(config)
err := v.ReadInConfig() err := v.ReadInConfig()
...@@ -42,8 +46,9 @@ func init() { ...@@ -42,8 +46,9 @@ func init() {
fmt.Println(err) fmt.Println(err)
} }
}) })
if err := v.Unmarshal(&global.GVA_CONFIG); err != nil { if err := v.Unmarshal(&global.GVA_CONFIG); err != nil {
fmt.Println(err) fmt.Println(err)
} }
global.GVA_VP = v return v
} }
...@@ -4,20 +4,15 @@ import ( ...@@ -4,20 +4,15 @@ import (
"fmt" "fmt"
"gin-vue-admin/global" "gin-vue-admin/global"
"gin-vue-admin/utils" "gin-vue-admin/utils"
zaprotatelogs "github.com/lestrrat-go/file-rotatelogs"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
"os" "os"
"time" "time"
) )
var ( var level zapcore.Level
err error
level zapcore.Level
writer zapcore.WriteSyncer
)
func init() { func Zap() (logger *zap.Logger) {
if ok, _ := utils.PathExists(global.GVA_CONFIG.Zap.Director); !ok { // 判断是否有Director文件夹 if ok, _ := utils.PathExists(global.GVA_CONFIG.Zap.Director); !ok { // 判断是否有Director文件夹
fmt.Printf("create %v directory\n", global.GVA_CONFIG.Zap.Director) fmt.Printf("create %v directory\n", global.GVA_CONFIG.Zap.Director)
_ = os.Mkdir(global.GVA_CONFIG.Zap.Director, os.ModePerm) _ = os.Mkdir(global.GVA_CONFIG.Zap.Director, os.ModePerm)
...@@ -42,34 +37,15 @@ func init() { ...@@ -42,34 +37,15 @@ func init() {
level = zap.InfoLevel level = zap.InfoLevel
} }
writer, err = getWriteSyncer() // 使用file-rotatelogs进行日志分割
if err != nil {
fmt.Printf("Get Write Syncer Failed err:%v", err.Error())
return
}
if level == zap.DebugLevel || level == zap.ErrorLevel { if level == zap.DebugLevel || level == zap.ErrorLevel {
global.GVA_LOG = zap.New(getEncoderCore(), zap.AddStacktrace(level)) logger = zap.New(getEncoderCore(), zap.AddStacktrace(level))
} else { } else {
global.GVA_LOG = zap.New(getEncoderCore()) logger = zap.New(getEncoderCore())
} }
if global.GVA_CONFIG.Zap.ShowLine { if global.GVA_CONFIG.Zap.ShowLine {
global.GVA_LOG.WithOptions(zap.AddCaller()) logger.WithOptions(zap.AddCaller())
} }
} return logger
// getWriteSyncer zap logger中加入file-rotatelogs
func getWriteSyncer() (zapcore.WriteSyncer, error) {
fileWriter, err := zaprotatelogs.New(
global.GVA_CONFIG.Zap.Director+string(os.PathSeparator)+"%Y-%m-%d.log",
zaprotatelogs.WithLinkName(global.GVA_CONFIG.Zap.LinkName),
zaprotatelogs.WithMaxAge(7*24*time.Hour),
zaprotatelogs.WithRotationTime(24*time.Hour),
)
if global.GVA_CONFIG.Zap.LogInConsole {
return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err
}
return zapcore.AddSync(fileWriter), err
} }
// getEncoderConfig 获取zapcore.EncoderConfig // getEncoderConfig 获取zapcore.EncoderConfig
...@@ -87,7 +63,7 @@ func getEncoderConfig() (config zapcore.EncoderConfig) { ...@@ -87,7 +63,7 @@ func getEncoderConfig() (config zapcore.EncoderConfig) {
EncodeDuration: zapcore.SecondsDurationEncoder, EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.FullCallerEncoder, EncodeCaller: zapcore.FullCallerEncoder,
} }
switch { switch {
case global.GVA_CONFIG.Zap.EncodeLevel == "LowercaseLevelEncoder": // 小写编码器(默认) case global.GVA_CONFIG.Zap.EncodeLevel == "LowercaseLevelEncoder": // 小写编码器(默认)
config.EncodeLevel = zapcore.LowercaseLevelEncoder config.EncodeLevel = zapcore.LowercaseLevelEncoder
case global.GVA_CONFIG.Zap.EncodeLevel == "LowercaseColorLevelEncoder": // 小写编码器带颜色 case global.GVA_CONFIG.Zap.EncodeLevel == "LowercaseColorLevelEncoder": // 小写编码器带颜色
...@@ -96,6 +72,8 @@ func getEncoderConfig() (config zapcore.EncoderConfig) { ...@@ -96,6 +72,8 @@ func getEncoderConfig() (config zapcore.EncoderConfig) {
config.EncodeLevel = zapcore.CapitalLevelEncoder config.EncodeLevel = zapcore.CapitalLevelEncoder
case global.GVA_CONFIG.Zap.EncodeLevel == "CapitalColorLevelEncoder": // 大写编码器带颜色 case global.GVA_CONFIG.Zap.EncodeLevel == "CapitalColorLevelEncoder": // 大写编码器带颜色
config.EncodeLevel = zapcore.CapitalColorLevelEncoder config.EncodeLevel = zapcore.CapitalColorLevelEncoder
default:
config.EncodeLevel = zapcore.LowercaseLevelEncoder
} }
return config return config
} }
...@@ -110,6 +88,11 @@ func getEncoder() zapcore.Encoder { ...@@ -110,6 +88,11 @@ func getEncoder() zapcore.Encoder {
// getEncoderCore 获取Encoder的zapcore.Core // getEncoderCore 获取Encoder的zapcore.Core
func getEncoderCore() (core zapcore.Core) { func getEncoderCore() (core zapcore.Core) {
writer, err := utils.GetWriteSyncer() // 使用file-rotatelogs进行日志分割
if err != nil {
fmt.Printf("Get Write Syncer Failed err:%v", err.Error())
return
}
return zapcore.NewCore(getEncoder(), writer, level) return zapcore.NewCore(getEncoder(), writer, level)
} }
......
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at // This file was generated by swaggo/swag at
// 2020-08-31 21:50:05.0136259 +0800 CST m=+0.193314401 // 2020-10-18 12:17:37.2292991 +0800 CST m=+0.263609801
package docs package docs
...@@ -593,36 +593,6 @@ var doc = `{ ...@@ -593,36 +593,6 @@ var doc = `{
} }
} }
}, },
"/base/register": {
"post": {
"produces": [
"application/json"
],
"tags": [
"Base"
],
"summary": "用户注册账号",
"parameters": [
{
"description": "用户注册接口",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.SysUser"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"注册成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/casbin/UpdateCasbin": { "/casbin/UpdateCasbin": {
"post": { "post": {
"security": [ "security": [
...@@ -883,6 +853,30 @@ var doc = `{ ...@@ -883,6 +853,30 @@ var doc = `{
} }
} }
}, },
"/email/emailTest": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"system"
],
"summary": "发送测试邮件",
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"返回成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/fileUploadAndDownload/breakpointContinue": { "/fileUploadAndDownload/breakpointContinue": {
"post": { "post": {
"security": [ "security": [
...@@ -2161,6 +2155,30 @@ var doc = `{ ...@@ -2161,6 +2155,30 @@ var doc = `{
} }
} }
}, },
"/system/getServerInfo": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"system"
],
"summary": "获取服务器信息",
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/system/getSystemConfig": { "/system/getSystemConfig": {
"post": { "post": {
"security": [ "security": [
...@@ -2331,6 +2349,36 @@ var doc = `{ ...@@ -2331,6 +2349,36 @@ var doc = `{
} }
} }
}, },
"/user/register": {
"post": {
"produces": [
"application/json"
],
"tags": [
"Base"
],
"summary": "用户注册账号",
"parameters": [
{
"description": "用户注册接口",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.SysUser"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"注册成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/user/setUserAuthority": { "/user/setUserAuthority": {
"post": { "post": {
"security": [ "security": [
...@@ -2369,6 +2417,44 @@ var doc = `{ ...@@ -2369,6 +2417,44 @@ var doc = `{
} }
} }
}, },
"/user/setUserInfo": {
"put": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"SysUser"
],
"summary": "删除用户",
"parameters": [
{
"description": "删除用户",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.SysUser"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"修改成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/workflow/createWorkFlow": { "/workflow/createWorkFlow": {
"post": { "post": {
"produces": [ "produces": [
...@@ -2423,6 +2509,32 @@ var doc = `{ ...@@ -2423,6 +2509,32 @@ var doc = `{
} }
} }
}, },
"config.Email": {
"type": "object",
"properties": {
"from": {
"type": "string"
},
"host": {
"type": "string"
},
"isSSL": {
"type": "boolean"
},
"nickname": {
"type": "string"
},
"port": {
"type": "integer"
},
"secret": {
"type": "string"
},
"to": {
"type": "string"
}
}
},
"config.JWT": { "config.JWT": {
"type": "object", "type": "object",
"properties": { "properties": {
...@@ -2431,38 +2543,44 @@ var doc = `{ ...@@ -2431,38 +2543,44 @@ var doc = `{
} }
} }
}, },
"config.LocalUpload": { "config.Local": {
"type": "object", "type": "object",
"properties": { "properties": {
"avatarPath": { "path": {
"type": "string"
},
"filePath": {
"type": "string" "type": "string"
},
"local": {
"type": "boolean"
} }
} }
}, },
"config.Log": { "config.Mysql": {
"type": "object", "type": "object",
"properties": { "properties": {
"file": { "config": {
"type": "string"
},
"dbname": {
"type": "string" "type": "string"
}, },
"logFile": { "logMode": {
"type": "boolean" "type": "boolean"
}, },
"prefix": { "maxIdleConns": {
"type": "integer"
},
"maxOpenConns": {
"type": "integer"
},
"password": {
"type": "string"
},
"path": {
"type": "string" "type": "string"
}, },
"stdout": { "username": {
"type": "string" "type": "string"
} }
} }
}, },
"config.Mysql": { "config.Postgresql": {
"type": "object", "type": "object",
"properties": { "properties": {
"config": { "config": {
...@@ -2471,7 +2589,10 @@ var doc = `{ ...@@ -2471,7 +2589,10 @@ var doc = `{
"dbname": { "dbname": {
"type": "string" "type": "string"
}, },
"logMode": { "host": {
"type": "string"
},
"logger": {
"type": "boolean" "type": "boolean"
}, },
"maxIdleConns": { "maxIdleConns": {
...@@ -2483,9 +2604,12 @@ var doc = `{ ...@@ -2483,9 +2604,12 @@ var doc = `{
"password": { "password": {
"type": "string" "type": "string"
}, },
"path": { "port": {
"type": "string" "type": "string"
}, },
"preferSimpleProtocol": {
"type": "boolean"
},
"username": { "username": {
"type": "string" "type": "string"
} }
...@@ -2505,6 +2629,15 @@ var doc = `{ ...@@ -2505,6 +2629,15 @@ var doc = `{
}, },
"secretKey": { "secretKey": {
"type": "string" "type": "string"
},
"useCdnDomains": {
"type": "boolean"
},
"useHttps": {
"type": "boolean"
},
"zone": {
"type": "string"
} }
} }
}, },
...@@ -2533,22 +2666,28 @@ var doc = `{ ...@@ -2533,22 +2666,28 @@ var doc = `{
"type": "object", "type": "object",
"$ref": "#/definitions/config.Casbin" "$ref": "#/definitions/config.Casbin"
}, },
"jwt": { "email": {
"type": "object", "type": "object",
"$ref": "#/definitions/config.JWT" "$ref": "#/definitions/config.Email"
}, },
"localUpload": { "jwt": {
"type": "object", "type": "object",
"$ref": "#/definitions/config.LocalUpload" "$ref": "#/definitions/config.JWT"
}, },
"log": { "local": {
"description": "oss",
"type": "object", "type": "object",
"$ref": "#/definitions/config.Log" "$ref": "#/definitions/config.Local"
}, },
"mysql": { "mysql": {
"description": "gorm",
"type": "object", "type": "object",
"$ref": "#/definitions/config.Mysql" "$ref": "#/definitions/config.Mysql"
}, },
"postgresql": {
"type": "object",
"$ref": "#/definitions/config.Postgresql"
},
"qiniu": { "qiniu": {
"type": "object", "type": "object",
"$ref": "#/definitions/config.Qiniu" "$ref": "#/definitions/config.Qiniu"
...@@ -2561,21 +2700,52 @@ var doc = `{ ...@@ -2561,21 +2700,52 @@ var doc = `{
"type": "object", "type": "object",
"$ref": "#/definitions/config.Sqlite" "$ref": "#/definitions/config.Sqlite"
}, },
"sqlserver": {
"type": "object",
"$ref": "#/definitions/config.Sqlserver"
},
"system": { "system": {
"type": "object", "type": "object",
"$ref": "#/definitions/config.System" "$ref": "#/definitions/config.System"
},
"zap": {
"type": "object",
"$ref": "#/definitions/config.Zap"
} }
} }
}, },
"config.Sqlite": { "config.Sqlite": {
"type": "object", "type": "object",
"properties": { "properties": {
"config": { "logger": {
"type": "boolean"
},
"maxIdleConns": {
"type": "integer"
},
"maxOpenConns": {
"type": "integer"
},
"path": {
"type": "string"
}
}
},
"config.Sqlserver": {
"type": "object",
"properties": {
"dbname": {
"type": "string" "type": "string"
}, },
"logMode": { "logger": {
"type": "boolean" "type": "boolean"
}, },
"maxIdleConns": {
"type": "integer"
},
"maxOpenConns": {
"type": "integer"
},
"password": { "password": {
"type": "string" "type": "string"
}, },
...@@ -2599,11 +2769,49 @@ var doc = `{ ...@@ -2599,11 +2769,49 @@ var doc = `{
"env": { "env": {
"type": "string" "type": "string"
}, },
"needInitData": {
"type": "boolean"
},
"ossType": {
"type": "string"
},
"useMultipoint": { "useMultipoint": {
"type": "boolean" "type": "boolean"
} }
} }
}, },
"config.Zap": {
"type": "object",
"properties": {
"director": {
"type": "string"
},
"encodeLevel": {
"type": "string"
},
"format": {
"type": "string"
},
"level": {
"type": "string"
},
"linkName": {
"type": "string"
},
"logInConsole": {
"type": "boolean"
},
"prefix": {
"type": "string"
},
"showLine": {
"type": "boolean"
},
"stacktraceKey": {
"type": "string"
}
}
},
"model.AutoCodeStruct": { "model.AutoCodeStruct": {
"type": "object", "type": "object",
"properties": { "properties": {
...@@ -2971,7 +3179,7 @@ var doc = `{ ...@@ -2971,7 +3179,7 @@ var doc = `{
"description": "是否是完结流节点", "description": "是否是完结流节点",
"type": "boolean" "type": "boolean"
}, },
"isStrat": { "isStart": {
"description": "是否是开始流节点", "description": "是否是开始流节点",
"type": "boolean" "type": "boolean"
}, },
......
...@@ -576,36 +576,6 @@ ...@@ -576,36 +576,6 @@
} }
} }
}, },
"/base/register": {
"post": {
"produces": [
"application/json"
],
"tags": [
"Base"
],
"summary": "用户注册账号",
"parameters": [
{
"description": "用户注册接口",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.SysUser"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"注册成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/casbin/UpdateCasbin": { "/casbin/UpdateCasbin": {
"post": { "post": {
"security": [ "security": [
...@@ -866,6 +836,30 @@ ...@@ -866,6 +836,30 @@
} }
} }
}, },
"/email/emailTest": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"system"
],
"summary": "发送测试邮件",
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"返回成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/fileUploadAndDownload/breakpointContinue": { "/fileUploadAndDownload/breakpointContinue": {
"post": { "post": {
"security": [ "security": [
...@@ -2144,6 +2138,30 @@ ...@@ -2144,6 +2138,30 @@
} }
} }
}, },
"/system/getServerInfo": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"produces": [
"application/json"
],
"tags": [
"system"
],
"summary": "获取服务器信息",
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/system/getSystemConfig": { "/system/getSystemConfig": {
"post": { "post": {
"security": [ "security": [
...@@ -2314,6 +2332,36 @@ ...@@ -2314,6 +2332,36 @@
} }
} }
}, },
"/user/register": {
"post": {
"produces": [
"application/json"
],
"tags": [
"Base"
],
"summary": "用户注册账号",
"parameters": [
{
"description": "用户注册接口",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.SysUser"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"注册成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/user/setUserAuthority": { "/user/setUserAuthority": {
"post": { "post": {
"security": [ "security": [
...@@ -2352,6 +2400,44 @@ ...@@ -2352,6 +2400,44 @@
} }
} }
}, },
"/user/setUserInfo": {
"put": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"SysUser"
],
"summary": "删除用户",
"parameters": [
{
"description": "删除用户",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.SysUser"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"修改成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/workflow/createWorkFlow": { "/workflow/createWorkFlow": {
"post": { "post": {
"produces": [ "produces": [
...@@ -2406,6 +2492,32 @@ ...@@ -2406,6 +2492,32 @@
} }
} }
}, },
"config.Email": {
"type": "object",
"properties": {
"from": {
"type": "string"
},
"host": {
"type": "string"
},
"isSSL": {
"type": "boolean"
},
"nickname": {
"type": "string"
},
"port": {
"type": "integer"
},
"secret": {
"type": "string"
},
"to": {
"type": "string"
}
}
},
"config.JWT": { "config.JWT": {
"type": "object", "type": "object",
"properties": { "properties": {
...@@ -2414,38 +2526,44 @@ ...@@ -2414,38 +2526,44 @@
} }
} }
}, },
"config.LocalUpload": { "config.Local": {
"type": "object", "type": "object",
"properties": { "properties": {
"avatarPath": { "path": {
"type": "string"
},
"filePath": {
"type": "string" "type": "string"
},
"local": {
"type": "boolean"
} }
} }
}, },
"config.Log": { "config.Mysql": {
"type": "object", "type": "object",
"properties": { "properties": {
"file": { "config": {
"type": "string"
},
"dbname": {
"type": "string" "type": "string"
}, },
"logFile": { "logMode": {
"type": "boolean" "type": "boolean"
}, },
"prefix": { "maxIdleConns": {
"type": "integer"
},
"maxOpenConns": {
"type": "integer"
},
"password": {
"type": "string"
},
"path": {
"type": "string" "type": "string"
}, },
"stdout": { "username": {
"type": "string" "type": "string"
} }
} }
}, },
"config.Mysql": { "config.Postgresql": {
"type": "object", "type": "object",
"properties": { "properties": {
"config": { "config": {
...@@ -2454,7 +2572,10 @@ ...@@ -2454,7 +2572,10 @@
"dbname": { "dbname": {
"type": "string" "type": "string"
}, },
"logMode": { "host": {
"type": "string"
},
"logger": {
"type": "boolean" "type": "boolean"
}, },
"maxIdleConns": { "maxIdleConns": {
...@@ -2466,9 +2587,12 @@ ...@@ -2466,9 +2587,12 @@
"password": { "password": {
"type": "string" "type": "string"
}, },
"path": { "port": {
"type": "string" "type": "string"
}, },
"preferSimpleProtocol": {
"type": "boolean"
},
"username": { "username": {
"type": "string" "type": "string"
} }
...@@ -2488,6 +2612,15 @@ ...@@ -2488,6 +2612,15 @@
}, },
"secretKey": { "secretKey": {
"type": "string" "type": "string"
},
"useCdnDomains": {
"type": "boolean"
},
"useHttps": {
"type": "boolean"
},
"zone": {
"type": "string"
} }
} }
}, },
...@@ -2516,22 +2649,28 @@ ...@@ -2516,22 +2649,28 @@
"type": "object", "type": "object",
"$ref": "#/definitions/config.Casbin" "$ref": "#/definitions/config.Casbin"
}, },
"jwt": { "email": {
"type": "object", "type": "object",
"$ref": "#/definitions/config.JWT" "$ref": "#/definitions/config.Email"
}, },
"localUpload": { "jwt": {
"type": "object", "type": "object",
"$ref": "#/definitions/config.LocalUpload" "$ref": "#/definitions/config.JWT"
}, },
"log": { "local": {
"description": "oss",
"type": "object", "type": "object",
"$ref": "#/definitions/config.Log" "$ref": "#/definitions/config.Local"
}, },
"mysql": { "mysql": {
"description": "gorm",
"type": "object", "type": "object",
"$ref": "#/definitions/config.Mysql" "$ref": "#/definitions/config.Mysql"
}, },
"postgresql": {
"type": "object",
"$ref": "#/definitions/config.Postgresql"
},
"qiniu": { "qiniu": {
"type": "object", "type": "object",
"$ref": "#/definitions/config.Qiniu" "$ref": "#/definitions/config.Qiniu"
...@@ -2544,21 +2683,52 @@ ...@@ -2544,21 +2683,52 @@
"type": "object", "type": "object",
"$ref": "#/definitions/config.Sqlite" "$ref": "#/definitions/config.Sqlite"
}, },
"sqlserver": {
"type": "object",
"$ref": "#/definitions/config.Sqlserver"
},
"system": { "system": {
"type": "object", "type": "object",
"$ref": "#/definitions/config.System" "$ref": "#/definitions/config.System"
},
"zap": {
"type": "object",
"$ref": "#/definitions/config.Zap"
} }
} }
}, },
"config.Sqlite": { "config.Sqlite": {
"type": "object", "type": "object",
"properties": { "properties": {
"config": { "logger": {
"type": "boolean"
},
"maxIdleConns": {
"type": "integer"
},
"maxOpenConns": {
"type": "integer"
},
"path": {
"type": "string"
}
}
},
"config.Sqlserver": {
"type": "object",
"properties": {
"dbname": {
"type": "string" "type": "string"
}, },
"logMode": { "logger": {
"type": "boolean" "type": "boolean"
}, },
"maxIdleConns": {
"type": "integer"
},
"maxOpenConns": {
"type": "integer"
},
"password": { "password": {
"type": "string" "type": "string"
}, },
...@@ -2582,11 +2752,49 @@ ...@@ -2582,11 +2752,49 @@
"env": { "env": {
"type": "string" "type": "string"
}, },
"needInitData": {
"type": "boolean"
},
"ossType": {
"type": "string"
},
"useMultipoint": { "useMultipoint": {
"type": "boolean" "type": "boolean"
} }
} }
}, },
"config.Zap": {
"type": "object",
"properties": {
"director": {
"type": "string"
},
"encodeLevel": {
"type": "string"
},
"format": {
"type": "string"
},
"level": {
"type": "string"
},
"linkName": {
"type": "string"
},
"logInConsole": {
"type": "boolean"
},
"prefix": {
"type": "string"
},
"showLine": {
"type": "boolean"
},
"stacktraceKey": {
"type": "string"
}
}
},
"model.AutoCodeStruct": { "model.AutoCodeStruct": {
"type": "object", "type": "object",
"properties": { "properties": {
...@@ -2954,7 +3162,7 @@ ...@@ -2954,7 +3162,7 @@
"description": "是否是完结流节点", "description": "是否是完结流节点",
"type": "boolean" "type": "boolean"
}, },
"isStrat": { "isStart": {
"description": "是否是开始流节点", "description": "是否是开始流节点",
"type": "boolean" "type": "boolean"
}, },
......
...@@ -14,38 +14,61 @@ definitions: ...@@ -14,38 +14,61 @@ definitions:
modelPath: modelPath:
type: string type: string
type: object type: object
config.Email:
properties:
from:
type: string
host:
type: string
isSSL:
type: boolean
nickname:
type: string
port:
type: integer
secret:
type: string
to:
type: string
type: object
config.JWT: config.JWT:
properties: properties:
signingKey: signingKey:
type: string type: string
type: object type: object
config.LocalUpload: config.Local:
properties: properties:
avatarPath: path:
type: string
filePath:
type: string type: string
local:
type: boolean
type: object type: object
config.Log: config.Mysql:
properties: properties:
file: config:
type: string type: string
logFile: dbname:
type: string
logMode:
type: boolean type: boolean
prefix: maxIdleConns:
type: integer
maxOpenConns:
type: integer
password:
type: string
path:
type: string type: string
stdout: username:
type: string type: string
type: object type: object
config.Mysql: config.Postgresql:
properties: properties:
config: config:
type: string type: string
dbname: dbname:
type: string type: string
logMode: host:
type: string
logger:
type: boolean type: boolean
maxIdleConns: maxIdleConns:
type: integer type: integer
...@@ -53,8 +76,10 @@ definitions: ...@@ -53,8 +76,10 @@ definitions:
type: integer type: integer
password: password:
type: string type: string
path: port:
type: string type: string
preferSimpleProtocol:
type: boolean
username: username:
type: string type: string
type: object type: object
...@@ -68,6 +93,12 @@ definitions: ...@@ -68,6 +93,12 @@ definitions:
type: string type: string
secretKey: secretKey:
type: string type: string
useCdnDomains:
type: boolean
useHttps:
type: boolean
zone:
type: string
type: object type: object
config.Redis: config.Redis:
properties: properties:
...@@ -86,17 +117,22 @@ definitions: ...@@ -86,17 +117,22 @@ definitions:
casbin: casbin:
$ref: '#/definitions/config.Casbin' $ref: '#/definitions/config.Casbin'
type: object type: object
email:
$ref: '#/definitions/config.Email'
type: object
jwt: jwt:
$ref: '#/definitions/config.JWT' $ref: '#/definitions/config.JWT'
type: object type: object
localUpload: local:
$ref: '#/definitions/config.LocalUpload' $ref: '#/definitions/config.Local'
type: object description: oss
log:
$ref: '#/definitions/config.Log'
type: object type: object
mysql: mysql:
$ref: '#/definitions/config.Mysql' $ref: '#/definitions/config.Mysql'
description: gorm
type: object
postgresql:
$ref: '#/definitions/config.Postgresql'
type: object type: object
qiniu: qiniu:
$ref: '#/definitions/config.Qiniu' $ref: '#/definitions/config.Qiniu'
...@@ -107,16 +143,37 @@ definitions: ...@@ -107,16 +143,37 @@ definitions:
sqlite: sqlite:
$ref: '#/definitions/config.Sqlite' $ref: '#/definitions/config.Sqlite'
type: object type: object
sqlserver:
$ref: '#/definitions/config.Sqlserver'
type: object
system: system:
$ref: '#/definitions/config.System' $ref: '#/definitions/config.System'
type: object type: object
zap:
$ref: '#/definitions/config.Zap'
type: object
type: object type: object
config.Sqlite: config.Sqlite:
properties: properties:
config: logger:
type: boolean
maxIdleConns:
type: integer
maxOpenConns:
type: integer
path:
type: string type: string
logMode: type: object
config.Sqlserver:
properties:
dbname:
type: string
logger:
type: boolean type: boolean
maxIdleConns:
type: integer
maxOpenConns:
type: integer
password: password:
type: string type: string
path: path:
...@@ -132,9 +189,34 @@ definitions: ...@@ -132,9 +189,34 @@ definitions:
type: string type: string
env: env:
type: string type: string
needInitData:
type: boolean
ossType:
type: string
useMultipoint: useMultipoint:
type: boolean type: boolean
type: object type: object
config.Zap:
properties:
director:
type: string
encodeLevel:
type: string
format:
type: string
level:
type: string
linkName:
type: string
logInConsole:
type: boolean
prefix:
type: string
showLine:
type: boolean
stacktraceKey:
type: string
type: object
model.AutoCodeStruct: model.AutoCodeStruct:
properties: properties:
abbreviation: abbreviation:
...@@ -378,7 +460,7 @@ definitions: ...@@ -378,7 +460,7 @@ definitions:
isEnd: isEnd:
description: 是否是完结流节点 description: 是否是完结流节点
type: boolean type: boolean
isStrat: isStart:
description: 是否是开始流节点 description: 是否是开始流节点
type: boolean type: boolean
stepAuthorityID: stepAuthorityID:
...@@ -919,25 +1001,6 @@ paths: ...@@ -919,25 +1001,6 @@ paths:
summary: 用户登录 summary: 用户登录
tags: tags:
- Base - Base
/base/register:
post:
parameters:
- description: 用户注册接口
in: body
name: data
required: true
schema:
$ref: '#/definitions/model.SysUser'
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"注册成功"}'
schema:
type: string
summary: 用户注册账号
tags:
- Base
/casbin/UpdateCasbin: /casbin/UpdateCasbin:
post: post:
consumes: consumes:
...@@ -1096,6 +1159,20 @@ paths: ...@@ -1096,6 +1159,20 @@ paths:
summary: 获取权限客户列表 summary: 获取权限客户列表
tags: tags:
- SysApi - SysApi
/email/emailTest:
post:
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"返回成功"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: 发送测试邮件
tags:
- system
/fileUploadAndDownload/breakpointContinue: /fileUploadAndDownload/breakpointContinue:
post: post:
consumes: consumes:
...@@ -1870,6 +1947,20 @@ paths: ...@@ -1870,6 +1947,20 @@ paths:
summary: 设置配置文件内容 summary: 设置配置文件内容
tags: tags:
- system - system
/system/getServerInfo:
post:
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"获取成功"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: 获取服务器信息
tags:
- system
/system/getSystemConfig: /system/getSystemConfig:
post: post:
produces: produces:
...@@ -1972,6 +2063,25 @@ paths: ...@@ -1972,6 +2063,25 @@ paths:
summary: 分页获取用户列表 summary: 分页获取用户列表
tags: tags:
- SysUser - SysUser
/user/register:
post:
parameters:
- description: 用户注册接口
in: body
name: data
required: true
schema:
$ref: '#/definitions/model.SysUser'
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"注册成功"}'
schema:
type: string
summary: 用户注册账号
tags:
- Base
/user/setUserAuthority: /user/setUserAuthority:
post: post:
consumes: consumes:
...@@ -1995,6 +2105,29 @@ paths: ...@@ -1995,6 +2105,29 @@ paths:
summary: 设置用户权限 summary: 设置用户权限
tags: tags:
- SysUser - SysUser
/user/setUserInfo:
put:
consumes:
- application/json
parameters:
- description: 删除用户
in: body
name: data
required: true
schema:
$ref: '#/definitions/model.SysUser'
produces:
- application/json
responses:
"200":
description: '{"success":true,"data":{},"msg":"修改成功"}'
schema:
type: string
security:
- ApiKeyAuth: []
summary: 删除用户
tags:
- SysUser
/workflow/createWorkFlow: /workflow/createWorkFlow:
post: post:
parameters: parameters:
......
...@@ -5,6 +5,7 @@ go 1.12 ...@@ -5,6 +5,7 @@ go 1.12
require ( require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6 // indirect
github.com/casbin/casbin v1.9.1 github.com/casbin/casbin v1.9.1
github.com/casbin/casbin/v2 v2.11.0 github.com/casbin/casbin/v2 v2.11.0
github.com/casbin/gorm-adapter/v3 v3.0.2 github.com/casbin/gorm-adapter/v3 v3.0.2
...@@ -20,12 +21,14 @@ require ( ...@@ -20,12 +21,14 @@ require (
github.com/go-redis/redis v6.15.7+incompatible github.com/go-redis/redis v6.15.7+incompatible
github.com/go-sql-driver/mysql v1.5.0 github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.4.2 // indirect github.com/golang/protobuf v1.4.2 // indirect
github.com/gookit/color v1.3.1
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84 github.com/jordan-wright/email v0.0.0-20200824153738-3f5bafa1cd84
github.com/json-iterator/go v1.1.10 // indirect github.com/json-iterator/go v1.1.10 // indirect
github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible github.com/lestrrat-go/file-rotatelogs v2.3.0+incompatible
github.com/lestrrat-go/strftime v1.0.3 // indirect github.com/lestrrat-go/strftime v1.0.3 // indirect
github.com/mailru/easyjson v0.7.1 // indirect github.com/mailru/easyjson v0.7.1 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.2.2 // indirect github.com/mitchellh/mapstructure v1.2.2 // indirect
github.com/mojocn/base64Captcha v1.3.1 github.com/mojocn/base64Captcha v1.3.1
github.com/onsi/ginkgo v1.7.0 // indirect github.com/onsi/ginkgo v1.7.0 // indirect
...@@ -37,12 +40,14 @@ require ( ...@@ -37,12 +40,14 @@ require (
github.com/shirou/gopsutil v2.20.8+incompatible github.com/shirou/gopsutil v2.20.8+incompatible
github.com/spf13/afero v1.2.2 // indirect github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.1.1
github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.6.2 github.com/spf13/viper v1.7.0
github.com/swaggo/gin-swagger v1.2.0 github.com/swaggo/gin-swagger v1.2.0
github.com/swaggo/swag v1.6.7 github.com/swaggo/swag v1.6.7
github.com/tebeka/strftime v0.1.3 // indirect github.com/tebeka/strftime v0.1.3 // indirect
github.com/unrolled/secure v1.0.7 github.com/unrolled/secure v1.0.7
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77 // indirect
go.uber.org/zap v1.10.0 go.uber.org/zap v1.10.0
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect golang.org/x/sys v0.0.0-20200610111108-226ff32320da // indirect
......
此差异已折叠。
...@@ -5,33 +5,23 @@ import ( ...@@ -5,33 +5,23 @@ import (
"gin-vue-admin/model" "gin-vue-admin/model"
"go.uber.org/zap" "go.uber.org/zap"
"gorm.io/driver/mysql" "gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlserver"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/logger" "gorm.io/gorm/logger"
"os" "os"
) )
var err error
// Gorm 初始化数据库并产生数据库全局变量 // Gorm 初始化数据库并产生数据库全局变量
func Gorm() { func Gorm() *gorm.DB {
switch global.GVA_CONFIG.System.DbType { switch global.GVA_CONFIG.System.DbType {
case "mysql": case "mysql":
GormMysql() return GormMysql()
case "postgresql":
GormPostgreSql()
//case "sqlite": // sqlite需要gcc支持 windows用户需要自行安装gcc 如需使用打开注释即可
// GormSqlite()
case "sqlserver":
GormSqlServer()
default: default:
GormMysql() return GormMysql()
} }
} }
// GormDBTables 注册数据库表专用 // MysqlTables 注册数据库表专用
func GormDBTables(db *gorm.DB) { func MysqlTables(db *gorm.DB) {
err := db.AutoMigrate( err := db.AutoMigrate(
model.SysUser{}, model.SysUser{},
model.SysAuthority{}, model.SysAuthority{},
...@@ -58,7 +48,7 @@ func GormDBTables(db *gorm.DB) { ...@@ -58,7 +48,7 @@ func GormDBTables(db *gorm.DB) {
} }
// GormMysql 初始化Mysql数据库 // GormMysql 初始化Mysql数据库
func GormMysql() { func GormMysql() *gorm.DB {
m := global.GVA_CONFIG.Mysql m := global.GVA_CONFIG.Mysql
dsn := m.Username + ":" + m.Password + "@tcp(" + m.Path + ")/" + m.Dbname + "?" + m.Config dsn := m.Username + ":" + m.Password + "@tcp(" + m.Path + ")/" + m.Dbname + "?" + m.Config
mysqlConfig := mysql.Config{ mysqlConfig := mysql.Config{
...@@ -69,80 +59,29 @@ func GormMysql() { ...@@ -69,80 +59,29 @@ func GormMysql() {
DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列 DontSupportRenameColumn: true, // 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
SkipInitializeWithVersion: false, // 根据版本自动配置 SkipInitializeWithVersion: false, // 根据版本自动配置
} }
gormConfig := config(m.LogMode) if db, err := gorm.Open(mysql.New(mysqlConfig), gormConfig(m.LogMode)); err != nil {
if global.GVA_DB, err = gorm.Open(mysql.New(mysqlConfig), gormConfig); err != nil {
global.GVA_LOG.Error("MySQL启动异常", zap.Any("err", err)) global.GVA_LOG.Error("MySQL启动异常", zap.Any("err", err))
os.Exit(0) os.Exit(0)
return nil
} else { } else {
GormDBTables(global.GVA_DB) sqlDB, _ := db.DB()
sqlDB, _ := global.GVA_DB.DB()
sqlDB.SetMaxIdleConns(m.MaxIdleConns) sqlDB.SetMaxIdleConns(m.MaxIdleConns)
sqlDB.SetMaxOpenConns(m.MaxOpenConns) sqlDB.SetMaxOpenConns(m.MaxOpenConns)
return db
} }
} }
// GormPostgreSql 初始化PostgreSql数据库 // gormConfig 根据配置决定是否开启日志
func GormPostgreSql() { func gormConfig(mod bool) *gorm.Config {
p := global.GVA_CONFIG.Postgresql
dsn := "host="+ p.Host + " user=" + p.Username + " password=" + p.Password + " dbname=" + p.Dbname + " port=" + p.Port + " " + p.Config
postgresConfig := postgres.Config{
DSN: dsn, // DSN data source name
PreferSimpleProtocol: p.PreferSimpleProtocol, // 禁用隐式 prepared statement
}
gormConfig := config(p.Logger)
if global.GVA_DB, err = gorm.Open(postgres.New(postgresConfig), gormConfig); err != nil {
global.GVA_LOG.Error("PostgreSql启动异常", zap.Any("err", err))
os.Exit(0)
} else {
GormDBTables(global.GVA_DB)
sqlDB, _ := global.GVA_DB.DB()
sqlDB.SetMaxIdleConns(p.MaxIdleConns)
sqlDB.SetMaxOpenConns(p.MaxOpenConns)
}
}
// GormSqlite 初始化Sqlite数据库 sqlite需要gcc支持 windows用户需要自行安装gcc 如需使用打开注释即可
//func GormSqlite() {
// s := global.GVA_CONFIG.Sqlite
// gormConfig := config(s.Logger)
// if global.GVA_DB, err = gorm.Open(sqlite.Open(s.Path), gormConfig); err != nil {
// global.GVA_LOG.Error("Sqlite启动异常", zap.Any("err", err))
// os.Exit(0)
// } else {
// GormDBTables(global.GVA_DB)
// sqlDB, _ := global.GVA_DB.DB()
// sqlDB.SetMaxIdleConns(s.MaxIdleConns)
// sqlDB.SetMaxOpenConns(s.MaxOpenConns)
// }
//}
// GormSqlServer 初始化SqlServer数据库
func GormSqlServer() {
ss := global.GVA_CONFIG.Sqlserver
dsn := "sqlserver://" + ss.Username + ":" + ss.Password + "@" + ss.Path + "?database=gorm"
if global.GVA_DB, err = gorm.Open(sqlserver.Open(dsn), &gorm.Config{}); err != nil {
global.GVA_LOG.Error("SqlServer启动异常", zap.Any("err", err))
os.Exit(0)
} else {
GormDBTables(global.GVA_DB)
sqlDB, _ := global.GVA_DB.DB()
sqlDB.SetMaxIdleConns(ss.MaxIdleConns)
sqlDB.SetMaxOpenConns(ss.MaxOpenConns)
}
}
// config 根据配置决定是否开启日志
func config(mod bool) (c *gorm.Config) {
if mod { if mod {
c = &gorm.Config{ return &gorm.Config{
Logger: logger.Default.LogMode(logger.Info), Logger: logger.Default.LogMode(logger.Info),
DisableForeignKeyConstraintWhenMigrating: true, DisableForeignKeyConstraintWhenMigrating: true,
} }
} else { } else {
c = &gorm.Config{ return &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent), Logger: logger.Default.LogMode(logger.Silent),
DisableForeignKeyConstraintWhenMigrating: true, DisableForeignKeyConstraintWhenMigrating: true,
} }
} }
return }
} \ No newline at end of file
...@@ -3,7 +3,6 @@ package main ...@@ -3,7 +3,6 @@ package main
import ( import (
"gin-vue-admin/core" "gin-vue-admin/core"
"gin-vue-admin/global" "gin-vue-admin/global"
"gin-vue-admin/gva/init_data"
"gin-vue-admin/initialize" "gin-vue-admin/initialize"
) )
...@@ -15,10 +14,10 @@ import ( ...@@ -15,10 +14,10 @@ import (
// @name x-token // @name x-token
// @BasePath / // @BasePath /
func main() { func main() {
initialize.Gorm() global.GVA_VP = core.Viper() // 初始化Viper
if global.GVA_CONFIG.System.NeedInitData { global.GVA_LOG = core.Zap() // 初始化zap日志库
init_data.InitData() // 通过配置文件初始化数据 默认为 false 首次运行需要将 ./config.yaml中 system下的 need-init-data 修改为true global.GVA_DB = initialize.Gorm() // gorm连接数据库
} initialize.MysqlTables(global.GVA_DB) // 初始化表
// 程序结束前关闭数据库链接 // 程序结束前关闭数据库链接
db, _ := global.GVA_DB.DB() db, _ := global.GVA_DB.DB()
defer db.Close() defer db.Close()
......
...@@ -16,7 +16,7 @@ type SysOperationRecord struct { ...@@ -16,7 +16,7 @@ type SysOperationRecord struct {
Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:延迟"` Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:延迟"`
Agent string `json:"agent" form:"agent" gorm:"column:agent;comment:代理"` Agent string `json:"agent" form:"agent" gorm:"column:agent;comment:代理"`
ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:错误信息"` ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:错误信息"`
Body string `json:"body" form:"body" gorm:"column:body;comment:请求Body"` Body string `json:"body" form:"body" gorm:"type:longtext;column:body;comment:请求Body"`
Resp string `json:"resp" form:"resp" gorm:"type:longtext;column:resp;comment:响应Body"` Resp string `json:"resp" form:"resp" gorm:"type:longtext;column:resp;comment:响应Body"`
UserID int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:用户id"` UserID int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:用户id"`
User SysUser `json:"user"` User SysUser `json:"user"`
......
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
func InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) { func InitBaseRouter(Router *gin.RouterGroup) (R gin.IRoutes) {
BaseRouter := Router.Group("base") BaseRouter := Router.Group("base")
{ {
BaseRouter.POST("register", v1.Register)
BaseRouter.POST("login", v1.Login) BaseRouter.POST("login", v1.Login)
BaseRouter.POST("captcha", v1.Captcha) BaseRouter.POST("captcha", v1.Captcha)
} }
......
...@@ -12,6 +12,7 @@ func InitUserRouter(Router *gin.RouterGroup) { ...@@ -12,6 +12,7 @@ func InitUserRouter(Router *gin.RouterGroup) {
Use(middleware.CasbinHandler()). Use(middleware.CasbinHandler()).
Use(middleware.OperationRecord()) Use(middleware.OperationRecord())
{ {
UserRouter.POST("register", v1.Register)
UserRouter.POST("changePassword", v1.ChangePassword) // 修改密码 UserRouter.POST("changePassword", v1.ChangePassword) // 修改密码
UserRouter.POST("getUserList", v1.GetUserList) // 分页获取用户列表 UserRouter.POST("getUserList", v1.GetUserList) // 分页获取用户列表
UserRouter.POST("setUserAuthority", v1.SetUserAuthority) // 设置用户权限 UserRouter.POST("setUserAuthority", v1.SetUserAuthority) // 设置用户权限
......
package utils
const (
ConfigEnv = "GVA_CONFIG"
ConfigFile = "config.yaml"
)
// +build !windows
package utils
import (
"gin-vue-admin/global"
zaprotatelogs "github.com/lestrrat-go/file-rotatelogs"
"go.uber.org/zap/zapcore"
"os"
"path"
"time"
)
// GetWriteSyncer zap logger中加入file-rotatelogs
func GetWriteSyncer() (zapcore.WriteSyncer, error) {
fileWriter, err := zaprotatelogs.New(
path.Join(global.GVA_CONFIG.Zap.Director, "%Y-%m-%d.log"),
zaprotatelogs.WithLinkName(global.GVA_CONFIG.Zap.LinkName),
zaprotatelogs.WithMaxAge(7*24*time.Hour),
zaprotatelogs.WithRotationTime(24*time.Hour),
)
if global.GVA_CONFIG.Zap.LogInConsole {
return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err
}
return zapcore.AddSync(fileWriter), err
}
\ No newline at end of file
package utils
import (
"gin-vue-admin/global"
zaprotatelogs "github.com/lestrrat-go/file-rotatelogs"
"go.uber.org/zap/zapcore"
"os"
"path"
"time"
)
// GetWriteSyncer zap logger中加入file-rotatelogs
func GetWriteSyncer() (zapcore.WriteSyncer, error) {
fileWriter, err := zaprotatelogs.New(
path.Join(global.GVA_CONFIG.Zap.Director, "%Y-%m-%d.log"),
zaprotatelogs.WithMaxAge(7*24*time.Hour),
zaprotatelogs.WithRotationTime(24*time.Hour),
)
if global.GVA_CONFIG.Zap.LogInConsole {
return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err
}
return zapcore.AddSync(fileWriter), err
}
\ No newline at end of file
/*
商用代码公司自用产品无需授权
若作为代码出售的产品(任何涉及代码交付第三方作为后续开发)必须保留此脚本
或标注原作者信息
否则将依法维权
*/
var child_process = require("child_process");
var url = "https://www.gin-vue-admin.com",
cmd = '';
console.log(process.platform)
switch (process.platform) {
case 'win32':
cmd = 'start';
child_process.exec(cmd + ' ' + url);
break;
case 'darwin':
cmd = 'open';
child_process.exec(cmd + ' ' + url);
break;
}
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "start https://www.gin-vue-admin.com && vue-cli-service serve", "serve": "node openDocument.js && vue-cli-service serve",
"build": "vue-cli-service build", "build": "vue-cli-service build",
"lint": "vue-cli-service lint" "lint": "vue-cli-service lint"
}, },
......
...@@ -30,7 +30,7 @@ export const captcha = (data) => { ...@@ -30,7 +30,7 @@ export const captcha = (data) => {
// @Router /base/resige [post] // @Router /base/resige [post]
export const register = (data) => { export const register = (data) => {
return service({ return service({
url: "/base/register", url: "/user/register",
method: 'post', method: 'post',
data: data data: data
}) })
......
...@@ -54,7 +54,7 @@ auth(Vue) ...@@ -54,7 +54,7 @@ auth(Vue)
import uploader from 'vue-simple-uploader' import uploader from 'vue-simple-uploader'
Vue.use(uploader) Vue.use(uploader)
new Vue({ export default new Vue({
render: h => h(App), render: h => h(App),
router, router,
store store
......
...@@ -3,7 +3,7 @@ import { store } from '@/store/index' ...@@ -3,7 +3,7 @@ import { store } from '@/store/index'
let asyncRouterFlag = 0 let asyncRouterFlag = 0
const whiteList = ['login', 'register'] const whiteList = ['login']
router.beforeEach(async(to, from, next) => { router.beforeEach(async(to, from, next) => {
const token = store.getters['user/token'] const token = store.getters['user/token']
......
...@@ -12,12 +12,6 @@ const baseRouters = [{ ...@@ -12,12 +12,6 @@ const baseRouters = [{
name: 'login', name: 'login',
component: () => component: () =>
import ('@/view/login/login.vue') import ('@/view/login/login.vue')
},
{
path: '/register',
name: 'register',
component: () =>
import ('@/view/login/register.vue')
} }
] ]
......
import axios from 'axios'; // 引入axios import axios from 'axios'; // 引入axios
import { Message, Loading } from 'element-ui'; import { Message } from 'element-ui';
import { store } from '@/store/index' import { store } from '@/store/index'
import context from '@/main.js'
const service = axios.create({ const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, baseURL: process.env.VUE_APP_BASE_API,
timeout: 99999 timeout: 99999
}) })
let acitveAxios = 0 let acitveAxios = 0
let loadingInstance
let timer let timer
const showLoading = () => { const showLoading = () => {
acitveAxios++ acitveAxios++
...@@ -15,7 +15,7 @@ const showLoading = () => { ...@@ -15,7 +15,7 @@ const showLoading = () => {
} }
timer = setTimeout(() => { timer = setTimeout(() => {
if (acitveAxios > 0) { if (acitveAxios > 0) {
loadingInstance = Loading.service({ fullscreen: true }) context.$bus.emit("showLoading")
} }
}, 400); }, 400);
} }
...@@ -24,13 +24,12 @@ const closeLoading = () => { ...@@ -24,13 +24,12 @@ const closeLoading = () => {
acitveAxios-- acitveAxios--
if (acitveAxios <= 0) { if (acitveAxios <= 0) {
clearTimeout(timer) clearTimeout(timer)
loadingInstance && loadingInstance.close() context.$bus.emit("closeLoading")
} }
} }
//http request 拦截器 //http request 拦截器
service.interceptors.request.use( service.interceptors.request.use(
config => { config => {
console.log(config)
if (!config.donNotShowLoading) { if (!config.donNotShowLoading) {
showLoading() showLoading()
} }
......
<template> <template>
<div> <div>
<h1>富文本编辑器</h1>
<div class="edit_container"> <div class="edit_container">
<quill-editor <quill-editor
:options="editorOption" :options="editorOption"
...@@ -11,6 +12,7 @@ ...@@ -11,6 +12,7 @@
></quill-editor> ></quill-editor>
<el-button plain @click="saveHtml">保存</el-button> <el-button plain @click="saveHtml">保存</el-button>
</div> </div>
<h1>markdown编辑器</h1>
<div class="edit"> <div class="edit">
<mavon-editor v-model="model.content"></mavon-editor> <mavon-editor v-model="model.content"></mavon-editor>
<el-button type="primary" size="small" @click="submit">发表</el-button> <el-button type="primary" size="small" @click="submit">发表</el-button>
...@@ -42,7 +44,9 @@ export default { ...@@ -42,7 +44,9 @@ export default {
onEditorBlur() {}, // 失去焦点事件 onEditorBlur() {}, // 失去焦点事件
onEditorFocus() {}, // 获得焦点事件 onEditorFocus() {}, // 获得焦点事件
onEditorChange() {}, // 内容改变事件 onEditorChange() {}, // 内容改变事件
saveHtml() {}, // 保存方法 saveHtml() {
console.log(this.content)
}, // 保存方法
submit(){} submit(){}
} }
} }
......
...@@ -58,11 +58,11 @@ ...@@ -58,11 +58,11 @@
</transition> </transition>
<transition mode="out-in" name="el-fade-in-linear"> <transition mode="out-in" name="el-fade-in-linear">
<keep-alive> <keep-alive>
<router-view class="admin-box" v-if="$route.meta.keepAlive"></router-view> <router-view v-loading="loadingFlag" element-loading-text="正在加载中" class="admin-box" v-if="$route.meta.keepAlive"></router-view>
</keep-alive> </keep-alive>
</transition> </transition>
<transition mode="out-in" name="el-fade-in-linear"> <transition mode="out-in" name="el-fade-in-linear">
<router-view class="admin-box" v-if="!$route.meta.keepAlive"></router-view> <router-view v-loading="loadingFlag" element-loading-text="正在加载中" class="admin-box" v-if="!$route.meta.keepAlive"></router-view>
</transition> </transition>
<BottomInfo /> <BottomInfo />
</el-main> </el-main>
...@@ -106,6 +106,7 @@ export default { ...@@ -106,6 +106,7 @@ export default {
isMobile: false, isMobile: false,
isShadowBg: false, isShadowBg: false,
showPassword: false, showPassword: false,
loadingFlag:false,
pwdModify: {}, pwdModify: {},
rules: { rules: {
password: [ password: [
...@@ -209,6 +210,12 @@ export default { ...@@ -209,6 +210,12 @@ export default {
} }
this.$bus.emit('collapse', this.isCollapse) this.$bus.emit('collapse', this.isCollapse)
this.$bus.emit('mobile', this.isMobile) this.$bus.emit('mobile', this.isMobile)
this.$bus.on("showLoading",()=>{
this.loadingFlag = true
})
this.$bus.on("closeLoading",()=>{
this.loadingFlag = false
})
window.onresize = () => { window.onresize = () => {
return (() => { return (() => {
let screenWidth = document.body.clientWidth let screenWidth = document.body.clientWidth
......
<template>
<div id="userLayout" class="user-layout-wrapper">
<div class="container">
<div class="top">
<div class="desc">
<img class="logo_login" src="@/assets/logo_login.png" alt="" />
</div>
<div class="header">
<a href="/">
<!-- <img src="~@/assets/logo.png" class="logo" alt="logo" /> -->
<span class="title">Gin-Vue-Admin</span>
</a>
</div>
</div>
<div class="main">
<el-form
:model="registerForm"
:rules="rules"
ref="registerForm"
@keyup.enter.native="submitForm"
>
<el-form-item prop="username">
<el-input
placeholder="请输入用户名"
v-model="registerForm.username"
>
<i
class="el-input__icon el-icon-user"
slot="suffix"
></i></el-input>
</el-form-item>
<el-form-item prop="password">
<el-input
:type="lock === 'lock' ? 'password' : 'text'"
placeholder="请输入密码"
v-model="registerForm.password"
>
<i
:class="'el-input__icon el-icon-' + lock"
@click="changeLock"
slot="suffix"
></i>
</el-input>
</el-form-item>
<el-form-item prop="rePassword" style="position:relative">
<el-input
:type="lock==='lock'?'password':'text'"
placeholder="请再次输入密码"
v-model="registerForm.rePassword"
>
<i :class="'el-input__icon el-icon-' + lock" @click="changeLock" slot="suffix"></i>
</el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm" style="width:100%"
>注 册</el-button
>
</el-form-item>
</el-form>
</div>
<div class="footer">
<div class="links">
<a href="http://doc.henrongyi.top/"
><img src="@/assets/docs.png" class="link-icon"
/></a>
<a href="https://www.yuque.com/flipped-aurora/"
><img src="@/assets/yuque.png" class="link-icon"
/></a>
<a href="https://github.com/flipped-aurora/gin-vue-admin"
><img src="@/assets/github.png" class="link-icon"
/></a>
<a href="https://space.bilibili.com/322210472"
><img src="@/assets/video.png" class="link-icon"
/></a>
</div>
<div class="copyright">
Copyright &copy; 2020 💖flipped-aurora
</div>
</div>
</div>
</div>
</template>
<script>
import { mapActions } from 'vuex'
import { register } from '@/api/user'
export default {
name: 'Register',
data() {
const ratioPassword = (rule, value, callback) => {
if (value != this.registerForm.password) {
return callback(new Error('两次密码不同'))
} else {
callback()
}
}
const checkUsername = (rule, value, callback) => {
if (value.length < 5 || value.length > 12) {
return callback(new Error('请输入正确的用户名'))
} else {
callback()
}
}
const checkPassword = (rule, value, callback) => {
if (value.length < 6 || value.length > 12) {
return callback(new Error('请输入正确的密码'))
} else {
callback()
}
}
return {
lock: 'lock',
registerForm: {
username: '',
password: '',
rePassword: ''
},
rules: {
username: [{ validator: checkUsername, trigger: 'blur' }],
password: [{ validator: checkPassword, trigger: 'blur' }],
rePassword: [{ validator: ratioPassword, trigger: 'blur' }]
}
}
},
methods: {
...mapActions('user', ['LoginIn']),
async submitForm() {
this.$refs.registerForm.validate(async v => {
if (v) {
const res = await register(this.registerForm)
if (res.code == 0) {
this.$message({
type: 'success',
message: '注册成功',
showClose: true
})
this.$router.push({name:"login"})
}
} else {
this.$message({
type: 'error',
message: '请正确填写注册信息',
showClose: true
})
return false
}
})
},
changeLock() {
this.lock === 'lock' ? (this.lock = 'unlock') : (this.lock = 'lock')
}
}
}
</script>
<style scoped lang="scss">
.login-register-box {
height: 100vh;
.login-box {
width: 40vw;
position: absolute;
left: 50%;
margin-left: -22vw;
top: 5vh;
.logo {
height: 35vh;
width: 35vh;
}
}
}
.link-icon {
width: 20px;
min-width: 20px;
height: 20px;
border-radius: 10px;
}
.vPic {
width: 33%;
height: 38px;
float: right !important;
img {
cursor: pointer;
vertical-align: middle;
}
}
.logo_login {
width: 100px;
}
#userLayout.user-layout-wrapper {
height: 100%;
position: relative;
&.mobile {
.container {
.main {
max-width: 368px;
width: 98%;
}
}
}
.container {
width: 100%;
min-height: 100%;
background: #f0f2f5 url(~@/assets/background.svg) no-repeat 50%;
background-size: 100%;
padding: 110px 0 144px;
a {
text-decoration: none;
}
.top {
text-align: center;
margin-top: -40px;
.header {
height: 44px;
line-height: 44px;
margin-bottom: 30px;
.badge {
position: absolute;
display: inline-block;
line-height: 1;
vertical-align: middle;
margin-left: -12px;
margin-top: -10px;
opacity: 0.8;
}
.logo {
height: 44px;
vertical-align: top;
margin-right: 16px;
border-style: none;
}
.title {
font-size: 33px;
color: rgba(0, 0, 0, 0.85);
font-family: Avenir, "Helvetica Neue", Arial, Helvetica, sans-serif;
font-weight: 600;
position: relative;
top: 2px;
}
}
.desc {
font-size: 14px;
color: rgba(0, 0, 0, 0.45);
margin-top: 12px;
}
}
.main {
min-width: 260px;
width: 368px;
margin: 0 auto;
}
.footer {
position: relative;
width: 100%;
margin: 40px 0 0 0;
text-align: center;
.links {
margin-bottom: 8px;
font-size: 14px;
a {
color: rgba(0, 0, 0, 0.45);
transition: all 0.3s;
&:not(:last-child) {
margin-right: 80px;
}
}
}
.copyright {
color: rgba(0, 0, 0, 0.45);
font-size: 14px;
}
}
}
}
</style>
\ No newline at end of file
...@@ -138,6 +138,7 @@ export default { ...@@ -138,6 +138,7 @@ export default {
name: "State", name: "State",
data() { data() {
return { return {
timer:null,
state: {}, state: {},
colors: [ colors: [
{ color: "#5cb87a", percentage: 20 }, { color: "#5cb87a", percentage: 20 },
...@@ -148,10 +149,14 @@ export default { ...@@ -148,10 +149,14 @@ export default {
}, },
created() { created() {
this.reload(); this.reload();
setInterval(() => { this.timer = setInterval(() => {
this.reload(); this.reload();
}, 1000*10); }, 1000*10);
}, },
beforeDestroy(){
clearInterval(this.timer)
this.timer = null
},
methods: { methods: {
async reload() { async reload() {
const { data } = await getSystemState(); const { data } = await getSystemState();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册