节点角标通知
节点角标通知能在组件节点右上角显示一个信息,用于提示组件使用者进行某些未完成的配置,待配置完成可以隐藏通知信息。
!!! info "提示"
节点角标通知功能在 sdk 0.18.14 之后支持,最低的算盘版本为3.7(项目定制的3.6.5-weichai版本亦支持),两者需同时满足。
示例
import suanpan
from suanpan.app import app
from suanpan.app.arguments import String
from suanpan import g
from suanpan.node_badge import node_badge
node_badge.add_notification('first', content='需要配置')
node_badge.add_notification('second', content='配置完成')
@app.afterInit
def init(context):
g.count = 0
@app.input(String(key="inputData1"))
@app.output(String(key="outputData1"))
def HelloWorld(context):
args = context.args
# 在此处编辑用户自定义代码
g.count += 1
if g.count % 2 == 1:
node_badge.show_notification('first')
node_badge.hide_notification('second')
else:
node_badge.hide_notification('first')
node_badge.show_notification('second')
return f"Hello World! {g.count}"
if __name__ == "__main__":
suanpan.run(app)
说明
node_badge
有 3 个方法:
1 . add_notification(name, content=None, title='配置项', pin=True, order=' ')
增加一个名称为 name 的通知,content 是要显示的内容,title 是显示标题,pin 是否置顶(目前前端未实现)
2 . show_notification(name, content=None)
在节点上显示名称为 name 的通知,content 是要显示的内容
3 . hide_notification(name)
隐藏名称为 name 的通知