From feaf44d859bdb19ab7997353a352aac5233d2804 Mon Sep 17 00:00:00 2001 From: shylinux Date: Fri, 12 Jun 2020 10:53:31 +0800 Subject: [PATCH] opt some --- index.css | 9 +++++++++ lib/page.js | 9 +++++++++ plugin/input/date.js | 9 +++++++-- plugin/input/key.js | 22 ++++++++++++++++++---- plugin/local/team/plan.js | 12 ++++++++++-- 5 files changed, 53 insertions(+), 8 deletions(-) diff --git a/index.css b/index.css index 8a43ed2b..5962b412 100644 --- a/index.css +++ b/index.css @@ -231,3 +231,12 @@ fieldset.input { position:absolute; left:0; top:0; } +fieldset.input { + z-index:99; +} +fieldset.input.date { + z-index:101; +} +fieldset.input.key { + z-index:101; +} diff --git a/lib/page.js b/lib/page.js index fb8c8cb1..d69812a3 100644 --- a/lib/page.js +++ b/lib/page.js @@ -587,5 +587,14 @@ var page = Volcanos("page", {help: "网页模块", break } }, + + offset: function(target) { + var offsetTop = 0, offsetLeft = 0 + for (var p = target; p != null; p = p.parentNode) { + offsetTop += (p.offsetTop||0) + offsetLeft += (p.offsetLeft||0) + } + return {Top: offsetTop, Left: offsetLeft} + }, }) diff --git a/plugin/input/date.js b/plugin/input/date.js index b29a54ce..5d726948 100644 --- a/plugin/input/date.js +++ b/plugin/input/date.js @@ -1,4 +1,7 @@ -Volcanos("onfigure", {help: "控件详情", list: [], +Volcanos("onfigure", {help: "控件详情", list: [], _merge: function(can, sub) { can.core.Item(sub, function(key, value) { + if (sub.hasOwnProperty(key)) { can.onfigure[key] = value } + }); return true }, + date: {onclick: function(event, can, item, target) { can._figure && can.page.Remove(can, can._figure.fieldset) can._figure = can.onappend.field(can, can._target, "input date", {}) @@ -11,7 +14,9 @@ Volcanos("onfigure", {help: "控件详情", list: [], // 添加插件 var figure = can._figure figure.table = can.page.Append(can, figure.output, [{type: "table"}]).first - can.page.Modify(can, figure.fieldset, {style: {top: target.offsetTop+20, left: target.offsetLeft}}) + // can.page.Modify(can, figure.fieldset, {style: {top: target.offsetTop+20, left: target.offsetLeft}}) + var offset = can.page.offset(can._target) + can.page.Modify(can, figure.fieldset, {style: {top: event.clientY-offset.Top+60, left: event.clientX-offset.Left+60}}) can.page.Remove(can, figure.legend) // 添加控件 diff --git a/plugin/input/key.js b/plugin/input/key.js index 6aaf6de0..a211249b 100644 --- a/plugin/input/key.js +++ b/plugin/input/key.js @@ -1,7 +1,21 @@ -Volcanos("onfigure", {help: "控件详情", list: [], - key: {click: function(event, can, value, cmd, target, figure) { - function run() {figure.output.innerHTML = "" - can.Run(event, ["action", "input", can.item.name, target.value], function(msg) { +Volcanos("onfigure", {help: "控件详情", list: [], _merge: function(can, sub) { can.core.Item(sub, function(key, value) { + if (sub.hasOwnProperty(key)) { can.onfigure[key] = value } + }); return true }, + + key: {onclick: function(event, can, item, target) { + can._figure && can.page.Remove(can, can._figure.fieldset) + can._figure = can.onappend.field(can, can._target, "input key", {}) + + var figure = can._figure, offset = can.page.offset(can._target) + can.page.Modify(can, figure.fieldset, {style: {top: event.clientY-offset.Top+60, left: event.clientX-offset.Left+60}}) + can.page.Remove(can, figure.legend), can.page.Append(can, figure.action, [ + {button: ["关闭", function(event) { + can._figure && can.page.Remove(can, can._figure.fieldset) + }]}, + ]) + + function run() { var msg = can.request(event); msg.Option(item) + can.run(event, ["action", "input", item.name, target.value], function(msg) { can.page.AppendTable(can, figure.output, msg, msg.append, function(event, value, key, index, tr, td) { target.value = value; msg.Option("_refresh") && run() }) diff --git a/plugin/local/team/plan.js b/plugin/local/team/plan.js index 003a55f6..39b94614 100644 --- a/plugin/local/team/plan.js +++ b/plugin/local/team/plan.js @@ -217,7 +217,10 @@ Volcanos("onaction", {help: "组件交互", list: ["统计", "添加", "详情", "", "导出", "导入", ], insertTask: function(event, can, now) { now = now || new Date() - can.require(["/plugin/input/date"]); function date(event) { + can.require([ + "/plugin/input/key", + "/plugin/input/date", + ]); function date(event) { can.onfigure.date.onclick(event, can, {}, event.target) } @@ -232,7 +235,12 @@ Volcanos("onaction", {help: "组件交互", list: ["统计", "添加", "详情", }]}, - "name", "text", + {name: "name", type: "input", onclick: function(event) { + can.onfigure.key.onclick(event, can, {name: "name", zone: ui.zone.value, type: ui.type.value}, event.target) + }, autocomplete: "off"}, + {name: "text", type: "input", onclick: function(event) { + can.onfigure.key.onclick(event, can, {name: "text", zone: ui.zone.value, type: ui.type.value}, event.target) + }, autocomplete: "off"}, {name: "begin_time", type: "input", value: can.base.Time(can.base.TimeAdd(now, now.getHours()/24)), onclick: date}, {name: "end_time", type: "input", value: can.base.Time(can.base.TimeAdd(now, (now.getHours()+1)/24)), onclick: date}, ], function(event, button, data, list) {