diff --git a/plugin/lib/dialog/controller.js b/plugin/lib/dialog/controller.js new file mode 100644 index 0000000..5d172f3 --- /dev/null +++ b/plugin/lib/dialog/controller.js @@ -0,0 +1,192 @@ +const { ipcRenderer } = require("electron"); + +// 等待 DOM 加载完成 +document.addEventListener("DOMContentLoaded", () => { + let parentId = null; + let dialogType = null; + + // 监听父窗口发来的对话框配置 + ipcRenderer.on("dialog-config", (event, config) => { + parentId = event.senderId; + dialogType = config.type; + + // 设置主题 + document.documentElement.setAttribute( + "data-theme", + config.isDark ? "dark" : "light" + ); + + // 设置对话框标题 + document.getElementById("title-text").textContent = config.title || "提示"; + + // 设置对话框内容 + if (config.content) { + document.getElementById("content").textContent = config.content; + } + + // 根据类型设置不同的对话框内容 + switch (config.type) { + case "message": + document.body.classList.add("dialog-message"); // 添加消息对话框的类 + break; + + case "input": + document.getElementById("input").style.display = "block"; + document.body.classList.add("dialog-input"); + // 创建输入框 + const inputContainer = document.getElementById("input-container"); + inputContainer.innerHTML = ""; // 清空现有内容 + config.inputOptions.forEach((inputOption, index) => { + console.log(inputOption); + const div = document.createElement("div"); + div.className = "input-group"; + + const label = document.createElement("label"); + label.textContent = + typeof inputOption === "string" ? inputOption : inputOption.label; + + const input = document.createElement("input"); + input.type = "text"; + input.id = `input-${index}`; + if (typeof inputOption !== "string") { + input.value = inputOption.value || ""; + input.placeholder = inputOption.hint || ""; + } + + div.appendChild(label); + div.appendChild(input); + inputContainer.appendChild(div); + }); + document.getElementById("input-0").focus(); + break; + + case "confirm": + document.getElementById("confirm").style.display = "block"; + document.body.classList.add("dialog-confirm"); + break; + + case "buttons": + document.getElementById("buttons").style.display = "block"; + document.body.classList.add("dialog-buttons"); + // 创建按钮 + const buttonContainer = document.getElementById("button-container"); + buttonContainer.innerHTML = ""; + config.buttons.forEach((btn, index) => { + const button = document.createElement("button"); + button.textContent = btn; + button.onclick = () => { + ipcRenderer.sendTo(parentId, "dialog-result", { + id: index, + text: btn, + }); + }; + buttonContainer.appendChild(button); + }); + break; + + case "textarea": + document.getElementById("textarea").style.display = "block"; + document.body.classList.add("dialog-textarea"); + const textarea = document.getElementById("text-content"); + if (config.placeholder) { + textarea.placeholder = config.placeholder; + } + if (config.defaultText) { + textarea.value = config.defaultText; + } + textarea.focus(); + break; + } + ipcRenderer.sendTo(parentId, "dialog-ready", calculateHeight()); + }); + + const calculateHeight = () => { + const titleBar = document.querySelector(".title-bar"); + const buttonBar = document.querySelector(".button-bar"); + const contentWrapper = document.querySelector(".content-wrapper"); + + // 计算总高度 + const totalHeight = + titleBar.offsetHeight + + contentWrapper.scrollHeight + + (buttonBar.style.display !== "none" ? buttonBar.offsetHeight : 0); + + // 确保高度在最小值和最大值之间 + return Math.min(Math.max(totalHeight, 100), 520); + }; + + // 确定按钮点击事件 + document.getElementById("ok-btn").onclick = () => { + let result; + + switch (dialogType) { + case "message": + result = true; + break; + + case "input": + const inputs = document.querySelectorAll("#input-container input"); + result = Array.from(inputs).map((input) => input.value); + break; + + case "confirm": + result = true; + break; + + case "textarea": + result = document.getElementById("text-content").value; + break; + } + + ipcRenderer.sendTo(parentId, "dialog-result", result); + }; + + const cancelDialog = () => { + let result; + switch (dialogType) { + case "input": + result = []; + break; + case "textarea": + result = ""; + break; + case "confirm": + result = false; + break; + case "buttons": + result = {}; + break; + default: + result = null; + } + ipcRenderer.sendTo(parentId, "dialog-result", result); + }; + + // 取消按钮点击事件 + document.getElementById("cancel-btn").onclick = () => { + cancelDialog(); + }; + + // ESC键关闭窗口 + document.addEventListener("keydown", (e) => { + if (e.key === "Escape") { + cancelDialog(); + } + }); + + // 回车键确认 + document.addEventListener("keydown", (e) => { + // 如果是文本区域且按下回车,不触发确认 + if (e.key === "Enter") { + if (dialogType === "textarea" && !e.ctrlKey) { + return; + } + document.getElementById("ok-btn").click(); + } + }); + + // 关闭按钮点击事件 + document.querySelector(".close-btn").onclick = () => { + cancelDialog(); + }; +}); diff --git a/plugin/lib/dialog/service.js b/plugin/lib/dialog/service.js new file mode 100644 index 0000000..5e98bbc --- /dev/null +++ b/plugin/lib/dialog/service.js @@ -0,0 +1,163 @@ +const { ipcRenderer } = require("electron"); +const { createBrowserWindow } = utools; +/** + * 创建对话框窗口 + * @param {object} config - 对话框配置 + * @returns {Promise} 返回对话框结果 + */ +const createDialog = (config) => { + return new Promise((resolve) => { + const dialogPath = "lib/dialog/view.html"; + const preloadPath = "lib/dialog/controller.js"; + + const dialogOptions = { + title: config.title || "对话框", + width: 470, + height: 80, + resizable: false, + minimizable: false, + maximizable: false, + fullscreenable: false, + skipTaskbar: true, + alwaysOnTop: true, + frame: false, + webPreferences: { + preload: preloadPath, + }, + }; + + // 创建窗口 + const UBrowser = createBrowserWindow(dialogPath, dialogOptions, () => { + const dialogResultHandler = (event, result) => { + resolve(result); + // 移除监听器 + ipcRenderer.removeListener("dialog-result", dialogResultHandler); + UBrowser.destroy(); + }; + + const dialogReadyHandler = (event, height) => { + // 获取当前窗口位置 + const bounds = UBrowser.getBounds(); + // 调整y坐标,保持窗口中心点不变 + const y = Math.round(bounds.y - (height - bounds.height) / 2); + // 确保坐标和尺寸都是有效的整数 + const newBounds = { + x: Math.round(bounds.x), + y: Math.max(0, y), // 确保不会超出屏幕顶部 + width: 470, + height: Math.round(height), + }; + // 设置新的位置和大小 + UBrowser.setBounds(newBounds); + ipcRenderer.removeListener("dialog-ready", dialogReadyHandler); + }; + ipcRenderer.on("dialog-ready", dialogReadyHandler); + + // 添加监听器 + ipcRenderer.on("dialog-result", dialogResultHandler); + + // 发送配置到子窗口 + ipcRenderer.sendTo(UBrowser.webContents.id, "dialog-config", { + ...config, + isDark: utools.isDarkColors(), + }); + }); + }); +}; + +/** + * 显示一个系统级消息框 + * @param {string} content - 消息内容 + * @param {string} [title] - 标题,默认为空 + * @returns {Promise} Promise + */ +const showSystemMessageBox = async (content, title = "") => { + await createDialog({ + type: "message", + title, + content, + }); +}; + +/** + * 显示一个系统级输入框组对话框 + * @param {string[]|{label:string,value:string,hint:string}[]} options - 输入框配置,可以是标签数组或者带属性的对象数组 + * @param {string} [title] - 标题,默认为空 + * @returns {Promise} 输入的内容数组 + */ +const showSystemInputBox = async (options, title = "") => { + // 确保 options 是数组 + const optionsArray = Array.isArray(options) ? options : [options]; + + // 转换每个选项为正确的格式 + const inputOptions = optionsArray.map((opt) => { + if (typeof opt === "string") { + return opt; + } + if (typeof opt === "object" && opt.label) { + return { + label: opt.label, + value: opt.value || "", + hint: opt.hint || "", + }; + } + throw new Error("输入框配置格式错误"); + }); + + return await createDialog({ + type: "input", + title, + inputOptions, + }); +}; + +/** + * 显示一个系统级确认框,返回是否点击了确认 + * @param {string} content - 确认内容 + * @param {string} [title] - 标题,默认为空 + * @returns {Promise} 是否确认 + */ +const showSystemConfirmBox = async (content, title = "") => { + const result = await createDialog({ + type: "confirm", + title, + content, + }); + return !!result; +}; + +/** + * 显示一个系统级按钮组对话框,返回点击的按钮的索引和文本 + * @param {string[]} buttons - 按钮文本数组 + * @param {string} [title] - 标题,默认为空 + * @returns {Promise<{id: number, text: string}|null>} 选择的按钮信息 + */ +const showSystemButtonBox = async (buttons, title = "") => { + return await createDialog({ + type: "buttons", + title, + buttons: Array.isArray(buttons) ? buttons : [buttons], + }); +}; + +/** + * 显示一个系统级多行文本输入框 + * @param {string} [placeholder] - 输入框的提示文本 + * @param {string} [defaultText] - 输入框的默认文本,默认为空 + * @returns {Promise} 编辑后的文本 + */ +const showSystemTextArea = async (placeholder = "请输入", defaultText = "") => { + return await createDialog({ + type: "textarea", + placeholder, + defaultText, + }); +}; + +module.exports = { + showSystemMessageBox, + showSystemInputBox, + showSystemConfirmBox, + showSystemButtonBox, + showSystemTextArea, +}; diff --git a/plugin/lib/dialog/view.html b/plugin/lib/dialog/view.html new file mode 100644 index 0000000..83e99cb --- /dev/null +++ b/plugin/lib/dialog/view.html @@ -0,0 +1,344 @@ + + + + + 对话框 + + + +
+ +
+
+ +

