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

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

View File

@ -24,13 +24,21 @@
<q-menu anchor="top end" self="top start">
<q-list>
<!-- 导入 -->
<q-item clickable v-close-popup @click="importCommand">
<q-item
clickable
v-close-popup
@click="importCommand(importCommandFromFile())"
>
<q-item-section side>
<q-icon name="text_snippet" />
</q-item-section>
<q-item-section>从文件导入命令</q-item-section>
</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-icon name="content_paste" />
</q-item-section>
@ -515,8 +523,22 @@ export default {
},
methods: {
//
importCommand(fromFile = true) {
this.configurationPage.importCommand(fromFile);
importCommand(command) {
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() {

View File

@ -4,21 +4,25 @@
// 是否含有 quickcommand 键值
let isJsonQc = (obj, strict = true) => {
var keys = strict ? ["features", "program", "cmd", "output"] : ["program", "cmd"]
if (keys.filter(x => typeof obj[x] == 'undefined').length) return false
return true
}
var keys = strict
? ["features", "program", "cmd", "output"]
: ["program", "cmd"];
if (keys.filter((x) => typeof obj[x] == "undefined").length) return false;
return true;
};
// 判断是否为可导入的快捷命令
let qcparser = (json, strict = true) => {
try {
var qc = JSON.parse(json)
} catch (error) {
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
}
try {
if (json.slice(0, 3) === "qc=") json = window.base64Decode(json.slice(3));
var qc = JSON.parse(json);
} catch (error) {
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"
persistent
maximized
:transition-show="newCommandDirect ? '' : 'slide-up'"
:transition-show="fromNewCommand ? '' : 'slide-up'"
transition-hide="slide-down"
style="overflow: hidden"
>
@ -318,9 +318,12 @@ export default {
tabBarWidth() {
return this.commandCardStyle === "mini" ? "0" : "80px";
},
newCommandDirect() {
fromNewCommand() {
return this.$route.name === "newcommand";
},
fromImportCommand() {
return this.$route.name === "importcommand";
},
},
mounted() {
this.initPage();
@ -328,21 +331,12 @@ export default {
methods: {
//
initPage() {
// newcommand
if (this.newCommandDirect) {
if (this.$root.enterData.type === "text") {
this.addNewCommand();
} else if (this.$root.enterData.payload.slice(0, 3) === "qc=") {
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");
}
// newcommand
if (this.fromNewCommand) this.addNewCommand();
// importcommand
else if (this.fromImportCommand)
this.importCommand(this.$root.enterData.payload);
this.$router.push("/configuration");
if (this.$route.params.tags) {
this.changeCurrentTag(window.hexDecode(this.$route.params.tags));
this.commandCardStyle = "mini";
@ -450,29 +444,12 @@ export default {
};
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) {
return code.slice(0, 8) === "default_";
},
//
importCommand(fromFile = true) {
let quickCommandInfo = fromFile
? this.importCommandFromFile()
: this.importCommandFromClipboard();
importCommand(quickCommandInfo) {
if (!quickCommandInfo)
return quickcommand.showMessageBox("导入未完成!", "warning");
let parsedData = quickcommandParser(quickCommandInfo);
@ -619,7 +596,7 @@ export default {
switch (event.type) {
case "save":
this.saveCommand(event.data);
// this.isCommandEditorShow = false;
// this.isCommandEditorShow = false;
default:
return;
}

View File

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