index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="mine">
  3. <view class="mine-header">
  4. <view class="mine-header-info">
  5. <image :src="avatarSrc" />
  6. <view>
  7. {{ state.info.userName }}
  8. </view>
  9. </view>
  10. </view>
  11. <view class="mine-content">
  12. <view class="mine-content-cell">
  13. <view class="mine-content-cell-left">
  14. <image :src="phoneSrc" />
  15. 手机号码
  16. </view>
  17. <view>
  18. {{ state.info.phoneNumber }}
  19. </view>
  20. </view>
  21. </view>
  22. <view class="mine-button">
  23. <wd-button :round="false" :block="true" :loading="state.buttonLoading" @click="onClickLogout">
  24. 退出登录
  25. </wd-button>
  26. </view>
  27. </view>
  28. </template>
  29. <script lang="ts" setup>
  30. import { onShow } from '@dcloudio/uni-app';
  31. import { reactive } from 'vue';
  32. import avatarSrc from '@/static/public/avatar@2x.png';
  33. import phoneSrc from '@/static/mine/phone@2x.png';
  34. import LocalStorage from '@/LocalStorage';
  35. import { apis } from '@/apis';
  36. interface State {
  37. info: {
  38. userName: string,
  39. phoneNumber: string,
  40. },
  41. buttonLoading: boolean,
  42. };
  43. const state: State = reactive({
  44. info: {
  45. userName: '测试',
  46. phoneNumber: '18888888888',
  47. },
  48. buttonLoading: false,
  49. });
  50. const api = {
  51. // 退出登录
  52. logout: async () => {
  53. state.buttonLoading = true;
  54. try {
  55. await apis.logout();
  56. } catch (error: any) {
  57. console.error(error);
  58. } finally {
  59. LocalStorage.clear();
  60. uni.reLaunch({
  61. url: '/pages/login/index/index',
  62. success: () => {
  63. uni.showToast({
  64. icon: 'success',
  65. mask: true,
  66. duration: 2000,
  67. title: '退出成功',
  68. });
  69. }
  70. });
  71. state.buttonLoading = false;
  72. }
  73. },
  74. }
  75. onShow(() => {
  76. });
  77. // 点击退出登录
  78. const onClickLogout = async () => {
  79. // 退出登录
  80. await api.logout();
  81. }
  82. </script>
  83. <style lang="scss" scoped>
  84. .mine {
  85. &-header {
  86. height: 180rpx;
  87. padding: 20rpx;
  88. border-bottom: 2rpx solid $background-color;
  89. display: flex;
  90. justify-content: space-between;
  91. align-items: center;
  92. &-info {
  93. display: flex;
  94. align-items: center;
  95. image {
  96. width: 100rpx;
  97. height: 100rpx;
  98. background: $background-color;
  99. border: 2rpx solid $background-color;
  100. border-radius: 50%;
  101. margin-right: 20rpx;
  102. }
  103. }
  104. }
  105. &-content {
  106. padding: 0 20rpx;
  107. &-cell {
  108. width: 100%;
  109. height: 120rpx;
  110. border-bottom: 2rpx solid $border-color;
  111. display: flex;
  112. justify-content: space-between;
  113. align-items: center;
  114. &-left {
  115. display: flex;
  116. align-items: center;
  117. image {
  118. width: 40rpx;
  119. height: 40rpx;
  120. margin-right: 20rpx;
  121. }
  122. }
  123. }
  124. }
  125. &-button {
  126. width: 100%;
  127. height: 150rpx;
  128. padding: 0 20rpx;
  129. position: fixed;
  130. /* #ifdef H5 */
  131. bottom: var(--tab-bar-height);
  132. left: 0;
  133. /* #endif */
  134. /* #ifndef H5 */
  135. bottom: 0;
  136. left: 0;
  137. /* #endif */
  138. }
  139. }
  140. </style>