mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-28 11:52:46 +08:00
变量选择支持enterData.type和enterData.payload
This commit is contained in:
parent
ded2a546a5
commit
89a493e626
@ -93,6 +93,7 @@
|
||||
@update-flow="updateFlows(flow)"
|
||||
:is-main-flow="flow.id === 'main'"
|
||||
:output-variables="outputVariables"
|
||||
:global-variables="pluginGlobalVariables"
|
||||
class="variable-panel"
|
||||
/>
|
||||
</div>
|
||||
@ -101,6 +102,7 @@
|
||||
|
||||
<script>
|
||||
import { defineComponent, provide, ref, computed } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import draggable from "vuedraggable";
|
||||
import ComposerFlow from "components/composer/ComposerFlow.vue";
|
||||
import ComposerButtons from "components/composer/flow/ComposerButtons.vue";
|
||||
@ -197,6 +199,49 @@ export default defineComponent({
|
||||
return flows.value.find((flow) => flow.id === activeTab.value);
|
||||
};
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
const isRunComposerPage = computed(() => {
|
||||
return route.name === "composer";
|
||||
});
|
||||
|
||||
const pluginGlobalVariables = computed(() => {
|
||||
if (isRunComposerPage.value) return [];
|
||||
return [
|
||||
{
|
||||
name: "quickcommand.enterData.type",
|
||||
sourceCommand: {
|
||||
label: "匹配模式",
|
||||
},
|
||||
description:
|
||||
"以什么模式进入插件,可能的值:\n" +
|
||||
"关键字:text\n" +
|
||||
"正则匹配:regex\n" +
|
||||
"所有文本:over\n" +
|
||||
"图片匹配:img\n" +
|
||||
"文件匹配:files\n" +
|
||||
"窗口匹配:window",
|
||||
type: "global",
|
||||
},
|
||||
|
||||
{
|
||||
name: "quickcommand.enterData.payload",
|
||||
sourceCommand: {
|
||||
label: "匹配内容",
|
||||
},
|
||||
description:
|
||||
"根据不同的匹配模式,返回不同的内容:\n" +
|
||||
"关键字(text):返回进入插件的关键字\n" +
|
||||
"正则(regex):返回匹配的文本\n" +
|
||||
"所有文本(over):返回匹配的文本\n" +
|
||||
"窗口(window):返回匹配的窗口信息(对象)\n" +
|
||||
"文件(files):返回匹配的文件信息(数组)\n" +
|
||||
"图片(img):返回匹配的图片信息(dataURL)",
|
||||
type: "global",
|
||||
},
|
||||
];
|
||||
});
|
||||
|
||||
// 获取当前函数所有输出变量
|
||||
const getOutputVariables = (flow = getCurrentFlow()) => {
|
||||
const variables = [];
|
||||
@ -251,7 +296,7 @@ export default defineComponent({
|
||||
label: v.type === "param" ? "函数参数" : "局部变量",
|
||||
},
|
||||
}));
|
||||
return [...customVariables, ...variables];
|
||||
return [...pluginGlobalVariables.value, ...customVariables, ...variables];
|
||||
};
|
||||
|
||||
provide("getCurrentVariables", getCurrentVariables);
|
||||
@ -263,8 +308,10 @@ export default defineComponent({
|
||||
commandConfig,
|
||||
activeTab,
|
||||
getOutputVariables,
|
||||
pluginGlobalVariables,
|
||||
updateFlows,
|
||||
clearFlows,
|
||||
isRunComposerPage,
|
||||
};
|
||||
},
|
||||
data() {
|
||||
@ -275,9 +322,6 @@ export default defineComponent({
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
isRunComposerPage() {
|
||||
return this.$route.name === "composer";
|
||||
},
|
||||
showCommandConfig() {
|
||||
return !this.isRunComposerPage && this.commandConfig.features;
|
||||
},
|
||||
|
@ -31,6 +31,7 @@
|
||||
<VariableList
|
||||
:show-variable-list="showVariableList"
|
||||
:show-function-list="showFunctionList"
|
||||
:show-global-variables="false"
|
||||
@emit-value="updateValBySelect"
|
||||
class="variable-list-btn"
|
||||
/>
|
||||
|
@ -51,6 +51,7 @@
|
||||
@emit-value="updateValBySelect"
|
||||
:show-variable-list="true"
|
||||
:show-function-list="true"
|
||||
:show-global-variables="true"
|
||||
class="prepend-btn variable-list-btn"
|
||||
/>
|
||||
</template>
|
||||
|
@ -30,10 +30,27 @@
|
||||
<q-item-label class="variable-name">
|
||||
{{ variable.name }}
|
||||
</q-item-label>
|
||||
<q-item-label caption class="variable-source">
|
||||
来自: {{ variable.sourceCommand.label }}
|
||||
<q-item-label
|
||||
caption
|
||||
class="variable-source"
|
||||
v-if="variable.sourceCommand"
|
||||
>
|
||||
<span>
|
||||
{{ variable.type === "global" ? "全局变量:" : "来自:" }}
|
||||
</span>
|
||||
<span>{{ variable.sourceCommand.label }}</span>
|
||||
</q-item-label>
|
||||
</q-item-section>
|
||||
<q-tooltip
|
||||
anchor="center left"
|
||||
self="center end"
|
||||
v-if="variable.description"
|
||||
>
|
||||
<div
|
||||
v-text="variable.description"
|
||||
class="variable-description"
|
||||
></div>
|
||||
</q-tooltip>
|
||||
</q-item>
|
||||
</div>
|
||||
<div v-if="functions.length && showFunctionList">
|
||||
@ -56,7 +73,7 @@
|
||||
<q-item-label class="variable-name">
|
||||
{{ func.name }}
|
||||
</q-item-label>
|
||||
<q-item-label caption class="variable-source">
|
||||
<q-item-label caption class="row item">
|
||||
{{ func.label }}
|
||||
</q-item-label>
|
||||
</q-item-section>
|
||||
@ -138,12 +155,15 @@ import { defineComponent, inject } from "vue";
|
||||
export default defineComponent({
|
||||
name: "VariableList",
|
||||
emits: ["emitValue"],
|
||||
setup() {
|
||||
setup(props) {
|
||||
const getCurrentVariables = inject("getCurrentVariables");
|
||||
const commandIndex = inject("commandIndex", null);
|
||||
|
||||
const getAvailableVariables = () => {
|
||||
const variables = getCurrentVariables();
|
||||
let variables = getCurrentVariables();
|
||||
if (!props.showGlobalVariables) {
|
||||
variables = variables.filter((variable) => variable.type !== "global");
|
||||
}
|
||||
const usableVariables = variables.filter((variable) =>
|
||||
// 输出变量只显示在当前命令之前的
|
||||
variable.type === "output"
|
||||
@ -192,6 +212,10 @@ export default defineComponent({
|
||||
},
|
||||
},
|
||||
props: {
|
||||
showGlobalVariables: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
showVariableList: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
@ -321,4 +345,10 @@ export default defineComponent({
|
||||
.empty-tip .q-separator {
|
||||
opacity: 0.2;
|
||||
}
|
||||
|
||||
.variable-description {
|
||||
word-break: break-all;
|
||||
white-space: pre-wrap;
|
||||
font-size: 11px;
|
||||
}
|
||||
</style>
|
||||
|
@ -92,6 +92,31 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
<div class="section-title">
|
||||
<q-icon name="data_object" size="16px" class="text-primary" />
|
||||
<span>全局变量</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="var-list">
|
||||
<div
|
||||
v-for="(variable, index) in globalVariables"
|
||||
:key="index"
|
||||
class="var-item"
|
||||
>
|
||||
<div class="global-var-name">{{ variable.name }}</div>
|
||||
<q-tooltip
|
||||
v-if="variable.description"
|
||||
anchor="center left"
|
||||
self="center end"
|
||||
>
|
||||
<div class="var-description">{{ variable.description }}</div>
|
||||
</q-tooltip>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 手动变量管理部分 -->
|
||||
<div class="section">
|
||||
<div class="section-header">
|
||||
@ -203,6 +228,11 @@ export default defineComponent({
|
||||
required: true,
|
||||
default: () => [],
|
||||
},
|
||||
globalVariables: {
|
||||
type: Array,
|
||||
required: true,
|
||||
default: () => [],
|
||||
},
|
||||
},
|
||||
emits: ["update:modelValue", "update:flow"],
|
||||
computed: {
|
||||
@ -410,12 +440,23 @@ export default defineComponent({
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.global-var-name {
|
||||
font-size: 11px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.var-source {
|
||||
margin-left: auto;
|
||||
font-size: 11px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.var-description {
|
||||
word-break: break-all;
|
||||
white-space: pre-wrap;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.section-content {
|
||||
padding: 8px;
|
||||
}
|
||||
|
@ -4,29 +4,6 @@ export const utoolsCommands = {
|
||||
label: "uTools功能",
|
||||
icon: "insights",
|
||||
commands: [
|
||||
{
|
||||
value: "quickcommand.enterData.valueOf",
|
||||
label: "获取匹配数据",
|
||||
icon: "visibility_off",
|
||||
outputs: {
|
||||
label: "匹配数据",
|
||||
suggestName: "enterData",
|
||||
placeholder: "返回 {code, type, payload, from}",
|
||||
structure: {
|
||||
type: {
|
||||
label: "匹配类型",
|
||||
suggestName: "enterType",
|
||||
placeholder:
|
||||
'返回 "text" | "img" | "file" | "regex" | "over" | "window"',
|
||||
},
|
||||
payload: {
|
||||
label: "匹配的数据",
|
||||
suggestName: "enterPayload",
|
||||
placeholder: "返回 string | MatchFile[] | MatchWindow",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
value: "utools.hideMainWindow",
|
||||
label: "隐藏主窗口",
|
||||
|
Loading…
x
Reference in New Issue
Block a user