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

opt favor

This commit is contained in:
shaoying 2019-12-12 01:50:01 +08:00
parent ff6b987c2d
commit 6c878dc7dc
5 changed files with 60 additions and 38 deletions

View File

@ -58,7 +58,7 @@ var can = Volcanos("chat", {
typeof cb == "function" && cb(event, pane, {width: width, height: height}, "size", pane.output) 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"; if (width < 0) {field.style.left = -width / 2 + "px";
field.style.width = (document.body.offsetWidth + width) + "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"; field.style.left = (document.body.offsetWidth - width) / 2 + "px";
} }
if (height > 0) {field.style.height = height + "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"; field.style.height = (document.body.offsetHeight + height) + "px";
} }
return field; return field;

View File

@ -13,7 +13,7 @@ Volcanos("onaction", {help: "组件交互", list: [],
switch (event.key) { switch (event.key) {
case " ": case " ":
if (can.Favor) { 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() item.focus()
}) })
} }

View File

@ -38,9 +38,9 @@ Volcanos("onimport", {help: "导入数据", list: [],
item.value = value item.value = value
}) })
}, },
favor: function(event, can, msg, cmd, output) { favor: function(event, can, msg, cmd, output) {cmd = msg.detail[0];
var p = can[msg.detail[0]]; var p = can[cmd]; if (p && p.Select) {p.Select(event, null, true); return msg._hand = true}
p.Select && p.Select(event, null, true) && (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", "工作", "办公", "聊天"], "清屏", "刷新", "串行", "并行", Volcanos("onaction", {help: "组件交互", list: [["layout", "工作", "办公", "聊天"], "清屏", "刷新", "串行", "并行",

View File

@ -1,47 +1,68 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: [],
_init: function(can, conf, output, action, option, field) { _init: function(can, conf, output, action, option, field) {
can.Show(400, 100, 100), can.Hide();
can.page.Append(can, option, [{input: ["cmd", function(event) { can.page.Append(can, option, [{input: ["cmd", function(event) {
function run(cmd) { can.page.oninput(event, can)
var msg = can.Event(event);
msg.detail = [cmd] function run(cmds) {cmds = cmds.split(" ")
msg._time = can.base.Time() var cmd = cmds[0]
msg._source = can
can.Export(event, msg, "favor") var msg = can.Event(event, {detail: cmds});
if (msg._hand) { var cb = can.onexport[cmd]
event.target.value = "" 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 return msg
} }
if (can.page.oninput(event, can, function(event) {
event.stopPropagation()
event.preventDefault()
return true
})) {return}
switch (event.key) { switch (event.key) {
case "Enter": case "Enter": run(event.target.value.trim()); break
var msg = run(event.target.value.trim()) case "Escape": can.Hide(); break
output.innerHTML = msg.Result()
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("onchoice", {help: "组件菜单", list: []})
Volcanos("ondetail", {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())
},
})

View File

@ -76,7 +76,7 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
}), }),
Event: shy("触发器", function(event, msg, proto) {event = event || {}; Event: shy("触发器", function(event, msg, proto) {event = event || {};
msg = event.msg = msg || event.msg || {}, msg.__proto__ = proto || { 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)}), Log: shy("输出日志", function() {console.log(arguments)}),
Option: function(key, val) { Option: function(key, val) {
if (val == undefined) {return msg[key]} 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) msg[key] = can.core.List(arguments).slice(1)
}, },
Echo: shy("输出响应", function(res) {msg.result = msg.result || [] Echo: shy("输出响应", function(res) {msg.result = msg.result || []
msg._hand = true
for (var i = 0; i < arguments.length; i++) {msg.result.push(arguments[i])} for (var i = 0; i < arguments.length; i++) {msg.result.push(arguments[i])}
return msg; return msg;
}), }),