Commit 6341be4a by shijiuyan

1

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