@@ -584,31 +584,39 @@ func (p *Template) BuildActionApi(ctx *quark.Context, params []string, uriKey st
584
584
func (p * Template ) BuildFormInitApi (ctx * quark.Context , params []string , uriKey string ) string {
585
585
var (
586
586
paramsUri = ""
587
- api = ""
587
+ api = ctx . Path ()
588
588
)
589
589
590
590
for _ , v := range params {
591
591
paramsUri = paramsUri + v + "=${" + v + "}&"
592
592
}
593
593
594
- // 列表页接口
595
- if ctx .IsIndex () {
596
- api = strings .Replace (ctx .Path (), "/index" , "/action/" + uriKey + "/values" , - 1 )
597
- }
594
+ // 获取api路径
595
+ apiPaths := strings .Split (api , "/" )
598
596
599
- // 创建页接口
600
- if ctx . IsCreating () {
601
- api = strings . Replace ( ctx . Path (), "/create" , "/action/" + uriKey + "/values" , - 1 )
597
+ // 错误路径,直接返回
598
+ if len ( apiPaths ) <= 2 {
599
+ return ""
602
600
}
603
601
604
- // 编辑页接口
605
- if ctx .IsEditing () {
602
+ // 解析数据
603
+ switch apiPaths [len (apiPaths )- 1 ] {
604
+ case "index" :
605
+ // 列表页接口
606
+ api = strings .Replace (api , "/index" , "/action/" + uriKey + "/values" , - 1 )
607
+ case "create" :
608
+ // 创建页接口
609
+ api = strings .Replace (api , "/create" , "/action/" + uriKey + "/values" , - 1 )
610
+ case "edit" :
611
+ // 编辑页接口
606
612
api = strings .Replace (api , "/edit" , "/action/" + uriKey + "/values" , - 1 )
607
- }
608
-
609
- // 详情页接口
610
- if ctx .IsDetail () {
613
+ case "detail" :
614
+ // 详情页接口
611
615
api = strings .Replace (api , "/detail" , "/action/" + uriKey + "/values" , - 1 )
616
+ case "form" :
617
+ // 表单页接口
618
+ lastPath := apiPaths [len (apiPaths )- 2 ]
619
+ api = strings .Replace (api , lastPath + "/form" , "action/" + uriKey + "/values" , - 1 )
612
620
}
613
621
614
622
// 追加参数
0 commit comments