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

Merge branches 'develop' and 'gva_gormv2_dev' of...

Merge branches 'develop' and 'gva_gormv2_dev' of https://github.com/flipped-aurora/gin-vue-admin into gva_gormv2_dev
package response
import (
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/gin-gonic/gin"
"net/http"
"strconv"
)
type Response struct {
......@@ -41,6 +43,20 @@ func OkDetailed(data interface{}, message string, c *gin.Context) {
Result(SUCCESS, data, message, c)
}
func OkWithXlsx(list []interface{}, title []string, fileName string, c *gin.Context) {
file := excelize.NewFile()
file.SetSheetRow("Sheet1", "A1", &title)
for i, v := range list {
// 第一行被title占用
lint := strconv.Itoa(i + 2)
file.SetSheetRow("Sheet1", "A"+lint, v)
}
c.Header("Content-Type", "application/octet-stream")
c.Header("Content-Disposition", "attachment; filename="+fileName)
c.Header("Content-Transfer-Encoding", "binary")
_ = file.Write(c.Writer)
}
func Fail(c *gin.Context) {
Result(ERROR, map[string]interface{}{}, "操作失败", c)
}
......
......@@ -3,6 +3,7 @@ module gin-vue-admin
go 1.12
require (
github.com/360EntSecGroup-Skylar/excelize v1.4.1 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/casbin/casbin v1.9.1
github.com/casbin/casbin/v2 v2.11.0
......
......@@ -9,7 +9,8 @@ import (
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
method := c.Request.Method
c.Header("Access-Control-Allow-Origin", "*")
origin := c.Request.Header.Get("Origin")
c.Header("Access-Control-Allow-Origin", origin)
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token,X-Token,X-User-Id\"")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS,DELETE,PUT")
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册