fix: index.ui用JS动态获取租户品牌数据,替代Jinja DB查询

This commit is contained in:
yumoqing 2026-07-09 12:05:30 +08:00
parent ec51ff30da
commit 0dd7414d06
2 changed files with 23 additions and 7 deletions

View File

@ -1,8 +1,3 @@
{% set userorgid = get_userorgid() %}
{% set sor = db.sqlorContext() %}
{% set org = sor.execute_sql('SELECT orgname, iconid FROM organization WHERE id = ${orgid}$', {'orgid': userorgid}).first() %}
{% set orgname = org.orgname if org and org.orgname else 'OpenComputing' %}
{% set icon = org.iconid if org and org.iconid else 'imgs/ocai.svg' %}
{ {
"widgettype": "VBox", "widgettype": "VBox",
"options": { "options": {
@ -43,17 +38,19 @@
}, },
{ {
"widgettype": "Svg", "widgettype": "Svg",
"id": "tenant_logo",
"options": { "options": {
"css": "sage-logo", "css": "sage-logo",
"rate": 2, "rate": 2,
"url": "{{entire_url('/appbase/show_icon.dspy')}}?id={{icon}}" "url": "{{entire_url('/imgs/ocai.svg')}}"
} }
}, },
{ {
"widgettype": "Title4", "widgettype": "Title4",
"id": "tenant_brand_title",
"options": { "options": {
"css": "sage-brand-title", "css": "sage-brand-title",
"text": "{{orgname}}", "text": "元境",
"fontWeight": "bold", "fontWeight": "bold",
"marginLeft": "8px" "marginLeft": "8px"
} }
@ -111,6 +108,15 @@
"url": "{{entire_url('/rbac/user/user_panel.ui')}}" "url": "{{entire_url('/rbac/user/user_panel.ui')}}"
} }
} }
],
"binds": [
{
"wid": "app",
"event": "user_logined",
"actiontype": "script",
"target": "self",
"script": "fetch('{{entire_url('/tenant_brand_data.dspy')}}').then(r=>r.json()).then(d=>{var l=bricks.getWidgetById('tenant_logo',bricks.app);if(l&&d.iconid)l.opts.url='{{entire_url('/appbase/show_icon.dspy')}}?id='+d.iconid;l.refresh();var t=bricks.getWidgetById('tenant_brand_title',bricks.app);if(t)t.opts.text=d.orgname;t.refresh();})"
}
] ]
}, },
{ {

View File

@ -0,0 +1,10 @@
# 返回租户品牌数据(系统名+图标)
userorgid = await get_userorgid()
env = request._run_ns
async with get_sor_context(env, 'sage') as sor:
orgs = await sor.sqlExe('SELECT orgname, iconid FROM organization WHERE id = ${orgid}$', {'orgid': userorgid})
org = orgs[0] if orgs else None
orgname = org.orgname if org and org.orgname else 'OpenComputing'
iconid = org.iconid if org and org.iconid else ''
result = json.dumps({"orgname": orgname, "iconid": iconid}, ensure_ascii=False)