diff --git a/apps/system/api/dict.go b/apps/system/api/dict.go index d40b417..90f965c 100644 --- a/apps/system/api/dict.go +++ b/apps/system/api/dict.go @@ -2,8 +2,6 @@ package api import ( "fmt" - "github.com/kakuilan/kgo" - "os" entity "pandax/apps/system/entity" services "pandax/apps/system/services" "pandax/base/biz" @@ -128,20 +126,15 @@ func (p *DictApi) DeleteDictType(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/dict/type/export [get] func (p *DictApi) ExportDictType(rc *ctx.ReqCtx) { + filename := rc.GinCtx.Query("filename") status := rc.GinCtx.Query("status") dictName := rc.GinCtx.Query("dictName") dictType := rc.GinCtx.Query("dictType") list := p.DictType.FindList(entity.SysDictType{Status: status, DictName: dictName, DictType: dictType}) - fileName := utils.GetFileName(config.Conf.Server.ExcelDir, "字典") + fileName := utils.GetFileName(config.Conf.Server.ExcelDir, filename) utils.InterfaceToExcel(*list, fileName) - - line, err := kgo.KFile.ReadFile(fileName) - if err != nil { - os.Remove(fileName) - biz.ErrIsNil(err, "读取文件失败") - } - rc.Download(line, fileName) + rc.Download(fileName) } // @Summary 字典数据列表 diff --git a/apps/system/api/role.go b/apps/system/api/role.go index fcdcda7..eb35b92 100644 --- a/apps/system/api/role.go +++ b/apps/system/api/role.go @@ -3,8 +3,6 @@ package api import ( "errors" "fmt" - "github.com/kakuilan/kgo" - "os" entity "pandax/apps/system/entity" services "pandax/apps/system/services" "pandax/base/biz" @@ -194,18 +192,13 @@ func (r *RoleApi) DeleteRole(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/dict/type/export [get] func (p *RoleApi) ExportRole(rc *ctx.ReqCtx) { + filename := rc.GinCtx.Query("filename") status := rc.GinCtx.Query("status") roleName := rc.GinCtx.Query("roleName") roleKey := rc.GinCtx.Query("roleKey") list := p.RoleApp.FindList(entity.SysRole{Status: status, RoleName: roleName, RoleKey: roleKey}) - fileName := utils.GetFileName(config.Conf.Server.ExcelDir, "角色") + fileName := utils.GetFileName(config.Conf.Server.ExcelDir, filename) utils.InterfaceToExcel(*list, fileName) - - line, err := kgo.KFile.ReadFile(fileName) - if err != nil { - os.Remove(fileName) - biz.ErrIsNil(err, "读取文件失败") - } - rc.Download(line, fileName) + rc.Download(fileName) } diff --git a/apps/system/api/user.go b/apps/system/api/user.go index f03dceb..346542b 100644 --- a/apps/system/api/user.go +++ b/apps/system/api/user.go @@ -6,7 +6,6 @@ import ( "github.com/kakuilan/kgo" "github.com/mssola/user_agent" "net/http" - "os" "pandax/apps/system/api/form" "pandax/apps/system/api/vo" "pandax/apps/system/entity" @@ -411,6 +410,7 @@ func (u *UserApi) DeleteSysUser(rc *ctx.ReqCtx) { // @Success 200 {string} string "{"code": 400, "message": "删除失败"}" // @Router /system/dict/type/export [get] func (u *UserApi) ExportUser(rc *ctx.ReqCtx) { + filename := rc.GinCtx.Query("filename") status := rc.GinCtx.Query("status") userName := rc.GinCtx.Query("username") phone := rc.GinCtx.Query("phone") @@ -420,15 +420,9 @@ func (u *UserApi) ExportUser(rc *ctx.ReqCtx) { user.Username = userName user.Phone = phone list := u.UserApp.FindList(user) - fileName := utils.GetFileName(config.Conf.Server.ExcelDir, "用户") + fileName := utils.GetFileName(config.Conf.Server.ExcelDir, filename) utils.InterfaceToExcel(*list, fileName) - - line, err := kgo.KFile.ReadFile(fileName) - if err != nil { - os.Remove(fileName) - biz.ErrIsNil(err, "读取文件失败") - } - rc.Download(line, fileName) + rc.Download(fileName) } // 构建前端路由 diff --git a/apps/system/entity/user.go b/apps/system/entity/user.go index b0d0cd3..c558194 100644 --- a/apps/system/entity/user.go +++ b/apps/system/entity/user.go @@ -2,18 +2,9 @@ package entity import "pandax/base/model" -type UserName struct { - Username string `gorm:"type:varchar(64)" json:"username"` -} - -type PassWord struct { - // 密码 - Password string `gorm:"type:varchar(128)" json:"password"` -} - type LoginM struct { - UserName - PassWord + Username string `gorm:"type:varchar(64)" json:"username"` + Password string `gorm:"type:varchar(128)" json:"password"` } type SysUserId struct { diff --git a/base/ctx/req_ctx.go b/base/ctx/req_ctx.go index 7e7b1b6..aecea1c 100644 --- a/base/ctx/req_ctx.go +++ b/base/ctx/req_ctx.go @@ -60,9 +60,9 @@ func (rc *ReqCtx) Handle(handler HandlerFunc) { } } -func (rc *ReqCtx) Download(data []byte, filename string) { +func (rc *ReqCtx) Download(filename string) { rc.noRes = true - ginx.Download(rc.GinCtx, data, filename) + ginx.Download(rc.GinCtx, filename) } // 新建请求上下文,默认需要校验token diff --git a/base/ginx/ginx.go b/base/ginx/ginx.go index bef9e6a..afff781 100644 --- a/base/ginx/ginx.go +++ b/base/ginx/ginx.go @@ -47,10 +47,11 @@ func PathParamInt(g *gin.Context, pm string) int { } // 文件下载 -func Download(g *gin.Context, data []byte, filename string) { - g.Header("Content-Type", "application/octet-stream") - g.Header("Content-Disposition", "attachment; filename="+filename) - g.Data(http.StatusOK, "application/octet-stream", data) +func Download(g *gin.Context, filename string) { + g.Writer.Header().Add("success", "true") + g.Writer.Header().Set("Content-Length", "-1") + g.Writer.Header().Set("Content-Disposition", "attachment; filename="+filename) + g.File(filename) } // 返回统一成功结果 diff --git a/base/utils/excel.go b/base/utils/excel.go index b532e7d..239d6f8 100644 --- a/base/utils/excel.go +++ b/base/utils/excel.go @@ -2,10 +2,8 @@ package utils import ( "fmt" - "github.com/kakuilan/kgo" "github.com/xuri/excelize/v2" "reflect" - "time" ) func ExportExcel(head []string, datas [][]any, filePath string) error { @@ -19,8 +17,8 @@ func ExportExcel(head []string, datas [][]any, filePath string) error { return nil } -func GetFileName(path, model string) string { - return path + fmt.Sprintf("%s_%s.xlsx", model, kgo.KTime.Date("20060102150405", time.Now())) +func GetFileName(path, filename string) string { + return path + filename } func InterfaceToExcel(data any, fileName string) { diff --git a/config.yml b/config.yml index 08d87ec..b45dfcb 100644 --- a/config.yml +++ b/config.yml @@ -40,9 +40,9 @@ redis: port: 6379 mysql: - host: 127.0.0.1 - username: root - password: 123456 + host: 47.104.252.2 + username: pandax + password: pandax db-name: pandax config: charset=utf8&loc=Local&parseTime=true