11import dash
22from dash import dcc
3+ import feffery_utils_components as fuc
34from flask import session
45import time
56from dash .dependencies import Input , Output , State
1112# 页首右侧个人中心选项卡回调
1213@app .callback (
1314 [Output ('dcc-url' , 'pathname' , allow_duplicate = True ),
14- Output ('logout-modal' , 'visible' )],
15+ Output ('logout-modal' , 'visible' ),
16+ Output ('layout-setting-drawer' , 'visible' )],
1517 Input ('index-header-dropdown' , 'nClicks' ),
1618 State ('index-header-dropdown' , 'clickedKey' ),
1719 prevent_initial_call = True
@@ -20,16 +22,25 @@ def index_dropdown_click(nClicks, clickedKey):
2022 if clickedKey == '退出登录' :
2123 return [
2224 dash .no_update ,
23- True
25+ True ,
26+ False
2427 ]
2528
2629 elif clickedKey == '个人资料' :
2730 return [
2831 '/user/profile' ,
32+ False ,
2933 False
3034 ]
3135
32- return [dash .no_update ] * 2
36+ elif clickedKey == '布局设置' :
37+ return [
38+ dash .no_update ,
39+ False ,
40+ True
41+ ]
42+
43+ return [dash .no_update ] * 3
3344
3445
3546# 退出登录回调
@@ -62,3 +73,72 @@ def logout_confirm(okCounts):
6273)
6374def reload_page (nClicks ):
6475 return True
76+
77+
78+ # 布局设置回调
79+ @app .callback (
80+ Output ('hex-color-picker' , 'color' , allow_duplicate = True ),
81+ Input ('layout-setting-drawer' , 'visible' ),
82+ State ('custom-app-primary-color-container' , 'data' ),
83+ prevent_initial_call = True
84+ )
85+ def init_hex_color_picker (visible , custom_color ):
86+ if visible :
87+ if custom_color :
88+ return custom_color
89+ return dash .no_update
90+
91+
92+ @app .callback (
93+ [Output ('selected-color-input' , 'value' ),
94+ Output ('selected-color-input' , 'style' )],
95+ Input ('hex-color-picker' , 'color' ),
96+ State ('selected-color-input' , 'style' ),
97+ prevent_initial_call = True
98+ )
99+ def show_selected_color (pick_color , old_style ):
100+
101+ return [
102+ pick_color ,
103+ {
104+ ** old_style ,
105+ 'background' : pick_color
106+ }
107+ ]
108+
109+
110+ @app .callback (
111+ [Output ('custom-app-primary-color-container' , 'data' ),
112+ Output ('hex-color-picker' , 'color' , allow_duplicate = True ),
113+ Output ('global-message-container' , 'children' , allow_duplicate = True )],
114+ [Input ('save-setting' , 'nClicks' ),
115+ Input ('reset-setting' , 'nClicks' )],
116+ [State ('selected-color-input' , 'value' ),
117+ State ('system-app-primary-color-container' , 'data' )],
118+ prevent_initial_call = True
119+ )
120+ def save_rest_layout_setting (save_click , reset_click , picked_color , system_color ):
121+ if save_click or reset_click :
122+ trigger_id = dash .ctx .triggered_id
123+ if trigger_id == 'save-setting' :
124+
125+ return [
126+ picked_color ,
127+ dash .no_update ,
128+ fuc .FefferyFancyMessage ('保存成功' , type = 'success' )
129+ ]
130+
131+ elif trigger_id == 'reset-setting' :
132+
133+ return [
134+ None ,
135+ system_color ,
136+ fuc .FefferyFancyMessage ('重置成功' , type = 'success' )
137+ ]
138+
139+ return [
140+ dash .no_update ,
141+ dash .no_update ,
142+ dash .no_update
143+ ]
144+
0 commit comments