页面操作

如果要在表单提交后将用户重定向到另一个页面,则可以在窗体的 on_submit 回调中返回页面操作:

def on_detail():
    return NavigateTo('/detail')

AdminUI 支持 NavigateToNotification 作为页面操作:

class adminui.NavigateTo(url='/')

页面操作:将用户导航到其他页面

参数:url – 新页面的 URL
class adminui.Notification(title='', text=None, type='default')

向用户发送右上角通知

参数:
  • title – 通知的标题
  • text – 通知的文本正文
  • type – default | success | info | warning | error: type of the notification box

If you want to combine two actions together, return a list. Say you want to notify the user twice:

return [
    Notification('A Notification', 'the content of the notification'),
    Notification('A Notification', 'the content of the notification'),
]

除了表单提交之外,您还可以在其他元素(如按钮被点击时)上使用页面操作。

class adminui.Button(title='Go', style=None, icon=None, on_click=None, link_to=None, id=None)

在页面上创建常规按钮

参数:
  • title – 按钮上显示的标题
  • style – 设置为”主”按钮(蓝色大按钮)
  • icon – 按钮标题前面的图标。有关字符串值,请参阅https://ant.design/components/icon/
  • on_click – 单击按钮时将调用自定义函数

您可以在按钮的on_click回调中使用页面操作。

Update page content in Page Actions

If you wish to change a part of the page in Page Actions, first identify the element with id attribute:

@app.page('/', 'Control Page')
def control_page():
    return [
        Card(content=[
            Button('Change Content', on_click=on_change_content),
            Button('Change Element', on_click=on_change_self),
        ]),
        Card(id='detail_card'),
        Card('Paragraph Card', [
            Paragraph('This is the original content', id='paragraph')
        ])
    ]

Then during a page action, you may return a ReplaceElement to replace an element with another:

def on_change_self():
    return ReplaceElement('paragraph', Paragraph('This element has been changed'))

Thus when users click the button “Change Element”, a new paragraph will replace the old one.

You may also choose to update some attributes of an element. The following code changes the content value of “detail_card” element when the users click the “Change Content” button.:

return UpdateElement('detail_card', content=[
        DetailGroup('Refund Request', content=[
            DetailItem('Ordre No.', 1100000),
            DetailItem('Status', "Fetched"),
            DetailItem('Shipping No.', 1234567),
            DetailItem('Sub Order', 1135456)
        ]),
    ])

Use a timer

Use timer, to let your Python function run every some seconds. You can also return Page Actions in the timer’s on_fire function:

@app.page('/', 'Detail Page')
def detail_page():
    return [
        Timer(on_fire=on_timer_fire, data='hello timer'),
        ...
    ]

Timers can be set at any position of the page. To remove a timer, replace it with ReplaceElement page action.

See example_page_actions.py for the complete example. https://github.com/bigeyex/python-adminui/blob/master/python/example_page_actions.py