diff --git a/plugin/plugin.json b/plugin/plugin.json index befc579..e56d260 100644 --- a/plugin/plugin.json +++ b/plugin/plugin.json @@ -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 } ] diff --git a/src/components/ConfigurationMenu.vue b/src/components/ConfigurationMenu.vue index a1e310f..36d56fd 100644 --- a/src/components/ConfigurationMenu.vue +++ b/src/components/ConfigurationMenu.vue @@ -24,13 +24,21 @@ - + 从文件导入命令 - + @@ -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() { diff --git a/src/js/common/quickcommandParser.js b/src/js/common/quickcommandParser.js index 4372f00..48df2cd 100644 --- a/src/js/common/quickcommandParser.js +++ b/src/js/common/quickcommandParser.js @@ -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; diff --git a/src/pages/ConfigurationPage.vue b/src/pages/ConfigurationPage.vue index 0af0dc6..df0e900 100644 --- a/src/pages/ConfigurationPage.vue +++ b/src/pages/ConfigurationPage.vue @@ -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; } diff --git a/src/router/routes.js b/src/router/routes.js index df497e0..c671c01 100644 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -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;