mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 16:58:06 +08:00
add Toast&Carte
This commit is contained in:
parent
8716ff9913
commit
e7d13748e7
24
frame.js
24
frame.js
@ -33,6 +33,18 @@ var can = Volcanos("chat", {
|
||||
typeof cb == "function" && cb(event, pane, value, key, output);
|
||||
},
|
||||
|
||||
Show: function(width, height) {field.style.display = "block";
|
||||
if (width > 0) {
|
||||
field.style.width = width + "px";
|
||||
field.style.left = (document.body.offsetWidth - width) / 2 + "px";
|
||||
}
|
||||
if (height > 0) {
|
||||
field.style.height = height + "px";
|
||||
field.style.top = (document.body.offsetHeight - height) / 2 + "px";
|
||||
}
|
||||
},
|
||||
Hide: function() {field.style.display = "none"},
|
||||
|
||||
run: function(event, cmds, cb) {var msg = pane.Event(event)
|
||||
can.page.Select(can, action, "input", function(item, index) {
|
||||
msg.Option(name, item.value)
|
||||
@ -40,6 +52,7 @@ var can = Volcanos("chat", {
|
||||
can.run(event, option.dataset, cmds, cb)
|
||||
},
|
||||
}, Config.libs.concat(["pane/"+name]), function(pane) {
|
||||
pane.onimport._init && pane.onimport._init(pane, output, action, option, field)
|
||||
typeof cb == "function" && cb(pane)
|
||||
})
|
||||
return pane.target = field, pane
|
||||
@ -53,6 +66,7 @@ var can = Volcanos("chat", {
|
||||
|
||||
var args = meta.args || [];
|
||||
var feature = JSON.parse(meta.feature||'{}');
|
||||
var exports = JSON.parse(meta.exports||'{}');
|
||||
var plugin = Volcanos(name, {type: "local",
|
||||
Inputs: can.Inputs, Output: can.Output,
|
||||
|
||||
@ -72,6 +86,9 @@ var can = Volcanos("chat", {
|
||||
plugin.page.Select(can, option, ".args", function(item) {return item.value})
|
||||
},
|
||||
Report: function(event, value, key, index) {
|
||||
for (var i = 0; i < exports.length; i += 3) {
|
||||
if (exports[i+1] == key) {key = exports[i]}
|
||||
}
|
||||
plugin[key] && plugin[key].target && plugin[key].Import(event, value, key, index)
|
||||
},
|
||||
Check: function(event, target, cb) {
|
||||
@ -124,6 +141,9 @@ var can = Volcanos("chat", {
|
||||
return input
|
||||
}),
|
||||
Output: shy("构造组件", function(can, type, msg, cb, target, option) {
|
||||
if (type == "inner" && (!msg.result || msg.result.length == 0)) {
|
||||
type = "table"
|
||||
}
|
||||
var output = Volcanos(type, {type: "local",
|
||||
Export: function(event, value, key, index) {can.Report(event, value, key, index)},
|
||||
run: function(event, cmd, cb, silent) {
|
||||
@ -137,8 +157,8 @@ var can = Volcanos("chat", {
|
||||
}, Config.libs.concat(Config.list), function(can) {
|
||||
if (ctx.Search("feature") != "") {
|
||||
can[Config.main] = can.Page(can, Config.main, Config, function(chat) {
|
||||
can.user.carte = page.carte.Pane.Show;
|
||||
can.user.toast = page.toast.Pane.Show;
|
||||
// can.user.carte = page.carte.Pane.Show;
|
||||
// can.user.toast = page.toast.Pane.Show;
|
||||
chat.River.Import(event||{}, "shy", "username")
|
||||
}, document.body)
|
||||
}
|
||||
|
@ -2,6 +2,12 @@ Volcanos("base", {help: "基础模块",
|
||||
isNone: function(c) {return c === undefined || c === null},
|
||||
isSpace: function(c) {return c == " " || c == "Enter"},
|
||||
|
||||
Duration: function(n) {var res = "", h = 0;
|
||||
h = parseInt(n/3600000), h > 0 && (res += h+"h"), n = n % 3600000;
|
||||
h = parseInt(n/60000), h > 0 && (res += h+"m"), n = n % 60000;
|
||||
h = parseInt(n/1000), h > 0 && (res += h+"s"), n = n % 1000;
|
||||
return n > 0? res + n: res;
|
||||
},
|
||||
Format: shy("数据格式化", function(obj) {return JSON.stringify(obj)}),
|
||||
Number: shy("数字格式化", function(d, n) {var result = [];
|
||||
while (d>0) {result.push(d % 10); d = parseInt(d / 10); n--}
|
||||
|
18
lib/page.js
18
lib/page.js
@ -88,6 +88,24 @@ Volcanos("page", {help: "网页模块",
|
||||
return target.innerHTML = "", can.page.Append(can, target, key, value)
|
||||
}),
|
||||
|
||||
AppendItem: shy("添加插件", function(can, target, list, click, cb) {
|
||||
can.core.List(list, function(line, index) {
|
||||
var item = can.page.Append(can, target, [{view: ["item "+line.key], list: [{text: [line.nick||line.key]}], click: function(event) {
|
||||
typeof cb == "function" && cb(event, line, item)
|
||||
can.page.Select(can, target, "div.item.select", function(item) {
|
||||
can.page.ClassList.del(can, item, "select")
|
||||
})
|
||||
can.page.ClassList.add(can, item, "select")
|
||||
}}]).first
|
||||
})
|
||||
|
||||
if (click === false) {return}
|
||||
if (click != "") {
|
||||
var list = can.page.Select(can, target, "div.item."+click)
|
||||
if (list.length>0) {list[0].click(); return}
|
||||
}
|
||||
can.page.Select(can, target, "div.item")[0].click()
|
||||
}),
|
||||
AppendField: shy("添加插件", function(can, target, type, item) {
|
||||
var field = can.page.Append(can, target, [{view: [type, "fieldset"], list: [
|
||||
{text: [item.name+item.help, "legend"]},
|
||||
|
41
lib/user.js
41
lib/user.js
@ -7,6 +7,47 @@ Volcanos("user", {help: "用户模块",
|
||||
toast: function(text) {},
|
||||
carte: function(event, cb) {},
|
||||
|
||||
Cookie: shy("会话变量", function(can, key, value, path) {
|
||||
function set(k, v) {document.cookie = k+"="+v+";path="+(path||"/")}
|
||||
|
||||
if (typeof key == "object") {
|
||||
for (var k in key) {set(k, key[k])}
|
||||
key = null
|
||||
}
|
||||
if (key == undefined) {var cs = {}
|
||||
document.cookie.split("; ").forEach(function(item) {
|
||||
var cookie = item.split("=")
|
||||
cs[cookie[0]] = cookie[1]
|
||||
})
|
||||
return cs
|
||||
}
|
||||
|
||||
value != undefined && set(key, value)
|
||||
var result = (new RegExp(key+"=([^;]*);?")).exec(document.cookie)
|
||||
return result && result.length > 0? result[1]: ""
|
||||
}),
|
||||
Search: shy("请求参数", function(can, key, value) {var args = {}
|
||||
location.search && location.search.slice(1).split("&").forEach(function(item) {var x = item.split("=")
|
||||
x[1] != "" && (args[x[0]] = decodeURIComponent(x[1]))
|
||||
})
|
||||
|
||||
if (typeof key == "object") {
|
||||
can.core.Item(key, function(key, value) {
|
||||
if (value != undefined) {args[key] = value}
|
||||
})
|
||||
} else if (key == undefined) {
|
||||
return args
|
||||
} else if (value == undefined) {
|
||||
return args[key] || can.user.Cookie(can, key)
|
||||
} else {
|
||||
args[key] = value
|
||||
}
|
||||
|
||||
return location.search = can.core.Item(args, function(key, value) {
|
||||
return key+"="+encodeURIComponent(value)
|
||||
}).join("&")
|
||||
}),
|
||||
|
||||
isWeiXin: navigator.userAgent.indexOf("MicroMessenger") > -1,
|
||||
isMobile: navigator.userAgent.indexOf("Mobile") > -1,
|
||||
isIPhone: navigator.userAgent.indexOf("iPhone") > -1,
|
||||
|
8
order.js
8
order.js
@ -1,10 +1,16 @@
|
||||
var Config = {
|
||||
main: "chat", list: [
|
||||
"page/chat", "pane/River", "pane/Storm", "pane/Action",
|
||||
"page/chat",
|
||||
"pane/Toast", "pane/Carte", "pane/Debug",
|
||||
"pane/River", "pane/Storm", "pane/Action",
|
||||
"plugin/state", "plugin/input", "plugin/table", "plugin/inner",
|
||||
],
|
||||
libs: ["lib/base", "lib/core", "lib/misc", "lib/page", "lib/user"],
|
||||
pane: [
|
||||
{group: "index", name: "Toast"},
|
||||
{group: "index", name: "Carte"},
|
||||
{group: "index", name: "Debug"},
|
||||
|
||||
{group: "index", name: "River"},
|
||||
{group: "index", name: "Storm"},
|
||||
{group: "index", name: "Action"},
|
||||
|
@ -1,6 +1,6 @@
|
||||
Volcanos("onimport", {help: "导入数据", list: [],
|
||||
init: function(can, msg, output) {output.innerHTML = "";
|
||||
msg.Table(function(item, index) {
|
||||
msg.Table(function(item, index) {if (!item.name) {return}
|
||||
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.page.AppendField(can, output, "item "+item.group+" "+item.name, item))
|
||||
@ -14,8 +14,7 @@ Volcanos("onimport", {help: "导入数据", list: [],
|
||||
|
||||
can.Conf("river", can.Conf("temp_river"))
|
||||
can.Conf("storm", value)
|
||||
var data = can.Cache(can.Conf("river")+"."+can.Conf("storm"), output);
|
||||
if (!data) {
|
||||
if (!can.Cache(can.Conf("river")+"."+can.Conf("storm"), output)) {
|
||||
can.run(event, [can.Conf("river"), can.Conf("storm")], function(msg) {
|
||||
can.onimport.init(can, msg, output)
|
||||
})
|
||||
|
25
pane/Carte.js
Normal file
25
pane/Carte.js
Normal file
@ -0,0 +1,25 @@
|
||||
Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, output, action, option, field) {
|
||||
can.user.carte = function(event, cb) {if (!cb || !cb.list || cb.list.length == 0) {return}
|
||||
output.innerHTML = "", can.page.AppendItem(can, output, can.core.List(cb.list, function(item) {
|
||||
return {key: item};
|
||||
}), "", function(event, line, item) {
|
||||
typeof cb == "function" && cb(event, line.key, cb.meta)
|
||||
})
|
||||
|
||||
var pos = {display: "block", left: event.x, top: event.y}
|
||||
if (document.body.clientWidth - event.x < 60) {
|
||||
var pos = {display: "block", right: event.x, top: event.y}
|
||||
}
|
||||
pos.left += "px"; pos.top += "px";
|
||||
can.page.Modify(can, field, {style: pos})
|
||||
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
can.Show()
|
||||
}
|
||||
}})
|
||||
Volcanos("onaction", {help: "组件交互", list: []})
|
||||
Volcanos("onchoice", {help: "组件菜单", list: []})
|
||||
Volcanos("ondetail", {help: "组件详情", list: []})
|
||||
Volcanos("onexport", {help: "导出数据", list: []})
|
||||
|
@ -1,15 +1,12 @@
|
||||
Volcanos("onimport", {help: "导入数据", list: [],
|
||||
init: function(can, msg, output) {output.innerHTML = "";
|
||||
msg.Table(function(item, index) {
|
||||
can.page.Append(can, output, [{view: ["item"], list: [{text: [item.nick||item.key]}], click: function(event) {
|
||||
can.Export(event, item.key, "river")
|
||||
}}])
|
||||
can.page.AppendItem(can, output, msg.Table(), can.user.Search(can, "river"), function(event, line, item) {
|
||||
can.Export(event, line.key, "river")
|
||||
})
|
||||
},
|
||||
username: function(event, can, value, key, output) {
|
||||
can.run(event, [], function(msg) {
|
||||
can.onimport.init(can, msg, output)
|
||||
can.Export(event, msg.key[0], "river")
|
||||
})
|
||||
},
|
||||
})
|
||||
|
@ -1,15 +1,12 @@
|
||||
Volcanos("onimport", {help: "导入数据", list: [],
|
||||
init: function(can, msg, output) {output.innerHTML = "";
|
||||
msg.Table(function(item, index) {
|
||||
can.page.Append(can, output, [{view: ["item"], list: [{text: [item.key]}], click: function(event) {
|
||||
can.Export(event, item.key, "storm")
|
||||
}}])
|
||||
can.page.AppendItem(can, output, msg.Table(), can.user.Search(can, "storm"), function(event, line, item) {
|
||||
can.Export(event, line.key, "storm")
|
||||
})
|
||||
},
|
||||
river: function(event, can, value, key, output) {
|
||||
can.run(event, [value], function(msg) {
|
||||
can.onimport.init(can, msg, output)
|
||||
can.Export(event, msg.key[0], "storm")
|
||||
})
|
||||
},
|
||||
})
|
||||
|
31
pane/Toast.js
Normal file
31
pane/Toast.js
Normal file
@ -0,0 +1,31 @@
|
||||
Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, output) {
|
||||
can.user.toast = function(text, title, duration, list) {if (!text) {return can.Hide()}
|
||||
text = typeof text == "object"? text: {list: list, text: text, title: title||"", duration: duration||3000}
|
||||
|
||||
var list = [{text: [text.title||"", "div", "title"]},
|
||||
{text: [text.text||"", "div", "content"]},
|
||||
{view: ["form"], list: text.list||[{type: "button", inner: "cancel", click: function() {
|
||||
timer.stop = true
|
||||
}}]},
|
||||
{text: [text.tick||"", "div", "tick"]},
|
||||
]
|
||||
|
||||
var toast = can.page.Appends(can, output, list)
|
||||
var width = text.width||text.text.length*10+10
|
||||
can.Show(width>400?400:width, text.height||80)
|
||||
|
||||
var begin = can.base.Time().split(" ")[1]
|
||||
var timer = can.Timer({value: 1000, length: text.duration > 0? text.duration/1000: text.duration}, function(t, i) {
|
||||
console.log(t, i)
|
||||
if (i > 10000) {return true}
|
||||
toast.tick.innerHTML = can.base.Duration(i*t) + " after " + begin
|
||||
}, function() {
|
||||
can.Hide()
|
||||
})
|
||||
}
|
||||
}})
|
||||
Volcanos("onaction", {help: "组件交互", list: []})
|
||||
Volcanos("onchoice", {help: "组件菜单", list: []})
|
||||
Volcanos("ondetail", {help: "组件详情", list: []})
|
||||
Volcanos("onexport", {help: "导出数据", list: []})
|
||||
|
@ -1,57 +0,0 @@
|
||||
Volcanos("onimport", {help: "导入数据", list: [],
|
||||
init: function(can, msg, output) {output.innerHTML = "";
|
||||
msg.Table(function(item, index) {
|
||||
can.Plugin(item, "state", index)
|
||||
})
|
||||
},
|
||||
})
|
||||
Volcanos("onaction", {help: "组件交互", list: [],
|
||||
})
|
||||
Volcanos("onchoice", {help: "组件菜单", list: ["返回", "清空", "复制", "下载", "表格", "绘图", "媒体"],
|
||||
"返回": function(event, can, msg, value, target) {
|
||||
can.run(event, ["", "Last"])
|
||||
},
|
||||
"清空": function(event, can, msg, value, target) {
|
||||
can.target.innerHTML = "";
|
||||
},
|
||||
"复制": function(event, can, msg, value, target) {
|
||||
var list = can.onexport.Format(can, msg, "data");
|
||||
can.user.toast(can.page.CopyText(can, list[2]), "复制成功")
|
||||
},
|
||||
"下载": function(event, can, msg, value, target) {
|
||||
var list = can.onexport.Format(can, msg, msg._plugin_name||"data");
|
||||
can.page.Download(can, list[0]+list[1], list[2]);
|
||||
},
|
||||
})
|
||||
Volcanos("ondetail", {help: "组件详情", list: ["选择", "修改", "删除", "复制", "下载"],
|
||||
"选择": "select",
|
||||
"删除": "delete",
|
||||
"修改": function(event, can, msg, value, index, key, td) {
|
||||
var text = td.innerHTML;
|
||||
can.page.Appends(can, td, [{type: "input", style: {width: td.clientWidth+"px"}, data: {onkeydown: function(event) {
|
||||
if (event.key != "Enter") {return}
|
||||
can.run(event, [index, "modify", key == "value" && msg.key? msg[key][index]: key, event.target.value,], function(msg) {
|
||||
td.innerHTML = event.target.value;
|
||||
can.user.toast("修改成功")
|
||||
}, true)
|
||||
}}}])
|
||||
},
|
||||
"复制": function(event, can, msg, value, index, key, target) {
|
||||
can.user.toast(can.page.CopyText(can, target.innerHTML), "复制成功")
|
||||
},
|
||||
"下载": function(event, can, msg, value, index, key, target) {
|
||||
can.page.Download(can, key, target.innerHTML);
|
||||
},
|
||||
})
|
||||
Volcanos("onexport", {help: "导出数据", list: [],
|
||||
Format: function(can, msg, name) {
|
||||
var ext = ".csv", txt = can.page.Select(can, can.target, "tr", function(tr) {
|
||||
return can.page.Select(can, tr, "td,th", function(td) {return td.innerText}).join(",")
|
||||
}).join("\n");
|
||||
|
||||
!txt && (ext = ".txt", txt = msg.result && msg.result.join("") || "");
|
||||
return [name, ext, txt]
|
||||
},
|
||||
})
|
||||
|
||||
|
@ -1,55 +0,0 @@
|
||||
Volcanos("onimport", {help: "导入数据", list: [],
|
||||
init: function(can, field, option, action, output) {output.innerHTML = "";
|
||||
},
|
||||
show: function(can, field, option, action, output) {output.innerHTML = "";
|
||||
},
|
||||
})
|
||||
Volcanos("onaction", {help: "组件交互", list: [],
|
||||
})
|
||||
Volcanos("onchoice", {help: "组件菜单", list: ["返回", "清空", "复制", "下载", "表格", "绘图", "媒体"],
|
||||
"返回": function(event, can, msg, value, target) {
|
||||
can.run(event, ["", "Last"])
|
||||
},
|
||||
"清空": function(event, can, msg, value, target) {
|
||||
can.target.innerHTML = "";
|
||||
},
|
||||
"复制": function(event, can, msg, value, target) {
|
||||
var list = can.onexport.Format(can, msg, "data");
|
||||
can.user.toast(can.page.CopyText(can, list[2]), "复制成功")
|
||||
},
|
||||
"下载": function(event, can, msg, value, target) {
|
||||
var list = can.onexport.Format(can, msg, msg._plugin_name||"data");
|
||||
can.page.Download(can, list[0]+list[1], list[2]);
|
||||
},
|
||||
})
|
||||
Volcanos("ondetail", {help: "组件详情", list: ["选择", "修改", "删除", "复制", "下载"],
|
||||
"选择": "select",
|
||||
"删除": "delete",
|
||||
"修改": function(event, can, msg, value, index, key, td) {
|
||||
var text = td.innerHTML;
|
||||
can.page.Appends(can, td, [{type: "input", style: {width: td.clientWidth+"px"}, data: {onkeydown: function(event) {
|
||||
if (event.key != "Enter") {return}
|
||||
can.run(event, [index, "modify", key == "value" && msg.key? msg[key][index]: key, event.target.value,], function(msg) {
|
||||
td.innerHTML = event.target.value;
|
||||
can.user.toast("修改成功")
|
||||
}, true)
|
||||
}}}])
|
||||
},
|
||||
"复制": function(event, can, msg, value, index, key, target) {
|
||||
can.user.toast(can.page.CopyText(can, target.innerHTML), "复制成功")
|
||||
},
|
||||
"下载": function(event, can, msg, value, index, key, target) {
|
||||
can.page.Download(can, key, target.innerHTML);
|
||||
},
|
||||
})
|
||||
Volcanos("onexport", {help: "导出数据", list: [],
|
||||
Format: function(can, msg, name) {
|
||||
var ext = ".csv", txt = can.page.Select(can, can.target, "tr", function(tr) {
|
||||
return can.page.Select(can, tr, "td,th", function(td) {return td.innerText}).join(",")
|
||||
}).join("\n");
|
||||
|
||||
!txt && (ext = ".txt", txt = msg.result && msg.result.join("") || "");
|
||||
return [name, ext, txt]
|
||||
},
|
||||
})
|
||||
|
13
proto.js
13
proto.js
@ -63,10 +63,13 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
|
||||
})
|
||||
}),
|
||||
Timer: shy("定时器", function(interval, cb, cbs) {interval = typeof interval == "object"? interval || []: [interval];
|
||||
function loop(i) {if (i >= interval.length) {return typeof cbs == "function" && cbs(interval)}
|
||||
return typeof cb == "function" && cb(interval[i], i, interval), setTimeout(function() {loop(i+1)}, interval[i]);
|
||||
var timer = {stop: false};
|
||||
function loop(i) {if (timer.stop || i >= interval.length && interval.length >= 0) {return typeof cbs == "function" && cbs(interval)}
|
||||
return typeof cb == "function" && cb(interval.value||interval[i], i, interval)?
|
||||
typeof cbs == "function" && cbs(interval): setTimeout(function() {loop(i+1)}, interval.value||interval[i+1]);
|
||||
}
|
||||
return loop(0)
|
||||
setTimeout(function() {loop(0)}, interval.value||interval[0]);
|
||||
return timer;
|
||||
}),
|
||||
Event: shy("触发器", function(event, msg, proto) {
|
||||
msg = event.msg = msg || event.msg || {}, msg.__proto__ = proto || {
|
||||
@ -96,9 +99,9 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块
|
||||
if (msg[key].length > len) {max = key, len = msg[key].length}
|
||||
});
|
||||
|
||||
return can.core.List(msg[max], function(value, index, array) {var one = {}
|
||||
return can.core.List(msg[max], function(value, index, array) {var one = {}, res;
|
||||
can.core.List(msg.append, function(key) {one[key] = msg[key][index]||""})
|
||||
return typeof cb == "function" && cb(one, index, array)
|
||||
return typeof cb == "function" && (res = cb(one, index, array)) && res != undefined || one
|
||||
})
|
||||
}),
|
||||
Result: function() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user