Skip to content

Commit 8719ced

Browse files
insistencegitee-org
authored andcommitted
!27 Dash-FastAPI-Admin v2.0.0
Merge pull request !27 from insistence/develop
2 parents dd95054 + 662bef9 commit 8719ced

File tree

295 files changed

+25311
-19583
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

295 files changed

+25311
-19583
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ __pycache__/
99
# Distribution / packaging
1010
.Python
1111
develop-eggs/
12+
df_admin/
1213
dist/
1314
downloads/
1415
eggs/

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
<p align="center">
22
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png">
33
</p>
4-
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v1.4.2</h1>
4+
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v2.0.0</h1>
55
<h4 align="center">基于Dash+FastAPI前后端分离的纯Python快速开发框架</h4>
66
<p align="center">
77
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/stargazers"><img src="https://gitee.com/insistence2022/dash-fastapi-admin/badge/star.svg?theme=dark"></a>
88
<a href="https://github.com/insistence/Dash-FastAPI-Admin"><img src="https://img.shields.io/github/stars/insistence/Dash-FastAPI-Admin?style=social"></a>
9-
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v1.4.2-brightgreen.svg"></a>
9+
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v2.0.0-brightgreen.svg"></a>
1010
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
11-
<img src="https://img.shields.io/badge/python-3.8 | 3.9-blue">
11+
<img src="https://img.shields.io/badge/python-3.9-blue">
1212
<img src="https://img.shields.io/badge/MySQL-≥5.7-blue">
1313
</p>
1414

15-
16-
17-
18-
19-
20-
21-
2215
## 平台简介
2316

2417
Dash-FastAPI-Admin是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。
@@ -219,12 +212,15 @@ python3 app.py --env=prod
219212
## 交流与赞助
220213
如果有对本项目及FastAPI感兴趣的朋友,欢迎加入知识星球一起交流学习,让我们一起变得更强。如果你觉得这个项目帮助到了你,你可以请作者喝杯咖啡表示鼓励☕。扫描下面微信二维码添加微信备注DF-Admin即可进群,也欢迎大家加入dash大神费弗里的知识星球学习更多dash开发知识。
221214
<table>
215+
<tr>
216+
<td><img alt="zanzhu_wx" src="https://gitee.com/insistence2022/dash-fastapi-admin/raw/master/demo-pictures/zanzhu_wx.jpg"></td>
217+
<td><img alt="zanzhu_zfb" src="https://gitee.com/insistence2022/dash-fastapi-admin/raw/master/demo-pictures/zanzhu_zfb.jpg"></td>
218+
</tr>
222219
<tr>
223220
<td><img alt="zsxq" src="https://gitee.com/insistence2022/dash-fastapi-admin/raw/master/demo-pictures/zsxq.jpg"></td>
224-
<td><img alt="zanzhu" src="https://gitee.com/insistence2022/dash-fastapi-admin/raw/master/demo-pictures/zanzhu.jpg"></td>
221+
<td><img alt="dashzsxq" src="https://gitee.com/insistence2022/dash-fastapi-admin/raw/master/demo-pictures/dashzsxq.jpg"></td>
225222
</tr>
226223
<tr>
227224
<td><img alt="wxcode" src="https://gitee.com/insistence2022/dash-fastapi-admin/raw/master/demo-pictures/wxcode.jpg"></td>
228-
<td><img alt="dashzsxq" src="https://gitee.com/insistence2022/dash-fastapi-admin/raw/master/demo-pictures/dashzsxq.jpg"></td>
229225
</tr>
230226
</table>

dash-fastapi-backend/.env.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '1.4.2'
13+
APP_VERSION= '2.0.0'
1414
# 应用是否开启热重载
1515
APP_RELOAD = true
1616
# 应用是否开启IP归属区域查询

dash-fastapi-backend/.env.prod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '1.4.2'
13+
APP_VERSION= '2.0.0'
1414
# 应用是否开启热重载
1515
APP_RELOAD = false
1616
# 应用是否开启IP归属区域查询
@@ -37,7 +37,7 @@ DB_PORT = 3306
3737
# 数据库用户名
3838
DB_USERNAME = 'root'
3939
# 数据库密码
40-
DB_PASSWORD = 'mysqlroot'
40+
DB_PASSWORD = 'root'
4141
# 数据库名称
4242
DB_DATABASE = 'dash-fastapi'
4343
# 是否开启sqlalchemy日志

