diff --git a/sui/api/request.go b/sui/api/request.go index af060ba7..d5ca7eb7 100644 --- a/sui/api/request.go +++ b/sui/api/request.go @@ -127,6 +127,8 @@ func (r *Request) Render() (string, int, error) { if !dataHitCache { // Request the data + // Copy the script pointer to the request For page backend script execution + r.Request.Script = c.Script data = r.Request.NewData() if c.Data != "" { err = r.Request.ExecStringMerge(data, c.Data) diff --git a/sui/core/context.go b/sui/core/context.go index c7c1b483..4c6c9fb9 100644 --- a/sui/core/context.go +++ b/sui/core/context.go @@ -50,7 +50,7 @@ func (ctx *BuildContext) GetComponents() []string { return []string{} } components := []string{} - for name := range ctx.components { + for _, name := range ctx.components { components = append(components, name) } return components diff --git a/sui/core/parser.go b/sui/core/parser.go index 286eba1a..4140705d 100644 --- a/sui/core/parser.go +++ b/sui/core/parser.go @@ -302,7 +302,7 @@ func (parser *TemplateParser) parseElementComponent(sel *goquery.Selection) { parser.errors = append(parser.errors, err) setError(sel, err) } - parser.sequence = parser.sequence + 1 + parser.sequence = compParser.sequence + 1 } func (parser *TemplateParser) clone(script *Script) *TemplateParser { @@ -365,7 +365,7 @@ func (parser *TemplateParser) transElementNode(sel *goquery.Selection) { } } -// 替换转义字符 +// Escape the text func (parser *TemplateParser) escapeText(content string) string { matches := stmtRe.FindAllStringSubmatch(content, -1) newContent := content diff --git a/sui/core/request.go b/sui/core/request.go index c2c2362c..78163b5f 100644 --- a/sui/core/request.go +++ b/sui/core/request.go @@ -285,6 +285,12 @@ func (r *Request) call(p interface{}) (interface{}, error) { return nil, fmt.Errorf("process name is empty") } + // Call the backend script + if r.Script != nil && strings.HasPrefix(processName, "@") { + method := processName[1:] + return r.Script.Call(r, method, processArgs...) + } + process, err := process.Of(processName, processArgs...) if err != nil { return nil, err diff --git a/sui/core/types.go b/sui/core/types.go index 5d0ed685..3ebf9f29 100644 --- a/sui/core/types.go +++ b/sui/core/types.go @@ -282,6 +282,7 @@ type Request struct { Sid string `json:"sid,omitempty"` Theme any `json:"theme,omitempty"` Locale any `json:"locale,omitempty"` + Script *Script `json:"-"` } // RequestSource is the struct for the request