Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

页面新结构和文档 #787

Merged
merged 2 commits into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added api/v1/pages/app/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions api/v1/pages/desktop/app_market.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@


router = routers.FrontRouter(
path=app_market_tag,
path="",
name=app_market_name,
icon='app',
page=app_market_tag,
page=[app_market_tag],
)


Expand Down
4 changes: 3 additions & 1 deletion api/v1/pages/user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
children=[
user_list.router,
],
)
)

# router.change_page_tag('core')
18 changes: 9 additions & 9 deletions api/v1/pages/user/user_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
user_list_name = '用户列表'


router = routers.FrontRouter(
path=user_list_tag,
name='用户管理',
icon='user',
page=user_list_tag,
)


page = pages.FrontPage(
tag=user_list_tag,
name=user_list_name,
Expand Down Expand Up @@ -113,6 +105,14 @@
]
)


router = routers.FrontRouter(
path=user_list_tag,
name='用户管理',
icon='user',
page=page,
)

pages.register_front_pages(page)
pages.register_front_pages(user_create_page)
pages.register_front_pages(user_edit_page)
pages.register_front_pages(user_edit_page)
3 changes: 2 additions & 1 deletion arkid/core/extension/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ def register_front_routers(self, router, primary=''):
self.front_routers.append((router, primary))

def register_front_pages(self, page):
page.tag = self.package + '_' + page.tag
page:core_page.FrontPage
page.add_tag_pre(self.package)

core_page.register_front_pages(page)
self.front_pages.append(page)
Expand Down
2 changes: 1 addition & 1 deletion arkid/core/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def get_openapi_schema(self, path_prefix: Optional[str] = None) -> OpenAPISchema
path_prefix = self.root_path
schema = get_schema(api=self, path_prefix=path_prefix)
schema["routers"] = routers.global_routers
schema["pages"] = pages.global_pages
schema["pages"] = pages.get_global_pages()
# permissions = get_permissions(self)
# schema["permissions"] = permissions

Expand Down
167 changes: 126 additions & 41 deletions arkid/core/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
from collections import OrderedDict
from uuid import uuid4
from enum import Enum
global_pages = []

global_pages = {}

class FrontPageType(Enum):
"""前端页面类型枚举类
Type页面类型 [可扩展]:
>>> 表格型页面 (table)
>>> 表单型页面 (form)
>>> 描述型页面 (description)
>>> 树状型页面 (tree)
>>> 切换型页面 (tabs)- 暂不支持
>>> 列表型页面 (list)- 暂不支持
>>> 卡片型页面 (cards)- 暂不支持
>>> 网格型页面 (grid)- 暂不支持
```
- 表格型页面 (table)
- 表单型页面 (form)
- 描述型页面 (description)
- 树状型页面 (tree)
- 切换型页面 (tabs)- 暂不支持
- 列表型页面 (list)- 暂不支持
- 卡片型页面 (cards)- 暂不支持
- 网格型页面 (grid)- 暂不支持
```
"""
FORM_PAGE = 'form'
TABLE_PAGE = 'table'
Expand All @@ -26,14 +27,14 @@ class FrontPageType(Enum):
CARDS_PAGE = 'cards'
GRID_PAGE = 'grid'

global_tags = []
global_tags = [] # 全局tag列表

def gen_tag(tag:str=None,tag_pre:str=None) -> str:
""" 为页面或者行为生成tag

Args:
tag (str, optional): tag字符串,可指定亦可动态生成. Defaults to None.
tag_pre (str, optional): tag前缀,一般可为插件名称或者其他. Defaults to None.
tag (str, optional): tag字符串,可指定亦可动态生成.
tag_pre (str, optional): tag前缀,一般可为插件名称或者其他.

Returns:
str: tag字符串
Expand All @@ -46,6 +47,44 @@ def gen_tag(tag:str=None,tag_pre:str=None) -> str:

class FrontPage(OrderedDict):
""" 前端页面配置类

