fred-admin 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fred_admin/__init__.py +91 -0
- fred_admin/common/AliyunSms.py +66 -0
- fred_admin/common/Blueprints.py +99 -0
- fred_admin/common/Email.py +23 -0
- fred_admin/common/Extensions.py +319 -0
- fred_admin/common/HandleExcetion.py +204 -0
- fred_admin/common/ImageVerification.py +117 -0
- fred_admin/common/IoTDBClient.py +698 -0
- fred_admin/common/PageSchema.py +65 -0
- fred_admin/common/Response.py +251 -0
- fred_admin/common/Route.py +390 -0
- fred_admin/common/RuntimeHook.py +111 -0
- fred_admin/common/SchedulerLog.py +277 -0
- fred_admin/common/Sqlacodegen.py +170 -0
- fred_admin/common/Swagger.py +77 -0
- fred_admin/common/SystemLog.py +80 -0
- fred_admin/common/Utils.py +1060 -0
- fred_admin/common/WechatLogin.py +97 -0
- fred_admin/common/__init__.py +3 -0
- fred_admin/config/Config.py +104 -0
- fred_admin/config/Logger.py +34 -0
- fred_admin/config/__init__.py +3 -0
- fred_admin/create_module.py +787 -0
- fred_admin/demo/app.py +6 -0
- fred_admin/demo/common/__init__.py +1 -0
- fred_admin/demo/common/config/Config.py +82 -0
- fred_admin/demo/common/config/README.md +8 -0
- fred_admin/demo/common/config/__init__.py +1 -0
- fred_admin/demo/common/config/__pycache__/Config.cpython-312.pyc +0 -0
- fred_admin/demo/common/config/__pycache__/__init__.cpython-312.pyc +0 -0
- fred_admin/demo/common/config/jwt_secret_key +1 -0
- fred_admin/demo/common/config/session_secret_key +1 -0
- fred_admin/demo/common/model/__pycache__/__init__.cpython-312.pyc +0 -0
- fred_admin/demo/common/model/__pycache__/model.cpython-312.pyc +0 -0
- fred_admin/demo/common/model/model.py +274 -0
- fred_admin/demo/demo_.gitignore +42 -0
- fred_admin/demo/modules/__init__.py +1 -0
- fred_admin/demo/modules/admin/README.md +38 -0
- fred_admin/demo/modules/admin/__init__.py +3 -0
- fred_admin/demo/modules/admin/backend/__init__.py +7 -0
- fred_admin/demo/modules/admin/backend/constant/RedisKey.py +10 -0
- fred_admin/demo/modules/admin/backend/controller/AdminAuthController.py +39 -0
- fred_admin/demo/modules/admin/backend/controller/AdminController.py +226 -0
- fred_admin/demo/modules/admin/backend/controller/ApiAuthController.py +93 -0
- fred_admin/demo/modules/admin/backend/controller/ButtonManageController.py +90 -0
- fred_admin/demo/modules/admin/backend/controller/FileController.py +28 -0
- fred_admin/demo/modules/admin/backend/controller/OrganizationController.py +218 -0
- fred_admin/demo/modules/admin/backend/controller/RoleController.py +143 -0
- fred_admin/demo/modules/admin/backend/controller/SystemController.py +112 -0
- fred_admin/demo/modules/admin/backend/controller/SystemLogController.py +63 -0
- fred_admin/demo/modules/admin/backend/controller/TableController.py +175 -0
- fred_admin/demo/modules/admin/backend/controller/__init__.py +55 -0
- fred_admin/demo/modules/admin/backend/schema/AdminSchema.py +356 -0
- fred_admin/demo/modules/admin/backend/schema/ApiAuthSchema.py +72 -0
- fred_admin/demo/modules/admin/backend/schema/AuthMenuSchema.py +79 -0
- fred_admin/demo/modules/admin/backend/schema/ButtonManageSchema.py +98 -0
- fred_admin/demo/modules/admin/backend/schema/OrganizationSchema.py +134 -0
- fred_admin/demo/modules/admin/backend/schema/RoleSchema.py +94 -0
- fred_admin/demo/modules/admin/backend/schema/SystemConfigSchema.py +115 -0
- fred_admin/demo/modules/admin/backend/schema/TableSchema.py +153 -0
- fred_admin/demo/modules/admin/backend/schema/UploadImg.py +35 -0
- fred_admin/demo/modules/admin/backend/schema/__init__.py +0 -0
- fred_admin/demo/modules/admin/backend/schema/__pycache__/AdminSchema.cpython-312.pyc +0 -0
- fred_admin/demo/modules/admin/backend/schema/__pycache__/ApiAuthSchema.cpython-312.pyc +0 -0
- fred_admin/demo/modules/admin/backend/schema/__pycache__/AuthMenuSchema.cpython-312.pyc +0 -0
- fred_admin/demo/modules/admin/backend/schema/__pycache__/ButtonManageSchema.cpython-312.pyc +0 -0
- fred_admin/demo/modules/admin/backend/schema/__pycache__/OrganizationSchema.cpython-312.pyc +0 -0
- fred_admin/demo/modules/admin/backend/schema/__pycache__/RoleSchema.cpython-312.pyc +0 -0
- fred_admin/demo/modules/admin/backend/schema/__pycache__/SystemConfigSchema.cpython-312.pyc +0 -0
- fred_admin/demo/modules/admin/backend/schema/__pycache__/TableSchema.cpython-312.pyc +0 -0
- fred_admin/demo/modules/admin/backend/schema/__pycache__/UploadImg.cpython-312.pyc +0 -0
- fred_admin/demo/modules/admin/backend/schema/__pycache__/__init__.cpython-312.pyc +0 -0
- fred_admin/demo/modules/admin/backend/service/AdminService.py +377 -0
- fred_admin/demo/modules/admin/backend/service/ApiAuthService.py +237 -0
- fred_admin/demo/modules/admin/backend/service/AuthButtonsService.py +155 -0
- fred_admin/demo/modules/admin/backend/service/AuthMenuService.py +265 -0
- fred_admin/demo/modules/admin/backend/service/ButtonManageService.py +386 -0
- fred_admin/demo/modules/admin/backend/service/ButtonManageService.py.broken +113 -0
- fred_admin/demo/modules/admin/backend/service/FileService.py +33 -0
- fred_admin/demo/modules/admin/backend/service/OrganizationService.py +465 -0
- fred_admin/demo/modules/admin/backend/service/RoleService.py +445 -0
- fred_admin/demo/modules/admin/backend/service/SystemConfigService.py +89 -0
- fred_admin/demo/modules/admin/backend/service/SystemLogService.py +142 -0
- fred_admin/demo/modules/admin/backend/service/TableService.py +978 -0
- fred_admin/demo/modules/admin/backend/service/__init__.py +1 -0
- fred_admin/demo/modules/admin/backend/sql/app.db +0 -0
- fred_admin/demo/modules/admin/backend/sql/fred.sql +3780 -0
- fred_admin/demo/modules/admin/frontend/LICENSE +21 -0
- fred_admin/demo/modules/admin/frontend/build/getEnv.ts +46 -0
- fred_admin/demo/modules/admin/frontend/build/plugins.ts +118 -0
- fred_admin/demo/modules/admin/frontend/build/proxy.ts +30 -0
- fred_admin/demo/modules/admin/frontend/commitlint.config.cjs +162 -0
- fred_admin/demo/modules/admin/frontend/demo_editorconfig +15 -0
- fred_admin/demo/modules/admin/frontend/demo_env +15 -0
- fred_admin/demo/modules/admin/frontend/demo_env.development +21 -0
- fred_admin/demo/modules/admin/frontend/demo_env.production +25 -0
- fred_admin/demo/modules/admin/frontend/demo_eslintignore +15 -0
- fred_admin/demo/modules/admin/frontend/demo_eslintrc.cjs +61 -0
- fred_admin/demo/modules/admin/frontend/demo_gitignore +27 -0
- fred_admin/demo/modules/admin/frontend/demo_prettierignore +9 -0
- fred_admin/demo/modules/admin/frontend/demo_prettierrc.cjs +41 -0
- fred_admin/demo/modules/admin/frontend/demo_stylelintignore +4 -0
- fred_admin/demo/modules/admin/frontend/demo_stylelintrc.cjs +40 -0
- fred_admin/demo/modules/admin/frontend/index.html +105 -0
- fred_admin/demo/modules/admin/frontend/lint-staged.config.cjs +8 -0
- fred_admin/demo/modules/admin/frontend/package.json +129 -0
- fred_admin/demo/modules/admin/frontend/pnpm-lock.yaml +11150 -0
- fred_admin/demo/modules/admin/frontend/postcss.config.cjs +5 -0
- fred_admin/demo/modules/admin/frontend/public/logo.png +0 -0
- fred_admin/demo/modules/admin/frontend/public/vue.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/App.vue +44 -0
- fred_admin/demo/modules/admin/frontend/src/api/config/servicePort.ts +2 -0
- fred_admin/demo/modules/admin/frontend/src/api/helper/axiosCancel.ts +57 -0
- fred_admin/demo/modules/admin/frontend/src/api/helper/checkStatus.ts +43 -0
- fred_admin/demo/modules/admin/frontend/src/api/index.ts +167 -0
- fred_admin/demo/modules/admin/frontend/src/api/interface/index.ts +179 -0
- fred_admin/demo/modules/admin/frontend/src/api/model/adminModel.ts +135 -0
- fred_admin/demo/modules/admin/frontend/src/api/model/apiAuthModel.ts +72 -0
- fred_admin/demo/modules/admin/frontend/src/api/model/index.ts +24 -0
- fred_admin/demo/modules/admin/frontend/src/api/model/loginModel.ts +79 -0
- fred_admin/demo/modules/admin/frontend/src/api/model/roleModel.ts +68 -0
- fred_admin/demo/modules/admin/frontend/src/api/model/storeModel.ts +80 -0
- fred_admin/demo/modules/admin/frontend/src/api/model/systemModel.ts +162 -0
- fred_admin/demo/modules/admin/frontend/src/api/model/uploadModel.ts +153 -0
- fred_admin/demo/modules/admin/frontend/src/api/modules/admin.ts +76 -0
- fred_admin/demo/modules/admin/frontend/src/api/modules/apiAuth.ts +53 -0
- fred_admin/demo/modules/admin/frontend/src/api/modules/buttonManage.ts +119 -0
- fred_admin/demo/modules/admin/frontend/src/api/modules/dataBase.ts +60 -0
- fred_admin/demo/modules/admin/frontend/src/api/modules/login.ts +54 -0
- fred_admin/demo/modules/admin/frontend/src/api/modules/organization.ts +123 -0
- fred_admin/demo/modules/admin/frontend/src/api/modules/role.ts +61 -0
- fred_admin/demo/modules/admin/frontend/src/api/modules/store.ts +303 -0
- fred_admin/demo/modules/admin/frontend/src/api/modules/system.ts +125 -0
- fred_admin/demo/modules/admin/frontend/src/api/modules/upload.ts +132 -0
- fred_admin/demo/modules/admin/frontend/src/api/modules/user.ts +63 -0
- fred_admin/demo/modules/admin/frontend/src/assets/fonts/DIN.otf +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/fonts/MetroDF.ttf +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/fonts/YouSheBiaoTiHei.ttf +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/fonts/font.scss +14 -0
- fred_admin/demo/modules/admin/frontend/src/assets/iconfont/iconfont.scss +51 -0
- fred_admin/demo/modules/admin/frontend/src/assets/iconfont/iconfont.ttf +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/icons/xianxingdaoyu.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/icons/xianxingdiqiu.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/icons/xianxingditu.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/icons/xianxingfanchuan.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/icons/xianxingfeiji.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/icons/xianxinglvhangriji.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/icons/xianxingtianqiyubao.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/icons/xianxingxiangjipaizhao.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/icons/xianxingxiarilengyin.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/icons/xianxingyoulun.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/icons/xianxingzijiayou.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/403.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/404.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/500.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/avatar.gif +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/login_bg.svg +33 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/login_left.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/login_left1.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/login_left2.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/login_left3.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/login_left4.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/login_left5.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/logo.svg +1 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/msg01.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/msg02.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/msg03.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/msg04.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/msg05.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/notData.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/images/welcome.png +0 -0
- fred_admin/demo/modules/admin/frontend/src/assets/json/authButtonList.json +8 -0
- fred_admin/demo/modules/admin/frontend/src/assets/json/authMenuList.json +1075 -0
- fred_admin/demo/modules/admin/frontend/src/assets/mock/Easy-Mock-API.zip +0 -0
- fred_admin/demo/modules/admin/frontend/src/components/ECharts/config/index.ts +72 -0
- fred_admin/demo/modules/admin/frontend/src/components/ECharts/index.vue +104 -0
- fred_admin/demo/modules/admin/frontend/src/components/ErrorMessage/403.vue +19 -0
- fred_admin/demo/modules/admin/frontend/src/components/ErrorMessage/404.vue +19 -0
- fred_admin/demo/modules/admin/frontend/src/components/ErrorMessage/500.vue +19 -0
- fred_admin/demo/modules/admin/frontend/src/components/ErrorMessage/index.scss +32 -0
- fred_admin/demo/modules/admin/frontend/src/components/Grid/components/GridItem.vue +68 -0
- fred_admin/demo/modules/admin/frontend/src/components/Grid/index.vue +167 -0
- fred_admin/demo/modules/admin/frontend/src/components/Grid/interface/index.ts +6 -0
- fred_admin/demo/modules/admin/frontend/src/components/ImageCaptcha/index.vue +71 -0
- fred_admin/demo/modules/admin/frontend/src/components/ImportExcel/index.scss +3 -0
- fred_admin/demo/modules/admin/frontend/src/components/ImportExcel/index.vue +151 -0
- fred_admin/demo/modules/admin/frontend/src/components/JsonViewer/index.vue +249 -0
- fred_admin/demo/modules/admin/frontend/src/components/Loading/fullScreen.ts +45 -0
- fred_admin/demo/modules/admin/frontend/src/components/Loading/index.scss +67 -0
- fred_admin/demo/modules/admin/frontend/src/components/Loading/index.vue +13 -0
- fred_admin/demo/modules/admin/frontend/src/components/ProTable/components/ColSetting.vue +45 -0
- fred_admin/demo/modules/admin/frontend/src/components/ProTable/components/Pagination.vue +101 -0
- fred_admin/demo/modules/admin/frontend/src/components/ProTable/components/TableColumn.vue +58 -0
- fred_admin/demo/modules/admin/frontend/src/components/ProTable/index.vue +348 -0
- fred_admin/demo/modules/admin/frontend/src/components/ProTable/interface/index.ts +87 -0
- fred_admin/demo/modules/admin/frontend/src/components/SearchForm/components/SearchFormItem.vue +96 -0
- fred_admin/demo/modules/admin/frontend/src/components/SearchForm/index.vue +98 -0
- fred_admin/demo/modules/admin/frontend/src/components/SelectFilter/index.scss +63 -0
- fred_admin/demo/modules/admin/frontend/src/components/SelectFilter/index.vue +110 -0
- fred_admin/demo/modules/admin/frontend/src/components/SelectIcon/index.scss +39 -0
- fred_admin/demo/modules/admin/frontend/src/components/SelectIcon/index.vue +90 -0
- fred_admin/demo/modules/admin/frontend/src/components/StoreFilter/index.vue +356 -0
- fred_admin/demo/modules/admin/frontend/src/components/SvgIcon/index.vue +22 -0
- fred_admin/demo/modules/admin/frontend/src/components/SwitchDark/index.vue +12 -0
- fred_admin/demo/modules/admin/frontend/src/components/TreeFilter/index.scss +44 -0
- fred_admin/demo/modules/admin/frontend/src/components/TreeFilter/index.vue +165 -0
- fred_admin/demo/modules/admin/frontend/src/components/Upload/Img.vue +304 -0
- fred_admin/demo/modules/admin/frontend/src/components/Upload/Imgs.vue +316 -0
- fred_admin/demo/modules/admin/frontend/src/components/WangEditor/index.scss +28 -0
- fred_admin/demo/modules/admin/frontend/src/components/WangEditor/index.vue +154 -0
- fred_admin/demo/modules/admin/frontend/src/config/amapMap.ts +11 -0
- fred_admin/demo/modules/admin/frontend/src/config/index.ts +16 -0
- fred_admin/demo/modules/admin/frontend/src/config/nprogress.ts +12 -0
- fred_admin/demo/modules/admin/frontend/src/directives/index.ts +28 -0
- fred_admin/demo/modules/admin/frontend/src/directives/modules/auth.ts +26 -0
- fred_admin/demo/modules/admin/frontend/src/directives/modules/copy.ts +37 -0
- fred_admin/demo/modules/admin/frontend/src/directives/modules/debounce.ts +31 -0
- fred_admin/demo/modules/admin/frontend/src/directives/modules/draggable.ts +49 -0
- fred_admin/demo/modules/admin/frontend/src/directives/modules/longpress.ts +49 -0
- fred_admin/demo/modules/admin/frontend/src/directives/modules/throttle.ts +41 -0
- fred_admin/demo/modules/admin/frontend/src/directives/modules/waterMarker.ts +36 -0
- fred_admin/demo/modules/admin/frontend/src/enums/httpEnum.ts +35 -0
- fred_admin/demo/modules/admin/frontend/src/hooks/interface/index.ts +32 -0
- fred_admin/demo/modules/admin/frontend/src/hooks/useAuthButtons.ts +22 -0
- fred_admin/demo/modules/admin/frontend/src/hooks/useDownload.ts +42 -0
- fred_admin/demo/modules/admin/frontend/src/hooks/useHandleData.ts +41 -0
- fred_admin/demo/modules/admin/frontend/src/hooks/useI18n.ts +51 -0
- fred_admin/demo/modules/admin/frontend/src/hooks/useOnline.ts +31 -0
- fred_admin/demo/modules/admin/frontend/src/hooks/useSelection.ts +34 -0
- fred_admin/demo/modules/admin/frontend/src/hooks/useTable.ts +150 -0
- fred_admin/demo/modules/admin/frontend/src/hooks/useTheme.ts +111 -0
- fred_admin/demo/modules/admin/frontend/src/hooks/useTime.ts +38 -0
- fred_admin/demo/modules/admin/frontend/src/languages/index.ts +32 -0
- fred_admin/demo/modules/admin/frontend/src/languages/modules/en.ts +978 -0
- fred_admin/demo/modules/admin/frontend/src/languages/modules/zh.ts +996 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/LayoutClassic/index.scss +60 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/LayoutClassic/index.vue +62 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/LayoutColumns/index.scss +95 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/LayoutColumns/index.vue +103 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/LayoutTransverse/index.scss +60 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/LayoutTransverse/index.vue +61 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/LayoutVertical/index.scss +48 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/LayoutVertical/index.vue +56 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Footer/index.scss +11 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Footer/index.vue +9 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/ToolBarLeft.vue +23 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/ToolBarRight.vue +51 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/components/AssemblySize.vue +37 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/components/Avatar.vue +79 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/components/Breadcrumb.vue +122 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/components/CollapseIcon.vue +21 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/components/Fullscreen.vue +25 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/components/InfoDialog.vue +22 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/components/Language.vue +38 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/components/Message.vue +109 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/components/PasswordDialog.vue +81 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/components/SearchMenu.vue +183 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Header/components/ThemeSetting.vue +12 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Main/components/Maximize.vue +39 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Main/index.scss +10 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Main/index.vue +88 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Menu/SubMenu.vue +85 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Tabs/components/MoreButton.vue +85 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Tabs/index.scss +69 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/Tabs/index.vue +115 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/ThemeDrawer/index.scss +137 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/components/ThemeDrawer/index.vue +191 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/index.vue +42 -0
- fred_admin/demo/modules/admin/frontend/src/layouts/indexAsync.vue +46 -0
- fred_admin/demo/modules/admin/frontend/src/main.ts +45 -0
- fred_admin/demo/modules/admin/frontend/src/routers/index.ts +106 -0
- fred_admin/demo/modules/admin/frontend/src/routers/modules/dynamicRouter.ts +99 -0
- fred_admin/demo/modules/admin/frontend/src/routers/modules/staticRouter.ts +63 -0
- fred_admin/demo/modules/admin/frontend/src/stores/helper/persist.ts +19 -0
- fred_admin/demo/modules/admin/frontend/src/stores/index.ts +8 -0
- fred_admin/demo/modules/admin/frontend/src/stores/interface/index.ts +63 -0
- fred_admin/demo/modules/admin/frontend/src/stores/modules/auth.ts +50 -0
- fred_admin/demo/modules/admin/frontend/src/stores/modules/global.ts +55 -0
- fred_admin/demo/modules/admin/frontend/src/stores/modules/keepAlive.ts +25 -0
- fred_admin/demo/modules/admin/frontend/src/stores/modules/tabs.ts +78 -0
- fred_admin/demo/modules/admin/frontend/src/stores/modules/user.ts +23 -0
- fred_admin/demo/modules/admin/frontend/src/styles/common.scss +129 -0
- fred_admin/demo/modules/admin/frontend/src/styles/element-dark.scss +28 -0
- fred_admin/demo/modules/admin/frontend/src/styles/element.scss +264 -0
- fred_admin/demo/modules/admin/frontend/src/styles/modules/annotation.scss +746 -0
- fred_admin/demo/modules/admin/frontend/src/styles/modules/assembly.scss +714 -0
- fred_admin/demo/modules/admin/frontend/src/styles/modules/device-manager.scss +659 -0
- fred_admin/demo/modules/admin/frontend/src/styles/modules/directives.scss +381 -0
- fred_admin/demo/modules/admin/frontend/src/styles/reset.scss +143 -0
- fred_admin/demo/modules/admin/frontend/src/styles/table-optimization.scss +242 -0
- fred_admin/demo/modules/admin/frontend/src/styles/theme/aside.ts +16 -0
- fred_admin/demo/modules/admin/frontend/src/styles/theme/header.ts +25 -0
- fred_admin/demo/modules/admin/frontend/src/styles/theme/menu.ts +31 -0
- fred_admin/demo/modules/admin/frontend/src/styles/var.scss +2 -0
- fred_admin/demo/modules/admin/frontend/src/typings/global.d.ts +74 -0
- fred_admin/demo/modules/admin/frontend/src/typings/utils.d.ts +17 -0
- fred_admin/demo/modules/admin/frontend/src/typings/window.d.ts +8 -0
- fred_admin/demo/modules/admin/frontend/src/utils/color.ts +59 -0
- fred_admin/demo/modules/admin/frontend/src/utils/dict.ts +17 -0
- fred_admin/demo/modules/admin/frontend/src/utils/eleValidate.ts +14 -0
- fred_admin/demo/modules/admin/frontend/src/utils/errorHandler.ts +28 -0
- fred_admin/demo/modules/admin/frontend/src/utils/index.ts +327 -0
- fred_admin/demo/modules/admin/frontend/src/utils/is/index.ts +125 -0
- fred_admin/demo/modules/admin/frontend/src/utils/mittBus.ts +5 -0
- fred_admin/demo/modules/admin/frontend/src/utils/svg.ts +13 -0
- fred_admin/demo/modules/admin/frontend/src/views/dataBase/fieldType/components/FieldTypeDrawer.vue +89 -0
- fred_admin/demo/modules/admin/frontend/src/views/dataBase/fieldType/index.vue +99 -0
- fred_admin/demo/modules/admin/frontend/src/views/dataBase/tableManage/components/DataBaseDrawer.vue +254 -0
- fred_admin/demo/modules/admin/frontend/src/views/dataBase/tableManage/components/IndexDrawer.vue +226 -0
- fred_admin/demo/modules/admin/frontend/src/views/dataBase/tableManage/components/TableDataDrawer.vue +136 -0
- fred_admin/demo/modules/admin/frontend/src/views/dataBase/tableManage/index.vue +234 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/columnChart/index.scss +0 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/columnChart/index.vue +139 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/lineChart/index.scss +0 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/lineChart/index.vue +123 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/nestedChart/index.scss +0 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/nestedChart/index.vue +97 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/pieChart/index.scss +0 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/pieChart/index.vue +68 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/radarChart/index.scss +0 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/radarChart/index.vue +56 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/waterChart/index.scss +0 -0
- fred_admin/demo/modules/admin/frontend/src/views/echarts/waterChart/index.vue +298 -0
- fred_admin/demo/modules/admin/frontend/src/views/home/index.scss +12 -0
- fred_admin/demo/modules/admin/frontend/src/views/home/index.vue +11 -0
- fred_admin/demo/modules/admin/frontend/src/views/login/components/LoginForm.vue +147 -0
- fred_admin/demo/modules/admin/frontend/src/views/login/index.scss +83 -0
- fred_admin/demo/modules/admin/frontend/src/views/login/index.vue +27 -0
- fred_admin/demo/modules/admin/frontend/src/views/proTable/complexProTable/index.vue +176 -0
- fred_admin/demo/modules/admin/frontend/src/views/proTable/components/UserDrawer.vue +152 -0
- fred_admin/demo/modules/admin/frontend/src/views/proTable/document/index.vue +13 -0
- fred_admin/demo/modules/admin/frontend/src/views/proTable/treeProTable/index.vue +129 -0
- fred_admin/demo/modules/admin/frontend/src/views/proTable/useProTable/detail.vue +12 -0
- fred_admin/demo/modules/admin/frontend/src/views/proTable/useProTable/index.vue +258 -0
- fred_admin/demo/modules/admin/frontend/src/views/proTable/useSelectFilter/index.vue +184 -0
- fred_admin/demo/modules/admin/frontend/src/views/proTable/useTreeFilter/detail.vue +12 -0
- fred_admin/demo/modules/admin/frontend/src/views/proTable/useTreeFilter/index.vue +147 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/accountManage/index.vue +244 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/apiAuth/components/ApiDrawer.vue +114 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/apiAuth/components/TokenDrawer.vue +160 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/apiAuth/index.vue +354 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/buttonManage/components/ButtonDrawer.vue +460 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/buttonManage/index.vue +426 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/configManage/components/ConfigDrawer.vue +106 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/configManage/index.vue +116 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/departmentManage/index.vue +7 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/dictManage/index.vue +7 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/menuManage/components/MenuDrawer.vue +262 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/menuManage/index.vue +310 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/organizationManage/components/CompanyDrawer.vue +72 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/organizationManage/components/DepartmentDrawer.vue +120 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/organizationManage/components/TeamDrawer.vue +162 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/organizationManage/components/TeamMemberDrawer.vue +243 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/organizationManage/index.vue +414 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/roleManage/components/RoleButtonDrawer.vue +587 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/roleManage/components/RoleDrawer.vue +77 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/roleManage/components/RoleMenuDrawer.vue +236 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/roleManage/components/RoleUserDrawer.vue +125 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/roleManage/index.vue +143 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/systemLog/components/SystemLogDrawer.vue +207 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/systemLog/index.vue +219 -0
- fred_admin/demo/modules/admin/frontend/src/views/system/timingTask/index.vue +7 -0
- fred_admin/demo/modules/admin/frontend/src/vite-env.d.ts +7 -0
- fred_admin/demo/modules/admin/frontend/tsconfig.json +42 -0
- fred_admin/demo/modules/admin/frontend/vite.config.ts +91 -0
- fred_admin/demo/modules/admin/frontend//321/205/320/231/320/235/321/207/320/273/320/277/321/204/342/225/227/320/263/321/207/320/260/320/221/321/210/320/277/342/224/244/321/206/320/250/320/236.md +100 -0
- fred_admin/demo/requirements.txt +1 -0
- fred_admin/fonts/NotoSansSC-VariableFont_wght.ttf +0 -0
- fred_admin/install_hook.py +1633 -0
- fred_admin/setup.py +18 -0
- fred_admin-1.0.0.dist-info/METADATA +97 -0
- fred_admin-1.0.0.dist-info/RECORD +376 -0
- fred_admin-1.0.0.dist-info/WHEEL +5 -0
- fred_admin-1.0.0.dist-info/entry_points.txt +3 -0
- fred_admin-1.0.0.dist-info/licenses/LICENSE +21 -0
- fred_admin-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"""
|
|
2
|
+
* @Author:cyg
|
|
3
|
+
* @Package:HandleExcetion
|
|
4
|
+
* @Project:Default (Template) Project
|
|
5
|
+
* @name:HandleExcetion
|
|
6
|
+
* @Date:2024/12/16 11:47
|
|
7
|
+
* @Filename:全局异常处理
|
|
8
|
+
"""
|
|
9
|
+
from http.client import NOT_FOUND
|
|
10
|
+
from flask_babelplus import gettext
|
|
11
|
+
from sqlite3 import OperationalError
|
|
12
|
+
from sqlalchemy.exc import OperationalError as SAOperationalError
|
|
13
|
+
|
|
14
|
+
from flask import jsonify
|
|
15
|
+
from marshmallow import ValidationError
|
|
16
|
+
from werkzeug.exceptions import HTTPException, Unauthorized
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class HandleException():
|
|
20
|
+
def __init__(self, app):
|
|
21
|
+
@app.errorhandler(NOT_FOUND)
|
|
22
|
+
def handle_404_error(e):
|
|
23
|
+
exception_message = {'message': gettext("您访问的地址溜走了!")}
|
|
24
|
+
response = jsonify(exception_message)
|
|
25
|
+
response.status_code = e.code
|
|
26
|
+
return response
|
|
27
|
+
|
|
28
|
+
@app.errorhandler(400)
|
|
29
|
+
def handle_400_error(e):
|
|
30
|
+
# 使用 abort(400,description =gettext("验证码有误!"))使用其自带的状态码和描述
|
|
31
|
+
code = e.code
|
|
32
|
+
message = e.description
|
|
33
|
+
exception_message = {'message': message}
|
|
34
|
+
response = jsonify(exception_message)
|
|
35
|
+
response.status_code = code
|
|
36
|
+
return response
|
|
37
|
+
|
|
38
|
+
@app.errorhandler(401)
|
|
39
|
+
def handle_401_error(e):
|
|
40
|
+
code = e.code
|
|
41
|
+
exception_message = {'message': gettext("登录失效或登录过期!")}
|
|
42
|
+
response = jsonify(exception_message)
|
|
43
|
+
response.status_code = code
|
|
44
|
+
return response
|
|
45
|
+
|
|
46
|
+
@app.errorhandler(422)
|
|
47
|
+
def handle_422_error(e):
|
|
48
|
+
code = e.code
|
|
49
|
+
# 尝试提取 Marshmallow 的 ValidationError 错误信息
|
|
50
|
+
errors = getattr(e, 'exc', None) # 获取原始异常对象
|
|
51
|
+
error_details = []
|
|
52
|
+
|
|
53
|
+
def extract_error_messages(messages, prefix=''):
|
|
54
|
+
"""
|
|
55
|
+
递归提取错误消息,支持嵌套结构(列表验证、字典验证等)
|
|
56
|
+
"""
|
|
57
|
+
result = []
|
|
58
|
+
if isinstance(messages, dict):
|
|
59
|
+
for key, value in messages.items():
|
|
60
|
+
# 构建字段路径
|
|
61
|
+
if isinstance(key, int):
|
|
62
|
+
# 列表索引,使用更友好的格式
|
|
63
|
+
if prefix:
|
|
64
|
+
field_path = f"{prefix}[第{key + 1}项]"
|
|
65
|
+
else:
|
|
66
|
+
field_path = f"第{key + 1}项"
|
|
67
|
+
elif isinstance(key, str):
|
|
68
|
+
# 字符串键(字段名)
|
|
69
|
+
if prefix:
|
|
70
|
+
field_path = f"{prefix}.{key}"
|
|
71
|
+
else:
|
|
72
|
+
field_path = key
|
|
73
|
+
else:
|
|
74
|
+
# 其他类型的键
|
|
75
|
+
if prefix:
|
|
76
|
+
field_path = f"{prefix}[{key}]"
|
|
77
|
+
else:
|
|
78
|
+
field_path = f"[{key}]"
|
|
79
|
+
|
|
80
|
+
if isinstance(value, list):
|
|
81
|
+
# 如果是列表,说明是错误消息列表
|
|
82
|
+
for msg in value:
|
|
83
|
+
if isinstance(msg, str):
|
|
84
|
+
result.append(f"{field_path}: {msg}")
|
|
85
|
+
elif isinstance(msg, dict):
|
|
86
|
+
# 嵌套字典,继续递归
|
|
87
|
+
result.extend(extract_error_messages(msg, field_path))
|
|
88
|
+
elif isinstance(value, dict):
|
|
89
|
+
# 嵌套字典,继续递归
|
|
90
|
+
result.extend(extract_error_messages(value, field_path))
|
|
91
|
+
elif isinstance(value, str):
|
|
92
|
+
# 直接是字符串错误消息
|
|
93
|
+
result.append(f"{field_path}: {value}")
|
|
94
|
+
elif isinstance(messages, list):
|
|
95
|
+
# 如果是列表,直接处理
|
|
96
|
+
for msg in messages:
|
|
97
|
+
if isinstance(msg, str):
|
|
98
|
+
if prefix:
|
|
99
|
+
result.append(f"{prefix}: {msg}")
|
|
100
|
+
else:
|
|
101
|
+
result.append(msg)
|
|
102
|
+
elif isinstance(msg, dict):
|
|
103
|
+
result.extend(extract_error_messages(msg, prefix))
|
|
104
|
+
elif isinstance(messages, str):
|
|
105
|
+
# 直接是字符串
|
|
106
|
+
if prefix:
|
|
107
|
+
result.append(f"{prefix}: {messages}")
|
|
108
|
+
else:
|
|
109
|
+
result.append(messages)
|
|
110
|
+
|
|
111
|
+
return result
|
|
112
|
+
|
|
113
|
+
if isinstance(errors, ValidationError):
|
|
114
|
+
# 提取 ValidationError 的 messages 属性
|
|
115
|
+
all_messages = extract_error_messages(errors.messages)
|
|
116
|
+
error_details.extend(all_messages)
|
|
117
|
+
|
|
118
|
+
# 如果没有提取到错误信息,使用默认消息
|
|
119
|
+
if not error_details:
|
|
120
|
+
error_details.append(gettext('参数验证失败'))
|
|
121
|
+
|
|
122
|
+
text = '; '.join(error_details)
|
|
123
|
+
exception_message = {'message': gettext(f'参数验证错误: {text}')}
|
|
124
|
+
response = jsonify(exception_message)
|
|
125
|
+
response.status_code = code
|
|
126
|
+
return response
|
|
127
|
+
|
|
128
|
+
@app.errorhandler(OperationalError)
|
|
129
|
+
def handle_operational_error(e):
|
|
130
|
+
# 自定义错误消息和状态码
|
|
131
|
+
error_message = gettext("数据库连接失败,请稍后重试!")
|
|
132
|
+
# if "Lost connection to MySQL server" in str(e):
|
|
133
|
+
# error_message = "与数据库的连接已丢失,请稍后重试!"
|
|
134
|
+
# elif "Operation timed out" in str(e):
|
|
135
|
+
# error_message = "数据库操作超时,请检查网络或服务器状态!"
|
|
136
|
+
|
|
137
|
+
exception_message = {'message': error_message}
|
|
138
|
+
response = jsonify(exception_message)
|
|
139
|
+
response.status_code = 500 # 使用 500 表示服务器内部错误
|
|
140
|
+
return response
|
|
141
|
+
|
|
142
|
+
@app.errorhandler(SAOperationalError)
|
|
143
|
+
def handle_sqlalchemy_operational_error(e):
|
|
144
|
+
# 默认使用通用错误信息
|
|
145
|
+
error_message = gettext("数据库操作失败,请检查SQL语句或数据库状态!")
|
|
146
|
+
|
|
147
|
+
# 尝试从原始异常 e.orig 中提取更具体的信息
|
|
148
|
+
# (pymysql.err.OperationalError) (1170, "BLOB/TEXT column 't2' used in key specification without a key length")
|
|
149
|
+
# e.orig.args -> (1170, "BLOB/TEXT column 't2' used in key specification without a key length")
|
|
150
|
+
if hasattr(e, 'orig') and e.orig and hasattr(e.orig, 'args') and len(e.orig.args) > 1:
|
|
151
|
+
# 提取具体的错误描述,通常是元组的第二个元素
|
|
152
|
+
error_detail = e.orig.args[1]
|
|
153
|
+
error_message = f"{gettext('数据库操作失败')}: {error_detail}"
|
|
154
|
+
|
|
155
|
+
exception_message = {'message': error_message}
|
|
156
|
+
response = jsonify(exception_message)
|
|
157
|
+
response.status_code = 500
|
|
158
|
+
return response
|
|
159
|
+
|
|
160
|
+
@app.errorhandler(500)
|
|
161
|
+
def handle_500_error(e):
|
|
162
|
+
"""
|
|
163
|
+
处理 500 错误,确保错误信息能够正确返回
|
|
164
|
+
"""
|
|
165
|
+
code = 500
|
|
166
|
+
# 尝试获取错误描述,如果没有则使用默认消息
|
|
167
|
+
message = getattr(e, 'description', None) or str(e) or gettext("服务器内部错误")
|
|
168
|
+
exception_message = {'message': message}
|
|
169
|
+
response = jsonify(exception_message)
|
|
170
|
+
response.status_code = code
|
|
171
|
+
return response
|
|
172
|
+
|
|
173
|
+
@app.errorhandler(HTTPException)
|
|
174
|
+
def handle_http_exception(e):
|
|
175
|
+
"""
|
|
176
|
+
处理其他 HTTP 异常
|
|
177
|
+
"""
|
|
178
|
+
code = e.code if hasattr(e, 'code') else 500
|
|
179
|
+
message = getattr(e, 'description', None) or str(e) or gettext("请求处理失败")
|
|
180
|
+
exception_message = {'message': message}
|
|
181
|
+
response = jsonify(exception_message)
|
|
182
|
+
response.status_code = code
|
|
183
|
+
return response
|
|
184
|
+
|
|
185
|
+
@app.errorhandler(Exception)
|
|
186
|
+
def handle_general_exception(e):
|
|
187
|
+
"""
|
|
188
|
+
处理所有未捕获的异常
|
|
189
|
+
"""
|
|
190
|
+
# 如果是 HTTPException,应该已经被上面的处理器处理了
|
|
191
|
+
if isinstance(e, HTTPException):
|
|
192
|
+
code = e.code if hasattr(e, 'code') else 500
|
|
193
|
+
message = getattr(e, 'description', None) or str(e) or gettext("请求处理失败")
|
|
194
|
+
exception_message = {'message': message}
|
|
195
|
+
response = jsonify(exception_message)
|
|
196
|
+
response.status_code = code
|
|
197
|
+
return response
|
|
198
|
+
|
|
199
|
+
# 其他异常,记录错误信息
|
|
200
|
+
error_message = str(e) if str(e) else gettext("服务器内部错误")
|
|
201
|
+
exception_message = {'message': error_message}
|
|
202
|
+
response = jsonify(exception_message)
|
|
203
|
+
response.status_code = 500
|
|
204
|
+
return response
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import random
|
|
6
|
+
import string
|
|
7
|
+
from io import BytesIO
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from PIL import Image, ImageFont, ImageDraw
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ImageVerification:
|
|
14
|
+
"""
|
|
15
|
+
@desc: 图形验证码
|
|
16
|
+
"""
|
|
17
|
+
width = 150
|
|
18
|
+
height = 60
|
|
19
|
+
num = 4
|
|
20
|
+
fontsize = 36
|
|
21
|
+
line_num = 4 # 干扰线密度
|
|
22
|
+
bg_color = (0, 0, 0, 0)
|
|
23
|
+
|
|
24
|
+
def rand_color(self):
|
|
25
|
+
"""生成用于绘制字符串的随机颜色(可以随意指定0-255之间的数字)"""
|
|
26
|
+
red = random.randint(0, 255)
|
|
27
|
+
green = random.randint(0, 255)
|
|
28
|
+
blue = random.randint(0, 255)
|
|
29
|
+
return red, green, blue
|
|
30
|
+
|
|
31
|
+
def gen_text(self):
|
|
32
|
+
"""生成4位随机字符串"""
|
|
33
|
+
# sample 用于从一个大的列表或字符串中,随机取得N个字符,来构建出一个子列表
|
|
34
|
+
new_str = string.ascii_letters.replace("o", "").replace("O", "") + string.digits.replace("0", "")
|
|
35
|
+
list = random.sample(new_str, self.num)
|
|
36
|
+
return ''.join(list)
|
|
37
|
+
|
|
38
|
+
# 获取字体(使用fonts目录中的字体文件)
|
|
39
|
+
def get_font(self):
|
|
40
|
+
"""
|
|
41
|
+
获取字体对象,优先使用包内fonts目录中的字体文件,如果不存在则尝试系统字体,最后使用PIL默认字体
|
|
42
|
+
支持通过 self.fontsize 动态调整字体大小
|
|
43
|
+
使用包内资源定位方式,适合pip包安装后的使用场景
|
|
44
|
+
"""
|
|
45
|
+
# 获取当前文件所在目录(包内路径)
|
|
46
|
+
current_file = Path(__file__).resolve()
|
|
47
|
+
# 从 common 目录向上到 fred_admin 目录,然后定位 fonts 目录
|
|
48
|
+
package_root = current_file.parent.parent # common -> fred_admin
|
|
49
|
+
font_path = package_root / 'fonts' / 'NotoSansSC-VariableFont_wght.ttf'
|
|
50
|
+
|
|
51
|
+
# 如果字体文件存在,使用该字体
|
|
52
|
+
if font_path.exists():
|
|
53
|
+
try:
|
|
54
|
+
return ImageFont.truetype(str(font_path), self.fontsize)
|
|
55
|
+
except Exception:
|
|
56
|
+
pass # 如果加载失败,继续尝试其他字体
|
|
57
|
+
|
|
58
|
+
# 尝试加载系统字体(支持指定大小)
|
|
59
|
+
system_fonts = [
|
|
60
|
+
'/System/Library/Fonts/Helvetica.ttc', # macOS
|
|
61
|
+
'/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', # Linux
|
|
62
|
+
'C:/Windows/Fonts/arial.ttf', # Windows
|
|
63
|
+
'C:/Windows/Fonts/msyh.ttc', # Windows 微软雅黑
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
for sys_font in system_fonts:
|
|
67
|
+
if os.path.exists(sys_font):
|
|
68
|
+
try:
|
|
69
|
+
return ImageFont.truetype(sys_font, self.fontsize)
|
|
70
|
+
except Exception:
|
|
71
|
+
continue
|
|
72
|
+
|
|
73
|
+
# 如果所有字体都加载失败,使用默认字体(注意:默认字体不支持大小参数)
|
|
74
|
+
# 但为了保持一致性,我们仍然返回默认字体
|
|
75
|
+
default_font = ImageFont.load_default()
|
|
76
|
+
# 注意:ImageFont.load_default() 不支持字体大小参数
|
|
77
|
+
# 如果需要支持字体大小,必须使用 truetype 字体
|
|
78
|
+
return default_font
|
|
79
|
+
|
|
80
|
+
def draw_lines(self, draw, num, width, height):
|
|
81
|
+
"""
|
|
82
|
+
绘制干扰线
|
|
83
|
+
:param draw: 图片对象
|
|
84
|
+
:param num: 干扰线数量
|
|
85
|
+
:param width: 图片的宽
|
|
86
|
+
:param height: 图片的高
|
|
87
|
+
:return:
|
|
88
|
+
"""
|
|
89
|
+
for num in range(num):
|
|
90
|
+
x1 = random.randint(0, int(round(width / 2)))
|
|
91
|
+
y1 = random.randint(0, int(round(height / 2)))
|
|
92
|
+
x2 = random.randint(0, width)
|
|
93
|
+
y2 = random.randint(int(round(height / 2)), height)
|
|
94
|
+
draw.line(((x1, y1), (x2, y2)), fill=self.rand_color(), width=2)
|
|
95
|
+
|
|
96
|
+
def draw_verify_code(self):
|
|
97
|
+
"""绘制验证码图片"""
|
|
98
|
+
code = self.gen_text()
|
|
99
|
+
width, height = self.width, self.height # 设定图片大小,可根据实际需求调整
|
|
100
|
+
im = Image.new('RGBA', (width, height), self.bg_color) # 创建图片对象,并设定背景色为白色'#54D8A5'
|
|
101
|
+
draw = ImageDraw.Draw(im) # 新建ImageDraw对象
|
|
102
|
+
# 获取字体对象(在循环外只加载一次,提高性能)
|
|
103
|
+
font = self.get_font()
|
|
104
|
+
# 绘制字符串
|
|
105
|
+
for i in range(self.num):
|
|
106
|
+
x = random.randint(0, 3) + self.fontsize * i
|
|
107
|
+
y = height / 10 + random.randint(-3, 3)
|
|
108
|
+
fill = self.rand_color()
|
|
109
|
+
text = code[i]
|
|
110
|
+
draw.text((x, y), text=text, fill=fill, font=font, stroke_width=1, stroke_fill=self.rand_color()) #
|
|
111
|
+
self.draw_lines(draw, self.line_num, width, height) # 绘制干扰线
|
|
112
|
+
|
|
113
|
+
# im.show() # 如需临时调试,可以直接将生成的图片显示出来
|
|
114
|
+
out = BytesIO()
|
|
115
|
+
im.save(out, "png")
|
|
116
|
+
out.seek(0)
|
|
117
|
+
return out, code
|