From a9b773868d30ac635c1c0b60c127123a45b40e59 Mon Sep 17 00:00:00 2001 From: luo-bo <603509782@qq.com> Date: Thu, 2 Apr 2026 03:22:42 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat(domain):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E5=BF=AB=E9=80=9F=E5=88=87=E6=8D=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在BaseController中新增getManagedDomainOptions方法,用于获取用户管理的域名选项 - 在Cloudflare和Domain控制器中集成域名选项数据传递到视图 - 更新前端模板文件以支持多域名选择下拉列表 - 扩展JavaScript中的initDomainQuickSwitch函数,增加AJAX支持选项 - 引入DnsHelper和Db门面用于域名数据查询和处理 ``` --- app/BaseController.php | 32 ++++++++++++++++++++++++++++++ app/controller/Cloudflare.php | 10 ++++++++++ app/controller/Domain.php | 10 ++++++++++ app/view/cloudflare/hostnames.html | 4 +++- app/view/domain/record.html | 4 +++- public/static/js/custom.js | 14 ++++++++----- 6 files changed, 67 insertions(+), 7 deletions(-) diff --git a/app/BaseController.php b/app/BaseController.php index 5b9d541..6cda57a 100644 --- a/app/BaseController.php +++ b/app/BaseController.php @@ -3,9 +3,11 @@ declare (strict_types = 1); namespace app; +use app\lib\DnsHelper; use think\App; use think\exception\ValidateException; use think\Validate; +use think\facade\Db; use think\facade\View; /** @@ -96,6 +98,36 @@ abstract class BaseController return $v->failException(true)->check($data); } + protected function getManagedDomainOptions(?string $type = null): array + { + if (!checkPermission(1)) { + return []; + } + + $query = Db::name('domain')->alias('A') + ->join('account B', 'A.aid = B.id') + ->field('A.id,A.name,B.type'); + if (!empty($type)) { + $query->where('B.type', $type); + } + if (request()->user['level'] == 1) { + $query->where('A.is_hide', 0)->where('A.name', 'in', request()->user['permission']); + } + + $rows = $query->order('A.name', 'asc')->select(); + $list = []; + foreach ($rows as $row) { + $typeName = DnsHelper::$dns_config[$row['type']]['name'] ?? strtoupper((string)$row['type']); + $list[] = [ + 'id' => intval($row['id']), + 'name' => $row['name'], + 'type' => $row['type'], + 'text' => $row['name'] . ' [' . $typeName . ']', + ]; + } + return $list; + } + protected function alert($code, $msg = '', $url = null, $wait = 3) { diff --git a/app/controller/Cloudflare.php b/app/controller/Cloudflare.php index 9d7ae58..f43ec79 100644 --- a/app/controller/Cloudflare.php +++ b/app/controller/Cloudflare.php @@ -14,8 +14,18 @@ class Cloudflare extends BaseController { try { $context = $this->getCloudflareDomainContext(input('param.id/d')); + $quickDomainOptions = $this->getManagedDomainOptions('cloudflare'); + if (empty($quickDomainOptions)) { + $quickDomainOptions = [[ + 'id' => intval($context['domain']['id']), + 'name' => $context['domain']['name'], + 'type' => 'cloudflare', + 'text' => $context['domain']['name'] . ' [Cloudflare]', + ]]; + } View::assign('domainId', $context['domain']['id']); View::assign('domainName', $context['domain']['name']); + View::assign('quickDomainOptions', $quickDomainOptions); return view(); } catch (Exception $e) { return $this->alert('error', $e->getMessage()); diff --git a/app/controller/Domain.php b/app/controller/Domain.php index c930df8..0e3c514 100644 --- a/app/controller/Domain.php +++ b/app/controller/Domain.php @@ -452,9 +452,19 @@ class Domain extends BaseController $dnsconfig = DnsHelper::$dns_config[$dnstype]; $dnsconfig['type'] = $dnstype; + $quickDomainOptions = $this->getManagedDomainOptions(); + if (empty($quickDomainOptions)) { + $quickDomainOptions = [[ + 'id' => intval($id), + 'name' => $drow['name'], + 'type' => $dnstype, + 'text' => $drow['name'] . ' [' . ($dnsconfig['name'] ?? strtoupper($dnstype)) . ']', + ]]; + } View::assign('domainId', $id); View::assign('domainName', $drow['name']); + View::assign('quickDomainOptions', $quickDomainOptions); View::assign('recordLine', $recordLineArr); View::assign('minTTL', $minTTL ? $minTTL : 1); View::assign('dnsconfig', $dnsconfig); diff --git a/app/view/cloudflare/hostnames.html b/app/view/cloudflare/hostnames.html index 7941934..f7b1ccd 100644 --- a/app/view/cloudflare/hostnames.html +++ b/app/view/cloudflare/hostnames.html @@ -9,7 +9,9 @@
diff --git a/app/view/domain/record.html b/app/view/domain/record.html index 8e957ab..ee957a5 100644 --- a/app/view/domain/record.html +++ b/app/view/domain/record.html @@ -171,7 +171,9 @@ td{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;max-width:360px;
diff --git a/public/static/js/custom.js b/public/static/js/custom.js index 391a697..2348e2e 100644 --- a/public/static/js/custom.js +++ b/public/static/js/custom.js @@ -66,6 +66,7 @@ function initDomainQuickSwitch(options){ currentId: '', currentText: '', placeholder: '搜索域名后切换', + useAjax: false, type: '', limit: 10, buildUrl: function(id){ @@ -79,11 +80,13 @@ function initDomainQuickSwitch(options){ if(settings.currentId !== '' && settings.currentText !== '' && $select.find('option[value="' + settings.currentId + '"]').length === 0){ $select.append(new Option(settings.currentText, settings.currentId, true, true)); } - $select.select2({ + var select2Options = { width: '100%', language: 'zh-CN', - placeholder: settings.placeholder, - ajax: { + placeholder: settings.placeholder + }; + if(settings.useAjax){ + select2Options.ajax = { url: '/domain/data', type: 'post', dataType: 'json', @@ -117,8 +120,9 @@ function initDomainQuickSwitch(options){ }; }, cache: true - } - }); + }; + } + $select.select2(select2Options); var navigate = function(){ var targetId = $.trim($select.val()); if(targetId === ''){