123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- // index.js
- var app = getApp();
- Page({
- data:{
- loading: true,
- src: "",
- msg: ""
- },
-
- onLoad:function(options){
- console.log(1111111111,encodeURIComponent("org_3"));
- app.getScene(options);
- var userId = wx.getStorageSync("userId");
- var token = wx.getStorageSync("token");
- if (!userId || token) { //未登录
- this.autologin();
- }else{
- this.setData({
- src: app.globalData.h5Url + "/#/pages/index/index?"+app.getCommonParam()
- })
- console.log(this.data.src);
- }
- },
- onShow: function () {
- var that = this;
- app.ajaxReadyCallback = res => { //各个接口统一回调方法
- var apiname = res.data.apiname;
- if(apiname == 'icon'){
-
- }
- }
- },
- autologin(){
- let that = this;
- wx.login({
- success: function (ret) {
- wx.showLoading({
- title: '加载中',
- mask: true
- });
- wx.request({
- url: app.globalData.serverUrl + 'Oauth/checkCode',
- data: {
- type: 2,
- code: ret.code,
- },
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success: function (res) {
- wx.hideLoading();
- if (res.data.code == 0) {
- try {
- app.logout();
- wx.setStorageSync("userId", res.data.data.userId);
- wx.setStorageSync("token", res.data.data.token);
- } catch (e) { };
- var userinfo = {
- userId: res.data.data.userId,
- token: res.data.data.token,
- };
- app.globalData.userinfo = userinfo;
-
- that.setData({
- src: app.globalData.h5Url + "/#/pages/index/index?"+app.getCommonParam()
- })
- console.log(that.data.src);
- }else{
- wx.showModal({
- title: '提示',
- content: res.data.message,
- showCancel: false
- })
- }
- },
- fail:function(e){
- wx.hideLoading();
- wx.showModal({
- title: '提示',
- content: '登录失败,请重试',
- showCancel: false
- })
- }
- })
- },
- fail:function(e){
- wx.hideLoading();
- wx.showModal({
- title: '提示',
- content: '登录失败,请重试',
- showCancel: false
- })
- }
- });
- }
-
- })
|