diff --git a/app/build.php b/app/build.php index 4a5d100e..d55d64b8 100644 --- a/app/build.php +++ b/app/build.php @@ -12,7 +12,7 @@ return [ // 生成应用公共文件 '__file__' => ['common.php'], - '__dir__' => ['controller', 'model', 'view'], + '__dir__' => ['controller', 'model', 'view', 'validate'], 'controller' => ['Index', 'admin/Config', 'admin/Menu', 'admin/Member', 'admin/Content', 'admin/Action', 'admin/Ad', 'admin/Attribute', 'admin/Category', 'admin/Channel', 'admin/Client', 'admin/Database', 'admin/Model', 'admin/Link', 'admin/Seo', 'admin/Addons', 'admin/Form', 'admin/Group'], 'model' => ['Member', 'Config', 'Content', 'Channel', 'Client', 'Model', 'Link', 'Ad', 'AdPlace'], 'view' => ['admin/index/index', 'admin/config/group', 'admin/member/index', 'admin/content/index', 'admin/category/index'], diff --git a/app/controller/Admin.php b/app/controller/Admin.php index 295b5a21..c6b0462f 100644 --- a/app/controller/Admin.php +++ b/app/controller/Admin.php @@ -16,6 +16,7 @@ use app\BaseController; class Admin extends BaseController { protected $middleware = [ + '\app\middleware\Validate', '\app\middleware\AdminAuth' => ['except' => ['login']], '\app\middleware\Admin' ]; diff --git a/app/controller/Index.php b/app/controller/Index.php index 3ce9f67e..c1ba1d02 100644 --- a/app/controller/Index.php +++ b/app/controller/Index.php @@ -7,11 +7,51 @@ class Index extends BaseController { protected $middleware = ['\app\middleware\Front']; + /** + * @title 网站首页 + */ public function index() { - return '

:)

ThinkPHP V6
13载初心不改 - 你值得信赖的PHP框架

