From 1c0c8869373288d279507cdeae04e74949269e5b Mon Sep 17 00:00:00 2001 From: Ying Date: Tue, 29 Nov 2022 11:42:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AD=97=E5=85=B8bug?= =?UTF-8?q?=E3=80=81=E7=BC=93=E5=AD=98=E9=BB=98=E8=AE=A4=E4=BD=BF=E7=94=A8?= =?UTF-8?q?file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 51 +++++--- app/admin/controller/Index.php | 2 +- app/admin/view/system/admin/index.html | 5 +- app/admin/view/system/dictionary/index.html | 136 ++++++++++---------- app/common/validate/system/Admin.php | 3 + app/install/install.sql | 2 +- config/session.php | 18 ++- public/static/system/module/admin.js | 17 +-- 8 files changed, 126 insertions(+), 108 deletions(-) diff --git a/README.md b/README.md index c372e69..c3523cb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ - -
@@ -15,18 +13,23 @@ `SWIFTADMIN` 是一款基于 webman + Layui 开发的 http 服务框架,提供了一个简单易用的(权限)后台管理系统, -拥有极简的封装扩展,特别适合中小企业和个人站长用于开发 web 站点或者 http 接口。支持路由、中间件、自动注入、多应用、 自定义进程、无需更改直接兼容现有 composer 项目组件等诸多特性。具有学习成本低、简单易用、超高性能、超高稳定性等特点。 +拥有极简的封装扩展,特别适合中小企业和个人站长用于开发 web 站点或者 http 接口。支持路由、中间件、 多应用、 自定义进程、无需更改直接兼容现有 composer 项目组件等诸多特性。具有学习成本低、简单易用、超高性能、超高稳定性等特点。 + +为什么选择 SWIFTADMIN? + +如果你熟悉ThinkPHP/Laravel/Yii2等框架,那么你可以很快上手 SWIFTADMIN,因为 SWIFTADMIN 是完全复用的这些框架的composer包。一样的代码写法,性能却可以提升10 倍以上。 +运行在PHPCLI模式之下,他不是类似于SWOOLE异步协程的工作模式,所以新手朋友不需要担心变量污染的问题,也不需要担心第三方扩展包异步协程的问题,只需要专注于业务开发即可。 ### 软件架构 -| 依赖 | 版本 | 说明 | -|-----|-----------|:----------------------------------| -| PHP | \>= 8.0 | 最低支持PHP8.0 | -| WebMan | \>= 1.4.3 | 基于1.4.3.不支持action-hook/auto-route | -| MySQL | \>= 5.7 | 最低 5.7,注意5.6版本无JSON字段,会报错 | -| Layui | \>= 2.7 | 特殊开发版,无法直接用官网替换 | -| layui-form-design | \>= 1.0 | 表单设计器,基于Sortable专为SAPHP框架开发 | -| Admin Theme | \>= 1.x | 专为本框架开发、封装超多功能、支持多种菜单布局 | +| 依赖 | 版本 | 说明 | +|-----|-----------|:----------------------------| +| PHP | \>= 8.0 | 最低支持PHP8.0 | +| WebMan | \>= 1.4.3 | 基于workerman强悍核心 | +| MySQL | \>= 5.7 | 最低 5.7,注意5.6版本无JSON字段,会报错 | +| Layui | \>= 2.7 | 特殊封装版,无法直接用官网替换 | +| layui-form-design | \>= 1.0 | 表单设计器,基于Sortable专为SAPHP框架开发 | +| Admin Theme | \>= 1.x | 专为本框架开发、封装超多功能、支持多种菜单布局 | ### 软件功能 @@ -65,9 +68,9 @@ ``` 2、Windows环境下启动开发服务 ``` -1、执行Windows.bat 进行完整开发,默认会监听app、config、plugin目录的PHP html的更改热加载 +执行Windows.bat 进行完整开发,默认会监听app、config、plugin目录的PHP html的更改热加载 ``` -2、Linux环境下启动开发服务 +3、Linux环境下启动开发服务 ``` 执行命令:php start.php start # 启动开发服务 执行命令:php start.php stop # 停止开发服务 @@ -76,16 +79,32 @@ 注:当前默认只有app、config文件夹下文件内容被修改后才会自动重启,全局监听方案,请参考开发文档 ``` -3、打开浏览器输入网址,访问项目 +4、打开浏览器输入网址,访问项目 ``` http://localhost:8787/index # 访问项目执行安装 ``` -4、安装完毕后,访问后台URL登录系统 +5、安装完毕后,访问后台URL登录系统 ``` http://localhost:8787/manage # 登录后台/生产环境下可自行修改后台地址 ``` -5、 +### 常见问题 + +1、启动开发服务后,访问项目报错 Server internal error +``` +请检查是否安装了PHP扩展fileinfo opcache redis imagemagick exif,一般这个错误是PHP扩展没有安装、或者Redis服务器安装后没启动 +``` +2、启动开发服务后,访问项目报错 404 Not Found +``` +请检查是否安装了Apache或者NGINX服务器,一般这个错误是服务器没有安装、或者没有启动 +``` +3、启动服务器的时候报错:PHP Fatal error: .... +``` +首先在CMD终端或Linux终端执行命令:php -v 查看 * 默认PHP版本 *,如果版本低于8.0,请升级PHP版本
+然后使用命令:php -m 查看 * 已安装的PHP扩展 *,如果没有安装fileinfo opcache redis imagemagick exif,请安装
+一定要注意的是:swiftadmin框架运行在webman核心上,并且运行的时候默认调用的是当前操作系统,默认的PHP环境变量的那个版本,
+如果是windows环境,之前安装过PHP7.3,那么安装PHP8之后需要修改系统环境变量才可以执行; +``` ### 反馈BUG diff --git a/app/admin/controller/Index.php b/app/admin/controller/Index.php index 4283013..f85eea6 100644 --- a/app/admin/controller/Index.php +++ b/app/admin/controller/Index.php @@ -392,7 +392,7 @@ class Index extends AdminController $parse['CACHE_DRIVER'] = $post['cache_type']; $parse['CACHE_HOSTNAME'] = $post['cache_host']; $parse['CACHE_HOSTPORT'] = $post['cache_port']; - $parse['CACHE_SELECT'] = min($post['cache_select'], 1); + $parse['CACHE_SELECT'] = $post['cache_select']; $parse['CACHE_USERNAME'] = $post['cache_user']; $parse['CACHE_PASSWORD'] = $post['cache_pass']; write_file($env, parse_array_ini($parse)); diff --git a/app/admin/view/system/admin/index.html b/app/admin/view/system/admin/index.html index cf28930..43cf103 100644 --- a/app/admin/view/system/admin/index.html +++ b/app/admin/view/system/admin/index.html @@ -329,7 +329,7 @@ // 获取用户id var pageThat = layui.$(this), _pageUrl = !status ? pageThat.attr('lay-edit') : pageThat.attr('lay-add'); - pageThat.attr("disabled",true); + // 开始POST提交数据 layui.$.post(_pageUrl, post.field, function(res){ @@ -338,6 +338,7 @@ // 关闭当前窗口 table.reload('lay-tableList'); layer.close(colletction.index); + pageThat.attr("disabled",true); } else { layer.error(res.msg); @@ -379,7 +380,6 @@ // 增加节点数据 post.field[event] = tree.getChecked('authTree', true); // 开始POST提交数据 - clickthis.attr("disabled", true); layui.$.post("{:url('/system/admin/edit" + event + "')}", post.field, function (res) { if (res.code === 200) { @@ -391,6 +391,7 @@ // 关闭当前窗口 layer.msg(res.msg); layer.close(colletction.index); + clickthis.attr("disabled", true); } else { layer.error(res.msg); } diff --git a/app/admin/view/system/dictionary/index.html b/app/admin/view/system/dictionary/index.html index 785c554..30d42a3 100644 --- a/app/admin/view/system/dictionary/index.html +++ b/app/admin/view/system/dictionary/index.html @@ -10,6 +10,17 @@ font-size: 16px; } + #layui-dic_group { + padding-bottom: 25px; + } + + #layui-dic_group .layui-table-view .layui-table { + width: 100%; + } + + #layui-dic_group table thead tr:first-child i { + display: none; + } @media screen and (max-width: 1200px){ .layui-table-tool-temp .layui-btn { @@ -24,21 +35,8 @@ } } - #layui_side_left { - padding-bottom: 25px; - } - - #layui_side_left .layui-table-view .layui-table { - width: 100%; - } - - #layui_side_left table thead tr:first-child i - { - display: none; - } - -
+
@@ -52,35 +50,20 @@ {:__('修改')} -
-
- - - - - - - - -
{:__('字典名称')}
+
+ +
-
+
@@ -125,13 +108,13 @@
- + diff --git a/app/common/validate/system/Admin.php b/app/common/validate/system/Admin.php index 0d53da3..0a544b6 100644 --- a/app/common/validate/system/Admin.php +++ b/app/common/validate/system/Admin.php @@ -31,6 +31,9 @@ class Admin extends Validate 'name.max' => '用户名不能超过12个字符', 'name.filters' => '用户名包含禁止注册字符', 'name.chsAlphaNum' => '用户名只能是汉字、字母和数字', + 'pwd.require' => '密码不能为空', + 'pwd.min' => '密码不能少于6个字符', + 'pwd.max' => '密码不能超过64个字符', ]; // 测试验证场景 diff --git a/app/install/install.sql b/app/install/install.sql index 2647a44..920313a 100644 --- a/app/install/install.sql +++ b/app/install/install.sql @@ -396,7 +396,7 @@ INSERT INTO `__PREFIX__config` VALUES (18, 'auth_code', 0, NULL, 'string', 'wMRk INSERT INTO `__PREFIX__config` VALUES (19, 'system_logs', 0, NULL, 'string', '0', '后台日志'); INSERT INTO `__PREFIX__config` VALUES (20, 'system_exception', 0, NULL, 'string', '0', '异常日志'); INSERT INTO `__PREFIX__config` VALUES (21, 'cache_status', 0, 'cache', 'string', '1', '缓存状态'); -INSERT INTO `__PREFIX__config` VALUES (22, 'cache_type', 0, 'cache', 'string', 'redis', '缓存类型'); +INSERT INTO `__PREFIX__config` VALUES (22, 'cache_type', 0, 'cache', 'string', 'file', '缓存类型'); INSERT INTO `__PREFIX__config` VALUES (23, 'cache_time', 0, 'cache', 'string', '6000', '缓存时间'); INSERT INTO `__PREFIX__config` VALUES (24, 'cache_host', 0, 'cache', 'string', '127.0.0.1', '服务器IP'); INSERT INTO `__PREFIX__config` VALUES (25, 'cache_port', 0, 'cache', 'string', '6379', '端口'); diff --git a/config/session.php b/config/session.php index 5a75eb8..35c564c 100644 --- a/config/session.php +++ b/config/session.php @@ -13,20 +13,18 @@ */ return [ - - 'type' => 'redis', // or redis or redis_cluster - 'handler' => Webman\Session\RedisSessionHandler::class, + 'type' => getenv('CACHE_DRIVER') ?: 'file', // or redis or redis_cluster + 'handler' => getenv('CACHE_DRIVER') == 'redis' ? Webman\Session\RedisSessionHandler::class : Webman\Session\FileSessionHandler::class, 'config' => [ 'file' => [ 'save_path' => runtime_path() . '/sessions', ], 'redis' => [ - 'host' => '127.0.0.1', - 'port' => 6379, - 'auth' => '', - 'timeout' => 2, - 'database' => getenv('CACHE_SELECT') ?? 0, - 'prefix' => '', + 'host' => getenv('CACHE_HOSTNAME') ?: '127.0.0.1', + 'port' => getenv('CACHE_HOSTPORT') ?: 6379, + 'database' => getenv('CACHE_SELECT') ?: 0, + 'auth' => getenv('CACHE_PASSWORD') ?: '', + 'prefix' => '', // session key prefix ], 'redis_cluster' => [ 'host' => ['127.0.0.1:7000', '127.0.0.1:7001', '127.0.0.1:7001'], @@ -35,7 +33,7 @@ return [ 'prefix' => '', ] ], - 'session_name' => 'SAPHPID', + 'session_name' => 'SESSION_ID', 'auto_update_timestamp' => false, 'lifetime' => 7 * 24 * 60 * 60, 'cookie_lifetime' => 7 * 24 * 60 * 60, diff --git a/public/static/system/module/admin.js b/public/static/system/module/admin.js index e022a68..f2a8e00 100644 --- a/public/static/system/module/admin.js +++ b/public/static/system/module/admin.js @@ -639,7 +639,7 @@ layui.define(['jquery', 'i18n', 'element', 'layer', 'form', 'rate', 'table', 'sl auto: clickObject.data('auto') || undefined, shadeClose: clickObject.data('shadeclose') || false, scrollbar: clickObject.data('scrollbar') || undefined, - disableform: clickObject.data('disable') || false, + disableForm: clickObject.data('disable') || false, callback: clickObject.attr('callback') || undefined, iframeAuto: false }; @@ -651,9 +651,9 @@ layui.define(['jquery', 'i18n', 'element', 'layer', 'form', 'rate', 'table', 'sl options.type = 1; options.url = $(options.url).html(); if (typeof tableThis !== 'undefined') { - let htmls = $(options.url); - $(htmls).find('*[data-disabled]').addClass('layui-disabled').attr('disabled', ''); - options.url = htmls.prop("outerHTML"); + let html_text = $(options.url); + $(html_text).find('*[data-disabled]').addClass('layui-disabled').attr('disabled', ''); + options.url = html_text.prop("outerHTML"); } } @@ -691,7 +691,7 @@ layui.define(['jquery', 'i18n', 'element', 'layer', 'form', 'rate', 'table', 'sl if (options.type <= 1) { // 禁止滚动条 $(layero).children('.layui-layer-content').css('overflow', 'visible'); - if (typeof tableThis !== 'undefined' && !options.disableform) { + if (typeof tableThis !== 'undefined' && !options.disableForm) { form.val(options.id, tableThis.data); } @@ -734,6 +734,7 @@ layui.define(['jquery', 'i18n', 'element', 'layer', 'form', 'rate', 'table', 'sl dataType: 'json', data: post.field, success: function (res) { + for (var elem in post.field) { var lay = $(clickObject).parents("tr").find('*[data-field=' + elem + ']').find('*[lay-skin]'); if (lay.length !== 0) { @@ -772,9 +773,7 @@ layui.define(['jquery', 'i18n', 'element', 'layer', 'form', 'rate', 'table', 'sl return false; }) - } - } }) } @@ -1565,11 +1564,12 @@ layui.define(['jquery', 'i18n', 'element', 'layer', 'form', 'rate', 'table', 'sl } var _parent = that.data('reload') || false; - that.attr("disabled", true); + $.post(_url, data.field, function (res) { if (res.code === 200) { top.layer.msg(res.msg); + that.attr("disabled", true); if (_close === undefined) { admin.event.closeDialog(that); } @@ -1594,6 +1594,7 @@ layui.define(['jquery', 'i18n', 'element', 'layer', 'form', 'rate', 'table', 'sl }, 'json'); + // 延迟释放按钮 setTimeout(function (e) { that.attr("disabled", false); }, 2000);