支持匹配文件夹

This commit is contained in:
fofolee 2024-12-21 14:44:31 +08:00
parent 4baab60804
commit b230088a3a
2 changed files with 88 additions and 49 deletions

View File

@ -18,7 +18,7 @@
icon="arrow_back_ios_new" icon="arrow_back_ios_new"
v-close-popup v-close-popup
class="absolute-left" class="absolute-left"
style="height: 48px" style="height: 48px; width: 22px"
/> />
<div class="col-12 flex justify-center"> <div class="col-12 flex justify-center">
<q-avatar size="64" square class="commandLogo"> <q-avatar size="64" square class="commandLogo">
@ -64,13 +64,7 @@
transition-hide="jump-up" transition-hide="jump-up"
borderless borderless
square square
@update:model-value=" @update:model-value="(val) => handleCmdTypeChange(val)"
(val) =>
(cmdMatch =
val.name === 'professional'
? JSON.stringify(val.jsonSample, null, 4)
: null)
"
:options="commandTypesOptions" :options="commandTypesOptions"
v-model="cmdType" v-model="cmdType"
type="text" type="text"
@ -93,13 +87,13 @@
</q-select> </q-select>
<!-- 匹配规则 --> <!-- 匹配规则 -->
<q-select <q-select
v-if="cmdType.valueType === 'array'"
:disable="!canCommandSave" :disable="!canCommandSave"
hide-dropdown-icon hide-dropdown-icon
stack-label stack-label
label-color="primary" label-color="primary"
transition-show="jump-down" transition-show="jump-down"
transition-hide="jump-up" transition-hide="jump-up"
v-if="cmdType.valueType === 'array'"
borderless borderless
square square
v-model="cmdMatch" v-model="cmdMatch"
@ -120,8 +114,8 @@
</template> </template>
</q-select> </q-select>
<q-input <q-input
:disable="!canCommandSave"
v-else v-else
:disable="!canCommandSave"
autogrow autogrow
borderless borderless
square square
@ -135,6 +129,22 @@
<template v-slot:prepend> <template v-slot:prepend>
<q-icon class="command-side-bar-icon" name="square_foot" /> <q-icon class="command-side-bar-icon" name="square_foot" />
</template> </template>
<template v-slot:append>
<q-icon
v-if="cmdType.name === 'files'"
name="folder"
size="xs"
:color="isFileTypeDirectory ? 'primary' : ''"
@click="isFileTypeDirectory = !isFileTypeDirectory"
style="cursor: pointer"
>
<q-tooltip>
切换匹配类型当前{{
isFileTypeDirectory ? "文件夹" : "文件"
}}
</q-tooltip>
</q-icon>
</template>
</q-input> </q-input>
<!-- 标签 --> <!-- 标签 -->
<q-select <q-select
@ -236,44 +246,41 @@
</template> </template>
</q-select> </q-select>
<!-- 搜索面板推送 --> <!-- 搜索面板推送 -->
<q-field <q-select
:disable="!canCommandSave" :disable="!canCommandSave"
hide-dropdown-icon
stack-label stack-label
label-color="primary" label-color="primary"
transition-show="jump-down"
transition-hide="jump-up"
borderless borderless
square square
type="text" v-model="searchPushValue"
:options="searchPushOptions"
label="搜索面板推送" label="搜索面板推送"
> >
<template v-slot:control>
<div class="self-center full-width no-outline" tabindex="0">
{{
currentCommand.features.mainPush
? "主搜索执行"
: "进插件执行"
}}
<q-btn
flat
round
icon="help_outline"
size="xs"
dense
@click="showMainPushHelp"
></q-btn>
</div>
</template>
<template v-slot:prepend> <template v-slot:prepend>
<q-icon class="command-side-bar-icon" name="search" /> <q-icon class="command-side-bar-icon" name="search" />
</template> </template>
<template v-slot:append> <template v-slot:option="scope">
<q-toggle <q-item v-bind="scope.itemProps">
v-model="currentCommand.features.mainPush" <q-item-section>
color="primary" <q-item-label>{{ scope.opt.label }}</q-item-label>
size="md" <q-item-label caption>{{ scope.opt.desc }}</q-item-label>
dense </q-item-section>
/> <q-item-section side v-if="scope.opt.value">
<q-btn
flat
round
icon="help_outline"
size="xs"
dense
@click.stop="showMainPushHelp"
/>
</q-item-section>
</q-item>
</template> </template>
</q-field> </q-select>
<!-- 平台 --> <!-- 平台 -->
<q-select <q-select
:disable="!canCommandSave" :disable="!canCommandSave"
@ -355,6 +362,14 @@ export default {
mainPush: false, mainPush: false,
}, },
}, },
searchPushOptions: [
{ value: false, label: "禁用", desc: "需要进入插件才能执行命令" },
{
value: true,
label: "启用",
desc: "可以在uTools主搜索框直接执行命令",
},
],
commandTypes: commandTypes, commandTypes: commandTypes,
platformTypes: platformTypes, platformTypes: platformTypes,
currentMatchType: "关键字", currentMatchType: "关键字",
@ -366,7 +381,8 @@ export default {
allQuickCommandTags: this.$parent.allQuickCommandTags, allQuickCommandTags: this.$parent.allQuickCommandTags,
showIconPicker: false, showIconPicker: false,
showUserData: false, showUserData: false,
sideBarPadding: 12, sideBarPadding: 20,
isFileTypeDirectory: false,
}; };
}, },
props: { props: {
@ -400,6 +416,18 @@ export default {
return this.outputTypesOptions; return this.outputTypesOptions;
} }
}, },
searchPushValue: {
get() {
return (
this.searchPushOptions.find(
(opt) => opt.value === this.currentCommand.features.mainPush
) || this.searchPushOptions[0]
);
},
set(option) {
this.currentCommand.features.mainPush = option.value;
},
},
}, },
watch: { watch: {
outputTypesOptionsDy(val) { outputTypesOptionsDy(val) {
@ -435,10 +463,11 @@ export default {
let cmds = this.quickcommandInfo.features?.cmds; let cmds = this.quickcommandInfo.features?.cmds;
if (!cmds) return data; if (!cmds) return data;
if (cmds.length === 1) { if (cmds.length === 1) {
let { type, match } = cmds[0]; let { type, match, fileType } = cmds[0];
data.type = type ? type : "key"; data.type = type ? type : "key";
data.match = data.match =
data.type === "key" ? cmds : match?.app ? match.app : match; data.type === "key" ? cmds : match?.app ? match.app : match;
this.isFileTypeDirectory = fileType === "directory";
} else { } else {
data.type = cmds.filter((x) => !x.length).length data.type = cmds.filter((x) => !x.length).length
? "professional" ? "professional"
@ -447,6 +476,12 @@ export default {
} }
return data; return data;
}, },
handleCmdTypeChange(val) {
this.cmdMatch =
val.name === "professional"
? JSON.stringify(val.jsonSample, null, 4)
: null;
},
tagVerify(val, done) { tagVerify(val, done) {
if ( if (
[ [
@ -508,8 +543,16 @@ export default {
if (verify !== true) { if (verify !== true) {
return quickcommand.showMessageBox(verify, "error"); return quickcommand.showMessageBox(verify, "error");
} }
//
let rules = this.cmdMatch;
if (this.cmdType.name === "files") {
rules = {
fileType: this.isFileTypeDirectory ? "directory" : "file",
match: this.cmdMatch,
};
}
updateData.features.cmds = this.cmdType.matchToCmds( updateData.features.cmds = this.cmdType.matchToCmds(
this.cmdMatch, rules,
updateData.features.explain updateData.features.explain
); );
@ -562,7 +605,7 @@ export default {
border-radius: 8px; border-radius: 8px;
padding: 4px; padding: 4px;
color: #f4f4f4; color: #f4f4f4;
font-size: 16px; font-size: 14px;
/* 分开设置不同属性的过渡效果 */ /* 分开设置不同属性的过渡效果 */
transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1),
@ -580,17 +623,12 @@ export default {
transform: scale(1.05) translateY(-1px) translateZ(0); transform: scale(1.05) translateY(-1px) translateZ(0);
background: var(--q-primary); background: var(--q-primary);
opacity: 0.9; opacity: 0.9;
/* 移除font-size变化 */
} }
/* 输入框得焦点时的图标效果 */ /* 输入框得焦点时的图标效果 */
.q-field--focused .command-side-bar-icon { .q-field--focused .command-side-bar-icon {
transform: scale(1.1) translateY(-1px) translateZ(0); transform: scale(1.1) translateY(-1px) translateZ(0);
background: var(--q-primary); background: var(--q-primary);
opacity: 0.85; opacity: 0.85;
} }
/* .command-side-bar-content {
width: 171px;
} */
</style> </style>

View File

@ -159,8 +159,9 @@ const commandTypes = {
matchToCmds: (rules, desc) => [{ matchToCmds: (rules, desc) => [{
type: "files", type: "files",
label: desc, label: desc,
match: rules, match: rules.match,
"minLength": 1, fileType: rules.fileType,
minLength: 1,
}, ], }, ],
verify: rules => !!rules > 0 || "正则不能为空", verify: rules => !!rules > 0 || "正则不能为空",
tempPayload: () => window.convertFilePathToUtoolsPayload(utools.showOpenDialog({ tempPayload: () => window.convertFilePathToUtoolsPayload(utools.showOpenDialog({