From fe085ce8895b0fc93e6c6d544b5f2608f3c944cf Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Fri, 4 Jun 2021 02:57:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E6=8E=A5=E5=85=A5=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=EF=BC=8C=E5=BC=80=E5=A7=8B=E5=87=86?= =?UTF-8?q?=E5=A4=87=E7=94=9F=E6=88=90=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application.go | 18 +++++++++--- code/config.go | 23 +++++++++++++++ context.go | 2 ++ db/{db.go => hotimedb.go} | 0 example/admin/user.go | 56 +++++++++++++++++++++++++++++-------- example/config/config.json | 5 +++- example/config/data.db | Bin 16384 -> 16384 bytes example/main.go | 3 ++ var.go | 9 ++++-- 9 files changed, 96 insertions(+), 20 deletions(-) create mode 100644 code/config.go rename db/{db.go => hotimedb.go} (100%) diff --git a/application.go b/application.go index c654e16..26884ac 100644 --- a/application.go +++ b/application.go @@ -2,6 +2,7 @@ package hotime import ( . "./cache" + "./code" . "./common" . "./db" . "./log" @@ -19,6 +20,7 @@ import ( ) type Application struct { + *code.MakeCode MethodRouter Router ContextBase @@ -307,10 +309,9 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) { unescapeUrl = req.RequestURI } //访问实例 - context := Context{SessionIns: SessionIns{SessionId: sessionId, - HoTimeCache: that.HoTimeCache, - }, - Resp: w, Req: req, Application: that, RouterString: s, Config: that.Config, Db: &that.Db, HandlerStr: unescapeUrl} + context := Context{SessionIns: SessionIns{SessionId: sessionId, HoTimeCache: that.HoTimeCache}, + Resp: w, Req: req, Application: that, RouterString: s, Config: that.Config, Db: &that.Db, + HandlerStr: unescapeUrl} //header默认设置 header := w.Header() header.Set("Content-Type", "text/html; charset=utf-8") @@ -448,6 +449,15 @@ func Init(config string) Application { SetDB(&appIns) appIns.SetCache() + appIns.MakeCode = &code.MakeCode{} + codeConfig := appIns.Config.GetMap("codeConfig") + if codeConfig != nil { + for k, _ := range codeConfig { + appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), appIns.Db) + } + + } + return appIns } diff --git a/code/config.go b/code/config.go new file mode 100644 index 0000000..28d8c3b --- /dev/null +++ b/code/config.go @@ -0,0 +1,23 @@ +package code + +import ( + . "../common" +) + +var Config = Map{ + "name": "HoTimeDashBoard", + "ID": "2f92h3herh23rh2y8", + "label": "HoTime管理平台", + "menu": []Map{ + {"label": "平台首页", "name": "HelloWorld", "icon": "el-icon-s-home"}, + {"label": "测试表格", "table": "table", "icon": "el-icon-suitcase"}, + {"label": "系统管理", "name": "setting", "icon": "el-icon-setting", + "menu": []Map{ + {"label": "用户管理", "table": "user"}, + {"label": "组织管理", "table": "organization"}, + {"label": "角色管理", "table": "role"}, + {"label": "系统设置", "table": "system", "default": "edit"}, + }, + }, + }, +} diff --git a/context.go b/context.go index c7f315c..49ab2c6 100644 --- a/context.go +++ b/context.go @@ -44,6 +44,8 @@ func (that *Context) Display(statu int, data interface{}) { temp["type"] = tpe temp["msg"] = data resp["result"] = temp + //兼容android等需要json转对象的服务 + resp["error"] = temp } else { resp["result"] = data } diff --git a/db/db.go b/db/hotimedb.go similarity index 100% rename from db/db.go rename to db/hotimedb.go diff --git a/example/admin/user.go b/example/admin/user.go index 56378a6..c2418be 100644 --- a/example/admin/user.go +++ b/example/admin/user.go @@ -3,26 +3,58 @@ package admin import ( . "../../../hotime" . "../../../hotime/common" - "fmt" ) var UserCtr = Ctr{ - "info": func(this *Context) { - user := this.Db.Get(this.RouterString[1], "*", Map{"id": this.RouterString[2]}) - this.Display(0, user) + "info": func(that *Context) { + re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]}) + that.Display(0, re) }, - "add": func(this *Context) { + "add": func(that *Context) { + inData := that.MakeCode.Add(that.RouterString[1], that.Req) + if inData == nil { + that.Display(3, "请求参数不足") + return + } + re := that.Db.Insert(that.RouterString[1], inData) - }, - "update": func(this *Context) { + if re == 0 { + that.Display(4, "无法插入对应数据") + return + } + that.Display(0, re) }, - "remove": func(this *Context) { + "update": func(that *Context) { + inData := that.MakeCode.Edit(that.RouterString[1], that.Req) + if inData == nil { + that.Display(3, "没有找到要更新的数据") + return + } + re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]}) + if re == 0 { + that.Display(4, "更新数据失败") + return + } + + that.Display(0, re) }, - "search": func(this *Context) { - user := this.Db.Select(this.RouterString[1], "*") - fmt.Println(user, user[0].GetFloat64("age")) - this.Display(0, user) + "remove": func(that *Context) { + re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]}) + + if re == 0 { + that.Display(4, "删除数据失败") + return + } + that.Display(0, re) + }, + "search": func(that *Context) { + + columnStr, where := that.MakeCode.Search(that.RouterString[1], that.Req) + reData := that.Db.Page(ObjToInt(that.Req.FormValue("page")), ObjToInt(that.Req.FormValue("pageRow"))). + Select(that.RouterString[1], columnStr, where) + + that.Display(0, reData) }, } diff --git a/example/config/config.json b/example/config/config.json index 672855e..53eb4a8 100644 --- a/example/config/config.json +++ b/example/config/config.json @@ -6,6 +6,9 @@ "timeout": 7200 } }, + "codeConfig": { + "admin": "config/app.json" + }, "db": { "sqlite": { "path": "example/config/data.db" @@ -16,7 +19,7 @@ "index.htm" ], "devConfig": { - "admin": "config/app.json" + "admin": "example/config/app.json" }, "error": { "1": "内部系统异常", diff --git a/example/config/data.db b/example/config/data.db index f657161208d0a8f542e3661907cd42ef773c8a2a..b33f3b4f284dd19d9149d55371b07c8f597e8c3f 100644 GIT binary patch delta 115 zcmZo@U~Fh$oFL7}GEv5vk!54T5`GRQ{$~vQpZT9{78JO}ufom5!XU}`Y;NDv*|WvC z89|(