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

opt proto.js

This commit is contained in:
shaoying 2020-12-12 17:54:16 +08:00
parent 2df8fd6192
commit d45af932f1
4 changed files with 42 additions and 60 deletions

View File

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<head> <head>
<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 charset="utf-8">
<title>volcanos</title> <title>volcanos</title>
<link rel="shortcut icon" type="image/ico" href="favicon.ico"> <link rel="shortcut icon" type="image/ico" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="cache.css"> <link rel="stylesheet" type="text/css" href="cache.css">

View File

@ -6,7 +6,7 @@ Volcanos({name: "chat", iceberg: "/chat/", volcano: "/frame.js",
{name: "River", help: "群聊组", pos: "left"}, {name: "River", help: "群聊组", pos: "left"},
{name: "Action", help: "工作台", pos: "middle"}, {name: "Action", help: "工作台", pos: "middle"},
{name: "Footer", help: "状态条", pos: "foot", state: ["ncmd", "keys"]}, {name: "Footer", help: "状态条", pos: "foot", state: ["ncmd", "keys"]},
], main: {name: "Header", engine: "remote", list: ["publish/order.js"]}, plugin: [ ], main: {name: "Header", engine: "remote", list: ["/publish/order.js"]}, plugin: [
"/plugin/state.js", "/plugin/state.js",
"/plugin/input.js", "/plugin/input.js",
"/plugin/table.js", "/plugin/table.js",

View File

@ -21,6 +21,7 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg,
// 添加插件 // 添加插件
can.onappend._init(can, value, ["/plugin/state.js"], function(plugin) { can.onappend._init(can, value, ["/plugin/state.js"], function(plugin) {
can._plugins = (can._plugins||[]).concat([plugin])
plugin.run = function(event, cmds, cb, silent) { var msg = plugin.request(event); cmds = cmds || [] plugin.run = function(event, cmds, cb, silent) { var msg = plugin.request(event); cmds = cmds || []
can.run(event, can.onengine[cmds[0]]? cmds: [river, storm, value.action].concat(cmds), function(msg) { can.run(event, can.onengine[cmds[0]]? cmds: [river, storm, value.action].concat(cmds), function(msg) {
typeof cb == "function" && cb(msg) typeof cb == "function" && cb(msg)

View File

@ -1,8 +1,8 @@
function shy(help, meta, list, cb) { function shy(help, meta, list, cb) {
var index = -1, value = "", type = "string", args = arguments; function next(check) { var index = -1, args = arguments; function next(check) {
if (++index >= args.length) {return false} if (++index >= args.length) { return }
if (check && check != typeof args[index]) {index--; return false} if (check && check != typeof args[index]) { index--; return }
return value = args[index], type = typeof value, value return args[index]
} }
var cb = arguments[arguments.length-1] || function() {} var cb = arguments[arguments.length-1] || function() {}
@ -14,15 +14,16 @@ function shy(help, meta, list, cb) {
var Volcanos = shy("火山架", {libs: [], cache: {}, index: 1}, [], function(name, can, libs, cb) { var Volcanos = shy("火山架", {libs: [], cache: {}, index: 1}, [], function(name, can, libs, cb) {
var meta = arguments.callee.meta, list = arguments.callee.list var meta = arguments.callee.meta, list = arguments.callee.list
if (typeof name == "object") { var Config = name if (typeof name == "object") { var Config = name
meta.volcano = Config.volcano, meta.libs = Config.libs // 预加载
var Preload = Config.libs; Config.panes.forEach(function(pane) { var Preload = Config.libs; Config.panes.forEach(function(pane) {
Preload = Preload.concat(pane.list = pane.list || ["/pane/"+pane.name+".css", "/pane/"+pane.name+".js"]) Preload = Preload.concat(pane.list = pane.list || ["/pane/"+pane.name+".css", "/pane/"+pane.name+".js"])
Preload = Preload.concat(pane.list = pane.list || ["/pane/"+pane.name+".js"])
}); Preload = Preload.concat(Config.plugin) }); Preload = Preload.concat(Config.plugin)
// 根模块
meta.libs = Config.libs, meta.volcano = Config.volcano
name = Config.name, can = { _follow: Config.name, name = Config.name, can = { _follow: Config.name,
_width: window.innerWidth, _height: window.innerHeight,
_target: document.body, _head: document.head, _body: document.body, _target: document.body, _head: document.head, _body: document.body,
_width: window.innerWidth, _height: window.innerHeight,
}, libs = Preload.concat(Config.volcano), cb = function(can) { }, libs = Preload.concat(Config.volcano), cb = function(can) {
can.onengine._init(can, can.Conf(Config), [], function(msg) { can.onengine._init(can, can.Conf(Config), [], function(msg) {
can.base.Log(can) can.base.Log(can)
@ -31,30 +32,24 @@ var Volcanos = shy("火山架", {libs: [], cache: {}, index: 1}, [], function(na
} }
var conf = {}, conf_cb = {} var conf = {}, conf_cb = {}
can = can || {}, list.push(can) && (can.__proto__ = {__proto__: Volcanos.meta, _name: name, _create_time: new Date(), _load: function(name, cb) { list.push(can = can || {}), can.__proto__ = {__proto__: Volcanos.meta, _name: name, _load: function(name, cb) {
// 加载缓存
for (var cache = meta.cache[name] || []; meta.index < list.length; meta.index++) { for (var cache = meta.cache[name] || []; meta.index < list.length; meta.index++) {
if (name == "/plugin/input/date.css" && cache.length > 0) { continue } list[meta.index] != can && cache.push(list[meta.index])
if (name == "/lib/base.js" && cache.length > 0) { continue } }; meta.cache[name] = cache
if (list[meta.index] == can) { continue }
cache.push(list[meta.index])
// 加载缓存
}
for (var i = 0; i < cache.length; i++) { // 加载模块
if (can[cache[i]._name] && can[cache[i]._name]._merge && can[cache[i]._name]._merge(can, cache[i])) { continue } for (var i = 0; i < cache.length; i++) { var sub = cache[i]
if (typeof cb == "function" && cb(can, name, cache[i])) { continue} if (can[sub._name] && can[sub._name]._merge && can[sub._name]._merge(can, sub)) { continue }
if (can[cache[i]._name]) { if (typeof cb == "function" && cb(can, name, sub)) { continue}
for (var k in cache[i]) { if (can[sub._name]) {
can[cache[i]._name].hasOwnProperty(k) || (can[cache[i]._name][k] = cache[i][k]) for (var k in sub) {
can[sub._name].hasOwnProperty(k) || (can[sub._name][k] = sub[k])
} }
} else { } else {
can[cache[i]._name] = cache[i] can[sub._name] = sub
} }
// 加载索引
} }
meta.cache[name] = cache
}, },
require: function(libs, cb, each) { if (!libs || libs.length == 0) { require: function(libs, cb, each) { if (!libs || libs.length == 0) {
typeof cb == "function" && setTimeout(function() { cb(can) }, 10) typeof cb == "function" && setTimeout(function() { cb(can) }, 10)
@ -66,60 +61,46 @@ var Volcanos = shy("火山架", {libs: [], cache: {}, index: 1}, [], function(na
if (meta.cache[source]) { if (meta.cache[source]) {
can._load(source, each), can.require(libs.slice(1), cb, each) can._load(source, each), can.require(libs.slice(1), cb, each)
return // 缓存加载 return // 加载缓存
} }
if (source.endsWith(".js")) { var script = document.createElement("script") if (source.endsWith(".css")) { var style = document.createElement("link")
if (can.user && source.indexOf("publish") == 0) { style.rel = "stylesheet", style.type = "text/css"
source += "?pod="+(can.user.Search(can, "pod")||"") style.href = source; style.onload = function() {
} can._load(source, each), can.require(libs.slice(1), cb, each)
if (can.user && source.indexOf("/publish") == 0) { } // 加载样式
target.appendChild(style)
} else if (source.endsWith(".js")) { var script = document.createElement("script")
if (source.indexOf("/publish") == 0 && can.user) {
source += "?pod="+(can.user.Search(can, "pod")||"") source += "?pod="+(can.user.Search(can, "pod")||"")
} }
script.src = source, script.onload = function() { script.src = source, script.onload = function() {
can._load(source, each), can.require(libs.slice(1), cb, each) can._load(source, each), can.require(libs.slice(1), cb, each)
} // 加载脚本 } // 加载脚本
target.appendChild(script) target.appendChild(script)
} else if (source.endsWith(".css")) { var style = document.createElement("link")
style.rel = "stylesheet", style.type = "text/css"
style.href = source; style.onload = function() {
can._load(source, each), can.require(libs.slice(1), cb, each)
} // 加载样式
target.appendChild(style)
} }
}, },
request: function(event, option) { event = event || {} request: function(event, option) { event = event || {}
if (event._msg) { event._msg = event._msg || can.misc.Message(event, can)
can.core.Item(option, event._msg.Option) can.core.Item(option, event._msg.Option)
return event._msg return event._msg
}
var ls = (can._name||can._help).split("/")
event._pane = ls[ls.length-1]
var msg = can.misc.Message(event, can)
can.core.Item(option, msg.Option)
return event._msg = msg
}, },
Conf: function(key, value, cb) { Conf: function(key, value) {
if (key == undefined) { return conf } if (key == undefined) { return conf }
if (typeof key == "object") { conf = key; return conf } if (typeof key == "object") { conf = key; return conf }
typeof cb == "function" && (conf_cb[key] = cb) conf[key] = value == undefined? conf[key]: value
if (value != undefined) { var old = conf[key], res;
conf[key] = conf_cb[key] && (res = conf_cb[key](value, old, key)) != undefined && res || value
}
if (conf[key] == undefined && key.indexOf(".") > 0) { if (conf[key] == undefined && key.indexOf(".") > 0) {
var p = conf, ls = key.split(".") var p = conf, ls = key.split("."); while (p && ls.length > 0) {
while (p && ls.length > 0) {
p = p[ls[0]], ls = ls.slice(1) p = p[ls[0]], ls = ls.slice(1)
} }
return p return p
} }
return conf[key] || "" return conf[key]
}, },
}) }
if (_can_name) { if (_can_name) {
meta.cache[_can_name] = meta.cache[_can_name] || [] meta.cache[_can_name] = meta.cache[_can_name] || []