diff --git a/plugin/lib/quickcomposer/simulate/index.js b/plugin/lib/quickcomposer/simulate/index.js index cb17c03..f8bc9f9 100644 --- a/plugin/lib/quickcomposer/simulate/index.js +++ b/plugin/lib/quickcomposer/simulate/index.js @@ -1,10 +1,13 @@ const { findImage } = require("./imageFinder"); -const { captureScreen } = require("./screenCapture"); const { keyboardTap, keySequence } = require("./keyboardTap"); +const { screenColorPick } = require("./screenColorPick"); +const screenCapture = require("./screenCapture"); module.exports = { findImage, - captureScreen, + screenCapture, keyboardTap, keySequence, + screenColorPick, + ...screenCapture, }; diff --git a/plugin/lib/quickcomposer/simulate/screenCapture.js b/plugin/lib/quickcomposer/simulate/screenCapture.js index 62ee22e..14c4eae 100644 --- a/plugin/lib/quickcomposer/simulate/screenCapture.js +++ b/plugin/lib/quickcomposer/simulate/screenCapture.js @@ -187,7 +187,7 @@ async function captureLinuxScreen() { } // 统一的截图接口 -async function captureScreen() { +async function captureFullScreen() { try { if (process.platform === "darwin") { return await captureMacScreen(); @@ -202,4 +202,41 @@ async function captureScreen() { return null; } -module.exports = { captureScreen }; +function captureAreaScreen() { + return new Promise((resolve) => { + window.utools.screenCapture((data) => { + resolve(data); + }); + }); +} + +async function captureScreen(range = "fullscreen") { + return range === "fullscreen" + ? await captureFullScreen() + : await captureAreaScreen(); +} + +async function captureScreenToFile(range = "fullscreen", path = null) { + if (!path) return null; + const result = await captureScreen(range); + if (!result) return null; + fs.writeFileSync( + path, + result.replace("data:image/png;base64,", ""), + "base64" + ); + return result; +} + +async function captureScreenToClipboard(range = "fullscreen") { + const result = await captureScreen(range); + if (!result) return null; + window.utools.copyImage(result); + return result; +} + +module.exports = { + captureScreen, + captureScreenToFile, + captureScreenToClipboard, +}; diff --git a/plugin/lib/quickcomposer/simulate/screenColorPick.js b/plugin/lib/quickcomposer/simulate/screenColorPick.js new file mode 100644 index 0000000..cfc7522 --- /dev/null +++ b/plugin/lib/quickcomposer/simulate/screenColorPick.js @@ -0,0 +1,11 @@ +const screenColorPick = () => { + return new Promise((resolve) => { + utools.screenColorPick((color) => { + resolve(color); + }); + }); +}; + +module.exports = { + screenColorPick, +}; diff --git a/src/components/composer/MultiParams.vue b/src/components/composer/MultiParams.vue index b0d0de6..2eed4d2 100644 --- a/src/components/composer/MultiParams.vue +++ b/src/components/composer/MultiParams.vue @@ -41,16 +41,16 @@ export default defineComponent({ // 过滤掉特定函数排除的参数, excludeConfig格式为[要排除的参数索引] this.modelValue.config?.filter( (_, index) => - !this.getSelectFunction()?.excludeConfig?.includes(index) + !this.getSelectSubCommand()?.excludeConfig?.includes(index) ) || [] ); }, // 特定函数独有参数配置,config格式和通用的config一致 - functionConfig() { - return this.getSelectFunction()?.config || []; + subCommandConfig() { + return this.getSelectSubCommand()?.config || []; }, localConfig() { - return [...this.commonConfig, ...this.functionConfig].map((item) => { + return [...this.commonConfig, ...this.subCommandConfig].map((item) => { const value = item.type === "varInput" ? item.defaultValue || newVarInputVal("str") @@ -79,7 +79,7 @@ export default defineComponent({ }); // 使用新选择的函数独有配置的默认值 - this.getSelectFunction(value)?.config?.forEach((config, index) => { + this.getSelectSubCommand(value)?.config?.forEach((config, index) => { newArgvs[this.commonConfig.length + index] = config.defaultValue; }); @@ -96,7 +96,7 @@ export default defineComponent({ }, }, methods: { - getSelectFunction(funcName = this.funcName) { + getSelectSubCommand(funcName = this.funcName) { return this.modelValue.subCommands?.find( (item) => item.value === funcName ); @@ -165,7 +165,7 @@ export default defineComponent({ }, getSummary(argvs) { // 虽然header里对溢出做了处理,但是这里截断主要是为了节省存储空间 - const funcNameLabel = this.getSelectFunction()?.label; + const funcNameLabel = this.getSelectSubCommand()?.label; const subFeature = funcNameLabel ? `${funcNameLabel} ` : ""; const allArgvs = argvs .filter((item) => item != null && item != "") diff --git a/src/components/composer/common/DictEditor.vue b/src/components/composer/common/DictEditor.vue index 650bf30..f999e9d 100644 --- a/src/components/composer/common/DictEditor.vue +++ b/src/components/composer/common/DictEditor.vue @@ -82,7 +82,10 @@ " /> -
+