Commit 6341be4a by shijiuyan

1

parent 7de55db2
......@@ -2,21 +2,50 @@
App({
url: 'https://www.koala-online.cn/compass/if/',
onLaunch: function () {
var that = this;
//调用wx用户登陆
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
this.checkUser(res.code, null);
wx.request({
url: that.url + 'ajax_check_user_registed.php',
data: {
code: res.code
},
success(resp) {
//保存返回的openId和unionId
console.log(resp)
let config = {
openId: resp.data.result.openId,
unionId: resp.data.result.unionId,
registed: resp.data.result.registed
};
// wx.showToast({
// title: "unionId=" + res.data.result.unionId,
// icon: 'success',
// duration: 2000
// });
wx.setStorageSync("config", config);
},
fail (resp) {
wx.showToast({
title: 'resp',
icon: 'success',
duration: 2000
});
},
complete (resp) {
},
})
}
})
var config = wx.getStorageSync('config');
var that = this;
//获取并保存用户的经纬度信息
wx.getLocation({
type: 'wgs84',
success: function (res) {
let location={
let location = {
latitude: res.latitude,
longitude: res.longitude
};
......@@ -26,48 +55,36 @@ App({
})
}
})
// 获取用户信息
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) {
//保存返回的openId和unionId
let config = {
openId: res.data.result.openId,
unionId: res.data.result.unionId,
registed: res.data.result.registed
};
wx.showToast({
title: "unionId=" + res.data.result.unionId,
icon: 'success',
duration: 2000
});
wx.setStorage({
key: 'config',
data: config,
});
},
fail: function (res) {
wx.showToast({
title: "失败",
icon: 'success',
duration: 2000
});
},
complete: function (res) {
},
})
},
globalData: {
userInfo: null
userInfo: null,
config:null
},
})
\ No newline at end of file
......@@ -29,15 +29,11 @@ Page({
var that=this;
//获取用户当前的经纬度信息并调用接口判断用户身份
var config = wx.getStorageSync('config');
setTimeout(function(){
wx.getStorage({
key: 'location',
success: function(resp) {
var location = resp.data;
var latitude = resp.data.latitude;
var longitude = resp.data.longitude;
var location = wx.getStorageSync('location');
var latitude = location.latitude;
var longitude = location.longitude;
wx.showToast({
title: config.unionId,
title: location,
})
wx.request({
url: app.url + 'ajax_get_user_role.php',
......@@ -51,9 +47,8 @@ Page({
dataType: 'json',
success: function (res) {
console.log(res)
if (res.statusCode == 200) {
if(res.statusCode==200){
//保存用户当前的省市区县信息
location.province = res.data.result.province
location.city = res.data.result.city
location.district = res.data.result.district
......@@ -69,7 +64,7 @@ Page({
})
//未注册用户的话。跳转到社会人士注册页面
if (res.data.status == "REGIST") {
if (res.data.status =="REGIST") {
//页面跳转
wx.redirectTo({
url: '../socialUserRegister/socialUserRegister',
......@@ -77,11 +72,11 @@ Page({
}
that.setData({
roleTitle: res.data.result.name,
role: res.data.result.role,
role:res.data.result.role,
childAge: res.data.result.childAge
})
//菜单控制[亲子活动]
if (res.data.result.role == 1 || res.data.result.childAge == 1) {
if (res.data.result.role == 1 || res.data.result.childAge==1) {
that.setData({
showFamily: true
})
......@@ -101,13 +96,13 @@ Page({
that.getIndexData();
}
},
fail: function (res) { },
complete: function (res) { },
fail: function (res) {
wx.showToast({
title: '数据获取异常',
})
},
complete: function (res) { },
})
},1000);
},
/**
......
......@@ -55,7 +55,8 @@ Page({
//家校/家园用户注册
regist(e){
//获取本地存储的openId和unionId
var config = wx.getStorageSync('config');
var that = this;
// 获取用户信息
wx.getUserInfo({
......@@ -68,9 +69,6 @@ Page({
this.userInfoReadyCallback(res)
}
//获取本地存储的openId和unionId
var config = wx.getStorageSync('config');
wx.request({
url: app.url + 'ajax_user_register.php',
data: {
......
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