1
0
mirror of https://shylinux.com/x/volcanos synced 2025-04-25 16:58:06 +08:00

add toast.progress

This commit is contained in:
shylinux 2020-08-24 23:04:24 +08:00
parent 6fd2e0e92e
commit 17d11c16bf
6 changed files with 56 additions and 7 deletions

View File

@ -193,11 +193,20 @@ div.toast div.title {
}
div.toast div.content {
text-align:center;
white-space:pre;
}
div.toast div.duration {
font-size:14px;
color:gray;
}
div.toast div.progress {
border:solid 2px green;
height:10px;
}
div.toast div.progress div.current {
background:red;
height:10px;
}
div.carte {
color:cyan;

View File

@ -25,7 +25,7 @@ var user = Volcanos("user", {help: "用户模块",
})
},
toast: function(can, text, title, duration) {
var meta = typeof text == "object"? text: {text: text, title: title||can._help, duration: duration}
var meta = typeof text == "object"? text: {text: text, title: title||can._help, duration: duration, progress: 0}
var width = meta.width||200, height = meta.height||100
var ui = can.page.Append(can, document.body, [{view: "toast", style: {
@ -35,13 +35,16 @@ var user = Volcanos("user", {help: "用户模块",
typeof meta.text == "object"? meta.text: {text: [meta.text||"执行成功", "div", "content"]},
{view: ["button"], list: meta.button},
{text: ["", "div", "duration"]},
meta.progress > 0 && {text: ["", "div", "progress"], style: {width: width}, list: [
{text: ["", "div", "current"], style: {width: meta.progress/100*width}},
]},
]}])
can.Timer({value: 100, length: (meta.duration||1000)/100}, function(event, interval, index) {
var timer = can.Timer({value: 100, length: (meta.duration||1000)/100}, function(event, interval, index) {
if (index > 20) { ui.duration.innerHTML = parseInt(index/10)+"."+(index%10)+"s..." }
}, function() { can.page.Remove(can, ui.first) })
}, function() { can.page.Remove(can, ui.first), timer.stop = true })
ui.Close = function() { can.page.Remove(can, ui.first) }
ui.Close = function() { can.page.Remove(can, ui.first), timer.stop = true }
return ui
},
share: function(can, msg, cmd) {

View File

@ -22,14 +22,32 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg,
}
sub.run = function(event, cmds, cb, silent) { var msg = can.request(event)
var _action = msg.Option("_action")
can.Conf("active", sub.Option())
can.Conf("action", value.name)
can.Conf("current", sub)
// 插件回调
return can.run(event, can.onengine[cmds[0]]? cmds: [river, storm, value.action].concat(cmds), function(msg) {
can.run(msg._event, ["search", "Footer.onaction.ncmd"])
can.user.toast(can, "执行成功", value.name, 1000)
typeof cb == "function" && cb(msg)
if (msg.Option("_progress")) {
if (msg.Append("count") != msg.Append("total")) {
can.user.toast(can, {
text: "执行进度: "+msg.Append("count")+"/"+msg.Append("total")+"\n"+msg.Append("name"),
title: value.name,
duration: 1100,
progress: parseInt(msg.Append("count"))*100/parseInt(msg.Append("total")),
})
can.Timer(1000, function() {
var res = can.request({})
res.Option("_action", _action)
res.Option("_progress", msg.Option("_progress"))
sub.run(res._event, cmds, cb, silent)
})
return
}
}
can.user.toast(can, "执行成功", value.name, 400)
}, silent)
}
sub._target.oncontextmenu = function(event) {

View File

@ -36,7 +36,9 @@ Volcanos("onaction", {help: "控件交互", list: [],
// 通用回调
if (can.Conf("type") == "button") {
var toast = can.user.toast(can, "执行中...", can.sup._help, 100000)
can.run(event, [], function(msg) { toast.Close() })
can.run(event, [], function(msg) {
toast.Close()
})
}
},
onkeydown: function(event, can) {

View File

@ -1,4 +1,16 @@
Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { can._output.innerHTML = "";
Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) {
if (msg.Option("_progress")) {
can.page.Select(can, can._output, "td", function(td) {
if (td.innerText == msg.Option("name")) {
can.page.Modify(can, td, {style: {
"background-color": "green",
}})
}
})
return
}
can._output.innerHTML = ""
can.ui = can.page.Append(can, can._target, [
{view: ["content", "div"]}, {view: ["display", "pre"]},
])

View File

@ -96,6 +96,11 @@ var Volcanos = shy("火山架", {cache: {}, index: 1, order: 1, debug: {
msg[key] = can.core.List(arguments).slice(1)
return val
},
Append: function(key, val) {
if (typeof key == "object") { can.core.Item(key, msg.Append) }
if (val == undefined) { return msg && msg[key] && msg[key][0] || msg._msg && msg._msg.Append(key) || "" }
return val
},
Copy: function(res) { if (!res) { return msg }
res.result && (msg.result = (msg.result||[]).concat(res.result))
res.append && (msg.append = res.append) && res.append.forEach(function(item) {