123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <template>
- <view class="content">
- <view class="user-v" @click="avatarClick">
- <image v-if="!user.avatar" class="user-icon" src="/static/user.png"></image>
- <image v-else class="user-icon" :src="user.avatar"></image>
- </view>
- <view class="text-area">
- <text class="title">{{user.username}}</text>
- </view>
- <view class="login-btn">
- <button v-if="!token" type="primary" plain="true" size="mini" @click="avatarClick">登录</button>
- <button v-else type="default" plain="true" size="mini" @click="dialogToggle">注销</button>
- </view>
- <uni-popup ref="alertDialog" type="dialog">
- <uni-popup-dialog type="info" cancelText="取消" confirmText="注销" title="注销" content="确定是要注销吗?"
- @confirm="logout"></uni-popup-dialog>
- </uni-popup>
- </view>
- </template>
- <script>
- import {
- ref
- } from 'vue';
- export default {
- data() {
- const token = ref(null)
- const user = ref(null)
- return {
- token,
- user,
- }
- },
- onLoad() {
- },
- onShow() {
- this.token = uni.getStorageSync('token');
- this.user = uni.getStorageSync('user');
- },
- methods: {
- avatarClick() {
- if (this.token) {
- } else {
- uni.navigateTo({
- url: "/pages/login/index"
- })
- }
- },
- logout() {
- uni.removeStorageSync('token')
- uni.removeStorageSync('user')
- this.token = uni.getStorageSync('token');
- this.user = uni.getStorageSync('user');
- },
- dialogToggle() {
- this.$refs.alertDialog.open()
- },
- }
- }
- </script>
- <style>
- .content {
- display: flex;
- flex-direction: column;
- align-items: center;
- justify-content: center;
- }
- .user-v {
- background: rgba(202, 202, 202, 0.5);
- border-radius: 50%;
- margin-top: 200rpx;
- margin-left: auto;
- margin-right: auto;
- margin-bottom: 36rpx;
- height: 140rpx;
- width: 140rpx;
- display: flex;
- justify-content: center;
- align-items: center;
- overflow: hidden;
- }
- .user-icon {
- height: 100rpx;
- width: 100rpx;
- }
- .text-area {
- display: flex;
- justify-content: center;
- }
- .title {
- font-size: 36rpx;
- color: #8f8f94;
- }
- .login-btn {
- margin-top: 20rpx;
- }
- </style>
|