demo.vue 2.3 KB

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