Commit 69c06183 by biao

1

parent 794937f6
//app.js
App({
url: 'https://www.koala-online.cn/compass/if/',
onLaunch: function () {
this.checkUser();
var config = wx.getStorageSync('config');
var that = this;
wx.getLocation({
type: 'wgs84',
success: function (res) {
// console.log(res);
var latitude = res.latitude;
var longitude = res.longitude;
let jingweidu={
latitude: res.latitude,
longitude: res.longitude
};
wx.setStorage({
key: 'jingweidu',
data: jingweidu,
})
wx: wx.request({
url: that.url + 'ajax_get_user_role.php',
data: {
unionId: config.unionId,
latitude: latitude,
longitude: longitude
},
header: { 'content-type': 'application/json' },
method: 'GET',
dataType: 'json',
success: function (res) {
console.log(res)
let location = {
province: res.data.result.province,
city: res.data.result.city,
district: res.data.result.district
}
wx.setStorage({
key: 'location',
data: location,
})
},
fail: function (res) { },
complete: function (res) { },
})
}
})
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// var config = wx.getStorageSync('config');
// if(!config){
// wx.login({
// success: res => {
// // 发送 res.code 到后台换取 openId, sessionKey, unionId
// this.checkUser(res.code, null);
// console.log(res,11)
// }
// })
// }else{
// this.checkUser(null, res.openId);
// console.log(res.openId,22)
// }
// wx.getStorage({
// key: 'config',
// success: function(res) {
// console.log('res')
// if(!res){
// wx.login({
// success: res => {
// // 发送 res.code 到后台换取 openId, sessionKey, unionId
// this.checkUser(res.code,null);
// }
// })
// }else{
// this.checkUser(null,res.openId);
// }
// },
// })
// 登录
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
checkUser:function(code,openid){
wx.request({
url: this.url + 'ajax_check_user_registed.php',
data: {
openId: openid,
code: code
},
header: {
'content-type': 'application/json' // 默认值
},
success(res) {
console.log(res, '成功调用checkUser方法')
// if(res.data.result.message=="未注册")
if (res.data.status=='OK'){
wx.showModal({
title: '提示',
content: '成功调用checkUser方法',
})
let config={
openId:res.result.openId,
unionId:res.result.unionId,
zhuce: res.data.result.message
};
wx.setStorage({
key: 'config',
data: config,
})
}
}
})
},
globalData: {
userInfo: null
},
})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment