2022-02-24 17:44:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\common\controller;
|
|
|
|
|
|
|
|
use app\admin\library\Auth;
|
2022-02-26 08:34:07 +00:00
|
|
|
use think\facade\Cookie;
|
2022-02-24 17:44:00 +00:00
|
|
|
|
|
|
|
class Backend extends Api
|
|
|
|
{
|
|
|
|
protected $noNeedLogin = [];
|
|
|
|
protected $noNeedPermission = [];
|
2022-03-08 16:15:32 +00:00
|
|
|
protected $preExcludeFields = [];
|
2022-02-24 17:44:00 +00:00
|
|
|
|
2022-02-26 20:55:27 +00:00
|
|
|
/**
|
|
|
|
* 权限类实例
|
|
|
|
* @var Auth
|
|
|
|
*/
|
2022-02-24 17:44:00 +00:00
|
|
|
protected $auth = null;
|
|
|
|
|
|
|
|
protected $model = null;
|
2022-02-26 08:34:07 +00:00
|
|
|
|
2022-03-10 14:50:16 +00:00
|
|
|
/**
|
|
|
|
* 权重(排序)字段
|
|
|
|
*/
|
|
|
|
protected $weighField = 'weigh';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 表格拖拽排序时,两个权重相等则自动重新整理
|
|
|
|
* config/buildadmin.php文件中的auto_sort_eq_weight为默认值
|
|
|
|
* null=取默认值,false=关,true=开
|
|
|
|
*/
|
|
|
|
protected $autoSortEqWeight = null;
|
|
|
|
|
2022-03-09 10:12:15 +00:00
|
|
|
/**
|
|
|
|
* 快速搜索字段
|
|
|
|
*/
|
2022-02-26 08:34:07 +00:00
|
|
|
protected $quickSearchField = 'id';
|
|
|
|
|
2022-03-08 16:15:32 +00:00
|
|
|
/**
|
|
|
|
* 引入traits
|
|
|
|
* traits内实现了index、add、edit等方法
|
|
|
|
*/
|
|
|
|
use \app\admin\library\traits\Backend;
|
|
|
|
|
2022-03-09 10:12:15 +00:00
|
|
|
public function initialize()
|
2022-02-26 08:34:07 +00:00
|
|
|
{
|
2022-03-09 10:12:15 +00:00
|
|
|
parent::initialize();
|
2022-02-26 08:34:07 +00:00
|
|
|
$this->auth = Auth::instance();
|
2022-03-09 10:12:15 +00:00
|
|
|
$routePath = $this->controllerPath . '/' . $this->request->action(true);
|
2022-02-26 20:55:27 +00:00
|
|
|
$token = $this->request->server('HTTP_BATOKEN', $this->request->request('batoken', Cookie::get('batoken') ?: false));
|
2022-02-27 16:44:12 +00:00
|
|
|
if (!$this->auth->actionInArr($this->noNeedLogin)) {
|
2022-02-26 08:34:07 +00:00
|
|
|
$this->auth->init($token);
|
|
|
|
if (!$this->auth->isLogin()) {
|
|
|
|
$this->error(__('Please login first'), [
|
2022-02-28 20:54:57 +00:00
|
|
|
'routeName' => 'adminLogin'
|
|
|
|
], 302);
|
2022-02-26 08:34:07 +00:00
|
|
|
}
|
2022-02-27 16:44:12 +00:00
|
|
|
if (!$this->auth->actionInArr($this->noNeedPermission)) {
|
2022-03-09 10:12:15 +00:00
|
|
|
if (!$this->auth->check($routePath)) {
|
2022-02-27 16:44:12 +00:00
|
|
|
$this->error(__('You have no permission'), [
|
2022-03-01 12:40:44 +00:00
|
|
|
'routeName' => 'admin'
|
2022-02-28 20:54:57 +00:00
|
|
|
], 302);
|
2022-02-27 16:44:12 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-26 08:34:07 +00:00
|
|
|
} else {
|
|
|
|
if ($token) {
|
|
|
|
$this->auth->init($token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-08 08:31:49 +00:00
|
|
|
|
|
|
|
public function select()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2022-02-24 17:44:00 +00:00
|
|
|
}
|