From d9af0a0b7f2ddac78e1afe5d2ebf117e88745d02 Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Wed, 22 Jul 2026 15:16:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9A=E5=9C=A8=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E8=AE=BE=E7=BD=AE=E4=B8=AD=E7=AE=A1=E7=90=86=E5=A4=9A?= =?UTF-8?q?=E4=B8=AA=E4=BA=91=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/SystemSettings/Databases.php | 321 +++++++++++------- app/Http/Livewire/Menu/Settings.php | 4 + app/Models/Settings/DatabaseConnection.php | 7 + ..._fields_to_system_database_connections.php | 37 ++ .../Services/UpstreamOdbcConnection.php | 52 ++- .../Services/UpstreamQueryCache.php | 8 +- .../Services/UpstreamSourceRegistry.php | 8 +- .../Services/UpstreamStoredConfiguration.php | 75 ++++ .../system_settings/databases/form.blade.php | 95 +++--- .../system_settings/databases/index.blade.php | 83 +++-- .../partials/navigation.blade.php | 16 +- routes/admin.php | 7 + .../SystemSettings/UpstreamDatabasesTest.php | 146 ++++++++ 13 files changed, 642 insertions(+), 217 deletions(-) create mode 100644 database/migrations/2026_07_22_150000_add_upstream_fields_to_system_database_connections.php create mode 100644 modules/EcommerceFinance/Services/UpstreamStoredConfiguration.php create mode 100644 tests/Feature/SystemSettings/UpstreamDatabasesTest.php diff --git a/app/Http/Controllers/SystemSettings/Databases.php b/app/Http/Controllers/SystemSettings/Databases.php index 27ebc337..b4bffb3f 100644 --- a/app/Http/Controllers/SystemSettings/Databases.php +++ b/app/Http/Controllers/SystemSettings/Databases.php @@ -6,190 +6,279 @@ use App\Models\Settings\DatabaseConnection; use App\Utilities\SystemAccess; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use Illuminate\Support\Facades\DB; use Illuminate\Validation\Rule; +use Illuminate\Validation\ValidationException; +use Modules\EcommerceFinance\Services\UpstreamOdbcConnection; +use Modules\EcommerceFinance\Services\UpstreamSourceRegistry; +use Modules\EcommerceFinance\Services\UpstreamStoredConfiguration; +use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; class Databases extends Controller { public function __construct() { $this->middleware(function ($request, $next) { - abort_unless(SystemAccess::canOpenSettings(), 403); + abort_unless(SystemAccess::isSuperAdmin(), 403); return $next($request); }); } - public function index() + public function index(UpstreamStoredConfiguration $storedConfiguration) { + $defaultConnection = (string) config('database.default'); + $systemDatabase = (array) config('database.connections.' . $defaultConnection, []); + return view('system_settings.databases.index', [ - 'connections' => DatabaseConnection::where('company_id', company_id())->orderBy('id')->get(), + 'connections' => $storedConfiguration->editable() + ? DatabaseConnection::query() + ->where('company_id', UpstreamStoredConfiguration::SYSTEM_COMPANY_ID) + ->orderBy('name') + ->get() + : collect(), + 'sourceLabels' => $this->sourceLabels(), + 'systemDatabase' => [ + 'connection' => $defaultConnection, + 'driver' => $systemDatabase['driver'] ?? $defaultConnection, + 'host' => $systemDatabase['host'] ?? '本机文件', + 'port' => $systemDatabase['port'] ?? null, + 'database' => $systemDatabase['database'] ?? '', + ], + 'editable' => $storedConfiguration->editable(), ]); } - public function create() + public function create(UpstreamStoredConfiguration $storedConfiguration) { - return view('system_settings.databases.form', ['connection' => null]); + abort_unless($storedConfiguration->editable(), 403); + + return view('system_settings.databases.form', [ + 'connection' => null, + 'sourceLabels' => $this->sourceLabels(), + 'values' => $this->defaultValues(), + ]); } - public function store(Request $request) + public function store(Request $request, UpstreamStoredConfiguration $storedConfiguration) { - $data = $this->validateConnection($request); - $data['company_id'] = company_id(); - $data['enabled'] = (bool) ($data['enabled'] ?? false); + abort_unless($storedConfiguration->editable(), 403); - DatabaseConnection::create($data); + $data = $this->validateConnection($request); + $connection = DatabaseConnection::create($this->attributes($data, null, $request)); + $this->resetSource($connection->source_key, $storedConfiguration); flash('数据库配置已新增。')->success(); return redirect()->route('system-settings.databases.index'); } - public function edit(int $id) + public function edit(int $connection, UpstreamStoredConfiguration $storedConfiguration) { + abort_unless($storedConfiguration->editable(), 403); + $connection = $this->connection($connection); + return view('system_settings.databases.form', [ - 'connection' => $this->findConnection($id), + 'connection' => $connection, + 'sourceLabels' => $this->sourceLabels(), + 'values' => $this->values($connection), ]); } - public function update(int $id, Request $request) + public function update(int $connection, Request $request, UpstreamStoredConfiguration $storedConfiguration) { - $connection = $this->findConnection($id); + abort_unless($storedConfiguration->editable(), 403); + $connection = $this->connection($connection); + $oldSource = $connection->source_key; $data = $this->validateConnection($request, $connection); - $data['enabled'] = (bool) ($data['enabled'] ?? false); + $connection->update($this->attributes($data, $connection, $request)); - if (empty($data['password'])) { - unset($data['password']); - } - - $connection->update($data); + $this->resetSource($oldSource, $storedConfiguration); + $this->resetSource($connection->source_key, $storedConfiguration); flash('数据库配置已修改。')->success(); return redirect()->route('system-settings.databases.index'); } - public function destroy(int $id) + public function destroy(int $connection, UpstreamStoredConfiguration $storedConfiguration) { - $this->findConnection($id)->delete(); + abort_unless($storedConfiguration->editable(), 403); + $connection = $this->connection($connection); + $source = $connection->source_key; + $connection->delete(); + $this->resetSource($source, $storedConfiguration); flash('数据库配置已删除。')->success(); return redirect()->route('system-settings.databases.index'); } - public function export() + public function test(int $connection, UpstreamStoredConfiguration $storedConfiguration) { - $connections = DatabaseConnection::where('company_id', company_id())->orderBy('id')->get(); + abort_unless($storedConfiguration->editable(), 403); + $connection = $this->connection($connection); - return response()->streamDownload(function () use ($connections) { - $stream = fopen('php://output', 'w'); - fwrite($stream, "\xEF\xBB\xBF"); - fputcsv($stream, ['name', 'driver', 'host', 'port', 'database_name', 'username', 'password', 'charset', 'enabled']); - - foreach ($connections as $connection) { - fputcsv($stream, [ - $connection->name, - $connection->driver, - $connection->host, - $connection->port, - $connection->database_name, - $connection->username, - '', - $connection->charset, - $connection->enabled ? 1 : 0, - ]); - } - - fclose($stream); - }, 'database-connections.csv', ['Content-Type' => 'text/csv; charset=UTF-8']); - } - - public function import(Request $request) - { - $request->validate(['file' => ['required', 'file', 'mimes:csv,txt', 'max:5120']]); - - $handle = fopen($request->file('file')->getRealPath(), 'r'); - $header = fgetcsv($handle); - $header = array_map(fn ($value) => trim((string) $value, "\xEF\xBB\xBF \t\n\r\0\x0B"), $header ?: []); - $required = ['name', 'driver', 'database_name']; - - if (array_diff($required, $header)) { - fclose($handle); - - return back()->withErrors(['file' => '文件表头不正确,请先导出模板后填写。']); + try { + UpstreamOdbcConnection::probeConfiguration($this->odbcConfiguration($connection), $connection->name); + } catch (ServiceUnavailableHttpException) { + throw ValidationException::withMessages([ + 'connection' => '连接失败。请检查地址、端口、数据库、账号、网络白名单和本机 ODBC 驱动。', + ]); } - $count = 0; - - DB::transaction(function () use ($handle, $header, &$count) { - while (($row = fgetcsv($handle)) !== false) { - if (count(array_filter($row, fn ($value) => trim((string) $value) !== '')) === 0) { - continue; - } - - $row = array_pad($row, count($header), ''); - $data = array_combine($header, array_slice($row, 0, count($header))); - $driver = in_array($data['driver'] ?? '', ['mysql', 'pgsql', 'sqlite', 'sqlsrv'], true) - ? $data['driver'] - : 'mysql'; - - $attributes = [ - 'driver' => $driver, - 'host' => $data['host'] ?: null, - 'port' => ($data['port'] ?? '') !== '' ? (int) $data['port'] : null, - 'database_name' => trim((string) ($data['database_name'] ?? '')), - 'username' => $data['username'] ?: null, - 'charset' => $data['charset'] ?: 'utf8mb4', - 'enabled' => filter_var($data['enabled'] ?? true, FILTER_VALIDATE_BOOL), - ]; - - if (($data['password'] ?? '') !== '') { - $attributes['password'] = $data['password']; - } - - if (trim((string) ($data['name'] ?? '')) === '' || $attributes['database_name'] === '') { - continue; - } - - DatabaseConnection::updateOrCreate( - ['company_id' => company_id(), 'name' => trim($data['name'])], - $attributes - ); - $count++; - } - }); - - fclose($handle); - flash("已导入 {$count} 条数据库配置。")->success(); + flash($connection->name . '连接成功,仅执行了 SELECT 1 只读测试。')->success(); return redirect()->route('system-settings.databases.index'); } - private function findConnection(int $id): DatabaseConnection - { - return DatabaseConnection::where('company_id', company_id())->findOrFail($id); - } - private function validateConnection(Request $request, ?DatabaseConnection $connection = null): array { + $sourceKeys = array_keys($this->sourceLabels()); + return $request->validate([ 'name' => [ 'required', 'string', 'max:191', Rule::unique('system_database_connections', 'name') - ->where(fn ($query) => $query->where('company_id', company_id())) + ->where(fn ($query) => $query->where('company_id', UpstreamStoredConfiguration::SYSTEM_COMPANY_ID)) ->ignore($connection?->id), ], - 'driver' => ['required', Rule::in(['mysql', 'pgsql', 'sqlite', 'sqlsrv'])], - 'host' => ['nullable', 'string', 'max:191'], - 'port' => ['nullable', 'integer', 'between:1,65535'], - 'database_name' => ['required', 'string', 'max:191'], - 'username' => ['nullable', 'string', 'max:191'], - 'password' => ['nullable', 'string', 'max:1000'], - 'charset' => ['required', 'string', 'max:30'], + 'source_key' => [ + 'nullable', + Rule::in($sourceKeys), + Rule::unique('system_database_connections', 'source_key') + ->where(fn ($query) => $query->where('company_id', UpstreamStoredConfiguration::SYSTEM_COMPANY_ID)) + ->ignore($connection?->id), + ], + 'host' => ['required', 'string', 'max:191', 'not_regex:/[;\x00-\x1F]/'], + 'port' => ['required', 'integer', 'between:1,65535'], + 'database_name' => ['required', 'string', 'max:191', 'not_regex:/[;\x00-\x1F]/'], + 'username' => ['required', 'string', 'max:191', 'not_regex:/[;\x00-\x1F]/'], + 'password' => [$connection ? 'nullable' : 'required', 'string', 'max:1000'], + 'odbc_driver' => ['required', 'string', 'max:128', 'not_regex:/[;{}\x00-\x1F]/'], + 'tds_version' => ['required', 'regex:/^\d+(?:\.\d+)?$/', 'max:16'], + 'connect_timeout' => ['required', 'integer', 'between:1,30'], + 'query_timeout' => ['required', 'integer', 'between:1,120'], + 'allowed_scopes' => ['nullable', 'string', 'max:4000'], 'enabled' => ['nullable', 'boolean'], ]); } + + private function attributes(array $data, ?DatabaseConnection $connection, Request $request): array + { + $attributes = [ + 'company_id' => UpstreamStoredConfiguration::SYSTEM_COMPANY_ID, + 'source_key' => $data['source_key'] ?? null, + 'name' => trim($data['name']), + 'driver' => 'sqlsrv', + 'host' => trim($data['host']), + 'port' => (int) $data['port'], + 'database_name' => trim($data['database_name']), + 'username' => trim($data['username']), + 'odbc_driver' => trim($data['odbc_driver']), + 'tds_version' => trim($data['tds_version']), + 'connect_timeout' => (int) $data['connect_timeout'], + 'query_timeout' => (int) $data['query_timeout'], + 'allowed_scopes' => $this->parseScopes((string) ($data['allowed_scopes'] ?? '')), + 'charset' => 'UTF-8', + 'enabled' => $request->boolean('enabled'), + ]; + + if (! empty($data['password'])) { + $attributes['password'] = $data['password']; + } + + return $attributes; + } + + private function parseScopes(string $value): array + { + $scopes = array_values(array_unique(array_filter(array_map('trim', preg_split('/[,\r\n]+/', $value) ?: [])))); + + foreach ($scopes as $scope) { + if ($scope === '*' || preg_match('/^[a-z0-9_.-]+(?:\.\*)?$/i', $scope) !== 1) { + throw ValidationException::withMessages([ + 'allowed_scopes' => '数据范围只允许精确名称或“前缀.*”,不能使用全局 *。', + ]); + } + } + + return $scopes; + } + + private function connection(int $id): DatabaseConnection + { + return DatabaseConnection::query() + ->where('company_id', UpstreamStoredConfiguration::SYSTEM_COMPANY_ID) + ->findOrFail($id); + } + + private function sourceLabels(): array + { + return collect((array) config('upstreams.sources', [])) + ->mapWithKeys(fn (array $source, string $key) => [$key => $source['label'] ?? $key]) + ->all(); + } + + private function defaultValues(): array + { + return [ + 'name' => '', + 'source_key' => '', + 'enabled' => false, + 'host' => '', + 'port' => 1433, + 'database_name' => '', + 'username' => '', + 'odbc_driver' => 'FreeTDS', + 'tds_version' => '7.4', + 'connect_timeout' => 5, + 'query_timeout' => 15, + 'allowed_scopes' => '', + ]; + } + + private function values(DatabaseConnection $connection): array + { + return [ + 'name' => $connection->name, + 'source_key' => $connection->source_key, + 'enabled' => $connection->enabled, + 'host' => $connection->host, + 'port' => $connection->port, + 'database_name' => $connection->database_name, + 'username' => $connection->username, + 'odbc_driver' => $connection->odbc_driver, + 'tds_version' => $connection->tds_version, + 'connect_timeout' => $connection->connect_timeout, + 'query_timeout' => $connection->query_timeout, + 'allowed_scopes' => implode(', ', $connection->allowed_scopes ?? []), + ]; + } + + private function odbcConfiguration(DatabaseConnection $connection): array + { + return [ + 'host' => $connection->host, + 'port' => $connection->port, + 'database' => $connection->database_name, + 'username' => $connection->username, + 'password' => $connection->password, + 'odbc_driver' => $connection->odbc_driver, + 'tds_version' => $connection->tds_version, + 'connect_timeout' => $connection->connect_timeout, + 'query_timeout' => $connection->query_timeout, + ]; + } + + private function resetSource(?string $source, UpstreamStoredConfiguration $storedConfiguration): void + { + if (! $source) { + return; + } + + $storedConfiguration->forget($source); + UpstreamOdbcConnection::reset($source); + } } diff --git a/app/Http/Livewire/Menu/Settings.php b/app/Http/Livewire/Menu/Settings.php index f3697ae5..0b283869 100644 --- a/app/Http/Livewire/Menu/Settings.php +++ b/app/Http/Livewire/Menu/Settings.php @@ -29,6 +29,10 @@ class Settings extends Component ['system-settings.sidebar.edit', '侧边栏管理', 'menu', '侧边栏 用户类型 指定管理员'], ]; + if (SystemAccess::isSuperAdmin()) { + $items[] = ['system-settings.databases.index', '数据库管理', 'storage', '数据库 云数据库 上游 连接 测试']; + } + foreach ($items as $index => [$route, $title, $icon, $keywords]) { if ($this->keyword && ! Str::contains(Str::lower($title . ' ' . $keywords), Str::lower($this->keyword))) { continue; diff --git a/app/Models/Settings/DatabaseConnection.php b/app/Models/Settings/DatabaseConnection.php index e95ad8aa..6bee08d3 100644 --- a/app/Models/Settings/DatabaseConnection.php +++ b/app/Models/Settings/DatabaseConnection.php @@ -10,6 +10,7 @@ class DatabaseConnection extends Model protected $fillable = [ 'company_id', + 'source_key', 'name', 'driver', 'host', @@ -17,12 +18,18 @@ class DatabaseConnection extends Model 'database_name', 'username', 'password', + 'odbc_driver', + 'tds_version', + 'connect_timeout', + 'query_timeout', + 'allowed_scopes', 'charset', 'enabled', ]; protected $casts = [ 'password' => 'encrypted', + 'allowed_scopes' => 'array', 'enabled' => 'boolean', ]; diff --git a/database/migrations/2026_07_22_150000_add_upstream_fields_to_system_database_connections.php b/database/migrations/2026_07_22_150000_add_upstream_fields_to_system_database_connections.php new file mode 100644 index 00000000..a1762b20 --- /dev/null +++ b/database/migrations/2026_07_22_150000_add_upstream_fields_to_system_database_connections.php @@ -0,0 +1,37 @@ +string('source_key', 64)->nullable()->after('company_id'); + $table->string('odbc_driver', 128)->nullable()->after('password'); + $table->string('tds_version', 16)->nullable()->after('odbc_driver'); + $table->unsignedInteger('connect_timeout')->nullable()->after('tds_version'); + $table->unsignedInteger('query_timeout')->nullable()->after('connect_timeout'); + $table->text('allowed_scopes')->nullable()->after('query_timeout'); + + $table->unique(['company_id', 'source_key'], 'system_database_connections_source_unique'); + }); + } + + public function down(): void + { + Schema::table('system_database_connections', function (Blueprint $table) { + $table->dropUnique('system_database_connections_source_unique'); + $table->dropColumn([ + 'source_key', + 'odbc_driver', + 'tds_version', + 'connect_timeout', + 'query_timeout', + 'allowed_scopes', + ]); + }); + } +}; diff --git a/modules/EcommerceFinance/Services/UpstreamOdbcConnection.php b/modules/EcommerceFinance/Services/UpstreamOdbcConnection.php index e4971569..d5c05cfd 100644 --- a/modules/EcommerceFinance/Services/UpstreamOdbcConnection.php +++ b/modules/EcommerceFinance/Services/UpstreamOdbcConnection.php @@ -24,15 +24,59 @@ class UpstreamOdbcConnection } public static function create(string $source): PDO + { + return self::connect($source, true); + } + + public static function probe(string $source): void { $sources = app(UpstreamSourceRegistry::class); $definition = $sources->definition($source); - if (! $sources->enabled($source)) { + self::probeConfiguration( + (array) $sources->value($source, 'connection', []), + $definition['label'], + $definition['key'], + ); + } + + public static function probeConfiguration(array $connection, string $label, string $source = 'custom'): void + { + $pdo = self::open($connection, $source, $label); + + try { + $statement = $pdo->query('SELECT 1'); + $statement->fetchColumn(); + } catch (PDOException $exception) { + Log::warning('上游数据库只读连接探测失败。', [ + 'source' => $source, + 'source_label' => $label, + 'sql_state' => (string) $exception->getCode(), + 'exception' => $exception::class, + ]); + + throw new ServiceUnavailableHttpException(60, '上游数据库连接探测失败,请检查配置。'); + } + } + + private static function connect(string $source, bool $requireEnabled): PDO + { + $sources = app(UpstreamSourceRegistry::class); + $definition = $sources->definition($source); + + if ($requireEnabled && ! $sources->enabled($source)) { throw new ServiceUnavailableHttpException(60, '该上游数据同步尚未启用,请联系管理员。'); } - $connection = (array) $sources->value($source, 'connection', []); + return self::open( + (array) $sources->value($source, 'connection', []), + $definition['key'], + $definition['label'], + ); + } + + private static function open(array $connection, string $source, string $label): PDO + { $host = trim((string) ($connection['host'] ?? '')); $port = min(max((int) ($connection['port'] ?? 1433), 1), 65535); $db = trim((string) ($connection['database'] ?? '')); @@ -83,8 +127,8 @@ class UpstreamOdbcConnection ]); } catch (PDOException $exception) { Log::warning('上游数据库连接失败。', [ - 'source' => $definition['key'], - 'source_label' => $definition['label'], + 'source' => $source, + 'source_label' => $label, 'sql_state' => (string) $exception->getCode(), 'exception' => $exception::class, ]); diff --git a/modules/EcommerceFinance/Services/UpstreamQueryCache.php b/modules/EcommerceFinance/Services/UpstreamQueryCache.php index 2a3b90c8..36f55881 100644 --- a/modules/EcommerceFinance/Services/UpstreamQueryCache.php +++ b/modules/EcommerceFinance/Services/UpstreamQueryCache.php @@ -24,16 +24,16 @@ class UpstreamQueryCache private readonly string $label; - private readonly string $configKey; + private readonly UpstreamSourceRegistry $sources; private ?array $lastReadState = null; public function __construct(UpstreamSourceRegistry $sources, string $source) { $definition = $sources->definition($source); + $this->sources = $sources; $this->source = $definition['key']; $this->label = $definition['label']; - $this->configKey = $definition['config']; } public function sourceKey(): string @@ -43,9 +43,7 @@ class UpstreamQueryCache public function setting(string $path, mixed $default = null): mixed { - $suffix = trim($path, '.'); - - return config($this->configKey . ($suffix === '' ? '' : '.' . $suffix), $default); + return $this->sources->value($this->source, $path, $default); } /** diff --git a/modules/EcommerceFinance/Services/UpstreamSourceRegistry.php b/modules/EcommerceFinance/Services/UpstreamSourceRegistry.php index b4b86112..e6926e77 100644 --- a/modules/EcommerceFinance/Services/UpstreamSourceRegistry.php +++ b/modules/EcommerceFinance/Services/UpstreamSourceRegistry.php @@ -9,6 +9,11 @@ use InvalidArgumentException; */ class UpstreamSourceRegistry { + public function __construct( + private readonly UpstreamStoredConfiguration $storedConfiguration, + ) { + } + /** * @return array{key:string,label:string,config:string} */ @@ -44,8 +49,9 @@ class UpstreamSourceRegistry $definition = $this->definition($source); $suffix = trim($path, '.'); $key = $definition['config'] . ($suffix === '' ? '' : '.' . $suffix); + $configured = config($key, $default); - return config($key, $default); + return $this->storedConfiguration->value($definition['key'], $suffix, $configured); } public function enabled(string $source): bool diff --git a/modules/EcommerceFinance/Services/UpstreamStoredConfiguration.php b/modules/EcommerceFinance/Services/UpstreamStoredConfiguration.php new file mode 100644 index 00000000..95416f0d --- /dev/null +++ b/modules/EcommerceFinance/Services/UpstreamStoredConfiguration.php @@ -0,0 +1,75 @@ + */ + private array $connections = []; + + public function editable(): bool + { + return app()->environment(['local', 'development', 'testing']); + } + + public function find(string $source): ?DatabaseConnection + { + if (! $this->editable()) { + return null; + } + + if (array_key_exists($source, $this->connections)) { + return $this->connections[$source]; + } + + if (! Schema::hasTable('system_database_connections')) { + return $this->connections[$source] = null; + } + + $this->connections[$source] = DatabaseConnection::query() + ->where('company_id', self::SYSTEM_COMPANY_ID) + ->where('source_key', $source) + ->first(); + + return $this->connections[$source]; + } + + public function forget(string $source): void + { + unset($this->connections[$source]); + } + + public function value(string $source, string $path, mixed $default = null): mixed + { + $connection = $this->find($source); + + if (! $connection) { + return $default; + } + + return match (trim($path, '.')) { + 'enabled' => $connection->enabled, + 'allowed_scopes' => $connection->allowed_scopes ?? [], + 'connection.host' => $connection->host, + 'connection.port' => $connection->port, + 'connection.database' => $connection->database_name, + 'connection.username' => $connection->username, + 'connection.password' => $connection->password, + 'connection.odbc_driver' => $connection->odbc_driver, + 'connection.tds_version' => $connection->tds_version, + 'connection.connect_timeout' => $connection->connect_timeout, + 'connection.query_timeout' => $connection->query_timeout, + default => $default, + }; + } +} diff --git a/resources/views/system_settings/databases/form.blade.php b/resources/views/system_settings/databases/form.blade.php index 89c57460..9cd2946e 100644 --- a/resources/views/system_settings/databases/form.blade.php +++ b/resources/views/system_settings/databases/form.blade.php @@ -1,70 +1,77 @@ - {{ $connection ? '修改数据库配置' : '新增数据库配置' }} + {{ $connection ? '修改数据库' : '添加数据库' }}
@include('system_settings.partials.navigation') -
+ @csrf @if ($connection) @method('PATCH') @endif @if ($errors->any()) -
+ @endif
-
-
- 取消 - +
+ 高级设置 +
+ + + + + +
+
+ +
+
+ + +
+
+ 取消 + +
diff --git a/resources/views/system_settings/databases/index.blade.php b/resources/views/system_settings/databases/index.blade.php index a505234f..27c184c3 100644 --- a/resources/views/system_settings/databases/index.blade.php +++ b/resources/views/system_settings/databases/index.blade.php @@ -1,81 +1,78 @@ - 数据库配置管理 + 数据库管理 - - - add新增配置 - - + @if ($editable) + + + 添加数据库 + + + @endif
@include('system_settings.partials.navigation') -
- 数据库密码加密保存,列表及导出文件均不会显示密码。导入时密码留空可保留已有密码。 -
- @if ($errors->any()) -
+ @endif -
-
- @csrf - - -
- - download导出 / 下载模板 - +
+

