index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view class="content">
  3. <view class="user-v" @click="avatarClick">
  4. <image v-if="!user.avatar" class="user-icon" src="/static/user.png"></image>
  5. <image v-else class="user-icon" :src="user.avatar"></image>
  6. </view>
  7. <view class="text-area">
  8. <text class="title">{{user.username}}</text>
  9. </view>
  10. <view class="login-btn">
  11. <button v-if="!token" type="primary" plain="true" size="mini" @click="avatarClick">登录</button>
  12. <button v-else type="default" plain="true" size="mini" @click="dialogToggle">注销</button>
  13. </view>
  14. <uni-popup ref="alertDialog" type="dialog">
  15. <uni-popup-dialog type="info" cancelText="取消" confirmText="注销" title="注销" content="确定是要注销吗?"
  16. @confirm="logout"></uni-popup-dialog>
  17. </uni-popup>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. ref
  23. } from 'vue';
  24. export default {
  25. data() {
  26. const token = ref(null)
  27. const user = ref(null)
  28. return {
  29. token,
  30. user,
  31. }
  32. },
  33. onLoad() {
  34. },
  35. onShow() {
  36. this.token = uni.getStorageSync('token');
  37. this.user = uni.getStorageSync('user');
  38. },
  39. methods: {
  40. avatarClick() {
  41. if (this.token) {
  42. } else {
  43. uni.navigateTo({
  44. url: "/pages/login/index"
  45. })
  46. }
  47. },
  48. logout() {
  49. uni.removeStorageSync('token')
  50. uni.removeStorageSync('user')
  51. this.token = uni.getStorageSync('token');
  52. this.user = uni.getStorageSync('user');
  53. },
  54. dialogToggle() {
  55. this.$refs.alertDialog.open()
  56. },
  57. }
  58. }
  59. </script>
  60. <style>
  61. .content {
  62. display: flex;
  63. flex-direction: column;
  64. align-items: center;
  65. justify-content: center;
  66. }
  67. .user-v {
  68. background: rgba(202, 202, 202, 0.5);
  69. border-radius: 50%;
  70. margin-top: 200rpx;
  71. margin-left: auto;
  72. margin-right: auto;
  73. margin-bottom: 36rpx;
  74. height: 140rpx;
  75. width: 140rpx;
  76. display: flex;
  77. justify-content: center;
  78. align-items: center;
  79. overflow: hidden;
  80. }
  81. .user-icon {
  82. height: 100rpx;
  83. width: 100rpx;
  84. }
  85. .text-area {
  86. display: flex;
  87. justify-content: center;
  88. }
  89. .title {
  90. font-size: 36rpx;
  91. color: #8f8f94;
  92. }
  93. .login-btn {
  94. margin-top: 20rpx;
  95. }
  96. </style>