优化表单生成规则

This commit is contained in:
hoteas 2021-06-11 09:41:23 +08:00
parent 32167d4721
commit cc4d91cdbb
3 changed files with 26 additions and 8 deletions

View File

@ -23,7 +23,7 @@ var Config = Map{
//},
},
}
var DefaultMenuParentName = "system"
var DefaultMenuParentName = "sys"
var ColumnDataType = map[string]string{
//sqlite专有类型

View File

@ -311,30 +311,44 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) {
}
for k, v := range fv {
//虚招后缀是_id结尾的表字段
//虚招后缀是_id结尾的表字段 假设org_id
if len(k) <= 3 || strings.LastIndex(k, "_id") != len(k)-3 {
continue
}
//普通表匹配
//普通表匹配 org_id匹配为org
oldTableName := k[:len(k)-3]
//上级ID匹配
if oldTableName == "parent" {
oldTableName = fk
}
//如果依然找不到则查询system_org是否存在
if that.TableConfig[DefaultMenuParentName+"_"+oldTableName] != nil {
oldTableName = DefaultMenuParentName + "_" + oldTableName
}
//字段有动词前缀,自动进行解析
prefixColumn := strings.Index(oldTableName, "_")
//sys_org_id oldTableName即为sys此处判断为org表存在
if prefixColumn > -1 && that.TableConfig[oldTableName[prefixColumn+1:]] != nil {
oldTableName = oldTableName[prefixColumn+1:]
}
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分比如表sys_user 字段org_id查询不到sys_org表则查询org表
//如果依然找不到则查询system_org是否存在
if prefixColumn > -1 && that.TableConfig[DefaultMenuParentName+"_"+oldTableName[prefixColumn+1:]] != nil {
oldTableName = DefaultMenuParentName + "_" + oldTableName[prefixColumn+1:]
}
//普通方式查询不到,则转换为大型项目模块划分,暂时只支持一级模块划分,
//比如表sys_user 字段org_id查询不到sys_org表则查询org表org表查询不到则查询默认前缀system_org表
//都查询不到则找不到,
prefix := strings.Index(fk, "_")
tableName := oldTableName
if prefix > 0 {
//表模块前缀
//表模块前缀sys_user sys即为前缀 sys_org
tableName = fk[:prefix+1] + oldTableName
if that.TableConfig[tableName] == nil {
//不存在则改为org
tableName = oldTableName
}
//表前缀+去除字段前缀
@ -350,11 +364,15 @@ func (that *MakeCode) Db2JSON(name string, path string, db db.HoTimeDB) {
//如果数据匹配则写入到配置中
if that.TableConfig[tableName] != nil {
v["link"] = tableName
//一般查询name字段如果没有name字段则默认第二个地段
//一般查询name字段或者label字段如果没有name字段则默认第二个地段
if that.TableColumns[tableName]["name"] != nil {
v["value"] = tableName + "." + "name"
break
}
if that.TableColumns[tableName]["label"] != nil {
v["value"] = tableName + "." + "label"
break
}
if len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
v["value"] = tableName + "." + that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")

View File

@ -106,12 +106,12 @@ func (that *HoTimeDB) PageSelect(table string, qu ...interface{}) []Map {
qu = append(qu, Map{"LIMIT": that.limit})
}
if len(qu) == 2 {
temp := qu[1].(Map)
temp := DeepCopyMap(qu[1]).(Map)
temp["LIMIT"] = that.limit
qu[1] = temp
}
if len(qu) == 3 {
temp := qu[2].(Map)
temp := DeepCopyMap(qu[2]).(Map)
temp["LIMIT"] = that.limit
qu[2] = temp
}