@@ -30,11 +30,16 @@ type nodeHandler interface {
3030 nodeType () int
3131}
3232
33+ type Page struct {
34+ Count int
35+ Page int
36+ }
37+
3338type Node struct {
3439 ctx context.Context
3540 queryContext * Query
3641
37- // 当前节点key Todos
42+ // 当前节点key Todos, 如果Todo[], 保存为Todo
3843 Key string
3944 // 当前节点path -> []/Todos
4045 Path string
@@ -43,7 +48,8 @@ type Node struct {
4348
4449 // 是否为列表节点
4550 isList bool
46- page model.Map // 分页参数
51+
52+ page * Page // 分页参数
4753
4854 // 访问当前节点的角色
4955 role string
@@ -104,28 +110,23 @@ func newNode(query *Query, key string, path string, nodeReq any) *Node {
104110 finish : false ,
105111 }
106112
107- // 节点类型判断
108- k , isList := util .ParseNodeKey (key )
113+ node .Key , node .isList = parseNodeKey (key , path )
109114
110- if util .IsFirstUp (k ) { // 大写开头, 为查询节点(对应数据库)
115+ // 节点类型判断
116+ if util .IsFirstUp (node .Key ) { // 大写开头, 为查询节点(对应数据库)
111117 node .Type = NodeTypeQuery
112- } else if strings .HasSuffix (k , consts .RefKeySuffix ) {
118+ } else if strings .HasSuffix (node . Key , consts .RefKeySuffix ) {
113119 node .Type = NodeTypeRef
114- } else if strings .HasSuffix (k , consts .FunctionsKeySuffix ) {
120+ } else if strings .HasSuffix (node . Key , consts .FunctionsKeySuffix ) {
115121 node .Type = NodeTypeFunc
116122 } else {
117123 node .Type = NodeTypeStruct // 结构节点下应该必须存在查询节点
118124
119125 if query .NoAccessVerify == false {
120- if lo .Contains (query .DbMeta .GetTableNameList (), k ) {
126+ if lo .Contains (query .DbMeta .GetTableNameList (), node . Key ) {
121127 node .Type = NodeTypeQuery
122128 }
123129 }
124-
125- }
126-
127- if isList || strings .HasSuffix (filepath .Dir (path ), consts .ListKeySuffix ) {
128- node .isList = true
129130 }
130131
131132 switch node .Type {
@@ -151,6 +152,20 @@ func newNode(query *Query, key string, path string, nodeReq any) *Node {
151152 return node
152153}
153154
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+
154169func (n * Node ) buildChild () error {
155170
156171 if n .Type == NodeTypeQuery && ! util .HasFirstUpKey (n .req ) { // 查询节点嵌套查询节点, 目前不支持
@@ -176,7 +191,7 @@ func (n *Node) buildChild() error {
176191 }
177192
178193 if n .isList {
179- if lo .Contains ([]string {"total" , "page" }, key ) {
194+ if lo .Contains ([]string {consts . Total , consts . Page }, key ) {
180195 continue
181196 }
182197 }
@@ -226,6 +241,23 @@ func (n *Node) parse() {
226241 g .Log ().Debugf (n .ctx , "【node】(%s) <parse> " , n .Path )
227242 }
228243
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+
229261 n .nodeHandler .parse ()
230262
231263 if n .queryContext .PrintProcessLog {
0 commit comments