1
0
mirror of https://shylinux.com/x/volcanos synced 2025-04-25 16:58:06 +08:00
This commit is contained in:
shylinux 2020-02-23 06:35:23 +08:00
parent adc9ebbf9d
commit 5f4992e41a
36 changed files with 833 additions and 638 deletions

View File

@ -1,5 +1,5 @@
var can = Volcanos("chat", { var can = Volcanos("chat", {
Page: shy("构造网页", function(can, name, conf, cb, body) { Page: shy("构造网页", function(can, name, conf, cb, body, topic) {
var page = Volcanos(name, {_type: "local", _panes: {}, _views: {}, target: body, var page = Volcanos(name, {_type: "local", _panes: {}, _views: {}, target: body,
Plugin: can.Plugin, Inputs: can.Inputs, Output: can.Output, Plugin: can.Plugin, Inputs: can.Inputs, Output: can.Output,
@ -7,17 +7,38 @@ var can = Volcanos("chat", {
typeof cb == "function" && cb(event, page, value, key, body); typeof cb == "function" && cb(event, page, value, key, body);
}, },
Report: function(event, value, key) { Report: function(event, value, key) {
page.Import && page.Import(event, value, key) // 导入数据
page.Import(event, value, key)
// 分发数据
can.core.Item(page._panes, function(index, item) { can.core.Item(page._panes, function(index, item) {
if (key == "favor") {var msg = value;
var cmds = msg.detail, cmd = cmds[0];
if (cmd == item._name || cmd == item.name()) {cmd = cmds[1], cmds = cmds.slice(1)}
var cb = item.onchoice[cmd];
if (typeof cb == "function") {
cb(event, item, value, cmd, item.target);
return msg.Echo(item._name, " onchoice ", cmd), msg._hand = true;
}
var cb = item.onaction[cmd];
if (typeof cb == "function") {
cb(event, item, value, cmd, item.target);
return msg.Echo(item._name, " onaction ", cmd), msg._hand = true;
}
}
// 下发数据
item.Import && item.Import(event, value, key) item.Import && item.Import(event, value, key)
}) })
}, },
run: function(event, option, cmds, cb) {can.misc.Run(event, page, option, cmds, cb)}, run: function(event, option, cmds, cb) {can.misc.Run(event, page, option, cmds, cb)},
}, Config.libs.concat(["page/"+name]), function(page) { }, Config.libs.concat(["page/"+name, "page/"+topic+".css"]), function(page) {
// 加载配置
page.onimport._init && page.onimport._init(page, page.Conf(conf), body) page.onimport._init && page.onimport._init(page, page.Conf(conf), body)
can.core.Next(conf.pane, function(item, cb) { can.core.Next(conf.pane, function(item, cb) {
// 加载模块
page._panes[item.name] = page[item.name] = page._views[item.pos] = page[item.pos] = can.Pane(page, item.name, item, cb, page._panes[item.name] = page[item.name] = page._views[item.pos] = page[item.pos] = can.Pane(page, item.name, item, cb,
can.page.Select(can, body, "fieldset."+item.name)[0] || can.page.Select(can, body, "fieldset."+item.name)[0] ||
can.page.AppendField(can, body, item.name+" "+(item.pos||""), item)) can.page.AppendField(can, body, item.name+" "+(item.pos||""), item))
@ -25,7 +46,7 @@ var can = Volcanos("chat", {
}, conf) }, conf)
return page return page
}), }),
Pane: shy("构造面板", function(can, name, meta, cb, field) { Pane: shy("构造组件", function(can, name, meta, cb, field) {
var river = "", storm = ""; var river = "", storm = "";
var pane = Volcanos(name, {_type: "local", _plugins: [], _local: {}, target: field, var pane = Volcanos(name, {_type: "local", _plugins: [], _local: {}, target: field,
@ -34,18 +55,21 @@ var can = Volcanos("chat", {
output: field.querySelector("div.output"), output: field.querySelector("div.output"),
Plugin: can.Plugin, Inputs: can.Inputs, Output: can.Output, Plugin: can.Plugin, Inputs: can.Inputs, Output: can.Output,
Export: function(event, value, key) {can.Report(event, value, key)}, Export: function(event, value, key) {var cb = pane.onexport[key];
typeof cb == "function"? cb(event, pane, value, key, field): can.Report(event, value, key)
},
Import: function(event, value, key) {var cb = pane.onimport[key]; Import: function(event, value, key) {var cb = pane.onimport[key];
// 导入数据 // 导入数据
typeof cb == "function" && cb(event, pane, value, key, pane.output); typeof cb == "function" && cb(event, pane, value, key, field);
// 分发数据 // 分发数据
can.core.List(pane._plugins, function(item) {item.Import(event, value, key)}) // can.core.List(pane._plugins, function(item) {item.Import(event, value, key)})
// 导入数据 // 显示数据
pane.page.Select(pane, pane.action, "input."+key, function(item) {item.value = value}) pane.page.Select(pane, pane.action, "input."+key, function(item) {item.value = value})
}, },
Action: function(key, value) { Action: function(key, value) {
return can.page.Select(can, pane.action, "input[name="+key+"],select."+key+",select[name="+key+"]", function(item) { return can.page.Select(can, pane.action, "input[name="+key+"],select."+key+",select[name="+key+"]", function(item) {
// 读写控件
value != undefined && (item.value = value), value = item.value value != undefined && (item.value = value), value = item.value
}), value }), value
}, },
@ -68,7 +92,7 @@ var can = Volcanos("chat", {
field.style.height = "" field.style.height = ""
} }
typeof cb == "function" && cb(event, pane, {width: width, height: height}, "size", pane.output) typeof cb == "function" && cb(event, pane, {width: width, height: height}, "size", field)
}, },
Show: function(event, width, height, offset) {field.style.display = "block"; Show: function(event, 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";
@ -97,6 +121,7 @@ var can = Volcanos("chat", {
run: function(event, cmds, cb) {var msg = pane.Event(event) run: function(event, cmds, cb) {var msg = pane.Event(event)
can.page.Select(can, pane.action, "input", function(item, index) { can.page.Select(can, pane.action, "input", function(item, index) {
// 控件参数
item.name && item.value && msg.Option(item.name, item.value) item.name && item.value && msg.Option(item.name, item.value)
}) })
can.run(event, pane.option.dataset, cmds, cb) can.run(event, pane.option.dataset, cmds, cb)
@ -123,6 +148,9 @@ var can = Volcanos("chat", {
option: option, action: action, output: output, option: option, action: action, output: output,
Inputs: can.Inputs, Output: can.Output, Inputs: can.Inputs, Output: can.Output,
Export: function(event, value, key) {var cb = plugin.onexport[key];
typeof cb == "function"? cb(event, plugin, value, key, field): can.Export(event, value, key)
},
Import: function(event, value, key) {var cb = plugin.onimport[key]; Import: function(event, value, key) {var cb = plugin.onimport[key];
// 导入数据 // 导入数据
typeof cb == "function" && cb(event, plugin, value, key, plugin.output); typeof cb == "function" && cb(event, plugin, value, key, plugin.output);
@ -145,19 +173,6 @@ var can = Volcanos("chat", {
} }
}, },
Share: function(event) {
can.user.input(event, can, ["name", "text"], function(event, cmd, meta, list) {
cmd == "提交" && plugin.Run(event, ["action", "share", meta.name, meta.text], function(msg) {
can.user.toast(can.user.Share(can, {path: "/share/"+msg.Result()+"/"}, true))
}, true)
return true
})
},
Rename: function(event) {var meta = field.Meta;
meta.help = can.user.prompt("", function(help) {
meta.help = help
}, meta.help)
},
Remove: function(event) {var list = can.page.Select(can, option, "input.temp") Remove: function(event) {var list = can.page.Select(can, option, "input.temp")
list.length > 0 && list[list.length-1].parentNode.removeChild(list[list.length-1]) list.length > 0 && list[list.length-1].parentNode.removeChild(list[list.length-1])
}, },
@ -215,6 +230,7 @@ var can = Volcanos("chat", {
}) })
}, },
Show: function(type, msg, cb) {plugin.msg = msg, msg._plugin_name = name; Show: function(type, msg, cb) {plugin.msg = msg, msg._plugin_name = name;
msg.Option("title") && can.user.title(msg.Option("title"))
return plugin._output = plugin._local[type] = plugin[type] = can.Output(plugin, feature, type, msg, cb, output, action, option, status) return plugin._output = plugin._local[type] = plugin[type] = can.Output(plugin, feature, type, msg, cb, output, action, option, status)
}, },
Clone: function(event, cb) {meta.nick = meta.name + can.ID() Clone: function(event, cb) {meta.nick = meta.name + can.ID()
@ -226,20 +242,21 @@ var can = Volcanos("chat", {
Delete: function(event) {field.parentNode.removeChild(field)}, Delete: function(event) {field.parentNode.removeChild(field)},
}, Config.libs.concat(["plugin/"+(meta.type||feature.active||"state")]), function(plugin) {plugin.Conf(meta); }, Config.libs.concat(["plugin/"+(meta.type||feature.active||"state")]), function(plugin) {plugin.Conf(meta);
var list = JSON.parse(meta.inputs||"[]"); var list = JSON.parse(meta.inputs||"[]");
// 加载配置
plugin.onimport._init? plugin.onimport._init(plugin, feature, plugin.output, plugin.action, plugin.option): plugin.onimport._init? plugin.onimport._init(plugin, feature, plugin.output, plugin.action, plugin.option):
// 加载控件
can.core.Next(list.length>0? list: [{type: "text"}, {type: "button", value: "执行"}], plugin.Append, function() { can.core.Next(list.length>0? list: [{type: "text"}, {type: "button", value: "执行"}], plugin.Append, function() {
typeof cb == "function" && cb(plugin) typeof cb == "function" && cb(plugin)
}) })
// 加载控件
meta.msg && plugin.Show(feature.display || "table", meta.msg) meta.msg && plugin.Show(feature.display || "table", meta.msg)
}, meta) }, meta)
field.Check = plugin.Check return field.Check = plugin.Check, plugin
return plugin
}), }),
Inputs: shy("构造控件", function(can, item, type, name, value, cb, option) { Inputs: shy("构造控件", function(can, item, type, name, value, cb, option) {
var input = Volcanos(name, {_type: "input", _plugin: can, item: item, target: "", var input = Volcanos(name, {_type: "input", _plugin: can, item: item, target: "",
Run: can.Run, Runs: can.Runs, Run: can.Run, Runs: can.Runs,
Select: function(event) {can.Select(event, input.target, true)},
Import: function(event, value, key, index) {var cb = input.onimport[item.imports]; Import: function(event, value, key, index) {var cb = input.onimport[item.imports];
value = typeof cb == "function" && cb(event, input, value, key, input.target) || value value = typeof cb == "function" && cb(event, input, value, key, input.target) || value
input.target.value = value; input.target.value = value;
@ -247,25 +264,24 @@ var can = Volcanos("chat", {
}, },
Append: function(event, value) {can.Append(null, function(input) {can.Select(event, input.target, true)})}, Append: function(event, value) {can.Append(null, function(input) {can.Select(event, input.target, true)})},
Clone: function(event, value) {can.Clone(event, function(input) {input.Select(event, null, true)})}, Clone: function(event, value) {can.Clone(event, function(input) {input.Select(event, null, true)})},
Select: function(event) {can.Select(event, input.target, true)},
run: function(event, cmd, cb, silent) {var msg = can.Event(event); run: function(event, cmd, cb, silent) {var msg = can.Event(event);
msg.Option("_action", item.name); msg.Option("_action", item.name);
(input[item.cb] || can[item.cb] || can.Check)(event, event.target, cb); (input[item.cb] || can[item.cb] || can.Check)(event, event.target, cb);
}, },
}, Config.libs.concat(["plugin/"+type, "plugin/input/"+(item.figure||"")]), function(input) {
}, Config.libs.concat(["plugin/"+type]), function(input) {
var target = input.onimport.init(input, item, name, value, option); var target = input.onimport.init(input, item, name, value, option);
input.target = target, typeof cb == "function" && cb(input); input.target = target, typeof cb == "function" && cb(input);
}) })
return input return input
}), }),
Output: shy("构造组件", function(can, feature, type, msg, cb, target, action, option, status) { Output: shy("构造组件", function(can, feature, type, msg, cb, target, action, option, status) {
if (type == "inner" && (!msg.result || msg.result.length == 0)) {type = "table"}
var output = Volcanos(type, {_type: "output", feature: feature, msg: msg, var output = Volcanos(type, {_type: "output", feature: feature, msg: msg,
target: target, action: action, target: target, action: action,
Run: can.Run, Runs: can.Runs, Run: can.Run, Runs: can.Runs,
Import: function(event, value, key) {var cb = output.onimport[key]; Import: function(event, value, key) {var cb = output.onimport && output.onimport[key];
typeof cb == "function" && cb(event, output, value, key, target); typeof cb == "function" && cb(event, output, value, key, target);
}, },
Option: function(key, value) { Option: function(key, value) {
@ -301,14 +317,11 @@ var can = Volcanos("chat", {
return output return output
}), }),
}, Config.libs.concat(Config.list), function(can) { }, Config.libs.concat(Config.list), function(can) {
can[Config.main] = can.Page(can, Config.main, Config, function(chat) { can.user.Search(can, "sessid") && can.user.Cookie(can, "sessid", can.user.Search(can, "sessid")) && can.user.Search(can, "sessid", "")
chat.Import(event||{}, can.user.Search(can, "layout")||Config.layout.def, "layout")
can.user.title(can.user.Search(can, "you")||Config.title)
chat.Login? can.user.login(function(user) {
chat.River.Import(event||{}, "update", "river")
chat.Header.Import(event||{}, user.name, "username")
}): (chat.Action.Import(event||{}, location.pathname.split("/")[2], "river"), chat.Action.Import(event||{}, "none", "storm"))
}, document.body)
can.require(["page/"+(can.user.Search(can, "topic")||Config.topic)+".css"], function() {}) can[Config.main] = can.Page(can, Config.main, Config, function(chat) {
chat.Import({}, can.user.Search(can, "layout")||Config.layout.def, "layout")
chat.Import({}, can.user.Search(can, "you")||can.user.Search(can, "title")||Config.title, "title")
chat.Import({}, "", "login")
}, document.body, can.user.Search(can, "topic")||Config.topic)
}) })

View File

@ -2,6 +2,7 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=0.7,user-scalable=no"> <meta name="viewport" content="width=device-width,initial-scale=0.7,user-scalable=no">
<meta name="viewport" content="width=device-width,initial-scale=0.7,user-scalable=no">
<title>volcanos</title> <title>volcanos</title>
<link rel="shortcut icon" type="image/ico" href="/static/volcanos/favicon.ico"> <link rel="shortcut icon" type="image/ico" href="/static/volcanos/favicon.ico">

View File

@ -1,24 +1,28 @@
var Config = {iceberg: "/chat/", volcano: "/static/volcanos/", var Config = {iceberg: "/chat/", volcano: "/static/volcanos/",
libs: ["lib/base", "lib/core", "lib/misc", "lib/page", "lib/user"], libs: ["lib/base", "lib/core", "lib/misc", "lib/page", "lib/user"],
main: "chat", list: ["page/chat", main: "chat", list: ["page/chat",
"pane/Toast", "pane/Tutor", "pane/Debug", "pane/Toast", "pane/Carte",
"pane/Carte", "pane/Favor", "pane/Login", "pane/Debug", "pane/Tutor", "pane/Favor", "pane/Login",
"pane/Header", "pane/Header",
"pane/Ocean", "pane/River", "pane/Storm", "pane/Steam", "pane/Ocean", "pane/River", "pane/Storm", "pane/Steam",
"pane/Target", "pane/Source", "pane/Action", "pane/Target", "pane/Source", "pane/Action",
"pane/Footer", "pane/Footer",
"plugin/state", "plugin/input", "plugin/table", "plugin/inner", "plugin/media", "plugin/state", "plugin/table", "plugin/input",
"plugin/input/date", "plugin/input/key",
], pane: [ ], pane: [
{group: "index", name: "Toast", pos: "dialog", duration: 3000}, {group: "index", name: "Toast", pos: "dialog", duration: 3000},
{group: "index", name: "Tutor", pos: "dialog"},
{group: "index", name: "Debug", pos: "dialog"},
{group: "index", name: "Carte", pos: "dialog"}, {group: "index", name: "Carte", pos: "dialog"},
{group: "index", name: "Debug", pos: "dialog"},
{group: "index", name: "Tutor", pos: "dialog"},
{group: "index", name: "Favor", pos: "dialog"}, {group: "index", name: "Favor", pos: "dialog"},
{group: "index", name: "Login", pos: "dialog"}, {group: "index", name: "Login", pos: "dialog"},
{group: "index", name: "Header", pos: "head", state: ["time", "user", "link"], title: "github.com/shylinux/context"}, {group: "index", name: "Header", pos: "head",
title: "github.com/shylinux/context",
state: ["time", "user", "link"],
},
{group: "index", name: "Ocean", pos: "dialog", def_name: "meet"}, {group: "index", name: "Ocean", pos: "dialog", def_name: "meet"},
{group: "index", name: "River", pos: "left"}, {group: "index", name: "River", pos: "left"},
{group: "index", name: "Storm", pos: "right"}, {group: "index", name: "Storm", pos: "right"},
@ -37,5 +41,5 @@ var Config = {iceberg: "/chat/", volcano: "/static/volcanos/",
"最长": {head: 30, foot: 30, left: 0, right: 0, bottom: -2, center: 0, top: 0}, "最长": {head: 30, foot: 30, left: 0, right: 0, bottom: -2, center: 0, top: 0},
"全屏": {head: 0, foot: 0, left: 0, right: 0, bottom: -1, center: 0, top: 0}, "全屏": {head: 0, foot: 0, left: 0, right: 0, bottom: -1, center: 0, top: 0},
}, border: 4, }, border: 4,
}, }, scroll: {line: 100},
} }

View File

@ -37,14 +37,14 @@ Volcanos("core", {help: "核心模块",
} }
return list return list
}), }),
Items: function(obj, cb) {var list = [] Items: shy("迭代器", function(obj, cb) {var list = [];
for (var key in obj) { for (var key in obj) {
list = list.concat(this.List(obj[key], function(value, index, array) { list = list.concat(this.List(obj[key], function(value, index, array) {
return typeof cb == "function" && cb(value, index, key, obj) return typeof cb == "function" && cb(value, index, key, obj)
})) }))
} }
return list return list
}, }),
Next: shy("迭代器", function(obj, cb, cbs) {obj = typeof obj == "string"? [obj]: (obj || []) Next: shy("迭代器", function(obj, cb, cbs) {obj = typeof obj == "string"? [obj]: (obj || [])
function next(list, cb) { function next(list, cb) {
list && list.length > 0? typeof cb == "function" && cb(list[0], function() { list && list.length > 0? typeof cb == "function" && cb(list[0], function() {
@ -53,4 +53,8 @@ Volcanos("core", {help: "核心模块",
} }
next(obj, cb) next(obj, cb)
}), }),
Split: shy("分词器", function(str, sep) {
return str.trim().split(sep||" ")
}),
}) })

View File

@ -1,7 +1,7 @@
Volcanos("page", {help: "网页模块", Volcanos("page", {help: "网页模块",
ClassList: { ClassList: {
has: function(can, obj, key) {var list = obj.className? obj.className.split(" "): []; has: function(can, obj, key) {var list = obj.className? obj.className.split(" "): [];
for (var i = 1; i < arguments.length; i++) { for (var i = 2; i < arguments.length; i++) {
if (list.indexOf(arguments[i]) == -1) {return false} if (list.indexOf(arguments[i]) == -1) {return false}
} }
return true; return true;
@ -264,7 +264,12 @@ Volcanos("page", {help: "网页模块",
AppendAction: shy("添加控件", function(can, action, list, cb) { AppendAction: shy("添加控件", function(can, action, list, cb) {
return can.page.Append(can, action, can.core.List(list, function(line) { return can.page.Append(can, action, can.core.List(list, function(line) {
return typeof line == "string"? {button: [line, cb]}: line.length > 0? {select: [line, cb]}: line return typeof line == "string"? {button: [line, cb]}: line.length > 0? {select: [line, cb]}:
line.input && typeof line.input != "string" ? {input: [line.input[0], function(event) {
typeof line.input[1] == "function" && line.input[1](event, can)
}, function(event) {
typeof line.input[2] == "function" && line.input[2](event, can)
}]}: line
})) }))
}), }),
AppendStatus: shy("添加控件", function(can, status, list, cb) { AppendStatus: shy("添加控件", function(can, status, list, cb) {
@ -394,5 +399,73 @@ Volcanos("page", {help: "网页模块",
event.preventDefault() event.preventDefault()
return true return true
}, },
Prepos: function(event, item) {
var pos = 1;
var p = item.getBoundingClientRect();
var y = (event.clientY - p.y) / p.height
if (y < 0.2) {
pos += 0;
} else if (y > 0.8) {
pos += 6;
} else {
pos += 3;
}
var x = (event.clientX - p.x) / p.width
if (x < 0.2) {
pos += 0;
} else if (x > 0.8) {
pos += 2;
} else {
pos += 1;
}
var cursor = [
"nw-resize", "n-resize", "ne-resize",
"w-resize", "move", "e-resize",
"sw-resize", "s-resize", "se-resize",
]
item.style.cursor = cursor[pos-1]
return pos
},
Resize: function(event, item, begin, pos) {
switch (pos) {
case 5:
item.style.left = begin.left + event.clientX - begin.x + "px"
item.style.top = begin.top + event.clientY - begin.y + "px"
return
}
switch (pos) {
case 1:
case 2:
case 3:
item.style.top = begin.top + event.clientY - begin.y + "px"
item.style.height = begin.height - event.clientY + begin.y + "px"
break
}
switch (pos) {
case 1:
case 4:
case 7:
item.style.left = begin.left + event.clientX - begin.x + "px"
item.style.width = begin.width - event.clientX + begin.x + "px"
break
}
switch (pos) {
case 3:
case 6:
case 9:
item.style.width = begin.width + event.clientX - begin.x + "px"
break
}
switch (pos) {
case 7:
case 8:
case 9:
item.style.height = begin.height + event.clientY - begin.y + "px"
break
}
},
}) })

View File

@ -28,9 +28,7 @@ Volcanos("user", {help: "用户模块",
can.page.Remove(can, view.first) can.page.Remove(can, view.first)
} }
}]}, {button: ["关闭", function(event, value) { }]}, {button: ["关闭", function(event, value) {
if (typeof cb == "function" && cb(event, value, {}, [])) { can.page.Remove(can, view.first)
can.page.Remove(can, view.first)
}
}]}]}, }]}]},
]}]) ]}])
can.page.Select(can, view.first, "input", function(item, index) { can.page.Select(can, view.first, "input", function(item, index) {
@ -38,10 +36,10 @@ Volcanos("user", {help: "用户模块",
}) })
return view return view
}, },
toast: function(text) {}, toast: function(text) {},
carte: function(event, cb) {}, carte: function(event, cb) {},
login: function(cb) {}, login: function(cb) {},
share: function(cb) {},
Share: shy("共享链接", function(can, objs, clear) {var obj = objs || {}; var path = location.pathname; Share: shy("共享链接", function(can, objs, clear) {var obj = objs || {}; var path = location.pathname;
obj.path && (path = obj.path, delete(obj.path)) obj.path && (path = obj.path, delete(obj.path))
@ -63,9 +61,11 @@ Volcanos("user", {help: "用户模块",
} else if (key == undefined) { } else if (key == undefined) {
return args return args
} else if (value == undefined) { } else if (value == undefined) {
return args[key] || can.user.Cookie(can, key) // return args[key] || can.user.Cookie(can, key)
return args[key]
} else { } else {
args[key] = value args[key] = value
args[key] == "" && delete(args[key])
} }
return location.search = can.core.Item(args, function(key, value) { return location.search = can.core.Item(args, function(key, value) {

View File

@ -5,34 +5,49 @@ Volcanos("onimport", {help: "导入数据", list: [],
} }
}, },
layout: function(event, can, value, key, body) {var conf = can.Conf() layout: function(event, can, value, key, body) {var conf = can.Conf()
can.onlayout["刷新"](event, can, conf, conf.layout.size[value], body) can.onlayout["刷新"](event, can, conf, value? conf.layout.size[value]: null, body)
},
title: function(event, can, value, key, body) {var conf = can.Conf()
can.user.title(value||conf.title)
},
login: function(event, can, value, key, body) {var conf = can.Conf()
var list = location.pathname.split("/");
can.Login? can.user.login(function(user) {
can.River.Import(event, "update", "river")
can.Header.Import(event, user.name, "username")
}): (
can.Action.Import(event, list[2], "river"),
can.Action.Import(event, "action", "storm")
)
} }
}) })
Volcanos("onaction", {help: "组件交互", list: [], Volcanos("onaction", {help: "组件交互", list: [],
onkeydown: function(event, can) { onkeydown: function(event, can) {var conf = can.Conf()
if (event.target.tagName == "INPUT" || event.target.tagName == "TEXTAREA") { if (event.target.tagName == "INPUT" || event.target.tagName == "TEXTAREA") {
return return
} }
if (event.target.getAttribute("contenteditable")) { if (event.target.getAttribute("contenteditable")) {
return return
} }
switch (event.key) { switch (event.key) {
case "k":
can.Report(event, {x: 0, y: -30}, "scroll")
break
case "j": case "j":
can.Report(event, {x: 0, y: 30}, "scroll") can.Report(event, {x: 0, y: conf.scroll.line}, "scroll")
break
case "k":
can.Report(event, {x: 0, y: -conf.scroll.line}, "scroll")
break break
case "Escape": case "Escape":
can.Action.escape && can.Action.escape(event) can.Report(event, event.key, "escape")
break
case "Enter":
can.Report(event, event.key, "enter")
break break
case " ": case " ":
can.Favor && can.page.Select(can, can.Favor.Show(), "input.cmd", function(item) { can.Report(event, event.key, "space")
item.focus() break
}) default:
can.Report(event, event.key, "keydown")
event.stopPropagation()
event.preventDefault()
} }
}, },
}) })
@ -48,6 +63,9 @@ Volcanos("onlayout", {help: "组件布局", list: ["刷新"],
can.foot.Size(event, width, layout.foot) can.foot.Size(event, width, layout.foot)
height -= can.head.target.offsetHeight+can.foot.target.offsetHeight height -= can.head.target.offsetHeight+can.foot.target.offsetHeight
layout.left != 0 && can.left.target.dataset.width && (layout.left = can.left.target.dataset.width)
layout.right != 0 && can.right.target.dataset.width && (layout.right = can.right.target.dataset.width)
layout.left == undefined && (layout.left = can.left.target.clientWidth) layout.left == undefined && (layout.left = can.left.target.clientWidth)
layout.right == undefined && (layout.right = can.right.target.clientWidth) layout.right == undefined && (layout.right = can.right.target.clientWidth)
can.left.Size(event, layout.left, height) can.left.Size(event, layout.left, height)
@ -66,13 +84,7 @@ Volcanos("onlayout", {help: "组件布局", list: ["刷新"],
can.top.Size(event, width, height) can.top.Size(event, width, height)
}, },
}) })
Volcanos("onchoice", {help: "组件菜单", list: ["刷新", "登出"], Volcanos("onchoice", {help: "组件菜单", list: []})
"刷新": function(event, can, conf, key, body) {
},
"登出": function(event, can, conf, value, target) {
can.target.innerHTML = "";
},
})
Volcanos("ondetail", {help: "组件详情", list: []}) Volcanos("ondetail", {help: "组件详情", list: []})
Volcanos("onexport", {help: "导出数据", list: []}) Volcanos("onexport", {help: "导出数据", list: []})

View File

@ -1,77 +1,202 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: [],
_init: function(can, conf, output, action, option, field) { _begin: function(can) {},
can.page.Select(can, action, "input", function(input) { _start: function(can) {
input.value = can.user.Search(can, input.name) || "" can.page.Select(can, can.action, "input,select", function(input) {
input.value = can.user.Search(can, input.name) || input.value || ""
}) })
}, },
init: function(event, can, msg, cmd, target) {can.output.innerHTML = "";
init: function(event, can, msg, cmd, field) {can.output.innerHTML = "";
can._local[msg.cmds[0]] = can._local[msg.cmds[0]] || {} can._local[msg.cmds[0]] = can._local[msg.cmds[0]] || {}
can._local[msg.cmds[0]][msg.cmds[1]] = msg.Table(function(item, index) {if (!item.name) {return} can._local[msg.cmds[0]][msg.cmds[1]] = msg.Table(function(item, index) {if (!item.name) {return}
// 添加插件
var plugin = can[item.name] = can.Plugin(can, item.name, item, function(event, cmds, cbs) { var plugin = can[item.name] = can.Plugin(can, item.name, item, function(event, cmds, cbs) {
can.run(event, [item.river, item.storm, item.action].concat(cmds), cbs) can.run(event, [item.river, item.storm, item.action].concat(cmds), cbs)
}, can.page.AppendField(can, can.output, "item "+item.name, item)) }, can.page.AppendField(can, can.output, "item "+item.name, item))
return can._plugins.push(plugin), plugin return can._plugins.push(plugin), plugin
}) })
}, },
river: function(event, can, value, cmd, target) { river: function(event, can, value, cmd, field) {if (value == "update") {return}
if (value == "update") {return}
can.Conf("temp_river", value) can.Conf("temp_river", value)
}, },
storm: function(event, can, value, cmd, target) { storm: function(event, can, value, cmd, field) {if (value == "update") {return}
// 保存界面
can.Cache(can.Conf("river")+"."+can.Conf("storm"), can.output, "some"); can.Cache(can.Conf("river")+"."+can.Conf("storm"), can.output, "some");
if (can.Cache(can.Conf("river", can.Conf("temp_river"))+"."+can.Conf("storm", value), can.output)) {
can.Conf("river", can.Conf("temp_river")) // 恢复界面
can.Conf("storm", value) return
if (!can.Cache(can.Conf("river")+"."+can.Conf("storm"), can.output)) {
can.run(event, [can.Conf("river"), can.Conf("storm")], function(msg) {
can.onimport.init(event, can, msg, cmd, can.output)
})
} }
}, // 刷新界面
can.run(event, [can.Conf("river"), can.Conf("storm")], function(msg) {
layout: function(event, can, value, cmd, target) {can.layout = value; can.onimport.init(event, can, msg, cmd, can.output)
can.page.Select(can, can.action, "select.layout", function(item) {
item.value = value
}) })
}, },
scroll: function(event, can, value, cmd, target) {can.layout = value; you: function(event, can, value, cmd, field) {
can.output.parentElement.scrollBy(value.x, value.y)
},
you: function(event, can, value, cmd, target) {
can.user.title(value) can.user.title(value)
}, },
favor: function(event, can, msg, cmd, target) {var key = msg.detail[0];
if (msg._hand) {return}
var cb = can.onaction[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, can.output); return msg.Echo(can._name, " onaction ", key), msg._hand = true}
var cb = can.onchoice[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, can.output); return msg.Echo(can._name, " onchoice ", key), msg._hand = true}
var sub = can[key]; if (sub && sub.Select) {sub.Select(event, null, true); return msg.Echo(can._name, " select ", sub._name), msg._hand = true} layout: function(event, can, value, cmd, field) {value && can.Action(cmd, value)},
scroll: function(event, can, value, cmd, field) {can.layout = value;
can.output.parentElement.scrollBy(value.x, value.y)
},
favor: function(event, can, msg, cmd, field) {if (msg._hand) {return}
var cmds = msg.detail, key = cmds[0];
if (key == can.name()) {key = cmds[1], cmds = cmds.slice(1)}
can._plugin && can._plugin.Import(event, msg, cmd) // 下发数据
can.core.Item(can._local, function(river, list) {
can.core.Item(list, function(storm, list) {
can.core.List(list, function(sub) {
if (sub._name == key) {
sub.Select(event), msg._hand = true;
msg.Echo(can._name, " ", key)
}
})
})
})
}, },
}) })
Volcanos("onaction", {help: "组件交互", list: [["layout"].concat(Config.layout.list), "刷新", "清屏", "并行","串行", Volcanos("onaction", {help: "组件交互", list: [
["action", "正常", "编辑", "编排", "定位"], ["layout"].concat(Config.layout.list), "清屏", "刷新", "并行","串行",
["action", "正常", "竖排", "编排", "定位", "定形"],
{input: "pod"}, {input: "you"}, {input: "hot"}, {input: "top"}, {input: "pod"}, {input: "you"}, {input: "hot"}, {input: "top"},
], ],
onmousemove: function(event, can, msg, cmd, target) { layout: function(event, can, value, cmd, field) {can.Export(event, value, cmd)},
can.resize && can.resize(event)
"清屏": function(event, can, msg, cmd, field) {
can.page.Select(can, can.output, "fieldset.item>div.output", function(item) {
item.innerHTML = "";
})
},
"刷新": function(event, can, msg, cmd, field) {
can.page.Select(can, can.output, "fieldset.item>div.output", function(item) {
item.innerHTML = "";
})
can.run(event, [can.Conf("river"), can.Conf("storm")], function(msg) {
can.onimport.init(event, can, msg, cmd, can.output)
})
},
"并行": function(event, can, msg, cmd, field) {
can.page.Select(can, field, "fieldset.item", function(field) {
can.page.Select(can, field, "input[type=button]", function(input, index) {
index == 0 && input.click()
})
})
},
"串行": function(event, can, msg, cmd, field) {
can.core.Next(can.page.Select(can, field, "fieldset.item", function(field) {
return field
}), function(field, cb) {
can.page.Select(can, field, "input[type=button]", function(input, index) {
index == 0 && field.Check(event, input, cb)
})
})
}, },
layout: function(event, can, value, cmd, target) {can.Export(event, value, cmd)}, "正常": function(event, can, value, cmd, field) {
can.page.Select(can, can.output, "fieldset.item", function(item) {
item.setAttribute("draggable", false)
item.style.position = ""
item.style.cursor = ""
item.style.clear = ""
item.style.left = ""
item.style.top = ""
})
},
"竖排": function(event, can, value, cmd, field) {
can.page.Select(can, can.output, "fieldset.item", function(item) {
item.style.clear = "both"
})
},
"编排": function(event, can, value, cmd, field) {
can.page.Select(can, can.target, "fieldset.item", function(item) {
item.setAttribute("draggable", true)
item.ondragstart = function(event) {can.drag = event.target}
item.ondragover = function(event) {event.preventDefault()}
item.ondrop = function(event) {event.preventDefault()
item.parentNode.insertBefore(can.drag, item)
}
})
},
"定位": function(event, can, value, cmd, field) {
can.page.Select(can, can.output, "fieldset.item", function(item) {
item.style.left = item.offsetLeft + "px"
item.style.top = item.offsetTop + "px"
})
"共享": function(event, can, msg, cmd, target) { var max, current, begin;
can.page.Select(can, can.output, "fieldset.item", function(item) {
item.style.position = "absolute"
item.onmousedown = function(event) {if (can.Action("action") != "定位") {return}
if (current) {
// 更新位置
current.style.left = begin.left + event.clientX - begin.x + "px"
current.style.top = begin.top + event.clientY - begin.y + "px"
current = null;
return
}
// 记录位置
current = item;
current.style["z-index"] = max = max + 1
begin = {x: event.clientX, y: event.clientY, left: item.offsetLeft, top: item.offsetTop}
};
can.output.onmousemove = item.onmousemove = function(event) {if (!current) {return}
// 移动位置
current.style.left = begin.left + event.clientX - begin.x + "px"
current.style.top = begin.top + event.clientY - begin.y + "px"
}
})
},
"定形": function(event, can, value, cmd, field) {
can.page.Select(can, can.output, "fieldset.item", function(item) {
item.style.top = item.offsetTop + "px"
item.style.left = item.offsetLeft + "px"
item.style.width = item.offsetWidth + "px"
item.style.height = item.offsetHeight + "px"
})
var max, pos, current, begin;
can.page.Select(can, can.output, "fieldset.item", function(item) {
item.style.position = "absolute"
item.onmousedown = function(event) {
if (can.Action("action") != "定形") {return}
if (current) {current = null; return}
// 记录位置
current = item;
current.style["z-index"] = max = max + 1
begin = {
x: event.clientX, y: event.clientY,
left: item.offsetLeft, top: item.offsetTop,
width: item.offsetWidth, height: item.offsetHeight,
}
};
item.onmousemove = function(event) {
if (can.Action("action") != "定形") {return}
var pos = can.page.Prepos(event, item)
if (!current) {return}
can.page.Resize(event, current, begin, pos)
}
})
},
})
Volcanos("onchoice", {help: "组件菜单", list: ["共享", "保存", "刷新"],
"共享": function(event, can, msg, cmd, field) {
can.user.input(event, can, ["name", "text"], function(event, cmd, meta, list) { can.user.input(event, can, ["name", "text"], function(event, cmd, meta, list) {
cmd == "提交" && can.run(event, [can.Conf("river"), can.Conf("storm"), "share", meta.name, meta.text], function(msg) { var msg = can.Event(event);
can.user.toast(can.user.Share(can, {path: "/share/"+msg.Result()+"/"}, true)) msg.Option("name", meta.name)
}, true) msg.Option("text", meta.key)
cmd == "提交" && can.Export(event, can.name(), "share")
return true return true
}) })
}, },
"保存": function(event, can, msg, cmd, target) { "保存": function(event, can, msg, cmd, field) {
var list = [] var list = []
can.page.Select(can, target, "fieldset", function(item) {var meta = item.Meta can.page.Select(can, field, "fieldset", function(item) {var meta = item.Meta
can.page.Select(can, item, "form.option", function(option) { can.page.Select(can, item, "form.option", function(option) {
meta.args = can.page.Select(can, option, ".args", function(item) {return item.value}) meta.args = can.page.Select(can, option, ".args", function(item) {return item.value})
}) })
@ -81,87 +206,7 @@ Volcanos("onaction", {help: "组件交互", list: [["layout"].concat(Config.layo
can.user.toast("保存成功") can.user.toast("保存成功")
}) })
}, },
"刷新": function(event, can, msg, cmd, target) {
can.page.Select(can, can.output, "fieldset.item>div.output", function(item) {
item.innerHTML = "";
})
can.run(event, [can.Conf("river"), can.Conf("storm")], function(msg) {
can.onimport.init(event, can, msg, cmd, can.output)
})
},
"清屏": function(event, can, msg, cmd, target) {
can.page.Select(can, can.output, "fieldset.item>div.output", function(item) {
item.innerHTML = "";
})
},
"并行": function(event, can, msg, cmd, target) {
can.page.Select(can, target, "fieldset.item", function(field) {
can.page.Select(can, field, "input[type=button]", function(input, index) {
index == 0 && field.Check(event, input, function() {})
})
})
},
"串行": function(event, can, msg, cmd, target) {
can.core.Next(can.page.Select(can, target, "fieldset.item", function(field) {
return field
}), function(field, cb) {
can.page.Select(can, field, "input[type=button]", function(input, index) {
index == 0 && field.Check(event, input, cb)
})
})
},
action: function(event, can, value, cmd, target) {
switch (value) {
case "正常":
can.page.Select(can, target, "fieldset.item", function(item) {
item.setAttribute("draggable", false)
item.style.position = ""
item.style.left = ""
item.style.top = ""
})
break
case "编排":
can.page.Select(can, target, "fieldset.item", function(item) {
item.setAttribute("draggable", true)
item.ondragstart = function(event) {can.drag = event.target}
item.ondragover = function(event) {event.preventDefault()}
item.ondrop = function(event) {event.preventDefault()
item.parentNode.insertBefore(can.drag, item)
}
})
break
case "定位":
var max = 0;
var current, begin;
can.page.Select(can, target, "fieldset.item", function(item) {
item.style.left = item.offsetLeft + "px"
item.style.top = item.offsetTop + "px"
})
can.page.Select(can, target, "fieldset.item", function(item) {
item.style.position = "absolute"
item.onmousedown = function(event) {
if (can.Action("action") != "定位") {return}
if (current) {
current.style.left = event.clientX - begin.x + begin.left + "px"
current.style.top = event.clientY - begin.y + begin.top + "px"
current = null;
return
}
current = event.target;
current.style["z-index"] = max = max + 1
begin = {x: event.clientX, y: event.clientY, left: item.offsetLeft, top: item.offsetTop}
};
target.onmousemove = item.onmousemove = function(event) {if (!current) {return}
current.style.left = event.clientX - begin.x + begin.left + "px"
current.style.top = event.clientY - begin.y + begin.top + "px"
}
})
break
}
},
}) })
Volcanos("onchoice", {help: "组件菜单", list: ["保存", "刷新", "共享"]})
Volcanos("ondetail", {help: "组件详情", list: []}) Volcanos("ondetail", {help: "组件详情", list: []})
Volcanos("onexport", {help: "导出数据", list: []}) Volcanos("onexport", {help: "导出数据", list: []})

View File

@ -1,10 +1,4 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: []})
_init: function(can, conf, output, action, option, field) {
},
favor: function(event, can, value, cmd, output) {
console.log(can.base.Time(), value)
},
})
Volcanos("onaction", {help: "组件交互", list: []}) Volcanos("onaction", {help: "组件交互", list: []})
Volcanos("onchoice", {help: "组件菜单", list: []}) Volcanos("onchoice", {help: "组件菜单", list: []})
Volcanos("ondetail", {help: "组件详情", list: []}) Volcanos("ondetail", {help: "组件详情", list: []})

View File

@ -5,36 +5,33 @@ Volcanos("onimport", {help: "导入数据", list: [],
can.target.style.width = "" can.target.style.width = ""
function res(msg) { function res(msg) {
if (msg._hand) {ui.cmd.value = ""; if (msg._hand) {ui.cmd.value = "", output.innerHTML = "";
output.innerHTML = msg.Result() msg.result && msg.result.length > 0? can.page.Append(can, output, [{text: msg.Result()}]):
can.page.AppendTable(can, output, msg, msg.append);
} }
return msg return msg
} }
function run(event, cmds) {cmds = cmds.trim().split(" "); function run(event, cmds) {cmds = can.core.Split(cmds);
var cmd = cmds[0]; if (cmd == "") {return} var cmd = cmds[0]; if (cmd == "") {return}
var msg = can.Event(event, {detail: cmds}); can.msg = can.Event(event, {detail: cmds});
can.msg = msg;
var cb = can.onexport[cmd]; var cb = can.onexport[cmd];
typeof cb == "function"? cb(event, can, msg, cmds, output): can.Export(event, msg, "favor"); typeof cb == "function"? cb(event, can, can.msg, cmds, output): can.Export(event, can.msg, "favor");
return can.msg._hand? res(can.msg): can.run(event, cmds, res, true);
return msg._hand? res(msg): can.run(event, cmds, res, true);
} }
var ui = can.page.Append(can, option, [{input: ["cmd", function(event) { var ui = can.page.Append(can, option, [{input: ["cmd", function(event) {
can.page.oninput(event, can)
switch (event.key) { switch (event.key) {
case "Enter": run(event, event.target.value); break case "Enter": run(event, event.target.value); return
case "Escape": can.Hide(); break case "Escape": can.Hide(); return
default: if (event.target.value.endsWith("j") && event.key == "k") { default: if (event.target.value.endsWith("j") && event.key == "k") {
can.page.DelText(event.target, event.target.selectionStart-1, 2) can.page.DelText(event.target, event.target.selectionStart-1, 2)
event.target.value == ""? can.Hide(): run(event, event.target.value) event.target.value == ""? can.Hide(): run(event, event.target.value)
break return
} return false }
} }
event.stopPropagation()
event.preventDefault() can.page.oninput(event, can)
return true return true
}, function(event) { }, function(event) {
switch (event.key) { switch (event.key) {
@ -45,8 +42,14 @@ Volcanos("onimport", {help: "导入数据", list: [],
return true return true
}]}]) }]}])
}, },
space: function(event, can, value, cmd, field) {
can.page.Select(can, can.Show(), "input.cmd", function(item) {
item.focus()
})
},
}) })
Volcanos("onaction", {help: "组件交互", list: [], Volcanos("onaction", {help: "组件交互", list: ["关闭", "清空", "下载"],
onmousedown: function(event, can) { onmousedown: function(event, can) {
if (event.ctrlKey) {can.moving = !can.moving, can.movarg = { if (event.ctrlKey) {can.moving = !can.moving, can.movarg = {
left: can.target.offsetLeft, left: can.target.offsetLeft,
@ -61,18 +64,21 @@ Volcanos("onaction", {help: "组件交互", list: [],
} }
}, },
onmouseup: function(event, can) { onmouseup: function(event, can) {
// can.moving = false;
}, },
}) "关闭": function(event, can, value, cmd, field) {
Volcanos("onchoice", {help: "组件菜单", list: ["下载"], can.Hide();
"下载": function(event, can, msg, cmd, target) {msg = msg || can.msg; },
var list = msg.Export(can._name); "清空": function(event, can, value, cmd, field) {
can.output.innerHTML = ""
},
"下载": function(event, can, value, cmd, field) {
var list = can.msg.Export(can._name);
can.page.Download(can, list[0]+list[1], list[2]); can.page.Download(can, list[0]+list[1], list[2]);
}, },
}) })
Volcanos("onchoice", {help: "组件菜单", list: ["下载", "关闭"]})
Volcanos("ondetail", {help: "组件详情", list: []}) Volcanos("ondetail", {help: "组件详情", list: []})
Volcanos("onexport", {help: "导出数据", list: [], Volcanos("onexport", {help: "导出数据", list: [],
hi: function(event, can, msg, cmd, output) {msg.Echo("hello world")}, time: function(event, can, msg, cmd, field) {msg.Echo(can.base.Time())},
time: function(event, can, msg, cmd, output) {msg.Echo(can.base.Time())},
}) })

View File

@ -1,19 +1,19 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: [],
_init: function(can, conf, output, action, option, field) {output.innerHTML = ""; _init: function(can, conf, output, action, option, field) {output.innerHTML = "";
conf.title && can.page.Append(can, output, [{view: "title", list: [{text: conf.title, className: "title"}]}]) conf.title && can.page.Append(can, output, [{view: "title", list: [{text: conf.title, className: "title"}]}])
can.ui = can.page.Append(can, output, [{view: "state", list: can.core.List(conf.state, function(item) { can.ui = can.page.Append(can, output, [{view: "state", list: can.core.List(conf.state, function(item) {
return {text: conf[item]||"", className: item, click: function(event) {var cb = can.onexport[item]; return {text: conf[item]||"", className: item, click: function(event) {can.Export(event, conf[item], item)}};
typeof cb == "function" && cb(event, can, item, item, output)
}};
})}]) })}])
}, },
email: function(event, can, value, cmd, output) {
email: function(event, can, value, cmd, field) {
can.ui[cmd].innerHTML = value can.ui[cmd].innerHTML = value
}, },
ntxt: function(event, can, value, cmd, output) {var state = can.Conf(cmd); ntxt: function(event, can, value, cmd, field) {var state = can.Conf(cmd);
can.ui[cmd].innerHTML = cmd+":"+ can.Conf(cmd, can.base.Int(value)+can.base.Int(state)) can.ui[cmd].innerHTML = cmd+":"+ can.Conf(cmd, can.base.Int(value)+can.base.Int(state))
}, },
ncmd: function(event, can, value, cmd, output) {var state = can.Conf(cmd); ncmd: function(event, can, value, cmd, field) {var state = can.Conf(cmd);
can.ui[cmd].innerHTML = cmd+":"+ can.Conf(cmd, can.base.Int(value)+can.base.Int(state)) can.ui[cmd].innerHTML = cmd+":"+ can.Conf(cmd, can.base.Int(value)+can.base.Int(state))
}, },
}) })

View File

@ -1,37 +1,34 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: [],
_init: function(can, conf, output, action, option, field) {output.innerHTML = ""; _init: function(can, conf, output, action, option, field) {output.innerHTML = "";
conf.title && can.page.Append(can, output, [{view: "title", conf.title && can.page.Append(can, output, [{view: "title",
list: [{text: conf.title, className: "title"}], click: function(event) {can.onexport.title(event, can)}}]) list: [{text: conf.title, className: "title"}], click: function(event) {can.Export(event, conf.title, "title")}}])
can.ui = can.page.Append(can, output, [{view: "state", list: can.core.List(conf.state, function(item) { can.ui = can.page.Append(can, output, [{view: "state", list: can.core.List(conf.state, function(item) {
return {text: conf[item]||"", className: item, click: function(event) {var cb = can.onexport[item]; return {text: conf[item]||"", className: item, click: function(event) {can.Export(event, conf[item], item)}};
typeof cb == "function" && cb(event, can, item, item, output)
}};
})}]) })}])
can.timer = can.Timer({interval: 1000, length: -1}, function() { can.timer = can.Timer({interval: 1000, length: -1}, function(event) {
can.ui.time.innerHTML = can.base.Time().split(" ")[1] can.Import(event, can.base.Time().split(" ")[1], "time")
}) })
}, },
title: function(event, can, value, cmd, output) { title: function(event, can, value, cmd, field) {
can.ui[cmd].innerHTML = value can.ui[cmd].innerHTML = value
}, },
username: function(event, can, value, cmd, output) { username: function(event, can, value, cmd, field) {
value.length > 10 && (value = value.slice(0, 8))
can.ui["user"].innerHTML = value can.ui["user"].innerHTML = value
}, },
time: function(event, can, value, cmd, output) { time: function(event, can, value, cmd, field) {
can.ui[cmd].innerHTML = value can.ui[cmd].innerHTML = value
}, },
link: function(event, can, value, cmd, output) {
can.ui[cmd].innerHTML = value river: function(event, can, value, cmd, field) {if (value == "update") {return}
},
river: function(event, can, value, cmd, output) {if (value == "update") {return}
can.Conf("river", value) can.Conf("river", value)
}, },
storm: function(event, can, value, cmd, output) {if (value == "update") {return} storm: function(event, can, value, cmd, field) {if (value == "update") {return}
can.Conf("storm", value) can.Conf("storm", value)
}, },
layout: function(event, can, value, cmd, output) {if (value == "update") {return} layout: function(event, can, value, cmd, field) {if (value == "update") {return}
can.Conf("layout", value) can.Conf("layout", value)
}, },
}) })
@ -39,26 +36,19 @@ Volcanos("onaction", {help: "组件交互", list: []})
Volcanos("onchoice", {help: "组件菜单", list: []}) Volcanos("onchoice", {help: "组件菜单", list: []})
Volcanos("ondetail", {help: "组件详情", list: []}) Volcanos("ondetail", {help: "组件详情", list: []})
Volcanos("onexport", {help: "导出数据", list: [], Volcanos("onexport", {help: "导出数据", list: [],
title: function(event, can, value, cmd, output) { title: function(event, can, value, cmd, field) {
var args = { var args = {river: can.Conf("river"), storm: can.Conf("storm"), layout: can.Conf("layout")}
river: can.Conf("river"),
storm: can.Conf("storm"), can.page.Select(can, field, "div.action>input", function(input) {
layout: can.Conf("layout"), input.name && input.value && (args[input.name] = input.value)
}
can.page.Select(can, document.body, "fieldset.Action>div.action>input", function(input) {
args[input.name] = input.value
}) })
can.user.Search(can, args) can.user.Search(can, args)
}, },
link: function(event, can, value, cmd, output) { user: function(event, can, value, cmd, field) {
can.ui[cmd].innerHTML = value
},
user: function(event, can, value, cmd, output) {
if (can.user.confirm("logout?")) { if (can.user.confirm("logout?")) {
can.user.Cookie(can, "sessid", "") can.user.Cookie(can, "sessid", "")
can.user.reload() can.user.reload()
} }
can.ui["user"].innerHTML = value
}, },
}) })

View File

@ -5,6 +5,19 @@ Volcanos("onimport", {help: "导入数据", list: [],
can.onaction.login(event, can, cb, "login", output) can.onaction.login(event, can, cb, "login", output)
} }
}, },
share: function(event, can, value, cmd, target) {var msg = can.Event(event)
var list = [];
switch (value) {
case "storm": list.push("river", msg.Conf("river")); break
case "action": list.push("river", msg.Conf("river")), list.push("storm", msg.Conf("storm")); break
}
can.run(event, ["share", value, msg.Option("name"), msg.Option("text")].concat(list), function(msg) {
var p = "/share/" + msg.Result(); can.user.toast({title: msg.Option("name"),
text: [{text: can.user.Share(can, {path: p}, true)}, {img: p+"/qrcode"}],
width: 300, height: 400, duration: 300000,
})
})
},
}) })
Volcanos("onaction", {help: "组件交互", list: [], Volcanos("onaction", {help: "组件交互", list: [],
check: function(event, can, cb, cmd, target) { check: function(event, can, cb, cmd, target) {
@ -41,7 +54,7 @@ Volcanos("onaction", {help: "组件交互", list: [],
break break
case "sessid": case "sessid":
can.user.Cookie(can, "sessid", msg.detail[1]) can.user.Cookie(can, "sessid", msg.detail[1])
can.Hide(), typeof cb == "function" && cb({name: user}) can.Hide(), typeof cb == "function" && cb({name: msg["user.name"]})
can.user.toast("") can.user.toast("")
return true return true
} }
@ -52,8 +65,7 @@ Volcanos("onaction", {help: "组件交互", list: [],
can.Show(event, -1, -1) can.Show(event, -1, -1)
}, },
socket: function(event, can, value, cmd, output) {can._username = value socket: function(event, can, value, cmd, output) {can._username = value
// location.protocol.replace("http", "ws")+"//"+location.host+"/space/?"+ return can._socket = can._socket || can.misc.WSS(can, "wss://shylinux.com/space/", {node: "active", name: ""}, function(event, msg) {
return can._socket = can._socket || can.misc.WSS(can, function(event, msg) {
if (msg.Option("_handle")) {return can.user.toast(msg.result.join(""))} if (msg.Option("_handle")) {return can.user.toast(msg.result.join(""))}
if (typeof cmd == "function" && cmd(event, msg)) {return msg.Reply(msg)} if (typeof cmd == "function" && cmd(event, msg)) {return msg.Reply(msg)}

View File

@ -20,8 +20,8 @@ Volcanos("onimport", {help: "导入数据", list: [],
]}]) ]}])
can.ui = ui can.ui = ui
}, },
init: function(event, can, msg, key, output) {output.innerHTML = ""; init: function(event, can, msg, key, field) {can.output.innerHTML = "";
var table = can.page.Append(can, output, "table"); var table = can.page.Append(can, can.output, "table");
can.page.Appends(can, table, [{text: ["1. 选择用户节点 ->", "caption"]}]) can.page.Appends(can, table, [{text: ["1. 选择用户节点 ->", "caption"]}])
can.page.AppendTable(can, table, msg, ["username", "usernode"], function(event, value, key, index, tr, td) {tr.className = "hidden"; can.page.AppendTable(can, table, msg, ["username", "usernode"], function(event, value, key, index, tr, td) {tr.className = "hidden";
@ -33,36 +33,23 @@ Volcanos("onimport", {help: "导入数据", list: [],
}}]) }}])
}) })
}, },
ocean: function(event, can, value, key, output) { ocean: function(event, can, value, key, field) {
if (value == "create") {can.Show(event); if (value == "create") {can.Show(event);
can.run(event, [], function(msg) { can.run(event, [], function(msg) {
can.onimport.init(event, can, msg, key, output); can.onimport.init(event, can, msg, key, field);
}); });
} }
}, },
}) })
Volcanos("onaction", {help: "组件交互", list: ["关闭", "刷新"], Volcanos("onaction", {help: "组件交互", list: ["关闭", "刷新"],
"关闭": function(event, can, meta, key, output) { "关闭": function(event, can, meta, key, field) {
can.Hide() can.Hide()
}, },
"刷新": function(event, can, meta, key, output) { "刷新": function(event, can, meta, key, field) {
can.run(event, [], function(msg) { can.Import(event, "create", "ocean")
can.onimport.init(event, can, msg, key, output)
})
},
})
Volcanos("onchoice", {help: "组件菜单", list: ["关闭", "刷新"],
"关闭": function(event, can, msg, key, target) {
can.onaction[key](event, can, key, can.output)
},
"刷新": function(event, can, msg, key, target) {
can.onaction[key](event, can, key, can.output)
},
})
Volcanos("ondetail", {help: "组件详情", list: ["共享"],
"共享": function(event, can, line, key, target) {
can.user.toast(can.user.Share(can, {river: line.key}), "共享链接", 10000)
}, },
}) })
Volcanos("onchoice", {help: "组件菜单", list: ["关闭", "刷新"]})
Volcanos("ondetail", {help: "组件详情", list: []})
Volcanos("onexport", {help: "导出数据", list: []}) Volcanos("onexport", {help: "导出数据", list: []})

