@@ -6,10 +6,16 @@ import (
66 "github.com/gogf/gf/v2/errors/gerror"
77 "github.com/gogf/gf/v2/frame/g"
88 "github.com/gogf/gf/v2/os/gtime"
9+ "github.com/samber/lo"
910)
1011
1112var accessMap = map [string ]Access {}
1213
14+ type FieldsGetValue struct {
15+ In map [string ][]string
16+ Out map [string ]string
17+ }
18+
1319type Access struct {
1420 Debug int8
1521 Name string
@@ -26,29 +32,67 @@ type Access struct {
2632
2733 // ext
2834
29- RowKey string
35+ RowKey string
36+ FieldsGet map [string ]FieldsGetValue
37+ }
38+
39+ func (a * Access ) GetFieldsGetOutByRole (role string ) []string {
40+ var fieldsMap map [string ]string
41+
42+ if val , exists := a .FieldsGet [role ]; exists {
43+ fieldsMap = val .Out
44+ } else {
45+ fieldsMap = a .FieldsGet ["default" ].Out
46+ }
47+ return lo .Keys (fieldsMap )
48+ }
49+
50+ func (a * Access ) GetFieldsGetInByRole (role string ) map [string ][]string {
51+ var inFieldsMap map [string ][]string
52+
53+ if val , exists := a .FieldsGet [role ]; exists {
54+ inFieldsMap = val .In
55+ } else {
56+ inFieldsMap = a .FieldsGet ["default" ].In
57+ }
58+
59+ return inFieldsMap
3060}
3161
3262func loadAccessMap () {
3363 _accessMap := make (map [string ]Access )
3464
3565 var accessList []Access
36- g .DB ().Model (config .TableAccess ).Scan (& accessList )
66+
67+ db := g .DB ()
68+
69+ db .Model (config .TableAccess ).Scan (& accessList )
70+
71+ type AccessExt struct {
72+ RowKey string
73+ FieldsGet map [string ]FieldsGetValue
74+ }
3775
3876 for _ , access := range accessList {
3977 name := access .Alias
4078 if name == "" {
4179 name = access .Name
4280 }
81+
82+ var ext * AccessExt
83+ db .Model (config .TableAccessExt ).Where ("table" , access .Name ).Scan (& ext )
84+ if ext != nil {
85+ access .RowKey = ext .RowKey
86+ access .FieldsGet = ext .FieldsGet
87+ }
88+
4389 _accessMap [name ] = access
4490 }
4591
4692 accessMap = _accessMap
4793}
4894
4995func GetAccess (table string , accessVerify bool ) (* Access , error ) {
50- // 暂未使用version
51- // 读取配置时将最新的版本额外增加一个@latest的版本, 传入为-1时候, 读取最新版本
5296 access , ok := accessMap [table ]
5397
5498 if ! ok {
@@ -66,8 +110,6 @@ func GetAccess(table string, accessVerify bool) (*Access, error) {
66110}
67111
68112func GetAccessRole (table string , method string ) ([]string , string , error ) {
69- // 暂未使用version
70- // 读取配置时将最新的版本额外增加一个@latest的版本, 传入为-1时候, 读取最新版本
71113 access , ok := accessMap [table ]
72114
73115 if ! ok {
0 commit comments