web
2025-07-11 ae00f214aaeb74d8f3c8e9c6fb0a8c793816f892
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<template>
    <view class="user" :style="{paddingTop:topHeight + 'rpx'}">
        <view class="content">
            <view class="user" @click="setUser">
                <view class="userImg">
                    <image :src="userInfo?.headImg ? userInfo.headImg : defaultImg" mode="widthFix"></image>
                </view>
                <view class="info">
                    <text class="name">{{userInfo?.nickName ? userInfo.nickName : '用户'}}</text>
                </view>
            </view>
            <view class="typeList">
                <view class="typeItem">
                    <view class="name">剩余水量</view>
                    <view class="val">{{userInfo?.balance}}m³</view>
                </view>
                <view class="typeItem">
                    <view class="name">总购水量</view>
                    <view class="val">{{userInfo?.sumBuyCount}}m³</view>
                </view>
                <view class="typeItem">
                    <view class="name">累计水量</view>
                    <view class="val">{{userInfo?.sumUseCount}}m³</view>
                </view>
            </view>
            <view class="loginOut">
                <button class="btn" type="primary" plain @click="loginOut">退出登录</button>
            </view>
        </view>
    </view>
</template>
 
<script setup>
    import { onMounted, ref } from "vue";
    import { onShow } from "@dcloudio/uni-app"
    import defaultImg from '../../static/images/default-head.png'
    
    const topHeight = ref(0)
    const userInfo = ref()
    
    // 获取状态栏高度
    const getTopHeight = () => {
        if(uni.getMenuButtonBoundingClientRect){
            topHeight.value = uni.getMenuButtonBoundingClientRect().bottom * 2
        }
    }
    
    const setUser = () => {
        uni.navigateTo({
            url: '/pages/userSet/index'
        })
    }
    
    // 退出登录
    const loginOut = () => {
        uni.showModal({
            title: '温馨提示',
            content: '确认退出登录?',
            success: (res) => {
                if(res.confirm){
                    uni.removeStorageSync('openId')
                    uni.removeStorageSync('token')
                    uni.navigateTo({
                        url: '/pages/login/index'
                    })
                }
            }
        })
    }
    
    onShow(() => {
        userInfo.value = JSON.parse(uni.getStorageSync('userInfo'))
    })
    
    onMounted(() => {
        getTopHeight()
    })
</script>
 
<style lang="scss" scoped>
    .content{
        padding: 0 32rpx;
        .user{
            height: 100rpx;
            display: flex;
            align-items: center;
            .userImg{
                width: 80rpx;
                height: 80rpx;
                image{
                    width: 100%;
                    height: 100%;
                    border-radius: 50%;
                }
            }
            .info{
                margin-left: 30rpx;
                .name{
                    vertical-align: text-bottom;
                }
            }
        }
        .typeList{
            margin-top: 30rpx;
            .typeItem{
                padding: 20rpx 0;
                border-bottom: 1rpx solid #dddddd;
                display: flex;
                justify-content: space-between;
                align-items: center;
            }
        }
        .loginOut{
            margin-top: 200rpx;
            .btn{
                color: $uni-base-color;
                border-color: $uni-base-color;
            }
        }
    }
</style>