View File

@ -1,23 +1,20 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: [],
_init: function(can, conf, output, action, option, field) { init: function(event, can, msg, cmd, field) {can.output.innerHTML = "";
}, can.page.AppendItem(can, can.output, msg.Table(), can.user.Search(can, can.name()), function(event, line, item) {
init: function(event, can, msg, key, output) {output.innerHTML = ""; can.Export(event, line.key, can.name())
can.page.AppendItem(can, output, msg.Table(), can.user.Search(can, "river"), function(event, line, item) {
can.Export(event, line.key, "river")
}) })
}, },
river: function(event, can, value, key, output) {if (value == "update") { river: function(event, can, value, cmd, field) {if (value == "update") {
can.run(event, [], function(msg) { can.run(event, [], function(msg) {
can.onimport.init(event, can, msg, key, output) can.onimport.init(event, can, msg, cmd, field)
}) })
}}, }},
favor: function(event, can, msg, cmd, output) {var key = msg.detail[0]; favor: function(event, can, msg, cmd, field) {if (msg._hand) {return}
if (msg._hand) {return} var cmds = msg.detail, key = cmds[0];
var cb = can.onaction[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onaction ", key), msg._hand = true} if (key == can.name()) {key = cmds[1], cmds = cmds.slice(1)}
var cb = can.onchoice[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onchoice ", key), msg._hand = true}
can.page.Select(can, output, "div.item>span", function(item) { can.page.Select(can, field, "div.item>span", function(item) {
if (item.innerText == msg.detail[0]) { if (item.innerText == key) {
item.click(), msg._hand = true; item.click(), msg._hand = true;
msg.Echo(can._name, " ", key) msg.Echo(can._name, " ", key)
} }
@ -25,22 +22,58 @@ Volcanos("onimport", {help: "导入数据", list: [],
}, },
}) })
Volcanos("onaction", {help: "组件交互", list: ["创建", "刷新"], Volcanos("onaction", {help: "组件交互", list: ["创建", "刷新"],
"创建": function(event, can, meta, key, output) { "创建": function(event, can, meta, cmd, field) {
can.Export(event, "create", "ocean") can.Export(event, "create", "ocean")
}, },
"刷新": function(event, can, meta, key, output) { "刷新": function(event, can, meta, cmd, field) {
can.Import(event, "update", "river") can.Import(event, "update", can.name())
},
})
Volcanos("onchoice", {help: "组件菜单", list: ["创建", "刷新"]})
Volcanos("ondetail", {help: "组件详情", list: ["共享"],
"共享": function(event, can, line, key, target) {
can.Export(event, "river", "share")
},
})
Volcanos("onexport", {help: "导出数据", list: [],
share: function(event, can, line, key, target) {
can.user.toast(can.user.Share(can, {river: line.key}), "共享链接", 10000)
}, },
}) })
Volcanos("onchoice", {help: "组件菜单", list: ["创建", "刷新", "宽度"],
"宽度": function(event, can, meta, cmd, field) {
var begin;
function end() {
field.onmousedown = null;
field.onmousemove = null;
field.style.cursor = "";
begin = null;
}
field.style.cursor = "e-resize"
field.onmousedown = function(event) {if (begin) {return end()}
begin = {x: event.clientX, width: field.offsetWidth}
}
field.onmousemove = function(event) {if (!begin) {return}
field.dataset.width = field.style.width = begin.width + event.clientX - begin.x + "px";
can.Export(event, "", "layout");
}
can.user.prompt("输入宽度", function(width) {
field.dataset.width = field.style.width = width + "px"
can.Export(event, "", "layout")
end()
}, field.offsetWidth)
},
})
Volcanos("ondetail", {help: "组件详情", list: ["共享", "重命名", "删除"],
"共享": function(event, can, line, value, cmd, item) {
var msg = can.Event(event);
msg.Option("name", line.name)
msg.Option("text", line.key)
can.Export(event, can.name(), "share")
},
"重命名": function(event, can, line, value, cmd, item) {
can.user.prompt("输入新名:", function(name) {
can.run(event, [value, "rename", name], function(msg) {
can.Import(event, "update", can.name())
})
}, line.name)
},
"删除": function(event, can, line, value, cmd, item) {
can.run(event, [value, "remove"], function(msg) {
can.Import(event, "update", can.name())
})
},
})
Volcanos("onexport", {help: "导出数据", list: []})

View File

@ -1,7 +1,4 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: []})
_init: function(can, conf, output, action, option, field) {
},
})
Volcanos("onaction", {help: "组件交互", list: []}) Volcanos("onaction", {help: "组件交互", list: []})
Volcanos("onchoice", {help: "组件菜单", list: []}) Volcanos("onchoice", {help: "组件菜单", list: []})
Volcanos("ondetail", {help: "组件详情", list: []}) Volcanos("ondetail", {help: "组件详情", list: []})

