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

 Conflicts:
	server/api/v1/sys_work_flow.go
	server/service/sys_workflow.go
This commit is contained in:
pixel
2020-11-10 11:43:56 +08:00
89 changed files with 4351 additions and 4136 deletions
+3 -1
View File
@@ -12,12 +12,14 @@
[English](./README-en.md) | 简体中文
[gitee地址](https://gitee.com/pixelmax/gin-vue-admin)
[gitee地址](https://gitee.com/pixelmax/gin-vue-admin)|
[github地址](https://github.com/flipped-aurora/gin-vue-admin)
# 项目文档
[在线文档](https://www.gin-vue-admin.com/) : https://www.gin-vue-admin.com/
[从环境到部署教学视频](https://www.bilibili.com/video/BV1fV411y7dT)
[开发教学](https://www.gin-vue-admin.com/docs/help) (贡献者: <a href="https://github.com/LLemonGreen">LLemonGreen</a> And <a href="https://github.com/fkk0509">Fann</a>)
- 前端UI框架:[element-ui](https://github.com/ElemeFE/element)
- 后台框架:[gin](https://github.com/gin-gonic/gin)
+27 -18
View File
@@ -1,12 +1,12 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
resp "gin-vue-admin/model/response"
"gin-vue-admin/global"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"io/ioutil"
"strconv"
)
@@ -17,7 +17,7 @@ import (
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "an example for breakpoint resume, 断点续传示例"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"切片创建成功"}"
// @Router /fileUploadAndDownload/breakpointContinue [post]
func BreakpointContinue(c *gin.Context) {
fileMd5 := c.Request.FormValue("fileMd5")
@@ -27,33 +27,39 @@ func BreakpointContinue(c *gin.Context) {
chunkTotal, _ := strconv.Atoi(c.Request.FormValue("chunkTotal"))
_, FileHeader, err := c.Request.FormFile("file")
if err != nil {
response.FailWithMessage(err.Error(), c)
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
f, err := FileHeader.Open()
if err != nil {
response.FailWithMessage(err.Error(), c)
global.GVA_LOG.Error("文件读取失败!", zap.Any("err", err))
response.FailWithMessage("文件读取失败", c)
return
}
defer f.Close()
cen, _ := ioutil.ReadAll(f)
if flag := utils.CheckMd5(cen, chunkMd5); !flag {
response.FailWithMessage(err.Error(), c)
if !utils.CheckMd5(cen, chunkMd5) {
global.GVA_LOG.Error("检查md5失败!", zap.Any("err", err))
response.FailWithMessage("检查md5失败", c)
return
}
err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal)
if err != nil {
response.FailWithMessage(err.Error(), c)
global.GVA_LOG.Error("查找或创建记录失败!", zap.Any("err", err))
response.FailWithMessage("查找或创建记录失败", c)
return
}
err, pathc := utils.BreakPointContinue(cen, fileName, chunkNumber, chunkTotal, fileMd5)
if err != nil {
response.FailWithMessage(err.Error(), c)
global.GVA_LOG.Error("断点续传失败!", zap.Any("err", err))
response.FailWithMessage("断点续传失败", c)
return
}
if err = service.CreateFileChunk(file.ID, pathc, chunkNumber); err != nil {
response.FailWithMessage(err.Error(), c)
global.GVA_LOG.Error("创建文件记录失败!", zap.Any("err", err))
response.FailWithMessage("创建文件记录失败", c)
return
}
response.OkWithMessage("切片创建成功", c)
@@ -73,14 +79,15 @@ func FindFile(c *gin.Context) {
chunkTotal, _ := strconv.Atoi(c.Query("chunkTotal"))
err, file := service.FindOrCreateFile(fileMd5, fileName, chunkTotal)
if err != nil {
global.GVA_LOG.Error("查找失败!", zap.Any("err", err))
response.FailWithMessage("查找失败", c)
} else {
response.OkWithData(resp.FileResponse{File: file}, c)
response.OkWithDetailed(response.FileResponse{File: file},"查找成功", c)
}
}
// @Tags ExaFileUploadAndDownload
// @Summary 查找文件
// @Summary 创建文件
// @Security ApiKeyAuth
// @accept multipart/form-data
// @Produce application/json
@@ -92,9 +99,10 @@ func BreakpointContinueFinish(c *gin.Context) {
fileName := c.Query("fileName")
err, filePath := utils.MakeFile(fileName, fileMd5)
if err != nil {
response.FailWithDetailed(response.ERROR, resp.FilePathResponse{FilePath: filePath}, fmt.Sprintf("文件创建失败%v", err), c)
global.GVA_LOG.Error("文件创建失败!", zap.Any("err", err))
response.FailWithDetailed(response.FilePathResponse{FilePath: filePath}, "文件创建失败", c)
} else {
response.OkDetailed(resp.FilePathResponse{FilePath: filePath}, "文件创建成功", c)
response.OkWithDetailed(response.FilePathResponse{FilePath: filePath}, "文件创建成功", c)
}
}
@@ -104,7 +112,7 @@ func BreakpointContinueFinish(c *gin.Context) {
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "删除缓存切片"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查找成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"缓存切片删除成功"}"
// @Router /fileUploadAndDownload/removeChunk [post]
func RemoveChunk(c *gin.Context) {
fileMd5 := c.Query("fileMd5")
@@ -113,8 +121,9 @@ func RemoveChunk(c *gin.Context) {
err := utils.RemoveChunk(fileMd5)
err = service.DeleteFileChunk(fileMd5, fileName, filePath)
if err != nil {
response.FailWithDetailed(response.ERROR, resp.FilePathResponse{FilePath: filePath}, fmt.Sprintf("缓存切片删除失败%v", err), c)
global.GVA_LOG.Error("缓存切片删除失败!", zap.Any("err", err))
response.FailWithDetailed(response.FilePathResponse{FilePath: filePath},"缓存切片删除失败", c)
} else {
response.OkDetailed(resp.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c)
response.OkWithDetailed(response.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c)
}
}
+56 -80
View File
@@ -2,164 +2,140 @@ package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysApi
// @Tags ExaCustomer
// @Summary 创建客户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "创建客户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.ExaCustomer true "客户用户名, 客户手机号码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /customer/customer [post]
func CreateExaCustomer(c *gin.Context) {
var cu model.ExaCustomer
_ = c.ShouldBindJSON(&cu)
CustomerVerify := utils.Rules{
"CustomerName": {utils.NotEmpty()},
"CustomerPhoneData": {utils.NotEmpty()},
}
CustomerVerifyErr := utils.Verify(cu, CustomerVerify)
if CustomerVerifyErr != nil {
response.FailWithMessage(CustomerVerifyErr.Error(), c)
var customer model.ExaCustomer
_ = c.ShouldBindJSON(&customer)
if err := utils.Verify(customer, utils.CustomerVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
claims, _ := c.Get("claims")
waitUse := claims.(*request.CustomClaims)
cu.SysUserID = waitUse.ID
cu.SysUserAuthorityID = waitUse.AuthorityId
err := service.CreateExaCustomer(cu)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
customer.SysUserID = getUserID(c)
customer.SysUserAuthorityID = getUserAuthorityId(c)
if err := service.CreateExaCustomer(customer); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags SysApi
// @Tags ExaCustomer
// @Summary 删除客户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "删除客户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.ExaCustomer true "客户ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /customer/customer [delete]
func DeleteExaCustomer(c *gin.Context) {
var cu model.ExaCustomer
_ = c.ShouldBindJSON(&cu)
CustomerVerify := utils.Rules{
"ID": {utils.NotEmpty()},
}
CustomerVerifyErr := utils.Verify(cu.GVA_MODEL, CustomerVerify)
if CustomerVerifyErr != nil {
response.FailWithMessage(CustomerVerifyErr.Error(), c)
var customer model.ExaCustomer
_ = c.ShouldBindJSON(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.DeleteExaCustomer(cu)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
if err := service.DeleteExaCustomer(customer); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysApi
// @Tags ExaCustomer
// @Summary 更新客户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "创建客户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.ExaCustomer true "客户ID, 客户信息"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /customer/customer [put]
func UpdateExaCustomer(c *gin.Context) {
var cu model.ExaCustomer
_ = c.ShouldBindJSON(&cu)
IdCustomerVerify := utils.Rules{
"ID": {utils.NotEmpty()},
}
IdCustomerVerifyErr := utils.Verify(cu.GVA_MODEL, IdCustomerVerify)
if IdCustomerVerifyErr != nil {
response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
var customer model.ExaCustomer
_ = c.ShouldBindJSON(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
CustomerVerify := utils.Rules{
"CustomerName": {utils.NotEmpty()},
"CustomerPhoneData": {utils.NotEmpty()},
}
CustomerVerifyErr := utils.Verify(cu, CustomerVerify)
if CustomerVerifyErr != nil {
response.FailWithMessage(CustomerVerifyErr.Error(), c)
if err := utils.Verify(customer, utils.CustomerVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.UpdateExaCustomer(&cu)
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败:%v", err), c)
if err := service.UpdateExaCustomer(&customer); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败!", c)
} else {
response.OkWithMessage("更新成功", c)
}
}
// @Tags SysApi
// @Tags ExaCustomer
// @Summary 获取单一客户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.ExaCustomer true "获取单一客户信息"
// @Param data body model.ExaCustomer true "客户ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /customer/customer [get]
func GetExaCustomer(c *gin.Context) {
var cu model.ExaCustomer
_ = c.ShouldBindQuery(&cu)
IdCustomerVerify := utils.Rules{
"ID": {utils.NotEmpty()},
}
IdCustomerVerifyErr := utils.Verify(cu.GVA_MODEL, IdCustomerVerify)
if IdCustomerVerifyErr != nil {
response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
var customer model.ExaCustomer
_ = c.ShouldBindQuery(&customer)
if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, customer := service.GetExaCustomer(cu.ID)
err, data := service.GetExaCustomer(customer.ID)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败%v", err), c)
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.ExaCustomerResponse{Customer: customer}, c)
response.OkWithDetailed(response.ExaCustomerResponse{Customer: data}, "获取成功", c)
}
}
// @Tags SysApi
// @Summary 获取权限客户列表
// @Tags ExaCustomer
// @Summary 分页获取权限客户列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "获取权限客户列表"
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /customer/customerList [get]
func GetExaCustomerList(c *gin.Context) {
claims, _ := c.Get("claims")
waitUse := claims.(*request.CustomClaims)
var pageInfo request.PageInfo
_ = c.ShouldBindQuery(&pageInfo)
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
if PageVerifyErr != nil {
response.FailWithMessage(PageVerifyErr.Error(), c)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, customerList, total := service.GetCustomerInfoList(waitUse.AuthorityId, pageInfo)
err, customerList, total := service.GetCustomerInfoList(getUserAuthorityId(c), pageInfo)
if err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: customerList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
+16 -12
View File
@@ -1,13 +1,13 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags ExaFileUploadAndDownload
@@ -23,15 +23,17 @@ func UploadFile(c *gin.Context) {
noSave := c.DefaultQuery("noSave", "0")
_, header, err := c.Request.FormFile("file")
if err != nil {
response.FailWithMessage(fmt.Sprintf("上传文件失败%v", err), c)
global.GVA_LOG.Error("接收文件失败!", zap.Any("err", err))
response.FailWithMessage("接收文件失败", c)
return
}
err, file = service.UploadFile(header, noSave) // 文件上传后拿到文件路径
if err != nil {
response.FailWithMessage(fmt.Sprintf("修改数据库链接失败%v", err), c)
global.GVA_LOG.Error("修改数据库链接失败!", zap.Any("err", err))
response.FailWithMessage("修改数据库链接失败", c)
return
}
response.OkDetailed(resp.ExaFileResponse{File: file}, "上传成功", c)
response.OkWithDetailed(response.ExaFileResponse{File: file}, "上传成功", c)
}
// @Tags ExaFileUploadAndDownload
@@ -39,13 +41,14 @@ func UploadFile(c *gin.Context) {
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body model.ExaFileUploadAndDownload true "传入文件里面id即可"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /fileUploadAndDownload/deleteFile [post]
func DeleteFile(c *gin.Context) {
var file model.ExaFileUploadAndDownload
_ = c.ShouldBindJSON(&file)
if err := service.DeleteFile(file); err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败%v", err), c)
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
return
}
response.OkWithMessage("删除成功", c)
@@ -56,7 +59,7 @@ func DeleteFile(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "分页获取文件户列表"
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /fileUploadAndDownload/getFileList [post]
func GetFileList(c *gin.Context) {
@@ -64,13 +67,14 @@ func GetFileList(c *gin.Context) {
_ = c.ShouldBindJSON(&pageInfo)
err, list, total := service.GetFileRecordInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
},"获取成功", c)
}
}
+21 -15
View File
@@ -1,12 +1,13 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SimpleUploader
@@ -15,7 +16,7 @@ import (
// @accept multipart/form-data
// @Produce application/json
// @Param file formData file true "断点续传插件版示例"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"切片创建成功"}"
// @Router /simpleUploader/upload [post]
func SimpleUploaderUpload(c *gin.Context) {
var chunk model.ExaSimpleUploader
@@ -29,42 +30,46 @@ func SimpleUploaderUpload(c *gin.Context) {
var chunkDir = "./chunk/" + chunk.Identifier + "/"
hasDir, _ := utils.PathExists(chunkDir)
if !hasDir {
utils.CreateDir(chunkDir)
if err := utils.CreateDir(chunkDir); err != nil {
global.GVA_LOG.Error("创建目录失败!", zap.Any("err", err))
}
}
chunkPath := chunkDir + chunk.Filename + chunk.ChunkNumber
err = c.SaveUploadedFile(header, chunkPath)
if err != nil {
response.FailWithMessage(fmt.Sprintf("切片创建失败%v", err), c)
global.GVA_LOG.Error("切片创建失败!", zap.Any("err", err))
response.FailWithMessage("切片创建失败", c)
return
}
chunk.CurrentChunkPath = chunkPath
err = service.SaveChunk(chunk)
if err != nil {
response.FailWithMessage(fmt.Sprintf("切片创建失败%v", err), c)
global.GVA_LOG.Error("切片创建失败!", zap.Any("err", err))
response.FailWithMessage("切片创建失败", c)
return
} else {
response.Ok(c)
response.OkWithMessage("切片创建成功", c)
}
}
// @Tags SimpleUploader
// @Summary 断点续传插件版示例
// @Security ApiKeyAuth
// @Produce application/json
// @Param md5 query string true "测试文件是否已经存在和判断已经上传过的切片"
// @Param md5 query string true "md5"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /simpleUploader/checkFileMd5 [get]
func CheckFileMd5(c *gin.Context) {
md5 := c.Query("md5")
err, chunks, isDone := service.CheckFileMd5(md5)
if err != nil {
response.FailWithMessage(fmt.Sprintf("md5读取失败%v", err), c)
global.GVA_LOG.Error("md5读取失败!", zap.Any("err", err))
response.FailWithMessage("md5读取失败", c)
} else {
response.OkWithData(gin.H{
response.OkWithDetailed(gin.H{
"chunks": chunks,
"isDone": isDone,
}, c)
},"查询成功", c)
}
}
@@ -72,7 +77,7 @@ func CheckFileMd5(c *gin.Context) {
// @Summary 合并文件
// @Security ApiKeyAuth
// @Produce application/json
// @Param md5 query string true "合并文件"
// @Param md5 query string true "md5"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"合并成功"}"
// @Router /simpleUploader/mergeFileMd5 [get]
func MergeFileMd5(c *gin.Context) {
@@ -80,8 +85,9 @@ func MergeFileMd5(c *gin.Context) {
fileName := c.Query("fileName")
err := service.MergeFileMd5(md5, fileName)
if err != nil {
response.FailWithMessage(fmt.Sprintf("md5读取失败%v", err), c)
global.GVA_LOG.Error("md5读取失败!", zap.Any("err", err))
response.FailWithMessage("md5读取失败", c)
} else {
response.OkWithData(gin.H{}, c)
response.OkWithMessage("合并成功", c)
}
}
+48 -70
View File
@@ -1,14 +1,14 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysApi
@@ -16,60 +16,47 @@ import (
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysApi true "创建api"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysApi true "api路径, api中文描述, api组, 方法"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /api/createApi [post]
func CreateApi(c *gin.Context) {
var api model.SysApi
_ = c.ShouldBindJSON(&api)
ApiVerify := utils.Rules{
"Path": {utils.NotEmpty()},
"Description": {utils.NotEmpty()},
"ApiGroup": {utils.NotEmpty()},
"Method": {utils.NotEmpty()},
}
ApiVerifyErr := utils.Verify(api, ApiVerify)
if ApiVerifyErr != nil {
response.FailWithMessage(ApiVerifyErr.Error(), c)
if err := utils.Verify(api, utils.ApiVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.CreateApi(api)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
if err := service.CreateApi(api); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// @Tags SysApi
// @Summary 删除指定api
// @Summary 删除api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysApi true "删除api"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysApi true "ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /api/deleteApi [post]
func DeleteApi(c *gin.Context) {
var a model.SysApi
_ = c.ShouldBindJSON(&a)
ApiVerify := utils.Rules{
"ID": {utils.NotEmpty()},
}
ApiVerifyErr := utils.Verify(a.GVA_MODEL, ApiVerify)
if ApiVerifyErr != nil {
response.FailWithMessage(ApiVerifyErr.Error(), c)
var api model.SysApi
_ = c.ShouldBindJSON(&api)
if err := utils.Verify(api.GVA_MODEL, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.DeleteApi(a)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.DeleteApi(api); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// 条件搜索后端看此api
// @Tags SysApi
// @Summary 分页获取API列表
// @Security ApiKeyAuth
@@ -79,24 +66,22 @@ func DeleteApi(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/getApiList [post]
func GetApiList(c *gin.Context) {
// 此结构体仅本方法使用
var sp request.SearchApiParams
_ = c.ShouldBindJSON(&sp)
PageVerifyErr := utils.Verify(sp.PageInfo, utils.CustomizeMap["PageVerify"])
if PageVerifyErr != nil {
response.FailWithMessage(PageVerifyErr.Error(), c)
var pageInfo request.SearchApiParams
_ = c.ShouldBindJSON(&pageInfo)
if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, list, total := service.GetAPIInfoList(sp.SysApi, sp.PageInfo, sp.OrderKey, sp.Desc)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, list, total := service.GetAPIInfoList(pageInfo.SysApi, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: sp.PageInfo.Page,
PageSize: sp.PageInfo.PageSize,
}, c)
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
@@ -111,16 +96,16 @@ func GetApiList(c *gin.Context) {
func GetApiById(c *gin.Context) {
var idInfo request.GetById
_ = c.ShouldBindJSON(&idInfo)
IdVerifyErr := utils.Verify(idInfo, utils.CustomizeMap["IdVerify"])
if IdVerifyErr != nil {
response.FailWithMessage(IdVerifyErr.Error(), c)
if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, api := service.GetApiById(idInfo.Id)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysAPIResponse{Api: api}, c)
response.OkWithData(response.SysAPIResponse{Api: api}, c)
}
}
@@ -129,28 +114,21 @@ func GetApiById(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysApi true "创建api"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysApi true "api路径, api中文描述, api组, 方法"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /api/updateApi [post]
func UpdateApi(c *gin.Context) {
var api model.SysApi
_ = c.ShouldBindJSON(&api)
ApiVerify := utils.Rules{
"Path": {utils.NotEmpty()},
"Description": {utils.NotEmpty()},
"ApiGroup": {utils.NotEmpty()},
"Method": {utils.NotEmpty()},
}
ApiVerifyErr := utils.Verify(api, ApiVerify)
if ApiVerifyErr != nil {
response.FailWithMessage(ApiVerifyErr.Error(), c)
if err := utils.Verify(api, utils.ApiVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.UpdateApi(api)
if err != nil {
response.FailWithMessage(fmt.Sprintf("修改数据失败,%v", err), c)
if err := service.UpdateApi(api); err != nil {
global.GVA_LOG.Error("修改失败!", zap.Any("err", err))
response.FailWithMessage("修改失败", c)
} else {
response.OkWithMessage("修改数据成功", c)
response.OkWithMessage("修改成功", c)
}
}
@@ -162,10 +140,10 @@ func UpdateApi(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/getAllApis [post]
func GetAllApis(c *gin.Context) {
err, apis := service.GetAllApis()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, apis := service.GetAllApis(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysAPIListResponse{Apis: apis}, c)
response.OkWithDetailed(response.SysAPIListResponse{Apis: apis}, "获取成功", c)
}
}
+60 -86
View File
@@ -1,166 +1,141 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags authority
// @Tags Authority
// @Summary 创建角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysAuthority true "创建角色"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysAuthority true "权限id, 权限名, 父角色id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /authority/createAuthority [post]
func CreateAuthority(c *gin.Context) {
var auth model.SysAuthority
_ = c.ShouldBindJSON(&auth)
AuthorityVerify := utils.Rules{
"AuthorityId": {utils.NotEmpty()},
"AuthorityName": {utils.NotEmpty()},
"ParentId": {utils.NotEmpty()},
}
AuthorityVerifyErr := utils.Verify(auth, AuthorityVerify)
if AuthorityVerifyErr != nil {
response.FailWithMessage(AuthorityVerifyErr.Error(), c)
var authority model.SysAuthority
_ = c.ShouldBindJSON(&authority)
if err := utils.Verify(authority, utils.AuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, authBack := service.CreateAuthority(auth)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
if err, authBack := service.CreateAuthority(authority); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithData(resp.SysAuthorityResponse{Authority: authBack}, c)
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "创建成功", c)
}
}
// @Tags authority
// @Tags Authority
// @Summary 拷贝角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body response.SysAuthorityCopyResponse true "拷贝角色"
// @Param data body response.SysAuthorityCopyResponse true "旧角色id, 新权限id, 新权限名, 新父角色id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"拷贝成功"}"
// @Router /authority/copyAuthority [post]
func CopyAuthority(c *gin.Context) {
var copyInfo resp.SysAuthorityCopyResponse
var copyInfo response.SysAuthorityCopyResponse
_ = c.ShouldBindJSON(&copyInfo)
OldAuthorityVerify := utils.Rules{
"OldAuthorityId": {utils.NotEmpty()},
}
OldAuthorityVerifyErr := utils.Verify(copyInfo, OldAuthorityVerify)
if OldAuthorityVerifyErr != nil {
response.FailWithMessage(OldAuthorityVerifyErr.Error(), c)
if err := utils.Verify(copyInfo, utils.OldAuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
AuthorityVerify := utils.Rules{
"AuthorityId": {utils.NotEmpty()},
"AuthorityName": {utils.NotEmpty()},
"ParentId": {utils.NotEmpty()},
}
AuthorityVerifyErr := utils.Verify(copyInfo.Authority, AuthorityVerify)
if AuthorityVerifyErr != nil {
response.FailWithMessage(AuthorityVerifyErr.Error(), c)
if err := utils.Verify(copyInfo.Authority, utils.AuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, authBack := service.CopyAuthority(copyInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("拷贝失败,%v", err), c)
if err, authBack := service.CopyAuthority(copyInfo); err != nil {
global.GVA_LOG.Error("拷贝失败!", zap.Any("err", err))
response.FailWithMessage("拷贝失败", c)
} else {
response.OkWithData(resp.SysAuthorityResponse{Authority: authBack}, c)
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authBack}, "拷贝成功", c)
}
}
// @Tags authority
// @Tags Authority
// @Summary 删除角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysAuthority true "删除角色"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /authority/deleteAuthority [post]
func DeleteAuthority(c *gin.Context) {
var a model.SysAuthority
_ = c.ShouldBindJSON(&a)
AuthorityIdVerifyErr := utils.Verify(a, utils.CustomizeMap["AuthorityIdVerify"])
if AuthorityIdVerifyErr != nil {
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
var authority model.SysAuthority
_ = c.ShouldBindJSON(&authority)
if err := utils.Verify(authority, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
// 删除角色之前需要判断是否有用户正在使用此角色
err := service.DeleteAuthority(&a)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.DeleteAuthority(&authority); err != nil { // 删除角色之前需要判断是否有用户正在使用此角色
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags authority
// @Summary 设置角色资源权限
// @Tags Authority
// @Summary 更新角色信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysAuthority true "设置角色资源权限"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
// @Param data body model.SysAuthority true "权限id, 权限名, 父角色id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /authority/updateAuthority [post]
func UpdateAuthority(c *gin.Context) {
var auth model.SysAuthority
_ = c.ShouldBindJSON(&auth)
AuthorityVerify := utils.Rules{
"AuthorityId": {utils.NotEmpty()},
"AuthorityName": {utils.NotEmpty()},
"ParentId": {utils.NotEmpty()},
}
AuthorityVerifyErr := utils.Verify(auth, AuthorityVerify)
if AuthorityVerifyErr != nil {
response.FailWithMessage(AuthorityVerifyErr.Error(), c)
if err := utils.Verify(auth, utils.AuthorityVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, authority := service.UpdateAuthority(auth)
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
if err, authority := service.UpdateAuthority(auth); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithData(resp.SysAuthorityResponse{Authority: authority}, c)
response.OkWithDetailed(response.SysAuthorityResponse{Authority: authority}, "更新成功", c)
}
}
// @Tags authority
// @Tags Authority
// @Summary 分页获取角色列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "分页获取用户列表"
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /authority/getAuthorityList [post]
func GetAuthorityList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo)
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
if PageVerifyErr != nil {
response.FailWithMessage(PageVerifyErr.Error(), c)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, list, total := service.GetAuthorityInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, list, total := service.GetAuthorityInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
// @Tags authority
// @Tags Authority
// @Summary 设置角色资源权限
// @Security ApiKeyAuth
// @accept application/json
@@ -171,15 +146,14 @@ func GetAuthorityList(c *gin.Context) {
func SetDataAuthority(c *gin.Context) {
var auth model.SysAuthority
_ = c.ShouldBindJSON(&auth)
AuthorityIdVerifyErr := utils.Verify(auth, utils.CustomizeMap["AuthorityIdVerify"])
if AuthorityIdVerifyErr != nil {
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
if err := utils.Verify(auth, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.SetDataAuthority(auth)
if err != nil {
response.FailWithMessage(fmt.Sprintf("设置关联失败,%v", err), c)
if err := service.SetDataAuthority(auth); err != nil {
global.GVA_LOG.Error("设置失败!", zap.Any("err", err))
response.FailWithMessage("设置失败", c)
} else {
response.Ok(c)
response.OkWithMessage("设置成功", c)
}
}
+40 -43
View File
@@ -3,16 +3,18 @@ package v1
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/global/response"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"go.uber.org/zap"
"net/url"
"os"
)
// @Tags SysApi
// @Tags AutoCode
// @Summary 自动代码模板
// @Security ApiKeyAuth
// @accept application/json
@@ -23,15 +25,8 @@ import (
func CreateTemp(c *gin.Context) {
var a model.AutoCodeStruct
_ = c.ShouldBindJSON(&a)
AutoCodeVerify := utils.Rules{
"Abbreviation": {utils.NotEmpty()},
"StructName": {utils.NotEmpty()},
"PackageName": {utils.NotEmpty()},
"Fields": {utils.NotEmpty()},
}
WKVerifyErr := utils.Verify(a, AutoCodeVerify)
if WKVerifyErr != nil {
response.FailWithMessage(WKVerifyErr.Error(), c)
if err := utils.Verify(a, utils.AutoCodeVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if a.AutoCreateApiToSql {
@@ -49,7 +44,7 @@ func CreateTemp(c *gin.Context) {
Method: "DELETE",
},
{
Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName+"ByIds",
Path: "/" + a.Abbreviation + "/" + "delete" + a.StructName + "ByIds",
Description: "批量删除" + a.Description,
ApiGroup: a.Abbreviation,
Method: "DELETE",
@@ -74,81 +69,83 @@ func CreateTemp(c *gin.Context) {
},
}
for _, v := range apiList {
errC := service.CreateApi(v)
if errC != nil {
if err := service.AutoCreateApi(v); err != nil {
global.GVA_LOG.Error("自动化创建失败!请自行清空垃圾数据!", zap.Any("err", err))
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msg", url.QueryEscape(fmt.Sprintf("自动化创建失败%v请自行清空垃圾数据", errC)))
c.Writer.Header().Add("msg", url.QueryEscape("自动化创建失败!请自行清空垃圾数据!"))
return
}
}
}
err := service.CreateTemp(a)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
os.Remove("./ginvueadmin.zip")
if errors.Is(err, model.AutoMoveErr) {
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msgtype", "success")
c.Writer.Header().Add("msg", url.QueryEscape(err.Error()))
} else {
c.Writer.Header().Add("success", "false")
c.Writer.Header().Add("msg", url.QueryEscape(err.Error()))
_ = os.Remove("./ginvueadmin.zip")
}
} else {
c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "ginvueadmin.zip")) // fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
c.Writer.Header().Add("Content-Type", "application/json")
c.Writer.Header().Add("success", "true")
c.File("./ginvueadmin.zip")
os.Remove("./ginvueadmin.zip")
_ = os.Remove("./ginvueadmin.zip")
}
}
// @Tags SysApi
// @Tags AutoCode
// @Summary 获取当前数据库所有表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /autoCode/getTables [get]
func GetTables(c *gin.Context) {
dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname)
err, tables := service.GetTables(dbName)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询table失败%v", err), c)
global.GVA_LOG.Error("查询table失败!", zap.Any("err", err))
response.FailWithMessage("查询table失败", c)
} else {
response.OkWithData(gin.H{
"tables": tables,
}, c)
response.OkWithDetailed(gin.H{"tables": tables}, "获取成功", c)
}
}
// @Tags SysApi
// @Tags AutoCode
// @Summary 获取当前所有数据库
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /autoCode/getDatabase [get]
func GetDB(c *gin.Context) {
err, dbs := service.GetDB()
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询table失败,%v", err), c)
if err, dbs := service.GetDB(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(gin.H{
"dbs": dbs,
}, c)
response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c)
}
}
// @Tags SysApi
// @Tags AutoCode
// @Summary 获取当前表所有字段
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /autoCode/getDatabase [get]
func GetColume(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /autoCode/getColumn [get]
func GetColumn(c *gin.Context) {
dbName := c.DefaultQuery("dbName", global.GVA_CONFIG.Mysql.Dbname)
tableName := c.Query("tableName")
err, columes := service.GetColume(tableName, dbName)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询table失败,%v", err), c)
if err, columns := service.GetColumn(tableName, dbName); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(gin.H{
"columes": columes,
}, c)
response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c)
}
}
+8 -9
View File
@@ -1,33 +1,32 @@
package v1
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/global/response"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"github.com/gin-gonic/gin"
"github.com/mojocn/base64Captcha"
"go.uber.org/zap"
)
var store = base64Captcha.DefaultMemStore
// @Tags base
// @Tags Base
// @Summary 生成验证码
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"验证码获取成功"}"
// @Router /base/captcha [post]
func Captcha(c *gin.Context) {
//字符,公式,验证码配置
// 生成默认数字的driver
driver := base64Captcha.NewDriverDigit(global.GVA_CONFIG.Captcha.ImgHeight, global.GVA_CONFIG.Captcha.ImgWidth, global.GVA_CONFIG.Captcha.KeyLong, 0.7, 80)
cp := base64Captcha.NewCaptcha(driver, store)
id, b64s, err := cp.Generate()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if id, b64s, err := cp.Generate(); err != nil {
global.GVA_LOG.Error("验证码获取失败!", zap.Any("err", err))
response.FailWithMessage("验证码获取失败", c)
} else {
response.OkDetailed(resp.SysCaptchaResponse{
response.OkWithDetailed(response.SysCaptchaResponse{
CaptchaId: id,
PicPath: b64s,
}, "验证码获取成功", c)
+21 -23
View File
@@ -1,56 +1,54 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags casbin
// @Summary 更角色api权限
// @Tags Casbin
// @Summary 更角色api权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CasbinInReceive true "更改角色api权限"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /casbin/UpdateCasbin [post]
func UpdateCasbin(c *gin.Context) {
var cmr request.CasbinInReceive
_ = c.ShouldBindJSON(&cmr)
AuthorityIdVerifyErr := utils.Verify(cmr, utils.CustomizeMap["AuthorityIdVerify"])
if AuthorityIdVerifyErr != nil {
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
if err := utils.Verify(cmr, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos)
if err != nil {
response.FailWithMessage(fmt.Sprintf("添加规则失败,%v", err), c)
if err := service.UpdateCasbin(cmr.AuthorityId, cmr.CasbinInfos); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("添加规则成功", c)
response.OkWithMessage("更新成功", c)
}
}
// @Tags casbin
// @Tags Casbin
// @Summary 获取权限列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CasbinInReceive true "获取权限列表"
// @Param data body request.CasbinInReceive true "权限id, 权限模型列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /casbin/getPolicyPathByAuthorityId [post]
func GetPolicyPathByAuthorityId(c *gin.Context) {
var cmr request.CasbinInReceive
_ = c.ShouldBindJSON(&cmr)
AuthorityIdVerifyErr := utils.Verify(cmr, utils.CustomizeMap["AuthorityIdVerify"])
if AuthorityIdVerifyErr != nil {
response.FailWithMessage(AuthorityIdVerifyErr.Error(), c)
var casbin request.CasbinInReceive
_ = c.ShouldBindJSON(&casbin)
if err := utils.Verify(casbin, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
paths := service.GetPolicyPathByAuthorityId(cmr.AuthorityId)
response.OkWithData(resp.PolicyPathResponse{Paths: paths}, c)
paths := service.GetPolicyPathByAuthorityId(casbin.AuthorityId)
response.OkWithDetailed(response.PolicyPathResponse{Paths: paths}, "获取成功", c)
}
+40 -35
View File
@@ -1,13 +1,14 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysDictionary
@@ -15,15 +16,15 @@ import (
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "创建SysDictionary"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysDictionary true "SysDictionary模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /sysDictionary/createSysDictionary [post]
func CreateSysDictionary(c *gin.Context) {
var sysDictionary model.SysDictionary
_ = c.ShouldBindJSON(&sysDictionary)
err := service.CreateSysDictionary(sysDictionary)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
var dictionary model.SysDictionary
_ = c.ShouldBindJSON(&dictionary)
if err := service.CreateSysDictionary(dictionary); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
@@ -34,15 +35,15 @@ func CreateSysDictionary(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "删除SysDictionary"
// @Param data body model.SysDictionary true "SysDictionary模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysDictionary/deleteSysDictionary [delete]
func DeleteSysDictionary(c *gin.Context) {
var sysDictionary model.SysDictionary
_ = c.ShouldBindJSON(&sysDictionary)
err := service.DeleteSysDictionary(sysDictionary)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
var dictionary model.SysDictionary
_ = c.ShouldBindJSON(&dictionary)
if err := service.DeleteSysDictionary(dictionary); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
@@ -53,15 +54,15 @@ func DeleteSysDictionary(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "更新SysDictionary"
// @Param data body model.SysDictionary true "SysDictionary模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /sysDictionary/updateSysDictionary [put]
func UpdateSysDictionary(c *gin.Context) {
var sysDictionary model.SysDictionary
_ = c.ShouldBindJSON(&sysDictionary)
err := service.UpdateSysDictionary(&sysDictionary)
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
var dictionary model.SysDictionary
_ = c.ShouldBindJSON(&dictionary)
if err := service.UpdateSysDictionary(&dictionary); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
@@ -72,17 +73,17 @@ func UpdateSysDictionary(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionary true "用id查询SysDictionary"
// @Param data body model.SysDictionary true "ID或字典英名"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysDictionary/findSysDictionary [get]
func FindSysDictionary(c *gin.Context) {
var sysDictionary model.SysDictionary
_ = c.ShouldBindQuery(&sysDictionary)
err, resysDictionary := service.GetSysDictionary(sysDictionary.Type, sysDictionary.ID)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
var dictionary model.SysDictionary
_ = c.ShouldBindQuery(&dictionary)
if err, sysDictionary := service.GetSysDictionary(dictionary.Type, dictionary.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(gin.H{"resysDictionary": resysDictionary}, c)
response.OkWithDetailed(gin.H{"resysDictionary": sysDictionary}, "查询成功", c)
}
}
@@ -91,21 +92,25 @@ func FindSysDictionary(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictionarySearch true "分页获取SysDictionary列表"
// @Param data body request.SysDictionarySearch true "页码, 每页大小, 搜索条件"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysDictionary/getSysDictionaryList [get]
func GetSysDictionaryList(c *gin.Context) {
var pageInfo request.SysDictionarySearch
_ = c.ShouldBindQuery(&pageInfo)
err, list, total := service.GetSysDictionaryInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, list, total := service.GetSysDictionaryInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
+38 -33
View File
@@ -1,13 +1,14 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysDictionaryDetail
@@ -15,15 +16,15 @@ import (
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionaryDetail true "创建SysDictionaryDetail"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /sysDictionaryDetail/createSysDictionaryDetail [post]
func CreateSysDictionaryDetail(c *gin.Context) {
var sysDictionaryDetail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&sysDictionaryDetail)
err := service.CreateSysDictionaryDetail(sysDictionaryDetail)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
var detail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail)
if err := service.CreateSysDictionaryDetail(detail); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
@@ -34,15 +35,15 @@ func CreateSysDictionaryDetail(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysDictionaryDetail true "删除SysDictionaryDetail"
// @Param data body model.SysDictionaryDetail true "SysDictionaryDetail模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysDictionaryDetail/deleteSysDictionaryDetail [delete]
func DeleteSysDictionaryDetail(c *gin.Context) {
var sysDictionaryDetail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&sysDictionaryDetail)
err := service.DeleteSysDictionaryDetail(sysDictionaryDetail)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
var detail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail)
if err := service.DeleteSysDictionaryDetail(detail); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
@@ -57,11 +58,11 @@ func DeleteSysDictionaryDetail(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /sysDictionaryDetail/updateSysDictionaryDetail [put]
func UpdateSysDictionaryDetail(c *gin.Context) {
var sysDictionaryDetail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&sysDictionaryDetail)
err := service.UpdateSysDictionaryDetail(&sysDictionaryDetail)
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
var detail model.SysDictionaryDetail
_ = c.ShouldBindJSON(&detail)
if err := service.UpdateSysDictionaryDetail(&detail); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
@@ -76,13 +77,17 @@ func UpdateSysDictionaryDetail(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysDictionaryDetail/findSysDictionaryDetail [get]
func FindSysDictionaryDetail(c *gin.Context) {
var sysDictionaryDetail model.SysDictionaryDetail
_ = c.ShouldBindQuery(&sysDictionaryDetail)
err, resysDictionaryDetail := service.GetSysDictionaryDetail(sysDictionaryDetail.ID)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
var detail model.SysDictionaryDetail
_ = c.ShouldBindQuery(&detail)
if err := utils.Verify(detail, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, resysDictionaryDetail := service.GetSysDictionaryDetail(detail.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(gin.H{"resysDictionaryDetail": resysDictionaryDetail}, c)
response.OkWithDetailed(gin.H{"resysDictionaryDetail": resysDictionaryDetail}, "查询成功", c)
}
}
@@ -91,21 +96,21 @@ func FindSysDictionaryDetail(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictionaryDetailSearch true "分页获取SysDictionaryDetail列表"
// @Param data body request.SysDictionaryDetailSearch true "页码, 每页大小, 搜索条件"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysDictionaryDetail/getSysDictionaryDetailList [get]
func GetSysDictionaryDetailList(c *gin.Context) {
var pageInfo request.SysDictionaryDetailSearch
_ = c.ShouldBindQuery(&pageInfo)
err, list, total := service.GetSysDictionaryDetailInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, list, total := service.GetSysDictionaryDetailInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
+8 -7
View File
@@ -1,22 +1,23 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags system
// @Tags System
// @Summary 发送测试邮件
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"发送成功"}"
// @Router /email/emailTest [post]
func EmailTest(c *gin.Context) {
err := service.EmailTest()
if err != nil {
response.FailWithMessage(fmt.Sprintf("发送失败,%v", err), c)
if err := service.EmailTest(); err != nil {
global.GVA_LOG.Error("发送失败!", zap.Any("err", err))
response.FailWithMessage("发送失败", c)
} else {
response.OkWithData("发送成功", c)
}
+8 -9
View File
@@ -1,14 +1,15 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags jwt
// @Tags Jwt
// @Summary jwt加入黑名单
// @Security ApiKeyAuth
// @accept application/json
@@ -17,12 +18,10 @@ import (
// @Router /jwt/jsonInBlacklist [post]
func JsonInBlacklist(c *gin.Context) {
token := c.Request.Header.Get("x-token")
modelJwt := model.JwtBlacklist{
Jwt: token,
}
err := service.JsonInBlacklist(modelJwt)
if err != nil {
response.FailWithMessage(fmt.Sprintf("jwt作废失败,%v", err), c)
jwt := model.JwtBlacklist{Jwt: token}
if err := service.JsonInBlacklist(jwt); err != nil {
global.GVA_LOG.Error("jwt作废失败!", zap.Any("err", err))
response.FailWithMessage("jwt作废失败", c)
} else {
response.OkWithMessage("jwt作废成功", c)
}
+122 -162
View File
@@ -1,259 +1,219 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags authorityAndMenu
// @Tags AuthorityMenu
// @Summary 获取用户动态路由
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body request.RegisterAndLoginStruct true "可以什么都不填"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Param data body request.Empty true "空"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getMenu [post]
func GetMenu(c *gin.Context) {
claims, _ := c.Get("claims")
waitUse := claims.(*request.CustomClaims)
err, menus := service.GetMenuTree(waitUse.AuthorityId)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
if err, menus := service.GetMenuTree(getUserAuthorityId(c)); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysMenusResponse{Menus: menus}, c)
response.OkWithDetailed(response.SysMenusResponse{Menus: menus}, "获取成功", c)
}
}
// @Tags menu
// @Summary 分页获取基础menu列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "分页获取基础menu列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getMenuList [post]
func GetMenuList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo)
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
if PageVerifyErr != nil {
response.FailWithMessage(PageVerifyErr.Error(), c)
return
}
err, menuList, total := service.GetInfoList()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
} else {
response.OkWithData(resp.PageResult{
List: menuList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}
}
// @Tags menu
// @Summary 新增菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysBaseMenu true "新增菜单"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/addBaseMenu [post]
func AddBaseMenu(c *gin.Context) {
var menu model.SysBaseMenu
_ = c.ShouldBindJSON(&menu)
MenuVerify := utils.Rules{
"Path": {utils.NotEmpty()},
"ParentId": {utils.NotEmpty()},
"Name": {utils.NotEmpty()},
"Component": {utils.NotEmpty()},
"Sort": {utils.Ge("0")},
}
MenuVerifyErr := utils.Verify(menu, MenuVerify)
if MenuVerifyErr != nil {
response.FailWithMessage(MenuVerifyErr.Error(), c)
return
}
MetaVerify := utils.Rules{
"Title": {utils.NotEmpty()},
}
MetaVerifyErr := utils.Verify(menu.Meta, MetaVerify)
if MetaVerifyErr != nil {
response.FailWithMessage(MetaVerifyErr.Error(), c)
return
}
err := service.AddBaseMenu(menu)
if err != nil {
response.FailWithMessage(fmt.Sprintf("添加失败,%v", err), c)
} else {
response.OkWithMessage("添加成功", c)
}
}
// @Tags authorityAndMenu
// @Tags AuthorityMenu
// @Summary 获取用户动态路由
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body request.RegisterAndLoginStruct true "可以什么都不填"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Param data body request.Empty true "空"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getBaseMenuTree [post]
func GetBaseMenuTree(c *gin.Context) {
err, menus := service.GetBaseMenuTree()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
if err, menus := service.GetBaseMenuTree(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysBaseMenusResponse{Menus: menus}, c)
response.OkWithDetailed(response.SysBaseMenusResponse{Menus: menus}, "获取成功", c)
}
}
// @Tags authorityAndMenu
// @Tags AuthorityMenu
// @Summary 增加menu和角色关联关系
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.AddMenuAuthorityInfo true "增加menu和角色关联关系"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body request.AddMenuAuthorityInfo true "角色ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}"
// @Router /menu/addMenuAuthority [post]
func AddMenuAuthority(c *gin.Context) {
var addMenuAuthorityInfo request.AddMenuAuthorityInfo
_ = c.ShouldBindJSON(&addMenuAuthorityInfo)
MenuVerify := utils.Rules{
"AuthorityId": {"notEmpty"},
}
MenuVerifyErr := utils.Verify(addMenuAuthorityInfo, MenuVerify)
if MenuVerifyErr != nil {
response.FailWithMessage(MenuVerifyErr.Error(), c)
var authorityMenu request.AddMenuAuthorityInfo
_ = c.ShouldBindJSON(&authorityMenu)
if err := utils.Verify(authorityMenu, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.AddMenuAuthority(addMenuAuthorityInfo.Menus, addMenuAuthorityInfo.AuthorityId)
if err != nil {
response.FailWithMessage(fmt.Sprintf("添加失败,%v", err), c)
if err := service.AddMenuAuthority(authorityMenu.Menus, authorityMenu.AuthorityId); err != nil {
global.GVA_LOG.Error("添加失败!", zap.Any("err", err))
response.FailWithMessage("添加失败", c)
} else {
response.OkWithMessage("添加成功", c)
}
}
// @Tags authorityAndMenu
// @Tags AuthorityMenu
// @Summary 获取指定角色menu
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.AuthorityIdInfo true "增加menu和角色关联关系"
// @Param data body request.GetAuthorityId true "角色ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/GetMenuAuthority [post]
func GetMenuAuthority(c *gin.Context) {
var authorityIdInfo request.AuthorityIdInfo
_ = c.ShouldBindJSON(&authorityIdInfo)
MenuVerify := utils.Rules{
"AuthorityId": {"notEmpty"},
}
MenuVerifyErr := utils.Verify(authorityIdInfo, MenuVerify)
if MenuVerifyErr != nil {
response.FailWithMessage(MenuVerifyErr.Error(), c)
var param request.GetAuthorityId
_ = c.ShouldBindJSON(&param)
if err := utils.Verify(param, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, menus := service.GetMenuAuthority(authorityIdInfo.AuthorityId)
if err != nil {
response.FailWithDetailed(response.ERROR, resp.SysMenusResponse{Menus: menus}, fmt.Sprintf("添加失败,%v", err), c)
if err, menus := service.GetMenuAuthority(&param); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithDetailed(response.SysMenusResponse{Menus: menus}, "获取失败", c)
} else {
response.Result(response.SUCCESS, gin.H{"menus": menus}, "获取成功", c)
response.OkWithDetailed(gin.H{"menus": menus}, "获取成功", c)
}
}
// @Tags menu
// @Tags Menu
// @Summary 新增菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"添加成功"}"
// @Router /menu/addBaseMenu [post]
func AddBaseMenu(c *gin.Context) {
var menu model.SysBaseMenu
_ = c.ShouldBindJSON(&menu)
if err := utils.Verify(menu, utils.MenuVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := utils.Verify(menu.Meta, utils.MenuMetaVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.AddBaseMenu(menu); err != nil {
global.GVA_LOG.Error("添加失败!", zap.Any("err", err))
response.FailWithMessage("添加失败", c)
} else {
response.OkWithMessage("添加成功", c)
}
}
// @Tags Menu
// @Summary 删除菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "删除菜单"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body request.GetById true "菜单id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /menu/deleteBaseMenu [post]
func DeleteBaseMenu(c *gin.Context) {
var idInfo request.GetById
_ = c.ShouldBindJSON(&idInfo)
IdVerifyErr := utils.Verify(idInfo, utils.CustomizeMap["IdVerify"])
if IdVerifyErr != nil {
response.FailWithMessage(IdVerifyErr.Error(), c)
var menu request.GetById
_ = c.ShouldBindJSON(&menu)
if err := utils.Verify(menu, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.DeleteBaseMenu(idInfo.Id)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
if err := service.DeleteBaseMenu(menu.Id); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags menu
// @Tags Menu
// @Summary 更新菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysBaseMenu true "更新菜单"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Param data body model.SysBaseMenu true "路由path, 父菜单ID, 路由name, 对应前端文件路径, 排序标记"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /menu/updateBaseMenu [post]
func UpdateBaseMenu(c *gin.Context) {
var menu model.SysBaseMenu
_ = c.ShouldBindJSON(&menu)
MenuVerify := utils.Rules{
"Path": {"notEmpty"},
"ParentId": {utils.NotEmpty()},
"Name": {utils.NotEmpty()},
"Component": {utils.NotEmpty()},
"Sort": {utils.Ge("0")},
}
MenuVerifyErr := utils.Verify(menu, MenuVerify)
if MenuVerifyErr != nil {
response.FailWithMessage(MenuVerifyErr.Error(), c)
if err := utils.Verify(menu, utils.MenuVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
MetaVerify := utils.Rules{
"Title": {utils.NotEmpty()},
}
MetaVerifyErr := utils.Verify(menu.Meta, MetaVerify)
if MetaVerifyErr != nil {
response.FailWithMessage(MetaVerifyErr.Error(), c)
if err := utils.Verify(menu.Meta, utils.MenuMetaVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.UpdateBaseMenu(menu)
if err != nil {
response.FailWithMessage(fmt.Sprintf("修改失败:%v", err), c)
if err := service.UpdateBaseMenu(menu); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("修改成功", c)
response.OkWithMessage("更新成功", c)
}
}
// @Tags menu
// @Tags Menu
// @Summary 根据id获取菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "根据id获取菜单"
// @Param data body request.GetById true "菜单id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getBaseMenuById [post]
func GetBaseMenuById(c *gin.Context) {
var idInfo request.GetById
_ = c.ShouldBindJSON(&idInfo)
MenuVerify := utils.Rules{
"Id": {"notEmpty"},
}
MenuVerifyErr := utils.Verify(idInfo, MenuVerify)
if MenuVerifyErr != nil {
response.FailWithMessage(MenuVerifyErr.Error(), c)
if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, menu := service.GetBaseMenuById(idInfo.Id)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询失败:%v", err), c)
if err, menu := service.GetBaseMenuById(idInfo.Id); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysBaseMenuResponse{Menu: menu}, c)
response.OkWithDetailed(response.SysBaseMenuResponse{Menu: menu}, "获取成功", c)
}
}
// @Tags Menu
// @Summary 分页获取基础menu列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/getMenuList [post]
func GetMenuList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, menuList, total := service.GetInfoList(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: menuList,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
},"获取成功", c)
}
}
+31 -26
View File
@@ -1,13 +1,14 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags SysOperationRecord
@@ -21,9 +22,9 @@ import (
func CreateSysOperationRecord(c *gin.Context) {
var sysOperationRecord model.SysOperationRecord
_ = c.ShouldBindJSON(&sysOperationRecord)
err := service.CreateSysOperationRecord(sysOperationRecord)
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
if err := service.CreateSysOperationRecord(sysOperationRecord); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
@@ -34,15 +35,15 @@ func CreateSysOperationRecord(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysOperationRecord true "删除SysOperationRecord"
// @Param data body model.SysOperationRecord true "SysOperationRecord模型"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sysOperationRecord/deleteSysOperationRecord [delete]
func DeleteSysOperationRecord(c *gin.Context) {
var sysOperationRecord model.SysOperationRecord
_ = c.ShouldBindJSON(&sysOperationRecord)
err := service.DeleteSysOperationRecord(sysOperationRecord)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.DeleteSysOperationRecord(sysOperationRecord); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
@@ -54,16 +55,16 @@ func DeleteSysOperationRecord(c *gin.Context) {
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除SysOperationRecord"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /sysOperationRecord/deleteSysOperationRecordByIds [delete]
func DeleteSysOperationRecordByIds(c *gin.Context) {
var IDS request.IdsReq
_ = c.ShouldBindJSON(&IDS)
err := service.DeleteSysOperationRecordByIds(IDS)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.DeleteSysOperationRecordByIds(IDS); err != nil {
global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
response.FailWithMessage("批量删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
response.OkWithMessage("批量删除成功", c)
}
}
@@ -72,17 +73,21 @@ func DeleteSysOperationRecordByIds(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysOperationRecord true "用id查询SysOperationRecord"
// @Param data body model.SysOperationRecord true "Id"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /sysOperationRecord/findSysOperationRecord [get]
func FindSysOperationRecord(c *gin.Context) {
var sysOperationRecord model.SysOperationRecord
_ = c.ShouldBindQuery(&sysOperationRecord)
err, resysOperationRecord := service.GetSysOperationRecord(sysOperationRecord.ID)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
if err := utils.Verify(sysOperationRecord, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, resysOperationRecord := service.GetSysOperationRecord(sysOperationRecord.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(gin.H{"resysOperationRecord": resysOperationRecord}, c)
response.OkWithDetailed(gin.H{"resysOperationRecord": resysOperationRecord}, "查询成功", c)
}
}
@@ -91,21 +96,21 @@ func FindSysOperationRecord(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysOperationRecordSearch true "分页获取SysOperationRecord列表"
// @Param data body request.SysOperationRecordSearch true "页码, 每页大小, 搜索条件"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sysOperationRecord/getSysOperationRecordList [get]
func GetSysOperationRecordList(c *gin.Context) {
var pageInfo request.SysOperationRecordSearch
_ = c.ShouldBindQuery(&pageInfo)
err, list, total := service.GetSysOperationRecordInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, list, total := service.GetSysOperationRecordInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
+29 -28
View File
@@ -1,78 +1,79 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/global"
"gin-vue-admin/model"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags system
// @Tags System
// @Summary 获取配置文件内容
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /system/getSystemConfig [post]
func GetSystemConfig(c *gin.Context) {
err, config := service.GetSystemConfig()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
if err, config := service.GetSystemConfig(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.SysConfigResponse{Config: config}, c)
response.OkWithDetailed(response.SysConfigResponse{Config: config}, "获取成功", c)
}
}
// @Tags system
// @Tags System
// @Summary 设置配置文件内容
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body model.System true "设置配置文件内容"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
// @Router /system/setSystemConfig [post]
func SetSystemConfig(c *gin.Context) {
var sys model.System
_ = c.ShouldBindJSON(&sys)
err := service.SetSystemConfig(sys)
if err != nil {
response.FailWithMessage(fmt.Sprintf("设置失败,%v", err), c)
if err := service.SetSystemConfig(sys); err != nil {
global.GVA_LOG.Error("设置失败!", zap.Any("err", err))
response.FailWithMessage("设置失败", c)
} else {
response.OkWithData("设置成功", c)
}
}
// 本方法开发中 开发者windows系统 缺少linux系统所需的包 因此搁置
// @Tags system
// @Summary 设置配置文件内容
// @Tags System
// @Summary 重启系统
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body model.System true "设置配置文件内容"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"返回成功"}"
// @Param data body model.System true "重启系统"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"重启系统成功"}"
// @Router /system/ReloadSystem [post]
func ReloadSystem(c *gin.Context) {
var sys model.System
_ = c.ShouldBindJSON(&sys)
err := service.SetSystemConfig(sys)
if err != nil {
response.FailWithMessage(fmt.Sprintf("设置失败,%v", err), c)
if err := service.SetSystemConfig(sys); err != nil {
global.GVA_LOG.Error("重启系统失败!", zap.Any("err", err))
response.FailWithMessage("重启系统失败", c)
} else {
response.OkWithMessage("设置成功", c)
response.OkWithMessage("重启系统成功", c)
}
}
// @Tags system
// @Tags System
// @Summary 获取服务器信息
// @Security ApiKeyAuth
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /system/getServerInfo [post]
func GetServerInfo(c *gin.Context) {
server, err := service.GetServerInfo()
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
if server, err := service.GetServerInfo(); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
return
}else {
response.OkWithDetailed(gin.H{"server": server}, "获取成功", c)
}
response.OkDetailed(gin.H{"server":server}, "获取成功",c)
}
}
+122 -118
View File
@@ -1,90 +1,50 @@
package v1
import (
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/global/response"
"gin-vue-admin/middleware"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
"github.com/go-redis/redis"
"mime/multipart"
"go.uber.org/zap"
"time"
)
// @Tags Base
// @Summary 用户注册账号
// @Produce application/json
// @Param data body model.SysUser true "用户注册接口"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}"
// @Router /user/register [post]
func Register(c *gin.Context) {
var R request.RegisterStruct
_ = c.ShouldBindJSON(&R)
UserVerify := utils.Rules{
"Username": {utils.NotEmpty()},
"NickName": {utils.NotEmpty()},
"Password": {utils.NotEmpty()},
"AuthorityId": {utils.NotEmpty()},
}
UserVerifyErr := utils.Verify(R, UserVerify)
if UserVerifyErr != nil {
response.FailWithMessage(UserVerifyErr.Error(), c)
return
}
user := &model.SysUser{Username: R.Username, NickName: R.NickName, Password: R.Password, HeaderImg: R.HeaderImg, AuthorityId: R.AuthorityId}
err, userReturn := service.Register(*user)
if err != nil {
response.FailWithDetailed(response.ERROR, resp.SysUserResponse{User: userReturn}, fmt.Sprintf("%v", err), c)
} else {
response.OkDetailed(resp.SysUserResponse{User: userReturn}, "注册成功", c)
}
}
// @Tags Base
// @Summary 用户登录
// @Produce application/json
// @Param data body request.RegisterAndLoginStruct true "用户登录接口"
// @Param data body request.Login true "用户名, 密码, 验证码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"登陆成功"}"
// @Router /base/login [post]
func Login(c *gin.Context) {
var L request.RegisterAndLoginStruct
var L request.Login
_ = c.ShouldBindJSON(&L)
UserVerify := utils.Rules{
"CaptchaId": {utils.NotEmpty()},
"Captcha": {utils.NotEmpty()},
"Username": {utils.NotEmpty()},
"Password": {utils.NotEmpty()},
}
UserVerifyErr := utils.Verify(L, UserVerify)
if UserVerifyErr != nil {
response.FailWithMessage(UserVerifyErr.Error(), c)
if err := utils.Verify(L, utils.LoginVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if store.Verify(L.CaptchaId, L.Captcha, true) {
U := &model.SysUser{Username: L.Username, Password: L.Password}
if err, user := service.Login(U); err != nil {
response.FailWithMessage(fmt.Sprintf("用户名密码错误或%v", err), c)
global.GVA_LOG.Error("登陆失败! 用户名不存在或者密码错误", zap.Any("err", err))
response.FailWithMessage("登陆失败!", c)
} else {
tokenNext(c, *user)
}
} else {
response.FailWithMessage("验证码错误", c)
}
}
// 登录以后签发jwt
func tokenNext(c *gin.Context, user model.SysUser) {
j := &middleware.JWT{
SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey), // 唯一签名
}
clams := request.CustomClaims{
j := &middleware.JWT{SigningKey: []byte(global.GVA_CONFIG.JWT.SigningKey)} // 唯一签名
claims := request.CustomClaims{
UUID: user.UUID,
ID: user.ID,
NickName: user.NickName,
@@ -97,32 +57,34 @@ func tokenNext(c *gin.Context, user model.SysUser) {
Issuer: "qmPlus", // 签名的发行者
},
}
token, err := j.CreateToken(clams)
token, err := j.CreateToken(claims)
if err != nil {
global.GVA_LOG.Error("获取token失败", zap.Any("err", err))
response.FailWithMessage("获取token失败", c)
return
}
if !global.GVA_CONFIG.System.UseMultipoint {
response.OkWithData(resp.LoginResponse{
response.OkWithDetailed(response.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
}, "登录成功", c)
return
}
err, jwtStr := service.GetRedisJWT(user.Username)
if err == redis.Nil {
if err, jwtStr := service.GetRedisJWT(user.Username); err == redis.Nil {
if err := service.SetRedisJWT(token, user.Username); err != nil {
global.GVA_LOG.Error("设置登录状态失败", zap.Any("err", err))
response.FailWithMessage("设置登录状态失败", c)
return
}
response.OkWithData(resp.LoginResponse{
response.OkWithDetailed(response.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
}, "登录成功", c)
} else if err != nil {
response.FailWithMessage(fmt.Sprintf("%v", err), c)
global.GVA_LOG.Error("设置登录状态失败", zap.Any("err", err))
response.FailWithMessage("设置登录状态失败", c)
} else {
var blackJWT model.JwtBlacklist
blackJWT.Jwt = jwtStr
@@ -134,11 +96,34 @@ func tokenNext(c *gin.Context, user model.SysUser) {
response.FailWithMessage("设置登录状态失败", c)
return
}
response.OkWithData(resp.LoginResponse{
response.OkWithDetailed(response.LoginResponse{
User: user,
Token: token,
ExpiresAt: clams.StandardClaims.ExpiresAt * 1000,
}, c)
ExpiresAt: claims.StandardClaims.ExpiresAt * 1000,
}, "登录成功", c)
}
}
// @Tags SysUser
// @Summary 用户注册账号
// @Produce application/json
// @Param data body model.SysUser true "用户名, 昵称, 密码, 角色ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}"
// @Router /user/register [post]
func Register(c *gin.Context) {
var R request.Register
_ = c.ShouldBindJSON(&R)
if err := utils.Verify(R, utils.RegisterVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
user := &model.SysUser{Username: R.Username, NickName: R.NickName, Password: R.Password, HeaderImg: R.HeaderImg, AuthorityId: R.AuthorityId}
err, userReturn := service.Register(*user)
if err != nil {
global.GVA_LOG.Error("注册失败", zap.Any("err", err))
response.FailWithDetailed(response.SysUserResponse{User: userReturn}, "注册失败", c)
} else {
response.OkWithDetailed(response.SysUserResponse{User: userReturn}, "注册成功", c)
}
}
@@ -146,60 +131,50 @@ func tokenNext(c *gin.Context, user model.SysUser) {
// @Summary 用户修改密码
// @Security ApiKeyAuth
// @Produce application/json
// @Param data body request.ChangePasswordStruct true "用户修改密码"
// @Param data body request.ChangePasswordStruct true "用户名, 原密码, 新密码"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/changePassword [put]
func ChangePassword(c *gin.Context) {
var params request.ChangePasswordStruct
_ = c.ShouldBindJSON(&params)
UserVerify := utils.Rules{
"Username": {utils.NotEmpty()},
"Password": {utils.NotEmpty()},
"NewPassword": {utils.NotEmpty()},
}
UserVerifyErr := utils.Verify(params, UserVerify)
if UserVerifyErr != nil {
response.FailWithMessage(UserVerifyErr.Error(), c)
var user request.ChangePasswordStruct
_ = c.ShouldBindJSON(&user)
if err := utils.Verify(user, utils.ChangePasswordVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
U := &model.SysUser{Username: params.Username, Password: params.Password}
if err, _ := service.ChangePassword(U, params.NewPassword); err != nil {
response.FailWithMessage("修改失败,请检查用户名密码", c)
U := &model.SysUser{Username: user.Username, Password: user.Password}
if err, _ := service.ChangePassword(U, user.NewPassword); err != nil {
global.GVA_LOG.Error("修改失败", zap.Any("err", err))
response.FailWithMessage("修改失败,原密码与当前账户不符", c)
} else {
response.OkWithMessage("修改成功", c)
}
}
type UserHeaderImg struct {
HeaderImg multipart.File `json:"headerImg"`
}
// @Tags SysUser
// @Summary 分页获取用户列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "分页获取用户列表"
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /user/getUserList [post]
func GetUserList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo)
PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
if PageVerifyErr != nil {
response.FailWithMessage(PageVerifyErr.Error(), c)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err, list, total := service.GetUserInfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
if err, list, total := service.GetUserInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithData(resp.PageResult{
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}, "获取成功", c)
}
}
@@ -208,24 +183,19 @@ func GetUserList(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SetUserAuth true "设置用户权限"
// @Param data body request.SetUserAuth true "用户UUID, 角色ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/setUserAuthority [post]
func SetUserAuthority(c *gin.Context) {
var sua request.SetUserAuth
_ = c.ShouldBindJSON(&sua)
UserVerify := utils.Rules{
"UUID": {utils.NotEmpty()},
"AuthorityId": {utils.NotEmpty()},
}
UserVerifyErr := utils.Verify(sua, UserVerify)
if UserVerifyErr != nil {
if UserVerifyErr := utils.Verify(sua, utils.SetUserAuthorityVerify); UserVerifyErr != nil {
response.FailWithMessage(UserVerifyErr.Error(), c)
return
}
err := service.SetUserAuthority(sua.UUID, sua.AuthorityId)
if err != nil {
response.FailWithMessage(fmt.Sprintf("修改失败,%v", err), c)
if err := service.SetUserAuthority(sua.UUID, sua.AuthorityId); err != nil {
global.GVA_LOG.Error("修改失败", zap.Any("err", err))
response.FailWithMessage("修改失败", c)
} else {
response.OkWithMessage("修改成功", c)
}
@@ -236,42 +206,76 @@ func SetUserAuthority(c *gin.Context) {
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.GetById true "删除用户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Param data body request.GetById true "用户ID"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /user/deleteUser [delete]
func DeleteUser(c *gin.Context) {
var reqId request.GetById
_ = c.ShouldBindJSON(&reqId)
IdVerifyErr := utils.Verify(reqId, utils.CustomizeMap["IdVerify"])
if IdVerifyErr != nil {
response.FailWithMessage(IdVerifyErr.Error(), c)
if err := utils.Verify(reqId, utils.IdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
err := service.DeleteUser(reqId.Id)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.DeleteUser(reqId.Id); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// @Tags SysUser
// @Summary 删除用户
// @Summary 设置用户信息
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysUser true "删除用户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Param data body model.SysUser true "ID, 用户名, 昵称, 头像链接"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
// @Router /user/setUserInfo [put]
func SetUserInfo(c *gin.Context) {
var user model.SysUser
c.ShouldBindJSON(&user)
err, ReqUser := service.SetUserInfo(user)
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
_ = c.ShouldBindJSON(&user)
if err := utils.Verify(user, utils.SetUserVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, ReqUser := service.SetUserInfo(user); err != nil {
global.GVA_LOG.Error("设置失败", zap.Any("err", err))
response.FailWithMessage("设置失败", c)
} else {
response.OkWithData(gin.H{
"userInfo": ReqUser,
}, c)
response.OkWithDetailed(gin.H{"userInfo": ReqUser}, "设置成功", c)
}
}
// 从Gin的Context中获取从jwt解析出来的用户ID
func getUserID(c *gin.Context) uint {
if claims, exists := c.Get("claims"); !exists {
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户ID失败, 请检查路由是否使用jwt中间件")
return 0
} else {
waitUse := claims.(*request.CustomClaims)
return waitUse.ID
}
}
// 从Gin的Context中获取从jwt解析出来的用户UUID
func getUserUuid(c *gin.Context) string {
if claims, exists := c.Get("claims"); !exists {
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件")
return ""
} else {
waitUse := claims.(*request.CustomClaims)
return waitUse.UUID.String()
}
}
// 从Gin的Context中获取从jwt解析出来的用户角色id
func getUserAuthorityId(c *gin.Context) string {
if claims, exists := c.Get("claims"); !exists {
global.GVA_LOG.Error("从Gin的Context中获取从jwt解析出来的用户UUID失败, 请检查路由是否使用jwt中间件")
return ""
} else {
waitUse := claims.(*request.CustomClaims)
return waitUse.AuthorityId
}
}
+32
View File
@@ -0,0 +1,32 @@
package v1
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"gin-vue-admin/utils"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags workflow
// @Summary 注册工作流
// @Produce application/json
// @Param data body model.SysWorkflow true "注册工作流接口"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"注册成功"}"
// @Router /workflow/createWorkFlow [post]
func CreateWorkFlow(c *gin.Context) {
var wk model.SysWorkflow
_ = c.ShouldBindJSON(&wk)
if err := utils.Verify(wk, utils.WorkFlowVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.Create(wk); err != nil {
global.GVA_LOG.Error("注册失败!", zap.Any("err", err))
response.FailWithMessage("注册失败", c)
} else {
response.OkWithMessage("注册成功", c)
}
}
+1 -1
View File
@@ -68,7 +68,7 @@ var Apis = []model.SysApi{
{global.GVA_MODEL{ID: 57, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/getSysOperationRecordList", "获取操作记录列表", "sysOperationRecord", "GET"},
{global.GVA_MODEL{ID: 58, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getTables", "获取数据库表", "autoCode", "GET"},
{global.GVA_MODEL{ID: 59, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getDB", "获取所有数据库", "autoCode", "GET"},
{global.GVA_MODEL{ID: 60, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getColume", "获取所选table的所有字段", "autoCode", "GET"},
{global.GVA_MODEL{ID: 60, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/autoCode/getColumn", "获取所选table的所有字段", "autoCode", "GET"},
{global.GVA_MODEL{ID: 61, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/sysOperationRecord/deleteSysOperationRecordByIds", "批量删除操作历史", "sysOperationRecord", "DELETE"},
{global.GVA_MODEL{ID: 62, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/upload", "插件版分片上传", "simpleUploader", "POST"},
{global.GVA_MODEL{ID: 63, CreatedAt: time.Now(), UpdatedAt: time.Now()}, "/simpleUploader/checkFileMd5", "文件完整度验证", "simpleUploader", "GET"},
+1 -1
View File
@@ -52,7 +52,7 @@ var Carbines = []gormadapter.CasbinRule{
{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: "/autoCode/getColumn", 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"},
+1 -1
View File
@@ -11,7 +11,7 @@ import (
)
var Users = []model.SysUser{
{GVA_MODEL: global.GVA_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"},
{GVA_MODEL: global.GVA_MODEL{ID: 1, CreatedAt: time.Now(), UpdatedAt: time.Now()}, UUID: uuid.NewV4(), Username: "admin", Password: "e10adc3949ba59abbe56e057f20f883e", NickName: "超级管理员", HeaderImg: "http://qmplusimg.henrongyi.top/gva_header.jpg", AuthorityId: "888"},
{GVA_MODEL: global.GVA_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"},
}
+2 -2
View File
@@ -58,14 +58,14 @@ mysql:
username: 'root'
password: 'Aa@6447985'
max-idle-conns: 10
max-open-conns: 10
max-open-conns: 100
log-mode: false
# local configuration
local:
path: 'uploads/file'
# qiniu configuration (请自行七牛申请对应的 公钥 私钥 bucket 域名地址)
# qiniu configuration (请自行七牛申请对应的 公钥 私钥 bucket ?域名地址)
qiniu:
zone: 'ZoneHuadong'
bucket: 'qm-plus-img'
+2 -1
View File
@@ -29,9 +29,10 @@ func RunWindowsServer() {
fmt.Printf(`
欢迎使用 Gin-Vue-Admin
当前版本:V2.3.4
当前版本:V2.3.6
默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
默认前端文件运行地址:http://127.0.0.1:8080
如果项目让您获得了收益,希望您能请团队喝杯可乐:https://www.gin-vue-admin.com/docs/coffee
`, address)
global.GVA_LOG.Error(s.ListenAndServe().Error())
}
+1 -1
View File
@@ -43,7 +43,7 @@ func Zap() (logger *zap.Logger) {
logger = zap.New(getEncoderCore())
}
if global.GVA_CONFIG.Zap.ShowLine {
logger.WithOptions(zap.AddCaller())
logger = logger.WithOptions(zap.AddCaller())
}
return logger
}
+342 -319
View File
File diff suppressed because it is too large Load Diff
+341 -317
View File
File diff suppressed because it is too large Load Diff
+275 -263
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -33,7 +33,7 @@ require (
github.com/onsi/ginkgo v1.7.0 // indirect
github.com/onsi/gomega v1.4.3 // indirect
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/qiniu/api.v7/v7 v7.4.1
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil v2.20.8+incompatible
+2 -2
View File
@@ -2,8 +2,8 @@ package middleware
import (
"gin-vue-admin/global"
"gin-vue-admin/global/response"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
)
@@ -25,7 +25,7 @@ func CasbinHandler() gin.HandlerFunc {
if global.GVA_CONFIG.System.Env == "develop" || success {
c.Next()
} else {
response.Result(response.ERROR, gin.H{}, "权限不足", c)
response.FailWithDetailed(gin.H{}, "权限不足", c)
c.Abort()
return
}
+17 -28
View File
@@ -3,9 +3,9 @@ package middleware
import (
"errors"
"gin-vue-admin/global"
"gin-vue-admin/global/response"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/dgrijalva/jwt-go"
"github.com/gin-gonic/gin"
@@ -19,16 +19,12 @@ func JWTAuth() gin.HandlerFunc {
// 我们这里jwt鉴权取头部信息 x-token 登录时回返回token信息 这里前端需要把token存储到cookie或者本地localStorage中 不过需要跟后端协商过期时间 可以约定刷新令牌或者重新登录
token := c.Request.Header.Get("x-token")
if token == "" {
response.Result(response.ERROR, gin.H{
"reload": true,
}, "未登录或非法访问", c)
response.FailWithDetailed(gin.H{"reload": true}, "未登录或非法访问", c)
c.Abort()
return
}
if service.IsBlacklist(token) {
response.Result(response.ERROR, gin.H{
"reload": true,
}, "您的帐户异地登陆或令牌失效", c)
response.FailWithDetailed(gin.H{"reload": true}, "您的帐户异地登陆或令牌失效", c)
c.Abort()
return
}
@@ -37,40 +33,33 @@ func JWTAuth() gin.HandlerFunc {
claims, err := j.ParseToken(token)
if err != nil {
if err == TokenExpired {
response.Result(response.ERROR, gin.H{
"reload": true,
}, "授权已过期", c)
response.FailWithDetailed(gin.H{"reload": true}, "授权已过期", c)
c.Abort()
return
}
response.Result(response.ERROR, gin.H{
"reload": true,
}, err.Error(), c)
response.FailWithDetailed(gin.H{"reload": true}, err.Error(), c)
c.Abort()
return
}
if err, _ = service.FindUserByUuid(claims.UUID.String()); err != nil{
response.Result(response.ERROR, gin.H{
"reload": true,
}, err.Error(), c)
if err, _ = service.FindUserByUuid(claims.UUID.String()); err != nil {
response.FailWithDetailed(gin.H{"reload": true}, err.Error(), c)
c.Abort()
}
if claims.ExpiresAt - time.Now().Unix()<claims.BufferTime {
if claims.ExpiresAt-time.Now().Unix() < claims.BufferTime {
claims.ExpiresAt = time.Now().Unix() + 60*60*24*7
newToken,_ := j.CreateToken(*claims)
newClaims,_ := j.ParseToken(newToken)
c.Header("new-token",newToken)
c.Header("new-expires-at",strconv.FormatInt(newClaims.ExpiresAt,10))
newToken, _ := j.CreateToken(*claims)
newClaims, _ := j.ParseToken(newToken)
c.Header("new-token", newToken)
c.Header("new-expires-at", strconv.FormatInt(newClaims.ExpiresAt, 10))
if global.GVA_CONFIG.System.UseMultipoint {
err,RedisJwtToken := service.GetRedisJWT(newClaims.Username)
if err!=nil {
global.GVA_LOG.Error("get redis jwt failed", zap.Any("err", err))
}else{
err, RedisJwtToken := service.GetRedisJWT(newClaims.Username)
if err != nil {
global.GVA_LOG.Error("get redis jwt failed", zap.Any("err", err))
} else { // 当之前的取成功时才进行拉黑操作
_ = service.JsonInBlacklist(model.JwtBlacklist{Jwt: RedisJwtToken})
//当之前的取成功时才进行拉黑操作
}
// 无论如何都要记录当前的活跃状态
_ = service.SetRedisJWT(newToken,newClaims.Username)
_ = service.SetRedisJWT(newToken, newClaims.Username)
}
}
c.Set("claims", claims)
+8 -1
View File
@@ -13,4 +13,11 @@ type GetById struct {
type IdsReq struct {
Ids []int `json:"ids" form:"ids"`
}
}
// Get role by id structure
type GetAuthorityId struct {
AuthorityId string
}
type Empty struct {}
+6 -6
View File
@@ -1,16 +1,16 @@
package request
type DBReq struct {
Database string `json:"database";gorm:"column:database"`
Database string `json:"database" gorm:"column:database"`
}
type TableReq struct {
TableName string `json:"tableName"`
}
type ColumeReq struct {
ColumeName string `json:"columeName";gorm:"column:colume_name"`
DataType string `json:"dataType";gorm:"column:data_type"`
DataTypeLong string `json:"dataTypeLong";gorm:"column:data_type_long"`
ColumeComment string `json:"columeComment";gorm:"column:colume_comment"`
type ColumnReq struct {
ColumnName string `json:"columnName" gorm:"column:column_name"`
DataType string `json:"dataType" gorm:"column:data_type"`
DataTypeLong string `json:"dataTypeLong" gorm:"column:data_type_long"`
ColumnComment string `json:"columnComment" gorm:"column:column_comment"`
}
-5
View File
@@ -7,8 +7,3 @@ type AddMenuAuthorityInfo struct {
Menus []model.SysBaseMenu
AuthorityId string
}
// Get role by id structure
type AuthorityIdInfo struct {
AuthorityId string
}
+2 -2
View File
@@ -3,7 +3,7 @@ package request
import uuid "github.com/satori/go.uuid"
// User register structure
type RegisterStruct struct {
type Register struct {
Username string `json:"userName"`
Password string `json:"passWord"`
NickName string `json:"nickName" gorm:"default:'QMPlusUser'"`
@@ -12,7 +12,7 @@ type RegisterStruct struct {
}
// User login structure
type RegisterAndLoginStruct struct {
type Login struct {
Username string `json:"username"`
Password string `json:"password"`
Captcha string `json:"captcha"`
@@ -37,7 +37,7 @@ func OkWithData(data interface{}, c *gin.Context) {
Result(SUCCESS, data, "操作成功", c)
}
func OkDetailed(data interface{}, message string, c *gin.Context) {
func OkWithDetailed(data interface{}, message string, c *gin.Context) {
Result(SUCCESS, data, message, c)
}
@@ -49,6 +49,6 @@ func FailWithMessage(message string, c *gin.Context) {
Result(ERROR, map[string]interface{}{}, message, c)
}
func FailWithDetailed(code int, data interface{}, message string, c *gin.Context) {
Result(code, data, message, c)
func FailWithDetailed(data interface{}, message string, c *gin.Context) {
Result(ERROR, data, message, c)
}
+5
View File
@@ -1,5 +1,7 @@
package model
import "errors"
// 初始版本自动化代码工具
type AutoCodeStruct struct {
StructName string `json:"structName"`
@@ -8,6 +10,7 @@ type AutoCodeStruct struct {
Abbreviation string `json:"abbreviation"`
Description string `json:"description"`
AutoCreateApiToSql bool `json:"autoCreateApiToSql"`
AutoMoveFile bool `json:"autoMoveFile"`
Fields []Field `json:"fields"`
}
@@ -23,3 +26,5 @@ type Field struct {
FieldSearchType string `json:"fieldSearchType"`
DictType string `json:"dictType"`
}
var AutoMoveErr error = errors.New("创建代码成功并移动文件成功")
@@ -1,13 +1,13 @@
package v1
import (
"fmt"
"gin-vue-admin/global/response"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
resp "gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/response"
"gin-vue-admin/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags {{.StructName}}
@@ -21,9 +21,9 @@ import (
func Create{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} model.{{.StructName}}
_ = c.ShouldBindJSON(&{{.Abbreviation}})
err := service.Create{{.StructName}}({{.Abbreviation}})
if err != nil {
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
if err := service.Create{{.StructName}}({{.Abbreviation}}); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
@@ -40,9 +40,9 @@ func Create{{.StructName}}(c *gin.Context) {
func Delete{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} model.{{.StructName}}
_ = c.ShouldBindJSON(&{{.Abbreviation}})
err := service.Delete{{.StructName}}({{.Abbreviation}})
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.Delete{{.StructName}}({{.Abbreviation}}); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
@@ -54,16 +54,16 @@ func Delete{{.StructName}}(c *gin.Context) {
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除{{.StructName}}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /{{.Abbreviation}}/delete{{.StructName}}ByIds [delete]
func Delete{{.StructName}}ByIds(c *gin.Context) {
var IDS request.IdsReq
_ = c.ShouldBindJSON(&IDS)
err := service.Delete{{.StructName}}ByIds(IDS)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
if err := service.Delete{{.StructName}}ByIds(IDS); err != nil {
global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
response.FailWithMessage("批量删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
response.OkWithMessage("批量删除成功", c)
}
}
@@ -78,9 +78,9 @@ func Delete{{.StructName}}ByIds(c *gin.Context) {
func Update{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} model.{{.StructName}}
_ = c.ShouldBindJSON(&{{.Abbreviation}})
err := service.Update{{.StructName}}(&{{.Abbreviation}})
if err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
if err := service.Update{{.StructName}}(&{{.Abbreviation}}); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
@@ -97,9 +97,9 @@ func Update{{.StructName}}(c *gin.Context) {
func Find{{.StructName}}(c *gin.Context) {
var {{.Abbreviation}} model.{{.StructName}}
_ = c.ShouldBindQuery(&{{.Abbreviation}})
err, re{{.Abbreviation}} := service.Get{{.StructName}}({{.Abbreviation}}.ID)
if err != nil {
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c)
if err, re{{.Abbreviation}} := service.Get{{.StructName}}({{.Abbreviation}}.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(gin.H{"re{{.Abbreviation}}": re{{.Abbreviation}}}, c)
}
@@ -116,15 +116,15 @@ func Find{{.StructName}}(c *gin.Context) {
func Get{{.StructName}}List(c *gin.Context) {
var pageInfo request.{{.StructName}}Search
_ = c.ShouldBindQuery(&pageInfo)
err, list, total := service.Get{{.StructName}}InfoList(pageInfo)
if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
} else {
response.OkWithData(resp.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, c)
}
if err, list, total := service.Get{{.StructName}}InfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败", zap.Any("err", err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
@@ -9,10 +9,10 @@ import (
type {{.StructName}} struct {
global.GVA_MODEL {{- range .Fields}}
{{- if eq .FieldType "bool" }}
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"`
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- if eq .FieldType "string" -}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"`
{{- else }}
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"`
{{- end }} {{- end }}
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- if eq .FieldType "string" -}}{{- if .DataTypeLong -}}({{.DataTypeLong}}){{- end -}}{{- end -}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}"`
{{- end }} {{- end }}
}
{{ if .TableName }}
@@ -6,67 +6,66 @@ import (
"gin-vue-admin/model/request"
)
// @title Create{{.StructName}}
// @description create a {{.StructName}}
// @param {{.Abbreviation}} model.{{.StructName}}
// @auth 2020/04/05 20:22
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Create{{.StructName}}
//@description: 创建{{.StructName}}记录
//@param: {{.Abbreviation}} model.{{.StructName}}
//@return: err error
func Create{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
err = global.GVA_DB.Create(&{{.Abbreviation}}).Error
return err
}
// @title Delete{{.StructName}}
// @description delete a {{.StructName}}
// @auth 2020/04/05 20:22
// @param {{.Abbreviation}} model.{{.StructName}}
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Delete{{.StructName}}
//@description: 删除{{.StructName}}记录
//@param: {{.Abbreviation}} model.{{.StructName}}
//@return: err error
func Delete{{.StructName}}({{.Abbreviation}} model.{{.StructName}}) (err error) {
err = global.GVA_DB.Delete({{.Abbreviation}}).Error
return err
}
// @title Delete{{.StructName}}ByIds
// @description delete {{.StructName}}s
// @auth 2020/04/05 20:22
// @param {{.Abbreviation}} model.{{.StructName}}
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Delete{{.StructName}}ByIds
//@description: 批量删除{{.StructName}}记录
//@param: ids request.IdsReq
//@return: err error
func Delete{{.StructName}}ByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]model.{{.StructName}}{},"id in ?",ids.Ids).Error
return err
}
// @title Update{{.StructName}}
// @description update a {{.StructName}}
// @param {{.Abbreviation}} *model.{{.StructName}}
// @auth 2020/04/05 20:22
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Update{{.StructName}}
//@description: 更新{{.StructName}}记录
//@param: {{.Abbreviation}} *model.{{.StructName}}
//@return: err error
func Update{{.StructName}}({{.Abbreviation}} *model.{{.StructName}}) (err error) {
err = global.GVA_DB.Save({{.Abbreviation}}).Error
return err
}
// @title Get{{.StructName}}
// @description get the info of a {{.StructName}}
// @auth 2020/04/05 20:22
// @param id uint
// @return error
// @return {{.StructName}} {{.StructName}}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Get{{.StructName}}
//@description: 根据id获取{{.StructName}}记录
//@param: id uint
//@return: err error, {{.Abbreviation}} model.{{.StructName}}
func Get{{.StructName}}(id uint) (err error, {{.Abbreviation}} model.{{.StructName}}) {
err = global.GVA_DB.Where("id = ?", id).First(&{{.Abbreviation}}).Error
return
}
// @title Get{{.StructName}}InfoList
// @description get {{.StructName}} list by pagination, 分页获取{{.StructName}}
// @auth 2020/04/05 20:22
// @param info PageInfo
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Get{{.StructName}}InfoList
//@description: 分页获取{{.StructName}}记录
//@param: info request.{{.StructName}}Search
//@return: err error, list interface{}, total int64
func Get{{.StructName}}InfoList(info request.{{.StructName}}Search) (err error, list interface{}, total int64) {
limit := info.PageSize
+125
View File
@@ -0,0 +1,125 @@
<template>
<div>
<el-form :model="formData" label-position="right" label-width="80px">
{{- range .Fields}}
<el-form-item label="{{.FieldDesc}}:">
{{- if eq .FieldType "bool" }}
<el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch>
{{ end -}}
{{- if eq .FieldType "string" }}
<el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" ></el-input>
{{ end -}}
{{- if eq .FieldType "int" }}
{{- if .DictType}}
<el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable>
<el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value"></el-option>
</el-select>
{{ else -}}
<el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"></el-input>
{{ end -}}
{{ end -}}
{{- if eq .FieldType "time.Time" }}
<el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" clearable></el-date-picker>
{{ end -}}
{{- if eq .FieldType "float64" }}
<el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable></el-input-number>
{{ end -}}
</el-form-item>
{{ end -}}
<el-form-item>
<el-button @click="save" type="primary">保存</el-button>
<el-button @click="back" type="primary">返回</el-button>
</el-form-item>
</el-form>
</div>
</template>
<script>
import {
create{{.StructName}},
update{{.StructName}},
find{{.StructName}}
} from "@/api/{{.PackageName}}"; // 此处请自行替换地址
import infoList from "@/mixins/infoList";
export default {
name: "{{.StructName}}",
mixins: [infoList],
data() {
return {
type: "",
{{- range .Fields}}
{{- if .DictType }}
{{ .DictType }}Options:[],
{{ end -}}
{{end -}}
formData: {
{{range .Fields}}
{{- if eq .FieldType "bool" -}}
{{.FieldJson}}:false,
{{ end -}}
{{- if eq .FieldType "string" -}}
{{.FieldJson}}:"",
{{ end -}}
{{- if eq .FieldType "int" -}}
{{.FieldJson}}:0,
{{ end -}}
{{- if eq .FieldType "time.Time" -}}
{{.FieldJson}}:new Date(),
{{ end -}}
{{- if eq .FieldType "float64" -}}
{{.FieldJson}}:0,
{{ end -}}
{{ end }}
}
};
},
methods: {
async save() {
let res;
switch (this.type) {
case "create":
res = await create{{.StructName}}(this.formData);
break;
case "update":
res = await update{{.StructName}}(this.formData);
break;
default:
res = await create{{.StructName}}(this.formData);
break;
}
if (res.code == 0) {
this.$message({
type:"success",
message:"创建/更改成功"
})
}
},
back(){
this.$router.go(-1)
}
},
async created() {
// 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
if(this.$route.query.id){
const res = await find{{.StructName}}({ ID: this.$route.query.id })
if(res.code == 0){
this.formData = res.data.re{{.Abbreviation}}
this.type == "update"
}
}else{
this.type == "create"
}
{{ range .Fields -}}
{{- if .DictType }}
await this.getDict("{{.DictType}}");
{{ end -}}
{{- end }}
}
};
</script>
<style>
</style>
@@ -136,7 +136,7 @@ import {
find{{.StructName}},
get{{.StructName}}List
} from "@/api/{{.PackageName}}"; // 此处请自行替换地址
import { formatTimeToStr } from "@/utils/data";
import { formatTimeToStr } from "@/utils/date";
import infoList from "@/mixins/infoList";
export default {
name: "{{.StructName}}",
@@ -149,11 +149,13 @@ export default {
type: "",
deleteVisible: false,
multipleSelection: [],
{{- range .Fields}}
{{- if .DictType }}
{{ .DictType }}Options:[],
{{ end -}}
{{end -}}
formData: {
{{range .Fields}}
{{- if eq .FieldType "bool" -}}
@@ -208,6 +210,13 @@ export default {
},
async onDelete() {
const ids = []
if(this.multipleSelection.length == 0){
this.$message({
type: 'warning',
message: '请选择要删除的数据'
})
return
}
this.multipleSelection &&
this.multipleSelection.map(item => {
ids.push(item.ID)
+2 -3
View File
@@ -9,12 +9,11 @@ import (
func InitAutoCodeRouter(Router *gin.RouterGroup) {
AutoCodeRouter := Router.Group("autoCode").
Use(middleware.JWTAuth()).
Use(middleware.CasbinHandler()).
Use(middleware.OperationRecord())
Use(middleware.CasbinHandler())
{
AutoCodeRouter.POST("createTemp", v1.CreateTemp) // 创建自动化代码
AutoCodeRouter.GET("getTables", v1.GetTables) // 获取对应数据库的表
AutoCodeRouter.GET("getDB", v1.GetDB) // 获取数据库
AutoCodeRouter.GET("getColume", v1.GetColume) // 获取指定表所有字段信息
AutoCodeRouter.GET("getColumn", v1.GetColumn) // 获取指定表所有字段信息
}
}
+15 -23
View File
@@ -7,15 +7,11 @@ import (
"gorm.io/gorm"
)
// @title FindOrCreateFile
// @description Check your file if it does not exist, or return current slice of the file
// 上传文件时检测当前文件属性,如果没有文件则创建,有则返回文件的当前切片
// @auth 2020/04/05 20:22
// @param fileMd5 string
// @param fileName string
// @param chunkTotal int
// @return err error
// @return file ExaFile
//@author: [piexlmax](https://github.com/piexlmax)
//@function: FindOrCreateFile
//@description: 上传文件时检测当前文件属性,如果没有文件则创建,有则返回文件的当前切片
//@param: fileMd5 string, fileName string, chunkTotal int
//@return: err error, file model.ExaFile
func FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err error, file model.ExaFile) {
var cfile model.ExaFile
@@ -33,13 +29,11 @@ func FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (err erro
return err, cfile
}
// @title CreateFileChunk
// @description create a chunk of the file, 创建文件切片记录
// @auth 2020/04/05 20:22
// @param id unit
// @param fileChunkPath string
// @param fileChunkNumber int
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateFileChunk
//@description: 创建文件切片记录
//@param: id uint, fileChunkPath string, fileChunkNumber int
//@return: error
func CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error {
var chunk model.ExaFileChunk
@@ -50,13 +44,11 @@ func CreateFileChunk(id uint, fileChunkPath string, fileChunkNumber int) error {
return err
}
// @title DeleteFileChunk
// @description delete a chuck of the file, 删除文件切片记录
// @auth 2020/04/05 20:22
// @param FileMd5 string
// @param FileName string
// @param FilePath string
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteFileChunk
//@description: 删除文件切片记录
//@param: fileMd5 string, fileName string, filePath string
//@return: error
func DeleteFileChunk(fileMd5 string, fileName string, filePath string) error {
var chunks []model.ExaFileChunk
+25 -27
View File
@@ -6,57 +6,55 @@ import (
"gin-vue-admin/model/request"
)
// @title CreateExaCustomer
// @description create a customer, 创建用户
// @param e model.ExaCustomer
// @auth 2020/04/05 20:22
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateExaCustomer
//@description: 创建客户
//@param: e model.ExaCustomer
//@return: err error
func CreateExaCustomer(e model.ExaCustomer) (err error) {
err = global.GVA_DB.Create(&e).Error
return err
}
// @title DeleteFileChunk
// @description delete a customer, 删除用户
// @auth 2020/04/05 20:22
// @param e model.ExaCustomer
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteFileChunk
//@description: 删除客户
//@param: e model.ExaCustomer
//@return: err error
func DeleteExaCustomer(e model.ExaCustomer) (err error) {
err = global.GVA_DB.Delete(e).Error
return err
}
// @title UpdateExaCustomer
// @description update a customer, 更新用户
// @param e *model.ExaCustomer
// @auth 2020/04/05 20:22
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateExaCustomer
//@description: 更新客户
//@param: e *model.ExaCustomer
//@return: err error
func UpdateExaCustomer(e *model.ExaCustomer) (err error) {
err = global.GVA_DB.Save(e).Error
return err
}
// @title GetExaCustomer
// @description get the info of a costumer , 获取用户信息
// @auth 2020/04/05 20:22
// @param id uint
// @return error
// @return customer ExaCustomer
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetExaCustomer
//@description: 获取客户信息
//@param: id uint
//@return: err error, customer model.ExaCustomer
func GetExaCustomer(id uint) (err error, customer model.ExaCustomer) {
err = global.GVA_DB.Where("id = ?", id).First(&customer).Error
return
}
// @title GetCustomerInfoList
// @description get customer list by pagination, 分页获取用户列表
// @auth 2020/04/05 20:22
// @param sysUserAuthorityID string
// @param info PageInfo
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetCustomerInfoList
//@description: 分页获取客户列表
//@param: sysUserAuthorityID string, info request.PageInfo
//@return: err error, list interface{}, total int64
func GetCustomerInfoList(sysUserAuthorityID string, info request.PageInfo) (err error, list interface{}, total int64) {
limit := info.PageSize
+26 -31
View File
@@ -10,22 +10,21 @@ import (
"strings"
)
// @title Upload
// @description 创建文件上传记录
// @param file model.ExaFileUploadAndDownload
// @auth 2020/04/05 20:22
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Upload
//@description: 创建文件上传记录
//@param: file model.ExaFileUploadAndDownload
//@return: error
func Upload(file model.ExaFileUploadAndDownload) error {
err := global.GVA_DB.Create(&file).Error
return err
return global.GVA_DB.Create(&file).Error
}
// @title FindFile
// @description 删除文件切片记录
// @auth 2020/04/05 20:22
// @param id uint
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: FindFile
//@description: 删除文件切片记录
//@param: id uint
//@return: error, model.ExaFileUploadAndDownload
func FindFile(id uint) (error, model.ExaFileUploadAndDownload) {
var file model.ExaFileUploadAndDownload
@@ -33,11 +32,11 @@ func FindFile(id uint) (error, model.ExaFileUploadAndDownload) {
return err, file
}
// @title DeleteFile
// @description 删除文件记录
// @auth 2020/04/05 20:22
// @param file model.ExaFileUploadAndDownload
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteFile
//@description: 删除文件记录
//@param: file model.ExaFileUploadAndDownload
//@return: err error
func DeleteFile(file model.ExaFileUploadAndDownload) (err error) {
var fileFromDb model.ExaFileUploadAndDownload
@@ -50,13 +49,11 @@ func DeleteFile(file model.ExaFileUploadAndDownload) (err error) {
return err
}
// @title GetFileRecordInfoList
// @description 分页获取数据
// @auth 2020/04/05 20:22
// @param info PageInfo
// @return err error
// @return list error
// @return total error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetFileRecordInfoList
//@description: 分页获取数据
//@param: info request.PageInfo
//@return: err error, list interface{}, total int64
func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
limit := info.PageSize
@@ -68,13 +65,11 @@ func GetFileRecordInfoList(info request.PageInfo) (err error, list interface{},
return err, fileLists, total
}
// @title UploadFile
// @description 根据配置文件判断是文件上传到本地或者七牛云
// @auth 2020/04/05 20:22
// @param header *multipart.FileHeader
// @param noSave string
// @return err error
// @return file file model.ExaFileUploadAndDownload
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UploadFile
//@description: 根据配置文件判断是文件上传到本地或者七牛云
//@param: header *multipart.FileHeader, noSave string
//@return: err error, file model.ExaFileUploadAndDownload
func UploadFile(header *multipart.FileHeader, noSave string) (err error, file model.ExaFileUploadAndDownload) {
oss := upload.NewOss()
+40 -26
View File
@@ -11,19 +11,34 @@ import (
"strconv"
)
// 保存文件切片路径
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SaveChunk
//@description: 保存文件切片路径
//@param: uploader model.ExaSimpleUploader
//@return: err error
func SaveChunk(uploader model.ExaSimpleUploader) (err error) {
return global.GVA_DB.Create(uploader).Error
}
// 检查文件是否已经上传过
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CheckFileMd5
//@description: 检查文件是否已经上传过
//@param: md5 string
//@return: err error, uploads []model.ExaSimpleUploader, isDone bool
func CheckFileMd5(md5 string) (err error, uploads []model.ExaSimpleUploader, isDone bool) {
err = global.GVA_DB.Find(&uploads, "identifier = ? AND is_done = ?", md5, false).Error
isDone = errors.Is(global.GVA_DB.First(&model.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, true).Error, gorm.ErrRecordNotFound)
return err, uploads, !isDone
}
// 合并文件
//@author: [piexlmax](https://github.com/piexlmax)
//@function: MergeFileMd5
//@description: 合并文件
//@param: md5 string, fileName string
//@return: err error
func MergeFileMd5(md5 string, fileName string) (err error) {
finishDir := "./finish/"
dir := "./chunk/" + md5
@@ -51,27 +66,26 @@ func MergeFileMd5(md5 string, fileName string) (err error) {
if err != nil {
return err
}
//创建事务
tx := global.GVA_DB.Begin()
//删除切片信息
err = tx.Delete(&model.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, false).Error
// 添加文件信息
if err != nil {
fmt.Println(err)
tx.Rollback()
}
err = tx.Create(&model.ExaSimpleUploader{
Identifier: md5,
IsDone: true,
FilePath: finishDir + fileName,
Filename: fileName,
}).Error
if err != nil {
fmt.Println(err)
tx.Rollback()
}
tx.Commit()
//清除切片
err = os.RemoveAll(dir)
return
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
//删除切片信息
if err = tx.Delete(&model.ExaSimpleUploader{}, "identifier = ? AND is_done = ?", md5, false).Error; err != nil {
fmt.Println(err)
return err
}
data := model.ExaSimpleUploader{
Identifier: md5,
IsDone: true,
FilePath: finishDir + fileName,
Filename: fileName,
}
// 添加文件信息
if err = tx.Create(&data).Error; err != nil {
fmt.Println(err)
return err
}
return nil
})
err = os.RemoveAll(dir) //清除切片
return err
}
+20 -23
View File
@@ -8,47 +8,44 @@ import (
"time"
)
// @title JsonInBlacklist
// @description create jwt blacklist
// @param jwtList model.JwtBlacklist
// @auth 2020/04/05 20:22
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: JsonInBlacklist
//@description: 拉黑jwt
//@param: jwtList model.JwtBlacklist
//@return: err error
func JsonInBlacklist(jwtList model.JwtBlacklist) (err error) {
err = global.GVA_DB.Create(&jwtList).Error
return
}
// @title IsBlacklist
// @description check if the Jwt is in the blacklist or not, 判断JWT是否在黑名单内部
// @auth 2020/04/05 20:22
// @param jwt string
// @param jwtList model.JwtBlacklist
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: IsBlacklist
//@description: 判断JWT是否在黑名单内部
//@param: jwt string
//@return: bool
func IsBlacklist(jwt string) bool {
isNotFound := errors.Is(global.GVA_DB.Where("jwt = ?", jwt).First(&model.JwtBlacklist{}).Error, gorm.ErrRecordNotFound)
return !isNotFound
}
// @title GetRedisJWT
// @description Get user info in redis
// @auth 2020/04/05 20:22
// @param userName string
// @return err error
// @return redisJWT string
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetRedisJWT
//@description: 从redis取jwt
//@param: userName string
//@return: err error, redisJWT string
func GetRedisJWT(userName string) (err error, redisJWT string) {
redisJWT, err = global.GVA_REDIS.Get(userName).Result()
return err, redisJWT
}
// @title SetRedisJWT
// @description set jwt into the Redis
// @auth 2020/04/05 20:22
// @param jwtList model.JwtBlacklist
// @param userName string
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetRedisJWT
//@description: jwt存入redis并设置过期时间
//@param: userName string
//@return: err error, redisJWT string
func SetRedisJWT(jwt string, userName string) (err error) {
// 此处过期时间等于jwt过期时间
+51 -39
View File
@@ -8,25 +8,24 @@ import (
"gorm.io/gorm"
)
// @title CreateApi
// @description create base apis, 新增基础api
// @auth 2020/04/05 20:22
// @param api model.SysApi
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateApi
//@description: 新增基础api
//@param: api model.SysApi
//@return: err error
func CreateApi(api model.SysApi) (err error) {
if !errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&model.SysApi{}).Error, gorm.ErrRecordNotFound) {
return errors.New("存在相同api")
}
return global.GVA_DB.Create(&api).Error
}
// @title DeleteApi
// @description delete a base api, 删除基础api
// @param api model.SysApi
// @auth 2020/04/05 20:22
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteApi
//@description: 删除基础api
//@param: api model.SysApi
//@return: err error
func DeleteApi(api model.SysApi) (err error) {
err = global.GVA_DB.Delete(api).Error
@@ -34,16 +33,33 @@ func DeleteApi(api model.SysApi) (err error) {
return err
}
// @title GetInfoList
// @description get apis by pagination, 分页获取数据
// @auth 2020/04/05 20:22
// @param api model.SysApi
// @param info request.PageInfo
// @param order string
// @param desc bool
// @return err error
// @return list interface{}
// @return total int
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateApi
//@description: 自动创建api数据,
//@param: api model.SysApi
//@return: err error
func AutoCreateApi(api model.SysApi) (err error) {
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
var fApi model.SysApi
var txErr error
fxErr := tx.Where("path = ? AND method = ?", api.Path, api.Method).First(&fApi).Error
if errors.Is(fxErr, gorm.ErrRecordNotFound) {
txErr = tx.Create(&api).Error
if txErr != nil{
return txErr
}
}
return nil
})
return err
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetAPIInfoList
//@description: 分页获取数据,
//@param: api model.SysApi, info request.PageInfo, order string, desc bool
//@return: err error
func GetAPIInfoList(api model.SysApi, info request.PageInfo, order string, desc bool) (err error, list interface{}, total int64) {
limit := info.PageSize
@@ -88,40 +104,36 @@ func GetAPIInfoList(api model.SysApi, info request.PageInfo, order string, desc
return err, apiList, total
}
// @title GetAllApis
// @description get all apis, 获取所有的api
// @auth 2020/04/05 20:22
// @return err error
// @return apis []SysApi
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetAllApis
//@description: 获取所有的api
//@return: err error, apis []model.SysApi
func GetAllApis() (err error, apis []model.SysApi) {
err = global.GVA_DB.Find(&apis).Error
return
}
// @title GetApiById
// @description 根据id获取api
// @auth 2020/04/05 20:22
// @param api model.SysApi
// @param id float64
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetApiById
//@description: 根据id获取api
//@param: id float64
//@return: err error, api model.SysApi
func GetApiById(id float64) (err error, api model.SysApi) {
err = global.GVA_DB.Where("id = ?", id).First(&api).Error
return
}
// @title UpdateApi
// @description update a base api, update api
// @auth 2020/04/05 20:22
// @param api model.SysApi
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateApi
//@description: 根据id更新api
//@param: api model.SysApi
//@return: err error
func UpdateApi(api model.SysApi) (err error) {
var oldA model.SysApi
err = global.GVA_DB.Where("id = ?", api.ID).First(&oldA).Error
if oldA.Path != api.Path || oldA.Method != api.Method {
if !errors.Is(global.GVA_DB.Where("path = ? AND method = ?", api.Path, api.Method).First(&model.SysApi{}).Error, gorm.ErrRecordNotFound) {
return errors.New("存在相同api路径")
+46 -52
View File
@@ -10,12 +10,11 @@ import (
"strconv"
)
// @title CreateAuthority
// @description 创建一个角色
// @auth 2020/04/05 20:22
// @param auth model.SysAuthority
// @return error
// @return authority model.SysAuthority
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateAuthority
//@description: 创建一个角色
//@param: auth model.SysAuthority
//@return: err error, authority model.SysAuthority
func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAuthority) {
var authorityBox model.SysAuthority
@@ -26,12 +25,11 @@ func CreateAuthority(auth model.SysAuthority) (err error, authority model.SysAut
return err, auth
}
// @title CopyAuthority
// @description 复制一个角色
// @auth 2020/04/05 20:22
// @param copyInfo response.SysAuthorityCopyResponse
// @return error
// @return authority model.SysAuthority
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CopyAuthority
//@description: 复制一个角色
//@param: copyInfo response.SysAuthorityCopyResponse
//@return: err error, authority model.SysAuthority
func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, authority model.SysAuthority) {
var authorityBox model.SysAuthority
@@ -39,7 +37,7 @@ func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, autho
return errors.New("存在相同角色id"), authority
}
copyInfo.Authority.Children = []model.SysAuthority{}
err, menus := GetMenuAuthority(copyInfo.OldAuthorityId)
err, menus := GetMenuAuthority(&request.GetAuthorityId{AuthorityId: copyInfo.OldAuthorityId})
var baseMenu []model.SysBaseMenu
for _, v := range menus {
intNum, _ := strconv.Atoi(v.MenuId)
@@ -57,24 +55,22 @@ func CopyAuthority(copyInfo response.SysAuthorityCopyResponse) (err error, autho
return err, copyInfo.Authority
}
// @title UpdateAuthority
// @description 更改一个角色
// @auth 2020/04/05 20:22
// @param auth model.SysAuthority
// @return error
// @return authority model.SysAuthority
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateAuthority
//@description: 更改一个角色
//@param: auth model.SysAuthority
//@return:err error, authority model.SysAuthority
func UpdateAuthority(auth model.SysAuthority) (err error, authority model.SysAuthority) {
err = global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&model.SysAuthority{}).Updates(&auth).Error
return err, auth
}
// @title DeleteAuthority
// @description 删除角色
// @auth 2020/04/05 20:22
// @param auth model.SysAuthority
// @return error
// 删除角色
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteAuthority
//@description: 删除角色
//@param: auth *model.SysAuthority
//@return: err error
func DeleteAuthority(auth *model.SysAuthority) (err error) {
if !errors.Is(global.GVA_DB.Where("authority_id = ?", auth.AuthorityId).First(&model.SysUser{}).Error, gorm.ErrRecordNotFound) {
@@ -95,12 +91,11 @@ func DeleteAuthority(auth *model.SysAuthority) (err error) {
return err
}
// @title GetInfoList
// @description 删除文件切片记录
// @auth 2020/04/05 20:22
// @param info request.PaveInfo
// @return error
// 分页获取数据
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetAuthorityInfoList
//@description: 分页获取数据
//@param: info request.PageInfo
//@return: err error, list interface{}, total int64
func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
limit := info.PageSize
@@ -116,23 +111,22 @@ func GetAuthorityInfoList(info request.PageInfo) (err error, list interface{}, t
return err, authority, total
}
// @title GetAuthorityInfo
// @description 获取所有角色信息
// @auth 2020/04/05 20:22
// @param auth model.SysAuthority
// @return error
// @param authority model.SysAuthority
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetAuthorityInfo
//@description: 获取所有角色信息
//@param: auth model.SysAuthority
//@return: err error, sa model.SysAuthority
func GetAuthorityInfo(auth model.SysAuthority) (err error, sa model.SysAuthority) {
err = global.GVA_DB.Preload("DataAuthorityId").Where("authority_id = ?", auth.AuthorityId).First(&sa).Error
return err, sa
}
// @title SetDataAuthority
// @description 设置角色资源权限
// @auth 2020/04/05 20:22
// @param auth model.SysAuthority
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetDataAuthority
//@description: 设置角色资源权限
//@param: auth model.SysAuthority
//@return:error
func SetDataAuthority(auth model.SysAuthority) error {
var s model.SysAuthority
@@ -141,11 +135,11 @@ func SetDataAuthority(auth model.SysAuthority) error {
return err
}
// @title SetMenuAuthority
// @description 菜单与角色绑定
// @auth 2020/04/05 20:22
// @param auth *model.SysAuthority
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetMenuAuthority
//@description: 菜单与角色绑定
//@param: auth *model.SysAuthority
//@return: error
func SetMenuAuthority(auth *model.SysAuthority) error {
var s model.SysAuthority
@@ -154,11 +148,11 @@ func SetMenuAuthority(auth *model.SysAuthority) error {
return err
}
// @title findChildrenAuthority
// @description 查询子角色
// @auth 2020/04/05 20:22
// @param auth *model.SysAuthority
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: findChildrenAuthority
//@description: 查询子角色
//@param: authority *model.SysAuthority
//@return: err error
func findChildrenAuthority(authority *model.SysAuthority) (err error) {
err = global.GVA_DB.Preload("DataAuthorityId").Where("parent_id = ?", authority.AuthorityId).Find(&authority.Children).Error
+96 -21
View File
@@ -1,27 +1,31 @@
package service
import (
"errors"
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/utils"
"io/ioutil"
"os"
"path/filepath"
"strings"
"text/template"
)
type tplData struct {
template *template.Template
locationPath string
autoCodePath string
template *template.Template
locationPath string
autoCodePath string
autoMoveFilePath string
}
// @title CreateTemp
// @description 函数的详细描述
// @auth 2020/04/05 20:22
// @param autoCode model.AutoCodeStruct
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateTemp
//@description: 创建代码
//@param: model.AutoCodeStruct
//@return: error
func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
basePath := "resource/template"
@@ -46,7 +50,7 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
}
// 生成文件路径,填充 autoCodePath 字段,readme.txt.tpl不符合规则,需要特殊处理
// resource/template/fe/api.js.tpl -> autoCode/fe/autoCode.PackageName/api/autoCode.PackageName.js
// resource/template/web/api.js.tpl -> autoCode/web/autoCode.PackageName/api/autoCode.PackageName.js
// resource/template/readme.txt.tpl -> autoCode/readme.txt
autoPath := "autoCode/"
for index, value := range dataList {
@@ -88,19 +92,36 @@ func CreateTemp(autoCode model.AutoCodeStruct) (err error) {
_ = f.Close()
}
// 生成压缩包
if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {
return err
}
// 移除中间文件
if err := os.RemoveAll(autoPath); err != nil {
return err
defer func() { // 移除中间文件
if err := os.RemoveAll(autoPath); err != nil {
return
}
}()
if autoCode.AutoMoveFile { // 判断是否需要自动转移
for index, _ := range dataList {
addAutoMoveFile(&dataList[index])
}
for _, value := range dataList { // 移动文件
if err := utils.FileMove(value.autoCodePath, value.autoMoveFilePath); err != nil {
fmt.Println(err)
return err
}
}
return errors.New("创建代码成功并移动文件成功")
} else { // 打包
if err := utils.ZipFiles("./ginvueadmin.zip", fileList, ".", "."); err != nil {
return err
}
}
return nil
}
// GetAllTplFile 用来获取 pathName 文件夹下所有 tpl 文件
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetAllTplFile
//@description: 获取 pathName 文件夹下所有 tpl 文件
//@param: pathName string, fileList []string
//@return: []string, error
func GetAllTplFile(pathName string, fileList []string) ([]string, error) {
files, err := ioutil.ReadDir(pathName)
for _, fi := range files {
@@ -118,17 +139,71 @@ func GetAllTplFile(pathName string, fileList []string) ([]string, error) {
return fileList, err
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetTables
//@description: 获取数据库的所有表名
//@param: pathName string
//@param: fileList []string
//@return: []string, error
func GetTables(dbName string) (err error, TableNames []request.TableReq) {
err = global.GVA_DB.Raw("select table_name as table_name from information_schema.tables where table_schema = ?", dbName).Scan(&TableNames).Error
return err, TableNames
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetDB
//@description: 获取数据库的所有数据库名
//@param: pathName string
//@param: fileList []string
//@return: []string, error
func GetDB() (err error, DBNames []request.DBReq) {
err = global.GVA_DB.Raw("SELECT SCHEMA_NAME AS `database` FROM INFORMATION_SCHEMA.SCHEMATA;").Scan(&DBNames).Error
return err, DBNames
}
func GetColume(tableName string, dbName string) (err error, Columes []request.ColumeReq) {
err = global.GVA_DB.Raw("SELECT COLUMN_NAME colume_name,DATA_TYPE data_type,CASE DATA_TYPE WHEN 'longtext' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'varchar' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'double' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'decimal' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'int' THEN c.NUMERIC_PRECISION WHEN 'bigint' THEN c.NUMERIC_PRECISION ELSE '' END AS data_type_long,COLUMN_COMMENT colume_comment FROM INFORMATION_SCHEMA.COLUMNS c WHERE table_name = ? AND table_schema = ?", tableName, dbName).Scan(&Columes).Error
return err, Columes
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetDB
//@description: 获取指定数据库和指定数据表的所有字段名,类型值等
//@param: pathName string
//@param: fileList []string
//@return: []string, error
func GetColumn(tableName string, dbName string) (err error, Columns []request.ColumnReq) {
err = global.GVA_DB.Raw("SELECT COLUMN_NAME column_name,DATA_TYPE data_type,CASE DATA_TYPE WHEN 'longtext' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'varchar' THEN c.CHARACTER_MAXIMUM_LENGTH WHEN 'double' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'decimal' THEN CONCAT_WS( ',', c.NUMERIC_PRECISION, c.NUMERIC_SCALE ) WHEN 'int' THEN c.NUMERIC_PRECISION WHEN 'bigint' THEN c.NUMERIC_PRECISION ELSE '' END AS data_type_long,COLUMN_COMMENT column_comment FROM INFORMATION_SCHEMA.COLUMNS c WHERE table_name = ? AND table_schema = ?", tableName, dbName).Scan(&Columns).Error
return err, Columns
}
//@author: [SliverHorn](https://github.com/SliverHorn)
//@author: [songzhibin97](https://github.com/songzhibin97)
//@function: addAutoMoveFile
//@description: 生成对应的迁移文件路径
//@param: *tplData
//@return: null
func addAutoMoveFile(data *tplData) {
dir := filepath.Base(filepath.Dir(data.autoCodePath))
base := filepath.Base(data.autoCodePath)
if strings.Contains(data.autoCodePath, "server") {
if strings.Contains(data.autoCodePath, "router") {
data.autoMoveFilePath = filepath.Join(dir, base)
} else if strings.Contains(data.autoCodePath, "api") {
data.autoMoveFilePath = filepath.Join(dir, "v1", base)
} else if strings.Contains(data.autoCodePath, "service") {
data.autoMoveFilePath = filepath.Join(dir, base)
} else if strings.Contains(data.autoCodePath, "model") {
data.autoMoveFilePath = filepath.Join(dir, base)
} else if strings.Contains(data.autoCodePath, "request") {
data.autoMoveFilePath = filepath.Join("model", dir, base)
}
} else if strings.Contains(data.autoCodePath, "web") {
if strings.Contains(data.autoCodePath, "js") {
data.autoMoveFilePath = filepath.Join("../", "web", "src", dir, base)
} else if strings.Contains(data.autoCodePath, "form") {
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), strings.TrimSuffix(base, filepath.Ext(base))+"From.vue")
} else if strings.Contains(data.autoCodePath, "table") {
data.autoMoveFilePath = filepath.Join("../", "web", "src", "view", filepath.Base(filepath.Dir(filepath.Dir(data.autoCodePath))), base)
}
}
}
+45 -23
View File
@@ -7,11 +7,11 @@ import (
"gorm.io/gorm"
)
// @title DeleteBaseMenu
// @description 删除基础路由
// @auth 2020/04/05 20:22
// @param id float64
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteBaseMenu
//@description: 删除基础路由
//@param: id float64
//@return: err error
func DeleteBaseMenu(id float64) (err error) {
err = global.GVA_DB.Preload("Parameters").Where("parent_id = ?", id).First(&model.SysBaseMenu{}).Error
@@ -30,11 +30,11 @@ func DeleteBaseMenu(id float64) (err error) {
return err
}
// @title UpdateBaseMenu
// @description 更新路由
// @auth 2020/04/05 20:22
// @param menu model.SysBaseMenu
// @return err errorgetMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateBaseMenu
//@description: 更新路由
//@param: menu model.SysBaseMenu
//@return:err error
func UpdateBaseMenu(menu model.SysBaseMenu) (err error) {
var oldMenu model.SysBaseMenu
@@ -50,23 +50,45 @@ func UpdateBaseMenu(menu model.SysBaseMenu) (err error) {
upDateMap["icon"] = menu.Icon
upDateMap["sort"] = menu.Sort
db := global.GVA_DB.Where("id = ?", menu.ID).Find(&oldMenu)
if oldMenu.Name != menu.Name {
if !errors.Is(global.GVA_DB.Where("id <> ? AND name = ?", menu.ID, menu.Name).First(&model.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) {
global.GVA_LOG.Debug("存在相同name修改失败")
return errors.New("存在相同name修改失败")
err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
db := tx.Where("id = ?", menu.ID).Find(&oldMenu)
if oldMenu.Name != menu.Name {
if !errors.Is(tx.Where("id <> ? AND name = ?", menu.ID, menu.Name).First(&model.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) {
global.GVA_LOG.Debug("存在相同name修改失败")
return errors.New("存在相同name修改失败")
}
}
}
err = global.GVA_DB.Delete(&model.SysBaseMenuParameter{}, "sys_base_menu_id = ?", menu.ID).Error
err = db.Updates(upDateMap).Error
err = tx.Delete(&model.SysBaseMenuParameter{}, "sys_base_menu_id = ?", menu.ID).Error
if err != nil {
global.GVA_LOG.Debug(err.Error())
return err
}
if len(menu.Parameters) > 0 {
for k, _ := range menu.Parameters {
menu.Parameters[k].SysBaseMenuID = menu.ID
}
err = tx.Create(&menu.Parameters).Error
if err != nil {
global.GVA_LOG.Debug(err.Error())
return err
}
}
err = db.Updates(upDateMap).Error
if err != nil {
global.GVA_LOG.Debug(err.Error())
return err
}
return nil
})
return err
}
// @title GetBaseMenuById
// @description get current menus, 返回当前选中menu
// @auth 2020/04/05 20:22
// @param id float64
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetBaseMenuById
//@description: 返回当前选中menu
//@param: id float64
//@return: err error, menu model.SysBaseMenu
func GetBaseMenuById(id float64) (err error, menu model.SysBaseMenu) {
err = global.GVA_DB.Preload("Parameters").Where("id = ?", id).First(&menu).Error
+35 -40
View File
@@ -12,12 +12,11 @@ import (
"strings"
)
// @title UpdateCasbin
// @description update casbin authority, 更新casbin权限
// @auth 2020/04/05 20:22
// @param authorityId string
// @param casbinInfos []CasbinInfo
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateCasbin
//@description: 更新casbin权限
//@param: authorityId string, casbinInfos []request.CasbinInfo
//@return: error
func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
ClearCasbin(0, authorityId)
@@ -39,14 +38,11 @@ func UpdateCasbin(authorityId string, casbinInfos []request.CasbinInfo) error {
return nil
}
// @title UpdateCasbinApi
// @description update casbin apis, API更新随动
// @auth 2020/04/05 20:22
// @param oldPath string
// @param newPath string
// @param oldMethod string
// @param newMethod string
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateCasbinApi
//@description: API更新随动
//@param: oldPath string, newPath string, oldMethod string, newMethod string
//@return: error
func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod string) error {
err := global.GVA_DB.Table("casbin_rule").Model(&model.CasbinModel{}).Where("v1 = ? AND v2 = ?", oldPath, oldMethod).Updates(map[string]interface{}{
@@ -56,11 +52,12 @@ func UpdateCasbinApi(oldPath string, newPath string, oldMethod string, newMethod
return err
}
// @title GetPolicyPathByAuthorityId
// @description get policy path by authorityId, 获取权限列表
// @auth 2020/04/05 20:22
// @param authorityId string
// @return []string
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetPolicyPathByAuthorityId
//@description: 获取权限列表
//@param: authorityId string
//@return: pathMaps []request.CasbinInfo
func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinInfo) {
e := Casbin()
@@ -74,12 +71,11 @@ func GetPolicyPathByAuthorityId(authorityId string) (pathMaps []request.CasbinIn
return pathMaps
}
// @title ClearCasbin
// @description 清除匹配的权限
// @auth 2020/04/05 20:22
// @param v int
// @param p string
// @return bool
//@author: [piexlmax](https://github.com/piexlmax)
//@function: ClearCasbin
//@description: 清除匹配的权限
//@param: v int, p ...string
//@return: bool
func ClearCasbin(v int, p ...string) bool {
e := Casbin()
@@ -88,9 +84,10 @@ func ClearCasbin(v int, p ...string) bool {
}
// @title Casbin
// @description store to DB, 持久化到数据库 引入自定义规则
// @auth 2020/04/05 20:22
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Casbin
//@description: 持久化到数据库 引入自定义规则
//@return: *casbin.Enforcer
func Casbin() *casbin.Enforcer {
admin := global.GVA_CONFIG.Mysql
@@ -101,12 +98,11 @@ func Casbin() *casbin.Enforcer {
return e
}
// @title ParamsMatch
// @description customized rule, 自定义规则函数
// @auth 2020/04/05 20:22
// @param fullNameKey1 string
// @param key2 string
// @return bool
//@author: [piexlmax](https://github.com/piexlmax)
//@function: ParamsMatch
//@description: 自定义规则函数
//@param: fullNameKey1 string, key2 string
//@return: bool
func ParamsMatch(fullNameKey1 string, key2 string) bool {
key1 := strings.Split(fullNameKey1, "?")[0]
@@ -114,12 +110,11 @@ func ParamsMatch(fullNameKey1 string, key2 string) bool {
return util.KeyMatch2(key1, key2)
}
// @title ParamsMatchFunc
// @description customized function, 自定义规则函数
// @auth 2020/04/05 20:22
// @param args ...interface{}
// @return interface{}
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: ParamsMatchFunc
//@description: 自定义规则函数
//@param: args ...interface{}
//@return: interface{}, error
func ParamsMatchFunc(args ...interface{}) (interface{}, error) {
name1 := args[0].(string)
+26 -26
View File
@@ -8,11 +8,11 @@ import (
"gorm.io/gorm"
)
// @title CreateSysDictionary
// @description create a SysDictionary
// @param sysDictionary model.SysDictionary
// @auth 2020/04/05 20:22
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteSysDictionary
//@description: 创建字典数据
//@param: sysDictionary model.SysDictionary
//@return: err error
func CreateSysDictionary(sysDictionary model.SysDictionary) (err error) {
if (!errors.Is(global.GVA_DB.First(&model.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) {
@@ -22,22 +22,22 @@ func CreateSysDictionary(sysDictionary model.SysDictionary) (err error) {
return err
}
// @title DeleteSysDictionary
// @description delete a SysDictionary
// @auth 2020/04/05 20:22
// @param sysDictionary model.SysDictionary
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteSysDictionary
//@description: 删除字典数据
//@param: sysDictionary model.SysDictionary
//@return: err error
func DeleteSysDictionary(sysDictionary model.SysDictionary) (err error) {
err = global.GVA_DB.Delete(sysDictionary).Delete(&sysDictionary.SysDictionaryDetails).Error
return err
}
// @title UpdateSysDictionary
// @description update a SysDictionary
// @param sysDictionary *model.SysDictionary
// @auth 2020/04/05 20:22
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateSysDictionary
//@description: 更新字典数据
//@param: sysDictionary *model.SysDictionary
//@return: err error
func UpdateSysDictionary(sysDictionary *model.SysDictionary) (err error) {
var dict model.SysDictionary
@@ -60,23 +60,23 @@ func UpdateSysDictionary(sysDictionary *model.SysDictionary) (err error) {
return err
}
// @title GetSysDictionary
// @description get the info of a SysDictionary
// @auth 2020/04/05 20:22
// @param id uint
// @return error
// @return SysDictionary SysDictionary
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetSysDictionary
//@description: 根据id或者type获取字典单条数据
//@param: Type string, Id uint
//@return: err error, sysDictionary model.SysDictionary
func GetSysDictionary(Type string, Id uint) (err error, sysDictionary model.SysDictionary) {
err = global.GVA_DB.Where("type = ? OR id = ?", Type, Id).Preload("SysDictionaryDetails").First(&sysDictionary).Error
return
}
// @title GetSysDictionaryInfoList
// @description get SysDictionary list by pagination, 分页获取用户列表
// @auth 2020/04/05 20:22
// @param info PageInfo
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: GetSysDictionaryInfoList
//@description: 分页获取字典列表
//@param: info request.SysDictionarySearch
//@return: err error, list interface{}, total int64
func GetSysDictionaryInfoList(info request.SysDictionarySearch) (err error, list interface{}, total int64) {
limit := info.PageSize
+25 -26
View File
@@ -6,56 +6,55 @@ import (
"gin-vue-admin/model/request"
)
// @title CreateSysDictionaryDetail
// @description create a SysDictionaryDetail
// @param sysDictionaryDetail model.SysDictionaryDetail
// @auth 2020/04/05 20:22
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: CreateSysDictionaryDetail
//@description: 创建字典详情数据
//@param: sysDictionaryDetail model.SysDictionaryDetail
//@return: err error
func CreateSysDictionaryDetail(sysDictionaryDetail model.SysDictionaryDetail) (err error) {
err = global.GVA_DB.Create(&sysDictionaryDetail).Error
return err
}
// @title DeleteSysDictionaryDetail
// @description delete a SysDictionaryDetail
// @auth 2020/04/05 20:22
// @param sysDictionaryDetail model.SysDictionaryDetail
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteSysDictionaryDetail
//@description: 删除字典详情数据
//@param: sysDictionaryDetail model.SysDictionaryDetail
//@return: err error
func DeleteSysDictionaryDetail(sysDictionaryDetail model.SysDictionaryDetail) (err error) {
err = global.GVA_DB.Delete(sysDictionaryDetail).Error
return err
}
// @title UpdateSysDictionaryDetail
// @description update a SysDictionaryDetail
// @param sysDictionaryDetail *model.SysDictionaryDetail
// @auth 2020/04/05 20:22
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateSysDictionaryDetail
//@description: 更新字典详情数据
//@param: sysDictionaryDetail *model.SysDictionaryDetail
//@return: err error
func UpdateSysDictionaryDetail(sysDictionaryDetail *model.SysDictionaryDetail) (err error) {
err = global.GVA_DB.Save(sysDictionaryDetail).Error
return err
}
// @title GetSysDictionaryDetail
// @description get the info of a SysDictionaryDetail
// @auth 2020/04/05 20:22
// @param id uint
// @return error
// @return SysDictionaryDetail SysDictionaryDetail
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetSysDictionaryDetail
//@description: 根据id获取字典详情单条数据
//@param: id uint
//@return: err error, sysDictionaryDetail model.SysDictionaryDetail
func GetSysDictionaryDetail(id uint) (err error, sysDictionaryDetail model.SysDictionaryDetail) {
err = global.GVA_DB.Where("id = ?", id).First(&sysDictionaryDetail).Error
return
}
// @title GetSysDictionaryDetailInfoList
// @description get SysDictionaryDetail list by pagination, 分页获取用户列表
// @auth 2020/04/05 20:22
// @param info PageInfo
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetSysDictionaryDetailInfoList
//@description: 分页获取字典详情列表
//@param: info request.SysDictionaryDetailSearch
//@return: err error
func GetSysDictionaryDetailInfoList(info request.SysDictionaryDetailSearch) (err error, list interface{}, total int64) {
limit := info.PageSize
+4 -4
View File
@@ -4,10 +4,10 @@ import (
"gin-vue-admin/utils"
)
// @title EmailTest
// @description 发送邮件测试
// @auth 2020/09/08 13:58
// @return err error
//@author: [maplepie](https://github.com/maplepie)
//@function: EmailTest
//@description: 发送邮件测试
//@return: err error
func EmailTest() (err error) {
subject := "test"
+50 -59
View File
@@ -4,15 +4,16 @@ import (
"errors"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gorm.io/gorm"
"strconv"
)
// @title getMenuTreeMap
// @description 获取路由总树map
// @auth qm (2020/05/06 10:26)
// @return err error
// @return menusMsp map{string}[]SysBaseMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: getMenuTreeMap
//@description: 获取路由总树map
//@param: authorityId string
//@return: err error, treeMap map[string][]model.SysMenu
func getMenuTreeMap(authorityId string) (err error, treeMap map[string][]model.SysMenu) {
var allMenus []model.SysMenu
@@ -24,12 +25,11 @@ func getMenuTreeMap(authorityId string) (err error, treeMap map[string][]model.S
return err, treeMap
}
// @title GetMenuTree
// @description 获取动态菜单树
// @auth 2020/04/05 20:22
// @param authorityId string
// @return err error
// @return menus []model.SysMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetMenuTree
//@description: 获取动态菜单树
//@param: authorityId string
//@return: err error, menus []model.SysMenu
func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) {
err, menuTree := getMenuTreeMap(authorityId)
@@ -40,12 +40,11 @@ func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) {
return err, menus
}
// @title getChildrenList
// @description 获取子菜单
// @auth 2020/04/05 20:22
// @param menu *model.SysMenu
// @param sql string
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: getChildrenList
//@description: 获取子菜单
//@param: menu *model.SysMenu, treeMap map[string][]model.SysMenu
//@return: err error
func getChildrenList(menu *model.SysMenu, treeMap map[string][]model.SysMenu) (err error) {
menu.Children = treeMap[menu.MenuId]
@@ -55,13 +54,10 @@ func getChildrenList(menu *model.SysMenu, treeMap map[string][]model.SysMenu) (e
return err
}
// @title GetInfoList
// @description 获取路由分页
// @auth 2020/04/05 20:22
// @param info request.PageInfo
// @return err error
// @return list interface{}
// @return total int
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetInfoList
//@description: 获取路由分页
//@return: err error, list interface{}, total int64
func GetInfoList() (err error, list interface{}, total int64) {
var menuList []model.SysBaseMenu
@@ -73,11 +69,11 @@ func GetInfoList() (err error, list interface{}, total int64) {
return err, menuList, total
}
// @title getBaseChildrenList
// @description get children of menu, 获取菜单的子菜单
// @auth 2020/04/05 20:22
// @param menu *model.SysBaseMenu
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: getBaseChildrenList
//@description: 获取菜单的子菜单
//@param: menu *model.SysBaseMenu, treeMap map[string][]model.SysBaseMenu
//@return: err error
func getBaseChildrenList(menu *model.SysBaseMenu, treeMap map[string][]model.SysBaseMenu) (err error) {
menu.Children = treeMap[strconv.Itoa(int(menu.ID))]
@@ -87,12 +83,11 @@ func getBaseChildrenList(menu *model.SysBaseMenu, treeMap map[string][]model.Sys
return err
}
// @title AddBaseMenu
// @description 函数的详细描述
// @auth 2020/04/05 20:22
// @param menu *model.SysBaseMenu
// @return err error
// 增加基础路由
//@author: [piexlmax](https://github.com/piexlmax)
//@function: AddBaseMenu
//@description: 添加基础路由
//@param: menu model.SysBaseMenu
//@return: err error
func AddBaseMenu(menu model.SysBaseMenu) (err error) {
if !errors.Is(global.GVA_DB.Where("name = ?", menu.Name).First(&model.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) {
@@ -102,11 +97,10 @@ func AddBaseMenu(menu model.SysBaseMenu) (err error) {
return err
}
// @title getBaseMenuTreeMap
// @description 获取路由总树map
// @auth qm (2020/05/06 10:26)
// @return err error
// @return menusMsp map{string}[]SysBaseMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: getBaseMenuTreeMap
//@description: 获取路由总树map
//@return: err error, treeMap map[string][]model.SysBaseMenu
func getBaseMenuTreeMap() (err error, treeMap map[string][]model.SysBaseMenu) {
var allMenus []model.SysBaseMenu
@@ -118,11 +112,10 @@ func getBaseMenuTreeMap() (err error, treeMap map[string][]model.SysBaseMenu) {
return err, treeMap
}
// @title GetBaseMenuTree
// @description 获取基础路由树
// @auth 2020/04/05 20:22
// @return err error
// @return menus []SysBaseMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetBaseMenuTree
//@description: 获取基础路由树
//@return: err error, menus []model.SysBaseMenu
func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) {
err, treeMap := getBaseMenuTreeMap()
@@ -133,12 +126,11 @@ func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) {
return err, menus
}
// @title AddMenuAuthority
// @description 为角色增加menu树
// @auth 2020/04/05 20:22
// @param menus []model.SysBaseMenu
// @param authorityId string
// @return error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: AddMenuAuthority
//@description: 为角色增加menu树
//@param: menus []model.SysBaseMenu, authorityId string
//@return: err error
func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error) {
var auth model.SysAuthority
@@ -148,16 +140,15 @@ func AddMenuAuthority(menus []model.SysBaseMenu, authorityId string) (err error)
return err
}
// @title GetMenuAuthority
// @description 查看当前角色树
// @auth 2020/04/05 20:22
// @param authorityId string
// @return err error
// @return menus []SysBaseMenu
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetMenuAuthority
//@description: 查看当前角色树
//@param: info *request.GetAuthorityId
//@return: err error, menus []model.SysMenu
func GetMenuAuthority(authorityId string) (err error, menus []model.SysMenu) {
func GetMenuAuthority(info *request.GetAuthorityId) (err error, menus []model.SysMenu) {
err = global.GVA_DB.Where("authority_id = ? ", info.AuthorityId).Order("sort").Find(&menus).Error
//sql := "SELECT authority_menu.keep_alive,authority_menu.default_menu,authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? ORDER BY authority_menu.sort ASC"
err = global.GVA_DB.Where("authority_id = ? ", authorityId).Order("sort").Find(&menus).Error
//err = global.GVA_DB.Raw(sql, authorityId).Scan(&menus).Error
return err, menus
}
+27 -26
View File
@@ -6,56 +6,57 @@ import (
"gin-vue-admin/model/request"
)
// @title CreateSysOperationRecord
// @description create a SysOperationRecord
// @param sysOperationRecord model.SysOperationRecord
// @auth 2020/04/05 20:22
// @return err error
//@author: [granty1](https://github.com/granty1)
//@function: CreateSysOperationRecord
//@description: 创建记录
//@param: sysOperationRecord model.SysOperationRecord
//@return: err error
func CreateSysOperationRecord(sysOperationRecord model.SysOperationRecord) (err error) {
err = global.GVA_DB.Create(&sysOperationRecord).Error
return err
}
// @title DeleteSysOperationRecord
// @description delete SysOperationRecords
// @auth 2020/04/05 20:22
// @param sysOperationRecord request.IdsReq
// @return error
//@author: [granty1](https://github.com/granty1)
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteSysOperationRecordByIds
//@description: 批量删除记录
//@param: ids request.IdsReq
//@return: err error
func DeleteSysOperationRecordByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]model.SysOperationRecord{}, "id in (?)", ids.Ids).Error
return err
}
// @title DeleteSysOperationRecord
// @description delete a SysOperationRecord
// @auth 2020/04/05 20:22
// @param sysOperationRecord model.SysOperationRecord
// @return error
//@author: [granty1](https://github.com/granty1)
//@function: DeleteSysOperationRecord
//@description: 删除操作记录
//@param: sysOperationRecord model.SysOperationRecord
//@return: err error
func DeleteSysOperationRecord(sysOperationRecord model.SysOperationRecord) (err error) {
err = global.GVA_DB.Delete(sysOperationRecord).Error
return err
}
// @title GetSysOperationRecord
// @description get the info of a SysOperationRecord
// @auth 2020/04/05 20:22
// @param id uint
// @return error
// @return SysOperationRecord SysOperationRecord
//@author: [granty1](https://github.com/granty1)
//@function: DeleteSysOperationRecord
//@description: 根据id获取单条操作记录
//@param: id uint
//@return: err error, sysOperationRecord model.SysOperationRecord
func GetSysOperationRecord(id uint) (err error, sysOperationRecord model.SysOperationRecord) {
err = global.GVA_DB.Where("id = ?", id).First(&sysOperationRecord).Error
return
}
// @title GetSysOperationRecordInfoList
// @description get SysOperationRecord list by pagination, 分页获取用户列表
// @auth 2020/04/05 20:22
// @param info PageInfo
// @return error
//@author: [granty1](https://github.com/granty1)
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetSysOperationRecordInfoList
//@description: 分页获取操作记录列表
//@param: info request.SysOperationRecordSearch
//@return: err error, list interface{}, total int64
func GetSysOperationRecordInfoList(info request.SysOperationRecordSearch) (err error, list interface{}, total int64) {
limit := info.PageSize
+14 -16
View File
@@ -8,21 +8,21 @@ import (
"go.uber.org/zap"
)
// @title GetSystemConfig
// @description 读取配置文件
// @auth 2020/04/05 20:22
// @return err error
// @return conf Server
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetSystemConfig
//@description: 读取配置文件
//@return: err error, conf config.Server
func GetSystemConfig() (err error, conf config.Server) {
return nil, global.GVA_CONFIG
}
// @title SetSystemConfig
// @description set system config, 设置配置文件
// @auth 2020/04/05 20:22
// @param system model.System
// @return err error
// @description set system config,
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetSystemConfig
//@description: 设置配置文件
//@param: system model.System
//@return: err error
func SetSystemConfig(system model.System) (err error) {
cs := utils.StructToMap(system.Config)
@@ -33,12 +33,10 @@ func SetSystemConfig(system model.System) (err error) {
return err
}
// @title GetServerInfo
// @description get server info , 获取服务器信息
// @auth 2020/04/05 20:22
// @return server *utils.Server
// @return err error
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: GetServerInfo
//@description: 获取服务器信息
//@return: server *utils.Server, err error
func GetServerInfo() (server *utils.Server, err error) {
var s utils.Server
+46 -56
View File
@@ -10,12 +10,12 @@ import (
"gorm.io/gorm"
)
// @title Register
// @description register, 用户注册
// @auth 2020/04/05 20:22
// @param u model.SysUser
// @return err error
// @return userInter *SysUser
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Register
//@description: 用户注册
//@param: u model.SysUser
//@return: err error, userInter model.SysUser
func Register(u model.SysUser) (err error, userInter model.SysUser) {
var user model.SysUser
@@ -29,12 +29,11 @@ func Register(u model.SysUser) (err error, userInter model.SysUser) {
return err, u
}
// @title Login
// @description login, 用户登录
// @auth 2020/04/05 20:22
// @param u *model.SysUser
// @return err error
// @return userInter *SysUser
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Login
//@description: 用户登录
//@param: u *model.SysUser
//@return: err error, userInter *model.SysUser
func Login(u *model.SysUser) (err error, userInter *model.SysUser) {
var user model.SysUser
@@ -43,13 +42,11 @@ func Login(u *model.SysUser) (err error, userInter *model.SysUser) {
return err, &user
}
// @title ChangePassword
// @description change the password of a certain user, 修改用户密码
// @auth 2020/04/05 20:22
// @param u *model.SysUser
// @param newPassword string
// @return err error
// @return userInter *SysUser
//@author: [piexlmax](https://github.com/piexlmax)
//@function: ChangePassword
//@description: 修改用户密码
//@param: u *model.SysUser, newPassword string
//@return: err error, userInter *model.SysUser
func ChangePassword(u *model.SysUser, newPassword string) (err error, userInter *model.SysUser) {
var user model.SysUser
@@ -58,13 +55,11 @@ func ChangePassword(u *model.SysUser, newPassword string) (err error, userInter
return err, u
}
// @title GetInfoList
// @description get user list by pagination, 分页获取数据
// @auth 2020/04/05 20:22
// @param info request.PageInfo
// @return err error
// @return list interface{}
// @return total int
//@author: [piexlmax](https://github.com/piexlmax)
//@function: GetUserInfoList
//@description: 分页获取数据
//@param: info request.PageInfo
//@return: err error, list interface{}, total int64
func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total int64) {
limit := info.PageSize
@@ -76,24 +71,22 @@ func GetUserInfoList(info request.PageInfo) (err error, list interface{}, total
return err, userList, total
}
// @title SetUserAuthority
// @description set the authority of a certain user, 设置一个用户的权限
// @auth 2020/04/05 20:22
// @param uuid UUID
// @param authorityId string
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetUserAuthority
//@description: 设置一个用户的权限
//@param: uuid uuid.UUID, authorityId string
//@return: err error
func SetUserAuthority(uuid uuid.UUID, authorityId string) (err error) {
err = global.GVA_DB.Where("uuid = ?", uuid).First(&model.SysUser{}).Update("authority_id", authorityId).Error
return err
}
// @title SetUserAuthority
// @description set the authority of a certain user, 设置一个用户的权限
// @auth 2020/04/05 20:22
// @param uuid UUID
// @param authorityId string
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteUser
//@description: 删除用户
//@param: id float64
//@return: err error
func DeleteUser(id float64) (err error) {
var user model.SysUser
@@ -101,24 +94,22 @@ func DeleteUser(id float64) (err error) {
return err
}
// @title SetUserInfo
// @description set the authority of a certain user, 设置用户信息
// @auth 2020/04/05 20:22
// @param uuid UUID
// @param authorityId string
// @return err error
//@author: [piexlmax](https://github.com/piexlmax)
//@function: SetUserInfo
//@description: 设置用户信息
//@param: reqUser model.SysUser
//@return: err error, user model.SysUser
func SetUserInfo(reqUser model.SysUser) (err error, user model.SysUser) {
err = global.GVA_DB.Updates(&reqUser).Error
return err, reqUser
}
// @title FindUserById
// @description Get user information by id, 通过id获取用户信息
// @auth 2020/04/05 20:22
// @param id int
// @return err error
// @return user *model.SysUser
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: FindUserById
//@description: 通过id获取用户信息
//@param: id int
//@return: err error, user *model.SysUser
func FindUserById(id int) (err error, user *model.SysUser) {
var u model.SysUser
@@ -126,12 +117,11 @@ func FindUserById(id int) (err error, user *model.SysUser) {
return err, &u
}
// @title FindUserByUuid
// @description Get user information by uuid, 通过uuid获取用户信息
// @auth 2020/04/05 20:22
// @param uuid string
// @return err error
// @return user *model.SysUser
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: FindUserByUuid
//@description: 通过uuid获取用户信息
//@param: uuid string
//@return: err error, user *model.SysUser
func FindUserByUuid(uuid string) (err error, user *model.SysUser) {
var u model.SysUser
+17
View File
@@ -0,0 +1,17 @@
package service
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
)
//@author: [piexlmax](https://github.com/piexlmax)
//@function: Create
//@description: 创建工作流
//@param: wk model.SysWorkflow
//@return: error
func Create(wk model.SysWorkflow) error {
err := global.GVA_DB.Create(&wk).Error
return err
}
+38
View File
@@ -0,0 +1,38 @@
package utils
import (
"os"
"path/filepath"
)
// FileMove: 文件移动供外部调用
// src: 源位置 绝对路径相对路径都可以
// dst: 目标位置 绝对路径相对路径都可以 dst 必须为文件夹
func FileMove(src string, dst string) (err error) {
if dst == "" {
return nil
}
src, err = filepath.Abs(src)
if err != nil {
return err
}
dst, err = filepath.Abs(dst)
if err != nil {
return err
}
var revoke = false
dir := filepath.Dir(dst)
Redirect:
_, err = os.Stat(dir)
if err != nil {
err = os.MkdirAll(dir, 0755)
if err != nil {
return err
}
if !revoke {
revoke = true
goto Redirect
}
}
return os.Rename(src, dst)
}
+21
View File
@@ -0,0 +1,21 @@
package utils
var (
IdVerify = Rules{"ID": {NotEmpty()}}
ApiVerify = Rules{"Path": {NotEmpty()}, "Description": {NotEmpty()}, "ApiGroup": {NotEmpty()}, "Method": {NotEmpty()}}
MenuVerify = Rules{"Path": {NotEmpty()}, "ParentId": {NotEmpty()}, "Name": {NotEmpty()}, "Component": {NotEmpty()}, "Sort": {Ge("0")}}
MenuMetaVerify = Rules{"Title": {NotEmpty()}}
LoginVerify = Rules{"CaptchaId": {NotEmpty()}, "Captcha": {NotEmpty()}, "Username": {NotEmpty()}, "Password": {NotEmpty()}}
SetUserVerify = Rules{"ID": {NotEmpty()}, "Username": {NotEmpty()}, "NickName": {NotEmpty()}, "HeaderImg": {NotEmpty()}}
RegisterVerify = Rules{"Username": {NotEmpty()}, "NickName": {NotEmpty()}, "Password": {NotEmpty()}, "AuthorityId": {NotEmpty()}}
PageInfoVerify = Rules{"Page": {NotEmpty()}, "PageSize": {NotEmpty()}}
CustomerVerify = Rules{"CustomerName": {NotEmpty()}, "CustomerPhoneData": {NotEmpty()}}
AutoCodeVerify = Rules{"Abbreviation": {NotEmpty()}, "StructName": {NotEmpty()}, "PackageName": {NotEmpty()}, "Fields": {NotEmpty()}}
WorkFlowVerify = Rules{"WorkflowNickName": {NotEmpty()}, "WorkflowName": {NotEmpty()}, "WorkflowDescription": {NotEmpty()}, "WorkflowStepInfo": {NotEmpty()}}
AuthorityVerify = Rules{"AuthorityId": {NotEmpty()}, "AuthorityName": {NotEmpty()}, "ParentId": {NotEmpty()}}
DictionaryVerify = Rules{"Type": {NotEmpty()}, "ID": {NotEmpty()}}
AuthorityIdVerify = Rules{"AuthorityId": {NotEmpty()}}
OldAuthorityVerify = Rules{"OldAuthorityId": {NotEmpty()}}
ChangePasswordVerify = Rules{"Username": {NotEmpty()}, "Password": {NotEmpty()}, "NewPassword": {NotEmpty()}}
SetUserAuthorityVerify = Rules{"UUID": {NotEmpty()}, "AuthorityId": {NotEmpty()}}
)
+657 -404
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -74,4 +74,4 @@
"> 1%",
"last 2 versions"
]
}
}
+3 -3
View File
@@ -58,10 +58,10 @@ export const getTable = (params) => {
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
// @Router /autoCode/getColume [get]
export const getColume = (params) => {
// @Router /autoCode/getColumn [get]
export const getColumn = (params) => {
return service({
url: "/autoCode/getColume",
url: "/autoCode/getColumn",
method: 'get',
params,
})
+2 -1
View File
@@ -66,7 +66,8 @@ Vue.prototype.$echarts = echarts;
console.log(`
欢迎使用 Gin-Vue-Admin
当前版本:V2.3.4
当前版本:V2.3.6
默认自动化文档地址:http://127.0.0.1%s/swagger/index.html
默认前端文件运行地址:http://127.0.0.1:8080
如果项目让您获得了收益希望您能请团队喝杯可乐:https://www.gin-vue-admin.com/docs/coffee
`)
+24
View File
@@ -0,0 +1,24 @@
// basice
$font-size: 14px;
$icon-size:17px;
$active-color:#1890ff;
$bg-main:#f0f2f5;
$border-color: #f4f4f4;
// aside
$color-aside:rgba(255, 255, 255,.9);
$icon-arrow-size-aside:12px;
$width-submenu-aside:55px;
$bg-aside:#191a23;
// header
$height-header: 60px;
// nav-scroll
$height-nav-scroll:40px;
$active-bg-tabs-item-nav-scroll:#409eff;
$bg-tabs-item-nav-scroll:#ddd;
// table
$bg-color-table-thead:#fafafa;
$border-color-table:#ededed;
$height-table-cell:45px;
$color-table-tbody:#595959;
$color-table-thead:#262626;
+134
View File
@@ -0,0 +1,134 @@
.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;
background: #ccc;
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 {
position: relative;
overflow: auto;
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%;
padding: 0 20px;
margin: 40px 0 10px;
text-align: center;
.links {
margin-bottom: 8px;
font-size: 14px;
width: 330px;
display: inline-flex;
flex-direction: row;
justify-content: space-between;
padding-right: 40px;
a {
color: rgba(0, 0, 0, 0.45);
transition: all 0.3s;
}
}
.copyright {
color: rgba(0, 0, 0, 0.45);
font-size: 14px;
padding-right: 40px;
}
}
}
}
+371 -59
View File
@@ -7,6 +7,7 @@
* 2. Prevent adjustments of font size after orientation changes in iOS.
*/
@import '@/style/basics.scss';
html {
line-height: 1.15;
/* 1 */
@@ -531,31 +532,30 @@ li {
list-style-type: none;
}
.el-table__body-wrapper {
tr {
td {
.cell {
.el-button+.el-button {
margin-left: 0;
}
}
}
}
}
// .el-table__body-wrapper {
// tr {
// td {
// .cell {
// .el-button+.el-button {
// margin-left: 0;
// }
// }
// }
// }
// }
// navbar
.aside {
.el-scrollbar {
.el-scrollbar__view {
.el-menu-vertical {
background-color: #001529;
background-color: $bg-aside;
}
.el-menu-item:hover i,
.el-menu-item:hover span {
color: #fff;
}
li {
background-color: #001529;
background-color: $bg-aside;
ul {
.el-menu-item {
background-color: #000408;
@@ -568,7 +568,7 @@ li {
}
}
.el-submenu__title:hover {
background-color: #001529;
background-color: $bg-aside;
}
.el-submenu__title:hover i,
.el-submenu__title:hover span {
@@ -589,10 +589,6 @@ li {
background-color: #ecf0f5;
padding: 0;
}
.breadcrumb {
background-color: #fff;
padding: 0 0 15px 15px;
}
}
}
@@ -742,7 +738,7 @@ li {
-webkit-transition: width .2s;
transition: width .2s;
width: 220px;
background-color: #304156;
background-color: $bg-aside;
height: 100%;
position: fixed;
font-size: 0;
@@ -815,22 +811,14 @@ li {
}
}
.el-menu .el-menu--inline {
background: #2c3b41;
}
.el-submenu .el-submenu {
background-color: #000408 !important;
}
// .el-menu .el-menu--inline {
// background: #2c3b41;
// }
// .el-submenu .el-submenu {
// background-color: #000408 !important;
// }
.aside .el-scrollbar .el-scrollbar__view .el-submenu__title:hover {
background-color: #000408 !important;
}
.el-submenu {
.aside .el-scrollbar .el-scrollbar__view .el-submenu__title:hover {
background-color: #000408 !important;
}
background-color: $bg-aside !important;
}
.el-menu--vertical {
@@ -852,8 +840,8 @@ li {
// add 5.13
.el-container {
.admin-box {
padding: 24px 24px 40px 24px;
margin: 115px 24px 24px 24px;
padding: 15px;
margin: 115px 15px 20px;
border-radius: 2px;
.button-box {
border: none;
@@ -863,12 +851,10 @@ li {
border-radius: 4px;
margin-bottom: 15px;
}
.el-table--border {
th {
border-left: 1px solid #e8e8e8;
}
}
.el-table {
thead {
color: $color-table-thead;
}
th {
padding: 5px 0;
.cell {
@@ -927,17 +913,17 @@ li {
}
.el-container.layout-cont {
.header-cont,
.breadcrumb {
height: 40px !important;
line-height: 40px !important;
}
// .header-cont,
// .breadcrumb {
// height: 40px !important;
// line-height: 40px !important;
// }
.main-cont.el-main {
background-color: #f0f2f5;
background-color: $bg-main;
.menu-total {
font-size: 22px;
color: #838383;
margin-top: 7px;
margin-top: 16px;
}
// background-color: #f0f2f5;
}
@@ -946,15 +932,37 @@ li {
.el-container.layout-cont {
.main-cont {
.router-history {
padding-bottom: 8px;
padding-top: 5px;
border-color: #f9f9f9;
box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
// box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
background: #fff;
padding: 0 6px;
border-top: 1px solid $border-color;
padding: 0;
.el-tabs__header {
margin: 0px 0 0 0;
.el-tabs__item {
line-height: 35px;
height: 35px;
height: $height-nav-scroll;
height: $height-nav-scroll;
border: none;
border-left: 1px solid $border-color;
}
.el-tabs__item::before {
content: "";
width: 9px;
height: 9px;
margin-right: 8px;
display: inline-block;
background-color: #ddd;
border-radius: 50%;
transition: background-color .2s;
}
.el-tabs__item.is-active::before {
background-color: #409eff;
}
.el-tabs__item.is-active {
background-color: rgba(64, 158, 255, .08);
}
.el-tabs__nav {
border: none;
}
}
}
@@ -1014,7 +1022,8 @@ li {
}
}
.el-input-number__decrease, .el-input-number__increase{
.el-input-number__decrease,
.el-input-number__increase {
position: absolute;
z-index: 1;
top: 6px !important;
@@ -1028,7 +1037,310 @@ li {
font-size: 13px;
}
.table-button {
margin-right: 8px !important;
}
.table-button{
margin-right:8px !important;
}
$headerHigh: 52px;
$mainHight: 100vh;
.dropdown-group {
min-width: 100px;
}
.topfix {
position: fixed;
top: 0;
box-sizing: border-box;
z-index: 999;
}
.admin-box {
min-height: calc(100vh - 200px);
background-color: rgb(255, 255, 255);
margin-top: 100px;
}
.el-scrollbar__wrap {
padding-bottom: 17px;
}
.layout-cont {
.right-box {
height: $height-header;
line-height: $height-header;
text-align: center;
vertical-align: middle;
margin-right: 40px;
img {
vertical-align: middle;
border: 1px solid #ccc;
border-radius: 6px;
}
}
.header-cont {
height: $height-header;
background: #fff;
}
.main-cont {
.breadcrumb {
height: $height-header;
line-height: $height-header;
display: inline-block;
background-color: #fff;
padding: 0 24px;
}
.fl-right {
// height: $height-header;
// line-height: $height-header;
}
&.el-main {
overflow: auto;
background: #fff;
}
height: $mainHight !important;
overflow: visible;
position: relative;
.menu-total {
float: left;
margin-top: 10px;
width: 30px;
height: 30px;
line-height: 30px;
font-size: 30px;
}
.aside {
overflow: auto;
// background: #fff;
&::-webkit-scrollbar {
display: none;
}
}
.el-menu-vertical {
height: calc(100vh - 64px) !important;
visibility: auto;
&:not(.el-menu--collapse) {
width: 220px;
}
}
.el-menu--collapse {
width: 54px;
li {
.el-tooltip,
.el-submenu__title {
padding: 0px 15px !important;
}
}
}
&::-webkit-scrollbar {
display: none;
}
&.main-left {
width: auto !important;
}
&.main-right {
.admin-title {
float: left;
font-size: 16px;
vertical-align: middle;
margin-left: 20px;
img {
vertical-align: middle;
}
&.collapse {
width: 53px;
}
}
}
}
}
.tilte {
min-height: 64px;
line-height: 64px;
background: $bg-aside;
text-align: center;
.logoimg {
width: 30px;
height: 30px;
vertical-align: middle;
background: #fff;
border-radius: 50%;
padding: 3px;
}
.tit-text {
display: inline-block;
color: #fff;
font-weight: 600;
font-size: 20px;
vertical-align: middle;
padding-left: 10px;
}
}
.screenfull {
display: inline-block;
}
.header-avatar {
display: flex;
justify-content: center;
align-items: center;
}
.search-component {
display: inline-block;
overflow: hidden;
height: 60px;
width: 120px;
text-align: center;
.el-input__inner {
border: none;
border-bottom: 1px solid #606266;
}
.el-dropdown-link {
cursor: pointer;
}
.search-icon {
font-size: $icon-size;
margin-right: 14px;
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
color: #606266;
}
.dropdown-group {
min-width: 100px;
}
}
.transition-box {
overflow: hidden;
width: 120px;
text-align: center;
}
.screenfull {
overflow: hidden;
width: 40px;
text-align: center;
}
.el-dropdown {
overflow: hidden;
height: 60px;
}
.card {
background-color: #fff;
padding: 20px;
border-radius: 4px;
overflow: hidden;
.car-left {
height: 68px;
width: 70%;
float: left;
}
.car-right {
height: 68px;
width: 29%;
float: left;
.flow,
.user-number,
.feedback {
width: 24px;
height: 24px;
display: inline-block;
border-radius: 50%;
line-height: 24px;
text-align: center;
font-size: 13px;
margin-right: 5px;
}
.flow {
background-color: #fff7e8;
border-color: #feefd0;
color: #faad14;
}
.user-number {
background-color: #ecf5ff;
border-color: #d9ecff;
color: #409eff;
}
.feedback {
background-color: #eef9e8;
border-color: #dcf3d1;
color: #52c41a;
}
.car-item {
text-align: right;
b {
display: block;
}
}
}
.card-img {
width: 68px;
height: 68px;
display: inline-block;
float: left;
overflow: hidden;
img {
width: 100%;
height: 100%;
border-radius: 50%;
}
}
.text {
height: 68px;
margin-left: 10px;
float: left;
margin-top: 14px;
h4 {
font-size: 20px;
color: #262626;
font-weight: 500;
white-space: nowrap;
word-break: break-all;
text-overflow: ellipsis;
}
.tips-text {
color: #8c8c8c;
margin-top: 8px;
}
}
}
.shadow {
margin: 5px 0;
.grid-content {
background-color: #fff;
border-radius: 4px;
text-align: center;
padding: 10px 0;
cursor: pointer;
.el-icon {
width: 30px;
height: 30px;
font-size: 30px;
margin-bottom: 8px;
}
}
}::-webkit-scrollbar-track-piece{
background-color: #f8f8f8;
}
::-webkit-scrollbar{
width: 9px;
height: 9px;
}
::-webkit-scrollbar-thumb{
background-color: #dddddd;
background-clip:padding-box;
min-height: 28px;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover{
background-color: #bbb;
}
+2 -2
View File
@@ -68,12 +68,12 @@ service.interceptors.response.use(
Message({
showClose: true,
message: response.data.msg || decodeURI(response.headers.msg),
type: 'error',
type: response.headers.msgtype||'error',
})
if (response.data.data && response.data.data.reload) {
store.commit('user/LoginOut')
}
return response.data.msg
return response.data.msg ? response.data : response
}
},
error => {
@@ -1,120 +0,0 @@
<template>
<div :class="className" :style="{height:height,width:width}" />
</template>
<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
const animationDuration = 3000
export default {
name:'RaddarChart',
props: {
className: {
type: String,
default: 'chart'
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '300px'
}
},
data() {
return {
chart: null
}
},
mounted() {
this.initChart()
/* this.__resizeHandler = debounce(() => {
if (this.chart) {
this.chart.resize()
}
}, 100)
window.addEventListener('resize', this.__resizeHandler)*/
},
beforeDestroy() {
if (!this.chart) {
return
}
// window.removeEventListener('resize', this.__resizeHandler)
this.chart.dispose()
this.chart = null
},
methods: {
initChart() {
this.chart = echarts.init(this.$el, 'light')
this.chart.setOption({
tooltip: {
trigger: 'axis',
axisPointer: { //
type: 'shadow' // 线'line' | 'shadow'
}
},
radar: {
radius: '66%',
center: ['50%', '42%'],
splitNumber: 8,
splitArea: {
areaStyle: {
color: 'rgba(255,192,203,.3)',
opacity: 1,
shadowBlur: 45,
shadowColor: 'rgba(0,0,0,.5)',
shadowOffsetX: 0,
shadowOffsetY: 15
}
},
indicator: [
{ name: 'Sales', max: 10000 },
{ name: 'Administration', max: 20000 },
{ name: 'Information Techology', max: 20000 },
{ name: 'Customer Support', max: 20000 },
{ name: 'Development', max: 20000 },
{ name: 'Marketing', max: 20000 }
]
},
legend: {
left: 'center',
bottom: '10',
data: ['Allocated Budget', 'Expected Spending', 'Actual Spending']
},
series: [{
type: 'radar',
symbolSize: 0,
areaStyle: {
normal: {
shadowBlur: 13,
shadowColor: 'rgba(0,0,0,.2)',
shadowOffsetX: 0,
shadowOffsetY: 10,
opacity: 1
}
},
data: [
{
value: [5000, 7000, 12000, 11000, 15000, 14000],
name: 'Allocated Budget'
},
{
value: [4000, 9000, 15000, 15000, 13000, 11000],
name: 'Expected Spending'
},
{
value: [5500, 11000, 12000, 15000, 12000, 12000],
name: 'Actual Spending'
}
],
animationDuration: animationDuration
}]
})
}
}
}
</script>
@@ -1,391 +0,0 @@
<template>
<div :class="className" :style="{height:height,width:width}" />
</template>
<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
const animationDuration = 3000
export default {
name: "Sunburst",
props: {
className: {
type: String,
default: 'chart'
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '300px'
}
},
data() {
return {
chart: null,
datas:[
{
name: 'Flora',
itemStyle: {
color: '#da0d68'
},
children: [{
name: 'Black Tea',
value: 1,
itemStyle: {
color: '#975e6d'
}
}, {
name: 'Floral',
itemStyle: {
color: '#e0719c'
},
children: [{
name: 'Chamomile',
value: 1,
itemStyle: {
color: '#f99e1c'
}
}, {
name: 'Rose',
value: 1,
itemStyle: {
color: '#ef5a78'
}
}, {
name: 'Jasmine',
value: 1,
itemStyle: {
color: '#f7f1bd'
}
}]
}]
},
{
name: 'Fruity',
itemStyle: {
color: '#da1d23'
},
children: [{
name: 'Berry',
itemStyle: {
color: '#dd4c51'
},
children: [{
name: 'Blackberry',
value: 1,
itemStyle: {
color: '#3e0317'
}
}, {
name: 'Raspberry',
value: 1,
itemStyle: {
color: '#e62969'
}
}, {
name: 'Blueberry',
value: 1,
itemStyle: {
color: '#6569b0'
}
}, {
name: 'Strawberry',
value: 1,
itemStyle: {
color: '#ef2d36'
}
}]
}, {
name: 'Dried Fruit',
itemStyle: {
color: '#c94a44'
},
children: [{
name: 'Raisin',
value: 1,
itemStyle: {
color: '#b53b54'
}
}, {
name: 'Prune',
value: 1,
itemStyle: {
color: '#a5446f'
}
}]
}, {
name: 'Other Fruit',
itemStyle: {
color: '#dd4c51'
},
children: [{
name: 'Coconut',
value: 1,
itemStyle: {
color: '#f2684b'
}
}, {
name: 'Cherry',
value: 1,
itemStyle: {
color: '#e73451'
}
}, {
name: 'Pomegranate',
value: 1,
itemStyle: {
color: '#e65656'
}
}, {
name: 'Pineapple',
value: 1,
itemStyle: {
color: '#f89a1c'
}
}, {
name: 'Grape',
value: 1,
itemStyle: {
color: '#aeb92c'
}
}, {
name: 'Apple',
value: 1,
itemStyle: {
color: '#4eb849'
}
}, {
name: 'Peach',
value: 1,
itemStyle: {
color: '#f68a5c'
}
}, {
name: 'Pear',
value: 1,
itemStyle: {
color: '#baa635'
}
}]
}, {
name: 'Citrus Fruit',
itemStyle: {
color: '#f7a128'
},
children: [{
name: 'Grapefruit',
value: 1,
itemStyle: {
color: '#f26355'
}
}, {
name: 'Orange',
value: 1,
itemStyle: {
color: '#e2631e'
}
}, {
name: 'Lemon',
value: 1,
itemStyle: {
color: '#fde404'
}
}, {
name: 'Lime',
value: 1,
itemStyle: {
color: '#7eb138'
}
}]
}]
},
{
name: 'Other',
itemStyle: {
color: '#0aa3b5'
},
children: [{
name: 'Papery/Musty',
itemStyle: {
color: '#9db2b7'
},
children: [{
name: 'Stale',
value: 1,
itemStyle: {
color: '#8b8c90'
}
}, {
name: 'Cardboard',
value: 1,
itemStyle: {
color: '#beb276'
}
}, {
name: 'Papery',
value: 1,
itemStyle: {
color: '#fefef4'
}
}, {
name: 'Woody',
value: 1,
itemStyle: {
color: '#744e03'
}
}, {
name: 'Moldy/Damp',
value: 1,
itemStyle: {
color: '#a3a36f'
}
}, {
name: 'Musty/Dusty',
value: 1,
itemStyle: {
color: '#c9b583'
}
}, {
name: 'Musty/Earthy',
value: 1,
itemStyle: {
color: '#978847'
}
}, {
name: 'Animalic',
value: 1,
itemStyle: {
color: '#9d977f'
}
}, {
name: 'Meaty Brothy',
value: 1,
itemStyle: {
color: '#cc7b6a'
}
}, {
name: 'Phenolic',
value: 1,
itemStyle: {
color: '#db646a'
}
}]
}, {
name: 'Chemical',
itemStyle: {
color: '#76c0cb'
},
children: [{
name: 'Bitter',
value: 1,
itemStyle: {
color: '#80a89d'
}
}, {
name: 'Salty',
value: 1,
itemStyle: {
color: '#def2fd'
}
}, {
name: 'Medicinal',
value: 1,
itemStyle: {
color: '#7a9bae'
}
}, {
name: 'Petroleum',
value: 1,
itemStyle: {
color: '#039fb8'
}
}, {
name: 'Skunky',
value: 1,
itemStyle: {
color: '#5e777b'
}
}, {
name: 'Rubber',
value: 1,
itemStyle: {
color: '#120c0c'
}
}]
}]
},
]
}
},
mounted() {
this.initChart()
/* this.__resizeHandler = debounce(() => {
if (this.chart) {
this.chart.resize()
}
}, 100)
window.addEventListener('resize', this.__resizeHandler)*/
},
beforeDestroy() {
if (!this.chart) {
return
}
// window.removeEventListener('resize', this.__resizeHandler)
this.chart.dispose()
this.chart = null
},
methods: {
initChart() {
this.chart = echarts.init(this.$el, 'macarons')
this.chart.setOption({
series: {
type: 'sunburst',
highlightPolicy: 'ancestor',
data: this.datas,
radius: [0, '95%'],
sort: null,
levels: [{}, {
r0: '15%',
r: '35%',
itemStyle: {
borderWidth: 2
},
label: {
rotate: 'tangential'
}
}, {
r0: '35%',
r: '70%',
label: {
align: 'right'
}
}, {
r0: '70%',
r: '72%',
label: {
position: 'outside',
padding: 3,
silent: false
},
itemStyle: {
borderWidth: 3
}
}]
},
animationDuration: animationDuration
})
}
}
}
</script>
<style scoped>
</style>
@@ -1,93 +0,0 @@
<template>
<div class="container">
<ul class="moon">
<li class="crater"></li>
<li class="crater"></li>
<li class="crater"></li>
</ul>
<ul class="mountain-range">
<li class="mountain"></li>
<li class="mountain"></li>
<li class="mountain"></li>
<li class="mountain"></li>
<li class="mountain"></li>
<li class="mountain"></li>
<li class="mountain"></li>
<li class="mountain"></li>
<li class="mountain"></li>
<li class="mountain"></li>
<li class="mountain"></li>
</ul>
<div class="mountain-range-mask"></div>
<ul class="forest">
<li class="hill"></li>
<li class="hill"></li>
<li class="hill"></li>
</ul>
<ul class="sparkles">
<li class="sparkle one"></li>
<li class="sparkle one"></li>
<li class="sparkle one"></li>
<li class="sparkle one"></li>
<li class="sparkle two"></li>
<li class="sparkle two"></li>
<li class="sparkle two"></li>
<li class="sparkle two"></li>
<li class="sparkle three"></li>
<li class="sparkle three"></li>
<li class="sparkle three"></li>
<li class="sparkle three"></li>
<li class="sparkle four"></li>
<li class="sparkle four"></li>
<li class="sparkle four"></li>
<li class="sparkle four"></li>
<li class="sparkle five"></li>
<li class="sparkle five"></li>
<li class="sparkle five"></li>
<li class="sparkle five"></li>
<li class="sparkle six"></li>
<li class="sparkle six"></li>
<li class="sparkle six"></li>
<li class="sparkle six"></li>
<li class="sparkle seven"></li>
<li class="sparkle seven"></li>
<li class="sparkle seven"></li>
<li class="sparkle seven"></li>
<li class="sparkle eight"></li>
<li class="sparkle eight"></li>
<li class="sparkle eight"></li>
<li class="sparkle eight"></li>
</ul>
<div class="grass">
<div class="pokemon">
<div class="poke" id="bulbasaur">
<div class="ear"></div>
<div class="ear"></div>
<div class="head"></div>
<div class="leg"></div>
<div class="bulba-body"></div>
<div class="bulbs">
<div class="bulb"></div>
</div>
</div>
<div class="poke" id="pikachu">
<div class="ear"></div>
<div class="ear"></div>
<div class="hand"></div>
<div class="pika-body"></div>
<div class="head"></div>
<div class="pika-tail"></div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'Animition'
}
</script>
<style lang="scss">
@import '@/style/animition.scss';
</style>
@@ -1,167 +0,0 @@
<template>
<div :class="className" :style="{height:height,width:width}" />
</template>
<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
const animationDuration = 3000
export default {
name: "stackMap",
props: {
className: {
type: String,
default: 'chart'
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '300px'
}
},
data() {
return {
chart: null
}
},
mounted() {
this.initChart()
/* this.__resizeHandler = debounce(() => {
if (this.chart) {
this.chart.resize()
}
}, 100)
window.addEventListener('resize', this.__resizeHandler)*/
},
beforeDestroy() {
if (!this.chart) {
return
}
// window.removeEventListener('resize', this.__resizeHandler)
this.chart.dispose()
this.chart = null
},
methods: {
initChart() {
this.chart = echarts.init(this.$el, 'light')
this.chart.setOption({
tooltip: {
trigger: 'axis',
axisPointer: { //
type: 'shadow' // 线'line' | 'shadow'
}
},
legend: {
data: ['Javascript', 'Java', 'Python', 'Ruby', 'PHP']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: {
type: 'value',
axisLabel: {
show: true,
textStyle: {
color: 'rgb(192,192,192)', //
fontSize : 12 //
}
},
axisTick: {
show: false
},
axisLine:{
lineStyle:{
color:'rgb(192,192,192)' //
}
},
},
yAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wen', 'Thu', 'Fri', 'Sat', 'Sun'],
axisLabel: {
show: true,
textStyle: {
color: 'rgb(192,192,192)', //
fontSize: 12 //
}
},
axisTick: {
show: false
},
axisLine: {
lineStyle: {
color: 'rgb(192,192,192)' //
}
}
},
series: [
{
name: 'Javascript',
type: 'bar',
stack: '总量',
label: {
show: true,
position: 'insideRight'
},
data: [320, 302, 301, 334, 390, 330, 320]
},
{
name: 'Java',
type: 'bar',
stack: '总量',
label: {
show: true,
position: 'insideRight'
},
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: 'Python',
type: 'bar',
stack: '总量',
label: {
show: true,
position: 'insideRight'
},
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: 'Ruby',
type: 'bar',
stack: '总量',
label: {
show: true,
position: 'insideRight'
},
data: [150, 212, 201, 154, 190, 330, 410]
},
{
name: 'PHP',
type: 'bar',
stack: '总量',
label: {
show: true,
position: 'insideRight'
},
data: [820, 832, 901, 934, 1290, 1330, 1320]
}
],
animationDuration: animationDuration
})
}
}
}
</script>
<style scoped>
</style>
@@ -47,9 +47,9 @@
completed: todos => todos.filter(todo => todo.done)
}
const defalutList = [
{ text: 'star this repository', done: false },
{ text: 'follow author', done: false },
{ text: 'vue-element-admin', done: true }
{ text: '工作流功能绘制工具', done: false },
{ text: '工作流流转方法', done: false },
{ text: '自动化代码优化', done: false }
]
export default {
components: { Todo },
+99 -133
View File
@@ -1,27 +1,51 @@
<template>
<div class="big">
<div class="mid">
<el-row :gutter="32">
<el-col :xs="24" :sm="24" :lg="8">
<div class="chart-wrapper">
<raddar-chart />
<div class="card">
<div class="car-left">
<div>
<span class="card-img"> <img :src="userInfo.headerImg" alt="" > </span>
<div class="text"><h4>早安管理员 请开始您一天的工作吧</h4>
<p class="tips-text">
<i class="el-icon-sunny"></i>
<span>今日晴0 - 10天气寒冷注意添加衣物</span>
</p>
</div>
</div>
</el-col>
<el-col :xs="24" :sm="24" :lg="8">
<div class="chart-wrapper">
<stackMap />
</div>
</el-col>
<el-col :xs="24" :sm="24" :lg="8">
<div class="chart-wrapper">
<Sunburst/>
</div>
</el-col>
</el-row>
</div>
<div class="top">
<div id="main" class="chart-container"></div>
</div>
</div>
<div class="car-right">
<el-row>
<el-col :span="8"><div class="car-item">
<span class="flow"><i class="el-icon-s-grid"></i></span>
<span>今日流量 </span>
<b>13260</b>
</div></el-col>
<el-col :span="8"><div class="car-item">
<span class="user-number">
<i class="el-icon-s-custom "></i>
</span>
<span>总用户 </span>
<b>48286</b>
</div></el-col>
<el-col :span="8"><div class="car-item ">
<span class="feedback">
<i class="el-icon-star-on"></i>
</span>
<span>好评率 </span>
<b>98%</b>
</div></el-col>
</el-row>
</div>
</div>
<div class="shadow">
<el-row :gutter="20">
<el-col :span="4" v-for="(card,key) in toolCards" :key="key" @click.native="toTarget(card.name)">
<el-card shadow="hover" class="grid-content">
<i :class="card.icon" :style="{color:card.color}"></i>
<p>{{card.label}}</p>
</el-card>
</el-col>
</el-row>
</div>
<div class="bottom">
<el-row :gutter="32">
<el-col :xs="24" :sm="24" :lg="12">
@@ -41,128 +65,69 @@
</template>
<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import RaddarChart from "./component/RaddarChart"
import stackMap from "./component/stackMap"
import Sunburst from "./component/Sunburst"
import musicPlayer from "./component/musicPlayer"
import TodoList from "./component/todoList"
import { mapGetters } from 'vuex'
export default {
name: 'Dashboard',
data() {
return {
toolCards:[
{
label:"用户管理",
icon:"el-icon el-icon-monitor",
name:"user",
color:"#ff9c6e"
},
{
label:"角色管理",
icon:"el-icon el-icon-setting",
name:"authority",
color:"#69c0ff"
},
{
label:"菜单管理",
icon:"el-icon el-icon-menu",
name:"menu",
color:"#b37feb"
},
{
label:"代码生成器",
icon:"el-icon el-icon-cpu",
name:"autoCode",
color:"#ffd666"
},
{
label:"表单生成器",
icon:"el-icon el-icon-document-checked",
name:"formCreate",
color:"#ff85c0"
},
{
label:"关于我们",
icon:"el-icon el-icon-user",
name:"about",
color:"#5cdbd3"
}
]
}
},
computed: {
...mapGetters('user', ['userInfo'])
},
components:{
RaddarChart, //
stackMap, //
Sunburst, //
musicPlayer, //
TodoList //TodoList
TodoList, //TodoList
// RaddarChart, //
// stackMap, //
// Sunburst, //
},
methods:{
toTarget(name){
this.$router.push({name})
}
},
mounted() {
let myChart = echarts.init(document.getElementById('main'),'macarons');
// let stackMap = echarts.init(document.getElementById('stackMap'));
let option = {
legend: {},
tooltip: {
trigger: 'axis',
showContent: false
},
dataset: {
source: [
['product', '2012', '2013', '2014', '2015', '2016', '2017','2018','2019','2020'],
['Matcha Latte', 41.1, 30.4, 65.1, 53.3, 83.8, 70.0,6.4, 65.2, 82.5],
['Milk Tea', 86.5, 92.1, 85.7, 83.1, 73.4, 55.1,2, 67.1, 69.2],
['Cheese Cocoa', 24.1, 67.2, 79.5, 86.4, 65.2, 82.5,65.1, 53.3, 83.8],
['Walnut Brownie', 55.2, 67.1, 69.2, 72.4, 53.9, 39.1,86.5, 92.1, 85.7]
]
},
xAxis: {
type: 'category',
axisLabel: {
show: true,
textStyle: {
color: 'rgb(192,192,192)', //
fontSize : 14 //
}
},
axisTick: {
show: false
},
axisLine:{
lineStyle:{
color:'rgb(192,192,192)' //
}
},
},
yAxis: {
gridIndex:0,
axisLabel: {
show: true,
textStyle: {
color: 'rgb(192,192,192)', //
fontSize: 14 //
}
},
axisTick: {
show: false
},
axisLine: {
lineStyle: {
color: 'rgb(192,192,192)' //
}
}
},
grid: {top: '55%'},
series: [
{type: 'line', smooth: true, seriesLayoutBy: 'row'},
{type: 'line', smooth: true, seriesLayoutBy: 'row'},
{type: 'line', smooth: true, seriesLayoutBy: 'row'},
{type: 'line', smooth: true, seriesLayoutBy: 'row'},
{
type: 'pie',
id: 'pie',
radius: '30%',
center: ['50%', '25%'],
label: {
formatter: '{b}: {@2012} ({d}%)'
},
encode: {
itemName: 'product',
value: '2012',
tooltip: '2012'
}
}
]
};
//
myChart.on('updateAxisPointer', function (event) {
var xAxisInfo = event.axesInfo[0];
if (xAxisInfo) {
var dimension = xAxisInfo.value + 1;
myChart.setOption({
series: {
id: 'pie',
label: {
formatter: '{b}: {@[' + dimension + ']} ({d}%)'
},
encode: {
value: dimension,
tooltip: dimension
}
}
});
}
});
window.addEventListener('resize',function() {myChart.resize()});
myChart.setOption(option);
}
}
</script>
@@ -170,7 +135,8 @@ export default {
.big{
margin:100px 0 0 0;
padding-top: 0;
background-color: rgb(243,243,243);;
background-color: rgb(243,243,243);
padding-top: 15px;
.top{
width: 100%;
height: 360px;
@@ -197,7 +163,7 @@ export default {
.bottom{
width: 100%;
height: 300px;
margin: 20px 0;
// margin: 20px 0;
.el-row{
margin-right: 4px !important;
}
@@ -224,10 +224,6 @@ export default {
background: #f2f2f2;
cursor: pointer;
}
.router-history {
background: #fff;
padding: 0 6px;
border-top: 1px solid #dcdcdc;
}
</style>
+146 -213
View File
@@ -32,7 +32,7 @@
<Screenfull class="screenfull"></Screenfull>
<el-dropdown>
<span class="header-avatar">
欢迎您<CustomPic/>
<CustomPic/>
<span style="margin-left: 5px">{{userInfo.nickName}}</span>
<i class="el-icon-arrow-down"></i>
</span>
@@ -43,7 +43,6 @@
<el-badge is-dot />
</span>
</el-dropdown-item>
<el-dropdown-item @click.native="showPassword=true" icon="el-icon-s-custom">修改密码</el-dropdown-item>
<el-dropdown-item @click.native="toPerson" icon="el-icon-s-custom">个人信息</el-dropdown-item>
<el-dropdown-item @click.native="LoginOut" icon="el-icon-table-lamp"> </el-dropdown-item>
</el-dropdown-menu>
@@ -67,23 +66,7 @@
<BottomInfo />
</el-main>
</el-container>
<el-dialog :visible.sync="showPassword" @close="clearPassword" title="修改密码" width="360px">
<el-form :model="pwdModify" :rules="rules" label-width="80px" ref="modifyPwdForm">
<el-form-item :minlength="6" label="原密码" prop="password">
<el-input show-password v-model="pwdModify.password"></el-input>
</el-form-item>
<el-form-item :minlength="6" label="新密码" prop="newPassword">
<el-input show-password v-model="pwdModify.newPassword"></el-input>
</el-form-item>
<el-form-item :minlength="6" label="确认密码" prop="confirmPassword">
<el-input show-password v-model="pwdModify.confirmPassword"></el-input>
</el-form-item>
</el-form>
<div class="dialog-footer" slot="footer">
<el-button @click="showPassword=false"> </el-button>
<el-button @click="savePassword" type="primary"> </el-button>
</div>
</el-dialog>
</el-container>
</template>
@@ -94,7 +77,6 @@ import Screenfull from '@/view/layout/screenfull'
import Search from '@/view/layout/search/search'
import BottomInfo from '@/view/layout/bottomInfo/bottomInfo'
import { mapGetters, mapActions } from 'vuex'
import { changePassword } from '@/api/user'
import CustomPic from '@/components/customPic'
export default {
name: 'Layout',
@@ -105,33 +87,8 @@ export default {
isSider: true,
isMobile: false,
isShadowBg: false,
showPassword: false,
loadingFlag:false,
pwdModify: {},
rules: {
password: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{ min: 6, message: '最少6个字符', trigger: 'blur' }
],
newPassword: [
{ required: true, message: '请输入新密码', trigger: 'blur' },
{ min: 6, message: '最少6个字符', trigger: 'blur' }
],
confirmPassword: [
{ required: true, message: '请输入确认密码', trigger: 'blur' },
{ min: 6, message: '最少6个字符', trigger: 'blur' },
{
validator: (rule, value, callback) => {
if (value !== this.pwdModify.newPassword) {
callback(new Error('两次密码不一致'))
} else {
callback()
}
},
trigger: 'blur'
}
]
},
value: ''
}
},
@@ -159,30 +116,6 @@ export default {
this.isSider = !!this.isCollapse
this.totalCollapse()
},
savePassword() {
this.$refs.modifyPwdForm.validate(valid => {
if (valid) {
changePassword({
username: this.userInfo.userName,
password: this.pwdModify.password,
newPassword: this.pwdModify.newPassword
}).then(() => {
this.$message.success('修改密码成功!')
this.showPassword = false
})
} else {
return false
}
})
},
clearPassword() {
this.pwdModify = {
password: '',
newPassword: '',
confirmPassword: ''
}
this.$refs.modifyPwdForm.clearValidate()
}
},
computed: {
...mapGetters('user', ['userInfo']),
@@ -241,151 +174,151 @@ export default {
</script>
<style lang="scss">
$headerHigh: 52px;
$mainHight: 100vh;
.dropdown-group {
min-width: 100px;
}
.topfix {
position: fixed;
top: 0;
box-sizing: border-box;
z-index: 999;
}
.admin-box {
min-height: calc(100vh - 240px);
background-color: rgb(255, 255, 255);
margin-top: 100px;
}
.el-scrollbar__wrap {
padding-bottom: 17px;
}
.layout-cont {
.right-box {
text-align: center;
vertical-align: middle;
img {
vertical-align: middle;
border: 1px solid #ccc;
border-radius: 6px;
}
}
// $headerHigh: 52px;
// $mainHight: 100vh;
// .dropdown-group {
// min-width: 100px;
// }
// .topfix {
// position: fixed;
// top: 0;
// box-sizing: border-box;
// z-index: 999;
// }
// .admin-box {
// min-height: calc(100vh - 240px);
// background-color: rgb(255, 255, 255);
// margin-top: 100px;
// }
// .el-scrollbar__wrap {
// padding-bottom: 17px;
// }
// .layout-cont {
// .right-box {
// text-align: center;
// vertical-align: middle;
// img {
// vertical-align: middle;
// border: 1px solid #ccc;
// border-radius: 6px;
// }
// }
.header-cont {
height: $headerHigh !important;
background: #fff;
box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
line-height: $headerHigh;
}
.main-cont {
.breadcrumb {
line-height: 48px;
display: inline-block;
padding: 0 24px;
// padding: 6px;
// border-bottom: 1px solid #eee;
}
// .header-cont {
// height: $headerHigh !important;
// background: #fff;
// box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
// line-height: $headerHigh;
// }
// .main-cont {
// .breadcrumb {
// line-height: 48px;
// display: inline-block;
// padding: 0 24px;
// // padding: 6px;
// // border-bottom: 1px solid #eee;
// }
&.el-main {
overflow: auto;
background: #fff;
// padding: 0px 10px;
// background: #fff;
}
height: $mainHight !important;
overflow: visible;
position: relative;
.menu-total {
// z-index: 5;
// position: absolute;
// top: 10px;
// right: -35px;
margin-left: -10px;
float: left;
margin-top: 10px;
width: 30px;
height: 30px;
line-height: 30px;
font-size: 30px;
// border: 0 solid #ffffff;
// border-radius: 50%;
// background: #fff;
}
.aside {
overflow: auto;
// background: #fff;
&::-webkit-scrollbar {
display: none;
}
}
.el-menu-vertical {
height: calc(100vh - 64px) !important;
visibility: auto;
&:not(.el-menu--collapse) {
width: 220px;
}
}
.el-menu--collapse {
width: 54px;
li {
.el-tooltip,
.el-submenu__title {
padding: 0px 15px !important;
}
}
}
&::-webkit-scrollbar {
display: none;
}
&.main-left {
width: auto !important;
}
&.main-right {
.admin-title {
float: left;
font-size: 16px;
vertical-align: middle;
margin-left: 20px;
img {
vertical-align: middle;
}
&.collapse {
width: 53px;
}
}
}
}
}
.tilte {
background: #001529;
min-height: 64px;
line-height: 64px;
background: #002140;
text-align: center;
.logoimg {
width: 30px;
height: 30px;
vertical-align: middle;
background: #fff;
border-radius: 50%;
padding: 3px;
}
.tit-text {
display: inline-block;
color: #fff;
font-weight: 600;
font-size: 20px;
vertical-align: middle;
}
}
// &.el-main {
// overflow: auto;
// background: #fff;
// // padding: 0px 10px;
// // background: #fff;
// }
// height: $mainHight !important;
// overflow: visible;
// position: relative;
// .menu-total {
// // z-index: 5;
// // position: absolute;
// // top: 10px;
// // right: -35px;
// margin-left: -10px;
// float: left;
// margin-top: 10px;
// width: 30px;
// height: 30px;
// line-height: 30px;
// font-size: 30px;
// // border: 0 solid #ffffff;
// // border-radius: 50%;
// // background: #fff;
// }
// .aside {
// overflow: auto;
// // background: #fff;
// &::-webkit-scrollbar {
// display: none;
// }
// }
// .el-menu-vertical {
// height: calc(100vh - 64px) !important;
// visibility: auto;
// &:not(.el-menu--collapse) {
// width: 220px;
// }
// }
// .el-menu--collapse {
// width: 54px;
// li {
// .el-tooltip,
// .el-submenu__title {
// padding: 0px 15px !important;
// }
// }
// }
// &::-webkit-scrollbar {
// display: none;
// }
// &.main-left {
// width: auto !important;
// }
// &.main-right {
// .admin-title {
// float: left;
// font-size: 16px;
// vertical-align: middle;
// margin-left: 20px;
// img {
// vertical-align: middle;
// }
// &.collapse {
// width: 53px;
// }
// }
// }
// }
// }
// .tilte {
// background: #001529;
// min-height: 64px;
// line-height: 64px;
// background: #002140;
// text-align: center;
// .logoimg {
// width: 30px;
// height: 30px;
// vertical-align: middle;
// background: #fff;
// border-radius: 50%;
// padding: 3px;
// }
// .tit-text {
// display: inline-block;
// color: #fff;
// font-weight: 600;
// font-size: 20px;
// vertical-align: middle;
// }
// }
.screenfull {
display: inline-block;
}
.header-avatar{
display: flex;
justify-content: center;
align-items: center;
}
// .screenfull {
// display: inline-block;
// }
// .header-avatar{
// display: flex;
// justify-content: center;
// align-items: center;
// }
</style>
+2 -2
View File
@@ -103,8 +103,8 @@ export default {
</script>
<style scoped>
.screenfull-svg {
width: 20px;
height: 20px;
width: 17px;
height: 17px;
cursor: pointer;
fill: #606266;
vertical-align: middle;
+18 -32
View File
@@ -3,6 +3,7 @@
<transition name="el-fade-in-linear">
<div class="transition-box" style="display: inline-block; " v-show="show">
<el-select
ref="search-input"
@blur="hiddenSearch"
@change="changeRouter"
filterable
@@ -18,56 +19,41 @@
</el-select>
</div>
</transition>
<div :style="{display:'inline-block'}">
<i @click="show = !show" class="el-icon-search search-icon"></i>
<div :style="{display:'inline-block',float:'right'}" class="user-box">
<i @click="showSearch()" class="el-icon-search search-icon"></i>
</div>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
import { mapGetters } from "vuex";
export default {
name: 'searchComponent',
name: "searchComponent",
data() {
return {
value: '',
value: "",
show: false
}
};
},
computed: {
...mapGetters('router', ['routerList'])
...mapGetters("router", ["routerList"])
},
methods: {
changeRouter() {
this.$router.push({ name: this.value })
this.value = ''
this.$router.push({ name: this.value });
this.value = "";
},
hiddenSearch() {
this.show = false
this.show = false;
},
showSearch() {
this.show = true;
this.$nextTick(()=>{
this.$refs['search-input'].focus()
})
}
}
}
};
</script>
<style lang="scss">
.search-component {
display: inline-block;
.el-input__inner {
border: none;
border-bottom: 1px solid #606266;
}
.el-dropdown-link {
cursor: pointer;
}
.search-icon {
font-size: 20px;
margin-right: 14px;
display: inline-block;
vertical-align: middle;
box-sizing: border-box;
color: #606266;
}
.dropdown-group {
min-width: 100px;
}
}
</style>
+1 -133
View File
@@ -167,138 +167,6 @@ export default {
</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;
}
}
}
@import '@/style/login.scss';
.link-icon {
width: 20px;
min-width: 20px;
height: 20px;
border-radius: 10px;
}
.vPic {
width: 33%;
height: 38px;
float: right !important;
background: #ccc;
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 {
position: relative;
overflow: auto;
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%;
padding: 0 20px;
margin: 40px 0 10px;
text-align: center;
.links {
margin-bottom: 8px;
font-size: 14px;
width: 330px;
display: inline-flex;
flex-direction: row;
justify-content: space-between;
padding-right: 40px;
a {
color: rgba(0, 0, 0, 0.45);
transition: all 0.3s;
}
}
.copyright {
color: rgba(0, 0, 0, 0.45);
font-size: 14px;
padding-right: 40px;
}
}
}
}
</style>
+246 -36
View File
@@ -1,52 +1,192 @@
<template>
<div>
<div class="fl-left left-mg-xs">
<el-avatar :size="120" :src="userInfo.headerImg" shape="square" @click.native="openChooseImg"></el-avatar>
</div>
<div class="fl-left left-mg-lg">
<div>用户ID{{userInfo.uuid}}</div>
<div>用户昵称{{userInfo.nickName}}</div>
<div>用户组{{userInfo.authority&&userInfo.authority.authorityName}}</div>
</div>
<ChooseImg ref="chooseImg" @enter-img="enterImg"/>
<el-row>
<el-col :span="6">
<div class="fl-left avatar-box">
<div class="user-card">
<el-avatar
class="user-avatar"
:size="160"
:src="userInfo.headerImg"
shape="square"
@click.native="openChooseImg"
></el-avatar>
<div class="user-personality">
<p class="nickname">{{userInfo.nickName}}</p>
<p class="person-info">这个家伙很懒什么都没有留下</p>
</div>
<div class="user-information">
<ul>
<li>
<i class="el-icon-user"></i>资深前端工程师
</li>
<li>
<i class="el-icon-data-analysis"></i>北京反转极光科技有限公司-技术部-前端事业群
</li>
<li>
<i class="el-icon-video-camera-solid"></i>中国·北京市·朝阳区
</li>
<li>
<i class="el-icon-medal-1"></i>goLang/JavaScript/Vue/Gorm
</li>
</ul>
</div>
</div>
</div>
</el-col>
<el-col :span="18">
<div class="user-addcount">
<el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane label="账号绑定" name="second">
<ul>
<li>
<p class="title">密保手机</p>
<p class="desc">
已绑定手机:1245678910
<a href="#">立即修改</a>
</p>
</li>
<li>
<p class="title">密保邮箱</p>
<p class="desc">
已绑定邮箱gin-vue-admin@google.com.cn
<a href="#">立即修改</a>
</p>
</li>
<li>
<p class="title">密保问题</p>
<p class="desc">
未设置密保问题
<a href="#">去设置</a>
</p>
</li>
<li>
<p class="title">修改密码</p>
<p class="desc">
修改个人密码
<a href="#" @click="showPassword=true">修改密码</a>
</p>
</li>
</ul>
</el-tab-pane>
</el-tabs>
</div>
</el-col>
</el-row>
<ChooseImg ref="chooseImg" @enter-img="enterImg" />
<el-dialog :visible.sync="showPassword" @close="clearPassword" title="修改密码" width="360px">
<el-form :model="pwdModify" :rules="rules" label-width="80px" ref="modifyPwdForm">
<el-form-item :minlength="6" label="原密码" prop="password">
<el-input show-password v-model="pwdModify.password"></el-input>
</el-form-item>
<el-form-item :minlength="6" label="新密码" prop="newPassword">
<el-input show-password v-model="pwdModify.newPassword"></el-input>
</el-form-item>
<el-form-item :minlength="6" label="确认密码" prop="confirmPassword">
<el-input show-password v-model="pwdModify.confirmPassword"></el-input>
</el-form-item>
</el-form>
<div class="dialog-footer" slot="footer">
<el-button @click="showPassword=false"> </el-button>
<el-button @click="savePassword" type="primary"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import ChooseImg from "@/components/chooseImg";
import {setUserInfo} from "@/api/user"
import { mapGetters, mapMutations } from 'vuex'
const path = process.env.VUE_APP_BASE_API
import { setUserInfo,changePassword } from "@/api/user";
import { mapGetters, mapMutations } from "vuex";
const path = process.env.VUE_APP_BASE_API;
export default {
name: 'Person',
data(){
name: "Person",
data() {
return {
path:path
}
path: path,
activeName: "second",
showPassword: false,
pwdModify: {},
rules: {
password: [
{ required: true, message: "请输入密码", trigger: "blur" },
{ min: 6, message: "最少6个字符", trigger: "blur" }
],
newPassword: [
{ required: true, message: "请输入新密码", trigger: "blur" },
{ min: 6, message: "最少6个字符", trigger: "blur" }
],
confirmPassword: [
{ required: true, message: "请输入确认密码", trigger: "blur" },
{ min: 6, message: "最少6个字符", trigger: "blur" },
{
validator: (rule, value, callback) => {
if (value !== this.pwdModify.newPassword) {
callback(new Error("两次密码不一致"));
} else {
callback();
}
},
trigger: "blur"
}
]
}
};
},
components: {
ChooseImg
},
computed: {
...mapGetters('user', ['userInfo', 'token'])
ChooseImg
},
methods:{
...mapMutations('user',['ResetUserInfo']),
openChooseImg(){
this.$refs.chooseImg.open()
},
async enterImg(url){
const res = await setUserInfo({headerImg:url,ID:this.userInfo.ID})
if(res.code == 0){
this.ResetUserInfo({headerImg:url})
this.$message({
type:"success",
message:"设置成功"
}
)
computed: {
...mapGetters("user", ["userInfo", "token"])
},
methods: {
...mapMutations("user", ["ResetUserInfo"]),
savePassword() {
this.$refs.modifyPwdForm.validate(valid => {
if (valid) {
changePassword({
username: this.userInfo.userName,
password: this.pwdModify.password,
newPassword: this.pwdModify.newPassword
}).then((res) => {
if(res.code == 0){
this.$message.success("修改密码成功!");
}
this.showPassword = false;
});
} else {
return false;
}
},
});
},
clearPassword() {
this.pwdModify = {
password: "",
newPassword: "",
confirmPassword: ""
};
this.$refs.modifyPwdForm.clearValidate();
},
openChooseImg() {
this.$refs.chooseImg.open();
},
async enterImg(url) {
const res = await setUserInfo({ headerImg: url, ID: this.userInfo.ID });
if (res.code == 0) {
this.ResetUserInfo({ headerImg: url });
this.$message({
type: "success",
message: "设置成功"
});
}
},
handleClick(tab, event) {
console.log(tab, event);
}
}
}
};
</script>
<style lang="scss">
.avatar-uploader .el-upload {
@@ -72,4 +212,74 @@ export default {
height: 178px;
display: block;
}
.avatar-box {
box-shadow: -2px 0 20px -16px;
width: 80%;
height: 100%;
.user-avatar{
cursor: pointer;
}
.user-card {
min-height: calc(90vh - 200px);
padding: 30px 20px;
text-align: center;
.el-avatar {
border-radius: 50%;
}
.user-personality {
padding: 24px 0;
text-align: center;
p {
font-size: 16px;
}
.nickname {
font-size: 26px;
}
.person-info{
margin-top: 6px;
font-size: 14px;
color:#999
}
}
.user-information {
width: 100%;
height: 100%;
text-align: left;
ul {
display: inline-block;
height: 100%;
li {
i {
margin-right: 8px;
}
padding: 20px 0;
font-size: 16px;
font-weight: 400;
color: #606266;
}
}
}
}
}
.user-addcount {
ul {
li {
.title {
padding: 10px;
font-size: 18px;
color: #696969;
}
.desc {
font-size: 16px;
padding: 0 10px 20px 10px;
color: #a9a9a9;
a {
color: rgb(64, 158, 255);
float: right;
}
}
border-bottom: 2px solid #f0f2f5;
}
}
}
</style>
@@ -195,7 +195,6 @@ export default {
}
},
async created() {
this.getDbfdOptions();
const dictRes = await getSysDictionaryList({
page: 1,
pageSize: 999999
+28 -16
View File
@@ -36,7 +36,7 @@
</el-select>
</el-form-item>
<el-form-item>
<el-button @click="getColume" type="primary">使用此表创建</el-button>
<el-button @click="getColumn" type="primary">使用此表创建</el-button>
</el-form-item>
</el-form>
</el-collapse-item>
@@ -63,6 +63,9 @@
<el-form-item label="自动创建api">
<el-checkbox v-model="form.autoCreateApiToSql"></el-checkbox>
</el-form-item>
<el-form-item label="自动移动文件">
<el-checkbox v-model="form.autoMoveFile"></el-checkbox>
</el-form-item>
</el-form>
<!-- 组件列表 -->
<div class="button-box clearflex">
@@ -114,7 +117,7 @@
<el-tag type="danger">id , created_at , updated_at , deleted_at 会自动生成请勿重复创建</el-tag>
<!-- 组件列表 -->
<div class="button-box clearflex">
<el-button @click="enterForm" type="primary">生成代码</el-button>
<el-button @click="enterForm" type="primary">生成代码</el-button>
</div>
<!-- 组件弹窗 -->
<el-dialog title="组件内容" :visible.sync="dialogFlag">
@@ -137,12 +140,12 @@ const fieldTemplate = {
dataTypeLong: "",
comment: "",
fieldSearchType: "",
dictType:""
dictType: ""
};
import FieldDialog from "@/view/systemTools/autoCode/component/fieldDialog.vue";
import { toUpperCase, toHump } from "@/utils/stringFun.js";
import { createTemp, getDB, getTable, getColume } from "@/api/autoCode.js";
import { createTemp, getDB, getTable, getColumn } from "@/api/autoCode.js";
import { getDict } from "@/utils/dictionary";
export default {
@@ -165,6 +168,7 @@ export default {
abbreviation: "",
description: "",
autoCreateApiToSql: false,
autoMoveFile: false,
fields: []
},
rules: {
@@ -274,6 +278,14 @@ export default {
return false;
}
const data = await createTemp(this.form);
if (data.headers?.success == "false") {
return;
} else {
this.$message({
type: "success",
message: "自动化代码创建成功,正在下载"
});
}
const blob = new Blob([data]);
const fileName = "ginvueadmin.zip";
if ("download" in document.createElement("a")) {
@@ -309,9 +321,9 @@ export default {
}
this.dbform.tableName = "";
},
async getColume() {
async getColumn() {
const gormModelList = ["id", "created_at", "updated_at", "deleted_at"];
const res = await getColume(this.dbform);
const res = await getColumn(this.dbform);
if (res.code == 0) {
const tbHump = toHump(this.dbform.tableName);
this.form.structName = toUpperCase(tbHump);
@@ -321,29 +333,29 @@ export default {
this.form.description = tbHump + "表";
this.form.autoCreateApiToSql = true;
this.form.fields = [];
res.data.columes &&
res.data.columes.map(item => {
if (!gormModelList.some(gormfd => gormfd == item.columeName)) {
const fbHump = toHump(item.columeName);
res.data.columns &&
res.data.columns.map(item => {
if (!gormModelList.some(gormfd => gormfd == item.columnName)) {
const fbHump = toHump(item.columnName);
this.form.fields.push({
fieldName: toUpperCase(fbHump),
fieldDesc: item.columeComment || fbHump + "字段",
fieldDesc: item.columnComment || fbHump + "字段",
fieldType: this.fdMap[item.dataType],
dataType: item.dataType,
fieldJson: fbHump,
dataTypeLong: item.dataTypeLong,
columnName: item.columeName,
comment: item.columeComment,
columnName: item.columnName,
comment: item.columnComment,
fieldSearchType: "",
dictType:""
dictType: ""
});
}
});
}
},
async setFdMap() {
const fdTpyes = ["string", "int", "bool", "float64", "time.Time"];
fdTpyes.map(async fdtype => {
const fdTypes = ["string", "int", "bool", "float64", "time.Time"];
fdTypes.map(async fdtype => {
const res = await getDict(fdtype);
res.map(item => {
this.fdMap[item.label] = fdtype;
+1 -1
View File
@@ -23,7 +23,7 @@ module.exports = {
// 把key的路径代理到target位置
// detail: https://cli.vuejs.org/config/#devserver-proxy
[process.env.VUE_APP_BASE_API]: { //需要代理的路径 例如 '/api'
target: `http://127.0.0.1:8888`, //代理到 目标路径
target: `http://127.0.0.1:8888/`, //代理到 目标路径
changeOrigin: true,
pathRewrite: { // 修改路径数据
['^' + process.env.VUE_APP_BASE_API]: '' // 举例 '^/api:""' 把路径中的/api字符串删除