1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

opt love.maps

This commit is contained in:
shaoying 2019-09-29 21:30:40 +08:00
parent f4e9c04228
commit 68d3812848
11 changed files with 141 additions and 116 deletions

View File

@ -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,
}

View File

@ -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]))

View File

@ -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)

View File

@ -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;

View File

@ -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('<span class="'+arguments[i][1]+'">', arguments[i][0], "</span>")
}
}
list.push("<br/>")
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+"<br/>"+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)
})
},
}}}

View File

@ -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

56
src/plugin/love/maps.js Normal file
View File

@ -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+"<br/>"+line.where, {width: 200, height: 100, title: line.what})
map.openInfoWindow(info, map.getCenter())
output.style.opacity = 0
kit.Opacity(output)
}, 3000)
})
},
}}}

View File

@ -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: "<img src=\""+ctx.Share({"group": "index", "name": "login", cmds: ["share", url]})+"\">", height: 320, width: 320, title: url, button: ["确定"], cb: function(which) {
page.ontoast({text: "<img src=\""+ctx.Share({"group": "index", "names": "login", cmds: ["share", url]})+"\">", height: 320, width: 320, title: url, button: ["确定"], cb: function(which) {
page.ontoast()
}})
})

View File

@ -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 {
}

View File

@ -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
}

View File

@ -414,6 +414,7 @@ kit = toolkit = {__proto__: document,
if (row[key].startsWith("http")) {
td.innerHTML = "<a href='"+row[key]+"' target='_blank'>"+row[key]+"</a>"
}
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('<span class="'+arguments[i][1]+'">', arguments[i][0], "</span>")
}
}
list.push("<br/>")
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"
},