webman-buildadmin框架优化

This commit is contained in:
2026-03-18 19:21:10 +08:00
parent 16f84dce24
commit 9effe705b3
6 changed files with 29 additions and 19 deletions

View File

@@ -845,8 +845,9 @@ class Helper
return $itemJson;
}
public static function formatObjectKey(string $keyName): string
public static function formatObjectKey(string|int $keyName): string
{
$keyName = (string) $keyName;
if (preg_match("/^[a-zA-Z_][a-zA-Z0-9_]+$/", $keyName)) {
return $keyName;
}

View File

@@ -3,11 +3,16 @@
* 查看
* @throws Throwable
*/
public function index(): void
public function index(\Webman\Http\Request $request): \support\Response
{
// 如果是 select 则转发到 select 方法,若未重写该方法,其实还是继续执行 index
if ($this->request->param('select')) {
$this->select();
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
if ($request->get('select') || $request->post('select')) {
$this->_select();
return $this->success();
}
/**
@@ -24,7 +29,7 @@
->order($order)
->paginate($limit);
$this->success('', [
return $this->success('', [
'list' => $res->items(),
'total' => $res->total(),
'remark' => get_route_remark(),

View File

@@ -127,13 +127,14 @@ class AdminLog extends Model
$useragent = strlen($useragent) > 255 ? substr($useragent, 0, 255) : $useragent;
self::create([
'admin_id' => $adminId,
'username' => $username,
'url' => $url,
'title' => $title,
'data' => !is_scalar($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data,
'ip' => $request->getRealIp(),
'useragent' => $useragent,
'admin_id' => $adminId,
'username' => $username,
'url' => $url,
'title' => $title,
'data' => !is_scalar($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data,
'ip' => $request->getRealIp(),
'useragent' => $useragent,
'create_time' => time(),
]);
}