forked from x/volcanos
add toast.progress
This commit is contained in:
parent
6fd2e0e92e
commit
17d11c16bf
@ -193,11 +193,20 @@ div.toast div.title {
|
|||||||
}
|
}
|
||||||
div.toast div.content {
|
div.toast div.content {
|
||||||
text-align:center;
|
text-align:center;
|
||||||
|
white-space:pre;
|
||||||
}
|
}
|
||||||
div.toast div.duration {
|
div.toast div.duration {
|
||||||
font-size:14px;
|
font-size:14px;
|
||||||
color:gray;
|
color:gray;
|
||||||
}
|
}
|
||||||
|
div.toast div.progress {
|
||||||
|
border:solid 2px green;
|
||||||
|
height:10px;
|
||||||
|
}
|
||||||
|
div.toast div.progress div.current {
|
||||||
|
background:red;
|
||||||
|
height:10px;
|
||||||
|
}
|
||||||
|
|
||||||
div.carte {
|
div.carte {
|
||||||
color:cyan;
|
color:cyan;
|
||||||
|
11
lib/user.js
11
lib/user.js
@ -25,7 +25,7 @@ var user = Volcanos("user", {help: "用户模块",
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
toast: function(can, text, title, duration) {
|
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 width = meta.width||200, height = meta.height||100
|
||||||
|
|
||||||
var ui = can.page.Append(can, document.body, [{view: "toast", style: {
|
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"]},
|
typeof meta.text == "object"? meta.text: {text: [meta.text||"执行成功", "div", "content"]},
|
||||||
{view: ["button"], list: meta.button},
|
{view: ["button"], list: meta.button},
|
||||||
{text: ["", "div", "duration"]},
|
{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..." }
|
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
|
return ui
|
||||||
},
|
},
|
||||||
share: function(can, msg, cmd) {
|
share: function(can, msg, cmd) {
|
||||||
|
@ -22,14 +22,32 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg,
|
|||||||
|
|
||||||
}
|
}
|
||||||
sub.run = function(event, cmds, cb, silent) { var msg = can.request(event)
|
sub.run = function(event, cmds, cb, silent) { var msg = can.request(event)
|
||||||
|
var _action = msg.Option("_action")
|
||||||
can.Conf("active", sub.Option())
|
can.Conf("active", sub.Option())
|
||||||
can.Conf("action", value.name)
|
can.Conf("action", value.name)
|
||||||
can.Conf("current", sub)
|
can.Conf("current", sub)
|
||||||
// 插件回调
|
// 插件回调
|
||||||
return can.run(event, can.onengine[cmds[0]]? cmds: [river, storm, value.action].concat(cmds), function(msg) {
|
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.run(msg._event, ["search", "Footer.onaction.ncmd"])
|
||||||
can.user.toast(can, "执行成功", value.name, 1000)
|
|
||||||
typeof cb == "function" && cb(msg)
|
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)
|
}, silent)
|
||||||
}
|
}
|
||||||
sub._target.oncontextmenu = function(event) {
|
sub._target.oncontextmenu = function(event) {
|
||||||
|
@ -36,7 +36,9 @@ Volcanos("onaction", {help: "控件交互", list: [],
|
|||||||
// 通用回调
|
// 通用回调
|
||||||
if (can.Conf("type") == "button") {
|
if (can.Conf("type") == "button") {
|
||||||
var toast = can.user.toast(can, "执行中...", can.sup._help, 100000)
|
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) {
|
onkeydown: function(event, can) {
|
||||||
|
@ -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, [
|
can.ui = can.page.Append(can, can._target, [
|
||||||
{view: ["content", "div"]}, {view: ["display", "pre"]},
|
{view: ["content", "div"]}, {view: ["display", "pre"]},
|
||||||
])
|
])
|
||||||
|
5
proto.js
5
proto.js
@ -96,6 +96,11 @@ var Volcanos = shy("火山架", {cache: {}, index: 1, order: 1, debug: {
|
|||||||
msg[key] = can.core.List(arguments).slice(1)
|
msg[key] = can.core.List(arguments).slice(1)
|
||||||
return val
|
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 }
|
Copy: function(res) { if (!res) { return msg }
|
||||||
res.result && (msg.result = (msg.result||[]).concat(res.result))
|
res.result && (msg.result = (msg.result||[]).concat(res.result))
|
||||||
res.append && (msg.append = res.append) && res.append.forEach(function(item) {
|
res.append && (msg.append = res.append) && res.append.forEach(function(item) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user