View File

@ -49,7 +49,7 @@ Volcanos("onimport", {help: "导入数据", list: [],
var node = msg.name[index]; var node = msg.name[index];
can.run(event, [can.Conf("river"), msg.user[index], node], function(com) {var list = com.Table() can.run(event, [can.Conf("river"), msg.user[index], node], function(com) {var list = com.Table()
can.page.Appends(can, can.device, [{text: ["2. 选择模块命令 ->", "caption"]}]) can.page.Appends(can, can.device, [{text: ["2. 选择模块命令 ->", "caption"]}])
var table = can.page.AppendTable(can, can.device, com, ["key", "index", "name", "help"], function(event, value, key, index, tr, td) { can.com = list, can.command = can.page.AppendTable(can, can.device, com, ["key", "index", "name", "help"], function(event, value, key, index, tr, td) {
var line = list[index]; var line = list[index];
line.pod = node; line.pod = node;
var last = can.page.Append(can, can.ui.list, [{ var last = can.page.Append(can, can.ui.list, [{
@ -65,42 +65,49 @@ Volcanos("onimport", {help: "导入数据", list: [],
}) })
}), table.querySelector("td").click() }), table.querySelector("td").click()
}, },
steam: function(event, can, value, key, output) { steam: function(event, can, value, key, field) {
if (value == "create") { if (value == "create") {
can.run(event, [can.Conf("river")], function(msg) { can.run(event, [can.Conf("river")], function(msg) {
can.onimport.init(event, can, msg, key, output); can.onimport.init(event, can, msg, key, field);
}); });
} }
}, },
river: function(event, can, value, key, output) { river: function(event, can, value, key, field) {if (value == "update") {return}
if (value == "update") {return}
can.Conf("river", value) can.Conf("river", value)
}, },
storm: function(event, can, value, key, output) { storm: function(event, can, value, key, field) {if (value == "update") {return}
if (value == "update") {return}
can.Conf("storm", value) can.Conf("storm", value)
}, },
}) })
Volcanos("onaction", {help: "组件交互", list: ["关闭", "刷新", {input: "pod"}], Volcanos("onaction", {help: "组件交互", list: ["关闭", "刷新", {input: ["pod"]}, {input: ["cmd", function(event, can) {
"关闭": function(event, can, meta, key, output) { }, function(event, can) {
if (event.key == "Enter") {
can.page.Select(can, can.command, "tr", function(tr, index) {
if (index == 0) {return}
if (!can.page.ClassList.has(can, tr, "hidden")) {
tr.firstChild.click()
event.target.value = ""
}
})
return
}
can.page.Select(can, can.command, "tr", function(tr, index) {
if (index == 0) {return}
if (can.com[index-1].index.indexOf(event.target.value) > -1) {
can.page.ClassList.del(can, tr, "hidden")
} else {
can.page.ClassList.add(can, tr, "hidden")
}
})
}]}],
"关闭": function(event, can, meta, key, field) {
can.Hide() can.Hide()
}, },
"刷新": function(event, can, meta, key, output) { "刷新": function(event, can, meta, key, field) {
can.run(event, [], function(msg) { can.Import(event, "create", "steam")
can.onimport.init(event, can, msg, key, output)
})
}, },
}) })
Volcanos("onchoice", {help: "组件菜单", list: ["关闭", "刷新"]}) Volcanos("onchoice", {help: "组件菜单", list: ["关闭", "刷新"]})
Volcanos("ondetail", {help: "组件详情", list: ["创建", "删除", "共享"], Volcanos("ondetail", {help: "组件详情", list: []})
"创建": function(event, can, msg, value, key, index, td) {
can.run(event, [can.Conf("river"), "spawn", msg.key[index]], function(msg) {
can.Hide(), can.Export(event, "update", "storm");
})
},
"共享": function(event, can, msg, value, key, index, td) {
can.user.toast(can.user.Share(can, {storm: line.key}), "共享链接", 10000)
},
})
Volcanos("onexport", {help: "导出数据", list: []}) Volcanos("onexport", {help: "导出数据", list: []})

View File

@ -1,88 +1,86 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: [],
init: function(event, can, msg, cmd, output) {output.innerHTML = ""; init: function(event, can, msg, cmd, field) {can.output.innerHTML = "";
can.page.AppendItem(can, output, msg.Table(), can.user.Search(can, "storm"), function(event, line, item) { can.page.AppendItem(can, can.output, msg.Table(), can.user.Search(can, can.name()), function(event, line, item) {
can.Export(event, line.key, "storm") can.Export(event, line.key, can.name())
}) })
}, },
layout: function(event, can, value, cmd, output) { river: function(event, can, value, cmd, field) {if (value == "update") {return}
can.Conf("layout", value)
},
river: function(event, can, value, cmd, output) {
if (value == "update") {return}
can.run(event, [can.Conf("river", value)], function(msg) { can.run(event, [can.Conf("river", value)], function(msg) {
can.onimport.init(event, can, msg, cmd, output) can.onimport.init(event, can, msg, cmd, field)
}) })
}, },
storm: function(event, can, value, cmd, output) { storm: function(event, can, value, cmd, field) {
if (value == "update") { if (value == "update") {
can.run(event, [can.Conf("river")], function(msg) { can.run(event, [can.Conf("river")], function(msg) {
can.onimport.init(event, can, msg, cmd, output) can.onimport.init(event, can, msg, cmd, field)
}) })
} else { } else {
can.Conf("storm", value) can.Conf(can.name(), value)
} }
}, },
favor: function(event, can, msg, cmd, output) {var key = msg.detail[0]; favor: function(event, can, msg, cmd, field) {if (msg._hand) {return}
if (msg._hand) {return} var cmds = msg.detail, key = cmds[0];
var cb = can.onaction[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onaction ", key), msg._hand = true} if (key == "river") {key = cmds[1], cmds = cmds.slice(1)}
var cb = can.onchoice[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onchoice ", key), msg._hand = true}
can.page.Select(can, field, "div.item>span", function(item) {
can.page.Select(can, output, "div.item.k"+msg.detail[0], function(item) { if (item.innerText == key) {
item.click(), msg._hand = true; item.click(), msg._hand = true;
msg.Echo(can._name, " ", key) msg.Echo(can._name, " ", key)
}
}) })
}, },
}) })
Volcanos("onaction", {help: "组件交互", list: ["创建", "刷新", "共享"], Volcanos("onaction", {help: "组件交互", list: ["创建", "刷新"],
"创建": function(event, can, meta, cmd, output) { "创建": function(event, can, meta, cmd, field) {
can.Export(event, "create", "steam") can.Export(event, "create", "steam")
}, },
"刷新": function(event, can, meta, cmd, output) { "刷新": function(event, can, meta, cmd, field) {
can.run(event, [can.Conf("river")], function(msg) { can.Import(event, "update", can.name())
can.onimport.init(event, can, msg, cmd, output)
})
},
"共享": function(event, can, meta, cmd, output) {
can.ondetail[cmd](event, can, meta, "", cmd, output)
}, },
}) })
Volcanos("onchoice", {help: "组件菜单", list: ["创建", "刷新"], Volcanos("onchoice", {help: "组件菜单", list: ["创建", "刷新", "宽度"],
"创建": function(event, can, msg, cmd, output) { "宽度": function(event, can, meta, cmd, field) {
can.Export(event, "create", "steam") var begin;
}, function end() {
"刷新": function(event, can, msg, cmd, output) { field.onmousedown = null;
can.run(event, [can.Conf("river")], function(msg) { field.onmousemove = null;
can.onimport.init(event, can, msg, cmd, output) field.style.cursor = "";
}) begin = null;
}
field.style.cursor = "w-resize"
field.onmousedown = function(event) {if (begin) {return end()}
begin = {x: event.clientX, width: field.offsetWidth}
}
field.onmousemove = function(event) {if (!begin) {return}
field.dataset.width = field.style.width = begin.width - event.clientX + begin.x + "px";
can.Export(event, "", "layout");
}
can.user.prompt("输入宽度", function(width) {
field.dataset.width = field.style.width = width + "px"
can.Export(event, "", "layout")
end()
}, field.offsetWidth)
}, },
}) })
Volcanos("ondetail", {help: "组件详情", list: ["共享", "保存", "恢复", "重命名", "删除"], Volcanos("ondetail", {help: "组件详情", list: ["共享", "重命名", "删除"],
"共享": function(event, can, line, value, cmd, item) {can.share || (can.share = {}); "共享": function(event, can, line, value, cmd, item) {can.share || (can.share = {});
var p = can.user.Share(can, {layout: can.Conf("layout"), river: can.Conf("river"), storm: can.Conf("storm")}, true) var msg = can.Event(event);
if (can.share[p]) { msg.Option("name", line.name)
can.user.toast({duration: 10000, height: 300, text: p, list: [{img: [can.user.Share(can, {path: "/share/"+can.share[p]}, true)]}]}); msg.Option("text", line.key)
} else { can.Export(event, can.name(), "share")
can.run(event, [can.Conf("river"), can.Conf("storm"), "share", "qrcode", can.Conf("storm"), p], function(msg) {
can.share[p] = msg.Result();
can.user.toast({duration: 10000, height: 300, text: p, list: [{img: [can.user.Share(can, {path: "/share/"+msg.Result()}, true)]}]});
})
}
}, },
"重命名": function(event, can, line, value, cmd, item) { "重命名": function(event, can, line, value, cmd, item) {
can.user.prompt("输入新名:", function(name) { can.user.prompt("输入新名:", function(name) {
can.run(event, [can.Conf("river"), value, "rename", name], function(msg) { can.run(event, [can.Conf("river"), value, "rename", name], function(msg) {
can.run(event, [can.Conf("river")], function(msg) { can.Import(event, "update", can.name())
can.onimport.init(event, can, msg, cmd, can.output)
})
}) })
}) }, line.name)
}, },
"删除": function(event, can, line, value, cmd, item) { "删除": function(event, can, line, value, cmd, item) {
can.run(event, [can.Conf("river"), value, "remove"], function(msg) { can.run(event, [can.Conf("river"), value, "remove"], function(msg) {
can.run(event, [can.Conf("river")], function(msg) { can.Import(event, "update", can.name())
can.onimport.init(event, can, msg, cmd, can.output)
})
}) })
}, },
}) })

View File

@ -1,7 +1,4 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: []})
_init: function(can, conf, output, action, option, field) {
},
})
Volcanos("onaction", {help: "组件交互", list: []}) Volcanos("onaction", {help: "组件交互", list: []})
Volcanos("onchoice", {help: "组件菜单", list: []}) Volcanos("onchoice", {help: "组件菜单", list: []})
Volcanos("ondetail", {help: "组件详情", list: []}) Volcanos("ondetail", {help: "组件详情", list: []})

