From ec41728d0e99cd9268a784807e4c6deec7dfb5b1 Mon Sep 17 00:00:00 2001 From: fofolee Date: Thu, 7 Apr 2022 23:53:22 +0800 Subject: [PATCH] =?UTF-8?q?3=20=E4=B8=AA=20ui=20=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/preload.js | 178 +++++------------- src/components/quickcommandUI/ButtonBox.vue | 55 ++++++ .../{ => quickcommandUI}/InputBox.vue | 0 src/components/quickcommandUI/TextArea.vue | 69 +++++++ src/js/quickcommand.js | 48 ++++- src/json/default_VSSnippet.json | 4 +- .../monaco/types/quickcommand.api.d.ts | 2 +- 7 files changed, 220 insertions(+), 136 deletions(-) create mode 100644 src/components/quickcommandUI/ButtonBox.vue rename src/components/{ => quickcommandUI}/InputBox.vue (100%) create mode 100644 src/components/quickcommandUI/TextArea.vue diff --git a/public/preload.js b/public/preload.js index 7a9b751..2d62525 100644 --- a/public/preload.js +++ b/public/preload.js @@ -92,86 +92,6 @@ quickcommand = { }) }, - // 显示输入框 - showInputBox: function(placeHolders = [""], title = '') { - return new Promise((reslove, reject) => { - if (!(placeHolders instanceof Array)) placeHolders = [placeHolders.toString()] - utools.setExpendHeight(550) - var html = "" - var inputBoxNumbers = placeHolders.length - for (let i = 0; i < inputBoxNumbers; i++) { - html += `` - } - var result = [] - var options = { - onBeforeOpen: () => { - document.getElementById(`inputBox0`).focus() - $('.swal2-content').keydown(function(e) { - e.which == 13 && swal.clickConfirm() - }) - $(".output").is(":parent") ? utools.setExpendHeight(550) : modWindowHeight($('.swal2-popup').outerHeight() + 20) - }, - title: title, - html: html, - focusConfirm: false, - showCancelButton: true, - backdrop: utools.isDarkColors() ? '#ffffff26' : '#bbbbbb80', - preConfirm: () => { - for (let i = 0; i < inputBoxNumbers; i++) { - result.push(document.getElementById(`inputBox${i}`).value) - } - reslove(result) - } - } - swalOneByOne(options) - }); - }, - - // 显示选项按钮 - showButtonBox: function(buttons, title = '') { - return new Promise((reslove, reject) => { - if (!(buttons instanceof Array)) return reject(new TypeError(`应为 Array, 而非 ${typeof buttons}`)) - utools.setExpendHeight(550) - var html = `` - var buttonBoxNumbers = buttons.length - for (let i = 0; i < buttonBoxNumbers; i++) { - html += `` - } - var options = { - onBeforeOpen: () => { - clickButton = i => { - reslove({ - id: i, - text: buttons[i] - }) - swal.clickConfirm() - } - $(".output").is(":parent") && utools.setExpendHeight(550) || modWindowHeight($('.swal2-popup').outerHeight() + 20) - }, - html: html, - title: title, - backdrop: utools.isDarkColors() ? '#ffffff26' : '#bbbbbb80', - showConfirmButton: false - } - swalOneByOne(options) - }); - }, - - // 显示自动消失的提示框 - showMessageBox: function(title, icon = "success", time = 3000) { - var options = { - icon: icon, - title: title, - toast: true, - position: 'top', - timer: time, - showConfirmButton: false, - // onBeforeOpen: () => { - // setTimeout(() => { Swal.clickConfirm() }, time); - // } - } - swal.fire(options) - }, // 显示选项列表 showSelectList: function(selects, opt = {}) { @@ -204,35 +124,35 @@ quickcommand = { $('#selectBox').data('options', data) $('#selectBox').data('type', opt.optionType) var prefer = { - // data: data, - width: "100%", - dropdownParent: $("#quickselect"), - closeOnSelect: false, - // 支持无限滚动 - ajax: { - transport: (params, success, failure) => { - let cont, pageSize = 50 - let term = (params.data.term || '').toLowerCase() - let page = (params.data.page || 1) - let items = $('#selectBox').data('options') - let results = items.filter(x => { - if (opt.optionType == 'json') cont = x.title - else if (opt.optionType == 'html') cont = x.text.replace(/<[^<>]+>/g, '') - else cont = x.text - return cont.toLowerCase().includes(term) || PinyinMatch.match(cont, term) - }) - let paged = results.slice((page - 1) * pageSize, page * pageSize) - let options = { - results: paged, - pagination: { - more: results.length >= page * pageSize + // data: data, + width: "100%", + dropdownParent: $("#quickselect"), + closeOnSelect: false, + // 支持无限滚动 + ajax: { + transport: (params, success, failure) => { + let cont, pageSize = 50 + let term = (params.data.term || '').toLowerCase() + let page = (params.data.page || 1) + let items = $('#selectBox').data('options') + let results = items.filter(x => { + if (opt.optionType == 'json') cont = x.title + else if (opt.optionType == 'html') cont = x.text.replace(/<[^<>]+>/g, '') + else cont = x.text + return cont.toLowerCase().includes(term) || PinyinMatch.match(cont, term) + }) + let paged = results.slice((page - 1) * pageSize, page * pageSize) + let options = { + results: paged, + pagination: { + more: results.length >= page * pageSize + } } + success(options) } - success(options) - } - }, - } - // 显示html时不转义标签 + }, + } + // 显示html时不转义标签 if (opt.optionType != 'plaintext') prefer.escapeMarkup = markup => markup $('#selectBox').select2(prefer) $('#selectBox').val(null).trigger('change') @@ -244,12 +164,12 @@ quickcommand = { }) modWindowHeight($('.select2-results').outerHeight()) opt.enableSearch && utools.setSubInput(({ - text - }) => { - $("#quickselect .select2-search__field").val(text).trigger('input') - modWindowHeight($('.select2-results').outerHeight()) - }, opt.placeholder) - // 关闭列表 + text + }) => { + $("#quickselect .select2-search__field").val(text).trigger('input') + modWindowHeight($('.select2-results').outerHeight()) + }, opt.placeholder) + // 关闭列表 let closeSelect = () => { $('#selectBox').off('select2:select') utools.removeSubInput() @@ -425,22 +345,22 @@ if (process.platform !== 'linux') quickcommand.runInTerminal = function(cmdline, } let getCommandToLaunchTerminal = (cmdline, dir) => { - let cd = '' - if (utools.isWindows()) { - let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/') - // 直接 existsSync wt.exe 无效 - if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) { - cmdline = cmdline.replace(/"/g, `\\"`) - if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"` - command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"` + let cd = '' + if (utools.isWindows()) { + let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/') + // 直接 existsSync wt.exe 无效 + if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) { + cmdline = cmdline.replace(/"/g, `\\"`) + if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"` + command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"` + } else { + cmdline = cmdline.replace(/"/g, `^"`) + if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&` + command = `${cd} start "" cmd /k "${cmdline}"` + } } else { - cmdline = cmdline.replace(/"/g, `^"`) - if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&` - command = `${cd} start "" cmd /k "${cmdline}"` - } - } else { - cmdline = cmdline.replace(/"/g, `\\"`) - if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&` + cmdline = cmdline.replace(/"/g, `\\"`) + if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&` if (fs.existsSync('/Applications/iTerm.app')) { command = `osascript -e 'tell application "iTerm" create window with default profile @@ -920,4 +840,4 @@ runCodeFile = (cmd, option, terminal, callback) => { // let stderr = err_chunks.join(""); // callback(stdout, stderr) // }) -} +} \ No newline at end of file diff --git a/src/components/quickcommandUI/ButtonBox.vue b/src/components/quickcommandUI/ButtonBox.vue new file mode 100644 index 0000000..1fad269 --- /dev/null +++ b/src/components/quickcommandUI/ButtonBox.vue @@ -0,0 +1,55 @@ + + + diff --git a/src/components/InputBox.vue b/src/components/quickcommandUI/InputBox.vue similarity index 100% rename from src/components/InputBox.vue rename to src/components/quickcommandUI/InputBox.vue diff --git a/src/components/quickcommandUI/TextArea.vue b/src/components/quickcommandUI/TextArea.vue new file mode 100644 index 0000000..59e796c --- /dev/null +++ b/src/components/quickcommandUI/TextArea.vue @@ -0,0 +1,69 @@ +