增加权限管理

This commit is contained in:
hoteas 2022-07-21 00:24:39 +08:00
parent 9cfdfbac78
commit f7410200e3
2 changed files with 53 additions and 35 deletions

View File

@ -677,6 +677,10 @@ func setMakeCodeLintener(name string, appIns *Application) {
return isFinished
}
if context.RouterString[1] == "hotime" && context.RouterString[2] == "config" {
return isFinished
}
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
context.Display(2, "你还没有登录")
return true

76
code.go
View File

@ -453,13 +453,13 @@ var TptProject = Proj{
hotimeName := that.RouterString[0]
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
if that.Session(fileConfig.GetString("table")+"_id").Data == nil {
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
if err != nil {
that.Display(4, "找不到配置文件")
return
}
if that.Session(fileConfig.GetString("table")+"_id").Data == nil {
conf := ObjToMap(string(btes))
delete(conf, "menus")
@ -468,17 +468,11 @@ var TptProject = Proj{
that.Display(0, conf)
return
}
btes, err := ioutil.ReadFile(fileConfig.GetString("config"))
if err != nil {
that.Display(4, "找不到配置文件")
}
//可读写配置
conf := ObjToMap(string(btes))
menus := conf.GetSlice("menus")
user := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": fileConfig.GetString("table") + "_id"})
user := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").Data})
if user == nil {
that.Display(2, "暂未登录")
@ -497,14 +491,14 @@ var TptProject = Proj{
for k1, _ := range menus {
v1 := menus.GetMap(k1)
if linkAuth[v1.GetString("name")] != nil {
v1["auth"] = linkAuth[v1.GetString("name")]
if linkAuth[v1.GetString("table")] != nil {
v1["auth"] = linkAuth[v1.GetString("table")]
}
for k2, _ := range v1.GetSlice("menus") {
v1menus := v1.GetSlice("menus")
for k2, _ := range v1menus {
v2 := menus.GetMap(k2)
if linkAuth[v2.GetString("name")] != nil {
v2["auth"] = linkAuth[v2.GetString("name")]
if linkAuth[v2.GetString("table")] != nil {
v2["auth"] = linkAuth[v2.GetString("table")]
}
}
}
@ -515,37 +509,57 @@ var TptProject = Proj{
userAuth := user.GetMap("auth")
for k1, _ := range menus {
v1 := menus.GetMap(k1)
if userAuth[v1.GetString("name")] != nil {
v1["auth"] = userAuth[v1.GetString("name")]
if userAuth[v1.GetString("table")] != nil {
v1["auth"] = userAuth[v1.GetString("table")]
}
for k2, _ := range v1.GetSlice("menus") {
v2 := menus.GetMap(k2)
if userAuth[v2.GetString("name")] != nil {
v2["auth"] = userAuth[v2.GetString("name")]
v1menus := v1.GetSlice("menus")
for k2, _ := range v1menus {
v2 := v1menus.GetMap(k2)
if userAuth[v2.GetString("table")] != nil {
v2["auth"] = userAuth[v2.GetString("table")]
}
}
}
//不可读写数据
config := DeepCopyMap(that.MakeCodeRouter[hotimeName].Config).(Map)
config["menus"] = menus
newTables := Map{}
for k1, _ := range menus {
v1 := menus.GetMap(k1)
if config.GetMap("tables").GetMap(v1.GetString("name")) != nil {
newTables[v1.GetString("name")] = config.GetMap("tables").GetMap(v1.GetString("name"))
if config.GetMap("tables").GetMap(v1.GetString("table")) != nil {
newTables[v1.GetString("name")] = config.GetMap("tables").GetMap(v1.GetString("table"))
}
v1menus := v1.GetSlice("menus")
for k2, _ := range v1.GetSlice("menus") {
v2 := menus.GetMap(k2)
if config.GetMap("tables").GetMap(v2.GetString("name")) != nil {
newTables[v2.GetString("name")] = config.GetMap("tables").GetMap(v2.GetString("name"))
v2 := v1menus.GetMap(k2)
if config.GetMap("tables").GetMap(v2.GetString("table")) != nil {
//有自定义配置文件
if conf.GetMap("tables") != nil && conf.GetMap("tables").GetMap(v2.GetString("table")) != nil {
columns := config.GetMap("tables").GetMap(v2.GetString("table")).GetSlice("columns")
columnsConf := conf.GetMap("tables").GetMap(v2.GetString("table")).GetSlice("columns")
for k3, _ := range columns {
v3 := columns.GetMap(k3)
for k4, _ := range columnsConf {
v4 := columnsConf.GetMap(k4)
if v3.GetString("name") == v4.GetString("name") {
columns[k3] = columnsConf[k4]
break
}
}
}
}
newTables[v2.GetString("table")] = config.GetMap("tables").GetMap(v2.GetString("table"))
}
}
}
config["tables"] = menus
config["tables"] = newTables
that.Display(0, config)
},