'; + } - public function miss($name = 'ThinkPHP6') { - return 'hello,' . $name; + /** + * @title 搜索页 + */ + public function search() { + + } + + /** + * @title 专题页 + */ + public function topic() { + + } + + /** + * @title 模型数据列表 + */ + public function lists() { + + } + + /** + * @title 栏目数据列表 + */ + public function category() { + + } + + /** + * @title 模型数据详情 + */ + public function detail() { + + } + + /** + * @title 未知页面调整到此方法 + */ + public function miss() { } } diff --git a/app/controller/admin/Index.php b/app/controller/admin/Index.php index 1bbd4342..b0d4b9a4 100644 --- a/app/controller/admin/Index.php +++ b/app/controller/admin/Index.php @@ -22,6 +22,15 @@ class Index extends Admin{ public function index(){ } + /** + * @title 更新缓存 + */ + public function clear(){ + } + + /** + * @title 后台登录 + */ public function login(){ if ($this->request->isAjax()) { Session::set('user', ['uid'=>1,'username'=>'admin']); diff --git a/app/controller/admin/Member.php b/app/controller/admin/User.php similarity index 95% rename from app/controller/admin/Member.php rename to app/controller/admin/User.php index 536e9e97..c4556d34 100644 --- a/app/controller/admin/Member.php +++ b/app/controller/admin/User.php @@ -10,7 +10,7 @@ namespace app\controller\admin; use app\controller\Admin; -class Member extends Admin{ +class User extends Admin{ /** * @title 系统首页 diff --git a/app/controller/api/Index.php b/app/controller/api/Index.php new file mode 100644 index 00000000..3296015e --- /dev/null +++ b/app/controller/api/Index.php @@ -0,0 +1,8 @@ + +// +---------------------------------------------------------------------- + +namespace app\middleware; +use think\Response; + +class Validate { + + /** + * @param \think\Request $request + * @param \Closure $next + * @return mixed|\think\response\Json + */ + public function handle($request, \Closure $next) { + //获取当前参数 + $params = $request->param(); + //获取访问控制器 + $controller = strtr(strtolower($request->controller()), '.', '\\'); + //获取操作名,用于验证场景scene + $scene = $request->action(); + $validate = "app\\validate\\" . $controller; + //仅当验证器存在时 进行校验 + if (class_exists($validate) && $request->isPost()) { + $v = new $validate; + //仅当存在验证场景才校验 + if ($v->hasScene($scene)) { + //设置当前验证场景 + $v->scene($scene); + if (!$v->check($params)) { + //校验不通过则直接返回错误信息 + $data = array( + 'msg' => $v->getError(), + 'code' => 1, + 'data' => '', + 'time' => time(), + ); + return Response::create($data, 'json', 200); + } + } + } + return $next($request); + } +} \ No newline at end of file diff --git a/app/validate/admin/Index.php b/app/validate/admin/Index.php new file mode 100644 index 00000000..46b46718 --- /dev/null +++ b/app/validate/admin/Index.php @@ -0,0 +1,29 @@ + +// +---------------------------------------------------------------------- + +namespace app\validate\admin; + +use think\Validate; + +class Index extends Validate { + + protected $rule = [ + 'username' => 'require', + 'password' => 'require', + ]; + + protected $message = []; + + /** + * @title 登录验证 + */ + public function sceneLogin() { + return $this->only(['username','password']); + } +} \ No newline at end of file diff --git a/app/view/admin/base.html b/app/view/admin/base.html new file mode 100644 index 00000000..ac364302 --- /dev/null +++ b/app/view/admin/base.html @@ -0,0 +1,227 @@ + + + + + + +SentCMS后台管理系统-{$meta|default="后台首页"} + + + + +{block name="style"}{/block} + + + +
+ + +
+{include file="admin/setting"} + + + + + + +{block name="script"}{/block} + + \ No newline at end of file diff --git a/app/view/admin/category/index.html b/app/view/admin/category/index.html index e69de29b..bdfbdaa3 100644 --- a/app/view/admin/category/index.html +++ b/app/view/admin/category/index.html @@ -0,0 +1 @@ +{extend name="admin/base"/} \ No newline at end of file diff --git a/app/view/admin/config/group.html b/app/view/admin/config/group.html index e69de29b..bdfbdaa3 100644 --- a/app/view/admin/config/group.html +++ b/app/view/admin/config/group.html @@ -0,0 +1 @@ +{extend name="admin/base"/} \ No newline at end of file diff --git a/app/view/admin/index/clear.html b/app/view/admin/index/clear.html new file mode 100644 index 00000000..bdfbdaa3 --- /dev/null +++ b/app/view/admin/index/clear.html @@ -0,0 +1 @@ +{extend name="admin/base"/} \ No newline at end of file diff --git a/app/view/admin/index/login.html b/app/view/admin/index/login.html index 9830d5e7..3159a17d 100644 --- a/app/view/admin/index/login.html +++ b/app/view/admin/index/login.html @@ -40,13 +40,13 @@
- +
- +
@@ -64,6 +64,7 @@ + + + + diff --git a/app/view/exception.html b/app/view/exception.html new file mode 100644 index 00000000..ae568d04 --- /dev/null +++ b/app/view/exception.html @@ -0,0 +1,37 @@ + + + + + + +系统发生错误 + + + + + + +
+ +
+
+ 系统错误 +
+ + +
+
+ + diff --git a/app/view/index/index.html b/app/view/index/index.html index 51052015..dff0d081 100644 --- a/app/view/index/index.html +++ b/app/view/index/index.html @@ -32,6 +32,7 @@ html, body {background-color: #fff; color: #636b6f; font-family: 'Raleway', sans 文档 资讯 Gitee + 后台管理 diff --git a/config/app.php b/config/app.php index 51b737c8..701c6f5d 100644 --- a/config/app.php +++ b/config/app.php @@ -38,7 +38,9 @@ return [ 'default_timezone' => 'Asia/Shanghai', // 异常页面的模板文件 - 'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl', + // 'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl', + 'exception_tmpl' => app()->getAppPath() . 'view/error.tpl', + // 'exception_tmpl' => app()->getAppPath() . 'view/exception.html', // 错误显示信息,非调试模式有效 'error_message' => '页面错误!请稍后再试~', diff --git a/route/app.php b/route/app.php index 021dc98d..dbd2e452 100644 --- a/route/app.php +++ b/route/app.php @@ -10,9 +10,12 @@ // +---------------------------------------------------------------------- use think\facade\Route; +Route::rule('/', 'index/index'); +Route::rule('search', 'index/search'); +Route::rule('topic-:id', 'index/topic'); + Route::group('admin', function(){ Route::rule('/', 'admin.index/index'); - //Route::rule(':controller', 'admin.:controller/index'); Route::rule('login', 'admin.index/login'); Route::rule(':controller/:function', 'admin.:controller/:function'); });