webman-buildadmin框架优化
This commit is contained in:
@@ -845,8 +845,9 @@ class Helper
|
|||||||
return $itemJson;
|
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)) {
|
if (preg_match("/^[a-zA-Z_][a-zA-Z0-9_]+$/", $keyName)) {
|
||||||
return $keyName;
|
return $keyName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,11 +3,16 @@
|
|||||||
* 查看
|
* 查看
|
||||||
* @throws Throwable
|
* @throws Throwable
|
||||||
*/
|
*/
|
||||||
public function index(): void
|
public function index(\Webman\Http\Request $request): \support\Response
|
||||||
{
|
{
|
||||||
// 如果是 select 则转发到 select 方法,若未重写该方法,其实还是继续执行 index
|
$response = $this->initializeBackend($request);
|
||||||
if ($this->request->param('select')) {
|
if ($response !== null) {
|
||||||
$this->select();
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->get('select') || $request->post('select')) {
|
||||||
|
$this->_select();
|
||||||
|
return $this->success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +29,7 @@
|
|||||||
->order($order)
|
->order($order)
|
||||||
->paginate($limit);
|
->paginate($limit);
|
||||||
|
|
||||||
$this->success('', [
|
return $this->success('', [
|
||||||
'list' => $res->items(),
|
'list' => $res->items(),
|
||||||
'total' => $res->total(),
|
'total' => $res->total(),
|
||||||
'remark' => get_route_remark(),
|
'remark' => get_route_remark(),
|
||||||
|
|||||||
@@ -127,13 +127,14 @@ class AdminLog extends Model
|
|||||||
$useragent = strlen($useragent) > 255 ? substr($useragent, 0, 255) : $useragent;
|
$useragent = strlen($useragent) > 255 ? substr($useragent, 0, 255) : $useragent;
|
||||||
|
|
||||||
self::create([
|
self::create([
|
||||||
'admin_id' => $adminId,
|
'admin_id' => $adminId,
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
'data' => !is_scalar($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data,
|
'data' => !is_scalar($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data,
|
||||||
'ip' => $request->getRealIp(),
|
'ip' => $request->getRealIp(),
|
||||||
'useragent' => $useragent,
|
'useragent' => $useragent,
|
||||||
|
'create_time' => time(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ global $argv;
|
|||||||
return [
|
return [
|
||||||
'webman' => [
|
'webman' => [
|
||||||
'handler' => Http::class,
|
'handler' => Http::class,
|
||||||
'listen' => 'http://0.0.0.0:8787',
|
'listen' => 'http://0.0.0.0:6969',
|
||||||
'count' => cpu_count() * 4,
|
'count' => cpu_count() * 4,
|
||||||
'user' => '',
|
'user' => '',
|
||||||
'group' => '',
|
'group' => '',
|
||||||
|
|||||||
@@ -4,5 +4,8 @@ ENV = 'development'
|
|||||||
# base路径
|
# base路径
|
||||||
VITE_BASE_PATH = './'
|
VITE_BASE_PATH = './'
|
||||||
|
|
||||||
# 本地环境接口地址 - 用空字符串走同源,由 vite 代理到 8787,避免 CORS
|
# 本地环境接口地址 - 用空字符串走同源,由 vite 代理到后端,避免 CORS
|
||||||
VITE_AXIOS_BASE_URL = ''
|
VITE_AXIOS_BASE_URL = ''
|
||||||
|
|
||||||
|
# 开发时代理目标地址(后端服务器地址,端口改为 6969 时在此配置)
|
||||||
|
VITE_PROXY_TARGET = http://localhost:6969
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ const pathResolve = (dir: string): any => {
|
|||||||
|
|
||||||
// https://vitejs.cn/config/
|
// https://vitejs.cn/config/
|
||||||
const viteConfig = ({ mode }: ConfigEnv): UserConfig => {
|
const viteConfig = ({ mode }: ConfigEnv): UserConfig => {
|
||||||
const { VITE_PORT, VITE_OPEN, VITE_BASE_PATH, VITE_OUT_DIR } = loadEnv(mode, process.cwd())
|
const { VITE_PORT, VITE_OPEN, VITE_BASE_PATH, VITE_OUT_DIR, VITE_PROXY_TARGET } = loadEnv(mode, process.cwd())
|
||||||
|
|
||||||
const alias: Record<string, string> = {
|
const alias: Record<string, string> = {
|
||||||
'/@': pathResolve('./src/'),
|
'/@': pathResolve('./src/'),
|
||||||
@@ -29,9 +29,9 @@ const viteConfig = ({ mode }: ConfigEnv): UserConfig => {
|
|||||||
open: VITE_OPEN != 'false',
|
open: VITE_OPEN != 'false',
|
||||||
// 开发时把 /api、/admin、/install 代理到 webman,避免跨域
|
// 开发时把 /api、/admin、/install 代理到 webman,避免跨域
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': { target: 'http://localhost:8787', changeOrigin: true },
|
'/api': { target: VITE_PROXY_TARGET || 'http://localhost:6969', changeOrigin: true },
|
||||||
'/admin': { target: 'http://localhost:8787', changeOrigin: true },
|
'/admin': { target: VITE_PROXY_TARGET || 'http://localhost:6969', changeOrigin: true },
|
||||||
'/install': { target: 'http://localhost:8787', changeOrigin: true },
|
'/install': { target: VITE_PROXY_TARGET || 'http://localhost:6969', changeOrigin: true },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
|
|||||||
Reference in New Issue
Block a user