demo.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <view class="wrap">
  3. </view>
  4. </template>
  5. <script>
  6. import {
  7. mapState
  8. } from 'vuex';
  9. export default {
  10. components: {
  11. },
  12. data() {
  13. return {
  14. }
  15. },
  16. onLoad() {
  17. },
  18. // #ifndef MP
  19. onNavigationBarButtonTap(e) {
  20. const index = e.index;
  21. if (index === 0) {
  22. this.navTo('/pages/set/set');
  23. } else if (index === 1) {
  24. // #ifdef APP-PLUS
  25. const pages = getCurrentPages();
  26. const page = pages[pages.length - 1];
  27. const currentWebview = page.$getAppWebview();
  28. currentWebview.hideTitleNViewButtonRedDot({
  29. index
  30. });
  31. // #endif
  32. uni.navigateTo({
  33. url: '/pages/notice/notice'
  34. })
  35. }
  36. },
  37. // #endif
  38. computed: {
  39. ...mapState(['hasLogin', 'userInfo']),
  40. },
  41. onShow() {
  42. this.$api.doRequest('get', '/commonUser/api/checkSession').then(res => {
  43. console.log("checkSession", res)
  44. if (res.data.data == "INVALID") {
  45. uni.showModal({
  46. title: '登录提示',
  47. content: '当前登入信息验证失败,是否重新登录?',
  48. showCancel: true,
  49. confirmText: '登录',
  50. success: (e) => {
  51. if (e.confirm) {
  52. uni.navigateTo({
  53. url: '/pages/public/login'
  54. })
  55. }
  56. },
  57. fail: () => {},
  58. complete: () => {}
  59. })
  60. }
  61. })
  62. console.log("hasLogin", this.hasLogin)
  63. },
  64. methods: {
  65. /**
  66. * 统一跳转接口,拦截未登录路由
  67. * navigator标签现在默认没有转场动画,所以用view
  68. */
  69. navTo(url) {
  70. if (!this.hasLogin) {
  71. url = '/pages/public/login';
  72. }
  73. uni.navigateTo({
  74. url
  75. })
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang='scss' scoped>
  81. page {
  82. background: #F5F6FA;
  83. }
  84. .wrap {
  85. background: #fff;
  86. margin: 10px;
  87. border-radius: 10px;
  88. padding: 10px;
  89. }
  90. </style>