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