12 Commits

Author SHA1 Message Date
b9f78cacf1 优化项目描述文件README.md 2026-03-21 14:31:16 +08:00
74d2103290 测试分支-部署-预检响应中缺少server请求头 2026-03-21 14:22:58 +08:00
a478c902be 测试分支-部署-预检响应中缺少server请求头 2026-03-21 14:17:42 +08:00
b0d25b30f9 测试分支-部署-优化跨域报错 2026-03-21 14:08:09 +08:00
ac30d8d1c9 测试分支-部署-优化跨域报错 2026-03-21 14:01:11 +08:00
c4c17180ee 测试分支-部署-优化跨域报错 2026-03-21 11:56:21 +08:00
85da91e3f3 测试分支-部署-添加跨域 2026-03-21 11:50:00 +08:00
a0f14015ed 测试分支-部署 2026-03-21 11:30:08 +08:00
9178fd643b Merge remote-tracking branch 'origin/master'
# Conflicts:
#	.env-example
2026-03-21 11:19:28 +08:00
7537c484ee 优化CURD功能 2026-03-21 11:18:11 +08:00
5fd33dd87c 修改连接数据库 2026-03-21 11:17:43 +08:00
37f5bd7e4e 修改连接数据库 2026-03-21 10:44:04 +08:00
14 changed files with 82 additions and 69 deletions

View File

@@ -7,12 +7,17 @@ APP_DEFAULT_TIMEZONE = Asia/Shanghai
# 语言
LANG_DEFAULT_LANG = zh-cn
# Database
# 数据库config/thinkorm.php/database.php
DATABASE_DRIVER = mysql
DATABASE_TYPE = mysql
DATABASE_HOSTNAME = 127.0.0.1
DATABASE_DATABASE = webman-buildadmin-mall
DATABASE_USERNAME = webman-buildadmin-mall
DATABASE_DATABASE = buildadmin-webman
DATABASE_USERNAME = buildadmin-webman
DATABASE_PASSWORD = 123456
DATABASE_HOSTPORT = 3306
DATABASE_CHARSET = utf8mb4
DATABASE_PREFIX =
DATABASE_PREFIX =
# 缓存config/cache.php
CACHE_DRIVER = file

4
.gitignore vendored
View File

@@ -1,8 +1,8 @@
# 通过 Git 部署项目至线上时建议删除的忽略规则
/vendor
/modules
/public/*.lock
/public/index.html
#/public/*.lock
#/public/index.html
/public/assets
# 通过 Git 部署项目至线上时可以考虑删除的忽略规则

View File

@@ -186,6 +186,30 @@ php webman migrate
> 注意:前端通过 Vite 代理将 `/api`、`/admin`、`/install` 转发到后端 8787 端口,请勿直接访问 8787 端口的前端页面,否则可能出现 404。
### 5.6 生产环境 Nginx反向代理 Webman
部署到服务器时,若使用 **Nginx** 作为站点入口,需将请求转发到本机 **Webman** 进程(默认监听端口与 `config/process.php` 中 `listen` 一致,一般为 `8787`,反代目标使用 `127.0.0.1:8787`)。
在站点 **`server { }`** 块中可增加如下写法:**先由 Nginx 根据 `root` 判断是否存在对应静态文件;不存在则转发到 Webman**`root` 建议指向项目 `public` 目录)。
```nginx
location ^~ / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Connection "";
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:8787;
}
}
```
修改配置后执行 `nginx -t` 校验,再重载 Nginx并确保 Webman 已启动(如 `php start.php start -d`)。
若前端与接口为**不同域名**(跨域),除反代外还需保证 **HTTPS 证书与域名一致**,以及后端 **CORS / 预检OPTIONS** 与前端请求头(如 `think-lang`、`server` 等)配置一致,否则浏览器会报跨域相关错误。
---
## 六、路由说明

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 = is_int($keyName) ? strval($keyName) : $keyName;
if (preg_match("/^[a-zA-Z_][a-zA-Z0-9_]+$/", $keyName)) {
return $keyName;
}

View File

@@ -30,7 +30,7 @@ class AllowCrossDomain implements MiddlewareInterface
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Max-Age' => '1800',
'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers' => 'Content-Type, Authorization, batoken, ba-user-token, think-lang',
'Access-Control-Allow-Headers' => 'Content-Type, Authorization, batoken, ba-user-token, think-lang, server',
];
$origin = $request->header('origin');
if (is_array($origin)) {

View File

@@ -3,12 +3,12 @@
namespace app\process;
use Webman\App;
use Webman\Http\Response;
class Http extends App
{
/**
* 在父类处理前拦截 OPTIONS 预检,直接返回 CORS 头(避免预检未命中路由时无 CORS
* 必须与 AllowCrossDomain::optionsResponse 一致,否则会覆盖中间件里对 Allow-Headers如 server的配置
*/
public function onMessage($connection, $request): void
{
@@ -18,19 +18,8 @@ class Http extends App
$path = is_string($path) ? trim($path, '/') : '';
$isApiOrAdmin = $path !== '' && (str_starts_with($path, 'api') || str_starts_with($path, 'admin'));
if ($isApiOrAdmin) {
$origin = $request->header('origin');
$origin = is_array($origin) ? ($origin[0] ?? '') : (is_string($origin) ? trim($origin) : '');
if ($origin === '') {
$origin = '*';
}
$headers = [
'Access-Control-Allow-Origin' => $origin,
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Max-Age' => '1800',
'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers' => 'Content-Type, Authorization, batoken, ba-user-token, think-lang',
];
$connection->send(new Response(204, $headers, ''));
$response = \app\common\middleware\AllowCrossDomain::optionsResponse($request);
$connection->send($response);
return;
}
}

