From 68d3812848a1e73398707c1148c1b215e0fb32f8 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 29 Sep 2019 21:30:40 +0800 Subject: [PATCH] opt love.maps --- src/contexts/cli/version.go | 2 +- src/contexts/ssh/ssh.go | 1 + src/contexts/web/web.go | 2 +- src/plugin/love/index.css | 4 ++ src/plugin/love/index.js | 114 ++++++++---------------------------- src/plugin/love/index.shy | 18 +++--- src/plugin/love/maps.js | 56 ++++++++++++++++++ usr/librarys/chat.js | 4 +- usr/librarys/example.css | 18 +++--- usr/librarys/example.js | 5 +- usr/librarys/toolkit.js | 33 +++++++++-- 11 files changed, 141 insertions(+), 116 deletions(-) create mode 100644 src/plugin/love/maps.js diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index 608a15d4..4ba4fbe0 100644 --- a/src/contexts/cli/version.go +++ b/src/contexts/cli/version.go @@ -7,5 +7,5 @@ var version = struct { self int }{ []string{"2017-11-01 01:02:03", "2019-07-13 18:02:21"}, - `2019-09-29 18:40:19`, `centos`, 617, + `2019-09-29 19:53:06`, `centos`, 619, } diff --git a/src/contexts/ssh/ssh.go b/src/contexts/ssh/ssh.go index 24da68b5..82b3dab6 100644 --- a/src/contexts/ssh/ssh.go +++ b/src/contexts/ssh/ssh.go @@ -433,6 +433,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心", } sort.Strings(keys) + m.Meta["append"] = []string{"id", "when"} m.Confm("flow", []string{m.Option("river"), "data", arg[1], "list"}, func(index int, value map[string]interface{}) { for _, k := range keys { m.Push(k, kit.Format(value[k])) diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index 93a89fc4..a11e58cf 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -855,7 +855,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", } else { w.Header().Set("Content-Type", "application/json") } - w.Header().Set("Access-Control-Allow-Origin", "api.map.baidu.com") + // w.Header().Set("Access-Control-Allow-Origin", "api.map.baidu.com") web, ok := m.Target().Server.(*WEB) m.Assert(ok) diff --git a/src/plugin/love/index.css b/src/plugin/love/index.css index 74ab4a25..e9914bb6 100644 --- a/src/plugin/love/index.css +++ b/src/plugin/love/index.css @@ -2,6 +2,10 @@ fieldset.item.love.date table td.today { border:solid 2px red; } +fieldset.item.love.date table td { + text-align:center; + min-width:40px; +} fieldset.item.love.days div.day { margin:8px; diff --git a/src/plugin/love/index.js b/src/plugin/love/index.js index b1ccb281..4e8fcd44 100644 --- a/src/plugin/love/index.js +++ b/src/plugin/love/index.js @@ -1,107 +1,43 @@ {init: function(run, field, option, output) { -var id return { - initMap: function() {var plugin = field.Plugin - var width = field.parentNode.clientWidth-40 - !id && (id = plugin.id+"map"+plugin.ID()) - kit.AppendChilds(output, [{type: "div", data: {id: id}, style: {width: width+"px", height: width*3/5}}]) - map = new BMap.Map(id) - map.addControl(new BMap.NavigationControl()) - map.addControl(new BMap.ScaleControl()) - map.addControl(new BMap.OverviewMapControl()) - map.addControl(new BMap.MapTypeControl()) - }, show: function(event) { - run(event, ["", "", "cmd", "ssh.data", "show", option.table.value], function(msg) {ctx.Table(msg, function(value) { - kit.Selector(output, ".s"+value[option.when.value].split(" ")[0].split("-").join(""), function(item) { - kit.classList.add(item.parentNode, "select") - item.parentNode.title = value[option.where.value] - }) - })}) + run(event, ["", "", "cmd", "ssh.data", "show", option.table.value], function(msg) { + kit.List(ctx.Table(msg), function(value) { + kit.Selector(output, ".s"+value[option.when.value].split(" ")[0].split("-").join(""), function(item) { + kit.classList.add(item.parentNode, "select") + item.parentNode.title = value[option.where.value] + }) + }, 500) + }) }, show_after: function(msg) { kit.Selector(output, ".s"+ kit.format_date().split(" ")[0].split("-").join(""), function(item) { kit.classList.add(item.parentNode, "today") }) }, - play: function(event) { - kit.AppendChilds(output, [{type: "video", data: {src: option.url.value, autoplay: ""}}]) - }, - Quick: function(event) { - var msg = field.Plugin.msg - var now = new Date() - function show(t, cb, cbs) { - kit.List(ctx.Table(msg).concat([{when: "9999-01-08", what: "最后一次爱你"}]), function(line, index, array) { - var day = new Date(line.when) - var mis = parseInt((day.getTime() - now.getTime()) / 1000 / 3600 / 24) - if (index == array.length-1) { - mis = 999999 - } + Order: function(t, cb, cbs) {var plugin = field.Plugin + var msg = plugin.msg, now = new Date() + kit.List(ctx.Table(msg).concat([{when: "9999-01-08", what: "最后一次爱你"}]), function(line, index, array) { + var day = new Date(line.when) + var mis = parseInt((day.getTime() - now.getTime()) / 1000 / 3600 / 24) + if (index == array.length-1) { + mis = 999999 + } - var list = [] - list.span = function(value, style) { - for (var i = 0; i < arguments.length; i++) { - if (typeof arguments[i] == "string") { - list.push(arguments[i]) - } else { - list.push('', arguments[i][0], "") - } - } - list.push("
") - return list - } + var list = kit.Span() + list.span(["距", "day"], line.when.split(" ")[0]).span([line.what, "what"]) + list.span(mis>0? "还有": "过去", [mis, mis>0? "day1": "day0"], "天") - list.span(["距", "day"], line.when.split(" ")[0]).span([line.what, "what"]) - list.span(mis>0? "还有": "过去", [mis, mis>0? "day1": "day0"], "天") - - var elm = cb(output, [{text: [list.join(""), "div", "day"]}]).last - kit.List([0.2, 0.4, 0.6, 0.8, 1.0], function(value) { - elm.style.opacity = value - }, 150) - }, t, cbs) - } - show(3000, function(output, list) { + kit.Opacity(cb(output, [{text: [list.join(""), "div", "day"]}]).last) + }, t, cbs) + }, + Flash: function(event) {var plugin = field.Plugin + plugin.Order(3000, function(output, list) { return kit.AppendChilds(output, list) }, function() { - show(1000, function(output, list) { + output.innerHTML = "", plugin.Order(1000, function(output, list) { return kit.AppendChild(output, list) }) }) }, - Search: function() {var plugin = field.Plugin - plugin.initMap() - var g = new BMap.Geocoder() - g.getPoint(option.place.value, function(p) { - kit.Log("place", p) - if (!p) {alert("not found"); return} - map.centerAndZoom(p, option.scale.value) - }, option.city.value) - }, - Record: function() {var plugin = field.Plugin - var l = map.getCenter() - run(event, [option.table.value, option.when.value, option.what.value, option.city.value, option.place.value, l.lng, l.lat, map.getZoom()], function(msg) { - console.log("ok") - }) - }, - Plays: function() {var plugin = field.Plugin - plugin.initMap(), run(event, [option.table.value], function(msg) { - kit.List(ctx.Table(msg), function(line) { - output.style.opacity = 0 - var p = new BMap.Point(line.longitude, line.latitude) - map.centerAndZoom(p, line.scale) - - var info = new BMap.InfoWindow(line.when+"
"+line.place, {width: 200, height: 100, title: line.what}) - map.openInfoWindow(info, map.getCenter()) - - var scales = [] - for (var i = 0; i < 10; i++) { - scales.push(i*0.1) - } - kit.List(scales, function(scale) { - output.style.opacity = scale - }, 100) - }, 3000) - }) - }, - }}} diff --git a/src/plugin/love/index.shy b/src/plugin/love/index.shy index 4aa3f1ab..f30d9f7f 100644 --- a/src/plugin/love/index.shy +++ b/src/plugin/love/index.shy @@ -26,8 +26,8 @@ fun days "每一天" "index.js" "index.css" protected \ text "days" name table imports plugin_table \ text "" name when init date \ text "" name what view long \ - button "记下了" \ - button "记下了" cb Quick + button "记录" \ + button "展示" cb Flash if $2 == "" || $3 == "" copy skip ssh.data show _ @@ -36,21 +36,21 @@ fun days "每一天" "index.js" "index.css" protected \ end end -fun maps "每一面" "index.js" "index.css" protected \ +fun maps "每一面" "maps.js" "index.css" protected \ text "maps" name table imports plugin_table \ text "" name when init date \ text "" name what view long \ - text "北京市" name city \ - text "弘源首著" name place \ - text "16" name scale \ - button "搜索" cb Search \ + text "北京市" name city view tiny \ + text "弘源首著" name where view long \ + button "本地" cb Current \ + button "搜索" cb Search action auto \ button "记录" cb Record \ - button "展示" cb Plays + button "展示" cb Flashs if $2 == "" || $3 == "" copy skip ssh.data show _ else - copy ssh.data insert _ when _ what _ city _ place _ longitude _ latitude _ scale _ + copy ssh.data insert _ when _ what _ city _ where _ longitude _ latitude _ scale _ end end diff --git a/src/plugin/love/maps.js b/src/plugin/love/maps.js new file mode 100644 index 00000000..78af75eb --- /dev/null +++ b/src/plugin/love/maps.js @@ -0,0 +1,56 @@ +{init: function(run, field, option, output) { +var id +return { + initMap: function() {var plugin = field.Plugin + var width = field.parentNode.clientWidth-40 + !id && (id = plugin.id+"map"+plugin.ID()) + kit.AppendChilds(output, [{type: "div", data: {id: id}, style: {width: width+"px", height: width*(kit.device.isMobile? 7: 3)/5}}]) + map = new BMap.Map(id) + map.addControl(new BMap.NavigationControl()) + map.addControl(new BMap.ScaleControl()) + map.addControl(new BMap.OverviewMapControl()) + map.addControl(new BMap.MapTypeControl()) + }, + Current: function() { + var geo = new BMap.Geolocation() + geo.getCurrentPosition(function(p) { + option.city.value = p.address.city + option.where.value = kit.Value(kit.Value(p.address.street, "")+kit.Value(p.address.street_number, ""), p.address.city) + map.centerAndZoom(p.point, map.getZoom()) + }) + }, + Search: function() {var plugin = field.Plugin + plugin.initMap() + var g = new BMap.Geocoder() + g.getPoint(option.where.value, function(p) { + kit.Log("where", p) + if (!p) {alert("not found"); return} + map.centerAndZoom(p, 18) + }, option.city.value) + }, + Record: function() {var plugin = field.Plugin + function trunc(value, len) { + len = kit.Value(len, 1000000) + return parseInt(value*len)/parseFloat(len) + } + var l = map.getCenter() + run(event, [option.table.value, option.when.value, option.what.value, option.city.value, option.where.value, trunc(l.lng), trunc(l.lat), map.getZoom()], function(msg) { + plugin.msg = msg, plugin.display("table") + }) + }, + Flashs: function() {var plugin = field.Plugin + plugin.initMap(), run(event, [option.table.value], function(msg) { + kit.List(ctx.Table(msg), function(line) { + var p = new BMap.Point(line.longitude, line.latitude) + map.centerAndZoom(p, line.scale) + + var info = new BMap.InfoWindow(line.when+"
"+line.where, {width: 200, height: 100, title: line.what}) + map.openInfoWindow(info, map.getCenter()) + + output.style.opacity = 0 + kit.Opacity(output) + }, 3000) + }) + }, +}}} + diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index 36b7ec85..6ebbd980 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -292,7 +292,7 @@ var page = Page({check: true, var msg = ctx.Event(event) var plugin = event.Plugin || page.plugin && page.plugin.Plugin || {}, engine = { share: function(args) { - return ctx.Share({"group": option.dataset.group, "name": option.dataset.name, "cmds": [ + return ctx.Share({"group": option.dataset.group, "names": option.dataset.names, "cmds": [ river, line.storm, line.action, args[1]||"", ]}) }, @@ -580,7 +580,7 @@ var page = Page({check: true, "layout": page.action.Pane.Layout(), })], function(msg) { var url = location.origin+location.pathname+"?relay="+msg.result.join("") - page.ontoast({text: "", height: 320, width: 320, title: url, button: ["确定"], cb: function(which) { + page.ontoast({text: "", height: 320, width: 320, title: url, button: ["确定"], cb: function(which) { page.ontoast() }}) }) diff --git a/usr/librarys/example.css b/usr/librarys/example.css index 34050d0a..4e2ddaf1 100644 --- a/usr/librarys/example.css +++ b/usr/librarys/example.css @@ -40,17 +40,20 @@ fieldset>form.option div.clear { fieldset>form.option label { margin-right:3px; } -fieldset>form.option div input.args { - width:80px; -} fieldset>form.option div.cmd input.args { color:white; background-color: black; width:160px; } -fieldset>form.option div.tiny input.args { +fieldset>form.option div.char input.args { width:20px; } +fieldset>form.option div.tiny input.args { + width:40px; +} +fieldset>form.option div input.args { + width:80px; +} fieldset>form.option div.long input.args { width:240px; } @@ -94,11 +97,10 @@ fieldset>div.output div.code span.green { } fieldset>div.output table td { word-break:break-all; - min-width:40px; } -fieldset>div.output table td { - word-break:keep-all; - min-width:40px; +fieldset>div.output table td.when { + text-align:center; + min-width:140px; } fieldset>div.output table.edit { } diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 947e8431..9fc748a9 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -1103,9 +1103,10 @@ function Plugin(page, pane, field, runs) { }, exports: JSON.parse(meta.exports||'["",""]'), }) - plugin.which = plugin.Sync("input") + plugin.which = plugin.Sync("input") + page[field.id] = pane[field.id] = pane[name] = field, field.Plugin = plugin inputs.map(function(item) {plugin.Append(item)}) kit.Log("init", "plugin", name, plugin) - return page[field.id] = pane[field.id] = pane[name] = field, field.Plugin = plugin + return plugin } diff --git a/usr/librarys/toolkit.js b/usr/librarys/toolkit.js index 5781b0c4..aa6c78cd 100644 --- a/usr/librarys/toolkit.js +++ b/usr/librarys/toolkit.js @@ -414,6 +414,7 @@ kit = toolkit = {__proto__: document, if (row[key].startsWith("http")) { td.innerHTML = ""+row[key]+"" } + if (key == "when") {td.className = "when"} if (typeof cb == "function") { td.onclick = function(event) { @@ -598,16 +599,17 @@ kit = toolkit = {__proto__: document, }, // 数据容器迭代 - Selector: function(obj, item, cb) { + Selector: function(obj, item, cb, interval, cbs) { var list = [] - obj.querySelectorAll(item).forEach(function(item, index, array) { + kit.List(obj.querySelectorAll(item), function(item, index, array) { if (typeof cb == "function") { var value = cb(item, index, array) value != undefined && list.push(value) } else { list.push(item) } - }) + }, interval, cbs) + for (var i = list.length-1; i >= 0; i--) { if (list[i] == "") { list.pop() @@ -624,7 +626,7 @@ kit = toolkit = {__proto__: document, typeof cb == "function" && cb(obj[i], i, obj) setTimeout(function() {loop(i+1)}, interval) } - obj.length > 0 && setTimeout(function() {loop(0)}, interval) + obj.length > 0 && setTimeout(function() {loop(0)}, interval/4) return obj } var list = [] @@ -640,7 +642,30 @@ kit = toolkit = {__proto__: document, } return list }, + Span: function(list) { + list = list || [] + list.span = function(value, style) { + for (var i = 0; i < arguments.length; i++) { + if (typeof arguments[i] == "string") { + list.push(arguments[i]) + } else { + list.push('', arguments[i][0], "") + } + } + list.push("
") + return list + } + return list + }, + Opacity: function(obj, list, interval) { + kit.List(kit.Value(list, [0, 0.2, 0.4, 0.6, 1.0]), function(value) { + obj.style.opacity = value + }, kit.Value(interval, 150)) + }, // 数据类型转换 + Value: function(obj, value) { + return obj === undefined || obj === null || obj === "" ? value: obj + }, isSpace: function(c) { return c == " " || c == "Enter" },