diff --git a/index.css b/index.css index db7a1a65..c18e6ae2 100644 --- a/index.css +++ b/index.css @@ -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; diff --git a/lib/user.js b/lib/user.js index 9cdf1c08..86bfa7c6 100644 --- a/lib/user.js +++ b/lib/user.js @@ -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) { diff --git a/pane/Action.js b/pane/Action.js index d7e467aa..63da5f6e 100644 --- a/pane/Action.js +++ b/pane/Action.js @@ -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) { diff --git a/plugin/input.js b/plugin/input.js index 0cf872d3..aea4ddc0 100644 --- a/plugin/input.js +++ b/plugin/input.js @@ -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) { diff --git a/plugin/table.js b/plugin/table.js index 17cee048..7802734e 100644 --- a/plugin/table.js +++ b/plugin/table.js @@ -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"]}, ]) diff --git a/proto.js b/proto.js index 44dc6ecd..41052511 100644 --- a/proto.js +++ b/proto.js @@ -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) {