feat: 导入命令增加弹窗选择

This commit is contained in:
fofolee 2020-12-30 12:19:20 +08:00
parent 12b4fad5dc
commit 8bc4c8f766

View File

@ -315,8 +315,8 @@
// 导入默认命令 // 导入默认命令
let importDefaultCommands = () => { let importDefaultCommands = () => {
let defaultCommands = getDefaultCommands() let defaultCommands = getDefaultCommands()
Object.values(defaultCommands).forEach(d => { Object.values(defaultCommands).forEach(async d => {
importCommand(d) await importCommand(d)
}) })
} }
@ -340,17 +340,26 @@
} }
// 导入 // 导入
let importCommand = file => { let importCommand = async file => {
var pushData, clipboardText = clipboardReadText() let options, fileinfo, command, pushData
if (!file) pushData = quickCommandParser(clipboardText) if (file) {
if (!pushData) { options = { type: 'file', argvs: file, readfile: true }
var options = file ? { type: 'file', argvs: file } : { type: 'dialog', argvs: { filters: [{ name: 'json', extensions: ['json'] }] } } fileinfo = getFileInfo(options)
options.readfile = true
var fileinfo = getFileInfo(options)
if (!fileinfo) return if (!fileinfo) return
pushData = quickCommandParser(fileinfo.data) command = fileinfo.data
if (!pushData) return false } else {
let choise = await quickcommand.showButtonBox(['从文件导入', '从剪贴板导入'])
if (choise.id == 0) {
options = { type: 'dialog', argvs: { filters: [{ name: 'json', extensions: ['json'] }] }, readfile: true }
fileinfo = getFileInfo(options)
if (!fileinfo) return
command = fileinfo.data
} else if (choise.id == 1) {
command = clipboardReadText()
}
} }
pushData = quickCommandParser(command)
if (!pushData) return false
// 单个命令导入 // 单个命令导入
if (pushData.single) { if (pushData.single) {
var code = pushData.qc.features.code; var code = pushData.qc.features.code;
@ -988,7 +997,7 @@
}); });
// 底部功能按钮 // 底部功能按钮
$("#options").on('click', '.footBtn', function () { $("#options").on('click', '.footBtn', async function () {
switch ($(this).attr('id')) { switch ($(this).attr('id')) {
case 'viewHelps': utools.createBrowserWindow('./helps/HELP.html', {width: 1280, height: 920}); case 'viewHelps': utools.createBrowserWindow('./helps/HELP.html', {width: 1280, height: 920});
break; break;
@ -998,7 +1007,7 @@
$("#customize").animate({ top: '0px' }); $("#customize").animate({ top: '0px' });
break; break;
case 'import': case 'import':
var success = importCommand() var success = await importCommand()
if (success) { if (success) {
if (success instanceof Object) locateToCode(success.tags, success.code) if (success instanceof Object) locateToCode(success.tags, success.code)
else showOptions() else showOptions()
@ -1376,8 +1385,8 @@
utools.setExpendHeight(600) utools.setExpendHeight(600)
} }
$("#out").on('click', '#importSharedQc', function () { $("#out").on('click', '#importSharedQc', async function () {
importCommand() ? quickcommand.showMessageBox("导入成功") : quickcommand.showMessageBox("导入失败,格式错误", "error") await importCommand() ? quickcommand.showMessageBox("导入成功") : quickcommand.showMessageBox("导入失败,格式错误", "error")
showOptions() showOptions()
utools.setExpendHeight(600) utools.setExpendHeight(600)
$('#out').empty() $('#out').empty()