webman迁移-优化
This commit is contained in:
@@ -109,10 +109,16 @@ class Index extends Backend
|
||||
$res = $this->auth->login($username, $password, (bool) $keep);
|
||||
if ($res === true) {
|
||||
$userInfo = $this->auth->getInfo();
|
||||
// 兜底:若 getInfo 未返回 token,在控制器层生成并入库
|
||||
if (empty($userInfo['token']) && $this->auth->isLogin()) {
|
||||
$adminId = $this->auth->id;
|
||||
$keepTime = (int) config('buildadmin.admin_token_keep_time', 86400 * 3);
|
||||
// 兜底:若 getInfo 未返回 token,在控制器层生成并入库(login 成功时必有 adminId)
|
||||
if (empty($userInfo['token']) && $adminId) {
|
||||
$userInfo['token'] = Random::uuid();
|
||||
Token::set($userInfo['token'], \app\admin\library\Auth::TOKEN_TYPE, $this->auth->id, (int) config('buildadmin.admin_token_keep_time', 86400 * 3));
|
||||
Token::set($userInfo['token'], \app\admin\library\Auth::TOKEN_TYPE, $adminId, $keepTime);
|
||||
}
|
||||
if (empty($userInfo['refresh_token']) && $keep && $adminId) {
|
||||
$userInfo['refresh_token'] = Random::uuid();
|
||||
Token::set($userInfo['refresh_token'], \app\admin\library\Auth::TOKEN_TYPE . '-refresh', $adminId, 2592000);
|
||||
}
|
||||
return $this->success(__('Login succeeded!'), [
|
||||
'userInfo' => $userInfo
|
||||
|
||||
@@ -41,8 +41,8 @@ class Group extends Backend
|
||||
$this->tree = Tree::instance();
|
||||
|
||||
$isTree = $request->get('isTree') ?? $request->post('isTree') ?? true;
|
||||
$this->initValue = $request->get('initValue') ?? [];
|
||||
$this->initValue = is_array($this->initValue) ? array_filter($this->initValue) : [];
|
||||
$initValue = $request->get('initValue') ?? $request->post('initValue') ?? [];
|
||||
$this->initValue = is_array($initValue) ? array_filter($initValue) : [];
|
||||
$this->keyword = $request->get('quickSearch') ?? $request->post('quickSearch') ?? '';
|
||||
|
||||
$this->assembleTree = $isTree && !$this->initValue;
|
||||
@@ -185,9 +185,10 @@ class Group extends Backend
|
||||
unset($rules[$ruKey]);
|
||||
}
|
||||
}
|
||||
$row->rules = array_values($rules);
|
||||
$rowData = $row->toArray();
|
||||
$rowData['rules'] = array_values($rules);
|
||||
return $this->success('', [
|
||||
'row' => $row
|
||||
'row' => $rowData
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -323,7 +324,7 @@ class Group extends Backend
|
||||
$rules = explode(',', $datum['rules']);
|
||||
if ($rules) {
|
||||
$rulesFirstTitle = AdminRule::where('id', $rules[0])->value('title');
|
||||
$datum['rules'] = count($rules) == 1 ? $rulesFirstTitle : $rulesFirstTitle . '等 ' . count($rules) . ' 项';
|
||||
$datum['rules'] = count($rules) == 1 ? $rulesFirstTitle : __('%first% etc. %count% items', ['%first%' => $rulesFirstTitle, '%count%' => count($rules)]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -39,8 +39,8 @@ class Rule extends Backend
|
||||
$this->model = new AdminRule();
|
||||
$this->tree = Tree::instance();
|
||||
$isTree = $request->get('isTree') ?? $request->post('isTree') ?? true;
|
||||
$this->initValue = $request->get('initValue') ?? [];
|
||||
$this->initValue = is_array($this->initValue) ? array_filter($this->initValue) : [];
|
||||
$initValue = $request->get('initValue') ?? $request->post('initValue') ?? [];
|
||||
$this->initValue = is_array($initValue) ? array_filter($initValue) : [];
|
||||
$this->keyword = $request->get('quickSearch') ?? $request->post('quickSearch') ?? '';
|
||||
$this->assembleTree = $isTree && !$this->initValue;
|
||||
return null;
|
||||
|
||||
@@ -30,6 +30,7 @@ class Crud extends Backend
|
||||
protected string $webTranslate = '';
|
||||
protected array $langTsData = [];
|
||||
protected array $dtStringToArray = ['checkbox', 'selects', 'remoteSelects', 'city', 'images', 'files'];
|
||||
protected array $noNeedLogin = ['getFileData'];
|
||||
protected array $noNeedPermission = ['logStart', 'getFileData', 'parseFieldData', 'generateCheck', 'uploadCompleted'];
|
||||
|
||||
protected function initController(Request $request): ?Response
|
||||
@@ -288,56 +289,61 @@ class Crud extends Backend
|
||||
|
||||
public function getFileData(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) return $response;
|
||||
|
||||
$table = $request->get('table');
|
||||
$commonModel = $request->get('commonModel', false);
|
||||
|
||||
if (!$table) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
|
||||
try {
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) return $response;
|
||||
|
||||
$table = $request->get('table');
|
||||
$commonModel = $request->get('commonModel', false);
|
||||
|
||||
if (!$table) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
|
||||
$modelFile = Helper::parseNameData($commonModel ? 'common' : 'admin', $table, 'model');
|
||||
$validateFile = Helper::parseNameData($commonModel ? 'common' : 'admin', $table, 'validate');
|
||||
$controllerFile = Helper::parseNameData('admin', $table, 'controller');
|
||||
$webViewsDir = Helper::parseWebDirNameData($table, 'views');
|
||||
|
||||
$adminModelDir = root_path() . 'app' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR;
|
||||
$commonModelDir = root_path() . 'app' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR;
|
||||
$adminModelFiles = is_dir($adminModelDir) ? Filesystem::getDirFiles($adminModelDir) : [];
|
||||
$commonModelFiles = is_dir($commonModelDir) ? Filesystem::getDirFiles($commonModelDir) : [];
|
||||
$adminControllerFiles = get_controller_list();
|
||||
|
||||
$modelFileList = [];
|
||||
$controllerFiles = [];
|
||||
foreach ($adminModelFiles as $item) {
|
||||
$item = Filesystem::fsFit('app/admin/model/' . $item);
|
||||
$modelFileList[$item] = $item;
|
||||
}
|
||||
foreach ($commonModelFiles as $item) {
|
||||
$item = Filesystem::fsFit('app/common/model/' . $item);
|
||||
$modelFileList[$item] = $item;
|
||||
}
|
||||
|
||||
$outExcludeController = ['Addon.php', 'Ajax.php', 'Dashboard.php', 'Index.php', 'Module.php', 'Terminal.php', 'routine/AdminInfo.php', 'routine/Config.php'];
|
||||
foreach ($adminControllerFiles as $item) {
|
||||
if (!in_array($item, $outExcludeController)) {
|
||||
$item = Filesystem::fsFit('app/admin/controller/' . $item);
|
||||
$controllerFiles[$item] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
// 路径统一使用正斜杠,便于 UI 展示及跨平台一致(相对于 dafuweng-webman 项目根)
|
||||
$pathFit = fn(string $p): string => str_replace('\\', '/', $p);
|
||||
|
||||
return $this->success('', [
|
||||
'modelFile' => $pathFit($modelFile['rootFileName']),
|
||||
'controllerFile' => $pathFit($controllerFile['rootFileName']),
|
||||
'validateFile' => $pathFit($validateFile['rootFileName']),
|
||||
'controllerFileList' => array_map($pathFit, $controllerFiles),
|
||||
'modelFileList' => array_map($pathFit, $modelFileList),
|
||||
'webViewsDir' => $pathFit($webViewsDir['views']),
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$adminModelFiles = Filesystem::getDirFiles(root_path() . 'app' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR);
|
||||
$commonModelFiles = Filesystem::getDirFiles(root_path() . 'app' . DIRECTORY_SEPARATOR . 'common' . DIRECTORY_SEPARATOR . 'model' . DIRECTORY_SEPARATOR);
|
||||
$adminControllerFiles = get_controller_list();
|
||||
|
||||
$modelFileList = [];
|
||||
$controllerFiles = [];
|
||||
foreach ($adminModelFiles as $item) {
|
||||
$item = Filesystem::fsFit('app/admin/model/' . $item);
|
||||
$modelFileList[$item] = $item;
|
||||
}
|
||||
foreach ($commonModelFiles as $item) {
|
||||
$item = Filesystem::fsFit('app/common/model/' . $item);
|
||||
$modelFileList[$item] = $item;
|
||||
}
|
||||
|
||||
$outExcludeController = ['Addon.php', 'Ajax.php', 'Dashboard.php', 'Index.php', 'Module.php', 'Terminal.php', 'routine/AdminInfo.php', 'routine/Config.php'];
|
||||
foreach ($adminControllerFiles as $item) {
|
||||
if (!in_array($item, $outExcludeController)) {
|
||||
$item = Filesystem::fsFit('app/admin/controller/' . $item);
|
||||
$controllerFiles[$item] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success('', [
|
||||
'modelFile' => $modelFile['rootFileName'],
|
||||
'controllerFile' => $controllerFile['rootFileName'],
|
||||
'validateFile' => $validateFile['rootFileName'],
|
||||
'controllerFileList' => $controllerFiles,
|
||||
'modelFileList' => $modelFileList,
|
||||
'webViewsDir' => $webViewsDir['views'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkCrudLog(Request $request): Response
|
||||
@@ -478,8 +484,8 @@ class Crud extends Backend
|
||||
$tableName = TableManager::tableName($field['form']['remote-table'], false, $table['databaseConnection'] ?? null);
|
||||
$rnPattern = '/(.*)(_ids|_id)$/';
|
||||
$relationName = preg_match($rnPattern, $field['name'])
|
||||
? parse_name(preg_replace($rnPattern, '$1', $field['name']), 1, false)
|
||||
: parse_name($field['name'] . '_table', 1, false);
|
||||
? parse_name(preg_replace($rnPattern, '$1', $field['name']), 1)
|
||||
: parse_name($field['name'] . '_table', 1);
|
||||
|
||||
if (empty($field['form']['remote-model']) || !file_exists(root_path() . $field['form']['remote-model'])) {
|
||||
$joinModelFile = Helper::parseNameData('admin', $tableName, 'model', $field['form']['remote-model'] ?? '');
|
||||
@@ -613,7 +619,8 @@ class Crud extends Backend
|
||||
{
|
||||
if (($field['designType'] ?? '') == 'editor') {
|
||||
$this->formVueData['bigDialog'] = true;
|
||||
$this->controllerData['filterRule'] = "\n" . Helper::tab(2) . '$this->request->filter(\'clean_xss\');';
|
||||
// Webman Request 无 filter 方法,使用 inputFilter 由 Backend trait 在 add/edit 时应用
|
||||
$this->controllerData['filterRule'] = "\n" . Helper::tab(2) . '$this->inputFilter = \'clean_xss\';';
|
||||
}
|
||||
if (!empty($table['defaultSortField']) && !empty($table['defaultSortType'])) {
|
||||
$defaultSortField = "{$table['defaultSortField']},{$table['defaultSortType']}";
|
||||
|
||||
@@ -24,6 +24,25 @@ class Group extends Backend
|
||||
return null;
|
||||
}
|
||||
|
||||
public function select(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) return $response;
|
||||
|
||||
list($where, $alias, $limit, $order) = $this->queryBuilder();
|
||||
$data = $this->model
|
||||
->alias($alias)
|
||||
->where($where)
|
||||
->order($order)
|
||||
->limit(9999)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $this->success('', [
|
||||
'options' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
public function add(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
@@ -106,8 +125,9 @@ class Group extends Backend
|
||||
unset($rules[$ruKey]);
|
||||
}
|
||||
}
|
||||
$row->rules = array_values($rules);
|
||||
return $this->success('', ['row' => $row]);
|
||||
$rowData = $row->toArray();
|
||||
$rowData['rules'] = array_values($rules);
|
||||
return $this->success('', ['row' => $rowData]);
|
||||
}
|
||||
|
||||
private function handleRules(array $data): array
|
||||
|
||||
@@ -27,8 +27,8 @@ class Rule extends Backend
|
||||
$this->model = new UserRule();
|
||||
$this->tree = Tree::instance();
|
||||
$isTree = filter_var($request->get('isTree', $request->post('isTree', true)), FILTER_VALIDATE_BOOLEAN);
|
||||
$this->initValue = $request->get('initValue', $request->post('initValue', []));
|
||||
$this->initValue = is_array($this->initValue) ? array_filter($this->initValue) : [];
|
||||
$initValue = $request->get('initValue') ?? $request->post('initValue') ?? [];
|
||||
$this->initValue = is_array($initValue) ? array_filter($initValue) : [];
|
||||
$this->keyword = $request->get('quickSearch', $request->post('quickSearch', ''));
|
||||
$this->assembleTree = $isTree && !$this->initValue;
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user