@@ -30,11 +30,16 @@ type nodeHandler interface {
30
30
nodeType () int
31
31
}
32
32
33
+ type Page struct {
34
+ Count int
35
+ Page int
36
+ }
37
+
33
38
type Node struct {
34
39
ctx context.Context
35
40
queryContext * Query
36
41
37
- // 当前节点key Todos
42
+ // 当前节点key Todos, 如果Todo[], 保存为Todo
38
43
Key string
39
44
// 当前节点path -> []/Todos
40
45
Path string
@@ -43,7 +48,8 @@ type Node struct {
43
48
44
49
// 是否为列表节点
45
50
isList bool
46
- page model.Map // 分页参数
51
+
52
+ page * Page // 分页参数
47
53
48
54
// 访问当前节点的角色
49
55
role string
@@ -104,28 +110,23 @@ func newNode(query *Query, key string, path string, nodeReq any) *Node {
104
110
finish : false ,
105
111
}
106
112
107
- // 节点类型判断
108
- k , isList := util .ParseNodeKey (key )
113
+ node .Key , node .isList = parseNodeKey (key , path )
109
114
110
- if util .IsFirstUp (k ) { // 大写开头, 为查询节点(对应数据库)
115
+ // 节点类型判断
116
+ if util .IsFirstUp (node .Key ) { // 大写开头, 为查询节点(对应数据库)
111
117
node .Type = NodeTypeQuery
112
- } else if strings .HasSuffix (k , consts .RefKeySuffix ) {
118
+ } else if strings .HasSuffix (node . Key , consts .RefKeySuffix ) {
113
119
node .Type = NodeTypeRef
114
- } else if strings .HasSuffix (k , consts .FunctionsKeySuffix ) {
120
+ } else if strings .HasSuffix (node . Key , consts .FunctionsKeySuffix ) {
115
121
node .Type = NodeTypeFunc
116
122
} else {
117
123
node .Type = NodeTypeStruct // 结构节点下应该必须存在查询节点
118
124
119
125
if query .NoAccessVerify == false {
120
- if lo .Contains (query .DbMeta .GetTableNameList (), k ) {
126
+ if lo .Contains (query .DbMeta .GetTableNameList (), node . Key ) {
121
127
node .Type = NodeTypeQuery
122
128
}
123
129
}
124
-
125
- }
126
-
127
- if isList || strings .HasSuffix (filepath .Dir (path ), consts .ListKeySuffix ) {
128
- node .isList = true
129
130
}
130
131
131
132
switch node .Type {
@@ -151,6 +152,20 @@ func newNode(query *Query, key string, path string, nodeReq any) *Node {
151
152
return node
152
153
}
153
154
155
+ func parseNodeKey (inK string , path string ) (k string , isList bool ) {
156
+ k = inK
157
+ if strings .HasSuffix (k , consts .ListKeySuffix ) {
158
+ isList = true
159
+ k = k [0 : len (k )- len (consts .ListKeySuffix )]
160
+ } else {
161
+ if strings .HasSuffix (filepath .Dir (path ), consts .ListKeySuffix ) { // parent is []
162
+ isList = true
163
+ }
164
+ }
165
+
166
+ return
167
+ }
168
+
154
169
func (n * Node ) buildChild () error {
155
170
156
171
if n .Type == NodeTypeQuery && ! util .HasFirstUpKey (n .req ) { // 查询节点嵌套查询节点, 目前不支持
@@ -176,7 +191,7 @@ func (n *Node) buildChild() error {
176
191
}
177
192
178
193
if n .isList {
179
- if lo .Contains ([]string {"total" , "page" }, key ) {
194
+ if lo .Contains ([]string {consts . Total , consts . Page }, key ) {
180
195
continue
181
196
}
182
197
}
@@ -226,6 +241,23 @@ func (n *Node) parse() {
226
241
g .Log ().Debugf (n .ctx , "【node】(%s) <parse> " , n .Path )
227
242
}
228
243
244
+ if n .isList {
245
+ page := & Page {}
246
+ if v , exists := n .req [consts .Page ]; exists {
247
+ page .Page = gconv .Int (v )
248
+ }
249
+ if v , exists := n .req [consts .Count ]; exists {
250
+ page .Count = gconv .Int (v )
251
+ }
252
+ if v , exists := n .req [consts .Query ]; exists {
253
+ switch gconv .String (v ) {
254
+ case "1" , "2" :
255
+ n .needTotal = true
256
+ }
257
+ }
258
+ n .page = page
259
+ }
260
+
229
261
n .nodeHandler .parse ()
230
262
231
263
if n .queryContext .PrintProcessLog {
0 commit comments