From 54af1c86981da6b7194ed7621fed75475b6b71cc Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 2 May 2021 13:04:23 +0800 Subject: [PATCH] opt daemon --- frame.js | 74 +++++++++++++++++++++++++++++++++++++++---- lib/base.js | 2 +- lib/misc.js | 4 +-- lib/user.js | 10 +++--- panel/Action.js | 4 +-- panel/Header.js | 20 +++++++++--- panel/River.js | 56 +++++++++++++++++++++----------- plugin/input.js | 9 +----- plugin/state.js | 14 ++++++++ plugin/story/spide.js | 1 - plugin/table.js | 4 +-- proto.js | 2 +- 12 files changed, 147 insertions(+), 53 deletions(-) diff --git a/frame.js b/frame.js index 06c2857d..4114c3a1 100644 --- a/frame.js +++ b/frame.js @@ -13,7 +13,7 @@ Volcanos("onengine", {help: "解析引擎", list: [], _init: function(can, meta, var panel = can[meta.main.name], msg = can.request() panel.onmotion._init(panel, target), panel.onkeypop._init(panel, target) panel.onaction._init(panel, msg, [], cb, panel._target) - }) + }), can.ondaemon._init(can) }, search: function(event, can, msg, panel, cmds, cb) { var sub, mod = can, fun = can, key = ""; can.core.List(cmds[1].split("."), function(value) { @@ -33,7 +33,7 @@ Volcanos("onengine", {help: "解析引擎", list: [], _init: function(can, meta, remote: function(event, can, msg, panel, cmds, cb) { delete(msg._handle), delete(msg._toast) if (panel.onengine.engine(event, can, msg, panel, cmds, cb)) { return } - can.misc.Runs(event, can, {names: panel._name}, cmds, cb) + can.misc.Runs(event, can, {names: panel._name, daemon: can._daemon}, cmds, cb) panel.run(event, ["search", "Footer.onimport.ncmd"]) }, engine: function(event, can, msg, panel, cmds, cb) { return false }, listen: shy("事件回调", {}, [], function(can, name, cb) { @@ -166,6 +166,30 @@ Volcanos("onengine", {help: "解析引擎", list: [], _init: function(can, meta, }}, }, }) +Volcanos("ondaemon", {help: "解析引擎", list: [], _init: function(can) { + can.misc.WSS(can, {type: "chrome", name: can.user.Search(can, "daemon")||""}, function(event, msg, cmd, arg) { if (!msg) { return } + if (can.base.isFunc(can.ondaemon[cmd])) { + can.core.CallFunc(can.ondaemon[cmd], { + "can": can, "msg": msg, + "cmd": cmd, "arg": arg, + "cb": function() { msg.Reply() }, + }) + } else { + can.onengine.search({}, can, msg, can, ["search", cmd].concat(arg), function() { + msg.Reply() + }) + } + }) + }, + toast: function(can, msg, arg) { arg[0] = can + can._toast && can._toast.Close() + can._toast = can.core.CallFunc(can.user.toast, arg) + }, + pwd: function(can, msg, arg) { + can.base.Log(msg) + can._daemon = arg[0] + }, +}) Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, list, cb, target, field) { meta.name = meta.name || "", meta.name = meta.name.split(" ")[0].split(".").pop() field = field || can.onappend.field(can, meta.type, meta, target).first @@ -317,7 +341,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, return can.run(event, cmds, function(msg) { var sub = can.core.Value(can, "_outputs.-1") if (can.core.CallFunc([sub, "onimport._process"], [sub, msg, cmds, cb])) { return } if (can.core.CallFunc([can, "onimport._process"], [can, msg, cmds, cb])) { return } - can.base.isFunc(cb) && cb(msg) + if (can.base.isFunc(cb) && cb(msg)) { return } if (silent) { return } var display = msg.Option("_display") || meta.display || meta.feature.display || "/plugin/table.js" @@ -504,14 +528,50 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, meta.height = meta.height||can.Conf("height") meta.type = meta.type||"story" + can.page.Modify(can, can._output, { + onmouseover: function(event) { + Volcanos.meta.data.menu && can.page.Remove(can, Volcanos.meta.data.menu.first) + }, + }) + can.onappend._init(can, meta, ["/plugin/state.js"], function(sub) { meta.type == "story" && sub.page.Remove(sub, sub._legend) can.base.isFunc(cb) && cb(sub, meta) + can.page.Modify(sub, sub._legend, { + onmouseenter: function(event) { + Volcanos.meta.data.menu && can.page.Remove(can, Volcanos.meta.data.menu.first) + Volcanos.meta.data.menu = can.user.carte(event, can, { + "保存参数": function(event) { + var msg = can.request(event, {river: can.Conf("river"), storm: can.Conf("storm"), id: meta.id}) + can.run(event, ["action", "modify", "arg", JSON.stringify(sub.Pack([], true))], function(msg) { + can.user.toast(can, "保存成功") + }) + }, + "清空参数": function(event) { + can.page.Select(can, sub._option, '.args', function(item) { return item.value = "" }) + }, + "共享工具": function(event) { + can.user.input(event, can, ["name"], function(event, button, data, list, args) { + can.user.share(can, can.request(event), ["action", "share", "type", "field", + "name", list[0], "text", JSON.stringify(sub.Pack([], true)), + "river", meta.ctx||meta.key||"", "storm", meta.index||meta.cmd||meta.name]) + }) + }, + "刷新结果": function(event) { + sub.onappend._output(sub, meta, {}, sub.Pack([], true)) + }, + "清空结果": function(event) { + sub.onmotion.clear(sub, sub._output) + }, + }, ["保存参数", "清空参数", "共享工具", "刷新结果", "清空结果"]) + + can.page.Modify(can, Volcanos.meta.data.menu.first, {style: { + left: event.target.offsetLeft+can.run(event, ["search", "River.onexport.width"]), + top: event.target.offsetTop-can._output.scrollTop+event.target.offsetHeight+can.run(event, ["search", "Header.onexport.height"]), + }}) + }, + }) sub._legend.onclick = function(event) { - var list = can.page.Select(can, sub._option, '.args', function(item) { return item.value||"" }) - can.user.share(can, can.request(event), ["action", "share", "type", "field", - "text", JSON.stringify(list), - "river", meta.ctx||meta.key||"", "storm", meta.index||meta.cmd||meta.name]) } }, target||can._output) }, diff --git a/lib/base.js b/lib/base.js index 2fc2c985..40c0c057 100644 --- a/lib/base.js +++ b/lib/base.js @@ -48,7 +48,7 @@ Volcanos("base", {help: "数据类型", } return res.join("&") }, - URLMerge: function(url) { var args = {} + MergeURL: function(url) { var args = {} var arg = url.split("?")[1]||"" arg && arg.split("&").forEach(function(item) { var ls = item.split("=") diff --git a/lib/misc.js b/lib/misc.js index dececbec..5b2b0e3f 100644 --- a/lib/misc.js +++ b/lib/misc.js @@ -126,7 +126,7 @@ Volcanos("misc", {help: "工具模块", Message: function(event, can) { var msg }) var path = (can.Conf("iceberg")||"/chat/")+dataset.names.toLowerCase() - can.misc.POST(can, msg, path+"?="+(msg._can.sup||msg._can)._name, form, function(msg) { + can.misc.POST(can, msg, can.base.MergeURL(path, "", (msg._can.sup||msg._can)._name, "_daemon", dataset.daemon), form, function(msg) { typeof cb == "function" && cb(msg) }) }), @@ -134,7 +134,7 @@ Volcanos("misc", {help: "工具模块", Message: function(event, can) { var msg var url = location.protocol.replace("http", "ws")+"//"+location.host+"/space/" if (url.indexOf("chrome") == 0) { url = "ws://localhost:9020/space/" } - var socket = new WebSocket(can.base.URLMerge(url, args)) + var socket = new WebSocket(can.base.MergeURL(url, args)) socket.onclose = function() { can.base.Log("wss", "close", args) typeof onclose == "function"? onclose(socket): can.core.Timer(1000, function() { can.misc.WSS(can, args, cb, onopen, onerror, onclose) diff --git a/lib/user.js b/lib/user.js index a6eed6f6..af23a662 100644 --- a/lib/user.js +++ b/lib/user.js @@ -72,8 +72,8 @@ Volcanos("user", {help: "用户模块", agent: { {text: [meta.title||"", "div", "title"]}, typeof meta.content == "object"? meta.content: {text: [meta.content||"执行成功", "div", "content"]}, {view: "button"}, - {view: "duration"}, meta.progress > 0 && {view: "progress", style: {width: width}, list: [ - {view: "current", style: {width: meta.progress/100*width}}, + {view: "duration"}, meta.progress != undefined && {view: "progress", style: {width: width}, list: [ + {view: "current", style: {width: (meta.progress||0)/100*width}}, ]}, ] }]); can.onmotion.story(can, ui.first) @@ -86,7 +86,7 @@ Volcanos("user", {help: "用户模块", agent: { close: function(event) { ui.Close() }, }) - can.run(can.request({}, { + can.run && can.run(can.request({}, { title: meta.title, content: meta.content, time: can.base.Time(), fileline: can.base.FileLine(2, 2), })._event, ["search", "Footer.onimport.toast"], null, true) @@ -269,8 +269,8 @@ Volcanos("user", {help: "用户模块", agent: { action.upload.click() return ui }, - download: function(can, path) { - var a = can.page.Append(can, document.body, [{type: "a", href: path, download: path.split("/").pop()}]).first + download: function(can, path, name) { + var a = can.page.Append(can, document.body, [{type: "a", href: path, download: name||path.split("/").pop()}]).first a.click() can.page.Remove(can, a) }, diff --git a/panel/Action.js b/panel/Action.js index cd65efdc..81accba8 100644 --- a/panel/Action.js +++ b/panel/Action.js @@ -116,7 +116,7 @@ Volcanos("onaction", {help: "交互操作", list: [], _init: function(can, msg, "自由布局": "free", } - key = trans[key]||key, can.Conf(LAYOUT, key) + key = trans[key]||key, can.Conf(can._LAYOUT, key) can.page.Modify(can, can._action, {className: "action "+key}) can.page.Modify(can, can._output, {className: "output "+key}) @@ -158,7 +158,7 @@ Volcanos("onexport", {help: "导出数据", list: [], msg.Option(can._WIDTH, can._target.offsetWidth) msg.Option(can._HEIGHT, can._target.offsetHeight) }, - layout: function(can, msg) { return can.Conf(LAYOUT) }, + layout: function(can, msg) { return can.Conf(can._LAYOUT) }, plugin: function(can, msg, word) { var fields = (msg.Option(can._FIELDS)||"ctx,cmd,type,name,text").split(",") can.page.Select(can, can._output, "fieldset.plugin>legend", function(item) { diff --git a/panel/Header.js b/panel/Header.js index 01965367..bab9811b 100644 --- a/panel/Header.js +++ b/panel/Header.js @@ -28,7 +28,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can.onimport._state(can, msg, target) can.onimport._search(can, msg, target) can.onimport._background(can, msg, target) - // can.onimport._daemon(can, msg, target) + can.onimport._daemon(can, msg, target) can.onimport._agent(can, msg, target) can.onimport._menu(can, msg, target) @@ -73,13 +73,22 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, !can.user.isLocalFile && can.page.Modify(can, "div.output div.state.avatar>img", {src: can.Conf(can._AVATAR, msg.Option(can._AVATAR))}) }, _background: function(can, msg) { - !can.user.isLocalFile && can.onlayout.background(can, msg.Option(can._BACKGROUND), document.body) + if (can.user.isLocalFile) { return } + if (can.user.isExtension) { return } + can.onlayout.background(can, msg.Option(can._BACKGROUND), document.body) }, _daemon: function(can, msg, target) { can.misc.WSS(can, {type: "chrome", name: can.user.Search(can, "daemon")||""}, function(event, msg, cmd, arg) { if (!msg) { return } - can.run(event, [can._SEARCH].concat(msg["detail"]||[]), function(msg) { - msg.Reply() - }) + switch (cmd) { + case "pwd": + can.base.Log(msg) + msg.Reply() + break + default: + can.run(event, [can._SEARCH].concat(msg["detail"]||[]), function(msg) { + msg.Reply() + }) + } }) }, _agent: function(can, msg, target) { @@ -233,6 +242,7 @@ Volcanos("onaction", {help: "交互数据", list: [], _init: function(can, msg, var toast = can.user.toast(can, "打包中...", "webpack", 1000000) can.run(event, ["webpack"], function(msg) { toast.Close(), can.user.toast(can, "打包成功", "webpack") + can.user.download(can, "/share/local/"+msg.Result(), name+".html") }) }) }, diff --git a/panel/River.js b/panel/River.js index 5db48cdf..0cee6fcc 100644 --- a/panel/River.js +++ b/panel/River.js @@ -1,4 +1,17 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, list, cb, target) { + can.base.isFunc(cb) && cb(msg) + can.onmotion.clear(can), can.sublist = {} + if (msg.Option("sess.river") == "_share") { return can.onmotion.hide(can) } + + can.onimport._main(can, msg) + can.onimport._menu(can, msg) + + var select; msg.Table(function(value, index, array) { + var item = can.onimport._river(can, value) + if (index == 0 || [value.hash, value.name].indexOf(can._main_river) > -1) { select = item } + }), select && select.click() + }, + _main: function(can, msg) { can._main_river = "project", can._main_storm = "studio" if (can.user.isExtension) { can._main_river = "product", can._main_storm = "chrome" } if (can.user.isMobile) { can._main_river = "product", can._main_storm = "office" } @@ -7,26 +20,8 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, can._main_river = can.user.Search(can, can._RIVER) || msg.Option("sess.river") || Volcanos.meta.args.river || can._main_river can._main_storm = can.user.Search(can, can._STORM) || msg.Option("sess.storm") || Volcanos.meta.args.storm || can._main_storm can._main_title = can.user.Search(can, can._TITLE) || msg.Option("sess.title") || Volcanos.meta.args.title || can.user.Search(can, "pod") || can._main_title - - can.base.isFunc(cb) && cb(msg) - can.onmotion.clear(can), can.sublist = {} - if (msg.Option("sess.river") == "_share") { return can.onmotion.hide(can) } - can.onimport._menu(can) - var select; msg.Table(function(value, index, array) { - var view = can.onappend.item(can, "item", value, function(event, item) { - // 左键选中 - can.onaction.storm(event, can, value.hash) - }, function(event) { - // 右键菜单 - can.user.carte(event, can, can.ondetail, can.ondetail.list, function(ev, item, meta) { - can.ondetail[item](event, can, item, value.hash) - }, {style: {left: can._target.offsetWidth}}) - }, target) - - if (index == 0 || [value.hash, value.name].indexOf(can._main_river) > -1) { select = view } - }), select && select.click() }, - _menu: function(can) { + _menu: function(can, msg) { can.run({}, [can._SEARCH, "Header.onimport.menu", can._RIVER, ["添加", "创建群组", "添加应用", "添加工具", "添加用户", "添加设备", "创建空间"], !can.user.isMobile && ["访问", "内部系统", "访问应用", "访问工具", "访问用户", "访问设备", "工作任务"], @@ -34,6 +29,29 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, ], function(event, item) { can.core.CallFunc([can.ondetail, item], [event, can, item, can.Conf(can._RIVER), can.Conf(can._STORM)]) }) + + can.page.Modify(can, can._output, {onmouseover: function(event) { + can.menu && can.page.Remove(can, can.menu.first) + }}) + }, + + _river: function(can, value) { + var item = can.onappend.item(can, "item", value, function(event, item) { + // 左键选中 + can.onaction.storm(event, can, value.hash) + }, function(event) { + // 右键菜单 + can.user.carte(event, can, can.ondetail, can.ondetail.list, function(ev, item, meta) { + can.ondetail[item](event, can, item, value.hash) + }, {style: {left: can._target.offsetWidth}}) + }, can._output) + + can.page.Modify(can, item, {onmouseenter: function(event) { + can.menu = can.user.carte(event, can, can.ondetail, can.ondetail.list, function(ev, item, meta) { + can.ondetail[item](event, can, item, value.hash) + }, {style: {left: can._target.offsetWidth}}) + }}) + return item }, }) Volcanos("onengine", {help: "解析引擎", list: [], engine: function(event, can, msg, panel, cmds, cb) { diff --git a/plugin/input.js b/plugin/input.js index e3a3ac34..9c890e28 100644 --- a/plugin/input.js +++ b/plugin/input.js @@ -17,14 +17,7 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, meta, "执行": function(event, can) { can.run(event) }, "刷新": function(event, can) { can.run(event) }, "查看": function(event, can) { can.run(event) }, - "返回": function(event, can) { - can.sup._history.pop(); for (var his = can.sup._history.pop(); his; his = can.sup._history.pop()) { - if (his[0] == "action") { continue } - can.page.Select(can, can._option, "textarea.args,input.args,select.args", function(item, index) { - item.value = his[index] || "" - }), can.run(event); break - } - }, + "返回": function(event, can) { can.sup.onimport._back(can.sup) }, onchange: function(event, can) { if (can.Conf("type") == "select") { can.run(event) } diff --git a/plugin/state.js b/plugin/state.js index 2705640a..5b3fd6ac 100644 --- a/plugin/state.js +++ b/plugin/state.js @@ -3,6 +3,20 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, conf, _process: function(can, msg, cmds, cb, silent) { return can.core.CallFunc([can.onimport, msg.Option("_process")], [can, msg, cmds, cb, silent]) }, + _hold: function(can, msg) { + return true + }, + _back: function(can) { + can._history.pop(); for (var his = can._history.pop(); his; his = can._history.pop()) { + if (his[0] == "action") { continue } + can.page.Select(can, can._option, "textarea.args,input.args,select.args", function(item, index) { + item.value = his[index]||"" + }), can.onappend._output(can, can.Conf(), {}, can.Pack([])) + break + } + return true + }, + _progress: function(can, msg, cmds, cb, silent) { var size = msg.Append("size") || msg.Append("count") if (size != "" && size == msg.Append("total")) { return true } diff --git a/plugin/story/spide.js b/plugin/story/spide.js index 93ec822b..558ead75 100644 --- a/plugin/story/spide.js +++ b/plugin/story/spide.js @@ -62,7 +62,6 @@ Volcanos("onaction", {help: "用户操作", list: ["编辑", ["view", "横向", can.draw.svg.Val("height", can._tree[""].height*can.size+2*can.margin) can.width = 0, can.onaction._draw(can, can._tree[""], can.margin, can.margin) can.draw.svg.Val("width", can.width+can.margin) - can.base.Log(can) }, "纵向": function(event, can) { can.onmotion.clear(can, can.draw.svg) diff --git a/plugin/table.js b/plugin/table.js index 80d9666e..04d00464 100644 --- a/plugin/table.js +++ b/plugin/table.js @@ -31,9 +31,9 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, }, _process: function(can, msg) { - var cb = can.onimport[msg.Option("_process")] - return can.base.isFunc(cb) && cb(can, msg) + return can.core.CallFunc([can.onimport, msg.Option("_process")], [can, msg]) }, + _follow: function(can, msg) { if (msg.Option("cache.status") == "stop") { return can.user.toast(can, msg.Option("cache.action")+" done!")} diff --git a/proto.js b/proto.js index 3842585c..35961a64 100644 --- a/proto.js +++ b/proto.js @@ -11,7 +11,7 @@ function shy(help, meta, list, cb) { cb.list = next("object") || [] return cb }; var _can_name = "" -var Volcanos = shy("火山架", {args: {}, pack: {}, libs: [], cache: {}}, [], function(name, can, libs, cb) { +var Volcanos = shy("火山架", {args: {}, data: {}, pack: {}, libs: [], cache: {}}, [], function(name, can, libs, cb) { var meta = arguments.callee.meta, list = arguments.callee.list if (typeof name == "object") { var Config = name; _can_name = "" meta.libs = Config.libs, meta.volcano = Config.volcano