diff --git a/frame.js b/frame.js index 6dadc9e7..52b42981 100644 --- a/frame.js +++ b/frame.js @@ -194,7 +194,7 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, key.indexOf("on") == 0 && !input._target[key] && (input._target[key] = function(event) { value(event, input) }) - }), can.onappend.figure(input, item, item.value, function() {}, input._target) + }), can.onappend.figure(input, item, input._target) can.core.CallFunc([input.onaction, "_init"], [input, item, [], next, input._target]) }) @@ -311,44 +311,10 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, case "": return can.page.Append(can, target, [item]) } - - var title = can.Conf(["feature", "title", item.name].join("."))||"" - var input = {type: html.INPUT, name: item.name, data: item, dataset: {}, _init: item._init, style: item.style} - item.value == "auto" && (item.value = "", item.action = "auto") - item.action == "auto" && (input.dataset.action = "auto") - title && (input.title = title) - - var br = [] - switch (item.type = item.type||item._input||html.TEXT) { - case "textarea": input.type = html.TEXTAREA; item.style = item.style||{} - item.style.width = item.style.width || can.Conf(["feature", html.TEXTAREA, item.name, "width"].join(".")) || can.Conf(["feature", html.TEXTAREA, "width"].join(".")) || 400 - item.style.height = item.style.height || can.Conf(["feature", html.TEXTAREA, item.name, "height"].join(".")) || can.Conf(["feature", html.TEXTAREA, "height"].join(".")) || 30 - br.push({type: "br"}) - // no break - case "password": - // no break - case "text": - item.autocomplete = "off" - item.value = value || item.value || "" - item.className || can.page.ClassList.add(can, item, "args") - break - case "select": input.type = html.SELECT - item.values = typeof item.values == "string"? can.core.Split(item.values): item.values - if (!item.values && item.value) { - item.values = can.core.Split(item.value), item.value = item.values[0] - if (item.values[0] == "day") { item.value = item.values[1] } - } - - item.value = value||item.value, input.list = item.values.map(function(value) { - return {type: html.OPTION, value: value, inner: value} - }), item.className || can.page.ClassList.add(can, item, "args") - break - case "button": item.value = item.value||item.name||"list"; break - case "upfile": item.type = html.FILE; break - case "upload": item.type = html.FILE, input.name = "upload"; break - } - - return can.page.Append(can, target, [{view: ["item "+item.type], list: [input]}].concat(br))[item.name] + var input = can.page.input(can, item, value) + var br = input.type == html.TEXTAREA? [{type: "br"}]: [] + var title = can.Conf(["feature", "title", item.name].join("."))||""; title && (input.title = title) + return can.page.Append(can, target, ([{view: ["item "+item.type], list: [input]}]).concat(br))[item.name] }, table: function(can, msg, cb, target, sort) { var table = can.page.AppendTable(can, msg, target||can._output, msg.append, cb||function(value, key, index, line, array) { @@ -411,25 +377,22 @@ Volcanos("onappend", {help: "渲染引擎", list: [], _init: function(can, meta, }) }, - figure: function(can, meta, key, cb, target) { - if (!key || key[0] != "@") { return } - var list = can.core.Split(key, "@=", "@=") - var pkey = list[0], pval = list[1]||"" + figure: function(can, meta, target, cb) { if (target.type == html.BUTTON) { return } + var input = meta.action||"key"; can.require(["/plugin/input/"+input+".js"], function(can) { + can.core.Item(can.onfigure[input], function(key, on) { if (key.indexOf("on") != 0) { return } + target[key] = function(event) { + can.onappend._init(can, {type: html.INPUT, name: input, pos: "float"}, [], function(sub) { + sub.Conf(meta), sub.run = function(event, cmds, cb) { + var msg = sub.request(event, can.Option()); + (meta.run||can.run)(event, cmds, cb, true) + } - target.type != html.BUTTON && (target.value = pval||""), can.require(["/plugin/input/"+pkey+".js"], function(can) { - can.core.Item(can.onfigure[pkey], function(key, on) { if (key.indexOf("on") == 0) { target[key] = function(event) { - can.onappend._init(can, {type: html.INPUT, name: pkey, pos: "float"}, [], function(sub) { - sub.run = function(event, cmds, cb) { - var msg = sub.request(event, can.Option()); - (meta.run||can.run)(event, cmds, cb, true) - }, sub.Conf(meta) - - can.onmotion.float.add(can, "input", sub) - - meta.style && sub.page.Modify(sub, sub._target, {style: meta.style}) - on(event, sub, meta, cb, target) - }, document.body) - } } }) + meta.style && sub.page.Modify(sub, sub._target, {style: meta.style}) + can.onmotion.float.add(can, "input", sub) + on(event, sub, meta, cb, target) + }, document.body) + } + }) }) }, _plugin: function(can, value, meta, cb, target) { @@ -705,9 +668,7 @@ Volcanos("onmotion", {help: "动态特效", list: [], _init: function(can, targe can.onkeypop.input(event, can) } }, _init: function(target) { - item && can.onappend.figure(can, item, item.value, function() { - - }, target), target.value = text + item && can.onappend.figure(can, item, target), target.value = text }}]); ui.first.focus(), ui.first.setSelectionRange(0, -1) }, modifys: function(can, target, cb) { var back = target.innerHTML diff --git a/lib/page.js b/lib/page.js index 7a0ad89e..7230cece 100644 --- a/lib/page.js +++ b/lib/page.js @@ -298,5 +298,36 @@ Volcanos("page", {help: "用户界面", ClassList: { } return delete(cache[name]), list.data }, + + input: function(can, item, value) { + var input = {type: html.INPUT, name: item.name, data: item, dataset: {}, _init: item._init, style: item.style||{}} + item.value == "auto" && (item.value = "", item.action = "auto"), item.action == "auto" && (input.dataset.action = "auto") + + switch (item.type = item.type||item._input||html.TEXT) { + case html.TEXTAREA: input.type = html.TEXTAREA + input.style.height = input.style.height||can.Conf(["feature", html.TEXTAREA, item.name, "height"].join("."))||can.Conf(["feature", html.TEXTAREA, "height"].join(".")) + input.style.width = input.style.width||can.Conf(["feature", html.TEXTAREA, item.name, "width"].join("."))||can.Conf(["feature", html.TEXTAREA, "width"].join(".")) + // no break + case "password": + // no break + case html.TEXT: + item.autocomplete = "off" + item.value = value||item.value||"" + item.className || can.page.ClassList.add(can, item, "args") + break + case html.SELECT: input.type = html.SELECT + item.values = typeof item.values == "string"? can.core.Split(item.values): item.values + if (!item.values && item.value) { item.values = can.core.Split(item.value), item.value = item.values[0] } + + item.value = value||item.value, input.list = item.values.map(function(value) { + return {type: html.OPTION, value: value, inner: value} + }), item.className || can.page.ClassList.add(can, item, "args") + break + case html.BUTTON: item.value = item.value||item.name||"list"; break + case "upfile": item.type = html.FILE; break + case "upload": item.type = html.FILE, input.name = "upload"; break + } + return input + }, }) diff --git a/lib/user.js b/lib/user.js index bb1db262..2cf0b982 100644 --- a/lib/user.js +++ b/lib/user.js @@ -105,7 +105,7 @@ Volcanos("user", {help: "用户操作", agent: { }) }) }, - login: function(can, cb) { + login: function(can, cb, method) { var ui = can.user.input({}, can, [ {username: "username"}, {password: "password"}, ], function(event, button, data, list) { return { @@ -135,7 +135,7 @@ Volcanos("user", {help: "用户操作", agent: { "飞书": function() { location.href = "/chat/lark/sso" }, - }[button]() }, ["登录", "扫码", "飞书"]) + }[button]() }, can.base.Obj(method, ["登录", "扫码", "飞书"])) can.page.Modify(can, ui._target, {className: "input login", style: {left: (window.innerWidth-ui._target.offsetWidth)/2, top: window.innerHeight/6}}) }, @@ -189,30 +189,26 @@ Volcanos("user", {help: "用户操作", agent: { return event.stopPropagation(), event.preventDefault(), carte }, input: function(event, can, form, cb, button) { // form [ string, array, object, {_input: "select", values: []} - var msg = can.request(event, can.Option()) + var msg = can.request(event) 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 == "textarea") && (item = {type: "textarea", data: item, name: item.name, _trans: item._trans, value: item.value}); - (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") + item = typeof item == "string"? {type: html.TEXT, name: item}: item.length > 0? {type: html.SELECT, name: item[0], values: item.slice(1)}: item item._init = function(target) { item.run = function(event, cmds, cb) { - var res = can.request(event, msg, function() { var value = {_handle: "true"} + can.request(event, function() { var value = {_handle: "true"} can.page.Select(can, ui.table, "textarea,input,select", function(item) { item.name && item.value && (value[item.name] = item.value) }); return value - }); can.run(event, cmds, cb, true) + }, msg, can.Option()); can.run(event, cmds, cb, true) } - can.onappend.figure(can, item, item.value, function() {}, target) - target.value = target.value || msg.Option(item.name) + target.value = target.value||can.Option(item.name)||"" + can.onappend.figure(can, item, target) } - return {type: "tr", list: [{type: "td", list: [{text: item._trans||can.user.trans(can, item.name)||""}]}, {type: "td", list: [item]} ]} - })}, - {view: "action"}, + return {type: "tr", list: [{type: "td", list: [{text: item._trans||can.user.trans(can, item.name)||""}]}, {type: "td", list: [can.page.input(can, item)]} ]} + })}, {view: "action"}, ]}]); can.onlayout.figure(event, can, ui._target) var action = can.onappend._action(can, button||["submit", "cancel"], ui.action, { diff --git a/page/index.css b/page/index.css index 27657965..88f70362 100644 --- a/page/index.css +++ b/page/index.css @@ -489,7 +489,7 @@ body.white table input[type=button][value=启动] { } body.white fieldset>div.status>div.item>label { - font-size:10px; color:#504242e0; + font-size:10px; color:#cefbfbe0; } body.white fieldset.Action { diff --git a/panel/header.js b/panel/header.js index 1745f849..f9cd0cec 100644 --- a/panel/header.js +++ b/panel/header.js @@ -111,11 +111,11 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, msg, }, _time: function(can, target) { can.core.Timer({interval: 500}, function() { can.onimport.time(can, target) }) - can.onappend.figure(can, {style: {"min-width": 306}}, "@date", function(sub) { + can.onappend.figure(can, {style: {"min-width": 306}, action: "date"}, target, function(sub) { can.search({}, ["Action.onexport.size"], function(msg, top) { can.page.Modify(can, sub._target, {style: {top: top, left: window.innerWidth-sub._target.offsetWidth}}) }) - }, target), target.onmouseenter = function() { target.click() } + }), target.onmouseenter = function() { target.click() } }, time: function(can, target) { can.onlayout.topic(can) @@ -187,7 +187,7 @@ Volcanos("onaction", {help: "交互数据", list: [], _init: function(can, meta, // 登录检查 can.user.isLocalFile? init(): can.run({}, [chat.CHECK], function(msg) { can.Conf(aaa.USERNAME, msg.Option(ice.MSG_USERNAME))? init(): - msg.Option("sso")? can.user.jumps(msg.Option("sso")): can.user.login(can, init) + msg.Option("sso")? can.user.jumps(msg.Option("sso")): can.user.login(can, init, msg.Option("login")) }) }, onstorm_select: function(can, msg, river, storm) { diff --git a/plugin/state.js b/plugin/state.js index 80ffdc2f..8393b67c 100644 --- a/plugin/state.js +++ b/plugin/state.js @@ -182,7 +182,7 @@ Volcanos("onaction", {help: "交互操作", list: [ change: function(event, can, name, value, cb) { return can.page.Select(can, can._option, "input.args", function(input) { if (input.name == name && value != input.value) { input.value = value - var data = input.dataset || {}; data.action == "auto" && can.Update(event, can.Input(), cb) + var data = input.dataset || {}; can.Update(event, can.Input(), cb) return input } }) diff --git a/proto.js b/proto.js index c6dd1a6c..9b74dcf1 100644 --- a/proto.js +++ b/proto.js @@ -210,10 +210,15 @@ var Volcanos = shy("火山架", {volcano: "/frame.js", args: {}, pack: {}, libs: request: function(event, option) { event = event || {} event._msg = event._msg || can.misc.Message(event, can) + function set(key, value) { + if (event._msg[key] == undefined) { + event._msg.Option(key, value) + } + } can.core.List(arguments, function(option, index) { if (index == 0) { return } can.base.isFunc(option.Option)? can.core.List(option.Option(), function(key) { - event._msg.Option(key, option.Option(key)) - }): can.core.Item(can.base.isFunc(option)? option(): option, event._msg.Option) + set(key, option.Option(key)) + }): can.core.Item(can.base.isFunc(option)? option(): option, set) }); return event._msg },