From 8695a556f96cef5f9bdba0c7b5e0a7a8487418b8 Mon Sep 17 00:00:00 2001 From: shylinux Date: Mon, 24 Feb 2020 05:39:56 +0800 Subject: [PATCH] opt table.js --- frame.js | 5 ++--- lib/page.js | 2 +- pane/Action.js | 4 ++-- pane/River.js | 14 ++++++------ pane/Storm.js | 14 ++++++------ plugin/input.js | 11 +--------- plugin/table.js | 57 +++++++++++++------------------------------------ proto.js | 2 +- 8 files changed, 36 insertions(+), 73 deletions(-) diff --git a/frame.js b/frame.js index d164d9c6..a7425cdc 100644 --- a/frame.js +++ b/frame.js @@ -13,7 +13,7 @@ var can = Volcanos("chat", { can.core.Item(page._panes, function(index, item) { if (key == "favor") {var msg = value; var cmds = msg.detail, cmd = cmds[0]; - if (cmd == item._name || cmd == item.name()) {cmd = cmds[1], cmds = cmds.slice(1)} + if (cmd == item._name || cmd == item.Name()) {cmd = cmds[1], cmds = cmds.slice(1)} var cb = item.onchoice[cmd]; if (typeof cb == "function") { @@ -224,8 +224,7 @@ var can = Volcanos("chat", { for (var i = args.length-1; i >= 0; i--) {if (args[i] == "") {args = args.slice(0, i)} else {break}} show && plugin.Timer(1000, function() {show && plugin.user.toast(can.base.Format(args||["running..."]), meta.name, -1)}); run(event, args, function(msg) {if (silent) {return typeof cb == "function" && cb(msg)} - plugin.msg = msg - plugin.Show(feature.display || "table", msg, cb) + plugin.msg = msg, plugin.Show(feature.display || "table", msg, cb) show = false, plugin.user.toast(); }) }, diff --git a/lib/page.js b/lib/page.js index a57f4a15..4429828b 100644 --- a/lib/page.js +++ b/lib/page.js @@ -201,7 +201,7 @@ Volcanos("page", {help: "网页模块", return field.Meta = item, field; }), AppendTable: shy("添加表格", function(can, target, msg, list, cb, cbs) { - if (!msg.append || msg.append.length == 0) {return {}} + if (!msg.append || msg.append.length == 0) {return} var table = can.page.Append(can, target, "table"); var tr = can.page.Append(can, table, "tr"); diff --git a/pane/Action.js b/pane/Action.js index be654fe8..97b16e3e 100644 --- a/pane/Action.js +++ b/pane/Action.js @@ -41,7 +41,7 @@ Volcanos("onimport", {help: "导入数据", list: [], }, favor: function(event, can, msg, cmd, field) {if (msg._hand) {return} var cmds = msg.detail, key = cmds[0]; - if (key == can.name()) {key = cmds[1], cmds = cmds.slice(1)} + if (key == can.Name()) {key = cmds[1], cmds = cmds.slice(1)} // 下发数据 can.core.Item(can._local, function(river, list) { @@ -190,7 +190,7 @@ Volcanos("onchoice", {help: "组件菜单", list: ["共享", "保存", "刷新"] var msg = can.Event(event); msg.Option("name", meta.name) msg.Option("text", meta.key) - cmd == "提交" && can.Export(event, can.name(), "share") + cmd == "提交" && can.Export(event, can.Name(), "share") return true }) }, diff --git a/pane/River.js b/pane/River.js index ed6ef258..e49eea33 100644 --- a/pane/River.js +++ b/pane/River.js @@ -1,7 +1,7 @@ Volcanos("onimport", {help: "导入数据", list: [], init: function(event, can, msg, cmd, field) {can.output.innerHTML = ""; - can.page.AppendItem(can, can.output, msg.Table(), can.user.Search(can, can.name()), function(event, line, item) { - can.Export(event, line.key, can.name()) + can.page.AppendItem(can, can.output, msg.Table(), can.user.Search(can, can.Name()), function(event, line, item) { + can.Export(event, line.key, can.Name()) }) }, river: function(event, can, value, cmd, field) {if (value == "update") { @@ -11,7 +11,7 @@ Volcanos("onimport", {help: "导入数据", list: [], }}, favor: function(event, can, msg, cmd, field) {if (msg._hand) {return} var cmds = msg.detail, key = cmds[0]; - if (key == can.name()) {key = cmds[1], cmds = cmds.slice(1)} + if (key == can.Name()) {key = cmds[1], cmds = cmds.slice(1)} can.page.Select(can, field, "div.item>span", function(item) { if (item.innerText == key) { @@ -26,7 +26,7 @@ Volcanos("onaction", {help: "组件交互", list: ["创建", "刷新"], can.Export(event, "create", "ocean") }, "刷新": function(event, can, meta, cmd, field) { - can.Import(event, "update", can.name()) + can.Import(event, "update", can.Name()) }, }) Volcanos("onchoice", {help: "组件菜单", list: ["创建", "刷新", "宽度"], @@ -60,18 +60,18 @@ Volcanos("ondetail", {help: "组件详情", list: ["共享", "重命名", "删 var msg = can.Event(event); msg.Option("name", line.name) msg.Option("text", line.key) - can.Export(event, can.name(), "share") + can.Export(event, can.Name(), "share") }, "重命名": function(event, can, line, value, cmd, item) { can.user.prompt("输入新名:", function(name) { can.run(event, [value, "rename", name], function(msg) { - can.Import(event, "update", can.name()) + can.Import(event, "update", can.Name()) }) }, line.name) }, "删除": function(event, can, line, value, cmd, item) { can.run(event, [value, "remove"], function(msg) { - can.Import(event, "update", can.name()) + can.Import(event, "update", can.Name()) }) }, }) diff --git a/pane/Storm.js b/pane/Storm.js index cfe48d4f..44257535 100644 --- a/pane/Storm.js +++ b/pane/Storm.js @@ -1,7 +1,7 @@ Volcanos("onimport", {help: "导入数据", list: [], init: function(event, can, msg, cmd, field) {can.output.innerHTML = ""; - can.page.AppendItem(can, can.output, msg.Table(), can.user.Search(can, can.name()), function(event, line, item) { - can.Export(event, line.key, can.name()) + can.page.AppendItem(can, can.output, msg.Table(), can.user.Search(can, can.Name()), function(event, line, item) { + can.Export(event, line.key, can.Name()) }) }, river: function(event, can, value, cmd, field) {if (value == "update") {return} @@ -15,7 +15,7 @@ Volcanos("onimport", {help: "导入数据", list: [], can.onimport.init(event, can, msg, cmd, field) }) } else { - can.Conf(can.name(), value) + can.Conf(can.Name(), value) } }, favor: function(event, can, msg, cmd, field) {if (msg._hand) {return} @@ -35,7 +35,7 @@ Volcanos("onaction", {help: "组件交互", list: ["创建", "刷新"], can.Export(event, "create", "steam") }, "刷新": function(event, can, meta, cmd, field) { - can.Import(event, "update", can.name()) + can.Import(event, "update", can.Name()) }, }) Volcanos("onchoice", {help: "组件菜单", list: ["创建", "刷新", "宽度"], @@ -69,18 +69,18 @@ Volcanos("ondetail", {help: "组件详情", list: ["共享", "重命名", "删 var msg = can.Event(event); msg.Option("name", line.name) msg.Option("text", line.key) - can.Export(event, can.name(), "share") + can.Export(event, can.Name(), "share") }, "重命名": function(event, can, line, value, cmd, item) { can.user.prompt("输入新名:", function(name) { can.run(event, [can.Conf("river"), value, "rename", name], function(msg) { - can.Import(event, "update", can.name()) + can.Import(event, "update", can.Name()) }) }, line.name) }, "删除": function(event, can, line, value, cmd, item) { can.run(event, [can.Conf("river"), value, "remove"], function(msg) { - can.Import(event, "update", can.name()) + can.Import(event, "update", can.Name()) }) }, }) diff --git a/plugin/input.js b/plugin/input.js index 5b9aa794..36575a41 100644 --- a/plugin/input.js +++ b/plugin/input.js @@ -12,11 +12,7 @@ Volcanos("onimport", {help: "导入数据", list: [], item.className || can.page.ClassList.add(can, item, "args"); break case "textarea": - var half = parseFloat(item.half||"1")||1; - input.type = "textarea", item.style = { - // width: parseInt(((500-35)/half))+"px", - // height: (item.height||50)+"px", - } + input.type = "textarea" // no break case "password": // no break @@ -27,11 +23,6 @@ Volcanos("onimport", {help: "导入数据", list: [], break } - // can.page.ClassList.add(can, item, item.view); - // can.core.List((item.clist||"").split(" "), function(value) { - // can.page.ClassList.add(can, item, value); - // }) - // var target = can.Dream(option, "input", input)[input.name]; !target.placeholder && (target.placeholder = item.name || ""); item.type != "button" && !target.title && (target.title = item.placeholder || item.name || ""); diff --git a/plugin/table.js b/plugin/table.js index 13e37229..1e29a095 100644 --- a/plugin/table.js +++ b/plugin/table.js @@ -1,52 +1,25 @@ Volcanos("onimport", {help: "导入数据", list: [], init: function(can, msg, cb, output, action, option) {output.innerHTML = ""; - var table = can.page.AppendTable(can, output, msg, msg.append); - table.onclick = function(event) {switch (event.target.tagName) { - case "TD": - can.onimport.which(event, table, msg.append, function(index, key) { - can.ondetail["复制"](event, can, msg, event.target.innerHTML, index, key, event.target); - can.Export(event, event.target.innerHTML.trim(), key, index) - }) - break - case "TH": - break - case "TR": - case "TABLE": - }} - table.oncontextmenu = function(event) {var target = event.target; - switch (event.target.tagName) { - case "TD": - can.onimport.which(event, table, msg.append, function(index, key) { - can.user.carte(event, shy("", can.ondetail, can.feature.detail || can.ondetail.list, function(event, cmd, meta) {var cb = meta[cmd]; - var sub = can.Event(event); - msg.append.forEach(function(key) {sub.Option(key, msg[key][index].trim())}) + var table = can.page.AppendTable(can, output, msg, msg.append, function(event, value, key, index, tr, td) { + can.ondetail["复制"](event, can, msg, value, index, key, td); + can.Export(event, value.trim(), key, index) + }, function(event, value, key, index, tr, td) { + can.user.carte(event, shy("上下文菜单", can.ondetail, can.feature.detail || can.ondetail.list, function(event, cmd, meta) {var cb = meta[cmd]; + var sub = can.Event(event); + msg.append.forEach(function(key) {sub.Option(key, msg[key][index].trim())}) - typeof cb == "function"? cb(event, can, msg, index, key, cmd, target): - can.run(event, ["action", typeof cb == "string"? cb: cmd, key, target.innerHTML.trim(), msg.Ids(index)], function(msg) { - can.user.toast(msg.Result()) - // can.onimport.init(can, msg, cb, output, option) - }, true) - })) - }) - event.stopPropagation() - event.preventDefault() - break - case "TH": - case "TR": - case "TABLE": - } - } + typeof cb == "function"? cb(event, can, msg, index, key, cmd, td): + can.run(event, ["action", typeof cb == "string"? cb: cmd, key, value.trim(), msg.Ids(index)], function(msg) { + can.user.toast(msg.Result()) + }, true) + })) + event.stopPropagation() + event.preventDefault() + }); msg.result && can.page.Append(can, output, [{view: ["code", "div", can.page.Display(msg.Result())]}]).code; return typeof cb == "function" && cb(msg); }, - which: function(event, table, list, cb) {if (event.target == table) {return cb(-1, "")} - can.page.Select(can, table, "tr", function(tr, index) {if (event.target == tr) {return cb(tr.dataset.index, "")} - can.page.Select(can, tr, "th,td", function(td, order) { - if (event.target == td) {return cb(tr.dataset.index, list[order])} - }) - }) - }, }) Volcanos("onaction", {help: "组件交互", list: []}) Volcanos("onchoice", {help: "组件菜单", list: ["返回", "清空", "复制", "下载"], diff --git a/proto.js b/proto.js index dead7f14..19a7edba 100644 --- a/proto.js +++ b/proto.js @@ -75,7 +75,7 @@ function Volcanos(name, can, libs, cb, msg) { // 封装模块 can._load(libs[0]), can.require(libs.slice(1), cb); }) }, - name: function() {return can._name.toLowerCase()}, + Name: function() {return can._name.toLowerCase()}, ID: shy("生成器", function() {return id++}), Log: shy("日志器", function() {console.log(arguments)}),