dash-fastapi-backend/app.py

Lines changed: 3 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,12 @@
1-
from fastapi import FastAPI, Request
21
import uvicorn
3-
from fastapi.exceptions import HTTPException
4-
from fastapi.middleware.cors import CORSMiddleware
5-
from module_admin.controller.login_controller import loginController
6-
from module_admin.controller.captcha_controller import captchaController
7-
from module_admin.controller.user_controller import userController
8-
from module_admin.controller.menu_controller import menuController
9-
from module_admin.controller.dept_controller import deptController
10-
from module_admin.controller.role_controller import roleController
11-
from module_admin.controller.post_controler import postController
12-
from module_admin.controller.dict_controller import dictController
13-
from module_admin.controller.config_controller import configController
14-
from module_admin.controller.notice_controller import noticeController
15-
from module_admin.controller.log_controller import logController
16-
from module_admin.controller.online_controller import onlineController
17-
from module_admin.controller.job_controller import jobController
18-
from module_admin.controller.server_controller import serverController
19-
from module_admin.controller.cache_controller import cacheController
20-
from module_admin.controller.common_controller import commonController
21-
from config.env import AppConfig
22-
from config.get_redis import RedisUtil
23-
from config.get_db import init_create_table
24-
from config.get_scheduler import SchedulerUtil
25-
from utils.response_util import *
26-
from utils.log_util import logger
27-
from utils.common_util import worship
2+
from server import app, AppConfig # noqa: F401
283

29-
app = FastAPI(
30-
title=AppConfig.app_name,
31-
description=f'{AppConfig.app_name}接口文档',
32-
version=AppConfig.app_version,
33-
root_path=AppConfig.app_root_path,
34-
)
35-
36-
# 前端页面url
37-
origins = [
38-
"http://localhost:8088",
39-
"http://127.0.0.1:8088",
40-
]
41-
42-
# 后台api允许跨域
43-
app.add_middleware(
44-
CORSMiddleware,
45-
allow_origins=origins,
46-
allow_credentials=True,
47-
allow_methods=["*"],
48-
allow_headers=["*"],
49-
)
50-
51-
52-
@app.on_event("startup")
53-
async def startup_event():
54-
logger.info(f"{AppConfig.app_name}开始启动")
55-
worship()
56-
await init_create_table()
57-
app.state.redis = await RedisUtil.create_redis_pool()
58-
await RedisUtil.init_sys_dict(app.state.redis)
59-
await RedisUtil.init_sys_config(app.state.redis)
60-
await SchedulerUtil.init_system_scheduler()
61-
logger.info(f"{AppConfig.app_name}启动成功")
62-
63-
64-
@app.on_event("shutdown")
65-
async def shutdown_event():
66-
await RedisUtil.close_redis_pool(app)
67-
await SchedulerUtil.close_system_scheduler()
68-
69-
70-
# 自定义token检验异常
71-
@app.exception_handler(AuthException)
72-
async def auth_exception_handler(request: Request, exc: AuthException):
73-
return response_401(data=exc.data, message=exc.message)
74-
75-
76-
# 自定义权限检验异常
77-
@app.exception_handler(PermissionException)
78-
async def permission_exception_handler(request: Request, exc: PermissionException):
79-
return response_403(data=exc.data, message=exc.message)
80-
81-
82-
@app.exception_handler(HTTPException)
83-
async def http_exception_handler(request: Request, exc: HTTPException):
84-
return JSONResponse(
85-
content=jsonable_encoder({"message": exc.detail, "code": exc.status_code}),
86-
status_code=exc.status_code
87-
)
88-
89-
90-
app.include_router(loginController, prefix="/login", tags=['登录模块'])
91-
app.include_router(captchaController, prefix="/captcha", tags=['验证码模块'])
92-
app.include_router(userController, prefix="/system", tags=['系统管理-用户管理'])
93-
app.include_router(menuController, prefix="/system", tags=['系统管理-菜单管理'])
94-
app.include_router(deptController, prefix="/system", tags=['系统管理-部门管理'])
95-
app.include_router(roleController, prefix="/system", tags=['系统管理-角色管理'])
96-
app.include_router(postController, prefix="/system", tags=['系统管理-岗位管理'])
97-
app.include_router(dictController, prefix="/system", tags=['系统管理-字典管理'])
98-
app.include_router(configController, prefix="/system", tags=['系统管理-参数管理'])
99-
app.include_router(noticeController, prefix="/system", tags=['系统管理-通知公告管理'])
100-
app.include_router(logController, prefix="/system", tags=['系统管理-日志管理'])
101-
app.include_router(onlineController, prefix="/monitor", tags=['系统监控-在线用户'])
102-
app.include_router(jobController, prefix="/monitor", tags=['系统监控-定时任务'])
103-
app.include_router(serverController, prefix="/monitor", tags=['系统监控-服务监控'])
104-
app.include_router(cacheController, prefix="/monitor", tags=['系统监控-缓存监控'])
105-
app.include_router(commonController, prefix="/common", tags=['通用模块'])
1064

