diff --git a/plugin/lib/quickcomposer/network/dns.js b/plugin/lib/quickcomposer/network/dns.js index 8e00ad2..46e91ba 100644 --- a/plugin/lib/quickcomposer/network/dns.js +++ b/plugin/lib/quickcomposer/network/dns.js @@ -13,9 +13,9 @@ const resolveCname = promisify(dns.resolveCname); const reverse = promisify(dns.reverse); // 解析主机名 -async function lookupHost(hostname, options = {}) { +async function lookupHost(hostname, family = 0, all = false) { try { - return await lookup(hostname, options); + return await lookup(hostname, { family, all }); } catch (error) { throw new Error(`DNS查询失败: ${error.message}`); } diff --git a/src/components/composer/MultiParams.vue b/src/components/composer/MultiParams.vue index 7904ba6..40a7b89 100644 --- a/src/components/composer/MultiParams.vue +++ b/src/components/composer/MultiParams.vue @@ -36,9 +36,15 @@ export default defineComponent({ }, // 通用参数配置 commonConfig() { - return this.modelValue.config || []; + return ( + // 过滤掉特定函数排除的参数, excludeConfig格式为[要排除的参数索引] + this.modelValue.config?.filter( + (_, index) => + !this.getSelectFunction()?.excludeConfig?.includes(index) + ) || [] + ); }, - // 特定函数独有参数配置 + // 特定函数独有参数配置,config格式和通用的config一致 functionConfig() { return this.getSelectFunction()?.config || []; }, diff --git a/src/components/composer/network/DnsEditor.vue b/src/components/composer/network/DnsEditor.vue deleted file mode 100644 index ecc35da..0000000 --- a/src/components/composer/network/DnsEditor.vue +++ /dev/null @@ -1,241 +0,0 @@ - - - - - diff --git a/src/js/composer/cardComponents.js b/src/js/composer/cardComponents.js index fe99821..f6fa48a 100644 --- a/src/js/composer/cardComponents.js +++ b/src/js/composer/cardComponents.js @@ -73,9 +73,6 @@ export const ZlibEditor = defineAsyncComponent(() => export const UrlEditor = defineAsyncComponent(() => import("components/composer/network/UrlEditor.vue") ); -export const DnsEditor = defineAsyncComponent(() => - import("components/composer/network/DnsEditor.vue") -); export const BufferEditor = defineAsyncComponent(() => import("src/components/composer/data/BufferEditor.vue") ); diff --git a/src/js/composer/commands/networkCommands.js b/src/js/composer/commands/networkCommands.js index 94b2f9a..a9ac8ca 100644 --- a/src/js/composer/commands/networkCommands.js +++ b/src/js/composer/commands/networkCommands.js @@ -54,12 +54,94 @@ export const networkCommands = { icon: "link", }, { - value: "quickcomposer.network.dns", + value: "quickcomposer.network.dns.lookupHost", label: "DNS操作", desc: "DNS解析和查询", - component: "DnsEditor", icon: "dns", isAsync: true, + config: [ + { + label: "要查询的域名", + icon: "dns", + type: "varInput", + width: "auto", + }, + ], + functionSelector: [ + { + label: "DNS查询", + value: "quickcomposer.network.dns.lookupHost", + icon: "search", + config: [ + { + label: "IP版本", + icon: "settings_ethernet", + type: "select", + options: [ + { label: "自动", value: 0 }, + { label: "IPv4", value: 4 }, + { label: "IPv6", value: 6 }, + ], + defaultValue: 0, + width: 2.5, + }, + { + label: "返回所有地址", + type: "checkbox", + defaultValue: false, + width: 2.5, + }, + ], + }, + { + value: "quickcomposer.network.dns.resolveAll", + label: "解析所有记录", + icon: "all_inclusive", + }, + { + value: "quickcomposer.network.dns.resolveIpv4", + label: "解析IPv4", + icon: "filter_4", + }, + { + value: "quickcomposer.network.dns.resolveIpv6", + label: "解析IPv6", + icon: "filter_6", + }, + { + value: "quickcomposer.network.dns.resolveMxRecords", + label: "解析MX记录", + icon: "mail", + }, + { + value: "quickcomposer.network.dns.resolveTxtRecords", + label: "解析TXT记录", + icon: "text_fields", + }, + { + value: "quickcomposer.network.dns.resolveNsRecords", + label: "解析NS记录", + icon: "dns", + }, + { + value: "quickcomposer.network.dns.resolveCnameRecords", + label: "解析CNAME记录", + icon: "link", + }, + { + value: "quickcomposer.network.dns.reverseResolve", + label: "反向解析", + icon: "swap_horiz", + excludeConfig: [0], + config: [ + { + label: "IP地址", + icon: "router", + type: "varInput", + }, + ], + }, + ], }, ], }; diff --git a/src/js/composer/commonComponentGuide.js b/src/js/composer/commonComponentGuide.js new file mode 100644 index 0000000..fb1c850 --- /dev/null +++ b/src/js/composer/commonComponentGuide.js @@ -0,0 +1,127 @@ +/** + * Common Component Creation Guide + * 通用组件创建指南 - 使用 MultiParams 组件 + */ +const commonComponentGuide = { + description: "创建使用 MultiParams 组件的命令的完整流程", + important: "创建过程中严禁删除、修改任何已有的函数或对象", + steps: { + "1. Backend Interface": { + location: "plugin/lib/quickcomposer/xxx/yyy.js", + description: "创建具体功能实现", + requirements: { + functionDefinition: "使用独立函数而非对象方法", + asyncHandling: "使用 async/await 处理异步操作", + errorHandling: "合理的错误捕获和提示", + paramValidation: "检查必要参数是否存在", + }, + }, + "2. Interface Export": { + location: "plugin/lib/quickcomposer/xxx/index.js", + description: "导出接口给quickcomposer使用", + examples: { + singleFunction: "module.exports = { operation }", + multipleFunctions: "module.exports = { ...encoder, ...hash }", + }, + }, + "3. Interface Registration": { + location: "plugin/lib/quickcomposer.js", + description: "将接口注册到quickcomposer对象", + format: "quickcomposer.xxx = require('./quickcomposer/xxx')", + }, + "4. Command Configuration": { + location: "src/js/composer/commands/xxxCommands.js", + description: "配置命令参数,使用 MultiParams 组件", + requiredFields: { + value: "必选,生成代码时使用的函数名,如 quickcomposer.xxx.yyy", + label: "必选,命令的显示名称", + config: { + description: "必选,通用参数配置数组,每个元素是一个对象", + properties: { + label: "必选,参数标签", + type: "必选,参数类型(varInput/numInput/select/checkbox等)", + icon: "必选,参数图标", + width: "可选,参数占用宽度(1-12或auto)", + defaultValue: "可选,参数默认值", + options: "可选,select等类型的选项", + }, + example: ` + config: [ + { + label: "域名", + type: "varInput", + icon: "dns", + width: "auto" + } + ] + `, + }, + functionSelector: { + description: + "可选,函数选择器配置,用于一个命令包含多个相关函数的情况", + properties: { + value: "必选,函数名", + label: "必选,显示名称", + icon: "可选,图标", + config: "可选,函数特有的参数配置,格式同通用config", + excludeConfig: "可选,要排除的通用参数索引数组", + }, + example: ` + functionSelector: [ + { + label: "DNS查询", + value: "quickcomposer.network.dns.lookupHost", + icon: "search", + config: [ + { + label: "IP版本", + type: "select", + options: [ + { label: "自动", value: 0 }, + { label: "IPv4", value: 4 } + ], + defaultValue: 0 + } + ] + }, + { + value: "quickcomposer.network.dns.reverseResolve", + label: "反向解析", + icon: "swap_horiz", + excludeConfig: [0], // 排除第一个通用参数 + config: [ + { + label: "IP地址", + type: "varInput", + icon: "router" + } + ] + } + ] + `, + }, + }, + optionalFields: { + desc: "命令描述", + isAsync: "是否异步命令", + icon: "命令图标", + }, + }, + }, + notes: { + bestPractices: { + description: "最佳实践", + tips: [ + "合理使用 width 属性布局参数", + "相关参数尽量放在同一行", + "使用 excludeConfig 禁用掉不需要的参数配置", + "合理设置 defaultValue", + "使用语义化的图标", + "保持参数标签简洁明了", + ], + }, + }, + examples: { + multiFunctionCommand: "多函数命令,如DNS操作", + }, +}; diff --git a/src/js/composer/customComponentGuide.js b/src/js/composer/customComponentGuide.js index 4c0e5b2..cf61a53 100644 --- a/src/js/composer/customComponentGuide.js +++ b/src/js/composer/customComponentGuide.js @@ -272,7 +272,6 @@ const customComponentGuide = { desc: "命令描述", isAsync: "是否异步命令", isControlFlow: "是否控制流命令", - allowEmptyArgv: "是否允许空参数", }, }, },