App.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. console.log('App Launch')
  5. uni.hideTabBar()
  6. // this.getuser()
  7. if (uni.getStorageSync("token")) {
  8. this.$u.post('/User/getDetail').then(res => {
  9. if (res.code == 0) {
  10. this.$Socket.connectSocket()
  11. } else {
  12. uni.removeStorageSync("token")
  13. }
  14. })
  15. }
  16. this.$u.post('/Version/initialization').then(res => {
  17. if (res.response.is_open_bottom_business == 1) {
  18. uni.$tabbar = [{
  19. "iconPath": "/static/images/index1.png",
  20. "selectedIconPath": "/static/images/index.png",
  21. "pagePath": "/pages/index/home",
  22. "text": "主页"
  23. },
  24. {
  25. "iconPath": "/static/images/order1.png",
  26. "selectedIconPath": "/static/images/order.png",
  27. "pagePath": "/pages/order/order",
  28. "text": "订单",
  29. "count": 0
  30. },
  31. {
  32. "iconPath": "/static/images/shop1.png",
  33. "selectedIconPath": "/static/images/shop.png",
  34. "pagePath": "/pages/shop/shop",
  35. "text": "商城"
  36. },
  37. {
  38. "iconPath": "/static/images/mine1.png",
  39. "selectedIconPath": "/static/images/mine.png",
  40. "pagePath": "/pages/mine/mine",
  41. "text": "我的"
  42. }
  43. ]
  44. } else {
  45. uni.$tabbar = [{
  46. "iconPath": "/static/images/index1.png",
  47. "selectedIconPath": "/static/images/index.png",
  48. "pagePath": "/pages/index/home",
  49. "text": "主页"
  50. },
  51. {
  52. "iconPath": "/static/images/order1.png",
  53. "selectedIconPath": "/static/images/order.png",
  54. "pagePath": "/pages/order/order",
  55. "text": "订单",
  56. "count": 0
  57. },
  58. // {
  59. // "iconPath": "/static/images/shop1.png",
  60. // "selectedIconPath": "/static/images/shop.png",
  61. // "pagePath": "/pages/shop/shop",
  62. // "text": "商城"
  63. // },
  64. {
  65. "iconPath": "/static/images/mine1.png",
  66. "selectedIconPath": "/static/images/mine.png",
  67. "pagePath": "/pages/mine/mine",
  68. "text": "我的"
  69. }
  70. ]
  71. }
  72. console.log(uni.$tabbar);
  73. })
  74. uni.login({
  75. provider: "weixin",
  76. success: (code) => {
  77. this.$u.post('/Auth/getWechatMiniOpenid', {
  78. content: {
  79. code: code.code
  80. }
  81. }).then(res => {
  82. uni.setStorageSync("openid", res.response.openid)
  83. })
  84. }
  85. })
  86. },
  87. onShow: function() {
  88. console.log('App Show')
  89. },
  90. onHide: function() {
  91. console.log('App Hide')
  92. },
  93. methods: {
  94. getuser() {
  95. if (getCurrentPages()[0] && getCurrentPages()[0].route != 'pages/index/index') {
  96. // console.log(getCurrentPages()[0].route);
  97. if (uni.getStorageSync("token")) {
  98. this.$u.post('/User/getDetail').then(res => {
  99. if (res.code == 0) {
  100. setTimeout(() => {
  101. this.getuser()
  102. }, 1500)
  103. } else {
  104. uni.removeStorageSync("token")
  105. setTimeout(() => {
  106. this.getuser()
  107. }, 2000)
  108. if (res.msg == '请登录。' || res.msg == '账号在其他地方登录,请重新登录。') {
  109. this.$u.toast(res.msg)
  110. console.log(getCurrentPages()[0].route);
  111. if (getCurrentPages()[0] && getCurrentPages()[0].route != 'pages/index/index') {
  112. setTimeout(() => {
  113. uni.navigateTo({
  114. url: "/pages/mine/login-wx"
  115. })
  116. }, 800)
  117. }
  118. // console.log(getCurrentPages()[0].route);
  119. }
  120. }
  121. })
  122. } else {
  123. setTimeout(() => {
  124. this.getuser()
  125. }, 2000)
  126. }
  127. } else {
  128. setTimeout(() => {
  129. this.getuser()
  130. }, 2000)
  131. }
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss">
  137. /*每个页面公共css */
  138. @import "uview-ui/index.scss";
  139. page {
  140. background-color: #E3F7F0;
  141. }
  142. </style>