buildadmin/app/common/controller/Backend.php

109 lines
2.8 KiB
PHP
Raw Normal View History

2022-02-24 17:44:00 +00:00
<?php
namespace app\common\controller;
use app\admin\library\Auth;
use think\db\exception\PDOException;
use think\facade\Cookie;
use think\facade\Db;
2022-02-24 17:44:00 +00:00
class Backend extends Api
{
protected $noNeedLogin = [];
protected $noNeedPermission = [];
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-03-10 14:50:16 +00:00
/**
* 权重(排序)字段
*/
protected $weighField = 'weigh';
/**
* 表格拖拽排序时,两个权重相等则自动重新整理
* config/buildadmin.php文件中的auto_sort_eq_weight为默认值
* null=取默认值,false=,true=
*/
protected $autoSortEqWeight = null;
/**
* 快速搜索字段
*/
protected $quickSearchField = 'id';
2022-03-11 17:29:06 +00:00
/**
* 是否开启模型验证
*/
protected $modelValidate = false;
/**
* 是否开启模型场景验证
*/
protected $modelSceneValidate = false;
/**
* 引入traits
* traits内实现了index、add、edit等方法
*/
use \app\admin\library\traits\Backend;
public function initialize()
{
parent::initialize();
// 检测数据库连接
try {
Db::execute("SELECT 1");
} catch (PDOException $e) {
$this->error(mb_convert_encoding($e->getMessage(), 'UTF-8', 'UTF-8,GBK,GB2312,BIG5'));
}
$this->auth = Auth::instance();
$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));
if (!$this->auth->actionInArr($this->noNeedLogin)) {
$this->auth->init($token);
if (!$this->auth->isLogin()) {
$this->error(__('Please login first'), [
2022-02-28 20:54:57 +00:00
'routeName' => 'adminLogin'
], 302);
}
if (!$this->auth->actionInArr($this->noNeedPermission)) {
if (!$this->auth->check($routePath)) {
$this->error(__('You have no permission'), [
'routeName' => 'admin'
2022-02-28 20:54:57 +00:00
], 302);
}
}
} else {
if ($token) {
$this->auth->init($token);
}
}
}
2022-03-08 08:31:49 +00:00
2022-03-13 13:23:43 +00:00
public function queryBuilder()
2022-03-08 08:31:49 +00:00
{
2022-03-14 13:46:51 +00:00
$quickSearch = $this->request->get("quick_search/s", '');
$page = $this->request->get("page/d", 1);
$limit = $this->request->get("limit/d", 10);
$where = [];
$alias = [];
if (!empty($this->model)) {
$tableName = $this->model->getTable();
$alias[$tableName] = $tableName;
}
// print_r($alias);
2022-03-08 08:31:49 +00:00
2022-03-14 13:46:51 +00:00
// 构建好where等返回
2022-03-08 08:31:49 +00:00
}
2022-02-24 17:44:00 +00:00
}