tp6更新到最新版本

目录结构调整
This commit is contained in:
2019-09-12 23:57:10 +08:00
parent db04a9c4e5
commit 0b0d659c5e
31 changed files with 656 additions and 635 deletions

View File

@@ -17,9 +17,9 @@ use think\facade\Cache;
class Admin extends BaseController {
protected $middleware = [
'\app\middleware\Validate',
'\app\middleware\AdminAuth' => ['except' => ['login']],
'\app\middleware\Admin'
'\app\http\middleware\Validate',
'\app\http\middleware\AdminAuth' => ['except' => ['login']],
'\app\http\middleware\Admin'
];
protected $data = ['data' => [], 'code' => 0, 'msg' => ''];
@@ -33,17 +33,17 @@ class Admin extends BaseController {
$this->data['config'] = $config;
}
protected function success($msg, $url){
protected function success($msg, $url = ''){
$this->data['code'] = 0;
$this->data['msg'] = $msg;
$this->data['url'] = $url->__toString();
return $this->data;
}
protected function error($msg, $url){
protected function error($msg, $url = ''){
$this->data['code'] = 1;
$this->data['msg'] = $msg;
$this->data['url'] = $url->__toString();
$this->data['url'] = $url ? $url->__toString() : '';
return $this->data;
}
}

View File

@@ -5,7 +5,7 @@ use app\BaseController;
class Index extends BaseController {
protected $middleware = ['\app\middleware\Front'];
protected $middleware = ['\app\http\middleware\Front'];
/**
* @title 网站首页

View File

@@ -16,6 +16,17 @@ class Group extends Admin{
* @title 系统首页
*/
public function index(){
if ($this->request->isAjax()) {
# code...
}
}
/**
* @title 权限列表
*/
public function access(){
if ($this->request->isAjax()) {
# code...
}
}
}

View File

@@ -69,6 +69,7 @@ class Index extends Admin{
public function logout(){
Session::set('user', null);
$this->data['code'] = 0;
$this->data['msg'] = "成功退出!";
return $this->data;
}
}

View File

@@ -19,8 +19,9 @@ class Menu extends Admin{
public function index(){
if($this->request->isAjax()){
$menu = new MenuModel();
$map = array();
$res = $menu->select();
$res = $menu->where($map)->order('sort asc, id asc')->select();
$this->data['data'] = $res;
return $this->data;
@@ -31,14 +32,28 @@ class Menu extends Admin{
* @title 编辑菜单
*/
public function edit(){
$menu = new MenuModel();
if($this->request->isAjax()){
$menu = new MenuModel();
$data = $this->request->post();
$res = $menu->select();
$this->data['data'] = $res;
$result = $menu->where('id', $data['id'])->save($data);
if (false !== $result) {
$this->data['code'] = 0;
$this->data['msg'] = '更新成功!';
}else{
$this->data['code'] = 1;
$this->data['msg'] = '更新失败!';
}
return $this->data;
}else{
$id = $this->request->param('id', 0);
if (!$id) {
return $this->error('非法操作!');
}
$info = $menu->where('id', $id)->find();
$this->data['data'] = array('info'=>$info);
return $this->data;
}
}
@@ -48,11 +63,6 @@ class Menu extends Admin{
*/
public function add(){
if($this->request->isAjax()){
$menu = new MenuModel();
$res = $menu->select();
$this->data['data'] = $res;
return $this->data;
}else{
$this->data['template'] = 'edit';
@@ -65,11 +75,6 @@ class Menu extends Admin{
*/
public function remove(){
if($this->request->isAjax()){
$menu = new MenuModel();
$res = $menu->select();
$this->data['data'] = $res;
return $this->data;
}
}

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\middleware;
namespace app\http\middleware;
use think\facade\View;
@@ -19,6 +19,7 @@ class Admin {
public function handle($request, \Closure $next) {
$response = $next($request);
if (is_array($response->getData())) {
$this->data = array_merge($this->data, $response->getData());
} else {
@@ -52,10 +53,10 @@ class Admin {
$template = (isset($this->data['template']) && $this->data['template']) ? $this->data['template'] : $template;
return View::config($config)
->assign('sent_version', sent_version)
->assign('config', (isset($this->data['config']) ? $this->data['config'] : []))
->assign((isset($this->data['data']) ? $this->data['data'] : []))
->fetch($template);
View::config($config);
View::assign('sent_version', sent_version);
View::assign('config', (isset($this->data['config']) ? $this->data['config'] : []));
View::assign((isset($this->data['data']) ? $this->data['data'] : []));
return View::fetch($template);
}
}

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\middleware;
namespace app\http\middleware;
use think\facade\Cache;
use think\facade\Session;

View File

@@ -6,7 +6,7 @@
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\middleware;
namespace app\http\middleware;
use think\facade\View;
@@ -36,15 +36,17 @@ class Front {
$config = array(
'tpl_replace_string' => array(
'__static__' => '/static',
'__img__' => '/static/admin/images',
'__css__' => '/static/admin/css',
'__js__' => '/static/admin/js',
'__public__' => '/static/admin',
'__img__' => '/static/front/images',
'__css__' => '/static/front/css',
'__js__' => '/static/front/js',
'__public__' => '/static/front',
)
);
if (is_string($this->data)) {
$this->data = array('data' => $this->data);
}
return View::config($config)->assign($this->data)->fetch($template);
View::config($config);
View::assign($this->data);
return View::engine('Think')->fetch($template);
}
}

View File

@@ -7,7 +7,7 @@
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\middleware;
namespace app\http\middleware;
use think\Response;
class Validate {
@@ -24,7 +24,7 @@ class Validate {
$controller = strtr(strtolower($request->controller()), '.', '\\');
//获取操作名,用于验证场景scene
$scene = $request->action();
$validate = "app\\validate\\" . $controller;
$validate = "app\\http\\validate\\" . $controller;
//仅当验证器存在时 进行校验
if (class_exists($validate) && $request->isPost()) {
$v = new $validate;

View File

@@ -7,7 +7,7 @@
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\validate\admin;
namespace app\http\validate\admin;
use think\Validate;