当前系统数据库

+

+ {{ strtoupper($systemDatabase['driver']) }} · {{ $systemDatabase['host'] }}{{ $systemDatabase['port'] ? ':' . $systemDatabase['port'] : '' }} · {{ $systemDatabase['database'] ?: $systemDatabase['connection'] }} +

+

用户、系统设置和下方所有数据库配置都统一保存在这个数据库中。系统库的启动连接由私有 runtime/.env 提供,页面不会显示密码。

+ @if ($editable) +

下方可继续添加多个云数据库;连接测试只执行 SELECT 1。

+ @else +

生产环境不允许在网页中修改数据库凭据。

+ @endif
- + - - - - - - - + + + + + + @forelse ($connections as $connection) - - - + + - + @empty - + @endforelse
配置名称类型主机 / 端口数据库用户名状态操作名称地址数据库业务绑定状态操作
{{ $connection->name }}{{ $connection->driver }}{{ $connection->host ?: '-' }}{{ $connection->port ? ':' . $connection->port : '' }}{{ $connection->name }}{{ $connection->host }}:{{ $connection->port }} {{ $connection->database_name }}{{ $connection->username ?: '-' }}{{ $sourceLabels[$connection->source_key] ?? '未绑定' }} $connection->enabled, - 'bg-gray-100 text-gray-500' => ! $connection->enabled, + 'bg-gray-100 text-gray-600' => ! $connection->enabled, ])>{{ $connection->enabled ? '启用' : '停用' }} - 修改 -
+ + @csrf + +
+ 修改 +
@csrf @method('DELETE') - +
暂无数据库配置
还没有数据库配置,点击“添加数据库”开始。
diff --git a/resources/views/system_settings/partials/navigation.blade.php b/resources/views/system_settings/partials/navigation.blade.php index 40219366..f7dc30b3 100644 --- a/resources/views/system_settings/partials/navigation.blade.php +++ b/resources/views/system_settings/partials/navigation.blade.php @@ -1,15 +1,23 @@