Examples:
>>> from arkid.core import pages
>>> from arkid.core.translation import gettext_default as _
>>>
>>> # 申明一个页面
>>> page = pages.FrontPage(
>>> tag="user_list",
>>> name="user_list",
>>> page_type=pages.FrontPageType.TABLE_PAGE,
>>> init_action=pages.FrontAction(
>>> path='/api/v1/tenant/{tenant_id}/users/',
>>> method=pages.FrontActionMethod.GET
>>> )
>>> )
>>> # 添加局部动作
>>> page.add_local_action(
>>> [
>>> pages.FrontAction(
>>> name=_("编辑"),
>>> page=user_edit_page,
>>> icon="icon-edit",
>>> action_type=pages.FrontActionType.OPEN_ACTION
>>> ),
>>> ...
>>> ]
>>> )
>>> # 添加全局动作
>>> page.add_global_action(
>>> [
>>> pages.FrontAction(
>>> name="创建",
>>> page=user_create_page,
>>> icon="icon-create",
>>> action_type=pages.FrontActionType.OPEN_ACTION
>>> )
>>> ]
>>> )
"""
def __init__(self, name:str, page_type:FrontPageType, init_action, tag:str=None, tag_pre:str=None, *args, **kwargs):
"""初始化函数
Expand All @@ -54,8 +93,8 @@ def __init__(self, name:str, page_type:FrontPageType, init_action, tag:str=None,
name (str): 页面名称
page_type (FrontPageType): 页面类型
init_action (FrontAction|OrderedDict): 初始化动作
tag (str, optional): 标识. Defaults to None.
tag_pre (str, optional): 标识前缀. Defaults to None.
tag (str, optional): 标识.
tag_pre (str, optional): 标识前缀.
"""
self["tag"] = gen_tag(tag,tag_pre)
self["name"] = name
Expand Down Expand Up @@ -97,21 +136,33 @@ def add_node_action(self, actions):
actions = list(actions)
if not self.get('node'):
self['node'] = []
self['node'].extend(actions)
self['node'].extend(actions)

def add_tag_pre(self,tag_pre:str):
"""添加标识前缀

用于插件中生成页面时给页面的标识添加前缀

Args:
tag_pre (str): 前缀
"""
self["tag"] = gen_tag(self["tag"],tag_pre)


class FrontActionType(Enum):
"""前端动作类型枚举类

ActionType操作类型 [可扩展]:

>>> direct 直接操作类型
>>> open 打开新页面类型
>>> cancel 取消操作类型
>>> reset 重置表单类型
>>> import 导入数据类型
>>> node 节点点击类型(页面中将隐藏该操作)
>>> url 内外链接类型
>>> password 编辑密码类型
```
- direct 直接操作类型
- open 打开新页面类型
- cancel 取消操作类型
- reset 重置表单类型
- import 导入数据类型
- node 节点点击类型(页面中将隐藏该操作)
- url 内外链接类型
- password 编辑密码类型
```
"""

DIRECT_ACTION = 'direct'
Expand All @@ -124,14 +175,16 @@ class FrontActionType(Enum):
PASSWORD_ACTION = 'password'

class FrontActionMethod(Enum):
"""前端动作类型枚举类
""" 前端动作类型枚举类

ActionMethod 动作方法 [可扩展]:

>>> get
>>> post
>>> put
>>> delete
```
- get
- post
- put
- delete
```
"""

GET = 'get'
Expand All @@ -141,21 +194,39 @@ class FrontActionMethod(Enum):


class FrontAction(OrderedDict):
"""前端页面动作类
""" 前端页面动作类

Examples:
>>> from arkid.core import pages
>>> from arkid.core.translation import gettext_default as _
>>>
>>> edit_action = pages.FrontAction(
>>> name=_("编辑"),
>>> page=user_edit_page,
>>> icon="icon-edit",
>>> action_type=pages.FrontActionType.OPEN_ACTION
>>> )
>>> delete_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
>>> )
"""

def __init__(self, tag:str=None, action_type:FrontActionType=None,name:str=None, page=None, path:str=None, method:FrontActionMethod=None, icon:str=None,tag_pre:str=None, *args, **kwargs):
"""初始化函数

Args:
tag (str, optional): 标识. Defaults to None.
action_type (FrontActionType, optional): 动作类型. Defaults to None.
name (str, optional): 名称. Defaults to None.
page (FrontPage|str, optional): 指向页面,此处存储页面的标识. Defaults to None.
path (str, optional): 请求路径. Defaults to None.
method (FrontActionMethod, optional): 请求方法. Defaults to None.
icon (str, optional): 图标名称. Defaults to None.
tag_pre (str, optional): 标识前缀. Defaults to None.
tag (str, optional): 标识.
action_type (FrontActionType, optional): 动作类型.
name (str, optional): 名称.
page (FrontPage|str, optional): 指向页面,此处存储页面的标识.
path (str, optional): 请求路径.
method (FrontActionMethod, optional): 请求方法.
icon (str, optional): 图标名称.
tag_pre (str, optional): 标识前缀.
"""
self["tag"] = gen_tag(tag,tag_pre)

Expand All @@ -175,6 +246,13 @@ def __init__(self, tag:str=None, action_type:FrontActionType=None,name:str=None,
self["type"] = action_type.value
super().__init__(*args, **kwargs)

def add_tag_pre(self,tag_pre:str):
""" 添加标识前缀

Args:
tag_pre (str): 标识前缀
"""
self["tag"] = gen_tag(self["tag"],tag_pre)

def register_front_pages(pages):
"""注册前端页面
Expand All @@ -184,7 +262,9 @@ def register_front_pages(pages):
"""
if not isinstance(pages, tuple) or not isinstance(pages, list):
pages = [pages]
global_pages.extend(pages)

for page in pages:
global_pages[page["tag"]] = page


def unregister_front_pages(pages):
Expand All @@ -197,4 +277,9 @@ def unregister_front_pages(pages):
pages = [pages]

for page in pages:
global_pages.remove(page)
global_pages.pop(page["tag"])

def get_global_pages():
"""获取页面列表
"""
return list(global_pages.values())
Loading