From a58ece0f725a57ec3b24649b6882fefff40dc332 Mon Sep 17 00:00:00 2001 From: shaoying Date: Sun, 29 Sep 2019 09:49:07 +0800 Subject: [PATCH] add love.maps --- src/contexts/cli/version.go | 2 +- src/contexts/web/web.go | 5 +++- src/plugin/love/index.js | 50 ++++++++++++++++++++++++++++++++++++- src/plugin/love/index.shy | 20 ++++++++++++++- usr/librarys/chat.js | 2 +- usr/librarys/example.js | 7 +----- usr/template/common.tmpl | 1 + 7 files changed, 76 insertions(+), 11 deletions(-) diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index 7562d509..cf85dbaa 100644 --- a/src/contexts/cli/version.go +++ b/src/contexts/cli/version.go @@ -4,5 +4,5 @@ var version = struct { host string self int }{ - "2019-09-27 10:34:50", "centos", 607, + "2019-09-28 15:18:05", "mac", 611, } diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index d58b0d1f..ead219fe 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -849,9 +849,12 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心", // 响应类型 accept_json := strings.HasPrefix(m.Option("accept"), "application/json") w := m.Optionv("response").(http.ResponseWriter) - if accept_json { + if !accept_json { w.Header().Set("Content-Type", "text/html") + } else { + w.Header().Set("Content-Type", "application/json") } + 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.js b/src/plugin/love/index.js index 4885559d..b1ccb281 100644 --- a/src/plugin/love/index.js +++ b/src/plugin/love/index.js @@ -1,4 +1,16 @@ -{init: function(run, field, option, output) {return { +{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) { @@ -56,4 +68,40 @@ }) }) }, + 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 45055648..4aa3f1ab 100644 --- a/src/plugin/love/index.shy +++ b/src/plugin/love/index.shy @@ -24,7 +24,7 @@ kit date "日历" "index.js" "index.css" protected "cli.date" _ nature _ \ fun days "每一天" "index.js" "index.css" protected \ text "days" name table imports plugin_table \ - text "" name when init date\ + text "" name when init date \ text "" name what view long \ button "记下了" \ button "记下了" cb Quick @@ -36,6 +36,24 @@ fun days "每一天" "index.js" "index.css" protected \ end end +fun maps "每一面" "index.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 \ + button "记录" cb Record \ + button "展示" cb Plays + + if $2 == "" || $3 == "" + copy skip ssh.data show _ + else + copy ssh.data insert _ when _ what _ city _ place _ longitude _ latitude _ scale _ + end +end + fun delay "以后告诉你" protected \ text "delay" name table imports plugin_table \ text "" name when init date\ diff --git a/usr/librarys/chat.js b/usr/librarys/chat.js index 28c1be79..36b7ec85 100644 --- a/usr/librarys/chat.js +++ b/usr/librarys/chat.js @@ -704,6 +704,6 @@ var page = Page({check: true, page.onaction[item] && page.onaction[item](event, item, value, page) }) page.river.Pane.Show() - page.WSS() + // page.WSS() }, }) diff --git a/usr/librarys/example.js b/usr/librarys/example.js index d5fdd249..947e8431 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -734,12 +734,7 @@ function Plugin(page, pane, field, runs) { Append: function(item, name, value) { kit.Item(plugin.onaction, function(k, cb) { item[k] == undefined && (item[k] = typeof cb == "function"? function(event) { - try { - cb(event, action, item.type, input.name, item) - } catch (e) { - console.trace() - kit.Log("err", e) - } + cb(event, action, item.type, input.name, item) }: cb) }); item.value = plugin.onformat(item.init)(item.value) diff --git a/usr/template/common.tmpl b/usr/template/common.tmpl index 8b793391..8dbf5654 100644 --- a/usr/template/common.tmpl +++ b/usr/template/common.tmpl @@ -30,6 +30,7 @@ {{range $index, $lib := option . "scripts"}} {{end}} + {{end}}