对话框

+
+
+
+ +
+
+ + +
+
+
+ + +
+ + +
+
+
+ + +
+ +
+
+
+ + +
+
+ + diff --git a/plugin/lib/quickcommand.js b/plugin/lib/quickcommand.js index 91dcce2..c24ce33 100644 --- a/plugin/lib/quickcommand.js +++ b/plugin/lib/quickcommand.js @@ -6,7 +6,7 @@ const iconv = require("iconv-lite"); const path = require("path"); const axios = require("axios"); -const systemDialog = require("./systemDialog"); +const systemDialog = require("./dialog/service"); const { getQuickcommandTempFile } = require("./getQuickcommandFile"); @@ -178,60 +178,7 @@ const quickcommand = { } return null; }, - - // 运行C#脚本 - runCsharp: function (script, args = []) { - return new Promise((reslove, reject) => { - let cscPath = path.join( - process.env.WINDIR, - "Microsoft.NET", - "Framework", - "v4.0.30319", - "csc.exe" - ); - if (!fs.existsSync(cscPath)) { - cscPath = path.join( - process.env.WINDIR, - "Microsoft.NET", - "Framework", - "v3.5", - "csc.exe" - ); - } - if (!fs.existsSync(cscPath)) { - return reject("未安装.NET Framework"); - } - let tempCsharpFile = getQuickcommandTempFile("cs"); - let tempBuildFile = getQuickcommandTempFile("exe"); - - fs.writeFile(tempCsharpFile, iconv.encode(script, "gbk"), (err) => { - if (err) return reject(err.toString()); - // 添加命令行参数 - const argsStr = - args.length > 0 - ? " " + - args - .map((arg) => - arg.startsWith("-") ? arg : `"${arg}"` - ) - .join(" ") - : ""; - child_process.exec( - `${cscPath} /nologo /out:${tempBuildFile} ${tempCsharpFile} && ${tempBuildFile}${argsStr}`, - { - encoding: "buffer", - windowsHide: true, - }, - (err, stdout) => { - if (err) reject(iconv.decode(stdout, "gbk")); - else reslove(iconv.decode(stdout, "gbk")); - fs.unlink(tempCsharpFile, () => {}); - fs.unlink(tempBuildFile, () => {}); - } - ); - }); - }); - }, + ...systemDialog, }; if (process.platform === "win32") { @@ -272,8 +219,6 @@ if (process.platform === "win32") { ); }); }; - - quickcommand.showSystemTextArea = systemDialog.showSystemTextArea; } if (process.platform === "darwin") { @@ -316,11 +261,6 @@ if (process.platform !== "linux") { let command = createTerminalCommand(cmdline, options); child_process.exec(command); }; - // 系统级弹窗 - quickcommand.showSystemMessageBox = systemDialog.showSystemMessageBox; - quickcommand.showSystemInputBox = systemDialog.showSystemInputBox; - quickcommand.showSystemConfirmBox = systemDialog.showSystemConfirmBox; - quickcommand.showSystemButtonBox = systemDialog.showSystemButtonBox; } module.exports = quickcommand; diff --git a/plugin/lib/systemDialog.js b/plugin/lib/systemDialog.js deleted file mode 100644 index d9e74da..0000000 --- a/plugin/lib/systemDialog.js +++ /dev/null @@ -1,303 +0,0 @@ -const fs = require("fs"); -const path = require("path"); -const { exec } = require("child_process"); -const { getQuickcommandFolderFile } = require("./getQuickcommandFile"); -const { runCsharpFeature } = require("./csharp"); - -// 辅助函数 -const execCommand = (cmd) => { - return new Promise((resolve, reject) => { - exec(cmd, (error, stdout, stderr) => { - if (error) { - reject(stderr); - } else { - resolve(stdout); - } - }); - }); -}; - -const checkZenity = async () => { - try { - await execCommand("which zenity"); - return true; - } catch (error) { - window.utools.showNotification( - "请先安装 zenity:\nsudo apt install zenity 或\nsudo yum install zenity 或\nsudo pacman -S zenity" - ); - return false; - } -}; - -const getQuickcommandIconPath = () => { - try { - const iconPath = getQuickcommandFolderFile("logo", "png"); - if (!fs.existsSync(iconPath)) { - const sourcePath = path.join(__dirname, "..", "logo.png"); - if (!fs.existsSync(sourcePath)) { - console.error("Source icon not found:", sourcePath); - return ""; - } - fs.copyFileSync(sourcePath, iconPath); - } - return iconPath; - } catch (error) { - console.error("Error getting icon path:", error); - return ""; - } -}; - -// 修改对话框函数,使用新的 dialog.cs -const showSystemMessageBox = async function (content, title = "提示") { - try { - const iconPath = getQuickcommandIconPath(); - if (window.utools.isWindows()) { - const args = [ - "-type", - "message", - "-title", - title, - "-content", - content.replace(/\r\n|\n/g, ""), - ]; - - if (iconPath) { - args.push("-iconpath", iconPath.replace(/\\/g, "\\\\")); - } - - const result = await runCsharpFeature("dialog", args); - if (result && result.startsWith("Error:")) { - throw new Error(result.substring(7)); - } - return true; - } - if (window.utools.isMacOs()) { - let iconParam = "note"; - if (iconPath) { - const posixPath = iconPath.replace(/\\/g, "/"); - iconParam = `alias POSIX file "${posixPath}"`; - } - const script = `display dialog "${content}" with title "${title}" buttons {"确定"} default button "确定" with icon ${iconParam}`; - await this.runAppleScript(script); - return true; - } else if (window.utools.isLinux()) { - if (!(await checkZenity())) return false; - try { - const script = `zenity --info --title="${title}" --text="${content}" --width=400`; - await execCommand(script); - return true; - } catch (error) { - return false; - } - } - } catch (error) { - console.error("Dialog error:", error); - window.utools.showNotification(`对话框错误: ${error.message}`); - return false; - } -}; - -const showSystemInputBox = async function (placeholders, title = "请输入") { - if (!Array.isArray(placeholders)) { - placeholders = [placeholders]; - } - - const iconPath = getQuickcommandIconPath(); - if (window.utools.isMacOs()) { - let iconParam = "note"; - if (iconPath) { - const posixPath = iconPath.replace(/\\/g, "/"); - iconParam = `alias POSIX file "${posixPath}"`; - } - try { - const results = []; - for (let i = 0; i < placeholders.length; i++) { - const isLast = i === placeholders.length - 1; - const buttons = isLast ? '{"取消", "确定"}' : '{"取消", "继续"}'; - const defaultButton = isLast ? '"确定"' : '"继续"'; - const script = `display dialog "${placeholders[i]}" with title "${title}" default answer "" buttons ${buttons} default button ${defaultButton} with icon ${iconParam}`; - const result = await this.runAppleScript(script); - const buttonClicked = isLast ? "确定" : "继续"; - if (!result.includes(`button returned:${buttonClicked}`)) { - return null; - } - const text = result.match(/text returned:(.+)/)[1]; - results.push(text); - } - return results; - } catch (err) { - console.error(err); - return []; - } - } else if (window.utools.isWindows()) { - const args = [ - "-type", - "input", - "-title", - title, - "-content", - placeholders.join("|||||"), - ]; - - if (iconPath) { - args.push("-iconpath", iconPath.replace(/\\/g, "\\\\")); - } - - const result = await runCsharpFeature("dialog", args); - return result ? JSON.parse(result) : []; - } else if (window.utools.isLinux()) { - if (!(await checkZenity())) return null; - const results = []; - for (let i = 0; i < placeholders.length; i++) { - try { - const script = `zenity --entry --title="${title}" --text="${placeholders[i]}" --width=400`; - const result = await execCommand(script); - if (!result) return []; - results.push(result.trim()); - } catch (error) { - console.error("执行 zenity 命令失败:", error); - return []; - } - } - return results; - } -}; - -const showSystemConfirmBox = async function (content, title = "请确认") { - const iconPath = getQuickcommandIconPath(); - if (window.utools.isMacOs()) { - let iconParam = "note"; - if (iconPath) { - const posixPath = iconPath.replace(/\\/g, "/"); - iconParam = `alias POSIX file "${posixPath}"`; - } - const script = `display dialog "${content}" with title "${title}" buttons {"取消", "确定"} default button "确定" with icon ${iconParam}`; - try { - const result = await this.runAppleScript(script); - return result.includes("button returned:确定"); - } catch (err) { - console.error(err); - return false; - } - } else if (window.utools.isWindows()) { - const args = [ - "-type", - "confirm", - "-title", - title, - "-content", - content.replace(/\r\n|\n/g, "\\n"), - ]; - - if (iconPath) { - args.push("-iconpath", iconPath.replace(/\\/g, "\\\\")); - } - - const result = await runCsharpFeature("dialog", args); - return result === "true"; - } else if (window.utools.isLinux()) { - if (!(await checkZenity())) return false; - try { - const script = `zenity --question --title="${title}" --text="${content}" --width=400`; - await execCommand(script); - return true; - } catch (error) { - return false; - } - } -}; - -const showSystemButtonBox = async function (buttons, title = "请选择") { - const iconPath = getQuickcommandIconPath(); - if (window.utools.isMacOs()) { - const itemList = buttons.map((item) => `"${item}"`).join(", "); - const script = `choose from list {${itemList}} with title "${title}" default items {"${buttons[0]}"}`; - try { - const result = await this.runAppleScript(script); - if (result.includes("false")) return {}; - const text = result.trim(); - const id = buttons.findIndex((item) => item === text); - return { id, text }; - } catch (err) { - console.error(err); - return {}; - } - } else if (window.utools.isWindows()) { - const args = [ - "-type", - "buttons", - "-title", - title, - "-content", - buttons.join("|||||"), - ]; - - if (iconPath) { - args.push("-iconpath", iconPath.replace(/\\/g, "\\\\")); - } - - const result = await runCsharpFeature("dialog", args); - if (result) { - return JSON.parse(result); - } - return {}; - } else if (window.utools.isLinux()) { - if (!(await checkZenity())) return null; - try { - const script1 = `zenity --info --title="${title}" --width=400`; - await execCommand(script1); - - const itemsList = buttons - .map((btn, index) => `"${index}" "${btn}"`) - .join(" "); - const script2 = `zenity --list --title="${title}" --column="序号" --column="选项" ${itemsList} --width=400 --height=300`; - const result = await execCommand(script2); - if (!result) return {}; - const text = result.trim(); - const id = buttons.findIndex((btn) => btn === text); - return { id, text }; - } catch (error) { - console.error("执行 zenity 命令失败:", error); - return null; - } - } -}; - -const showSystemTextArea = async function (defaultText = "", title = "请输入") { - const iconPath = getQuickcommandIconPath(); - if (window.utools.isWindows()) { - const args = [ - "-type", - "textarea", - "-title", - title, - "-content", - defaultText, - ]; - - if (iconPath) { - args.push("-iconpath", iconPath.replace(/\\/g, "\\\\")); - } - - const result = await runCsharpFeature("dialog", args); - return result || null; - } else if (window.utools.isLinux()) { - if (!(await checkZenity())) return null; - try { - const script = `zenity --text-info --title="${title}" --editable --width=450 --height=350 --filename=<(echo "${defaultText}")`; - const result = await execCommand(script); - return result ? result.trim() : null; - } catch (error) { - console.error("执行 zenity 命令失败:", error); - return null; - } - } -}; - -module.exports = { - showSystemMessageBox, - showSystemInputBox, - showSystemConfirmBox, - showSystemButtonBox, - showSystemTextArea, -}; diff --git a/src/js/composer/commands/uiCommands.js b/src/js/composer/commands/uiCommands.js index f5aa1d8..2ccc956 100644 --- a/src/js/composer/commands/uiCommands.js +++ b/src/js/composer/commands/uiCommands.js @@ -258,50 +258,37 @@ export const uiCommands = { isAsync: true, outputVariable: "[inputValue1]", saveOutput: true, + config: [ + { + label: "输入框", + component: "ArrayEditor", + width: 12, + columns: { + label: { + label: "标签", + }, + value: { + label: "默认值", + }, + }, + defaultValue: [ + { + label: newVarInputVal("str", "请输入"), + value: newVarInputVal("str"), + }, + ], + }, + ], subCommands: [ { value: "quickcommand.showInputBox", icon: "call_to_action", label: "插件内弹窗", - config: [ - { - label: "输入框", - component: "ArrayEditor", - width: 12, - columns: { - label: { - label: "标签", - }, - value: { - label: "默认值", - }, - }, - defaultValue: [ - { - label: newVarInputVal("str", "请输入"), - value: newVarInputVal("str"), - }, - ], - }, - ], }, { value: "quickcommand.showSystemInputBox", icon: "report", label: "系统弹窗", - config: [ - { - label: "提示信息", - component: "ArrayEditor", - width: 12, - }, - { - label: "标题", - component: "VariableInput", - defaultValue: newVarInputVal("str", "请输入"), - width: 12, - }, - ], }, ], }, @@ -317,44 +304,30 @@ export const uiCommands = { isAsync: true, outputVariable: "textareaValue", saveOutput: true, + config: [ + { + label: "文本框占位符", + component: "VariableInput", + defaultValue: newVarInputVal("str", "请输入"), + width: 6, + }, + { + label: "文本框默认值", + component: "VariableInput", + defaultValue: newVarInputVal("str"), + width: 6, + }, + ], subCommands: [ { value: "quickcommand.showTextArea", icon: "call_to_action", label: "插件内弹窗", - config: [ - { - label: "文本框占位符", - component: "VariableInput", - defaultValue: newVarInputVal("str", "请输入"), - width: 6, - }, - { - label: "文本框默认值", - component: "VariableInput", - defaultValue: newVarInputVal("str"), - width: 6, - }, - ], }, { value: "quickcommand.showSystemTextArea", icon: "report", - label: "系统弹窗(Mac不支持)", - config: [ - { - label: "文本框默认值", - component: "VariableInput", - defaultValue: newVarInputVal("str"), - width: 6, - }, - { - label: "标题", - component: "VariableInput", - defaultValue: newVarInputVal("str", "请输入"), - width: 6, - }, - ], + label: "系统弹窗", }, ], }, diff --git a/src/plugins/monaco/types/quickcommand.api.d.ts b/src/plugins/monaco/types/quickcommand.api.d.ts index 3e230de..e6475d9 100644 --- a/src/plugins/monaco/types/quickcommand.api.d.ts +++ b/src/plugins/monaco/types/quickcommand.api.d.ts @@ -131,9 +131,9 @@ interface quickcommandApi { * ``` * * @param placeholder 文本框占位符 - * @param value 默认的文本值 + * @param defaultText 默认的文本值 */ - showTextArea(placeholder?: string, value?: string): Promise; + showTextArea(placeholder?: string, defaultText?: string): Promise; /** * 显示一个自动消失的提示框 @@ -483,7 +483,7 @@ interface quickcommandApi { }; /** - * 显示一个系统级消息框(不支持Linux) + * 显示一个系统级消息框 * * ```js * quickcommand.showSystemMessageBox("这是一条消息", "标题") @@ -495,30 +495,33 @@ interface quickcommandApi { showSystemMessageBox(content: string, title?: string): Promise; /** - * 显示一个系统级输入框组,返回所有输入框的值(不支持Linux) + * 显示一个系统级输入框组对话框,返回所有输入框的值 * * ```js - * // 单个输入框 - * quickcommand.showSystemInputBox("请输入:", "标题").then(results => { - * console.log(results[0]) // 第一个输入框的值 + * // 简单数组形式 + * quickcommand.showSystemInputBox(["姓名", "年龄", "地址"], "个人信息").then(values => { + * console.log(values) // ["张三", "25", "北京"] * }) * - * // 多个输入框 - * quickcommand.showSystemInputBox(["姓名:", "年龄:", "地址:"], "个人信息").then(results => { - * console.log(results) // ["张三", "25", "北京"] + * // 对象数组形式 + * quickcommand.showSystemInputBox([ + * { label: "姓名", value: "张三", hint: "请输入姓名" }, + * { label: "年龄", value: "25", hint: "请输入年龄" } + * ], "个人信息").then(values => { + * console.log(values) // ["张三", "25"] * }) * ``` * - * @param placeholders 输入框的提示文本,可以是单个字符串或字符串数组 + * @param options 输入框配置,可以是标签数组或者带属性的对象数组 * @param title 标题,默认为空 */ showSystemInputBox( - placeholders: string | string[], + options: string[] | { label: string; value?: string; hint?: string }[], title?: string ): Promise; /** - * 显示一个系统级确认框,返回是否点击了确认(不支持Linux) + * 显示一个系统级确认框,返回是否点击了确认 * * ```js * quickcommand.showSystemConfirmBox("确定要删除吗?", "确认删除").then(confirmed => { @@ -533,9 +536,8 @@ interface quickcommandApi { */ showSystemConfirmBox(content: string, title?: string): Promise; - /** - * 显示一个系统级按钮组对话框,返回点击的按钮的索引和文本(不支持Linux) + * 显示一个系统级按钮组对话框,返回点击的按钮的索引和文本 * * ```js * quickcommand.showSystemButtonBox(["保存", "不保存", "取消"], "保存确认").then(result => { @@ -554,22 +556,22 @@ interface quickcommandApi { ): Promise<{ id: number; text: string } | null>; /** - * 显示一个系统级多行文本输入框(仅Windows支持) + * 显示一个系统级多行文本输入框 * * ```js - * quickcommand.showSystemTextArea("默认内容", "文本编辑").then(text => { + * quickcommand.showSystemTextArea("请输入内容", "").then(text => { * if (text) { * console.log("输入的文本:", text) * } * }) * ``` * - * @param defaultText 默认文本,默认为空 - * @param title 标题,默认为空 + * @param placeholder 输入框的提示文本,默认为空 + * @param defaultText 输入框的默认文本,默认为空 */ showSystemTextArea( - defaultText?: string, - title?: string + placeholder?: string, + defaultText?: string ): Promise; /**