123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- // pages/splash/splash.js
- var app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- spashTextValue: '- 智慧服务 智创未来 -',
- splashImageUrl: '/images/tu.png',
- splashImageUrl2: '/images/zi.png'
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- app.getScene(options);
- this.setData({
- type: options.type?options.type:''
- });
- if(options.type){
- wx.setStorageSync("visitorType",options.type);
- if(options.type == 'visitorAdd'){
- wx.setStorageSync("visitorToUserId",options.userId?options.userId:0);
- wx.setStorageSync("visitorOrgId",options.orgId?options.orgId:0);
- }
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- var that = this;
-
- setTimeout(function(){
- if(that.data.type == 'visitorAdd'){
- var token = wx.getStorageSync("visitorToken");
- if (!token || token == undefined) { //未登录
- app.loginVisitor(that.data.type);
- } else {
- wx.redirectTo({
- url: '/pages/visitor/add/index'
- });
- }
- }else if(that.data.type == 'visitor'){
- var token = wx.getStorageSync("visitorToken");
- if (!token || token == undefined) { //未登录
- app.loginVisitor(that.data.type);
- } else {
- wx.redirectTo({
- url: '/pages/visitor/index'
- });
- }
- }else{
- var userId = wx.getStorageSync("userId");
- if (!userId || userId == undefined) { //未登录
- // wx.redirectTo({
- // url: '/pages/userLogin/userLogin'
- // })
- wx.login({
- success: function (ret) {
- wx.showLoading({
- title: '加载中',
- mask: true
- });
- let orgId = wx.getStorageSync("orgId");
- wx.request({
- url: app.globalData.serverUrl + 'login/wxPreLogin',
- data: {
- orgId: orgId,
- code: ret.code,
- },
- method: 'POST',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- success: function (res) {
- console.log(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;
- wx.switchTab({
- url: '/pages/index/index'
- });
- }else{
- wx.showModal({
- title: '提示',
- content: res.data.message,
- showCancel: false
- })
- }
- },
- fail:function(e){
- console.log(e);
- wx.hideLoading();
- wx.showModal({
- title: '提示',
- content: '登录失败,请重试',
- showCancel: false
- })
- }
- })
- }
- });
- } else {
- wx.switchTab({
- url: '/pages/index/index'
- });
- }
- }
- },1500);
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|