291 lines
9.0 KiB
JavaScript
291 lines
9.0 KiB
JavaScript
// import config from '../config'
|
|
import api from '../utils/apiQuery'
|
|
const app = getApp()
|
|
|
|
/**
|
|
* 获取用户信息
|
|
*/
|
|
function getAjaxUserInfo(){
|
|
return new Promise(function (resolve, reject) {
|
|
api.getUserInfo().then(res=>{
|
|
resolve(res)
|
|
})
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 判断用户是否授权用户信息
|
|
*/
|
|
function isAuthUserInfo() {
|
|
return new Promise(function (resolve, reject) {
|
|
api.getUserInfo().then(res=>{
|
|
resolve(Boolean(res && res.headimg))
|
|
})
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 判断用户是否绑定手机
|
|
*/
|
|
function isBindMobile() {
|
|
return new Promise(function (resolve, reject) {
|
|
api.getUserInfo().then(res=>{
|
|
resolve(res && res.mobile)
|
|
})
|
|
})
|
|
}
|
|
|
|
|
|
/**
|
|
* 是否开卡
|
|
*/
|
|
function isOpenCard() {
|
|
return new Promise(function (resolve, reject) {
|
|
api.getUserInfo().then(res=>{
|
|
resolve(res && res.card_id)
|
|
})
|
|
})
|
|
}
|
|
|
|
const getUserLocation = function () {
|
|
return new Promise(function (resolve, reject) {
|
|
wx.getLocation({
|
|
type: 'gcj02', //wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
|
|
success(res) {
|
|
app.setStorage('u_lat', res.latitude)
|
|
app.setStorage('u_lng', res.longitude)
|
|
resolve({
|
|
lat: res.latitude,
|
|
lng: res.longitude,
|
|
from_storage: false,
|
|
});
|
|
},
|
|
fail(res) {
|
|
app.printErrorClient('userLocationFail', ['错误信息:' + JSON.stringify(res)])
|
|
console.log(res)
|
|
_ModelForGetLocationModel(resolve, reject, res.errMsg);
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
|
|
function _ModelForGetLocationModel(resolve, reject, errMsg) {
|
|
if (errMsg && errMsg.indexOf('auth') > -1) {
|
|
wx.showModal({
|
|
title: '',
|
|
content: '检测到你未打开地理位置的权限,是否前往开启',
|
|
confirmText: '前往开启',
|
|
showCancel: false,
|
|
success(res) {
|
|
if (res.confirm) {
|
|
//成功的时候只执行一次(通过手动的时候就没执行了)
|
|
wx.openSetting({
|
|
success(res) {
|
|
wx.authorize({
|
|
scope: 'scope.userLocation',
|
|
success() {
|
|
// resolve("toggle");
|
|
wx.getLocation({
|
|
type: 'wgs84',
|
|
success(res) {
|
|
app.setStorage('u_lat', res.latitude)
|
|
app.setStorage('u_lng', res.longitude)
|
|
resolve({
|
|
lat: res.latitude,
|
|
lng: res.longitude,
|
|
from_storage: false,
|
|
});
|
|
}
|
|
})
|
|
},
|
|
fail() {
|
|
app.printErrorClient('userLocationFail', ['错误信息:打开打开地理位置的权限,未设置'])
|
|
// _ModelForGetLocationModel(resolve, reject);
|
|
getUserLocation()
|
|
reject()
|
|
}
|
|
})
|
|
}
|
|
})
|
|
} else if (res.cancel) {
|
|
app.printErrorClient('userLocationFail', ['错误信息:用户点击取消'])
|
|
reject()
|
|
}
|
|
}
|
|
})
|
|
} else if (errMsg && (!wx.getSystemInfoSync().locationEnabled || errMsg.indexOf('system') > -1 || errMsg.indexOf('fail authorize no response') > -1)) {
|
|
wx.showModal({
|
|
title: '获取定位失败',
|
|
content: '请在系统设置中\n打开定位服务后刷新页面',
|
|
confirmText: '确定',
|
|
showCancel: false,
|
|
complete: res => {
|
|
reject()
|
|
// _ModelForGetLocationModel(resolve, reject,res.errMsg)
|
|
}
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: '请刷新页面,重新授权地理位置信息',
|
|
// content: '请刷新页面\n重新授权地理位置信息',
|
|
// confirmText: '确定',
|
|
// showCancel: false,
|
|
icon: 'none',
|
|
success: res => {
|
|
reject()
|
|
//_ModelForGetLocationModel(resolve, reject,res.errMsg)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
// const getUserAuthLocation = () => {
|
|
// let that = this
|
|
// return new Promise(function (resolve, reject) {
|
|
// if (app.getStorageByKey('isAgreeAuthLocation')) {
|
|
// wx.startLocationUpdate({
|
|
// success() {
|
|
// wx.onLocationChange(function (res) {
|
|
// app.setStorage('u_lat', res.latitude)
|
|
// app.setStorage('u_lng', res.longitude)
|
|
// resolve({
|
|
// lat: res.latitude,
|
|
// lng: res.longitude,
|
|
// from_storage: false,
|
|
// });
|
|
// wx.stopLocationUpdate()
|
|
// })
|
|
// },
|
|
// fail(){
|
|
// app.printErrorClient('userLocationFail', ['错误信息:用户拒绝授权LocationUpdate'])
|
|
// getCityLocation().then(res => {
|
|
// app.setStorage('isAgreeAuthLocation', 1)
|
|
// resolve({
|
|
// lat: res.lat,
|
|
// lng: res.lng,
|
|
// from_storage: false,
|
|
// })
|
|
// })
|
|
// }
|
|
// })
|
|
// } else if(app.getStorageByKey('isRefuseAuthLocation')) {
|
|
// wx.showModal({
|
|
// title: '',
|
|
// content: '开启地理位置权限,获得更精准的体验哦~',
|
|
// showCancel: true,
|
|
// cancelText: '我再想想',
|
|
// confirmText: '前往开启',
|
|
// success(res) {
|
|
// if (res.confirm) {
|
|
// //成功的时候只执行一次(通过手动的时候就没执行了)
|
|
// wx.openSetting({
|
|
// success(res) {
|
|
// wx.authorize({
|
|
// scope: 'scope.userLocation',
|
|
// success() {
|
|
// // resolve("toggle");
|
|
// wx.getLocation({
|
|
// type: 'gcj02',
|
|
// success(res) {
|
|
// app.setStorage('u_lat', res.latitude)
|
|
// app.setStorage('u_lng', res.longitude)
|
|
// app.setStorage('isAgreeAuthLocation', 1)
|
|
// resolve({
|
|
// lat: res.latitude,
|
|
// lng: res.longitude,
|
|
// from_storage: false,
|
|
// });
|
|
// }
|
|
// })
|
|
|
|
// },
|
|
// fail() {
|
|
// app.printErrorClient('userLocationFail', ['错误信息:打开打开地理位置的权限,未设置'])
|
|
// // _ModelForGetLocationModel(resolve, reject);
|
|
// getIpCtiy().then(res => {
|
|
// getCityLocation(res.cname).then(res => {
|
|
// app.setStorage('isRefuseAuthLocation', 1)
|
|
// resolve({
|
|
// lat: res.lat,
|
|
// lng: res.lng,
|
|
// from_storage: false,
|
|
// })
|
|
// })
|
|
// })
|
|
// }
|
|
// })
|
|
// }
|
|
// })
|
|
// } else if (res.cancel) {
|
|
// app.printErrorClient('userLocationFail', ['错误信息:用户点击取消'])
|
|
// getIpCtiy().then(res => {
|
|
// getCityLocation(res.cname).then(res => {
|
|
// app.setStorage('isRefuseAuthLocation', 1)
|
|
// resolve({
|
|
// lat: res.lat,
|
|
// lng: res.lng,
|
|
// from_storage: false,
|
|
// })
|
|
// })
|
|
// }).catch(res=>{
|
|
// console.log(1)
|
|
// })
|
|
// }
|
|
// }
|
|
// })
|
|
// }else{
|
|
// wx.getLocation({
|
|
// type: 'gcj02', //wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
|
|
// success(res) {
|
|
// app.setStorage('u_lat', res.latitude)
|
|
// app.setStorage('u_lng', res.longitude)
|
|
// app.setStorage('isAgreeAuthLocation', 1)
|
|
// resolve({
|
|
// lat: res.latitude,
|
|
// lng: res.longitude,
|
|
// from_storage: false,
|
|
// });
|
|
// },
|
|
// fail(res) {
|
|
// console.log(res)
|
|
// app.printErrorClient('userLocationFail', ['错误信息:' + JSON.stringify(res)])
|
|
// getIpCtiy().then(res => {
|
|
// getCityLocation(res.cname).then(res => {
|
|
// app.setStorage('isRefuseAuthLocation', 1)
|
|
// resolve({
|
|
// lat: res.lat,
|
|
// lng: res.lng,
|
|
// from_storage: false,
|
|
// })
|
|
// })
|
|
// }).catch(res=>{
|
|
// getCityLocation().then(res => {
|
|
// app.setStorage('isRefuseAuthLocation', 1)
|
|
// resolve({
|
|
// lat: res.lat,
|
|
// lng: res.lng,
|
|
// from_storage: false,
|
|
// })
|
|
// }).catch(res=>{
|
|
// console.log(2)
|
|
// })
|
|
// })
|
|
// // _ModelForGetLocationModel(resolve, reject,res.errMsg);
|
|
|
|
// }
|
|
// })
|
|
// }
|
|
|
|
// })
|
|
// }
|
|
|
|
module.exports = {
|
|
getAjaxUserInfo,
|
|
isAuthUserInfo,
|
|
isBindMobile,
|
|
isOpenCard,
|
|
getUserLocation,
|
|
// getUserAuthLocation
|
|
} |