mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-07-01 21:42:45 +08:00
由回调改为promise
This commit is contained in:
parent
c21fb57031
commit
427b396c84
@ -82,14 +82,10 @@ quickcommand = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 显示输入框
|
// 显示输入框
|
||||||
showInputBox: function (callback, placeHolders) {
|
showInputBox: function (placeHolders) {
|
||||||
let helps = `正确用法:
|
return new Promise((reslove, reject) => {
|
||||||
quickcommand.showInputBox(yourinput => {
|
|
||||||
//do something...
|
|
||||||
}, [placeholder of input1, placeholder of input2...])`
|
|
||||||
if (!(callback instanceof Function)) throw helps
|
|
||||||
placeHolders || (placeHolders = [""])
|
placeHolders || (placeHolders = [""])
|
||||||
if (!(placeHolders instanceof Array)) throw helps
|
if (!(placeHolders instanceof Array)) reject("参数类型错误:应为数组")
|
||||||
utools.setExpendHeight(600)
|
utools.setExpendHeight(600)
|
||||||
var html = ""
|
var html = ""
|
||||||
var inputBoxNumbers = placeHolders.length
|
var inputBoxNumbers = placeHolders.length
|
||||||
@ -110,22 +106,17 @@ quickcommand = {
|
|||||||
for (let i = 0; i < inputBoxNumbers; i++) {
|
for (let i = 0; i < inputBoxNumbers; i++) {
|
||||||
result.push(document.getElementById(`inputBox${i}`).value)
|
result.push(document.getElementById(`inputBox${i}`).value)
|
||||||
}
|
}
|
||||||
callback(result)
|
reslove(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
swalOneByOne(options)
|
swalOneByOne(options)
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 显示选项按钮
|
// 显示选项按钮
|
||||||
showButtonBox: function (callback, buttons) {
|
showButtonBox: function (buttons) {
|
||||||
let helps = `正确用法:
|
return new Promise((reslove, reject) => {
|
||||||
quickcommand.showButtonBox(yourchoise => {
|
if (!(buttons instanceof Array)) reject("参数类型错误:应为数组")
|
||||||
var index = choise.index
|
|
||||||
var text = choise.text
|
|
||||||
//do something...
|
|
||||||
}, [button1, button2...])`
|
|
||||||
if (!(callback instanceof Function)) throw helps
|
|
||||||
if (!(buttons instanceof Array)) throw helps
|
|
||||||
utools.setExpendHeight(600)
|
utools.setExpendHeight(600)
|
||||||
var html = ``
|
var html = ``
|
||||||
var buttonBoxNumbers = buttons.length
|
var buttonBoxNumbers = buttons.length
|
||||||
@ -135,8 +126,8 @@ quickcommand = {
|
|||||||
var options = {
|
var options = {
|
||||||
onBeforeOpen: () => {
|
onBeforeOpen: () => {
|
||||||
clickButton = i => {
|
clickButton = i => {
|
||||||
callback({ index: i, text: buttons[i] })
|
setTimeout(() => { swal.clickConfirm() }, 50);
|
||||||
swal.clickConfirm()
|
reslove({ id: i, text: buttons[i] })
|
||||||
}
|
}
|
||||||
$(".output").is(":parent") && utools.setExpendHeight(600) || modWindowHeight($('.swal2-popup').outerHeight() + 20)
|
$(".output").is(":parent") && utools.setExpendHeight(600) || modWindowHeight($('.swal2-popup').outerHeight() + 20)
|
||||||
},
|
},
|
||||||
@ -145,6 +136,7 @@ quickcommand = {
|
|||||||
showConfirmButton: false
|
showConfirmButton: false
|
||||||
}
|
}
|
||||||
swalOneByOne(options)
|
swalOneByOne(options)
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 显示自动消失的提示框
|
// 显示自动消失的提示框
|
||||||
@ -166,15 +158,9 @@ quickcommand = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 显示选项列表
|
// 显示选项列表
|
||||||
showSelectList: function (callback, selects, opt = {}) {
|
showSelectList: function (selects, opt = {}) {
|
||||||
let helps = `正确用法:
|
return new Promise((reslove, reject) => {
|
||||||
quickcommand.showSelectList(choise => {
|
if (!(selects instanceof Array)) reject("参数类型错误:应为数组")
|
||||||
var index = choise.index
|
|
||||||
var text = choise.text
|
|
||||||
//do something...
|
|
||||||
}, [option1, option2...], { placeholder, optionType, enableSearch, closeOnSelect })`
|
|
||||||
if (!(callback instanceof Function)) throw helps
|
|
||||||
if (!(selects instanceof Array)) throw helps
|
|
||||||
opt.optionType || (opt.optionType = 'plaintext')
|
opt.optionType || (opt.optionType = 'plaintext')
|
||||||
typeof opt.placeholder == 'undefined' && (opt.placeholder = "搜索,支持拼音")
|
typeof opt.placeholder == 'undefined' && (opt.placeholder = "搜索,支持拼音")
|
||||||
typeof opt.enableSearch == 'undefined' && (opt.enableSearch = true)
|
typeof opt.enableSearch == 'undefined' && (opt.enableSearch = true)
|
||||||
@ -237,13 +223,15 @@ quickcommand = {
|
|||||||
$('#selectBox').on('select2:select', function (e) {
|
$('#selectBox').on('select2:select', function (e) {
|
||||||
let result = $('#selectBox').data('options')[$(this).val()]
|
let result = $('#selectBox').data('options')[$(this).val()]
|
||||||
delete result.selected
|
delete result.selected
|
||||||
callback(result)
|
reslove(result)
|
||||||
if (opt.closeOnSelect) {
|
if (opt.closeOnSelect) {
|
||||||
$('#selectBox').off('select2:select')
|
$('#selectBox').off('select2:select')
|
||||||
utools.removeSubInput()
|
utools.removeSubInput()
|
||||||
$("#quickselect").remove()
|
$("#quickselect").remove()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 更新选项列表
|
// 更新选项列表
|
||||||
@ -273,12 +261,8 @@ quickcommand = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 显示文本输入框
|
// 显示文本输入框
|
||||||
showTextAera: function (callback, placeholder = "") {
|
showTextAera: function (placeholder = "") {
|
||||||
let helps = `正确用法:
|
return new Promise((reslove, reject) => {
|
||||||
quickcommand.showTextAera(text => {
|
|
||||||
//do something...
|
|
||||||
}, placeholder)`
|
|
||||||
if (!(callback instanceof Function)) throw helps
|
|
||||||
utools.setExpendHeight(600)
|
utools.setExpendHeight(600)
|
||||||
var html = `
|
var html = `
|
||||||
<div id="quicktextarea">
|
<div id="quicktextarea">
|
||||||
@ -290,8 +274,9 @@ quickcommand = {
|
|||||||
$("#quicktextarea > button").click(function () {
|
$("#quicktextarea > button").click(function () {
|
||||||
$("#quicktextarea").addClass("fadeOutDownWindow")
|
$("#quicktextarea").addClass("fadeOutDownWindow")
|
||||||
setTimeout(() => { $("#quicktextarea").remove() }, 300);
|
setTimeout(() => { $("#quicktextarea").remove() }, 300);
|
||||||
callback($("#quicktextarea > textarea").val())
|
reslove($("#quicktextarea > textarea").val())
|
||||||
})
|
})
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// 关闭进程
|
// 关闭进程
|
||||||
|
Loading…
x
Reference in New Issue
Block a user