splash.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/splash/splash.js
  2. var app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. spashTextValue: '- 智慧服务 智创未来 -',
  9. splashImageUrl: '/images/tu.png',
  10. splashImageUrl2: '/images/zi.png'
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. app.getScene(options);
  17. this.setData({
  18. type: options.type?options.type:''
  19. });
  20. if(options.type){
  21. wx.setStorageSync("visitorType",options.type);
  22. if(options.type == 'visitorAdd'){
  23. wx.setStorageSync("visitorToUserId",options.userId?options.userId:0);
  24. wx.setStorageSync("visitorOrgId",options.orgId?options.orgId:0);
  25. }
  26. }
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow: function () {
  37. var that = this;
  38. setTimeout(function(){
  39. if(that.data.type == 'visitorAdd'){
  40. var token = wx.getStorageSync("visitorToken");
  41. if (!token || token == undefined) { //未登录
  42. app.loginVisitor(that.data.type);
  43. } else {
  44. wx.redirectTo({
  45. url: '/pages/visitor/add/index'
  46. });
  47. }
  48. }else if(that.data.type == 'visitor'){
  49. var token = wx.getStorageSync("visitorToken");
  50. if (!token || token == undefined) { //未登录
  51. app.loginVisitor(that.data.type);
  52. } else {
  53. wx.redirectTo({
  54. url: '/pages/visitor/index'
  55. });
  56. }
  57. }else{
  58. var userId = wx.getStorageSync("userId");
  59. if (!userId || userId == undefined) { //未登录
  60. // wx.redirectTo({
  61. // url: '/pages/userLogin/userLogin'
  62. // })
  63. wx.login({
  64. success: function (ret) {
  65. wx.showLoading({
  66. title: '加载中',
  67. mask: true
  68. });
  69. let orgId = wx.getStorageSync("orgId");
  70. wx.request({
  71. url: app.globalData.serverUrl + 'login/wxPreLogin',
  72. data: {
  73. orgId: orgId,
  74. code: ret.code,
  75. },
  76. method: 'POST',
  77. header: {
  78. 'content-type': 'application/x-www-form-urlencoded'
  79. },
  80. success: function (res) {
  81. console.log(res);
  82. wx.hideLoading();
  83. if (res.data.code == 0) {
  84. try {
  85. app.logout();
  86. wx.setStorageSync("userId", res.data.data.userId);
  87. wx.setStorageSync("token", res.data.data.token);
  88. } catch (e) { };
  89. var userinfo = {
  90. userId: res.data.data.userId,
  91. token: res.data.data.token,
  92. };
  93. app.globalData.userinfo = userinfo;
  94. wx.switchTab({
  95. url: '/pages/index/index'
  96. });
  97. }else{
  98. wx.showModal({
  99. title: '提示',
  100. content: res.data.message,
  101. showCancel: false
  102. })
  103. }
  104. },
  105. fail:function(e){
  106. console.log(e);
  107. wx.hideLoading();
  108. wx.showModal({
  109. title: '提示',
  110. content: '登录失败,请重试',
  111. showCancel: false
  112. })
  113. }
  114. })
  115. }
  116. });
  117. } else {
  118. wx.switchTab({
  119. url: '/pages/index/index'
  120. });
  121. }
  122. }
  123. },1500);
  124. },
  125. /**
  126. * 生命周期函数--监听页面隐藏
  127. */
  128. onHide: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面卸载
  132. */
  133. onUnload: function () {
  134. },
  135. /**
  136. * 页面相关事件处理函数--监听用户下拉动作
  137. */
  138. onPullDownRefresh: function () {
  139. },
  140. /**
  141. * 页面上拉触底事件的处理函数
  142. */
  143. onReachBottom: function () {
  144. },
  145. /**
  146. * 用户点击右上角分享
  147. */
  148. onShareAppMessage: function () {
  149. }
  150. })