新建命令正则匹配功能改为直接导入命令

This commit is contained in:
fofolee 2024-05-07 13:07:08 +08:00
parent 897d597885
commit 545d4b3b31
5 changed files with 125 additions and 125 deletions

View File

@ -37,17 +37,17 @@
"explain": "快速新建快捷命令", "explain": "快速新建快捷命令",
"cmds": [ "cmds": [
"新建快捷命令", "新建快捷命令",
"NewCommand", "NewCommand"
{ ]
"type": "regex",
"label": "新建快捷命令",
"match": "/^\\{[\\s\\S]*\"program\" *: *\".*\"[\\s\\S]*\"cmd\" *: *\".*\"[\\s\\S]*\\}$/i",
"maxNum": 1
}, },
{
"code": "importcommand",
"explain": "导入快捷命令",
"cmds": [
{ {
"type": "regex", "type": "regex",
"label": "新建快捷命令", "label": "导入命令",
"match": "/^qc=eyJwcm9ncmFtIj/", "match": "/(^\\{[\\s\\S]*\"program\" *: *\".*\"[\\s\\S]*\"cmd\" *: *\".*\"[\\s\\S]*\\}$)|(^qc=e)/i",
"maxNum": 1 "maxNum": 1
} }
] ]

View File

@ -24,13 +24,21 @@
<q-menu anchor="top end" self="top start"> <q-menu anchor="top end" self="top start">
<q-list> <q-list>
<!-- 导入 --> <!-- 导入 -->
<q-item clickable v-close-popup @click="importCommand"> <q-item
clickable
v-close-popup
@click="importCommand(importCommandFromFile())"
>
<q-item-section side> <q-item-section side>
<q-icon name="text_snippet" /> <q-icon name="text_snippet" />
</q-item-section> </q-item-section>
<q-item-section>从文件导入命令</q-item-section> <q-item-section>从文件导入命令</q-item-section>
</q-item> </q-item>
<q-item clickable v-close-popup @click="importCommand(false)"> <q-item
clickable
v-close-popup
@click="importCommand(importCommandFromClipboard())"
>
<q-item-section side> <q-item-section side>
<q-icon name="content_paste" /> <q-icon name="content_paste" />
</q-item-section> </q-item-section>
@ -515,8 +523,22 @@ export default {
}, },
methods: { methods: {
// //
importCommand(fromFile = true) { importCommand(command) {
this.configurationPage.importCommand(fromFile); this.configurationPage.importCommand(command);
},
//
importCommandFromFile() {
let options = {
type: "dialog",
argvs: { filters: [{ name: "json", extensions: ["json"] }] },
readfile: true,
};
let fileContent = window.getFileInfo(options);
return fileContent ? fileContent.data : false;
},
//
importCommandFromClipboard() {
return window.clipboardReadText();
}, },
// //
exportAllCommands() { exportAllCommands() {

View File

@ -4,21 +4,25 @@
// 是否含有 quickcommand 键值 // 是否含有 quickcommand 键值
let isJsonQc = (obj, strict = true) => { let isJsonQc = (obj, strict = true) => {
var keys = strict ? ["features", "program", "cmd", "output"] : ["program", "cmd"] var keys = strict
if (keys.filter(x => typeof obj[x] == 'undefined').length) return false ? ["features", "program", "cmd", "output"]
return true : ["program", "cmd"];
} if (keys.filter((x) => typeof obj[x] == "undefined").length) return false;
return true;
};
// 判断是否为可导入的快捷命令 // 判断是否为可导入的快捷命令
let qcparser = (json, strict = true) => { let qcparser = (json, strict = true) => {
try { try {
var qc = JSON.parse(json) if (json.slice(0, 3) === "qc=") json = window.base64Decode(json.slice(3));
var qc = JSON.parse(json);
} catch (error) { } catch (error) {
return false return false;
}
if (isJsonQc(qc, strict)) return { single: true, qc: qc }
else if (!Object.values(qc).filter(q => !isJsonQc(q, strict)).length) return { single: false, qc: qc }
else return false
} }
if (isJsonQc(qc, strict)) return { single: true, qc: qc };
else if (!Object.values(qc).filter((q) => !isJsonQc(q, strict)).length)
return { single: false, qc: qc };
else return false;
};
export default qcparser export default qcparser;

View File

@ -202,7 +202,7 @@
v-model="isCommandEditorShow" v-model="isCommandEditorShow"
persistent persistent
maximized maximized
:transition-show="newCommandDirect ? '' : 'slide-up'" :transition-show="fromNewCommand ? '' : 'slide-up'"
transition-hide="slide-down" transition-hide="slide-down"
style="overflow: hidden" style="overflow: hidden"
> >
@ -318,9 +318,12 @@ export default {
tabBarWidth() { tabBarWidth() {
return this.commandCardStyle === "mini" ? "0" : "80px"; return this.commandCardStyle === "mini" ? "0" : "80px";
}, },
newCommandDirect() { fromNewCommand() {
return this.$route.name === "newcommand"; return this.$route.name === "newcommand";
}, },
fromImportCommand() {
return this.$route.name === "importcommand";
},
}, },
mounted() { mounted() {
this.initPage(); this.initPage();
@ -328,21 +331,12 @@ export default {
methods: { methods: {
// //
initPage() { initPage() {
// newcommand // newcommand
if (this.newCommandDirect) { if (this.fromNewCommand) this.addNewCommand();
if (this.$root.enterData.type === "text") { // importcommand
this.addNewCommand(); else if (this.fromImportCommand)
} else if (this.$root.enterData.payload.slice(0, 3) === "qc=") { this.importCommand(this.$root.enterData.payload);
this.editCommand(
JSON.parse(
window.base64Decode(this.$root.enterData.payload.slice(3))
)
);
} else {
this.editCommand(JSON.parse(this.$root.enterData.payload));
}
this.$router.push("/configuration"); this.$router.push("/configuration");
}
if (this.$route.params.tags) { if (this.$route.params.tags) {
this.changeCurrentTag(window.hexDecode(this.$route.params.tags)); this.changeCurrentTag(window.hexDecode(this.$route.params.tags));
this.commandCardStyle = "mini"; this.commandCardStyle = "mini";
@ -450,29 +444,12 @@ export default {
}; };
this.isCommandEditorShow = true; this.isCommandEditorShow = true;
}, },
//
importCommandFromFile() {
let options = {
type: "dialog",
argvs: { filters: [{ name: "json", extensions: ["json"] }] },
readfile: true,
};
let fileContent = window.getFileInfo(options);
return fileContent ? fileContent.data : false;
},
//
importCommandFromClipboard() {
return window.clipboardReadText();
},
// //
isDefaultCommand(code) { isDefaultCommand(code) {
return code.slice(0, 8) === "default_"; return code.slice(0, 8) === "default_";
}, },
// //
importCommand(fromFile = true) { importCommand(quickCommandInfo) {
let quickCommandInfo = fromFile
? this.importCommandFromFile()
: this.importCommandFromClipboard();
if (!quickCommandInfo) if (!quickCommandInfo)
return quickcommand.showMessageBox("导入未完成!", "warning"); return quickcommand.showMessageBox("导入未完成!", "warning");
let parsedData = quickcommandParser(quickCommandInfo); let parsedData = quickcommandParser(quickCommandInfo);

View File

@ -1,63 +1,60 @@
const routes = [{ const routes = [
path: '/configuration', {
name: 'configuration', path: "/configuration",
component: () => name: "configuration",
import ('pages/ConfigurationPage.vue') component: () => import("pages/ConfigurationPage.vue"),
}, },
{ {
path: '/code', path: "/code",
name: 'code', name: "code",
component: () => component: () => import("pages/RunCodePage.vue"),
import ('pages/RunCodePage.vue')
}, },
{ {
path: '/newcommand', path: "/newcommand",
name: 'newcommand', name: "newcommand",
component: () => component: () => import("pages/ConfigurationPage.vue"),
import ('pages/ConfigurationPage.vue')
}, },
{ {
path: '/:type(default|files|img|key|regex|over|window|professional)_:uid(\\w+)', path: "/importcommand",
name: 'command', name: "importcommand",
component: () => component: () => import("pages/ConfigurationPage.vue"),
import ('pages/CommandPage.vue')
}, },
{ {
path: '/panel_:tags(\\w+)', path: "/:type(default|files|img|key|regex|over|window|professional)_:uid(\\w+)",
name: 'panel', name: "command",
component: () => component: () => import("pages/CommandPage.vue"),
import ('pages/ConfigurationPage.vue')
}, },
{ {
path: '/needupdate', path: "/panel_:tags(\\w+)",
name: 'needupdate', name: "panel",
component: () => import("pages/ConfigurationPage.vue"),
},
{
path: "/needupdate",
name: "needupdate",
props: true, props: true,
component: () => component: () => import("pages/updateWarningPage.vue"),
import ('pages/updateWarningPage.vue')
}, },
{ {
path: '/', path: "/",
name: 'loading', name: "loading",
component: () => component: () => import("pages/LoadingPage.vue"),
import ('pages/LoadingPage.vue')
}, {
path: '/share',
name: 'share',
component: () =>
import ('pages/ShareCenterPage.vue')
}, },
{ {
path: '/feature_:featuretype(\\w+)', path: "/share",
name: 'feature', name: "share",
component: () => component: () => import("pages/ShareCenterPage.vue"),
import ('pages/FeaturesPage.vue')
}, },
{ {
path: '/server', path: "/feature_:featuretype(\\w+)",
name: 'server', name: "feature",
component: () => component: () => import("pages/FeaturesPage.vue"),
import ('pages/ServerPage.vue') },
} {
] path: "/server",
name: "server",
component: () => import("pages/ServerPage.vue"),
},
];
export default routes export default routes;