|
6 | 6 | import feffery_utils_components as fuc |
7 | 7 |
|
8 | 8 | from server import app |
9 | | -from api.cache import get_cache_key_list_api, get_cache_value_api, clear_cache_name_api, clear_cache_key_api |
| 9 | +from api.cache import get_cache_name_list_api, get_cache_key_list_api, get_cache_value_api, clear_cache_name_api, clear_cache_key_api, clear_all_cache_api |
| 10 | + |
| 11 | + |
| 12 | +@app.callback( |
| 13 | + [Output('cache_name-list-table', 'data'), |
| 14 | + Output('cache_name-list-table', 'key'), |
| 15 | + Output('api-check-token', 'data', allow_duplicate=True)], |
| 16 | + Input('refresh-cache_name', 'nClicks'), |
| 17 | + prevent_initial_call=True |
| 18 | +) |
| 19 | +def get_cache_name_list(refresh_click): |
| 20 | + """ |
| 21 | + 刷新键名列表回调 |
| 22 | + """ |
| 23 | + if refresh_click: |
| 24 | + |
| 25 | + cache_name_res = get_cache_name_list_api() |
| 26 | + if cache_name_res.get('code') == 200: |
| 27 | + cache_name_list = cache_name_res.get('data') |
| 28 | + cache_name_data = [{'key': item.get('cache_name'), 'id': index + 1, 'operation': {'type': 'link', 'icon': 'antd-delete'}, **item} for index, item in enumerate(cache_name_list)] |
| 29 | + |
| 30 | + return [ |
| 31 | + cache_name_data, |
| 32 | + str(uuid.uuid4()), |
| 33 | + {'timestamp': time.time()} |
| 34 | + ] |
| 35 | + |
| 36 | + return [ |
| 37 | + dash.no_update, |
| 38 | + dash.no_update, |
| 39 | + {'timestamp': time.time()} |
| 40 | + ] |
| 41 | + |
| 42 | + raise PreventUpdate |
10 | 43 |
|
11 | 44 |
|
12 | 45 | @app.callback( |
|
18 | 51 | ), |
19 | 52 | inputs=dict( |
20 | 53 | cache_name_table_row_click=Input('cache_name-list-table', 'nClicksCell'), |
| 54 | + cache_key_refresh_click=Input('refresh-cache_key', 'nClicks'), |
21 | 55 | operations=Input('cache_list-operations-store', 'data') |
22 | 56 | ), |
23 | 57 | state=dict( |
24 | 58 | cache_name_table_click_row_record=State('cache_name-list-table', 'recentlyCellClickRecord'), |
25 | 59 | ), |
26 | 60 | prevent_initial_call=True |
27 | 61 | ) |
28 | | -def get_cache_key_list(cache_name_table_row_click, operations, cache_name_table_click_row_record): |
| 62 | +def get_cache_key_list(cache_name_table_row_click, cache_key_refresh_click, operations, cache_name_table_click_row_record): |
29 | 63 | """ |
30 | 64 | 获取键名列表回调 |
31 | 65 | """ |
32 | | - if cache_name_table_row_click or operations: |
| 66 | + if cache_name_table_row_click or cache_key_refresh_click or operations: |
33 | 67 |
|
34 | 68 | cache_key_res = get_cache_key_list_api(cache_name=cache_name_table_click_row_record.get('key')) |
35 | 69 | if cache_key_res.get('code') == 200: |
@@ -186,3 +220,52 @@ def clear_cache_key(clear_click, recently_button_clicked_row, cache_name_store, |
186 | 220 | ) |
187 | 221 |
|
188 | 222 | raise PreventUpdate |
| 223 | + |
| 224 | + |
| 225 | +@app.callback( |
| 226 | + output=dict( |
| 227 | + cache_name=Output('cache_name-input', 'value', allow_duplicate=True), |
| 228 | + cache_key=Output('cache_key-input', 'value', allow_duplicate=True), |
| 229 | + cache_value=Output('cache_value-input', 'value', allow_duplicate=True), |
| 230 | + refresh_cache_name=Output('refresh-cache_name', 'nClicks'), |
| 231 | + refresh_cache_key=Output('refresh-cache_key', 'nClicks'), |
| 232 | + api_check_token_trigger=Output('api-check-token', 'data', allow_duplicate=True), |
| 233 | + global_message_container=Output('global-message-container', 'children', allow_duplicate=True) |
| 234 | + ), |
| 235 | + inputs=dict( |
| 236 | + clear_all_click=Input('clear-all-cache', 'nClicks') |
| 237 | + ), |
| 238 | + state=dict( |
| 239 | + refresh_cache_name_click=State('refresh-cache_name', 'nClicks'), |
| 240 | + refresh_cache_key_click=State('refresh-cache_key', 'nClicks') |
| 241 | + ), |
| 242 | + prevent_initial_call=True |
| 243 | +) |
| 244 | +def clear_all_cache(clear_all_click, refresh_cache_name_click, refresh_cache_key_click): |
| 245 | + """ |
| 246 | + 清除所有缓存回调 |
| 247 | + """ |
| 248 | + if clear_all_click: |
| 249 | + clear_all_cache_res = clear_all_cache_api() |
| 250 | + if clear_all_cache_res.get('code') == 200: |
| 251 | + return dict( |
| 252 | + cache_name=None, |
| 253 | + cache_key=None, |
| 254 | + cache_value=None, |
| 255 | + refresh_cache_name=refresh_cache_name_click + 1 if refresh_cache_name_click else 1, |
| 256 | + refresh_cache_key=refresh_cache_key_click + 1 if refresh_cache_key_click else 1, |
| 257 | + api_check_token_trigger={'timestamp': time.time()}, |
| 258 | + global_message_container=fuc.FefferyFancyMessage(clear_all_cache_res.get('message'), type='success') |
| 259 | + ) |
| 260 | + |
| 261 | + return dict( |
| 262 | + cache_name=dash.no_update, |
| 263 | + cache_key=dash.no_update, |
| 264 | + cache_value=dash.no_update, |
| 265 | + refresh_cache_name=dash.no_update, |
| 266 | + refresh_cache_key=dash.no_update, |
| 267 | + api_check_token_trigger={'timestamp': time.time()}, |
| 268 | + global_message_container=fuc.FefferyFancyMessage(clear_all_cache_res.get('message'), type='error') |
| 269 | + ) |
| 270 | + |
| 271 | + raise PreventUpdate |
0 commit comments