from dash import Dash, dcc, html, callback
import dash_bootstrap_components as dbc
import base64
import logging
def get_encoded_image(image_path: str) -> str:
"""获取Base64编码的图像"""
try:
with open(image_path, 'rb') as f:
return base64.b64encode(f.read()).decode('utf-8')
except Exception as e:
logging.error(f"Error encoding image {image_path}: {e}")
return ""
# 导航链接样式
def nav_link_style() -> dict:
"""导航链接样式配置"""
return {
'fontFamily': 'Arial',
'fontSize': '18px',
'marginRight': '30px',
'color': '#6c757d'
}
html.Div([
dbc.Navbar(
[
html.Div(
[
html.Img(
src='data:image/png;base64,"assets/vwklogo.png"',
style={
'height': '40px',
'marginLeft': '100px',
'marginRight': '50px',
'marginTop': '15px',
'marginBottom': '15px'
}
),
dbc.NavLink("Home", href="/home", style=nav_link_style()),
dbc.NavLink("About", href="#", style=nav_link_style()),
dbc.NavLink("Contact", href="#", style=nav_link_style()),
],
className="d-flex align-items-center"
),
html.Div(
[
dbc.Button("LOG IN",
outline=True,
color="secondary",
className="me-3",
style={'minWidth': '120px'}),
dbc.Button("SIGN UP",
outline=True,
color="secondary",
className="me-5",
style={'minWidth': '120px'})
],
className="ms-auto d-flex align-items-center",
style={'marginRight': '80px'}
)
],
color="#f3f5f9",
sticky="top",
className="px-4"
),
dbc.Row([
dbc.Col([
html.Div([
html.H1("Add Robot", style={
'fontSize': 60,
'fontFamily': 'Arial',
'marginTop': '100px',
'marginBottom': '80px'
}),
], style={'marginLeft': '35%'})
], md=6),
dbc.Col([
html.Img(
src=f'data:image/jpeg;base64,{get_encoded_image("assets/robot.jpeg")}',
style={
'width': '580px',
'height': '580px',
'marginTop': '12%',
'borderRadius': '15px'
}
)
], md=6)
]),
])
转成modal格式