自定义标题和图标

This commit is contained in:
ljmwkx
2025-01-20 14:10:47 +08:00
parent 677841d0ca
commit 47d91a2189
9 changed files with 176 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models
+20
View File
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
{
'license': 'LGPL-3',
'name': "自定义窗口标题和图标",
'summary': "自定义窗口标题和图标",
'version': '1.0',
'depends': ['base_setup'],
'data': [
'templates/web_layout.xml',
'views/res_config.xml',
],
'assets': {
'web.assets_backend': [
'keke_window_title/static/src/js/keke_window_title.js',
],
},
'installable': True,
'auto_install': False,
'application': False,
}
+5
View File
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
from . import ir_ui_view
from . import res_config
from . import res_company
+18
View File
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
import logging
from odoo import api, fields, models, _
_logger = logging.getLogger(__name__)
class View(models.Model):
_inherit = 'ir.ui.view'
@api.model
def _render_template(self, template, values=None):
if template in ['web.login', 'web.webclient_bootstrap']:
if not values:
values = {}
values["title"] = self.env['ir.config_parameter'].sudo().get_param("web.base.title", "")
return super(View, self)._render_template(template, values)
+20
View File
@@ -0,0 +1,20 @@
from odoo import models, fields
class ResCompany(models.Model):
_inherit = 'res.company'
#----------------------------------------------------------
# Fields
#----------------------------------------------------------
favicon = fields.Binary(
string="Company Favicon",
attachment=True
)
background_image = fields.Binary(
string='Apps Menu Background Image',
attachment=True
)
+34
View File
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
import logging
from odoo import api, fields, models, _
_logger = logging.getLogger(__name__)
CONFIG_PARAM_KEKE_WINDOW_TITLE = "web.base.title"
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
keke_window_title = fields.Char('Window Title')
theme_favicon = fields.Binary(
related='company_id.favicon',
readonly=False
)
@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
ir_config = self.env['ir.config_parameter'].sudo()
keke_window_title = ir_config.get_param(CONFIG_PARAM_KEKE_WINDOW_TITLE, default='')
res.update(
keke_window_title=keke_window_title
)
return res
def set_values(self):
super(ResConfigSettings, self).set_values()
ir_config = self.env['ir.config_parameter'].sudo()
ir_config.set_param(CONFIG_PARAM_KEKE_WINDOW_TITLE, self.keke_window_title or "")
@@ -0,0 +1,12 @@
/** @odoo-module alias=web.window.title **/
import { WebClient } from "@web/webclient/webclient";
import {patch} from "@web/core/utils/patch";
patch(WebClient.prototype, {
setup() {
const title = document.title;
super.setup();
this.title.setParts({ zopenerp: title });
}
});
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="layout" inherit_id="web.layout">
<xpath expr="//link[@rel='shortcut icon']" position="before">
<t
t-set="x_icon"
t-value="x_icon or '/web/image/res.company/%s/favicon' % request.env.company.id"
/>
</xpath>
</template>
</odoo>
+51
View File
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.web.window.title</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
<field name="arch" type="xml">
<div id="languages" position="before">
<h2>窗口设置</h2>
<div class="row mt16 o_settings_container" name="window">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<span class="o_form_label">窗口标题</span>
<div class="text-muted">
自定义 Web 窗口标题
</div>
<div class="content-group">
<div class="mt16 row">
<label for="keke_window_title" string="标题" class="col-3 col-lg-3 o_light_label"/>
<field name="keke_window_title" class="oe_inline"/>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_right_pane">
<span class="o_form_label">窗口图标</span>
<div class="text-muted">
自定义 Web 窗口图标
</div>
<div class="content-group">
<div class="mt16 row">
<label for="theme_favicon" string="图标" class="col-3 col-lg-3 o_light_label"/>
<field name="theme_favicon" widget="image" class="ml-4 oe_avatar oe_inline"/>
</div>
</div>
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
</div>
</div>
</div>
</field>
</record>
</data>
</odoo>