diff --git a/README.md b/README.md index 108aed0883f0e2d0f84a15f679c87e9a0107b60e..bf347a475d54fe35c57a37ad5cd5c7d4056a4947 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@

logo

-

Dash-FastAPI-Admin v1.0.9

+

Dash-FastAPI-Admin v1.0.10

基于Dash+FastAPI前后端分离的纯Python快速开发框架

- + @@ -20,6 +20,12 @@ Dash-FastAPI-Admin是一套全部开源的快速开发平台,毫无保留给 * 后端采用FastAPI、sqlalchemy、MySQL、Redis、OAuth2 & Jwt。 * 权限认证使用OAuth2 & Jwt,支持多终端认证系统。 * 支持加载动态权限菜单,多方式轻松权限控制。 +* Vue2版本: + - Gitte仓库地址:https://gitee.com/insistence2022/RuoYi-Vue-FastAPI + - GitHub仓库地址:https://github.com/insistence/RuoYi-Vue-FastAPI +* Vue3版本: + - Gitte仓库地址:https://gitee.com/insistence2022/RuoYi-Vue3-FastAPI + - GitHub仓库地址:https://github.com/insistence/RuoYi-Vue3-FastAPI * 特别鸣谢:[RuoYi-Vue](https://gitee.com/y_project/RuoYi-Vue)[feffery-antd-components](https://github.com/CNFeffery/feffery-antd-components)[feffery-utils-components](https://github.com/CNFeffery/feffery-utils-components)。 ## 内置功能 diff --git a/dash-fastapi-backend/config/get_redis.py b/dash-fastapi-backend/config/get_redis.py index c7bc8ec6dfdca02c4670df43e2c4e55699ad8cb0..2890d63c6cfce90a10ac9c5959b9695a35563501 100644 --- a/dash-fastapi-backend/config/get_redis.py +++ b/dash-fastapi-backend/config/get_redis.py @@ -1,4 +1,5 @@ -import aioredis +from redis import asyncio as aioredis +from redis.exceptions import AuthenticationError, TimeoutError, RedisError from module_admin.service.dict_service import DictDataService from module_admin.service.config_service import ConfigService from config.env import RedisConfig @@ -27,7 +28,18 @@ class RedisUtil: encoding="utf-8", decode_responses=True ) - logger.info("redis连接成功") + try: + connection = await redis.ping() + if connection: + logger.info("redis连接成功") + else: + logger.error("redis连接失败") + except AuthenticationError as e: + logger.error(f"redis用户名或密码错误,详细错误信息:{e}") + except TimeoutError as e: + logger.error(f"redis连接超时,详细错误信息:{e}") + except RedisError as e: + logger.error(f"redis连接错误,详细错误信息:{e}") return redis @classmethod diff --git a/dash-fastapi-backend/module_admin/dao/dept_dao.py b/dash-fastapi-backend/module_admin/dao/dept_dao.py index 1686d095467808cba2426858a4cb6121d8864527..32d85abb410a2a184664217c01d8bf15cb9af136 100644 --- a/dash-fastapi-backend/module_admin/dao/dept_dao.py +++ b/dash-fastapi-backend/module_admin/dao/dept_dao.py @@ -86,12 +86,10 @@ class DeptDao: SysDept.parent_id != dept_info.dept_id, SysDept.del_flag == 0, SysDept.status == 0, eval(data_scope_sql)) \ - .all() - dept = cls.get_dept_by_id(db, dept_info.dept_id) - parent = cls.get_dept_by_id(db, dept.parent_id) - dept_result.insert(0, parent) + .order_by(SysDept.order_num) \ + .distinct().all() - return list_format_datetime(list(set(dept_result))) + return list_format_datetime(dept_result) @classmethod def get_children_dept(cls, db: Session, dept_id: int): diff --git a/dash-fastapi-frontend/callbacks/forget_c.py b/dash-fastapi-frontend/callbacks/forget_c.py index 7b12a2bac2794f27515e672612eb52ce949a3d22..9c3ac5f9b2577f58982c9527a44dad83ef3534b1 100644 --- a/dash-fastapi-frontend/callbacks/forget_c.py +++ b/dash-fastapi-frontend/callbacks/forget_c.py @@ -5,6 +5,7 @@ from dash.dependencies import Input, Output, State from dash.exceptions import PreventUpdate from server import app +from utils.common import validate_data_not_empty from api.user import forget_user_pwd_api from api.message import send_message_api @@ -38,7 +39,7 @@ from api.message import send_message_api def forget_auth(nClicks, username, password, password_again, input_captcha, session_id): if nClicks: # 校验全部输入值是否不为空 - if all([username, password, password_again, input_captcha]): + if all(validate_data_not_empty(item) for item in [username, password, password_again, input_captcha]): if password == password_again: try: @@ -107,14 +108,14 @@ def forget_auth(nClicks, username, password, password_again, input_captcha, sess ) return dict( - username_form_status=None if username else 'error', - password_form_status=None if password else 'error', - password_again_form_status=None if password_again else 'error', - captcha_form_status=None if input_captcha else 'error', - username_form_help=None if username else '请输入用户名!', - password_form_help=None if password else '请输入新密码!', - password_again_form_help=None if password_again else '请再次输入新密码!', - captcha_form_help=None if input_captcha else '请输入短信验证码!', + username_form_status=None if validate_data_not_empty(username) else 'error', + password_form_status=None if validate_data_not_empty(password) else 'error', + password_again_form_status=None if validate_data_not_empty(password_again) else 'error', + captcha_form_status=None if validate_data_not_empty(input_captcha) else 'error', + username_form_help=None if validate_data_not_empty(username) else '请输入用户名!', + password_form_help=None if validate_data_not_empty(password) else '请输入新密码!', + password_again_form_help=None if validate_data_not_empty(password_again) else '请再次输入新密码!', + captcha_form_help=None if validate_data_not_empty(input_captcha) else '请输入短信验证码!', submit_loading=False, redirect_container=None, global_message_container=None diff --git a/dash-fastapi-frontend/callbacks/login_c.py b/dash-fastapi-frontend/callbacks/login_c.py index d423bd013541e7b9a8c9f89fdefd9a2723265e7e..e3b2059b075e5878580d0d30951cd2f351e2abb8 100644 --- a/dash-fastapi-frontend/callbacks/login_c.py +++ b/dash-fastapi-frontend/callbacks/login_c.py @@ -6,6 +6,7 @@ from flask import session import time from server import app +from utils.common import validate_data_not_empty from api.login import login_api, get_captcha_image_api @@ -41,7 +42,7 @@ def login_auth(nClicks, username, password, input_captcha, session_id, image_cli if captcha_hidden: input_captcha = 'hidden' # 校验全部输入值是否不为空 - if all([username, password, input_captcha]): + if all(validate_data_not_empty(item) for item in [username, password, input_captcha]): try: user_params = dict(username=username, password=password, captcha=input_captcha, session_id=session_id) @@ -95,12 +96,12 @@ def login_auth(nClicks, username, password, input_captcha, session_id, image_cli ) return dict( - username_form_status=None if username else 'error', - password_form_status=None if password else 'error', - captcha_form_status=None if input_captcha else 'error', - username_form_help=None if username else '请输入用户名!', - password_form_help=None if password else '请输入密码!', - captcha_form_help=None if input_captcha else '请输入验证码!', + username_form_status=None if validate_data_not_empty(username) else 'error', + password_form_status=None if validate_data_not_empty(password) else 'error', + captcha_form_status=None if validate_data_not_empty(input_captcha) else 'error', + username_form_help=None if validate_data_not_empty(username) else '请输入用户名!', + password_form_help=None if validate_data_not_empty(password) else '请输入密码!', + captcha_form_help=None if validate_data_not_empty(input_captcha) else '请输入验证码!', image_click=dash.no_update, submit_loading=False, token=None, diff --git a/dash-fastapi-frontend/callbacks/monitor_c/job_c/job_c.py b/dash-fastapi-frontend/callbacks/monitor_c/job_c/job_c.py index a7aa458f3e8234311b893b157f77d2ade209d03e..24210133a749eecdd9a959aefbe458390b69448b 100644 --- a/dash-fastapi-frontend/callbacks/monitor_c/job_c/job_c.py +++ b/dash-fastapi-frontend/callbacks/monitor_c/job_c/job_c.py @@ -8,6 +8,7 @@ from dash.exceptions import PreventUpdate import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from api.job import get_job_list_api, get_job_detail_api, add_job_api, edit_job_api, execute_job_api, delete_job_api, export_job_list_api from api.dict import query_dict_data_list_api @@ -334,7 +335,7 @@ def job_confirm(confirm_trigger, modal_type, edit_row_info, form_value, form_lab # 获取所有输入表单项对应的value及label form_value_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-2]} form_label_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-1]} - if all([form_value_state.get(k) for k in form_label_output_list]): + if all(validate_data_not_empty(item) for item in [form_value_state.get(k) for k in form_label_output_list]): params_add = form_value_state params_edit = params_add.copy() params_edit['job_id'] = edit_row_info.get('job_id') if edit_row_info else None @@ -374,8 +375,8 @@ def job_confirm(confirm_trigger, modal_type, edit_row_info, form_value, form_lab ) return dict( - form_label_validate_status=[None if form_value_state.get(k) else 'error' for k in form_label_output_list], - form_label_validate_info=[None if form_value_state.get(k) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], + form_label_validate_status=[None if validate_data_not_empty(form_value_state.get(k)) else 'error' for k in form_label_output_list], + form_label_validate_info=[None if validate_data_not_empty(form_value_state.get(k)) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], modal_visible=dash.no_update, operations=dash.no_update, api_check_token_trigger=dash.no_update, diff --git a/dash-fastapi-frontend/callbacks/system_c/config_c.py b/dash-fastapi-frontend/callbacks/system_c/config_c.py index b13305931af0ee7a8cddc196c20ee5576707e772..99a25ac70cc95304d047e7e4c2be39464d390cf9 100644 --- a/dash-fastapi-frontend/callbacks/system_c/config_c.py +++ b/dash-fastapi-frontend/callbacks/system_c/config_c.py @@ -7,6 +7,7 @@ from dash.exceptions import PreventUpdate import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from api.config import get_config_list_api, get_config_detail_api, add_config_api, edit_config_api, delete_config_api, export_config_list_api, refresh_config_api @@ -297,7 +298,7 @@ def add_edit_config_modal(operation_click, button_click, selected_row_keys, clic ), prevent_initial_call=True ) -def dict_type_confirm(confirm_trigger, modal_type, edit_row_info, form_value, form_label): +def config_confirm(confirm_trigger, modal_type, edit_row_info, form_value, form_label): """ 新增或编辑参数设置弹窗确认回调,实现新增或编辑操作 """ @@ -307,7 +308,7 @@ def dict_type_confirm(confirm_trigger, modal_type, edit_row_info, form_value, fo # 获取所有输入表单项对应的value及label form_value_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-2]} form_label_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-1]} - if all([form_value_state.get(k) for k in form_label_output_list]): + if all(validate_data_not_empty(item) for item in [form_value_state.get(k) for k in form_label_output_list]): params_add = form_value_state params_edit = params_add.copy() params_edit['config_id'] = edit_row_info.get('config_id') if edit_row_info else None @@ -347,8 +348,8 @@ def dict_type_confirm(confirm_trigger, modal_type, edit_row_info, form_value, fo ) return dict( - form_label_validate_status=[None if form_value_state.get(k) else 'error' for k in form_label_output_list], - form_label_validate_info=[None if form_value_state.get(k) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], + form_label_validate_status=[None if validate_data_not_empty(form_value_state.get(k)) else 'error' for k in form_label_output_list], + form_label_validate_info=[None if validate_data_not_empty(form_value_state.get(k)) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], modal_visible=dash.no_update, operations=dash.no_update, api_check_token_trigger=dash.no_update, diff --git a/dash-fastapi-frontend/callbacks/system_c/dept_c.py b/dash-fastapi-frontend/callbacks/system_c/dept_c.py index 57eb7873353df20ad3712db31041a0b03659a6ef..877f587132965a96afc1da825cd97d2411220df9 100644 --- a/dash-fastapi-frontend/callbacks/system_c/dept_c.py +++ b/dash-fastapi-frontend/callbacks/system_c/dept_c.py @@ -6,6 +6,7 @@ from dash.exceptions import PreventUpdate import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from utils.tree_tool import list_to_tree from api.dept import get_dept_tree_api, get_dept_list_api, add_dept_api, edit_dept_api, delete_dept_api, \ get_dept_detail_api, get_dept_tree_for_edit_option_api @@ -304,7 +305,7 @@ def dept_confirm(confirm_trigger, modal_type, edit_row_info, form_value, form_la # 获取所有输入表单项对应的value及label form_value_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-2]} form_label_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-1]} - if all([form_value_state.get(k) for k in form_label_output_list]): + if all(validate_data_not_empty(item) for item in [form_value_state.get(k) for k in form_label_output_list]): params_add = form_value_state params_edit = params_add.copy() params_edit['dept_id'] = edit_row_info.get('dept_id') if edit_row_info else None @@ -344,8 +345,8 @@ def dept_confirm(confirm_trigger, modal_type, edit_row_info, form_value, form_la ) return dict( - form_label_validate_status=[None if form_value_state.get(k) else 'error' for k in form_label_output_list], - form_label_validate_info=[None if form_value_state.get(k) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], + form_label_validate_status=[None if validate_data_not_empty(form_value_state.get(k)) else 'error' for k in form_label_output_list], + form_label_validate_info=[None if validate_data_not_empty(form_value_state.get(k)) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], modal_visible=dash.no_update, operations=dash.no_update, api_check_token_trigger=dash.no_update, diff --git a/dash-fastapi-frontend/callbacks/system_c/dict_c/dict_c.py b/dash-fastapi-frontend/callbacks/system_c/dict_c/dict_c.py index b557febb2de27c7cae0f35ab6167d656397b6b7e..a4698f1cc952e35ad1347d66e48fc38c113c1b24 100644 --- a/dash-fastapi-frontend/callbacks/system_c/dict_c/dict_c.py +++ b/dash-fastapi-frontend/callbacks/system_c/dict_c/dict_c.py @@ -7,6 +7,7 @@ from dash.exceptions import PreventUpdate import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from api.dict import get_dict_type_list_api, get_all_dict_type_api, get_dict_type_detail_api, add_dict_type_api, edit_dict_type_api, delete_dict_type_api, export_dict_type_list_api, refresh_dict_api @@ -311,7 +312,7 @@ def dict_type_confirm(confirm_trigger, modal_type, edit_row_info, form_value, fo # 获取所有输入表单项对应的value及label form_value_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-2]} form_label_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-1]} - if all([form_value_state.get(k) for k in form_label_output_list]): + if all(validate_data_not_empty(item) for item in [form_value_state.get(k) for k in form_label_output_list]): params_add = form_value_state params_edit = params_add.copy() params_edit['dict_id'] = edit_row_info.get('dict_id') if edit_row_info else None @@ -351,8 +352,8 @@ def dict_type_confirm(confirm_trigger, modal_type, edit_row_info, form_value, fo ) return dict( - form_label_validate_status=[None if form_value_state.get(k) else 'error' for k in form_label_output_list], - form_label_validate_info=[None if form_value_state.get(k) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], + form_label_validate_status=[None if validate_data_not_empty(form_value_state.get(k)) else 'error' for k in form_label_output_list], + form_label_validate_info=[None if validate_data_not_empty(form_value_state.get(k)) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], modal_visible=dash.no_update, operations=dash.no_update, api_check_token_trigger=dash.no_update, diff --git a/dash-fastapi-frontend/callbacks/system_c/dict_c/dict_data_c.py b/dash-fastapi-frontend/callbacks/system_c/dict_c/dict_data_c.py index 795cf07d95fdd7964353f0c2c6047f68258f7607..cf4ae9dd3b59a94a61af1a30b3e7fe2eb0fad757 100644 --- a/dash-fastapi-frontend/callbacks/system_c/dict_c/dict_data_c.py +++ b/dash-fastapi-frontend/callbacks/system_c/dict_c/dict_data_c.py @@ -7,6 +7,7 @@ from dash.exceptions import PreventUpdate import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from api.dict import get_dict_data_list_api, get_dict_data_detail_api, add_dict_data_api, edit_dict_data_api, delete_dict_data_api, export_dict_data_list_api @@ -306,7 +307,7 @@ def dict_data_confirm(confirm_trigger, modal_type, edit_row_info, form_value, fo # 获取所有输入表单项对应的value及label form_value_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-2]} form_label_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-1]} - if all([form_value_state.get(k) for k in form_label_output_list]): + if all(validate_data_not_empty(item) for item in [form_value_state.get(k) for k in form_label_output_list]): params_add = form_value_state params_edit = params_add.copy() params_edit['dict_code'] = edit_row_info.get('dict_code') if edit_row_info else None @@ -346,8 +347,8 @@ def dict_data_confirm(confirm_trigger, modal_type, edit_row_info, form_value, fo ) return dict( - form_label_validate_status=[None if form_value_state.get(k) else 'error' for k in form_label_output_list], - form_label_validate_info=[None if form_value_state.get(k) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], + form_label_validate_status=[None if validate_data_not_empty(form_value_state.get(k)) else 'error' for k in form_label_output_list], + form_label_validate_info=[None if validate_data_not_empty(form_value_state.get(k)) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], modal_visible=dash.no_update, operations=dash.no_update, api_check_token_trigger=dash.no_update, diff --git a/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/button_type_c.py b/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/button_type_c.py index 7116953826d51579f7bd1df13efad100a2f4f2b7..a39764c1b2d72b8eee2a3880b6563ff039a1e2bb 100644 --- a/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/button_type_c.py +++ b/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/button_type_c.py @@ -5,6 +5,7 @@ from dash.exceptions import PreventUpdate import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from api.menu import add_menu_api, edit_menu_api @@ -43,7 +44,7 @@ def menu_confirm_button(confirm_trigger, modal_type, edit_row_info, parent_id, m 菜单类型为按钮时新增或编辑弹窗确认回调,实现新增或编辑操作 """ if confirm_trigger: - if all([parent_id, menu_name, order_num]): + if all(validate_data_not_empty(item) for item in [parent_id, menu_name, order_num]): params_add = dict(parent_id=parent_id, menu_type=menu_type, icon=icon, menu_name=menu_name, order_num=order_num, perms=perms) params_edit = dict(menu_id=edit_row_info.get('menu_id') if edit_row_info else None, parent_id=parent_id, menu_type=menu_type, icon=icon, menu_name=menu_name, order_num=order_num, perms=perms) @@ -81,12 +82,12 @@ def menu_confirm_button(confirm_trigger, modal_type, edit_row_info, parent_id, m return dict( form_validate=[ - None if parent_id else 'error', - None if menu_name else 'error', - None if order_num else 'error', - None if parent_id else '请选择上级菜单!', - None if menu_name else '请输入菜单名称!', - None if order_num else '请输入显示排序!' + None if validate_data_not_empty(parent_id) else 'error', + None if validate_data_not_empty(menu_name) else 'error', + None if validate_data_not_empty(order_num) else 'error', + None if validate_data_not_empty(parent_id) else '请选择上级菜单!', + None if validate_data_not_empty(menu_name) else '请输入菜单名称!', + None if validate_data_not_empty(order_num) else '请输入显示排序!' ], modal_visible=dash.no_update, operations=dash.no_update, diff --git a/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/content_type_c.py b/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/content_type_c.py index 967ba75388d7605812963cffa9aaeb5985b10a39..c1404ae466ec693787d1e2f0373395611161c9e5 100644 --- a/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/content_type_c.py +++ b/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/content_type_c.py @@ -5,6 +5,7 @@ from dash.exceptions import PreventUpdate import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from api.menu import add_menu_api, edit_menu_api @@ -48,7 +49,7 @@ def menu_confirm_content(confirm_trigger, modal_type, edit_row_info, parent_id, 菜单类型为目录时新增或编辑弹窗确认回调,实现新增或编辑操作 """ if confirm_trigger: - if all([parent_id, menu_name, order_num, path]): + if all(validate_data_not_empty(item) for item in [parent_id, menu_name, order_num, path]): params_add = dict(parent_id=parent_id, menu_type=menu_type, icon=icon, menu_name=menu_name, order_num=order_num, is_frame=is_frame, path=path, visible=visible, status=status) params_edit = dict(menu_id=edit_row_info.get('menu_id') if edit_row_info else None, parent_id=parent_id, menu_type=menu_type, icon=icon, @@ -87,14 +88,14 @@ def menu_confirm_content(confirm_trigger, modal_type, edit_row_info, parent_id, return dict( form_validate=[ - None if parent_id else 'error', - None if menu_name else 'error', - None if order_num else 'error', - None if path else 'error', - None if parent_id else '请选择上级菜单!', - None if menu_name else '请输入菜单名称!', - None if order_num else '请输入显示排序!', - None if path else '请输入路由地址!', + None if validate_data_not_empty(parent_id) else 'error', + None if validate_data_not_empty(menu_name) else 'error', + None if validate_data_not_empty(order_num) else 'error', + None if validate_data_not_empty(path) else 'error', + None if validate_data_not_empty(parent_id) else '请选择上级菜单!', + None if validate_data_not_empty(menu_name) else '请输入菜单名称!', + None if validate_data_not_empty(order_num) else '请输入显示排序!', + None if validate_data_not_empty(path) else '请输入路由地址!', ], modal_visible=dash.no_update, operations=dash.no_update, diff --git a/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/menu_type_c.py b/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/menu_type_c.py index 8242bb2014aa310a461f2183f111c5dc1b83eef6..2fcb149a836ccbf3fcfbb90e08a42604bcb525f5 100644 --- a/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/menu_type_c.py +++ b/dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/menu_type_c.py @@ -5,6 +5,7 @@ from dash.exceptions import PreventUpdate import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from api.menu import add_menu_api, edit_menu_api @@ -53,7 +54,7 @@ def menu_confirm_menu(confirm_trigger, modal_type, edit_row_info, parent_id, men 菜单类型为菜单时新增或编辑弹窗确认回调,实现新增或编辑操作 """ if confirm_trigger: - if all([parent_id, menu_name, order_num, path]): + if all(validate_data_not_empty(item) for item in [parent_id, menu_name, order_num, path]): params_add = dict(parent_id=parent_id, menu_type=menu_type, icon=icon, menu_name=menu_name, order_num=order_num, is_frame=is_frame, path=path, component=component, perms=perms, query=query, is_cache=is_cache, visible=visible, status=status) params_edit = dict(menu_id=edit_row_info.get('menu_id') if edit_row_info else None, parent_id=parent_id, menu_type=menu_type, icon=icon, @@ -93,14 +94,14 @@ def menu_confirm_menu(confirm_trigger, modal_type, edit_row_info, parent_id, men return dict( form_validate=[ - None if parent_id else 'error', - None if menu_name else 'error', - None if order_num else 'error', - None if path else 'error', - None if parent_id else '请选择上级菜单!', - None if menu_name else '请输入菜单名称!', - None if order_num else '请输入显示排序!', - None if path else '请输入路由地址!' + None if validate_data_not_empty(parent_id) else 'error', + None if validate_data_not_empty(menu_name) else 'error', + None if validate_data_not_empty(order_num) else 'error', + None if validate_data_not_empty(path) else 'error', + None if validate_data_not_empty(parent_id) else '请选择上级菜单!', + None if validate_data_not_empty(menu_name) else '请输入菜单名称!', + None if validate_data_not_empty(order_num) else '请输入显示排序!', + None if validate_data_not_empty(path) else '请输入路由地址!' ], modal_visible=dash.no_update, operations=dash.no_update, diff --git a/dash-fastapi-frontend/callbacks/system_c/notice_c.py b/dash-fastapi-frontend/callbacks/system_c/notice_c.py index 79bb7d6602fcfa36e6774caa057c9868015470b5..74b3bb9449f90fa4b3d8f6422cff9975697e77b9 100644 --- a/dash-fastapi-frontend/callbacks/system_c/notice_c.py +++ b/dash-fastapi-frontend/callbacks/system_c/notice_c.py @@ -7,6 +7,7 @@ from dash.exceptions import PreventUpdate import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from api.notice import get_notice_list_api, add_notice_api, edit_notice_api, delete_notice_api, get_notice_detail_api from api.dict import query_dict_data_list_api @@ -340,7 +341,7 @@ def notice_confirm(confirm_trigger, modal_type, edit_row_info, notice_title, not 新增或编辑通知公告弹窗确认回调,实现新增或编辑操作 """ if confirm_trigger: - if all([notice_title, notice_type]): + if all(validate_data_not_empty(item) for item in [notice_title, notice_type]): params_add = dict(notice_title=notice_title, notice_type=notice_type, status=status, notice_content=notice_content) params_edit = dict(notice_id=edit_row_info.get('notice_id') if edit_row_info else None, @@ -388,10 +389,10 @@ def notice_confirm(confirm_trigger, modal_type, edit_row_info, notice_title, not ) return dict( - notice_title_form_status=None if notice_title else 'error', - notice_type_form_status=None if notice_type else 'error', - notice_title_form_help=None if notice_title else '请输入公告标题!', - notice_type_form_help=None if notice_type else '请输入公告类型!', + notice_title_form_status=None if validate_data_not_empty(notice_title) else 'error', + notice_type_form_status=None if validate_data_not_empty(notice_type) else 'error', + notice_title_form_help=None if validate_data_not_empty(notice_title) else '请输入公告标题!', + notice_type_form_help=None if validate_data_not_empty(notice_type) else '请输入公告类型!', modal_visible=dash.no_update, operations=dash.no_update, api_check_token_trigger=dash.no_update, diff --git a/dash-fastapi-frontend/callbacks/system_c/post_c.py b/dash-fastapi-frontend/callbacks/system_c/post_c.py index 07712ab632ff930d6a26502cede7398732f08cd5..fa0fd279f07309d572de4818f795afccfd6f7b76 100644 --- a/dash-fastapi-frontend/callbacks/system_c/post_c.py +++ b/dash-fastapi-frontend/callbacks/system_c/post_c.py @@ -7,6 +7,7 @@ from dash.exceptions import PreventUpdate import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from api.post import get_post_list_api, get_post_detail_api, add_post_api, edit_post_api, delete_post_api, export_post_list_api @@ -295,7 +296,7 @@ def post_confirm(confirm_trigger, modal_type, edit_row_info, form_value, form_la # 获取所有输入表单项对应的value及label form_value_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-2]} form_label_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-1]} - if all([form_value_state.get(k) for k in form_label_output_list]): + if all(validate_data_not_empty(item) for item in [form_value_state.get(k) for k in form_label_output_list]): params_add = form_value_state params_edit = params_add.copy() params_edit['post_id'] = edit_row_info.get('post_id') if edit_row_info else None @@ -335,8 +336,8 @@ def post_confirm(confirm_trigger, modal_type, edit_row_info, form_value, form_la ) return dict( - form_label_validate_status=[None if form_value_state.get(k) else 'error' for k in form_label_output_list], - form_label_validate_info=[None if form_value_state.get(k) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], + form_label_validate_status=[None if validate_data_not_empty(form_value_state.get(k)) else 'error' for k in form_label_output_list], + form_label_validate_info=[None if validate_data_not_empty(form_value_state.get(k)) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], modal_visible=dash.no_update, operations=dash.no_update, api_check_token_trigger=dash.no_update, diff --git a/dash-fastapi-frontend/callbacks/system_c/role_c/role_c.py b/dash-fastapi-frontend/callbacks/system_c/role_c/role_c.py index 1d751463e11f76f356bdb3fb1bb4b9dd4427719e..11a9757db7aafa3d630ac77dad187e6e7a0091ae 100644 --- a/dash-fastapi-frontend/callbacks/system_c/role_c/role_c.py +++ b/dash-fastapi-frontend/callbacks/system_c/role_c/role_c.py @@ -8,6 +8,7 @@ import feffery_antd_components as fac import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from api.role import get_role_list_api, get_role_detail_api, add_role_api, edit_role_api, delete_role_api, export_role_list_api from api.menu import get_menu_tree_api @@ -503,7 +504,7 @@ def role_confirm(confirm_trigger, modal_type, edit_row_info, form_value, form_la # 获取所有输入表单项对应的value及label form_value_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[2]} form_label_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[3]} - if all([form_value_state.get(k) for k in form_label_output_list]): + if all(validate_data_not_empty(item) for item in [form_value_state.get(k) for k in form_label_output_list]): menu_half_checked_keys = menu_half_checked_keys if menu_half_checked_keys else [] menu_checked_keys = menu_checked_keys if menu_checked_keys else [] if parent_checked: @@ -550,8 +551,8 @@ def role_confirm(confirm_trigger, modal_type, edit_row_info, form_value, form_la ) return dict( - form_label_validate_status=[None if form_value_state.get(k) else 'error' for k in form_label_output_list], - form_label_validate_info=[None if form_value_state.get(k) else form_label_state.get(k) for k in form_label_output_list], + form_label_validate_status=[None if validate_data_not_empty(form_value_state.get(k)) else 'error' for k in form_label_output_list], + form_label_validate_info=[None if validate_data_not_empty(form_value_state.get(k)) else form_label_state.get(k) for k in form_label_output_list], modal_visible=dash.no_update, operations=dash.no_update, api_check_token_trigger=dash.no_update, diff --git a/dash-fastapi-frontend/callbacks/system_c/user_c/user_c.py b/dash-fastapi-frontend/callbacks/system_c/user_c/user_c.py index d521334a268fe90abe93159dea9562bb44a4f776..d2c6e36581ad9cf62fbee538649a68fb618b82dc 100644 --- a/dash-fastapi-frontend/callbacks/system_c/user_c/user_c.py +++ b/dash-fastapi-frontend/callbacks/system_c/user_c/user_c.py @@ -7,6 +7,7 @@ from dash.exceptions import PreventUpdate import feffery_utils_components as fuc from server import app +from utils.common import validate_data_not_empty from api.dept import get_dept_tree_api from api.user import get_user_list_api, get_user_detail_api, add_user_api, edit_user_api, delete_user_api, reset_user_password_api, batch_import_user_api, download_user_import_template_api, export_user_list_api from api.role import get_role_select_option_api @@ -328,7 +329,7 @@ def usr_add_confirm(add_confirm, post, role, form_value, form_label): form_value_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-2]} form_label_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-1]} - if all([form_value_state.get(k) for k in form_label_output_list]): + if all(validate_data_not_empty(item) for item in [form_value_state.get(k) for k in form_label_output_list]): params = form_value_state params['post_id'] = ','.join(map(str, post)) if post else '' params['role_id'] = ','.join(map(str, role)) if role else '' @@ -354,8 +355,8 @@ def usr_add_confirm(add_confirm, post, role, form_value, form_label): ) return dict( - form_label_validate_status=[None if form_value_state.get(k) else 'error' for k in form_label_output_list], - form_label_validate_info=[None if form_value_state.get(k) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], + form_label_validate_status=[None if validate_data_not_empty(form_value_state.get(k)) else 'error' for k in form_label_output_list], + form_label_validate_info=[None if validate_data_not_empty(form_value_state.get(k)) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], modal_visible=dash.no_update, operations=dash.no_update, api_check_token_trigger=dash.no_update, @@ -482,7 +483,7 @@ def usr_edit_confirm(edit_confirm, edit_row_info, post, role, form_value, form_l form_value_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-2]} form_label_state = {x['id']['index']: x.get('value') for x in dash.ctx.states_list[-1]} - if all([form_value_state.get(k) for k in form_label_output_list]): + if all(validate_data_not_empty(item) for item in [form_value_state.get(k) for k in form_label_output_list]): params = form_value_state params['user_id'] = edit_row_info.get('user_id') if edit_row_info else None params['post_id'] = ','.join(map(str, post)) if post else '' @@ -509,8 +510,8 @@ def usr_edit_confirm(edit_confirm, edit_row_info, post, role, form_value, form_l ) return dict( - form_label_validate_status=[None if form_value_state.get(k) else 'error' for k in form_label_output_list], - form_label_validate_info=[None if form_value_state.get(k) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], + form_label_validate_status=[None if validate_data_not_empty(form_value_state.get(k)) else 'error' for k in form_label_output_list], + form_label_validate_info=[None if validate_data_not_empty(form_value_state.get(k)) else f'{form_label_state.get(k)}不能为空!' for k in form_label_output_list], modal_visible=dash.no_update, operations=dash.no_update, api_check_token_trigger=dash.no_update, diff --git a/dash-fastapi-frontend/utils/common.py b/dash-fastapi-frontend/utils/common.py new file mode 100644 index 0000000000000000000000000000000000000000..dd4e84b360af5bd16747d70f3b34939b8a38a32d --- /dev/null +++ b/dash-fastapi-frontend/utils/common.py @@ -0,0 +1,7 @@ +def validate_data_not_empty(input_data): + """ + 工具方法:根据输入数据校验数据是否不为None和'' + :param input_data: 输入数据 + :return: 校验结果 + """ + return input_data is not None and input_data != '' diff --git a/requirements.txt b/requirements.txt index 469418ae42df4847009dfc42d5ba4fae423ab8a1..41f8638b70b399a0eefae1f1880c05f704ac8835 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,86 +1,23 @@ -aioredis==2.0.1 -anyio==3.6.2 APScheduler==3.10.4 -async-timeout==4.0.2 -bcrypt==4.0.1 -blinker==1.6.2 -Brotli==1.0.9 -certifi==2023.5.7 -cffi==1.15.1 -charset-normalizer==3.1.0 -click==8.1.3 -colorama==0.4.6 -cryptography==40.0.2 dash==2.10.2 -dash-core-components==2.0.0 -dash-html-components==2.0.0 -dash-table==5.0.0 DateTime==5.1 -decorator==5.1.1 -dnspython==2.3.0 -ecdsa==0.18.0 -email-validator==2.0.0.post2 -et-xmlfile==1.1.0 -fastapi==0.95.1 +fastapi[all]==0.95.1 feffery-antd-charts==0.0.1rc17 feffery-antd-components==0.2.11 feffery-markdown-components==0.2.10 feffery-utils-components==0.2.0b12 -Flask==2.2.5 Flask-Compress==1.13 -greenlet==2.0.2 -h11==0.14.0 -httpcore==0.17.0 -httptools==0.5.0 -httpx==0.24.0 -idna==3.4 -importlib-metadata==6.6.0 -itsdangerous==2.1.2 -Jinja2==3.1.2 jsonpath-ng==1.5.3 loguru==0.7.0 -MarkupSafe==2.1.2 -numpy==1.24.3 openpyxl==3.1.2 -orjson==3.8.12 -packaging==23.1 pandas==1.5.3 -passlib==1.7.4 -Pillow==10.0.0 -plotly==5.14.1 -ply==3.11 +passlib[bcrypt]==1.7.4 +Pillow==10.2.0 psutil==5.9.5 -pyasn1==0.5.0 -pycparser==2.21 -pydantic==1.10.7 PyMySQL==1.0.3 -python-dateutil==2.8.2 -python-dotenv==1.0.0 -python-jose==3.3.0 -python-multipart==0.0.6 -pytz==2023.3 -PyYAML==6.0 -redis==4.5.5 +python-jose[cryptography]==3.3.0 +redis==5.0.1 requests==2.30.0 -rsa==4.9 -six==1.16.0 -sniffio==1.3.0 SQLAlchemy==1.4.48 -starlette==0.26.1 -tenacity==8.2.2 -typing_extensions==4.5.0 -tzdata==2023.3 -tzlocal==5.0.1 -ua-parser==0.16.1 -ujson==5.7.0 -urllib3==2.0.2 user-agents==2.2.0 -uvicorn==0.22.0 waitress==2.1.2 -watchfiles==0.19.0 -websockets==11.0.3 -Werkzeug==2.2.3 -win32-setctime==1.1.0 -WTForms==3.0.1 -zipp==3.15.0 -zope.interface==6.0