main.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import logging
  2. import flet as ft
  3. from Home import HomePage
  4. from Todo import TodoPage
  5. import plotly.graph_objects as go
  6. from flet.plotly_chart import PlotlyChart
  7. from PlotlyChart import ChartPage
  8. def main(page: ft.Page):
  9. log_format = "%(asctime)s - %(levelname)s - %(message)s"
  10. logging.basicConfig(filename='app.log', level=logging.DEBUG, format=log_format)
  11. logging.info('程序启动')
  12. content = HomePage()
  13. def menu_changed(e):
  14. content.controls.clear()
  15. print("Selected destination:", e.control.selected_index)
  16. if e.control.selected_index == 0:
  17. content.controls.append(HomePage())
  18. elif e.control.selected_index == 1:
  19. # content.controls.append(ft.Text("One!"))
  20. content.controls.append(TodoPage())
  21. elif e.control.selected_index == 2:
  22. content.controls.append(ft.Text("商品库!"))
  23. elif e.control.selected_index == 3:
  24. fig = ChartPage().DrawChart()
  25. # fig.show()
  26. content.controls.append(PlotlyChart(fig, expand=True))
  27. elif e.control.selected_index == 4:
  28. content.controls.append(ft.Text("Setting!"))
  29. page.update()
  30. rail = ft.NavigationRail(
  31. selected_index=0,
  32. label_type=ft.NavigationRailLabelType.ALL,
  33. # extended=True,
  34. min_width=100,
  35. min_extended_width=400,
  36. # leading=ft.FloatingActionButton(icon=ft.icons.CREATE, text="Add"),
  37. group_alignment=-0.9,
  38. destinations=[
  39. ft.NavigationRailDestination(
  40. icon=ft.icons.HOME, selected_icon=ft.icons.HOME, label="首页"
  41. ),
  42. ft.NavigationRailDestination(
  43. icon_content=ft.Icon(ft.icons.FAVORITE),
  44. selected_icon_content=ft.Icon(name=ft.icons.FAVORITE, color=ft.colors.PINK),
  45. label="关键词",
  46. ),
  47. ft.NavigationRailDestination(
  48. icon_content=ft.Icon(ft.icons.SHOPIFY),
  49. selected_icon_content=ft.Icon(name=ft.icons.SHOPIFY, color=ft.colors.PINK),
  50. label="商品库",
  51. ),
  52. ft.NavigationRailDestination(
  53. icon_content=ft.Icon(ft.icons.BAR_CHART),
  54. selected_icon_content=ft.Icon(name=ft.icons.BAR_CHART, color=ft.colors.PINK),
  55. label="数据分析",
  56. ),
  57. ft.NavigationRailDestination(
  58. icon=ft.icons.SETTINGS_OUTLINED,
  59. selected_icon_content=ft.Icon(ft.icons.SETTINGS),
  60. label_content=ft.Text("Settings"),
  61. ),
  62. ],
  63. on_change=menu_changed,
  64. )
  65. page.title = 'First App'
  66. page.add(
  67. ft.Row(
  68. [
  69. rail,
  70. ft.VerticalDivider(width=1),
  71. content,
  72. ],
  73. expand=True,
  74. )
  75. )
  76. ft.app(target=main)