1075
if __name__ == '__main__':
1086
uvicorn.run(
1097
app='app:app',
1108
host=AppConfig.app_host,
1119
port=AppConfig.app_port,
112-
reload=AppConfig.app_reload
10+
root_path=AppConfig.app_root_path,
11+
reload=AppConfig.app_reload,
11312
)
-197 KB
Binary file not shown.
-211 KB
Binary file not shown.
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
class CommonConstant:
2+
"""
3+
常用常量
4+
5+
WWW: www主域
6+
HTTP: http请求
7+
HTTPS: https请求
8+
LOOKUP_RMI: RMI远程方法调用
9+
LOOKUP_LDAP: LDAP远程方法调用
10+
LOOKUP_LDAPS: LDAPS远程方法调用
11+
YES: 是否为系统默认(是)
12+
NO: 是否为系统默认(否)
13+
DEPT_NORMAL: 部门正常状态
14+
DEPT_DISABLE: 部门停用状态
15+
UNIQUE: 校验是否唯一的返回标识(是)
16+
NOT_UNIQUE: 校验是否唯一的返回标识(否)
17+
"""
18+
19+
WWW = 'www.'
20+
HTTP = 'http://'
21+
HTTPS = 'https://'
22+
LOOKUP_RMI = 'rmi:'
23+
LOOKUP_LDAP = 'ldap:'
24+
LOOKUP_LDAPS = 'ldaps:'
25+
YES = 'Y'
26+
NO = 'N'
27+
DEPT_NORMAL = '0'
28+
DEPT_DISABLE = '1'
29+
UNIQUE = True
30+
NOT_UNIQUE = False
31+
32+
33+
class HttpStatusConstant:
34+
"""
35+
返回状态码
36+
37+
SUCCESS: 操作成功
38+
CREATED: 对象创建成功
39+
ACCEPTED: 请求已经被接受
40+
NO_CONTENT: 操作已经执行成功,但是没有返回数据
41+
MOVED_PERM: 资源已被移除
42+
SEE_OTHER: 重定向
43+
NOT_MODIFIED: 资源没有被修改
44+
BAD_REQUEST: 参数列表错误(缺少,格式不匹配)
45+
UNAUTHORIZED: 未授权
46+
FORBIDDEN: 访问受限,授权过期
47+
NOT_FOUND: 资源,服务未找到
48+
BAD_METHOD: 不允许的http方法
49+
CONFLICT: 资源冲突,或者资源被锁
50+
UNSUPPORTED_TYPE: 不支持的数据,媒体类型
51+
ERROR: 系统内部错误
52+
NOT_IMPLEMENTED: 接口未实现
53+
WARN: 系统警告消息
54+
"""
55+
56+
SUCCESS = 200
57+
CREATED = 201
58+
ACCEPTED = 202
59+
NO_CONTENT = 204
60+
MOVED_PERM = 301
61+
SEE_OTHER = 303
62+
NOT_MODIFIED = 304
63+
BAD_REQUEST = 400
64+
UNAUTHORIZED = 401
65+
FORBIDDEN = 403
66+
NOT_FOUND = 404
67+
BAD_METHOD = 405
68+
CONFLICT = 409
69+
UNSUPPORTED_TYPE = 415
70+
ERROR = 500
71+
NOT_IMPLEMENTED = 501
72+
WARN = 601
73+
74+
75+
class JobConstant:
76+
"""
77+
定时任务常量
78+
79+
JOB_ERROR_LIST: 定时任务禁止调用模块及违规字符串列表
80+
JOB_WHITE_LIST: 定时任务允许调用模块列表
81+
"""
82+
83+
JOB_ERROR_LIST = [
84+
'app',
85+
'config',
86+
'exceptions',
87+
'import ',
88+
'middlewares',
89+
'module_admin',
90+
'open(',
91+
'os.',
92+
'server',
93+
'sub_applications',
94+
'subprocess.',
95+
'sys.',
96+
'utils',
97+
'while ',
98+
'__import__',
99+
'"',
100+
"'",
101+
',',
102+
'?',
103+
':',
104+
';',
105+
'/',
106+
'|',
107+
'+',
108+
'-',
109+
'=',
110+
'~',
111+
'!',
112+
'#',
113+
'$',
114+
'%',
115+
'^',
116+
'&',
117+
'*',
118+
'<',
119+
'>',
120+
'(',
121+
')',
122+
'[',
123+
']',
124+
'{',
125+
'}',
126+
' ',
127+
]
128+
JOB_WHITE_LIST = ['module_task']
129+
130+
131+
class MenuConstant:
132+
"""
133+
菜单常量
134+
135+
TYPE_DIR: 菜单类型(目录)
136+
TYPE_MENU: 菜单类型(菜单)
137+
TYPE_BUTTON: 菜单类型(按钮)
138+
YES_FRAME: 是否菜单外链(是)
139+
NO_FRAME: 是否菜单外链(否)
140+
LAYOUT: Layout组件标识
141+
PARENT_VIEW: ParentView组件标识
142+
INNER_LINK: InnerLink组件标识
143+
"""
144+
145+
TYPE_DIR = 'M'
146+
TYPE_MENU = 'C'
147+
TYPE_BUTTON = 'F'
148+
YES_FRAME = 0
149+
NO_FRAME = 1
150+
LAYOUT = 'Layout'
151+
PARENT_VIEW = 'ParentView'
152+
INNER_LINK = 'InnerLink'
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
from sqlalchemy import create_engine
2-
from sqlalchemy.ext.declarative import declarative_base
3-
from sqlalchemy.orm import sessionmaker
1+
from sqlalchemy.ext.asyncio import create_async_engine
2+
from sqlalchemy.ext.asyncio import async_sessionmaker
3+
from sqlalchemy.ext.asyncio import AsyncAttrs
4+
from sqlalchemy.orm import DeclarativeBase
45
from urllib.parse import quote_plus
56
from config.env import DataBaseConfig
67

