增加权限管理
This commit is contained in:
+86
-70
@@ -27,7 +27,7 @@ type MakeCode struct {
|
||||
|
||||
func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
isMake := false
|
||||
hasConfigFile := false
|
||||
//hasConfigFile := false
|
||||
idSlice := Slice{}
|
||||
that.FileConfig = config
|
||||
if that.TableColumns == nil {
|
||||
@@ -38,25 +38,25 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
}
|
||||
|
||||
//加载配置文件
|
||||
btes, err := ioutil.ReadFile(config.GetString("config"))
|
||||
|
||||
//btes, err := ioutil.ReadFile(config.GetString("config"))
|
||||
var err error
|
||||
that.Config = DeepCopyMap(Config).(Map)
|
||||
|
||||
that.Config["name"] = config.GetString("table")
|
||||
if err == nil {
|
||||
cmap := Map{}
|
||||
//文件是否损坏
|
||||
cmap.JsonToMap(string(btes), &that.Error)
|
||||
for k, v := range cmap {
|
||||
that.Config[k] = v //程序配置
|
||||
//Config[k] = v //系统配置
|
||||
}
|
||||
hasConfigFile = true
|
||||
} else {
|
||||
|
||||
that.Error.SetError(errors.New("config配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||
|
||||
}
|
||||
//if err == nil {
|
||||
// cmap := Map{}
|
||||
// //文件是否损坏
|
||||
// cmap.JsonToMap(string(btes), &that.Error)
|
||||
// for k, v := range cmap {
|
||||
// that.Config[k] = v //程序配置
|
||||
// //Config[k] = v //系统配置
|
||||
// }
|
||||
// hasConfigFile = true
|
||||
//} else {
|
||||
//
|
||||
// that.Error.SetError(errors.New("config配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||
//
|
||||
//}
|
||||
//加载规则文件
|
||||
btesRule, errRule := ioutil.ReadFile(config.GetString("rule"))
|
||||
that.RuleConfig = []Map{}
|
||||
@@ -83,7 +83,7 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
that.Error.SetError(errors.New("rule配置文件不存在,或者配置出错,使用缺省默认配置"))
|
||||
}
|
||||
|
||||
//that.IndexMenus = Map{}
|
||||
that.IndexMenus = Map{}
|
||||
//menusConfig := that.Config.GetSlice("menus")
|
||||
////将配置写入到内存中仅作为判断用
|
||||
//if menusConfig != nil {
|
||||
@@ -384,56 +384,56 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
|
||||
//目录没有收录
|
||||
//if !isMenusGet {
|
||||
if !hasConfigFile {
|
||||
tablePrefixCode := strings.Index(fk, "_")
|
||||
isNewPrefix := false //假定表名没有前缀
|
||||
prefixName := ""
|
||||
//并且代表有前缀,根据数据表分库设定使用
|
||||
if tablePrefixCode != -1 {
|
||||
prefixName = fk[:tablePrefixCode]
|
||||
} else {
|
||||
prefixName = fk
|
||||
}
|
||||
//if tablePrefixCode != -1 {
|
||||
for ck, _ := range that.TableColumns {
|
||||
//判断不止一个前缀相同
|
||||
if (strings.Index(ck, prefixName) == 0 || strings.Index(prefixName, ck) == 4) && ck != fk {
|
||||
isNewPrefix = true
|
||||
break
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
prefixName = DefaultMenuParentName + ":" + prefixName
|
||||
|
||||
menuIns := Map{"label": that.TableConfig.GetMap(fk).GetString("label"), "table": fk}
|
||||
//多耗费一点内存
|
||||
mMenu := Map{"menus": Slice{menuIns}, "label": that.TableConfig.GetMap(fk).GetString("label"), "name": prefixName, "icon": "el-icon-setting"}
|
||||
//表名有前缀
|
||||
if !isNewPrefix {
|
||||
//是否已有对应前缀,已经有对应的menu只需要push进去即可
|
||||
prefixName = DefaultMenuParentName
|
||||
mMenu = Map{"menus": Slice{menuIns}, "label": "系统管理", "name": prefixName, "icon": "el-icon-setting"}
|
||||
}
|
||||
//没有新前缀
|
||||
if that.IndexMenus[prefixName] != nil {
|
||||
if that.IndexMenus[prefixName+"/"+fk] == nil {
|
||||
that.IndexMenus.GetMap(prefixName)["menus"] = append(that.IndexMenus.GetMap(prefixName).GetSlice("menus"), menuIns)
|
||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||
} else {
|
||||
for k, v := range menuIns {
|
||||
that.IndexMenus.GetMap(prefixName + "/" + fk)[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
that.Config["menus"] = append(that.Config.GetSlice("menus"), mMenu) //注入配置
|
||||
//写入Index
|
||||
that.IndexMenus[prefixName] = mMenu
|
||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||
//if !hasConfigFile {
|
||||
tablePrefixCode := strings.Index(fk, "_")
|
||||
isNewPrefix := false //假定表名没有前缀
|
||||
prefixName := ""
|
||||
//并且代表有前缀,根据数据表分库设定使用
|
||||
if tablePrefixCode != -1 {
|
||||
prefixName = fk[:tablePrefixCode]
|
||||
} else {
|
||||
prefixName = fk
|
||||
}
|
||||
//if tablePrefixCode != -1 {
|
||||
for ck, _ := range that.TableColumns {
|
||||
//判断不止一个前缀相同
|
||||
if (strings.Index(ck, prefixName) == 0 || strings.Index(prefixName, ck) == 4) && ck != fk {
|
||||
isNewPrefix = true
|
||||
break
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
prefixName = DefaultMenuParentName + ":" + prefixName
|
||||
|
||||
menuIns := Map{"label": that.TableConfig.GetMap(fk).GetString("label"), "table": fk}
|
||||
//多耗费一点内存
|
||||
mMenu := Map{"menus": Slice{menuIns}, "label": that.TableConfig.GetMap(fk).GetString("label"), "name": prefixName, "icon": "el-icon-setting"}
|
||||
//表名有前缀
|
||||
if !isNewPrefix {
|
||||
//是否已有对应前缀,已经有对应的menu只需要push进去即可
|
||||
prefixName = DefaultMenuParentName
|
||||
mMenu = Map{"menus": Slice{menuIns}, "label": "系统管理", "name": prefixName, "icon": "el-icon-setting"}
|
||||
}
|
||||
//没有新前缀
|
||||
if that.IndexMenus[prefixName] != nil {
|
||||
if that.IndexMenus[prefixName+"/"+fk] == nil {
|
||||
that.IndexMenus.GetMap(prefixName)["menus"] = append(that.IndexMenus.GetMap(prefixName).GetSlice("menus"), menuIns)
|
||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||
} else {
|
||||
for k, v := range menuIns {
|
||||
that.IndexMenus.GetMap(prefixName + "/" + fk)[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
that.Config["menus"] = append(that.Config.GetSlice("menus"), mMenu) //注入配置
|
||||
//写入Index
|
||||
that.IndexMenus[prefixName] = mMenu
|
||||
that.IndexMenus[prefixName+"/"+fk] = menuIns
|
||||
}
|
||||
//}
|
||||
|
||||
for k, v := range fv {
|
||||
|
||||
@@ -566,12 +566,28 @@ func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
|
||||
}
|
||||
}
|
||||
|
||||
//写入配置文件
|
||||
//err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t")
|
||||
if !hasConfigFile {
|
||||
//配置文件
|
||||
if config.GetString("configDB") != "" {
|
||||
|
||||
that.Config["id"] = id
|
||||
_ = os.MkdirAll(filepath.Dir(config.GetString("configDB")), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("configDB"), []byte(that.Config.ToJsonString()), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
that.Logger.Warn("新建")
|
||||
|
||||
}
|
||||
|
||||
//不存在配置文件则生成,存在则不管
|
||||
_, err = ioutil.ReadFile(config.GetString("config"))
|
||||
if err != nil {
|
||||
|
||||
that.Config["id"] = id
|
||||
_ = os.MkdirAll(filepath.Dir(config.GetString("config")), os.ModeDir)
|
||||
err = ioutil.WriteFile(config.GetString("config"), []byte(that.Config.ToJsonString()), os.ModePerm)
|
||||
newConfig := DeepCopyMap(that.Config).(Map)
|
||||
delete(newConfig, "tables")
|
||||
err = ioutil.WriteFile(config.GetString("config"), []byte(newConfig.ToJsonString()), os.ModePerm)
|
||||
if err != nil {
|
||||
that.Error.SetError(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user