From 3463a8f378ac1c857a2ad5fd24b3e7610df2ce2a Mon Sep 17 00:00:00 2001 From: shylinux Date: Sat, 5 Jun 2021 10:32:48 +0800 Subject: [PATCH] opt some --- frame.js | 11 +++++++++-- lib/user.js | 5 +++-- panel/river.js | 21 +++++++++------------ plugin/input/date.js | 6 +++--- plugin/local/team/plan.js | 2 +- proto.js | 3 +-- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/frame.js b/frame.js index ad31a480..73af2210 100644 --- a/frame.js +++ b/frame.js @@ -229,8 +229,9 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, can._daemon == undefined && (can._daemon = can.ondaemon._list.push(can)-1), msg._daemon = msg._daemon||can._daemon return can.run(event, cmds, function(msg) { var sub = can.core.Value(can, "_outputs.-1")||{}; can._msg = msg, sub._msg = msg - if (msg._can == can && can.core.CallFunc([sub, "onimport._process"], [sub, msg, cmds, cb])) { return } - if (msg._can == can && can.core.CallFunc([can, "onimport._process"], [can, msg, cmds, cb])) { return } + var process = msg._can == can || msg._can == sub + if (process && can.core.CallFunc([sub, "onimport._process"], [sub, msg, cmds, cb])) { return } + if (process && can.core.CallFunc([can, "onimport._process"], [can, msg, cmds, cb])) { return } if (can.base.isFunc(cb) && can.core.CallFunc(cb, {can: can, msg: msg})) { return } if (silent) { return } @@ -248,6 +249,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, return can.onappend._output(can, meta, event, can.Pack(cmds, silent), cb, silent) }, can._outputs.push(table), table._msg = msg + table._display = display table.onimport && table.onimport._init && table.onimport._init(table, msg, msg.result||[], function(msg) { can.page.Modify(can, can._action, ""), can.page.Modify(can, can._status, "") table.onaction && table.onappend._action(table, can.base.Obj(msg.Option("_action"), meta._action||table.onaction.list)) @@ -370,6 +372,11 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, code && code.scrollBy(0, 10000) return code }, + style: function(can, cb) { + can.require([can._display.replace(/.js$/, ".css")], function() { + can.base.isFunc(cb) && cb() + }) + }, figure: function(can, meta, key, cb, target) { if (!key || key[0] != "@") { return } diff --git a/lib/user.js b/lib/user.js index 77f5f88b..8ab28c02 100644 --- a/lib/user.js +++ b/lib/user.js @@ -168,7 +168,7 @@ Volcanos("user", {help: "用户操作", agent: { var msg = can.request(event, can.Option()) var ui = can.page.Append(can, document.body, [{view: ["input"], style: {left: 0, top: 0}, list: [ {view: ["option", "table"], list: can.core.List(form, function(item) { - (item._input == "select"||item.values) && (item = {select: [[item.name].concat(item.values)], data: item, name: item.name}) + (item._input == "select"||item.values) && (item = {select: [[item.name].concat(item.values)], data: item, name: item.name, _trans: item._trans}) item = typeof item == "string"? {input: item, name: item}: item.length > 0? {select: [item], name: item[0]}: item item.type = item.type||"input", item.type == "input" && (item.data=item.data||{}, item.data.type = item.data.type||"text") @@ -185,7 +185,7 @@ Volcanos("user", {help: "用户操作", agent: { target.value = target.value || msg.Option(item.name) } - return {type: "tr", list: [{type: "td", list: [{text: can.user.trans(can, item.name)||""}]}, {type: "td", list: [item]} ]} + return {type: "tr", list: [{type: "td", list: [{text: item._trans||can.user.trans(can, item.name)||""}]}, {type: "td", list: [item]} ]} })}, {view: "action"}, ]}]); can.onlayout.figure(event, can, ui._target) @@ -197,6 +197,7 @@ Volcanos("user", {help: "用户操作", agent: { list = can.page.Select(can, ui.table, "textarea,input,select", function(item) { return item.name && item.value && args.push(item.name, item.value), data[item.name] = item.value }) + var msg = can.request(event, {_handle: "true"}) can.base.isFunc(cb) && !cb(event, button, data, list, args) && action.cancel() }, _target: ui._target, }) diff --git a/panel/river.js b/panel/river.js index ed71b9b0..21620ccf 100644 --- a/panel/river.js +++ b/panel/river.js @@ -71,10 +71,7 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, msg, can.base.isFunc(cb) && cb() }, _const: ["title", "river", "storm", "action"], - _trans: { - create: "创建", refresh: "刷新", - "public": "公开群", "protected": "内部群", "private": "私有群", - }, + _trans: {create: "创建", refresh: "刷新"}, onlogin: function(can, msg) { can.onappend._action(can, can.Conf("action")||can.onaction.list) can.run({}, [], function(msg) { can.onimport._init(can, msg, [], null, can._output) }) @@ -122,10 +119,10 @@ Volcanos("onaction", {help: "控件交互", list: [], _init: function(can, msg, }, create: function(event, can) { - can.user.trans(can, {type: "类型", name: "群名", text: "简介"}) + can.user.trans(can, {"public": "公开群", "protected": "内部群", "private": "私有群"}) can.user.input(event, can, [ - {name: "type", values: ["public", "protected", "private"]}, - {name: "name", value: "hi"}, {type: "textarea", name: "text", value: "hello"}, + {name: "type", values: ["public", "protected", "private"], _trans: "类型"}, + {name: "name", value: "hi", _trans: "群名"}, {type: "textarea", name: "text", value: "hello", _trans: "简介"}, ], function(event, button, meta, list, args) { can.run(event, [can._ACTION, "create"].concat(args), function(msg) { can.user.Search(can, {river: msg.Result()}) @@ -145,7 +142,7 @@ Volcanos("ondetail", {help: "菜单交互", list: ["共享群组", "添加用户 "共享群组": function(event, can, button, river) { can.user.input(event, can, [ - {name: "name", value: river}, + {name: "name", value: river, _trans: "标题"}, ], function(event, button, meta, list) { can.user.share(can, can.request(event), [river, can._ACTION, "share", "type", can._RIVER, "name", meta.name]) }) @@ -165,10 +162,10 @@ Volcanos("ondetail", {help: "菜单交互", list: ["共享群组", "添加用户 }) }, "添加应用": function(event, can, button, river) { - can.user.trans(can, {type: "类型", name: "名称", text: "简介"}) + can.user.trans(can, {"public": "公开应用", "protected": "群组应用", "private": "个人应用"}) can.user.input(event, can, [ - {name: "type", values: ["public", "protected", "private"]}, - {name: "name", value: "hi"}, {name: "text", value: "hello"}, + {name: "type", values: ["public", "protected", "private"], _trans: "类型"}, + {name: "name", value: "hi", _trans: "名称"}, {type: "textarea", name: "text", value: "hello", _trans: "简介"}, ], function(event, button, meta, list, args) { can.run({}, [river, "tool", can._ACTION, "create"].concat(args), function(msg) { can.user.Search(can, {river: river, storm: msg.Result()}) @@ -191,7 +188,7 @@ Volcanos("ondetail", {help: "菜单交互", list: ["共享群组", "添加用户 "共享应用": function(event, can, button, river, storm) { can.user.input(event, can, [ - {name: "name", value: storm}, + {name: "name", value: storm, _trans: "标题"}, ], function(event, button, meta, list) { var msg = can.request(event) can.user.share(can, msg, [river, can._ACTION, "share", "type", can._STORM, "name", meta.name, diff --git a/plugin/input/date.js b/plugin/input/date.js index 88c888b0..45fab1e4 100644 --- a/plugin/input/date.js +++ b/plugin/input/date.js @@ -11,9 +11,9 @@ Volcanos("onfigure", {help: "控件详情", list: [], date: {onclick: function(e ["month"].concat(can.core.List(1, 13)), "下一月", ], can._action, { "关闭": function(event) { can.page.Remove(can, can._target) }, - "hour": function(event, can, key, value) { now.setHours(parseInt(value)), show(now) }, - "minute": function(event, can, key, value) { now.setMinutes(parseInt(value)), show(now) }, - "second": function(event, can, key, value) { now.setSeconds(parseInt(value)), show(now) }, + "hour": function(event, can, key, value) { now.setHours(parseInt(value)||0), show(now) }, + "minute": function(event, can, key, value) { now.setMinutes(parseInt(value)||0), show(now) }, + "second": function(event, can, key, value) { now.setSeconds(parseInt(value)||0), show(now) }, "今天": function(event) { now = new Date(), set(show(now)) }, "上一月": function(event) { now.setMonth(now.getMonth()-1), show(now) }, diff --git a/plugin/local/team/plan.js b/plugin/local/team/plan.js index f1f505a5..5b31132a 100644 --- a/plugin/local/team/plan.js +++ b/plugin/local/team/plan.js @@ -168,7 +168,7 @@ Volcanos("onaction", {help: "组件交互", list: [ ["score", "all", "s1", "s2", "s3", "s4", "s5"], ["view", "", "name", "text", "level", "score"], ], - insertTask: function(event, can, time) { + insertTask: function(event, can, time) { var msg = can.sup.request(event, {begin_time: time}) can.user.input(event, can, can.Conf("feature.insert"), function(event, button, data, list) { var args = ["action", "insert"]; can.core.Item(data, function(key, value) { if (key == "begin_time") { value = value || time } diff --git a/proto.js b/proto.js index 22755ff0..5ca7a7f9 100644 --- a/proto.js +++ b/proto.js @@ -28,8 +28,7 @@ var Volcanos = shy("火山架", {args: {}, pack: {}, libs: [], cache: {}}, [], f } } - var proto = {_name: name, _load: function(name, cb) { - // 加载缓存 + var proto = {_name: name, _load: function(name, cb) { // 加载缓存 var cache = meta.cache[name] || []; for (list.reverse(); list.length > 0; list) { var sub = list.pop(); sub != can && cache.push(sub) }; meta.cache[name] = cache