View File

@@ -5,7 +5,7 @@
return [
// 允许跨域访问的域名(* 表示任意;开发可用 *,生产建议填具体域名)
'cors_request_domain' => '*',
'cors_request_domain' => '*,test.zhenhui666.top',
// 是否开启会员登录验证码
'user_login_captcha' => true,
// 是否开启管理员登录验证码

View File

@@ -15,8 +15,8 @@ return [
'driver' => 'mysql',
'host' => $env('database.hostname', '127.0.0.1'),
'port' => $env('database.hostport', '3306'),
'database' => $env('database.database', 'dafuweng-buildadmin'),
'username' => $env('database.username', 'dafuweng-buildadmin'),
'database' => $env('database.database', 'buildadmin-webman'),
'username' => $env('database.username', 'buildadmin-webman'),
'password' => $env('database.password', '123456'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',

View File

@@ -42,9 +42,9 @@ return [
// 服务器地址
'hostname' => $env('database.hostname', '127.0.0.1'),
// 数据库名(与 database.php / .env 一致)
'database' => $env('database.database', 'dafuweng-buildadmin-webman'),
'database' => $env('database.database', 'buildadmin-webman'),
// 用户名(与 .env DATABASE_USERNAME 一致,默认勿用 root 以免与本机 MySQL 不符)
'username' => $env('database.username', 'dafuweng-buildadmin-webman'),
'username' => $env('database.username', 'buildadmin-webman'),
// 密码(与 .env DATABASE_PASSWORD 一致)
'password' => $env('database.password', '123456'),
// 端口

View File

@@ -1,40 +0,0 @@
# BuildAdmin Webman - Nginx 反向代理示例
# 将 server_name 和 root 改为实际值后,放入 nginx 的 conf.d 或 sites-available
upstream webman {
server 127.0.0.1:8787;
keepalive 10240;
}
server {
server_name 你的域名;
listen 80;
access_log off;
root /path/to/dafuweng-webman/public;
location / {
try_files $uri $uri/ @proxy;
}
location @proxy {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://webman;
}
location ~ \.php$ {
return 404;
}
location ~ ^/\.well-known/ {
allow all;
}
location ~ /\. {
return 404;
}
}

23
public/index.html Normal file

File diff suppressed because one or more lines are too long

1
public/install.lock Normal file
View File

@@ -0,0 +1 @@
2026-03-18 11:17:18

View File

@@ -8,4 +8,4 @@ VITE_BASE_PATH = '/'
VITE_OUT_DIR = 'dist'
# 线上环境接口地址 - 'getCurrentDomain:表示获取当前域名'
VITE_AXIOS_BASE_URL = 'getCurrentDomain'
VITE_AXIOS_BASE_URL = 'https://test-api.zhenhui666.top'

View File

@@ -95,7 +95,7 @@
:label-width="140"
:block-help="t('crud.crud.For quick combination code generation location, please fill in the relative path')"
:input-attr="{
onChange: onTableChange,
onChange: (val) => onTableChange(val ?? state.table.generateRelativePath?.replace(/\\/g, '/') ?? state.table.name ?? ''),
onInput: debouncedOnRelativePathInput,
}"
/>
@@ -1396,6 +1396,16 @@ const loadData = () => {
}
state.table.isCommonModel = parseInt(res.data.table.isCommonModel)
state.table.databaseConnection = res.data.table.databaseConnection ? res.data.table.databaseConnection : ''
// 复制设计时,根据接口返回刷新路径,确保与 getFileData 一致
const tableName = state.table.name || state.table.generateRelativePath?.replace(/\\/g, '/')
if (tableName) {
getFileData(tableName, state.table.isCommonModel).then((fileRes) => {
state.table.modelFile = fileRes.data.modelFile
state.table.controllerFile = fileRes.data.controllerFile
state.table.validateFile = fileRes.data.validateFile
state.table.webViewsDir = fileRes.data.webViewsDir
}).catch(() => {})
}
})
.finally(() => {
state.loading.init = false