diff --git a/src/assets/options.js b/src/assets/options.js index d25a558..c77d8b3 100644 --- a/src/assets/options.js +++ b/src/assets/options.js @@ -151,21 +151,39 @@ let programs = { } } -let showOptions = () => { - $("#featureList").remove(); +let showOptions = (tag = "默认") => { + $("#options").empty().fadeIn(); var currentFts = utools.getFeatures(), customFts = getDB('customFts'); - let featureList = '
模式 | 说明 | 启用 |
+ | 模式 | +说明 | +启用 | +
${cmds} | ${features.explain} |
-
- | |
${cmds} | +${features.explain} | +
+
+ | `
- };
- featureList += `
@@ -216,15 +244,17 @@ let showCustomize = () => { 关键字
-说 明
+说 明
+
+
类 型
- 图 标
-
+ 标 签
+
变 量 @@ -258,13 +288,13 @@ let showCustomize = () => { - + ﹢动作 ﹢按键 ?帮助 - - 格式化 + + 格式化
@@ -324,7 +354,7 @@ let beautifyCode = () => { switch ($("#program").val()) { case "simulation": case "javascript": - window.editor.setValue(js_beautify(cm)) + window.editor.setValue(js_beautify(cmd, { brace_style: "collapse,preserve-inline" })) break; case "python": py_beautify(cmd, data => { @@ -467,6 +497,7 @@ $("#options").on('click', '.editBtn', function () { var code = $(this).attr('code'); var data = utools.db.get("customFts").data[code]; showCustomize(); + data.tags && $('#tags').val(data.tags.join(",")) var cmds = data.features.cmds[0] if (cmds.type == 'regex') { $('#type').val('regex') @@ -518,19 +549,6 @@ $("#options").on('click', '#showHelp', function () { }) }) -// 添加延时 -$("#options").on('click', '#addDelay', function () { - var t = $('#keydelay').val(); - if (/\d+/.test(t)) { - window.editor.replaceSelection(`sleep(${t});\n`) - } else { - Swal.fire({ - icon: 'warning', - text: '请输入正确的时间, 单位 ms', - }) - } -}) - // 添加动作 $("#options").on('click', '#addAction', function () { var html = ` @@ -544,7 +562,7 @@ $("#options").on('click', '#addAction', function () { - + 加引号 @@ -579,13 +597,27 @@ $("#options").on('click', '.exportBtn', function () { // 删除 $("#options").on('click', '.delBtn', function () { - var code = $(this).attr('code'), - db = utools.db.get("customFts"), - data = db.data; - delete data[code]; - utools.removeFeature(code); - utools.db.put({ _id: "customFts", data: data, _rev: db._rev }); - showOptions(); + Swal.fire({ + text: '删除这个快捷命令', + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#3085d6', + cancelButtonColor: '#d33', + confirmButtonText: '确定!', + cancelButtonText: '手抖...', + }).then((result) => { + if (result.value) { + var code = $(this).attr('code'), + db = utools.db.get("customFts"), + data = db.data; + delete data[code]; + utools.removeFeature(code); + utools.db.put({ _id: "customFts", data: data, _rev: db._rev }); + var currentTag = $('.currentTag').text() + if ($('#featureList tr').length == 2) currentTag = "默认" + showOptions(currentTag); + } + }) }) // 选择图标 @@ -608,6 +640,7 @@ let SaveCurrentCommand = async () => { if ($("#customize").is(":parent") && $("#featureList").is(":parent")) { var type = $('#type').val(); var code = $("#code").val(); + var tags = $('#tags').val() if (!code) { // 生成唯一code var uid = Number(Math.random().toString().substr(3, 3) + Date.now()).toString(36); @@ -648,9 +681,9 @@ let SaveCurrentCommand = async () => { } var rule = $('#rule').val(); if (type == 'key') { - cmds = rule.split(',') + cmds = rule.split(",").map(x => x.trim()) } else if (type == 'regex') { - if (rule[0] != '/' || rule[rule.length - 1] != '/') { + if (!/^\/.*?\/[igm]*$/.test(rule)) { await Swal.fire({ icon: 'info', text: '亲,是不是忘了正则表达式两边的"/"了?正确的写法是/xxxx/,不过作者会很贴心地帮你自动加上哟', @@ -664,13 +697,20 @@ let SaveCurrentCommand = async () => { "minNum": 1 }]; } else if (type == 'window') { - cmds = [{ + var cmdOfWin = { "label": desc, - "type": "window", - "match": { - "app": rule.split(',') + "type": "window" + } + if (rule) { + try { + cmdOfWin.match = JSON.parse(rule) + } catch (error) { + cmdOfWin.match = { + "app": rule.split(',') + } } - }]; + } + cmds = [cmdOfWin]; } // 需要子输入框 if (cmd.includes('{{subinput}}')) { @@ -678,12 +718,6 @@ let SaveCurrentCommand = async () => { } else { hasSubInput = false; } - $("#customize").animate({ top: '100%' }); - // if (type == "robotjs") { - // program = ""; - // output = ""; - // robotjs = true; - // } // 添加特性 pushData = { features: { @@ -696,8 +730,8 @@ let SaveCurrentCommand = async () => { cmd: cmd, output: output, hasSubInput: hasSubInput - // robotjs: robotjs } + if (tags) pushData.tags = tags.split(",").map(x => x.trim()) if (program == 'custom') { pushData.customOptions = { "bin": $('#custombin').val(), @@ -706,16 +740,26 @@ let SaveCurrentCommand = async () => { 'codec': $('#customcodec').val() } } - // if (program == 'simulation') { - // $('#output').val(''); - // } putDB(code, pushData, 'customFts'); - showOptions(); - $("#customize").empty() - $(`#${code}`).click(); - if (!$(`#${code}`).is(':checked')) { + $("#customize").animate({ top: '100%' }, () => { + // 保存后标签跳转处理 + var redirectTag, currentTag = $('.currentTag').text() + if (tags) { + if (pushData.tags.includes(currentTag)) { + redirectTag = currentTag + } else { + redirectTag = pushData.tags[0] + } + } else { + redirectTag = "未分类" + } + showOptions(redirectTag); + $("#customize").empty() $(`#${code}`).click(); - } + if (!$(`#${code}`).is(':checked')) { + $(`#${code}`).click(); + } + }); } } } @@ -724,7 +768,7 @@ let SaveCurrentCommand = async () => { let showRunResult = (content, raw, success) => { var options var maxlength = 100000 - var position = $("#varoutput").is(":parent") ? 'top' : 'bottom' + var position = $(".varoutput").is(":parent") ? 'top' : 'bottom' var preView = () => { var result = $('#swal2-content').text() result = htmlEncode(result, raw) @@ -745,7 +789,7 @@ let showRunResult = (content, raw, success) => { text: content, position: position, width: 800, - showConfirmButton: false, + showConfirmButton: true, showClass: { popup: 'fadeInDownWindow' }, @@ -753,7 +797,7 @@ let showRunResult = (content, raw, success) => { popup: 'fadeOutUpWindow' } } - Swal.fire(options) + swalOneByOne(options) } } @@ -770,6 +814,7 @@ let runCurrentCommand = async () => { await Swal.fire({ title: "需要临时为以下变量赋值", html: html, + focusConfirm: false, preConfirm: () => { requireInputVal.forEach(r => { cmd = cmd.replace(new RegExp(r, 'g'), document.getElementById(r).value) @@ -867,8 +912,14 @@ showCodeEditor = () => { window.editor.setValue(db.history.cmd) } programCheck() + $("#options").show() } +// 切换TAGS +$("#options").on('click', '.sidebar li', function () { + showOptions($(this).text()); +}) + // 运行 $("#options").on('click', '.cmdBtn.run, #runCode', function () { runCurrentCommand()