Skip to content

前端#

根据上述配置信息结构说明,我们需要在后端接口(/api/v1/openapi.json)中对应生成页面配置数据以供前端解析,以下是基础的代码步骤:

创建一个page#

from arkid.core import pages

user_list_tag = 'user_list'
user_list_name = '用户列表'


page = pages.FrontPage(
    tag=user_list_tag,
    name=user_list_name,
    page_type=pages.FrontPageType.TABLE_PAGE,
    init_action=pages.FrontAction(
        path='/api/v1/tenant/{tenant_id}/users/',
        method=pages.FrontActionMethod.GET
    )
)

为page添加action#

...

page.add_local_action(
    [
        pages.FrontAction(
            name=_("删除"),
            method=pages.FrontActionMethod.DELETE,
            path="/api/v1/tenant/{tenant_id}/users/{id}/",
            icon="icon-delete",
            action_type=pages.FrontActionType.DIRECT_ACTION
        )
    ]
)

...

将page注册到全局#

pages.register_front_pages(page)

写入路由信息#

from arkid.core import routers

user_list_router = routers.FrontRouter(
    path="user_list",
    name='用户管理',
    icon='user',
    page=page,
)

router = routers.FrontRouter(
    path='user',
    name='用户管理',
    icon='user',
    children=[
        user_list_router,
    ],
)

最后在访问/api/v1/openapi.json接口时可得到数据为:#

{
  ...
  "routers": [
      {
          "path": "user",
          "name": "用户管理",
          "icon": "user",
          "children": [
              {
                  "path": "user_list",
                  "name": "用户管理",
                  "icon": "user",
                  "page": "user_list"
              }
          ]
      }
  ],
  "pages": [
      {
          "tag": "user_list",
          "name": "用户列表",
          "type": "table",
          "init": {
              "tag": "16058e11df284ae1a58fd1220a85e501",
              "path": "/api/v1/tenant/{tenant_id}/users/",
              "method": "get"
          },
          "local": [
              {
                  "tag": "9181f711ffcb4ac5b5a793e043468595",
                  "name": "删除",
                  "path": "/api/v1/tenant/{tenant_id}/users/{id}/",
                  "method": "delete",
                  "icon": "icon-delete",
                  "type": "direct"
              }
          ],
      },
  ]
}
...

评论