未验证 提交 8261157a 编写于 作者: Mr.奇淼('s avatar Mr.奇淼( 提交者: GitHub

Merge pull request #839 from flipped-aurora/pgsqlDevelop

Pgsql develop
......@@ -135,3 +135,19 @@ Timer:
{ tableName: "sys_operation_records" , compareField: "created_at", interval: "2160h" },
#{ tableName: "log2" , compareField: "created_at", interval: "2160h" }
]
# 跨域配置
# 需要配合 server/initialize/router.go#L32 使用
cors:
mode: whitelist # 放行模式: allow-all, 放行全部; whitelist, 白名单模式, 来自白名单内域名的请求添加 cors 头; strict-whitelist 严格白名单模式, 白名单外的请求一律拒绝
whitelist:
- allow-origin: example1.com
allow-headers: content-type
allow-methods: GET, POST
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type
allow-credentials: true # 布尔值
- allow-origin: example2.com
allow-headers: content-type
allow-methods: GET, POST
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type
allow-credentials: true # 布尔值
......@@ -179,4 +179,18 @@ Timer:
#{ tableName: "log2" , compareField: "created_at", interval: "2160h" }
]
# 跨域配置
# 需要配合 server/initialize/router.go#L32 使用
cors:
mode: whitelist # 放行模式: allow-all, 放行全部; whitelist, 白名单模式, 来自白名单内域名的请求添加 cors 头; strict-whitelist 严格白名单模式, 白名单外的请求一律拒绝
whitelist:
- allow-origin: example1.com
allow-headers: content-type
allow-methods: GET, POST
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type
allow-credentials: true # 布尔值
- allow-origin: example2.com
allow-headers: content-type
allow-methods: GET, POST
expose-headers: Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type
allow-credentials: true # 布尔值
......@@ -23,4 +23,7 @@ type Server struct {
Excel Excel `mapstructure:"excel" json:"excel" yaml:"excel"`
Timer Timer `mapstructure:"timer" json:"timer" yaml:"timer"`
// 跨域配置
Cors CORS `mapstructure:"cors" json:"cors" yaml:"cors"`
}
package config
type CORS struct {
Mode string `mapstructure:"mode" json:"mode" yaml:"mode"`
Whitelist []CORSWhitelist `mapstructure:"whitelist" json:"whitelist" yaml:"whitelist"`
}
type CORSWhitelist struct {
AllowOrigin string `mapstructure:"allow-origin" json:"allow-origin" yaml:"allow-origin"`
AllowMethods string `mapstructure:"allow-methods" json:"allow-methods" yaml:"allow-methods"`
AllowHeaders string `mapstructure:"allow-headers" json:"allow-headers" yaml:"allow-headers"`
ExposeHeaders string `mapstructure:"expose-headers" json:"expose-headers" yaml:"expose-headers"`
AllowCredentials bool `mapstructure:"allow-credentials" json:"allow-credentials" yaml:"allow-credentials"`
}
......@@ -29,8 +29,9 @@ func Routers() *gin.Engine {
Router.StaticFS(global.GVA_CONFIG.Local.Path, http.Dir(global.GVA_CONFIG.Local.Path)) // 为用户头像和文件提供静态地址
// Router.Use(middleware.LoadTls()) // 打开就能玩https了
global.GVA_LOG.Info("use middleware logger")
// 跨域
// Router.Use(middleware.Cors()) // 如需跨域可以打开
// 跨域,如需跨域可以打开下面的注释
// Router.Use(middleware.Cors()) // 直接放行全部跨域请求
//Router.Use(middleware.CorsByRules()) // 按照配置的规则放行跨域请求
global.GVA_LOG.Info("use middleware cors")
Router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
global.GVA_LOG.Info("register swagger handler")
......
package middleware
import (
"net/http"
"github.com/flipped-aurora/gin-vue-admin/server/config"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/gin-gonic/gin"
"net/http"
)
// 处理跨域请求,支持options访问
// Cors 直接放行所有跨域请求并放行所有 OPTIONS 方法
func Cors() gin.HandlerFunc {
return func(c *gin.Context) {
method := c.Request.Method
......@@ -25,3 +26,48 @@ func Cors() gin.HandlerFunc {
c.Next()
}
}
// CorsByRules 按照配置处理跨域请求
func CorsByRules() gin.HandlerFunc {
// 放行全部
if global.GVA_CONFIG.Cors.Mode == "allow-all" {
return Cors()
}
return func(c *gin.Context) {
whitelist := checkCors(c.GetHeader("origin"))
// 通过检查, 添加请求头
if whitelist != nil {
c.Header("Access-Control-Allow-Origin", whitelist.AllowOrigin)
c.Header("Access-Control-Allow-Headers", whitelist.AllowHeaders)
c.Header("Access-Control-Allow-Methods", whitelist.AllowMethods)
c.Header("Access-Control-Expose-Headers", whitelist.ExposeHeaders)
if whitelist.AllowCredentials {
c.Header("Access-Control-Allow-Credentials", "true")
}
}
// 严格白名单模式且未通过检查,直接拒绝处理请求
if whitelist == nil && global.GVA_CONFIG.Cors.Mode == "strict-whitelist" && !(c.Request.Method == "GET" && c.Request.URL.Path == "/health") {
c.AbortWithStatus(http.StatusForbidden)
} else {
// 非严格白名单模式,无论是否通过检查均放行所有 OPTIONS 方法
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
}
}
// 处理请求
c.Next()
}
}
func checkCors(currentOrigin string) *config.CORSWhitelist {
for _, whitelist := range global.GVA_CONFIG.Cors.Whitelist {
// 遍历配置中的跨域头,寻找匹配项
if currentOrigin == whitelist.AllowOrigin {
return &whitelist
}
}
return nil
}
......@@ -21,7 +21,6 @@ type Field struct {
FieldDesc string `json:"fieldDesc"` // 中文名
FieldType string `json:"fieldType"` // Field数据类型
FieldJson string `json:"fieldJson"` // FieldJson
DataType string `json:"dataType"` // 数据库字段类型
DataTypeLong string `json:"dataTypeLong"` // 数据库字段长度
Comment string `json:"comment"` // 数据库字段描述
ColumnName string `json:"columnName"` // 数据库字段
......
......@@ -10,9 +10,9 @@ import (
type {{.StructName}} struct {
global.GVA_MODEL {{- range .Fields}}
{{- if ne .FieldType "string" }}
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}}{{- if .DataType -}};type:{{.DataType}}{{- end }}"`
{{.FieldName}} *{{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}"`
{{- else }}
{{.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 ne .FieldType "string" -}}{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}{{- end -}}{{- end -}}"`
{{.FieldName}} {{.FieldType}} `json:"{{.FieldJson}}" form:"{{.FieldJson}}" gorm:"column:{{.ColumnName}};comment:{{.Comment}};{{- if .DataTypeLong -}}size:{{.DataTypeLong}};{{- end -}}"`
{{- end }} {{- end }}
}
......
......@@ -22,14 +22,14 @@
<el-input v-model="searchInfo.{{.FieldJson}}" placeholder="搜索条件" />
</el-form-item>{{ end }}{{ end }}{{ end }}
<el-form-item>
<el-button size="mini" type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
<el-button size="mini" icon="el-icon-refresh" @click="onReset">重置</el-button>
<el-button size="mini" type="primary" icon="search" @click="onSubmit">查询</el-button>
<el-button size="mini" icon="refresh" @click="onReset">重置</el-button>
</el-form-item>
</el-form>
</div>
<div class="gva-table-box">
<div class="gva-btn-list">
<el-button size="mini" type="primary" icon="el-icon-plus" @click="openDialog">新增</el-button>
<el-button size="mini" type="primary" icon="plus" @click="openDialog">新增</el-button>
<el-popover v-model:visible="deleteVisible" placement="top" width="160">
<p>确定要删除吗?</p>
<div style="text-align: right; margin-top: 8px;">
......@@ -37,7 +37,7 @@
<el-button size="mini" type="primary" @click="onDelete">确定</el-button>
</div>
<template #reference>
<el-button icon="el-icon-delete" size="mini" style="margin-left: 10px;" :disabled="!multipleSelection.length">删除</el-button>
<el-button icon="delete" size="mini" style="margin-left: 10px;" :disabled="!multipleSelection.length">删除</el-button>
</template>
</el-popover>
</div>
......@@ -69,8 +69,8 @@
{{- end }}
<el-table-column align="left" label="按钮组">
<template #default="scope">
<el-button type="text" icon="el-icon-edit" size="small" class="table-button" @click="update{{.StructName}}(scope.row)">变更</el-button>
<el-button type="text" icon="el-icon-delete" size="mini" @click="deleteRow(scope.row)">删除</el-button>
<el-button type="text" icon="edit" size="small" class="table-button" @click="update{{.StructName}}(scope.row)">变更</el-button>
<el-button type="text" icon="delete" size="mini" @click="deleteRow(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
......
......@@ -24,7 +24,7 @@
"screenfull": "^5.0.2",
"script-ext-html-webpack-plugin": "^2.1.4",
"spark-md5": "^3.0.1",
"vue": "^3.2.0",
"vue": "^3.2.25",
"vue-particle-line": "^0.1.4",
"vue-router": "^4.0.0-0",
"vuex": "^4.0.0-0",
......@@ -47,8 +47,8 @@
"eslint-plugin-vue": "^7.0.0",
"sass": "^1.26.5",
"sass-loader": "^8.0.2",
"vite": "2.5.3",
"vite": "2.5.10",
"vite-plugin-banner": "^0.1.3",
"vite-plugin-importer": "^0.2.5"
}
}
\ No newline at end of file
}
......@@ -40,25 +40,8 @@
/>
</el-select>
</el-form-item>
<el-form-item label="数据库字段类型" prop="dataType">
<el-select
v-model="middleDate.dataType"
style="width:100%"
:disabled="!middleDate.fieldType"
placeholder="请选择数据库字段类型"
clearable
>
<el-option
v-for="item in dbfdOptions"
:key="item.label"
:label="item.label"
:value="item.label"
/>
</el-select>
</el-form-item>
<el-form-item label="数据库字段长度" prop="dataTypeLong">
<el-input v-model="middleDate.dataTypeLong" placeholder="自定义类型必须指定长度" :disabled="!middleDate.dataType" />
<el-form-item label="类型长度" prop="dataTypeLong">
<el-input v-model="middleDate.dataTypeLong" placeholder="数据库类型长度" />
</el-form-item>
<el-form-item label="Field查询条件" prop="fieldSearchType">
<el-select
......@@ -97,7 +80,6 @@
</template>
<script>
import { getDict } from '@/utils/dictionary'
import { toLowerCase, toSQLLine } from '@/utils/stringFun'
import { getSysDictionaryList } from '@/api/sysDictionary'
import warningBar from '@/components/warningBar/warningBar.vue'
......@@ -116,7 +98,6 @@ export default {
data() {
return {
middleDate: {},
dbfdOptions: [],
dictOptions: [],
typeSearchOptions: [
{
......@@ -189,25 +170,12 @@ export default {
})
this.dictOptions = dictRes.data.list
this.getDict()
},
methods: {
autoFill() {
this.middleDate.fieldJson = toLowerCase(this.middleDate.fieldName)
this.middleDate.columnName = toSQLLine(this.middleDate.fieldJson)
},
async getDbfdOptions() {
this.middleDate.dataType = ''
this.middleDate.dataTypeLong = ''
this.middleDate.fieldSearchType = ''
this.middleDate.dictType = ''
this.getDict()
},
async getDict() {
if (this.middleDate.fieldType) {
this.dbfdOptions = await getDict(this.middleDate.fieldType)
}
}
}
}
</script>
......@@ -61,7 +61,7 @@
<el-input v-model="form.description" placeholder="中文描述作为自动api描述" />
</el-form-item>
<el-form-item label="文件名称" prop="packageName">
<el-input v-model="form.packageName" placeholder="生成文件的默认名称(建议为驼峰格式,首字母小写,如sysXxxXxxx)" />
<el-input v-model="form.packageName" placeholder="生成文件的默认名称(建议为驼峰格式,首字母小写,如sysXxxXxxx)" @blur="toLowerCase(form,'packageName')" />
</el-form-item>
<el-form-item>
<template #label>
......@@ -92,7 +92,6 @@
<el-table-column align="left" prop="fieldDesc" label="中文名" />
<el-table-column align="left" prop="fieldJson" label="FieldJson" />
<el-table-column align="left" prop="fieldType" label="Field数据类型" width="130" />
<el-table-column align="left" prop="dataType" label="数据库字段类型" width="130" />
<el-table-column align="left" prop="dataTypeLong" label="数据库字段长度" width="130" />
<el-table-column align="left" prop="columnName" label="数据库字段" width="130" />
<el-table-column align="left" prop="comment" label="数据库字段描述" width="130" />
......@@ -182,7 +181,7 @@ const fieldTemplate = {
import FieldDialog from '@/view/systemTools/autoCode/component/fieldDialog.vue'
import PreviewCodeDialog from '@/view/systemTools/autoCode/component/previewCodeDialg.vue'
import { toUpperCase, toHump, toSQLLine } from '@/utils/stringFun'
import { toUpperCase, toHump, toSQLLine, toLowerCase } from '@/utils/stringFun'
import { createTemp, getDB, getTable, getColumn, preview, getMeta } from '@/api/autoCode'
import { getDict } from '@/utils/dictionary'
......@@ -247,6 +246,9 @@ export default {
}
},
methods: {
toLowerCase(form, key) {
form[key] = toLowerCase(form[key])
},
selectText() {
this.$refs.preview.selectText()
},
......@@ -324,6 +326,11 @@ export default {
}
this.$refs.autoCodeForm.validate(async valid => {
if (valid) {
for (const key in this.form) {
if (typeof this.form[key] === 'string') {
this.form[key] = this.form[key].trim()
}
}
this.form.structName = toUpperCase(this.form.structName)
if (this.form.tableName) { this.form.tableName = this.form.tableName.replace(' ', '') }
if (this.form.structName === this.form.abbreviation) {
......@@ -413,7 +420,7 @@ export default {
fieldType: this.fdMap[item.dataType],
dataType: item.dataType,
fieldJson: fbHump,
dataTypeLong: item.dataTypeLong,
dataTypeLong: item.dataTypeLong && item.dataTypeLong.split(',')[0],
columnName: item.columnName,
comment: item.columnComment,
fieldSearchType: '',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册