diff --git a/college/__manifest__.py b/college/__manifest__.py index 450b722..64569c9 100644 --- a/college/__manifest__.py +++ b/college/__manifest__.py @@ -59,6 +59,8 @@ 'web.assets_backend': [ 'college/static/src/scss/college_theme.scss', 'college/static/src/js/hide_company_menu.js', + 'college/static/src/js/portal_indicator.js', + 'college/static/src/xml/portal_indicator.xml', ], 'web.assets_web_dark': [ 'college/static/src/scss/college_theme_dark.scss', diff --git a/college/static/src/js/portal_indicator.js b/college/static/src/js/portal_indicator.js new file mode 100644 index 0000000..50ba951 --- /dev/null +++ b/college/static/src/js/portal_indicator.js @@ -0,0 +1,31 @@ +/** @odoo-module **/ +import { registry } from "@web/core/registry"; +import { user } from "@web/core/user"; +import { Component, onWillStart, useState } from "@odoo/owl"; + +export class PortalIndicator extends Component { + static template = "college.PortalIndicator"; + + setup() { + this.state = useState({ label: "" }); + onWillStart(async () => { + // 顺序:管理员 -> 老师 -> 学生(高权限优先) + if (await user.hasGroup("base.group_system")) { + this.state.label = "管理员端"; + } else if (await user.hasGroup("college.group_teacher")) { + this.state.label = "教师端"; + } else if (await user.hasGroup("college.group_student")) { + this.state.label = "学生端"; + } else { + this.state.label = "用户端"; + } + }); + } +} + +// sequence 越小越靠右(user_menu 是 0)。想贴最右边用负数。 +registry.category("systray").add( + "college.PortalIndicator", + { Component: PortalIndicator }, + { sequence: 1} +); \ No newline at end of file diff --git a/college/static/src/scss/college_theme.scss b/college/static/src/scss/college_theme.scss index 71d66ae..549fad2 100644 --- a/college/static/src/scss/college_theme.scss +++ b/college/static/src/scss/college_theme.scss @@ -275,3 +275,18 @@ display: none !important; } + +// 角色提示徽章:避免被 Odoo 导航栏 .badge 通知样式影响 +.o_college_portal_indicator { + align-self: center; // 在 systray 中垂直居中,不被拉伸/裁切 +} + +.o_portal_badge { + display: inline-block; + padding: 0.2em 0.7em; + font-size: 0.8rem; + line-height: 1.2; + color: #fff; + white-space: nowrap; // 不换行 +} + diff --git a/college/static/src/xml/portal_indicator.xml b/college/static/src/xml/portal_indicator.xml new file mode 100644 index 0000000..cbd745c --- /dev/null +++ b/college/static/src/xml/portal_indicator.xml @@ -0,0 +1,7 @@ + + +
+ +
+
\ No newline at end of file