diff --git a/application.go b/application.go index c391914..d6a1c0b 100644 --- a/application.go +++ b/application.go @@ -405,7 +405,7 @@ func (that *Application) crossDomain(context *Context) { header := context.Resp.Header() //header.Set("Access-Control-Allow-Origin", "*") - header.Set("Access-Control-Allow-Methods", "*") + header.Set("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PUT,DELETE") header.Set("Access-Control-Allow-Credentials", "true") header.Set("Access-Control-Expose-Headers", "*") header.Set("Access-Control-Allow-Headers", "X-Requested-With,Content-Type,Access-Token") diff --git a/code/config.go b/code/config.go index 2ffc727..8fd83bb 100644 --- a/code/config.go +++ b/code/config.go @@ -87,6 +87,6 @@ var ColumnNameType = []ColumnShow{ {"file", false, true, true, false, "file", false}, {"age", false, true, true, false, "", false}, {"email", false, true, true, false, "", false}, - {"time", true, false, false, false, "", false}, + {"time", true, false, true, false, "", false}, {"level", false, false, true, false, "", false}, } diff --git a/code/makecode.go b/code/makecode.go index 855a292..af94b97 100644 --- a/code/makecode.go +++ b/code/makecode.go @@ -203,7 +203,7 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) { } for _, v := range ColumnNameType { - if (v.Strict && coloum.GetString("name") == v.Name) || strings.Contains(coloum.GetString("name"), v.Name) { + if (v.Strict && coloum.GetString("name") == v.Name) || (!v.Strict && strings.Contains(coloum.GetString("name"), v.Name)) { //全部都不需要则不加入 if v.Edit == false && v.List == false && v.Info == false { coloum["notUse"] = true @@ -386,11 +386,12 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) { //字段有动词前缀,自动进行解析 prefixColumn := strings.Index(oldTableName, "_") + //sys_org_id oldTableName即为sys此处判断为org表存在 + if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil { oldTableName = oldTableName[prefixColumn+1:] } - //如果依然找不到则查询system_org是否存在 if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil { oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:] @@ -404,7 +405,7 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) { if prefix > 0 { //表模块前缀sys_user sys即为前缀 sys_org tableName = fk[:prefix+1] + oldTableName - if that.TableConfig[tableName] == nil { + if that.TableConfig[tableName] == nil || that.TableConfig[oldTableName] != nil { //不存在则改为org tableName = oldTableName } @@ -486,7 +487,7 @@ func (that *MakeCode) Info(table string) string { continue } if v.Get("info") == nil || v.GetBool("info") { - reStr += v.GetString("name") + "," + reStr += "`" + v.GetString("name") + "`," } } if len(reStr) != 0 { @@ -502,11 +503,17 @@ func (that *MakeCode) Add(table string, req *http.Request) Map { continue } if v.Get("add") == nil || v.GetBool("add") { - reqValue := req.FormValue(v.GetString("name")) - if reqValue == "" { + + if len(req.Form[v.GetString("name")]) == 0 { return nil } - data[v.GetString("name")] = reqValue + reqValue := req.FormValue(v.GetString("name")) + if reqValue == "" && strings.Contains(v.GetString("name"), "id") { + data[v.GetString("name")] = nil + } else { + data[v.GetString("name")] = reqValue + } + } } if len(data) == 0 { diff --git a/db/hotimedb.go b/db/hotimedb.go index 902ff27..809a76b 100644 --- a/db/hotimedb.go +++ b/db/hotimedb.go @@ -582,11 +582,11 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) { } if x == len(condition) && y == len(vcond) { - if reflect.ValueOf(v).Type().String() == "common.Slice" && len(v.(Slice)) == 0 { + if v != nil && reflect.ValueOf(v).Type().String() == "common.Slice" && len(v.(Slice)) == 0 { continue } - if reflect.ValueOf(v).Type().String() == "[]interface {}" && len(v.([]interface{})) == 0 { + if v != nil && reflect.ValueOf(v).Type().String() == "[]interface {}" && len(v.([]interface{})) == 0 { continue } diff --git a/example/main.go b/example/main.go index 94cf62d..5bc4741 100644 --- a/example/main.go +++ b/example/main.go @@ -18,6 +18,7 @@ func main() { appIns := hotime.Init("config/config.json") //RESTfull接口适配 appIns.SetConnectListener(func(context *hotime.Context) bool { + //文件上传接口 if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" {