From 86badb0c38678840eab4b7a897143d88f723eabc Mon Sep 17 00:00:00 2001 From: shylinux Date: Wed, 27 May 2020 10:50:34 +0800 Subject: [PATCH] opt index.js --- frame.js | 13 ++++---- history/plugin/chrome/chrome.html | 2 +- history/plugin/chrome/popup.html | 2 +- history/share.html | 2 +- style.css => index.css | 0 index.html | 4 +-- index.js | 23 ++++---------- page/share.html | 2 +- pane/Action.js | 9 ++++-- proto.js | 50 ++++++++++++++++++------------- 10 files changed, 52 insertions(+), 55 deletions(-) rename style.css => index.css (100%) diff --git a/frame.js b/frame.js index 2a9c5db9..a954ec87 100644 --- a/frame.js +++ b/frame.js @@ -1,12 +1,12 @@ Volcanos("onaction", { _init: function(can, meta, list, cb, target) { can.core.Next(meta.panes, function(item, next) { - can.onappend._init(can, item, Config.libs.concat(item.list), function(pane) { + can.onappend._init(can, item, meta.libs.concat(item.list), function(pane) { pane.Conf(item), pane.run = function(event, cmds, cb) { (can.onaction[cmds[0]]||can.onaction[meta.main.engine])(event, can, pane.request(event), pane, cmds, cb); }, can[item.name] = pane, next(); }, can._target); }, function() { can.onlayout._init(can, meta, list, function() { - can.require(["/publish/order.js"], function(can) { + can.require(meta.main.list, function(can) { function getAction() {} function getStorm(storm) { can.core.Item(storm, function(key, value) { value._link? can.require([value._link], function(can) { @@ -100,7 +100,7 @@ Volcanos("onappend", { _init: function(can, meta, list, cb, target, field) { var sub = Volcanos(meta.name, { _help: meta.name, _target: field, _option: option, _action: action, _output: output, _history: [], _follow: can._follow+"."+meta.name, - }, [Config.volcano].concat(list), function(sub) { + }, [Volcanos.meta.volcano].concat(list), function(sub) { meta.feature = can.base.Obj(meta.feature, {}) meta.detail = meta.feature["detail"] || {} sub.onimport._init(sub, sub.Conf(meta), list, function() {}, field); @@ -112,7 +112,7 @@ Volcanos("onappend", { _init: function(can, meta, list, cb, target, field) { _target: can.onappend.input(sub, option, item.type, item, args[index]), _option: option, _action: action, _output: output, _follow: can._follow+"."+meta.name+"."+item.name, - }, Config.libs.concat([item.display||"/plugin/input.js"]), function(input) { + }, Volcanos.meta.libs.concat([item.display||"/plugin/input.js"]), function(input) { input.onimport._init(input, input.Conf(item), item.list||[], function() {}, input._target); input.run = function(event, cmds, cb, silent) { @@ -144,7 +144,7 @@ Volcanos("onappend", { _init: function(can, meta, list, cb, target, field) { sub[display] = Volcanos(display, { _target: output, _option: option, _action: action, _output: output, _follow: can._follow+"."+meta.name+"."+display, - }, Config.libs.concat(["/frame.js", display]), function(table) { table.Conf(sub.Conf()) + }, Volcanos.meta.libs.concat(["/frame.js", display]), function(table) { table.Conf(sub.Conf()) table.onimport._init(table, msg, msg.append||[], function() {}, output) table.run = function(event, cmds, cb, silent) { @@ -233,7 +233,7 @@ Volcanos("onappend", { _init: function(can, meta, list, cb, target, field) { item.type == "textarea" && can.page.Append(can, option, [{type: "br"}]); item.type == "text" && !target.placeholder && (target.placeholder = item.name || ""); - item.type != "button" && !target.title && (target.title = item.placeholder); + item.type != "button" && !target.title && (target.title = target.placeholder); // item.type == "button" && item.action == "auto" && can.run && can.run({}); item.type == "select" && (target.value = item.value || item.values[item.index||0]); return target; @@ -354,7 +354,6 @@ Volcanos("onappend", { _init: function(can, meta, list, cb, target, field) { }, [], function(can) {}) Volcanos("onlayout", { _init: function(can, meta, list, cb, target) { var width = can._width, height = can._height; - if (Volcanos.meta.follow[can._root]) { debugger } can.page.Select(can, target, "fieldset.head", function(field) { height -= field.offsetHeight; diff --git a/history/plugin/chrome/chrome.html b/history/plugin/chrome/chrome.html index f50dcf02..ef630a19 100644 --- a/history/plugin/chrome/chrome.html +++ b/history/plugin/chrome/chrome.html @@ -2,7 +2,7 @@ - + diff --git a/history/plugin/chrome/popup.html b/history/plugin/chrome/popup.html index 436c82dd..902facfd 100644 --- a/history/plugin/chrome/popup.html +++ b/history/plugin/chrome/popup.html @@ -2,7 +2,7 @@ - + diff --git a/history/share.html b/history/share.html index fdf8c554..a50b95b3 100644 --- a/history/share.html +++ b/history/share.html @@ -5,7 +5,7 @@ volcanos - + diff --git a/style.css b/index.css similarity index 100% rename from style.css rename to index.css diff --git a/index.html b/index.html index d1830245..f05f86f6 100644 --- a/index.html +++ b/index.html @@ -3,8 +3,8 @@ volcanos - - + + diff --git a/index.js b/index.js index b3c065b1..44859e84 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -var Config = {name: "demo", volcano: "/frame.js", iceberg: "/chat/", intshell: "plug.sh", +Volcanos({name: "demo", volcano: "/frame.js", iceberg: "/chat/", intshell: "plug.sh", libs: ["/lib/base", "/lib/core", "/lib/misc", "/lib/page", "/lib/user"], panes: [ {type: "pane", name: "Header", help: "标题栏", pos: "head", list: ["/pane/Header.js", "/pane/Header.css"], state: [ "time", "username", @@ -9,26 +9,13 @@ var Config = {name: "demo", volcano: "/frame.js", iceberg: "/chat/", intshell: " {type: "pane", name: "Footer", help: "状态条", pos: "foot", list: ["/pane/Footer.js", "/pane/Footer.css"], state: [ "ncmd", ]}, - ], main: {name: "Header", engine: "remote", list: []}, - list: ["/plugin/state.js", "/plugin/input.js", "/plugin/table.js", + ], main: {name: "Header", engine: "remote", list: ["/publish/order.js"]}, plugin: [ + "/plugin/state.js", + "/plugin/input.js", + "/plugin/table.js", "/plugin/input/key", "/plugin/input/date", "/plugin/input/upload", "/plugin/input/province", ], -} - -var Preload = Config.libs; Config.panes.forEach(function(pane) { - Preload = Preload.concat(pane.list); -}); Preload = Preload.concat(Config.list) - -Volcanos(Config.name, { _target: document.body, _follow: "demo", - _head: document.head, _body: document.body, - _width: window.innerWidth, _height: window.innerHeight, -}, Preload.concat(Config.volcano), function(can) { // 程序入口 - can.onaction._init(can, can.Conf(Config), [], function(msg) { - console.log(can._root, can._name, "start", can, msg); - can.Footer.onaction._init(can.Footer, msg); - }, can._target) }) - diff --git a/page/share.html b/page/share.html index 291c2339..7c42a158 100644 --- a/page/share.html +++ b/page/share.html @@ -5,7 +5,7 @@ volcanos - + diff --git a/pane/Action.js b/pane/Action.js index 21331f9d..aa5f3014 100644 --- a/pane/Action.js +++ b/pane/Action.js @@ -27,9 +27,12 @@ Volcanos("onexport", {help: "导出数据", list: [], if (position) { can._output.scrollTo(0, position-1); return } msg.Clear("option"), can.run(msg._event, [river, storm], function(sup) { can._output.innerHTML = ""; sup.Table(function(value, index, array) { - value.inputs = can.base.Obj(value.inputs, []) - value.inputs.length == 0 && (value.inputs = [{type: "text"}, {type: "button", name: "查看"}]) - can.onappend._init(can, value, Config.libs.concat(["/plugin/state.js"]), function(sub) { + value.inputs = can.base.Obj(value.inputs, []), value.inputs.length == 0 && (value.inputs = [ + {type: "text", name: "name", action: "auto"}, + {type: "button", name: "查看", action: "auto"}, + {type: "button", name: "返回"}, + ]); + can.onappend._init(can, value, Volcanos.meta.libs.concat(["/plugin/state.js"]), function(sub) { sub.run = function(event, cmds, cb, silent) { var msg = can.request(event, {_msg: sup}); // 插件回调 can.run(event, [river, storm, index].concat(cmds), function(msg) { diff --git a/proto.js b/proto.js index 5a26bfd0..fdf3f607 100644 --- a/proto.js +++ b/proto.js @@ -9,7 +9,7 @@ function shy(help, meta, list, cb) { } var cb = arguments[arguments.length-1] || function() {}; - cb.help = next("string") || "还没有写"; + cb.help = next("string") || cb.name; cb.meta = next("object") || {}; cb.list = next("object") || []; return cb; @@ -18,23 +18,31 @@ var Volcanos = shy("火山架", {cache: {}, index: 1, order: 1, debug: { volcano: false, config: true, require: true, cache: false, frame: false, request: true, search: true, -}, follow: { - volcano: false, debug: true, - // volcano: true, debug: true, -}}, [], function(name, can, libs, cb) { var meta = arguments.callee.meta, list = arguments.callee.list; +}, libs: []}, [], function(name, can, libs, cb) { var meta = arguments.callee.meta, list = arguments.callee.list; + if (typeof name == "object") { var Config = name; + meta.volcano = Config.volcano, meta.libs = Config.libs; + var Preload = Config.libs; Config.panes.forEach(function(pane) { + Preload = Preload.concat(pane.list); + }); Preload = Preload.concat(Config.plugin) - var conf = {}, conf_cb = {}, sync = {}, cache = {}; - meta.debug[can._root] && console.debug(can._root, name, "create"); - can = can || {}, list.push(can) && (can.__proto__ = { _name: name, _root: "volcano", _create_time: new Date(), _load: function(name, cb) { + name = Config.name, can = { _target: document.body, _follow: Config.name, + _head: document.head, _body: document.body, + _width: window.innerWidth, _height: window.innerHeight, + }, libs = Preload.concat(Config.volcano), cb = function(can) { + can.onaction._init(can, can.Conf(Config), [], function(msg) { + }, can._target) + } + } + + var conf = {}, conf_cb = {}, cache = {}; + can = can || {}, list.push(can) && (can.__proto__ = {_name: name, _root: "volcano", _create_time: new Date(), _load: function(name, cb) { for (var cache = meta.cache[name] || []; meta.index < list.length; meta.index++) { - if (list[meta.index] == can) {continue} - meta.debug["cache"] && console.debug("cache", name, "load", meta.index, list[meta.index]); + if (list[meta.index] == can) { continue } cache.push(list[meta.index]); // 加载缓存 } for (var i = 0; i < cache.length; i++) { - meta.debug["frame"] && console.debug("frame", can._name, "load", i, cache[i]); typeof cb == "function" && cb(can, name, cache[i]) || (can[cache[i]._name] = cache[i]); // 加载索引 } @@ -159,16 +167,6 @@ var Volcanos = shy("火山架", {cache: {}, index: 1, order: 1, debug: { } return conf[key] || "" }), - Timer: shy("定时器, value, [1,2,3,4], {value, length}", function(interval, cb, cbs) { interval = typeof interval == "object"? interval || []: [interval]; - var timer = {stop: false}; - 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(event, interval.value||interval[i], i, interval)? - typeof cbs == "function" && cbs(event, interval): - setTimeout(function() {loop(event, i+1)}, interval.value||interval[i+1]); - } - setTimeout(function(event) {loop(event, 0)}, interval.value||interval[0]); - return timer; - }), Cache: shy("缓存器", function(name, output, data) { if (data) { if (output.children.length == 0) { return } // 写缓存 @@ -196,6 +194,16 @@ var Volcanos = shy("火山架", {cache: {}, index: 1, order: 1, debug: { delete(cache[name]); return list.data; }), + Timer: shy("定时器, value, [1,2,3,4], {value, length}", function(interval, cb, cbs) { interval = typeof interval == "object"? interval || []: [interval]; + var timer = {stop: false}; + 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(event, interval.value||interval[i], i, interval)? + typeof cbs == "function" && cbs(event, interval): + setTimeout(function() {loop(event, i+1)}, interval.value||interval[i+1]); + } + setTimeout(function(event) {loop(event, 0)}, interval.value||interval[0]); + return timer; + }), }); return can.require(libs, cb), can