完善插件别名功能

This commit is contained in:
fofolee 2022-04-16 00:46:09 +08:00
parent 8d74288ed7
commit fc4ba4606c

View File

@ -1,14 +1,121 @@
<template>
<div
class="flex justify-center content-center"
style="height: 500px"
v-show="showPluNickNameSetting"
>
<div class="q-gutter-lg q-pa-lg" style="width: 600px">
<div class="text-center text-h2 q-ma-none">插件别名设置</div>
<q-select
outlined
v-model="plugin"
:options="plugins"
type="text"
class="full-width"
:display-value="plugin.pluginName"
@update:model-value="feature = features[0]"
label="请选择插件"
>
<template v-slot:prepend>
<q-icon name="extension" />
</template>
<template v-slot:option="scope">
<q-item v-bind="scope.itemProps">
<q-item-section avatar>
<q-img :src="`file:///${scope.opt.logoPath}`" />
</q-item-section>
<q-item-section>
<q-item-label v-html="scope.opt.pluginName" />
<q-item-label caption>{{ scope.opt.description }}</q-item-label>
</q-item-section>
</q-item>
</template>
</q-select>
<q-select
outlined
v-model="feature"
:options="features"
type="text"
:display-value="feature.cmd || ''"
class="full-width"
label="请选择功能关键字"
>
<template v-slot:prepend>
<q-icon name="font_download" />
</template>
<template v-slot:option="scope">
<q-item v-bind="scope.itemProps">
<q-item-section avatar>
<q-img :src="`file:///${plugin.logoPath}`" />
</q-item-section>
<q-item-section>
<q-item-label v-html="scope.opt.cmd" />
<q-item-label caption>{{ scope.opt.explain }}</q-item-label>
</q-item-section>
</q-item>
</template>
</q-select>
<q-select
class="full-width"
max-values="3"
type="text"
placeholder="键入后回车"
use-input
hide-dropdown-icon
use-chips
multiple
new-value-mode="add-unique"
input-debounce="0"
outlined
v-model="nickName"
label="要设置的别名"
>
<template v-slot:prepend>
<q-icon name="drive_file_rename_outline" />
</template>
</q-select>
<q-btn
class="full-width"
color="primary"
label="确定"
@click="addPluNickName()"
/>
</div>
</div>
</template>
<script> <script>
export default { export default {
data() { data() {
return { return {
featureType: this.$route.params.featuretype, featureType: this.$route.params.featuretype,
cmdCtrlKey: window.processPlatform === "darwin" ? "command" : "control",
plugins: [],
plugin: {},
feature: {},
nickName: [],
showPluNickNameSetting: false,
}; };
}, },
computed: {
features() {
return this.plugin?.features
?.map((x) => {
return {
explain: x.explain,
cmd: x.cmds.filter((y) => y.length)[0],
};
})
.filter((x) => x.cmd);
},
},
mounted() { mounted() {
switch (this.featureType) { switch (this.featureType) {
case "pluNickName": case "pluNickName":
this.showNickNameSetting(); this.showPluNickNameSetting = true;
this.plugins = _.values(window.getUtoolsPlugins());
this.plugin = this.plugins[0];
this.feature = this.features[0];
break; break;
case "favFile": case "favFile":
this.addFavFile(); this.addFavFile();
@ -28,17 +135,32 @@ export default {
}, ms); }, ms);
}); });
}, },
showNickNameSetting() { getPlugins() {},
quickcommand addPluNickName() {
.showInputBox(["插件的功能关键字", "要设置的别名"], "插件别名设置") if (!this.nickName.length)
.then((res) => {}); return quickcommand.showMessageBox("请填写别名", "warning");
let uid = this.getUid();
let command = {
features: {
cmds: this.nickName,
explain: this.feature.explain,
icon: window.getBase64Ico(this.plugin.logoPath),
platform: this.plugin.platform || ["darwin", "win32", "linux"],
code: `key_${uid}`,
},
program: "quickcommand",
cmd: `utools.redirect("${this.feature.cmd}");utools.showMainWindow()`,
output: "ignore",
tags: [this.$profile.quickFeatures.pluNickName.tag],
};
this.importCommand(command);
this.nickName = [];
quickcommand.showMessageBox("添加成功!");
}, },
addFavFile() { addFavFile() {
utools.setExpendHeight(0); utools.setExpendHeight(0);
quickcommand.enterData.payload.forEach((file) => { quickcommand.enterData.payload.forEach((file) => {
let uid = Number( let uid = this.getUid();
Math.random().toString().substr(3, 3) + Date.now()
).toString(36);
let fileInfo = window.getFileInfo({ let fileInfo = window.getFileInfo({
type: "file", type: "file",
argvs: file.path, argvs: file.path,
@ -60,20 +182,20 @@ export default {
}; };
this.importCommand(command); this.importCommand(command);
}); });
utools.showNotification("收藏成功!"); this.showMsg();
utools.outPlugin();
}, },
async addFavUrl() { async addFavUrl() {
utools.setExpendHeight(0); utools.setExpendHeight(0);
utools.hideMainWindow(); utools.hideMainWindow();
// getCurrentBrowserUrl // getCurrentBrowserUrl
// let url = utools.getCurrentBrowserUrl(); // let url = utools.getCurrentBrowserUrl();
utools.simulateKeyboardTap("l", "control"); utools.simulateKeyboardTap("l", this.cmdCtrlKey);
await this.wait(50); await this.wait(50);
utools.simulateKeyboardTap("c", "control"); utools.simulateKeyboardTap("c", this.cmdCtrlKey);
await this.wait(50); await this.wait(50);
let url = window.clipboardReadText(); let url = window.clipboardReadText();
if (!/^http/.test(url)) { if (!/^http/.test(url)) {
utools.showMainWindow();
utools.setExpendHeight(550); utools.setExpendHeight(550);
let choise = await quickcommand.showButtonBox( let choise = await quickcommand.showButtonBox(
["http", "https"], ["http", "https"],
@ -93,9 +215,7 @@ export default {
utools.getPath("temp"), utools.getPath("temp"),
"quickcommandfavicon.ico" "quickcommandfavicon.ico"
); );
let uid = Number( let uid = this.getUid();
Math.random().toString().substr(3, 3) + Date.now()
).toString(36);
let command = { let command = {
features: { features: {
explain: `访问${title}`, explain: `访问${title}`,
@ -113,8 +233,7 @@ export default {
if (res) command.features.icon = iconPath; if (res) command.features.icon = iconPath;
} catch (e) {} } catch (e) {}
this.importCommand(command); this.importCommand(command);
utools.showNotification("收藏成功!"); this.showMsg();
utools.outPlugin();
}, },
importCommand(command) { importCommand(command) {
command = _.cloneDeep(command); command = _.cloneDeep(command);
@ -124,6 +243,15 @@ export default {
); );
this.$utools.whole.setFeature(command.features); this.$utools.whole.setFeature(command.features);
}, },
getUid() {
return Number(
Math.random().toString().substr(3, 3) + Date.now()
).toString(36);
},
showMsg() {
utools.showNotification("操作成功!");
utools.outPlugin();
},
}, },
}; };
</script> </script>