exit.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view>
  3. <scroll-view
  4. :scroll-y="modalName == null"
  5. class="page"
  6. :class="modalName != null ? 'show' : ''"
  7. >
  8. <cu-custom bgColor="bg-gradual-pink" :isBack="false">
  9. <!-- <block slot="backText">返回</block> -->
  10. <block slot="content">退出页</block>
  11. </cu-custom>
  12. <view class="solids-bottom padding-xs flex align-center">
  13. <view class="flex-sub text-center">
  14. <view class="solid-bottom text-xsl padding">
  15. <text class="cuIcon-roundcheckfill text-green"></text>
  16. </view>
  17. <view class="padding">{{ item.msg }}</view>
  18. </view>
  19. </view>
  20. <view class="padding flex flex-direction">
  21. <button class="cu-btn bg-green shadow-blur round lg" @tap="goback()">
  22. 返回登录
  23. </button>
  24. </view>
  25. </scroll-view>
  26. </view>
  27. </template>
  28. <script>
  29. import api from "@/api/api";
  30. import { ACCESS_TOKEN, USER_NAME, USER_INFO } from "@/common/util/constants";
  31. export default {
  32. data() {
  33. return {
  34. modalName: null,
  35. item: { msg: "退出成功" },
  36. jumping: false, // 防止重复点击导致连续跳转
  37. };
  38. },
  39. onLoad: function (option) {
  40. const logoutToken = uni.getStorageSync(ACCESS_TOKEN);
  41. const logoutRequest = api.logout(logoutToken);
  42. console.log(logoutToken, "token");
  43. this.clearLoginState();
  44. logoutRequest.catch(() => {
  45. console.error("退出登录请求失败");
  46. });
  47. },
  48. onBackPress() {
  49. return true;
  50. },
  51. methods: {
  52. clearLoginState() {
  53. [
  54. ACCESS_TOKEN,
  55. USER_NAME,
  56. USER_INFO,
  57. "menuPermission",
  58. "btnPermission",
  59. ].forEach((key) => {
  60. uni.removeStorageSync(key);
  61. });
  62. this.$store.commit("SET_TOKEN", "");
  63. this.$store.commit("SET_NAME", { username: "", realname: "" });
  64. this.$store.commit("SET_DICT", "");
  65. },
  66. goback() {
  67. // 避免重复点击/与 401 跳转叠加,造成 do not operate continuously
  68. if (this.jumping) {
  69. return;
  70. }
  71. this.jumping = true;
  72. // 退出登录后清空页面栈,否则登录页侧滑会回到系统内部页面
  73. uni.reLaunch({
  74. url: "/pages/login/login",
  75. complete: () => {
  76. setTimeout(() => {
  77. this.jumping = false;
  78. }, 800);
  79. },
  80. });
  81. },
  82. },
  83. };
  84. </script>
  85. <style>
  86. </style>