|
@@ -1,4 +1,7 @@
|
|
|
|
|
|
+const {http} = require('./utils/util')
|
|
|
+const {login,getUserInfo} = require('./API/appraise')
|
|
|
+
|
|
|
App({
|
|
|
onLaunch() {
|
|
|
|
|
@@ -13,18 +16,24 @@ App({
|
|
|
}
|
|
|
const ui_w = 360;
|
|
|
|
|
|
- wx.setStorage({
|
|
|
- key: 'vid',
|
|
|
- data: '',
|
|
|
- success: function() {
|
|
|
- console.log('写入vid缓存成功')
|
|
|
- },
|
|
|
- fail: function() {
|
|
|
- console.log('写入vid发生错误')
|
|
|
- }
|
|
|
- })
|
|
|
+ wx.setStorageSync('vid', '')
|
|
|
|
|
|
var clientWidth = wx.getSystemInfoSync().windowWidth;
|
|
|
+var loginOption = {
|
|
|
+
|
|
|
+ header :{
|
|
|
+ "content-type": 'application/x-www-form-urlencoded',
|
|
|
+ },
|
|
|
+ data:{
|
|
|
+ vid: wx.getStorageSync('vid')
|
|
|
+ },
|
|
|
+}
|
|
|
+
|
|
|
+var infoOption = {
|
|
|
+ header:{
|
|
|
+ "Authorization": wx.getStorageSync('token')
|
|
|
+ },
|
|
|
+}
|
|
|
|
|
|
|
|
|
if(wx.getStorageSync('token') == ''){
|
|
@@ -38,68 +47,68 @@ var clientWidth = wx.getSystemInfoSync().windowWidth;
|
|
|
|
|
|
console.log("code: "+res.code);
|
|
|
var url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + wxInfo.appid + '&secret=' + wxInfo.appSecret + '&js_code=' + res.code + '&grant_type=authorization_code'
|
|
|
- wx.request({
|
|
|
- url: url,
|
|
|
- success(res){
|
|
|
- wx.setStorageSync('vid', res.data.openid);
|
|
|
- console.log(wx.getStorageSync('vid'));
|
|
|
- wx.getUserProfile({
|
|
|
- desc: '登录',
|
|
|
-
|
|
|
- success: (res) => {
|
|
|
- wx.setStorageSync('nickName', res.userInfo.nickuName);
|
|
|
- wx.setStorageSync('avatarUrl', res.userInfo.avatarUrl);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- wx.request({
|
|
|
- url: 'http://192.168.31.29:8084/user/login',
|
|
|
- method:'POST',
|
|
|
- header: {
|
|
|
- 'content-type': 'application/x-www-form-urlencoded'
|
|
|
- },
|
|
|
- data:{
|
|
|
- vid: wx.getStorageSync('vid')
|
|
|
- },
|
|
|
-
|
|
|
- success(res){
|
|
|
- console.log(res);
|
|
|
-
|
|
|
-
|
|
|
- console.log('vid: '+ wx.getStorageSync('vid'));
|
|
|
- if(res.data.code == 403){
|
|
|
- wx.navigateTo({
|
|
|
- url: '/pages/register/register',
|
|
|
- })
|
|
|
- }else if(res.data.code == 200){
|
|
|
- wx.setStorageSync('token', res.data.data.token);
|
|
|
- wx.setStorageSync('uid', res.data.data.Uid);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- })
|
|
|
+ wx.request({
|
|
|
+ url:url,
|
|
|
+ success: (res) => {
|
|
|
+ console.log(res);
|
|
|
+ console.log(res.data.openid);
|
|
|
+ wx.setStorageSync('vid', res.data.openid);
|
|
|
+ console.log(wx.getStorageSync('vid'));
|
|
|
+
|
|
|
+ login(loginOption).then(res => {
|
|
|
+ console.log(res);
|
|
|
+ wx.setStorageSync('token', res.token);
|
|
|
+ wx.setStorageSync('uid', res.uid);
|
|
|
+ wx.setStorageSync('avatarUrl', res.user_info.avatar);
|
|
|
+ wx.setStorageSync('nickName', res.user_info.name);
|
|
|
+ }).catch(err => {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/register/register',
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
})
|
|
|
}else{
|
|
|
- wx.request({
|
|
|
- url: 'http://192.168.31.29:8084/user/info',
|
|
|
- header:{
|
|
|
- "Authorization": wx.getStorageSync('token')
|
|
|
- },
|
|
|
- success(res){
|
|
|
- console.log(res);
|
|
|
- if(res.data.code == 200){
|
|
|
- console.log('token有效');
|
|
|
- wx.setStorageSync('uid', res.data.data.Uid);
|
|
|
- }
|
|
|
- }
|
|
|
+ getUserInfo(infoOption).then(res => {
|
|
|
+ console.log(res);
|
|
|
+ console.log('token有效');
|
|
|
+ wx.setStorageSync('uid', res.uid);
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(err);
|
|
|
+ console.log('token已失效,请重新登录');
|
|
|
+ wx.login({
|
|
|
+ success: (res) => {
|
|
|
+
|
|
|
+ console.log("code: "+res.code);
|
|
|
+ var url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + wxInfo.appid + '&secret=' + wxInfo.appSecret + '&js_code=' + res.code + '&grant_type=authorization_code'
|
|
|
+ wx.request({
|
|
|
+ url:url,
|
|
|
+ success: (res) => {
|
|
|
+ console.log(res);
|
|
|
+ console.log(res.data.openid);
|
|
|
+ wx.setStorageSync('vid', res.data.openid);
|
|
|
+ console.log(wx.getStorageSync('vid'));
|
|
|
+ login(loginOption).then(res => {
|
|
|
+ console.log(res);
|
|
|
+ wx.setStorageSync('token', res.token);
|
|
|
+ wx.setStorageSync('uid', res.user_info.uid);
|
|
|
+ wx.setStorageSync('avatarUrl', res.user_info.avatar);
|
|
|
+ wx.setStorageSync('nickName', res.user_info.name);
|
|
|
+ }).catch(err => {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/register/register',
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
})
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
},
|
|
|
globalData: {
|