From 3e36095b83714bb61681b6da9e0f00e900fe3c2b Mon Sep 17 00:00:00 2001 From: jingrow Date: Sun, 3 Aug 2025 21:00:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B7=BB=E5=8A=A0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=88=A0=E9=99=A4=E5=9F=9F=E5=90=8D=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src2/components/JsiteDomainDNSRecords.vue | 351 ++++++++++++++---- 1 file changed, 282 insertions(+), 69 deletions(-) diff --git a/dashboard/src2/components/JsiteDomainDNSRecords.vue b/dashboard/src2/components/JsiteDomainDNSRecords.vue index 6dfca71..24cb479 100644 --- a/dashboard/src2/components/JsiteDomainDNSRecords.vue +++ b/dashboard/src2/components/JsiteDomainDNSRecords.vue @@ -3,7 +3,7 @@
-

域名解析记录

+

DNS解析记录

管理域名的DNS解析记录

@@ -17,12 +17,12 @@ 刷新
@@ -47,7 +47,7 @@ -
+
@@ -56,16 +56,19 @@ + - + + - - - - - + @@ -187,12 +300,12 @@ -
+

暂无DNS记录

开始添加您的第一个DNS解析记录

- @@ -253,7 +366,12 @@ export default { onSuccess: (response) => { this.loading = false; if (response.status === 'success' && response.data) { - this.dnsRecords = response.data.items || []; + // 为每个记录添加编辑状态 + this.dnsRecords = (response.data.items || []).map(record => ({ + ...record, + editing: false, + isNew: false + })); this.pagination = { pageno: response.data.pageno || 1, limit: response.data.limit || 20, @@ -303,27 +421,130 @@ export default { return variantMap[type] || 'default'; }, - // 显示添加记录对话框 - showAddRecordDialog() { - const JsiteDomainAddDNSRecordDialog = defineAsyncComponent(() => import('./JsiteDomainAddDNSRecordDialog.vue')); - - renderDialog(h(JsiteDomainAddDNSRecordDialog, { - domain: this.domain, - domainDoc: this.$domain.pg, - onSuccess: this.onRecordAdded - })); + // 获取线路显示名称 + getLineDisplayName(line) { + const lineMap = { + 'LTEL': '电信', + 'LCNC': '联通', + 'LMOB': '移动', + 'LEDU': '教育网', + 'LSEO': '搜索引擎', + '': '默认' + }; + return lineMap[line] || line; + }, + + // 添加新行 + addNewRow() { + this.dnsRecords.push({ + id: null, // 新增记录没有ID + item: '', + type: 'A', + line: '', + value: '', + ttl: 600, + level: 10, + editing: true, // 新增记录直接进入编辑模式 + isNew: true + }); }, // 编辑记录 editRecord(record) { - const JsiteDomainEditDNSRecordDialog = defineAsyncComponent(() => import('./JsiteDomainEditDNSRecordDialog.vue')); - - renderDialog(h(JsiteDomainEditDNSRecordDialog, { - domain: this.domain, - domainDoc: this.$domain.pg, - record: record, - onSuccess: this.onRecordUpdated - })); + // 保存原始值用于取消编辑 + record._original = { ...record }; + record.editing = true; + record.isNew = false; // 确保不是新增记录 + }, + + // 保存记录 + async saveRecord(record) { + if (!record.item || !record.type || !record.value) { + toast.error('主机名、类型和记录值不能为空'); + return; + } + + // 验证TTL值 + if (record.ttl < 60 || record.ttl > 86400) { + toast.error('TTL值必须在60~86400秒之间'); + return; + } + + // 验证优先级 + if (record.level < 1 || record.level > 100) { + toast.error('优先级必须在1~100之间'); + return; + } + + try { + let url, params; + + if (record.isNew) { + // 新增记录 + url = 'jcloud.api.domain_west.west_domain_add_dns_record'; + params = { + domain: this.$domain.pg.domain, + record_type: record.type, + host: record.item, + value: record.value, + ttl: record.ttl, + level: record.level, + line: record.line + }; + } else { + // 修改记录 + url = 'jcloud.api.domain_west.west_domain_modify_dns_record'; + params = { + domain: this.$domain.pg.domain, + record_id: record.id, + value: record.value, + ttl: record.ttl, + level: record.level, + line: record.line + }; + } + + const request = createResource({ + url: url, + params: params, + onSuccess: (response) => { + if (response.status === 'success') { + toast.success('DNS记录保存成功'); + record.editing = false; + record.isNew = false; + // 重新加载记录列表 + this.loadDNSRecords(); + } else { + toast.error(response.message || '保存DNS记录失败'); + } + }, + onError: (error) => { + toast.error(getToastErrorMessage(error)); + } + }); + request.submit(); + } catch (error) { + toast.error('保存DNS记录失败'); + console.error('保存DNS记录失败:', error); + } + }, + + // 取消编辑 + cancelEdit(record) { + if (record.isNew) { + // 如果是新增记录,直接删除 + const index = this.dnsRecords.indexOf(record); + if (index > -1) { + this.dnsRecords.splice(index, 1); + } + } else { + // 如果是编辑中的记录,恢复其原始值 + if (record._original) { + Object.assign(record, record._original); + delete record._original; + } + record.editing = false; + } }, // 删除记录 @@ -350,10 +571,14 @@ export default { domain: this.$domain.pg.domain, record_id: record.id }, - onSuccess: () => { - toast.success('DNS记录删除成功'); - hide(); - this.loadDNSRecords(); + onSuccess: (response) => { + if (response.status === 'success') { + toast.success('DNS记录删除成功'); + hide(); + this.loadDNSRecords(); + } else { + toast.error(response.message || '删除DNS记录失败'); + } }, onError: (error) => { toast.error(getToastErrorMessage(error)); @@ -364,18 +589,6 @@ export default { toast.error('删除DNS记录失败'); console.error('删除DNS记录失败:', error); } - }, - - // 记录添加成功回调 - onRecordAdded() { - toast.success('DNS记录添加成功'); - this.loadDNSRecords(); - }, - - // 记录更新成功回调 - onRecordUpdated() { - toast.success('DNS记录更新成功'); - this.loadDNSRecords(); } }, computed: {
- 主机名 + 编号 - 类型 + 主机名 * - 线路类型 + 类型 * - 对应值 + 线路 + + 对应值 * TTL @@ -77,43 +80,125 @@ 状态 - 操作 + ⚙️
- {{ record.item }} + + {{ index + 1 }} - - {{ record.type || '未知' }} - + +
+ +
+
+ {{ record.item || '-' }} +
- 默认 + + +
+ +
+
+ + {{ record.type || '未知' }} + +
- {{ record.value }} + + +
+ +
+
+ {{ getLineDisplayName(record.line) }} +
- {{ record.ttl || '600' }} + + +
+ +
+
+ {{ record.value || '-' }} +
- {{ record.type === 'MX' && record.level ? record.level : '-' }} + + +
+ +
+
+ {{ record.ttl || '600' }} +
+
+ +
+ +
+
+ {{ record.type === 'MX' && record.level ? record.level : '-' }} +
@@ -123,12 +208,40 @@
+ + +