|
@@ -1,96 +1,11 @@
|
|
|
//app.js
|
|
|
-const api = require('./config.js');
|
|
|
-
|
|
|
+import WxAuthor from './utils/WxAuthor'
|
|
|
App({
|
|
|
- host: api.host,
|
|
|
onLaunch: function () {
|
|
|
let self = this;
|
|
|
// 登录
|
|
|
- wx.login({
|
|
|
- success: res => {
|
|
|
- wx.request({
|
|
|
- url: self.host,
|
|
|
- data: {
|
|
|
- act: "login",
|
|
|
- op: "ministart",
|
|
|
- code: res.code,
|
|
|
- client_type: "mini"
|
|
|
- },
|
|
|
- success: function (res) {
|
|
|
- self.globalData.userId.openid = res.data.datas.openid;
|
|
|
- self.globalData.userId.unionid = res.data.datas.unionid;
|
|
|
- // 获取用户信息
|
|
|
- wx.getSetting({
|
|
|
- success: res => {
|
|
|
- if (res.authSetting['scope.userInfo']) {
|
|
|
- wx.getUserInfo({
|
|
|
- success: res => {
|
|
|
- self.globalData.userInfo = res.userInfo;
|
|
|
- self.globalData.userInfo.nickname = res.userInfo.nickName;
|
|
|
- let userInfo = Object.assign({}, self.globalData.userId, self.globalData.userInfo);
|
|
|
- wx.request({
|
|
|
- url: self.host,
|
|
|
- method: 'GET',
|
|
|
- data: {
|
|
|
- user_info: userInfo,
|
|
|
- act: "login",
|
|
|
- op: "wxauthen",
|
|
|
- client_type: "mini"
|
|
|
- },
|
|
|
- success: function (res) {
|
|
|
- wx.setStorageSync('session_id', res.data.datas.HPHPSESSID);
|
|
|
- if (res.statusCode == 200) {
|
|
|
- let len = getCurrentPages().length
|
|
|
- let currentPage = getCurrentPages()[len - 1]
|
|
|
- let params = ''
|
|
|
- if (currentPage.options) {
|
|
|
- for (let k in currentPage.options) {
|
|
|
- params = params + k + '=' + currentPage.options[k] + '&'
|
|
|
- }
|
|
|
- params = params.slice(0, params.length - 1)
|
|
|
- }
|
|
|
- let current_url = "/" + currentPage['route']
|
|
|
- if (params) {
|
|
|
- current_url = current_url + '?' + params
|
|
|
- }
|
|
|
- console.log('current_url:', current_url);
|
|
|
- wx.reLaunch({
|
|
|
- url: current_url
|
|
|
- });
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
|
|
- // 所以此处加入 callback 以防止这种情况
|
|
|
- if (this.userInfoReadyCallback) {
|
|
|
- this.userInfoReadyCallback(res)
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
- let len = getCurrentPages().length
|
|
|
- let currentPage = getCurrentPages()[len - 1].route
|
|
|
- console.log('currentPage:', getCurrentPages()[len - 1]);
|
|
|
- if(currentPage.indexOf('shareBonus/shareBonus') != -1) {
|
|
|
- wx.navigateTo({
|
|
|
- url: `/pages/login/login`
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- // 发送 res.code 到后台换取 openId, sessionKey, unionId
|
|
|
- }
|
|
|
- })
|
|
|
+ new WxAuthor(self)
|
|
|
+
|
|
|
},
|
|
|
globalData: {
|
|
|
userId: {
|