App.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. const that=this;
  5. // #ifdef MP
  6. let sysInfo=uni.getSystemInfoSync(),menuInfo=uni.getMenuButtonBoundingClientRect();
  7. let offsetBottom=menuInfo.top-sysInfo.statusBarHeight;
  8. if(sysInfo.system.indexOf('iOS')!==-1){
  9. this.$store.commit('setPlatform','ios');
  10. }
  11. else if(sysInfo.system.indexOf('Android')!==-1){
  12. this.$store.commit('setPlatform','android');
  13. }
  14. else{
  15. this.$store.commit('setPlatform','other');
  16. }
  17. this.$store.commit('setStatusBarHeight',sysInfo.statusBarHeight);
  18. this.$store.commit('setTopbarOffsetHeight',sysInfo.statusBarHeight + offsetBottom*2 + menuInfo.height);
  19. this.$store.commit('setTabBarHeight',(this.$util.hasSafeArea()?68:20)+106);
  20. return;//单元测试开关
  21. if(uni.getStorageSync('autoLogin')==='false'){
  22. return;
  23. }
  24. uni.login({//免密登录
  25. success:(res)=>{
  26. that.$api.login.wxLogin({
  27. scene: "WxMPLogin",
  28. miniProgramEncryUserInfoParam:{
  29. jsCode:res.code
  30. }
  31. }).then(result=>{
  32. if(result.status==='Succ'){
  33. if(!result.data.succ){
  34. if(result.data.wxLoginInfo){//新用户保存用户openid,unionId
  35. uni.setStorageSync('openId',result.data.wxLoginInfo.openId);
  36. uni.setStorageSync('unionId',result.data.wxLoginInfo.unionId);
  37. }
  38. }
  39. else{
  40. uni.setStorageSync('LL_Ukn',result.data.userToken.ukn);
  41. uni.setStorageSync('token',result.data.userToken.token);
  42. uni.setStorageSync('userInfo',JSON.stringify(result.data));
  43. uni.setStorageSync('user',JSON.stringify(result.data.userToken.user));
  44. this.$api.public.aliossCdn({}).then(cdnRes=>{
  45. this.$store.commit('setImageCdn',cdnRes.data.pictureCdn);
  46. this.$store.commit('setVideoCdn',cdnRes.data.videoCdn);
  47. })
  48. this.$api.public.mineDetail({
  49. getAlbum:true,
  50. completeUser:result.data.userToken.user
  51. }).then(res=>{
  52. this.$store.commit('setUserInfo',res.data);
  53. uni.setStorageSync('userInfo',JSON.stringify(res.data));
  54. if(result.data.isNew){
  55. uni.reLaunch({
  56. url:'/pages/info/sex'
  57. })
  58. return;
  59. }
  60. let step=result.data.regStepNew||result.data.regStep;
  61. switch(step){
  62. case 'Sex':
  63. uni.reLaunch({
  64. url:'/pages/info/sex'
  65. })
  66. break;
  67. case 'SocialImage':
  68. uni.reLaunch({
  69. url:'/pages/info/figure'
  70. })
  71. break;
  72. case 'SocialData':
  73. uni.reLaunch({
  74. url:'/pages/info/datum'
  75. })
  76. break;
  77. case 'CityStay':
  78. uni.reLaunch({
  79. url:'/pages/info/city'
  80. })
  81. break;
  82. case 'WxInfo':
  83. uni.reLaunch({
  84. url:'/pages/info/wechat'
  85. })
  86. break;
  87. case 'Basic':
  88. case 'Index':
  89. uni.reLaunch({
  90. url:'/pages/friends/friends'
  91. })
  92. break;
  93. }
  94. uni.reLaunch({
  95. url:'/pages/friends/friends'
  96. })
  97. })
  98. }
  99. }
  100. })
  101. },
  102. fail: (err) => {
  103. console.log(err)
  104. }
  105. });
  106. // #endif
  107. },
  108. onShow: function() {
  109. console.log('App Show')
  110. },
  111. onHide: function() {
  112. console.log('App Hide')
  113. },
  114. onUnload() {
  115. console.log('im logout')
  116. uni.$TUIKit.logout();
  117. uni.$TUIKit.destroy();
  118. },
  119. }
  120. </script>