From 6c878dc7dc3b17f062e7991309cc66af2bae7291 Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 12 Dec 2019 01:50:01 +0800 Subject: [PATCH] opt favor --- frame.js | 6 ++-- page/chat.js | 2 +- pane/Action.js | 6 ++-- pane/Favor.js | 81 +++++++++++++++++++++++++++++++------------------- proto.js | 3 +- 5 files changed, 60 insertions(+), 38 deletions(-) diff --git a/frame.js b/frame.js index 309f8d42..a0930a13 100644 --- a/frame.js +++ b/frame.js @@ -58,7 +58,7 @@ var can = Volcanos("chat", { typeof cb == "function" && cb(event, pane, {width: width, height: height}, "size", pane.output) }, - Show: function(width, height) {field.style.display = "block"; + Show: function(width, height, offset) {field.style.display = "block"; if (width < 0) {field.style.left = -width / 2 + "px"; field.style.width = (document.body.offsetWidth + width) + "px"; } @@ -66,9 +66,9 @@ var can = Volcanos("chat", { field.style.left = (document.body.offsetWidth - width) / 2 + "px"; } if (height > 0) {field.style.height = height + "px"; - field.style.top = (document.body.offsetHeight - height) / 2 + "px"; + field.style.top = (document.body.offsetHeight - height) / 2 + (offset||0) + "px"; } - if (height < 0) {field.style.top = -height / 2 + "px"; + if (height < 0) {field.style.top = -height / 2 + (offset||0) + "px"; field.style.height = (document.body.offsetHeight + height) + "px"; } return field; diff --git a/page/chat.js b/page/chat.js index 3905a15b..2a3c00be 100644 --- a/page/chat.js +++ b/page/chat.js @@ -13,7 +13,7 @@ Volcanos("onaction", {help: "组件交互", list: [], switch (event.key) { case " ": if (can.Favor) { - can.page.Select(can, can.Favor.Show(400, 200), "input.cmd", function(item) { + can.page.Select(can, can.Favor.Show(), "input.cmd", function(item) { item.focus() }) } diff --git a/pane/Action.js b/pane/Action.js index 2dce262c..1eaa2317 100644 --- a/pane/Action.js +++ b/pane/Action.js @@ -38,9 +38,9 @@ Volcanos("onimport", {help: "导入数据", list: [], item.value = value }) }, - favor: function(event, can, msg, cmd, output) { - var p = can[msg.detail[0]]; - p.Select && p.Select(event, null, true) && (msg._hand = true) + favor: function(event, can, msg, cmd, output) {cmd = msg.detail[0]; + var p = can[cmd]; if (p && p.Select) {p.Select(event, null, true); return msg._hand = true} + var cb = can.onaction[cmd]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg._hand = true} }, }) Volcanos("onaction", {help: "组件交互", list: [["layout", "工作", "办公", "聊天"], "清屏", "刷新", "串行", "并行", diff --git a/pane/Favor.js b/pane/Favor.js index 77cc4511..6e8d8e10 100644 --- a/pane/Favor.js +++ b/pane/Favor.js @@ -1,47 +1,68 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, conf, output, action, option, field) { + can.Show(400, 100, 100), can.Hide(); can.page.Append(can, option, [{input: ["cmd", function(event) { - function run(cmd) { - var msg = can.Event(event); - msg.detail = [cmd] - msg._time = can.base.Time() - msg._source = can - can.Export(event, msg, "favor") - if (msg._hand) { - event.target.value = "" + can.page.oninput(event, can) + + function run(cmds) {cmds = cmds.split(" ") + var cmd = cmds[0] + + var msg = can.Event(event, {detail: cmds}); + var cb = can.onexport[cmd] + if (typeof cb == "function") { + cb(event, can, msg, cmds, output); + } else { + can.Export(event, msg, "favor") + } + + if (!msg._hand) { + can.run(event, cmds, function(msg) { + (output.innerHTML = msg.Result()) == ""? (can.target.style.height = "100px"): (can.target.style.height = ""); + event.target.value = ""; + }, true) + } else { + output.innerHTML = msg.Result(); + event.target.value = ""; } return msg } - if (can.page.oninput(event, can, function(event) { - event.stopPropagation() - event.preventDefault() - return true - })) {return} - switch (event.key) { - case "Enter": - var msg = run(event.target.value.trim()) - output.innerHTML = msg.Result() - break - case "Escape": - can.Hide() - break + case "Enter": run(event.target.value.trim()); break + case "Escape": can.Hide(); break } - }, function(event) { - if (event.ctrlKey) { - event.stopPropagation() - event.preventDefault() - return true - } - }]}]) }, }) -Volcanos("onaction", {help: "组件交互", list: []}) +Volcanos("onaction", {help: "组件交互", list: [], + onmousedown: function(event, can) { + can.moving = !can.moving; + can.movarg = { + x: event.x, y: event.y, + top: can.target.offsetTop, + left: can.target.offsetLeft, + }; + }, + onmousemove: function(event, can) { + if (can.moving) { + can.target.style.top = can.movarg.top + event.y - can.movarg.y + "px" + can.target.style.left = can.movarg.left + event.x - can.movarg.x + "px" + } + }, + onmouseup: function(event, can) { + // can.moving = false; + }, +}) Volcanos("onchoice", {help: "组件菜单", list: []}) Volcanos("ondetail", {help: "组件详情", list: []}) -Volcanos("onexport", {help: "导出数据", list: []}) +Volcanos("onexport", {help: "导出数据", list: [], + pwd: function(event, can, msg, cmd, output) { + msg.Echo("hello world") + }, + time: function(event, can, msg, cmd, output) { + msg.Echo(can.base.Time()) + }, +}) diff --git a/proto.js b/proto.js index 0094ab89..db660f85 100644 --- a/proto.js +++ b/proto.js @@ -76,7 +76,7 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块 }), Event: shy("触发器", function(event, msg, proto) {event = event || {}; msg = event.msg = msg || event.msg || {}, msg.__proto__ = proto || { - _create_time: can.base.Time(), + _create_time: can.base.Time(), _source: can, Log: shy("输出日志", function() {console.log(arguments)}), Option: function(key, val) { if (val == undefined) {return msg[key]} @@ -87,6 +87,7 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块 msg[key] = can.core.List(arguments).slice(1) }, Echo: shy("输出响应", function(res) {msg.result = msg.result || [] + msg._hand = true for (var i = 0; i < arguments.length; i++) {msg.result.push(arguments[i])} return msg; }),