7-
SQLALCHEMY_DATABASE_URL = f"mysql+pymysql://{DataBaseConfig.db_username}:{quote_plus(DataBaseConfig.db_password)}@" \
8-
f"{DataBaseConfig.db_host}:{DataBaseConfig.db_port}/{DataBaseConfig.db_database}"
8+
ASYNC_SQLALCHEMY_DATABASE_URL = (
9+
f'mysql+asyncmy://{DataBaseConfig.db_username}:{quote_plus(DataBaseConfig.db_password)}@'
10+
f'{DataBaseConfig.db_host}:{DataBaseConfig.db_port}/{DataBaseConfig.db_database}'
11+
)
912

10-
engine = create_engine(
11-
SQLALCHEMY_DATABASE_URL,
13+
async_engine = create_async_engine(
14+
ASYNC_SQLALCHEMY_DATABASE_URL,
1215
echo=DataBaseConfig.db_echo,
1316
max_overflow=DataBaseConfig.db_max_overflow,
1417
pool_size=DataBaseConfig.db_pool_size,
1518
pool_recycle=DataBaseConfig.db_pool_recycle,
16-
pool_timeout=DataBaseConfig.db_pool_timeout
19+
pool_timeout=DataBaseConfig.db_pool_timeout,
1720
)
18-
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
19-
Base = declarative_base()
21+
AsyncSessionLocal = async_sessionmaker(autocommit=False, autoflush=False, bind=async_engine)
22+
23+
24+
class Base(AsyncAttrs, DeclarativeBase):
25+
pass

0 commit comments

Comments
 (0)