mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 16:58:06 +08:00
opt base.js
This commit is contained in:
parent
3bad92a73b
commit
6f17d35c7c
2
index.js
2
index.js
@ -17,5 +17,7 @@ Volcanos({name: "chat", iceberg: "/chat/", volcano: "/frame.js",
|
||||
"/plugin/local/wiki/word.js",
|
||||
"/plugin/local/code/vimer.js",
|
||||
"/plugin/local/code/inner.js",
|
||||
"/plugin/story/trend.js",
|
||||
"/plugin/story/spide.js",
|
||||
],
|
||||
})
|
||||
|
31
lib/base.js
31
lib/base.js
@ -15,13 +15,13 @@ Volcanos("base", {help: "基础模块",
|
||||
}
|
||||
return res
|
||||
},
|
||||
|
||||
Args: function(obj) {var res = [];
|
||||
for (var k in obj) {
|
||||
res.push(encodeURIComponent(k)+"="+encodeURIComponent(obj[k]))
|
||||
}
|
||||
return res.join("&")
|
||||
},
|
||||
|
||||
Size: function(size) {size = parseInt(size)
|
||||
if (size > 1000000000) {
|
||||
return parseInt(size / 1000000000) + "." + parseInt(size / 10000000 % 100) + "G"
|
||||
@ -62,18 +62,17 @@ Volcanos("base", {help: "基础模块",
|
||||
fmt = fmt.replace("%S", this.Number(now.getSeconds(), 2))
|
||||
return fmt
|
||||
}),
|
||||
Duration: function(n) {var res = "", h = 0;
|
||||
h = parseInt(n/3600000/24), h > 0 && (res += h+"d"), n = n % (3600000*24);
|
||||
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), n = n % 1000;
|
||||
return res + (n > 0? "."+parseInt(n/10): "") + "s";
|
||||
Duration: function(n) { var res = "", h = 0
|
||||
h = parseInt(n/3600000/24), h > 0 && (res += h+"d"), n = n % (3600000*24)
|
||||
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), n = n % 1000
|
||||
return res + (n > 0? "."+parseInt(n/10): "") + "s"
|
||||
},
|
||||
Number: shy("数字格式化", function(d, n) {var result = [];
|
||||
Number: shy("数字格式化", function(d, n) { var result = []
|
||||
while (d > 0) { result.push(d % 10); d = parseInt(d / 10); n-- }
|
||||
while (n > 0) { result.push("0"); n-- }
|
||||
result.reverse();
|
||||
return result.join("");
|
||||
return result.reverse(), result.join("")
|
||||
}),
|
||||
Format: shy("数据格式化", function(obj) { return JSON.stringify(obj) }),
|
||||
|
||||
@ -83,23 +82,23 @@ Volcanos("base", {help: "基础模块",
|
||||
isNight: function() { var now = new Date()
|
||||
return now.getHours() < 7 || now.getHours() > 17
|
||||
},
|
||||
parseSize: function(size) {
|
||||
if (size.endsWith("TB") || size.endsWith("tb") || size.endsWith("T") || size.endsWith("t")) {
|
||||
parseSize: function(size) { size = size.toLowerCase()
|
||||
if (size.endsWith("tb") || size.endsWith("t")) {
|
||||
return parseInt(size) * 1024 * 1024 * 1024 * 1024
|
||||
}
|
||||
if (size.endsWith("GB") || size.endsWith("gb") || size.endsWith("G") || size.endsWith("g")) {
|
||||
if (size.endsWith("gb") || size.endsWith("g")) {
|
||||
return parseInt(size) * 1024 * 1024 * 1024
|
||||
}
|
||||
if (size.endsWith("MB") || size.endsWith("mb") || size.endsWith("M") || size.endsWith("m")) {
|
||||
if (size.endsWith("mb") || size.endsWith("m")) {
|
||||
return parseInt(size) * 1024 * 1024
|
||||
}
|
||||
if (size.endsWith("KB") || size.endsWith("kb") || size.endsWith("K") || size.endsWith("k")) {
|
||||
if (size.endsWith("kb") || size.endsWith("k")) {
|
||||
return parseInt(size) * 1024
|
||||
}
|
||||
return parseInt(size)
|
||||
},
|
||||
|
||||
_fileLine: function() { var obj = {}; Error.captureStackTrace(obj, arguments.callee); return obj.stack; },
|
||||
_fileLine: function() { var obj = {}; Error.captureStackTrace(obj, arguments.callee); return obj.stack },
|
||||
FileLine: function(depth) { return this._fileLine().split("\n")[1+depth].trim() },
|
||||
Log: function() {
|
||||
var args = [this.Time(), this.FileLine(2, 3).split("/").slice(3).slice(-length).join("/") ]
|
||||
|
31
lib/core.js
31
lib/core.js
@ -1,5 +1,5 @@
|
||||
Volcanos("core", {help: "核心模块",
|
||||
Items: shy("迭代器", function(obj, cb) {var list = [];
|
||||
Items: shy("迭代器", function(obj, cb) { var list = []
|
||||
for (var key in obj) {
|
||||
list = list.concat(this.List(obj[key], function(value, index, array) {
|
||||
return typeof cb == "function" && cb(value, index, key, obj)
|
||||
@ -7,7 +7,7 @@ Volcanos("core", {help: "核心模块",
|
||||
}
|
||||
return list
|
||||
}),
|
||||
Item: shy("迭代器", function(obj, cb) {var list = [];
|
||||
Item: shy("迭代器", function(obj, cb) { var list = []
|
||||
for (var k in obj) {
|
||||
var res = typeof cb == "function"? cb(k, obj[k]): k
|
||||
res && list.push(res)
|
||||
@ -16,12 +16,12 @@ Volcanos("core", {help: "核心模块",
|
||||
}),
|
||||
List: shy("迭代器", function(obj, cb, interval, cbs) {
|
||||
if (typeof obj == "number") {
|
||||
var begin = 0, end = obj, step = 1;
|
||||
var begin = 0, end = obj, step = 1
|
||||
if (typeof interval == "number") {
|
||||
step = interval
|
||||
}
|
||||
if (typeof cb == "number") {
|
||||
begin = obj, end = cb;
|
||||
begin = obj, end = cb
|
||||
}
|
||||
|
||||
var list = []
|
||||
@ -34,17 +34,17 @@ Volcanos("core", {help: "核心模块",
|
||||
obj = typeof obj == "string"? [obj]: (obj || [])
|
||||
if (interval > 0) {
|
||||
function loop(i) { if (i >= obj.length) { return typeof cbs == "function" && cbs(obj) }
|
||||
typeof cb == "function" && cb(obj[i], i, obj), setTimeout(function() {loop(i+1)}, interval);
|
||||
typeof cb == "function" && cb(obj[i], i, obj), setTimeout(function() { loop(i+1) }, interval)
|
||||
}
|
||||
obj.length > 0 && setTimeout(function() {loop(0)}, interval/4);
|
||||
return obj;
|
||||
obj.length > 0 && setTimeout(function() { loop(0) }, interval/4)
|
||||
return obj
|
||||
}
|
||||
|
||||
var list = [], res;
|
||||
var list = [], res
|
||||
for (var i = 0; i < obj.length; i++) {
|
||||
typeof cb == "function"? (res = cb(obj[i], i, obj)) != undefined && list.push(res): list.push(obj[i]);
|
||||
typeof cb == "function"? (res = cb(obj[i], i, obj)) != undefined && list.push(res): list.push(obj[i])
|
||||
}
|
||||
return list;
|
||||
return list
|
||||
}),
|
||||
Next: shy("迭代器", function(obj, cb, cbs) { obj = typeof obj == "string"? [obj]: (obj || [])
|
||||
function next(list, cb, index) {
|
||||
@ -62,15 +62,15 @@ Volcanos("core", {help: "核心模块",
|
||||
|
||||
function _list(str) { var res = {}; for (var i = 0; i < str.length; i++) { res[str[i]] = true }; return res }
|
||||
// 空白符
|
||||
var seps = _list(arg[0]||"\t ,\n");
|
||||
var seps = _list(arg[0]||"\t ,\n")
|
||||
// 分隔符
|
||||
var sups = _list(arg[1]||"{[(.:)]}");
|
||||
var sups = _list(arg[1]||"{[(.:)]}")
|
||||
// 引用符
|
||||
var subs = _list(arg[2]||"'\"`");
|
||||
var subs = _list(arg[2]||"'\"`")
|
||||
|
||||
// 开始分词
|
||||
var res = [], list = str;
|
||||
var left = "", space = true, begin = 0;
|
||||
var res = [], list = str
|
||||
var left = "", space = true, begin = 0
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
if (seps[list[i]]) {
|
||||
// 空白符
|
||||
@ -164,6 +164,5 @@ Volcanos("core", {help: "核心模块",
|
||||
}
|
||||
return obj === other
|
||||
},
|
||||
|
||||
})
|
||||
|
||||
|
27
lib/misc.js
27
lib/misc.js
@ -1,6 +1,6 @@
|
||||
Volcanos("misc", {help: "工具模块",
|
||||
Message: function(event, can) { var msg = {}
|
||||
msg.__proto__ = {_event: event, _can: can, _create_time: new Date(),
|
||||
msg.__proto__ = {_event: event, _can: can,
|
||||
Option: function(key, val) {
|
||||
if (key == undefined) { return msg && msg.option || [] }
|
||||
if (typeof key == "object") { can.core.Item(key, msg.Option) }
|
||||
@ -17,7 +17,7 @@ Volcanos("misc", {help: "工具模块",
|
||||
msg[key] = can.core.List(arguments).slice(1)
|
||||
return val
|
||||
},
|
||||
Result: function(cb) {
|
||||
Result: function() {
|
||||
return msg.result && msg.result.join("") || ""
|
||||
},
|
||||
Table: function(cb) { if (!msg.append || !msg.append.length || !msg[msg.append[0]]) { return }
|
||||
@ -72,9 +72,8 @@ Volcanos("misc", {help: "工具模块",
|
||||
return msg
|
||||
},
|
||||
Echo: function(res) { msg.result = msg.result || []
|
||||
msg._hand = true
|
||||
for (var i = 0; i < arguments.length; i++) { msg.result.push(arguments[i]) }
|
||||
return msg
|
||||
return msg._hand = true, msg
|
||||
},
|
||||
}
|
||||
return msg
|
||||
@ -96,7 +95,7 @@ Volcanos("misc", {help: "工具模块",
|
||||
try { // 解析响应
|
||||
var res = JSON.parse(xhr.responseText)
|
||||
} catch (e) {
|
||||
var res = {"result": []}
|
||||
var res = {"result": [xhr.responseText]}
|
||||
}
|
||||
}
|
||||
xhr.status == 200 && typeof cb == "function" && cb(msg.Copy(res))
|
||||
@ -105,12 +104,12 @@ Volcanos("misc", {help: "工具模块",
|
||||
if (msg.upload) {
|
||||
// 文件参数
|
||||
var data = new FormData()
|
||||
can.core.Item(form, function(key, value) {
|
||||
can.core.List(value, function(item) {data.append(key, item)})
|
||||
})
|
||||
data.append("upload", msg.upload)
|
||||
can.core.Items(form, function(value, index, key) {
|
||||
data.append(key, item)
|
||||
}), data.append("upload", msg.upload)
|
||||
|
||||
xhr.upload.onprogress = function(event) {
|
||||
typeof msg._progress == "function" && msg._progress(event, parseInt(event.loaded/event.total*100), event.total, event.loaded)
|
||||
typeof msg._progress == "function" && msg._progress(event, parseInt(event.loaded*100/event.total), event.total, event.loaded)
|
||||
}
|
||||
} else {
|
||||
// 表单参数
|
||||
@ -132,11 +131,11 @@ Volcanos("misc", {help: "工具模块",
|
||||
}
|
||||
msg._xhr = xhr
|
||||
}),
|
||||
Run: shy("请求后端", {order: 0}, function(event, can, dataset, cmd, cb) { event = event || {}
|
||||
var msg = (can.request||can.Event)(event)
|
||||
Run: shy("请求后端", {order: 0}, function(event, can, dataset, cmd, cb) {
|
||||
var msg = can.request(event = event || {})
|
||||
|
||||
// 解析参数
|
||||
var option = {"cmds": cmd||msg.cmd}
|
||||
var option = {cmds: cmd||msg.cmd}
|
||||
msg.option && msg.option.forEach(function(item) {
|
||||
msg[item] && (option[item] = msg[item])
|
||||
})
|
||||
@ -144,7 +143,7 @@ Volcanos("misc", {help: "工具模块",
|
||||
return msg[key] = value, key
|
||||
})
|
||||
|
||||
msg._hand = true, can.misc.POST(can, msg, can.Conf("iceberg")+(msg.names||dataset.names||event.names||"").toLowerCase()+"?="+event._pane, option, function(msg) {
|
||||
msg._hand = true, can.misc.POST(can, msg, can.Conf("iceberg")+(msg.names||dataset.names||event.names||"").toLowerCase()+"?="+(msg._can.sup||msg._can)._name, option, function(msg) {
|
||||
typeof cb == "function" && cb(msg)
|
||||
}), delete(event.msg)
|
||||
}),
|
||||
|
@ -31,6 +31,7 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, meta,
|
||||
}
|
||||
},
|
||||
|
||||
"upload": function(event, can) { can.user.upload(event, can) },
|
||||
"关闭": function(event, can) { can.page.Remove(can, can.sup._target) },
|
||||
"上传": function(event, can) { can.user.upload(event, can) },
|
||||
"执行": function(event, can) { can.run(event) },
|
||||
|
2
proto.js
2
proto.js
@ -20,7 +20,7 @@ var Volcanos = shy("火山架", {libs: [], cache: {}}, [], function(name, can, l
|
||||
}); Preload = Preload.concat(Config.plugin)
|
||||
|
||||
// 根模块
|
||||
meta.libs = Config.libs, meta.volcano = Config.volcano
|
||||
meta.volcano = Config.volcano, meta.libs = Config.libs
|
||||
name = Config.name, can = {_follow: Config.name,
|
||||
_target: document.body, _width: window.innerWidth, _height: window.innerHeight,
|
||||
}, libs = Preload.concat(Config.volcano), cb = function(can) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user