Commit e38ddb81b3e43db060086640c7c3341014a78884

Authored by vking
1 parent 4b64f30a

new 2.0

// components/userinfo/getpos.js
Component({
/**
* 组件的属性列表
*/
properties: {
},
/**
* 组件的初始数据
*/
data: {},
attached(){
},
/**
* 组件的方法列表
*/
methods: {
getPosDo(timeout=3000){
return new Promise(function(success,fail){
let timer1=setTimeout(()=>{
fail('timeout')
},timeout)
wx.getLocation({
type: 'gcj02',
success: (res) => {
success(res)
},
fail: (res) => {
fail(res)
},
complete:()=>{
if(timer1) clearTimeout(timer1)
}
});
})
},
getPos(fouce=false){
wx.getSetting({
success: res => {
console.log('getPos.scope.userLocation',res.authSetting)
let timeout=3000;
if(typeof res.authSetting['scope.userLocation']=='undefined'){
timeout=86400;
}
if(res.authSetting['scope.userLocation']===false){
if(fouce){
this.selectComponent('#confirm').options({
header: '定位失败',
body: '请开启定位,为您查询附近餐厅。'
}).show();
}else{
this.triggerEvent("pos",{
latitude: '',
longitude: '',
});
}
}else{//
this.getPosDo(timeout).then(res=>{
console.log('getPos.then',res)
this.triggerEvent("pos",{
latitude: res.latitude,
longitude: res.longitude,
});
}).catch(res=>{
console.log('getPos.catch',res)
this.triggerEvent("pos",{
latitude: '',
longitude: '',
});
})
}
}
})
},
confirmEvent(e){
wx.openSetting({
success:res=>{
console.log('getPos.openSetting',res)
this.getPos();
}
})
},
}
})
... ...
{
"component": true,
"usingComponents": {
"confirm":"/components/2.0/dialog/confirm"
}
}
\ No newline at end of file
... ...
<!--components/userinfo/getpos.wxml-->
<confirm id="confirm"
confirmText="去开启"
confirmColor="#FFFFFF"
cancelText="再想想"
cancelColor="#42A5FF"
bindevent="confirmEvent"></confirm>
... ...
/* components/userinfo/getpos.wxss */
\ No newline at end of file
... ...
... ... @@ -309,8 +309,6 @@ Page({
let ms=(e.detail.scrollTop%162)>100?1:0;
idx+=ms;
}
//console.log('scrollEvent',e,e.detail.scrollTop,idx)
//console.log('scrollEvent',this.sellers[idx].sellername)
this.debounce(()=>{
this.scrollEventActive(idx)
},300)
... ...
... ... @@ -3,7 +3,7 @@
"navigationBarTextStyle": "black",
"navigationBarTitleText":"周到安排",
"usingComponents": {
"getpos":"/components/userinfo/getpos",
"getpos":"/components/2.0/userinfo/getpos",
"a2l":"/components/tips/add-to-lite",
"filter-group":"/components/2.0/filter/filter-group",
"seller-card":"/components/2.0/seller/card",
... ...
<!--pages/reservr/index.wxml-->
<map id="map" scale="{{map.scale}}"
longitude="{{map.longitude}}" latitude="{{map.latitude}}"
longitude="{{map.longitude||118.170300}}" latitude="{{map.latitude||39.65273}}"
markers="{{markers}}" polygons="{{polygons}}"
bindmarkertap="markertap"
bindcallouttap="markertap"
... ...