View File

@ -5,12 +5,12 @@ Volcanos("onimport", {help: "导入数据", list: [],
can.target.style.width = "" can.target.style.width = ""
var timer; var timer;
can.user.toast = function(text, title, duration, list) {if (!text) {return can.Hide()} can.user.toast = function(text, title, duration, action) {if (!text) {return can.Hide()}
text = typeof text == "object"? text: {list: list, text: text, title: title||""} text = typeof text == "object"? text: {list: action, text: text, title: title||""}
text.duration = text.duration || conf.duration || 3000 text.duration = text.duration || conf.duration || 3000
var list = [{text: [text.title||"", "div", "title"]}, var list = [{text: [text.title||"", "div", "title"]},
{text: [text.text||"", "div", "content"]}, typeof text.text == "string"? {text: [text.text||"", "div", "content"]}: {view: "content", list: text.text},
{view: ["form"], list: text.list||[{type: "button", inner: "ok", click: function() { {view: ["form"], list: text.list||[{type: "button", inner: "ok", click: function() {
timer.stop = true timer.stop = true
}}]}, }}]},

View File

@ -1,7 +1,4 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: []})
_init: function(can, conf, output, action, option, field) {
},
})
Volcanos("onaction", {help: "组件交互", list: []}) Volcanos("onaction", {help: "组件交互", list: []})
Volcanos("onchoice", {help: "组件菜单", list: []}) Volcanos("onchoice", {help: "组件菜单", list: []})
Volcanos("ondetail", {help: "组件详情", list: []}) Volcanos("ondetail", {help: "组件详情", list: []})

View File

@ -1,6 +1,4 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: [],
_begin: function(can) {},
_start: function(can) {},
init: shy("添加控件", function(can, item, name, value, option) { init: shy("添加控件", function(can, item, name, value, option) {
var input = {type: "input", name: name, data: item}; var input = {type: "input", name: name, data: item};
item.type = item.type || item._type || item._input; item.type = item.type || item._type || item._input;
@ -27,14 +25,15 @@ Volcanos("onimport", {help: "导入数据", list: [],
case "button": case "button":
item.value = item.value || item.name; item.value = item.value || item.name;
} }
can.page.ClassList.add(can, item, item.view); can.page.ClassList.add(can, item, item.view);
can.core.List((item.clist||"").split(" "), function(value) { can.core.List((item.clist||"").split(" "), function(value) {
can.page.ClassList.add(can, item, value); can.page.ClassList.add(can, item, value);
}) })
var target = can.Dream(option, "input", input)[input.name]; var target = can.Dream(option, "input", input)[input.name];
!target.placeholder && (target.placeholder = item.name || ""); !target.placeholder && (target.placeholder = item.name || "");
// (item.type == "text" || item.type == "textarea") && !target.placeholder && (target.placeholder = item.name || "");
item.type == "text" && !target.title && (target.title = item.placeholder || item.name || ""); item.type == "text" && !target.title && (target.title = item.placeholder || item.name || "");
item.type == "button" && item.action == "auto" && can.run && can.run({}); item.type == "button" && item.action == "auto" && can.run && can.run({});
item.type == "textarea" && can.page.Append(can, option, [{type: "br"}]) item.type == "textarea" && can.page.Append(can, option, [{type: "br"}])
@ -45,153 +44,7 @@ Volcanos("onimport", {help: "导入数据", list: [],
return target.value + (target.value == "" || target.value.endsWith("/")? "": "/") + value return target.value + (target.value == "" || target.value.endsWith("/")? "": "/") + value
}, },
}) })
Volcanos("onfigure", {help: "控件详情", list: [], Volcanos("onfigure", {help: "控件交互", list: []})
key: {click: function(event, can, value, cmd, target) {
function add(msg, list, update) {
can.page.Append(can, can.figure.output, [{view: "list", list: can.core.List(list, function(item) {
return {text: [item, "div", "label"], onclick: function(event) {
target.value = item;
update && can.history.unshift(item);
msg.Option("_refresh") && run()
}}
})}])
}
function run() {can.figure.output.innerHTML = ""
can.Run(event, ["action", "input", can.item.name, target.value], function(msg) {
add(msg, can.history), can.core.List(msg.append, function(key) {add(msg, msg[key], true)})
}, true)
}
can.history = can.history || [];
can.onfigure._prepare(event, can, value, cmd ,target) && run()
}},
date: {click: function(event, can, value, cmd, target) {if (can.date) {return}
target.style.width = "120px"
function set(now) {
target.value = can.base.Time(now);
if (can.item.action == "auto") {
can.run({});
}
}
can.stick = false
can.now = target.value? new Date(target.value): new Date();
can.date = can.page.Append(can, document.body, [{view: ["date input", "fieldset"], style: {
position: "absolute", left: event.clientX+"px", top: event.clientY+10+"px",
}, onmouseleave: function(event) {
if (can.stick) {can.stick = false; return}
can.page.Remove(can, can.date); delete(can.date);
}}]).last
var action = can.page.Append(can, can.date, [{view: ["action"]}]).last
var control = can.page.AppendAction(can, action, ["今天", "随机",
["hour"].concat(can.core.List(24)), ["minute"].concat(can.core.List(0, 60, 5)), ["second"].concat(can.core.List(0, 60, 5)), {view: ["", "br"]},
"上一月", ["year"].concat(can.core.List(can.now.getFullYear() - 20, can.now.getFullYear() + 20)),
["month"].concat(can.core.List(1, 13)), "下一月", {view: ["", "br"]},
], function(event, value, cmd) {can.stick = true;
switch (cmd) {
case "year": can.now.setFullYear(parseInt(value)); show(can.now); return;
case "month": can.now.setMonth(parseInt(value)-1); show(can.now); return;
case "hour": can.now.setHours(parseInt(value)); show(can.now); set(can.now); return;
case "minute": can.now.setMinutes(parseInt(value)); show(can.now); set(can.now); return;
case "second": can.now.setSeconds(parseInt(value)); show(can.now); set(can.now); return;
}
switch (value) {
case "今天": can.now = new Date(); show(can.now); set(can.now); break;
case "随机": can.now.setDate((Math.random() * 100 - 50) + can.now.getDate()); show(can.now); set(can.now); break;
case "关闭":can.page.Remove(can, can.date); delete(can.date);
case "前一年": can.now.setFullYear(can.now.getFullYear()-1); show(can.now); break;
case "后一年": can.now.setFullYear(can.now.getFullYear()+1); show(can.now); break;
case "上一月": can.now.setMonth(can.now.getMonth()-1); show(can.now); break;
case "下一月": can.now.setMonth(can.now.getMonth()+1); show(can.now); break;
}
})
var table = can.page.Append(can, can.date, [{type: "table"}]).table
function click(event) {
var day = new Date(parseInt(event.target.dataset.date))
can.now = day;
set(can.now);
}
function show(now) {
control.month.value = now.getMonth()+1;
control.year.value = now.getFullYear();
control.hour.value = now.getHours();
control.minute.value = parseInt(now.getMinutes()/5)*5;
control.second.value = parseInt(now.getSeconds()/5)*5;
var meta = ["日", "一", "二", "三", "四", "五", "六"]
can.page.Appends(can, table, [{type: "tr", list: can.core.List(meta, function(day) {return {text: [day, "th"]}})}])
var one = new Date(now); one.setDate(1);
var end = new Date(now); end.setMonth(now.getMonth()+1); end.setDate(1);
var head = new Date(one); head.setDate(one.getDate()-one.getDay());
var tail = new Date(end); tail.setDate(end.getDate()+7-end.getDay());
var tr;
function add(day, type) {
if (day.getDay() == 0) {tr = can.page.Append(can, table, [{type: "tr"}]).tr}
can.page.Append(can, tr, [{className: can.base.Time(day).split(" ")[0] == can.base.Time(now).split(" ")[0]? "now": type,
text: [day.getDate(), "td"], dataset: {date: day.getTime()}, click: click,
}])
}
for (var day = new Date(head); day < one; day.setDate(day.getDate()+1)) {add(day, "last")}
for (var day = new Date(one); day < end; day.setDate(day.getDate()+1)) {add(day, "main")}
for (var day = new Date(end); end.getDay() != 0 && day < tail; day.setDate(day.getDate()+1)) {add(day, "next")}
}
show(can.now);
set(can.now);
}},
province: {click: function(event, can, value, cmd, target) {
if (can.figure) {return}
can.figure = can.page.Append(can, document.body, [{view: ["date input", "fieldset"], style: {
position: "absolute", left: "20px", top: event.clientY+10+"px",
}, onmouseleave: function(event) {
can.page.Remove(can, can.figure); delete(can.figure);
}}]).last
can.page.Append(can, can.figure, [{include: ["/plugin/github.com/shylinux/echarts/echarts.js", function(event) {
can.page.Append(can, can.figure, [{include: ["/plugin/github.com/shylinux/echarts/china.js", function(event) {
var china_chart = echarts.init(can.page.Append(can, can.figure, [{type: "div", style: {width: "600px", height: "400px"}}]).last);
var option = {geo: {map: 'china'}};
china_chart.setOption(option);
china_chart.on('click', function (params) {
target.value = params.name;
});
}]}]);
}]}]);
},
},
upload: {click: function(event, can, value, cmd, target) {
if (!can.onfigure._prepare(event, can, value, cmd, target)) {return}
can.figure.stick = true
var action = can.page.AppendAction(can, can.figure.action, [{type: "input", data: {name: "upload", type: "file"}}, "上传", "关闭"], function(event, value, cmd) {
switch (value) {
case "关闭": can.onfigure._release(event, can, value, cmd, target); return
}
var msg = can.Event(event);
msg.upload = action.upload.files[0]
can.run(event, ["action", "上传"], true, function(msg) {
can.user.toast("上传成功")
})
})
}},
_prepare: function(event, can, value, cmd, target) {if (can.figure) {return}
can.figure = can.page.Append(can, document.body, [{view: ["input "+cmd, "fieldset"], style: {
position: "absolute", left: "20px", top: event.clientY+10+"px",
}, list: [{text: [cmd, "legend"]}, {view: ["action"]}, {view: ["output"]}], onmouseleave: function(event) {
!can.figure.stick && can.onfigure._release(event, can, value, cmd, target)
}}])
return can.figure
},
_release: function(event, can, value, cmd, target) {
can.page.Remove(can, can.figure.first); delete(can.figure);
},
})
Volcanos("onaction", {help: "控件交互", list: [], Volcanos("onaction", {help: "控件交互", list: [],
onclick: function(event, can) {can.Select(event); onclick: function(event, can) {can.Select(event);
var figure = can.onfigure[can.item.cb] || can.onfigure[can.item.figure] var figure = can.onfigure[can.item.cb] || can.onfigure[can.item.figure]

91
plugin/input/date.js Normal file
View File

@ -0,0 +1,91 @@
Volcanos("onfigure", {help: "控件详情", list: [],
date: {click: function(event, can, value, cmd, target) {if (can.date) {return}
target.style.width = "120px"
function set(now) {
target.value = can.base.Time(now);
if (can.item.action == "auto") {
can.run({});
}
}
can.stick = false
can.now = target.value? new Date(target.value): new Date();
can.date = can.page.Append(can, document.body, [{view: ["date input", "fieldset"], style: {
position: "absolute", left: event.clientX+"px", top: event.clientY+10+"px",
}, onmouseleave: function(event) {
if (can.stick) {can.stick = false; return}
can.page.Remove(can, can.date); delete(can.date);
}}]).last
var action = can.page.Append(can, can.date, [{view: ["action"]}]).last
var control = can.page.AppendAction(can, action, ["今天", "随机",
["hour"].concat(can.core.List(24)), ["minute"].concat(can.core.List(0, 60, 5)), ["second"].concat(can.core.List(0, 60, 5)), {view: ["", "br"]},
"上一月", ["year"].concat(can.core.List(can.now.getFullYear() - 20, can.now.getFullYear() + 20)),
["month"].concat(can.core.List(1, 13)), "下一月", {view: ["", "br"]},
], function(event, value, cmd) {can.stick = true;
switch (cmd) {
case "year": can.now.setFullYear(parseInt(value)); show(can.now); return;
case "month": can.now.setMonth(parseInt(value)-1); show(can.now); return;
case "hour": can.now.setHours(parseInt(value)); show(can.now); set(can.now); return;
case "minute": can.now.setMinutes(parseInt(value)); show(can.now); set(can.now); return;
case "second": can.now.setSeconds(parseInt(value)); show(can.now); set(can.now); return;
}
switch (value) {
case "今天": can.now = new Date(); show(can.now); set(can.now); break;
case "随机": can.now.setDate((Math.random() * 100 - 50) + can.now.getDate()); show(can.now); set(can.now); break;
case "关闭":can.page.Remove(can, can.date); delete(can.date);
case "前一年": can.now.setFullYear(can.now.getFullYear()-1); show(can.now); break;
case "后一年": can.now.setFullYear(can.now.getFullYear()+1); show(can.now); break;
case "上一月": can.now.setMonth(can.now.getMonth()-1); show(can.now); break;
case "下一月": can.now.setMonth(can.now.getMonth()+1); show(can.now); break;
}
})
var table = can.page.Append(can, can.date, [{type: "table"}]).table
function click(event) {
var day = new Date(parseInt(event.target.dataset.date))
can.now = day;
set(can.now);
}
function show(now) {
control.month.value = now.getMonth()+1;
control.year.value = now.getFullYear();
control.hour.value = now.getHours();
control.minute.value = parseInt(now.getMinutes()/5)*5;
control.second.value = parseInt(now.getSeconds()/5)*5;
var meta = ["日", "一", "二", "三", "四", "五", "六"]
can.page.Appends(can, table, [{type: "tr", list: can.core.List(meta, function(day) {return {text: [day, "th"]}})}])
var one = new Date(now); one.setDate(1);
var end = new Date(now); end.setMonth(now.getMonth()+1); end.setDate(1);
var head = new Date(one); head.setDate(one.getDate()-one.getDay());
var tail = new Date(end); tail.setDate(end.getDate()+7-end.getDay());
var tr;
function add(day, type) {
if (day.getDay() == 0) {tr = can.page.Append(can, table, [{type: "tr"}]).tr}
can.page.Append(can, tr, [{className: can.base.Time(day).split(" ")[0] == can.base.Time(now).split(" ")[0]? "now": type,
text: [day.getDate(), "td"], dataset: {date: day.getTime()}, click: click,
}])
}
for (var day = new Date(head); day < one; day.setDate(day.getDate()+1)) {add(day, "last")}
for (var day = new Date(one); day < end; day.setDate(day.getDate()+1)) {add(day, "main")}
for (var day = new Date(end); end.getDay() != 0 && day < tail; day.setDate(day.getDate()+1)) {add(day, "next")}
}
show(can.now);
set(can.now);
}},
_prepare: function(event, can, value, cmd, target) {if (can.figure) {return}
can.figure = can.page.Append(can, document.body, [{view: ["input "+cmd, "fieldset"], style: {
position: "absolute", left: "20px", top: event.clientY+10+"px",
}, list: [{text: [cmd, "legend"]}, {view: ["action"]}, {view: ["output"]}], onmouseleave: function(event) {
!can.figure.stick && can.onfigure._release(event, can, value, cmd, target)
}}])
return can.figure
},
_release: function(event, can, value, cmd, target) {
can.page.Remove(can, can.figure.first); delete(can.figure);
},
})

32
plugin/input/key.js Normal file
View File

@ -0,0 +1,32 @@
Volcanos("onfigure", {help: "控件详情", list: [],
key: {click: function(event, can, value, cmd, target) {
function add(msg, list, update) {
can.page.Append(can, can.figure.output, [{view: "list", list: can.core.List(list, function(item) {
return {text: [item, "div", "label"], onclick: function(event) {
target.value = item;
update && can.history.unshift(item);
msg.Option("_refresh") && run()
}}
})}])
}
function run() {can.figure.output.innerHTML = ""
can.Run(event, ["action", "input", can.item.name, target.value], function(msg) {
add(msg, can.history), can.core.List(msg.append, function(key) {add(msg, msg[key], true)})
}, true)
}
can.history = can.history || [];
can.onfigure._prepare(event, can, value, cmd ,target) && run()
}},
_prepare: function(event, can, value, cmd, target) {if (can.figure) {return}
can.figure = can.page.Append(can, document.body, [{view: ["input "+cmd, "fieldset"], style: {
position: "absolute", left: "20px", top: event.clientY+10+"px",
}, list: [{text: [cmd, "legend"]}, {view: ["action"]}, {view: ["output"]}], onmouseleave: function(event) {
!can.figure.stick && can.onfigure._release(event, can, value, cmd, target)
}}])
return can.figure
},
_release: function(event, can, value, cmd, target) {
can.page.Remove(can, can.figure.first); delete(can.figure);
},
})

34
plugin/input/province.js Normal file
View File

@ -0,0 +1,34 @@
Volcanos("onfigure", {help: "控件详情", list: [],
province: {click: function(event, can, value, cmd, target) {
if (can.figure) {return}
can.figure = can.page.Append(can, document.body, [{view: ["date input", "fieldset"], style: {
position: "absolute", left: "20px", top: event.clientY+10+"px",
}, onmouseleave: function(event) {
can.page.Remove(can, can.figure); delete(can.figure);
}}]).last
can.page.Append(can, can.figure, [{include: ["/plugin/github.com/shylinux/echarts/echarts.js", function(event) {
can.page.Append(can, can.figure, [{include: ["/plugin/github.com/shylinux/echarts/china.js", function(event) {
var china_chart = echarts.init(can.page.Append(can, can.figure, [{type: "div", style: {width: "600px", height: "400px"}}]).last);
var option = {geo: {map: 'china'}};
china_chart.setOption(option);
china_chart.on('click', function (params) {
target.value = params.name;
});
}]}]);
}]}]);
}},
_prepare: function(event, can, value, cmd, target) {if (can.figure) {return}
can.figure = can.page.Append(can, document.body, [{view: ["input "+cmd, "fieldset"], style: {
position: "absolute", left: "20px", top: event.clientY+10+"px",
}, list: [{text: [cmd, "legend"]}, {view: ["action"]}, {view: ["output"]}], onmouseleave: function(event) {
!can.figure.stick && can.onfigure._release(event, can, value, cmd, target)
}}])
return can.figure
},
_release: function(event, can, value, cmd, target) {
can.page.Remove(can, can.figure.first); delete(can.figure);
},
})

28
plugin/input/upload.js Normal file
View File

@ -0,0 +1,28 @@
Volcanos("onfigure", {help: "控件详情", list: [],
upload: {click: function(event, can, value, cmd, target) {
if (!can.onfigure._prepare(event, can, value, cmd, target)) {return}
can.figure.stick = true
var action = can.page.AppendAction(can, can.figure.action, [{type: "input", data: {name: "upload", type: "file"}}, "上传", "关闭"], function(event, value, cmd) {
switch (value) {
case "关闭": can.onfigure._release(event, can, value, cmd, target); return
}
var msg = can.Event(event);
msg.upload = action.upload.files[0]
can.run(event, ["action", "上传"], true, function(msg) {
can.user.toast("上传成功")
})
})
}},
_prepare: function(event, can, value, cmd, target) {if (can.figure) {return}
can.figure = can.page.Append(can, document.body, [{view: ["input "+cmd, "fieldset"], style: {
position: "absolute", left: "20px", top: event.clientY+10+"px",
}, list: [{text: [cmd, "legend"]}, {view: ["action"]}, {view: ["output"]}], onmouseleave: function(event) {
!can.figure.stick && can.onfigure._release(event, can, value, cmd, target)
}}])
return can.figure
},
_release: function(event, can, value, cmd, target) {
can.page.Remove(can, can.figure.first); delete(can.figure);
},
})

View File

@ -1,18 +1,26 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: []})
favor: function(event, can, msg, cmd, output) {var key = msg.detail[0];
var cb = can.onaction[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onaction ", key), msg._hand = true}
var cb = can.onchoice[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onchoice ", key), msg._hand = true}
var sub = can[key]; if (sub && sub.target) {sub.target.focus; return msg.Echo(can._name, " ", sub._name, " ", key), msg._hand = true}
can._output && can._output.Import(event, msg, cmd)
},
})
Volcanos("onaction", {help: "组件交互", list: []}) Volcanos("onaction", {help: "组件交互", list: []})
Volcanos("onchoice", {help: "组件菜单", list: ["执行", "返回", "共享", "重命名", "选项", "加参", "减参", "克隆", "删除"], Volcanos("onchoice", {help: "组件菜单", list: ["执行", "返回", "共享", "重命名", "选项", "加参", "减参", "克隆", "删除"],
"执行": function(event, can, msg, cmd, field) {can.Runs(event)}, "执行": function(event, can, msg, cmd, field) {can.Runs(event)},
"返回": function(event, can, msg, cmd, field) {can.Last(event)}, "返回": function(event, can, msg, cmd, field) {can.Last(event)},
"共享": function(event, can, msg, cmd, field) {can.Share(event)}, "共享": function(event, can, msg, cmd, field) {
"重命名": function(event, can, msg, cmd, field) {can.Rename(event)}, can.user.input(event, can, ["name", "text"], function(event, cmd, meta, list) {
var msg = can.Event(event);
msg.Option("name", meta.name)
msg.Option("text", meta.text)
can.Conf("args", JSON.stringify(can.Option()))
can.core.List(["node", "group", "index", "args"], function(key) {
msg.Option(key, can.Conf(key))
})
can.Export(event, "action", "share")
return true
})
},
"重命名": function(event, can, msg, cmd, field) {var meta = field.Meta;
meta.help = can.user.prompt("", function(help) {
meta.help = help
}, meta.help)
},
"选项": function(event, can, msg, cmd, field) { "选项": function(event, can, msg, cmd, field) {
can.user.input(event, can, ["name", "value"], function(event, cmd, meta, list) { can.user.input(event, can, ["name", "value"], function(event, cmd, meta, list) {
var data = {type: "text", value: meta.value||""} var data = {type: "text", value: meta.value||""}
@ -28,14 +36,6 @@ Volcanos("onchoice", {help: "组件菜单", list: ["执行", "返回", "共享",
"克隆": function(event, can, msg, cmd, field) {can.Clone(event)}, "克隆": function(event, can, msg, cmd, field) {can.Clone(event)},
"删除": function(event, can, msg, cmd, field) {can.Delete(event)}, "删除": function(event, can, msg, cmd, field) {can.Delete(event)},
}) })
Volcanos("ondetail", {help: "组件详情", list: ["copy", "复制", "下载"]}) Volcanos("ondetail", {help: "组件详情", list: []})
Volcanos("onexport", {help: "导出数据", list: ["复制", "下载"], Volcanos("onexport", {help: "导出数据", list: []})
you_status: function(event, can, msg, value, key, index) {
var cmd = [can.option.pod.value, msg.you[index]]
value == "start" && cmd.push("stop")
var timer = can.user.toast(cmd.join(" ")+"...", msg.you[index], 5000)
can.Run(event, cmd, function(msg) {
})
}
})

View File

@ -18,11 +18,11 @@ Volcanos("onimport", {help: "导入数据", list: [],
case "TD": case "TD":
can.onimport.which(event, table, msg.append, function(index, key) { can.onimport.which(event, table, msg.append, function(index, key) {
can.user.carte(event, shy("", can.ondetail, can.feature.detail || can.ondetail.list, function(event, cmd, meta) {var cb = meta[cmd]; can.user.carte(event, shy("", can.ondetail, can.feature.detail || can.ondetail.list, function(event, cmd, meta) {var cb = meta[cmd];
var id = msg.Ids(index);
var sub = can.Event(event); var sub = can.Event(event);
msg.append.forEach(function(key) {sub.Option(key, msg[key][index].trim())}) msg.append.forEach(function(key) {sub.Option(key, msg[key][index].trim())})
typeof cb == "function"? cb(event, can, msg, index, key, cmd, target): typeof cb == "function"? cb(event, can, msg, index, key, cmd, target):
can.run(event, ["action", typeof cb == "string"? cb: cmd, key, target.innerHTML, id], function(msg) { can.run(event, ["action", typeof cb == "string"? cb: cmd, key, target.innerHTML.trim(), msg.Ids(index)], function(msg) {
can.user.toast(msg.Result()) can.user.toast(msg.Result())
// can.onimport.init(can, msg, cb, output, option) // can.onimport.init(can, msg, cb, output, option)
}, true) }, true)
@ -47,14 +47,8 @@ Volcanos("onimport", {help: "导入数据", list: [],
}) })
}) })
}, },
favor: function(event, can, msg, cmd, output) {var key = msg.detail[0];
var cb = can.onaction[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onaction ", key), msg._hand = true}
var cb = can.onchoice[key]; if (typeof cb == "function") {cb(event, can, msg, cmd, output); return msg.Echo(can._name, " onchoice ", key), msg._hand = true}
},
})
Volcanos("onaction", {help: "组件交互", list: [],
}) })
Volcanos("onaction", {help: "组件交互", list: []})
Volcanos("onchoice", {help: "组件菜单", list: ["返回", "清空", "复制", "下载"], Volcanos("onchoice", {help: "组件菜单", list: ["返回", "清空", "复制", "下载"],
"返回": function(event, can, msg, cmd, target) { "返回": function(event, can, msg, cmd, target) {
can.run(event, ["", "Last"]) can.run(event, ["", "Last"])
@ -79,7 +73,7 @@ Volcanos("ondetail", {help: "组件详情", list: ["选择", "编辑", "删除",
var input = can.page.Appends(can, td, [{type: "input", value: text, style: {width: td.clientWidth+"px"}, data: {onkeydown: function(event) { var input = can.page.Appends(can, td, [{type: "input", value: text, style: {width: td.clientWidth+"px"}, data: {onkeydown: function(event) {
if (event.key != "Enter") {return} if (event.key != "Enter") {return}
if (key == "value" && msg.key) {key = msg.key[index]} if (key == "value" && msg.key) {key = msg.key[index]}
can.run(event, ["action", "modify", key, event.target.value, text, msg.Ids(index)], function(msg) { can.run(event, ["action", "modify", key, event.target.value, text, can.Option("id")||msg.Ids(index)], function(msg) {
td.innerHTML = event.target.value; td.innerHTML = event.target.value;
can.user.toast("修改成功") can.user.toast("修改成功")
}, true) }, true)

View File

@ -1,34 +0,0 @@
Volcanos("onimport", {help: "导入数据", list: [],
init: function(can, msg, cb, output, option) {output.innerHTML = "";
if (!msg.append || msg.append.length == 0) {
var code = can.page.Append(can, output, [{view: ["code", "div", msg.Result()]}]).code;
return typeof cb == "function" && cb(msg), code;
}
var table = can.page.AppendTable(can, output, msg, msg.append);
table.oncontextmenu = function(event) {var target = event.target; var data = target.dataset;
switch (event.target.tagName) {
case "SPAN":
can.user.carte(event, shy("", can.ondetail, can.feature.detail || can.ondetail.list, function(event, cmd, meta) {
var id = data.id;
can.run(event, [id, cmd], function(msg) {
can.onimport.init(can, msg, cb, output, option)
can.user.toast(cmd+"成功");
}, true)
}))
event.stopPropagation()
event.preventDefault()
break
case "TH":
case "TR":
case "TABLE":
}
}
return typeof cb == "function" && cb(msg), table;
},
})
Volcanos("onaction", {help: "组件交互", list: []})
Volcanos("onchoice", {help: "组件菜单", list: []})
Volcanos("ondetail", {help: "组件详情", list: []})
Volcanos("onexport", {help: "导出数据", list: []})

View File

@ -2,6 +2,7 @@ Volcanos("onimport", {help: "导入数据", list: [],
init: function(can, msg, cb, output, action, option) {output.innerHTML = ""; init: function(can, msg, cb, output, action, option) {output.innerHTML = "";
var table = can.page.AppendTable(can, output, msg, msg.append); var table = can.page.AppendTable(can, output, msg, msg.append);
table.onclick = function(event) {switch (event.target.tagName) { table.onclick = function(event) {switch (event.target.tagName) {
case "SPAN":
case "TD": case "TD":
var input = can.user.input(event, can, ["zone", "type", "name", "text"], function(event, value, data) { var input = can.user.input(event, can, ["zone", "type", "name", "text"], function(event, value, data) {
switch (value) { switch (value) {
@ -46,6 +47,7 @@ Volcanos("onimport", {help: "导入数据", list: [],
} }
can.page.Select(can, table, "div.task", function(item) { can.page.Select(can, table, "div.task", function(item) {
// 拖动排期
item.setAttribute("draggable", true) item.setAttribute("draggable", true)
item.ondragstart = function(event) {can.drag = event.target} item.ondragstart = function(event) {can.drag = event.target}
item.ondragover = function(event) {event.preventDefault()} item.ondragover = function(event) {event.preventDefault()}
@ -75,6 +77,11 @@ Volcanos("onimport", {help: "导入数据", list: [],
begin_time.setMonth(parseInt(tr.list[0].innerText)-1); begin_time.setMonth(parseInt(tr.list[0].innerText)-1);
break break
case "month": case "month":
can.page.Select(can, item, "span", function(item) {var data = item.dataset
begin_time.setYear(parseInt(data.year))
begin_time.setMonth(parseInt(data.month)-1)
begin_time.setDate(parseInt(data.day))
})
break break
case "week": case "week":
begin_time.setDate(begin_time.getDate() - (begin_time.getDay() - index + 1)) begin_time.setDate(begin_time.getDate() - (begin_time.getDay() - index + 1))

View File

@ -1,5 +1,6 @@
Volcanos("onimport", {help: "导入数据", list: [], Volcanos("onimport", {help: "导入数据", list: [],
init: function(can, msg, cb, output, action, option) {output.innerHTML = ""; init: function(can, msg, cb, output, action, option) {
can.page.Appends(can, output, [{img: [window.URL.createObjectURL(new Blob(msg.result, {type: "image/png"}))]}])
}, },
}) })
Volcanos("onaction", {help: "组件交互", list: []}) Volcanos("onaction", {help: "组件交互", list: []})
@ -8,3 +9,4 @@ Volcanos("ondetail", {help: "组件详情", list: []})
Volcanos("onexport", {help: "导出数据", list: []}) Volcanos("onexport", {help: "导出数据", list: []})

View File

@ -24,6 +24,7 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
if (meta.cache[name]) {var cache = meta.cache[name]; if (meta.cache[name]) {var cache = meta.cache[name];
for (var i = 0; i < cache.length; i++) {var item = cache[i]; for (var i = 0; i < cache.length; i++) {var item = cache[i];
if (item._name == can._name) {continue} if (item._name == can._name) {continue}
// 加载索引
can[item._name] = item; can[item._name] = item;
} }
return can return can
@ -32,6 +33,7 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
meta.cache[name] = [] meta.cache[name] = []
for (var i = meta.index; i < list.length; i++) {var item = list[i]; for (var i = meta.index; i < list.length; i++) {var item = list[i];
if (item._name == can._name || item._type == "local"|| item._type == "input" || item._type == "output") {continue} if (item._name == can._name || item._type == "local"|| item._type == "input" || item._type == "output") {continue}
// 加载缓存
can[item._name] = item; can[item._name] = item;
meta.cache[name].push(item); meta.cache[name].push(item);
} }
@ -69,10 +71,11 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
} }
// 加载脚本 // 加载脚本
can.Dream(document.body, libs[0].indexOf(".") == -1? libs[0]+".js": libs[0], function() { can.Dream(document.body, !libs[0].endsWith("/") && libs[0].indexOf(".") == -1? libs[0]+".js": libs[0], function() {
can._load(libs[0]), can.require(libs.slice(1), cb); can._load(libs[0]), can.require(libs.slice(1), cb);
}) })
}, },
name: function() {return can._name.toLowerCase()},
ID: shy("生成器", function() {return id++}), ID: shy("生成器", function() {return id++}),
Log: shy("日志器", function() {console.log(arguments)}), Log: shy("日志器", function() {console.log(arguments)}),
@ -101,16 +104,20 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
// [1,2,3,4] // [1,2,3,4]
// {value, length} // {value, length}
var timer = {stop: false}; var timer = {stop: false};
function loop(i) {if (timer.stop || i >= interval.length && interval.length >= 0) {return typeof cbs == "function" && cbs(interval)} function loop(event, i) {if (timer.stop || i >= interval.length && interval.length >= 0) {return typeof cbs == "function" && cbs(event, interval)}
return typeof cb == "function" && cb(interval.value||interval[i], i, interval)? return typeof cb == "function" && cb(event, interval.value||interval[i], i, interval)?
typeof cbs == "function" && cbs(interval): setTimeout(function() {loop(i+1)}, interval.value||interval[i+1]); typeof cbs == "function" && cbs(event, interval):
setTimeout(function() {loop(event, i+1)}, interval.value||interval[i+1]);
} }
setTimeout(function() {loop(0)}, interval.value||interval[0]); setTimeout(function(event) {loop(event, 0)}, interval.value||interval[0]);
return timer; return timer;
}), }),
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 || { if (!msg && event.msg) {return event.msg}
_create_time: can.base.Time(), _source: can,
event.msg = msg = msg || {}, msg.__proto__ = proto || {
__proto__: can, _create_time: can.base.Time(),
option: [],
Log: shy("输出日志", function() {console.log(arguments)}), Log: shy("输出日志", function() {console.log(arguments)}),
Ids: function(index, key) {var id = index; Ids: function(index, key) {var id = index;
msg && msg.id && (id = msg.id[index]) || msg && msg.name && (id = msg.name[index]); msg && msg.id && (id = msg.id[index]) || msg && msg.name && (id = msg.name[index]);
@ -124,11 +131,6 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
}).length > 0 || msg.option.push(key) }).length > 0 || msg.option.push(key)
msg[key] = can.core.List(arguments).slice(1) 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;
}),
Push: function(key, value) {msg.append = msg.append || [] Push: function(key, value) {msg.append = msg.append || []
if (typeof key == "object") { if (typeof key == "object") {
value? can.core.List(value, function(item) { value? can.core.List(value, function(item) {
@ -148,6 +150,11 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
msg[key] = msg[key] || [] msg[key] = msg[key] || []
msg[key].push(""+value) msg[key].push(""+value)
}, },
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;
}),
Copy: function(res) { Copy: function(res) {
res.result && (msg.result = res.result) res.result && (msg.result = res.result)
res.append && (msg.append = res.append) && res.append.forEach(function(item) { res.append && (msg.append = res.append) && res.append.forEach(function(item) {
@ -182,7 +189,7 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
}; };
return msg.event = event, msg return msg.event = event, msg
}), }),
Dream: shy("构造器", function(target, type, line, key) { Dream: shy("构造器", function(target, type, line) {
if (type.endsWith(".css")) { if (type.endsWith(".css")) {
var style = document.createElement("link"); var style = document.createElement("link");
style.rel = "stylesheet", style.type = "text/css"; style.rel = "stylesheet", style.type = "text/css";
@ -198,6 +205,11 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
target.appendChild(script); target.appendChild(script);
return script return script
} }
if (type.endsWith("/")) {
typeof line == "function" && line()
return
}
var text = line, list = [], item = false, style = "" var text = line, list = [], item = false, style = ""
switch (type) { switch (type) {
case "option": case "option":
@ -212,6 +224,7 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
}), }),
Cache: shy("缓存器", function(name, output, data) { Cache: shy("缓存器", function(name, output, data) {
if (data) { if (data) {
// 写缓存
var temp = document.createDocumentFragment() var temp = document.createDocumentFragment()
while (output.childNodes.length>0) { while (output.childNodes.length>0) {
var item = output.childNodes[0] var item = output.childNodes[0]
@ -224,6 +237,8 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
var list = cache[name]; var list = cache[name];
if (!list) {return} if (!list) {return}
// 读缓存
while (list.node.childNodes.length>0) { while (list.node.childNodes.length>0) {
var item = list.node.childNodes[0] var item = list.node.childNodes[0]
item.parentNode.removeChild(item) item.parentNode.removeChild(item)
@ -240,7 +255,6 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
can.onimport && can.onimport._begin && can.onimport._begin(can) can.onimport && can.onimport._begin && can.onimport._begin(can)
typeof cb == "function" && cb(can); typeof cb == "function" && cb(can);
if (can.target) { if (can.target) {
// 初始化主模块
function run(event, msg, key, cb) { function run(event, msg, key, cb) {
if (typeof cb == "function") { if (typeof cb == "function") {
// 本地命令 // 本地命令
@ -250,13 +264,14 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
can.run(event, ["action", key], function(msg) {can.Import(event, msg, key)}, true) can.run(event, ["action", key], function(msg) {can.Import(event, msg, key)}, true)
} }
} }
// 注册event
// 注册事件
can.core.Item(can.onaction, function(key, cb) {key.indexOf("on") == 0 && (can.target[key] = function(event) {cb(event, can)})}); can.core.Item(can.onaction, function(key, cb) {key.indexOf("on") == 0 && (can.target[key] = function(event) {cb(event, can)})});
// 注册action // 注册控件
can.action && (can.action.innerHTML = ""), can.onaction && can.page.AppendAction(can, can.action, can.onaction.list, function(event, value, key) { can.action && (can.action.innerHTML = ""), can.onaction && can.page.AppendAction(can, can.action, can.onaction.list, function(event, value, key) {
key? run(event, value, key, can.onaction[key]||can.onaction[value]): run(event, msg, value, can.onaction[value]); key? run(event, value, key, can.onaction[key]||can.onaction[value]): run(event, msg, value, can.onaction[value]);
}) })
// 注册choice // 注册菜单
can.target.oncontextmenu = function(event) {can.user.carte(event, shy("", can.onchoice, can.onchoice.list, function(event, key, meta) { can.target.oncontextmenu = function(event) {can.user.carte(event, shy("", can.onchoice, can.onchoice.list, function(event, key, meta) {
run(event, msg, key, can.onchoice[key] || can.onaction[key]); run(event, msg, key, can.onchoice[key] || can.onaction[key]);
}), can), event.stopPropagation(), event.preventDefault()} }), can), event.stopPropagation(), event.preventDefault()}

View File

@ -241,6 +241,9 @@ fieldset table caption {
fieldset table tbody { fieldset table tbody {
overflow:auto; overflow:auto;
} }
fieldset table tr.hidden {
display:none;
}
fieldset table th.order { fieldset table th.order {
background-color:red; background-color:red;
cursor:pointer; cursor:pointer;