wangzhibo
4 天以前 10595d8632f959d0954d1939243196f4eed02372
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<template>
    <cl-page>
        <view class="page-set">
            <template v-if="user.info">
                <cl-text value="账号" :margin="[0, 0, 20, 20]" block />
 
                <cl-list :radius="16">
                    <cl-list-item label="头像" :arrow-icon="false">
                        <view class="avatar">
                            <!-- #ifdef MP-WEIXIN -->
                            <button open-type="chooseAvatar" @chooseavatar="uploadAvatar">
                                <cl-avatar round :size="88" :src="user.info.avatarUrl" />
                            </button>
                            <!-- #endif -->
 
                            <!-- #ifndef MP-WEIXIN -->
                            <cl-avatar
                                round
                                :size="88"
                                :src="user.info.avatarUrl"
                                @tap="uploadAvatar()"
                            />
                            <!-- #endif -->
                        </view>
                    </cl-list-item>
                    <cl-list-item label="昵称" @tap="router.push('/pages/user/edit')">
                        <cl-text :value="user.info.nickName" />
                    </cl-list-item>
                    <cl-list-item label="手机号" :arrow-icon="false">
                        <cl-text :value="user.info.phone" />
                    </cl-list-item>
                    <cl-list-item label="ID" :arrow-icon="false" :border="false">
                        <cl-text :value="user.info.id" />
                    </cl-list-item>
                </cl-list>
            </template>
 
            <cl-text value="关于" :margin="[30, 0, 20, 20]" block />
 
            <cl-list :radius="16">
                <cl-list-item
                    :label="`关于${app.info.name}`"
                    @tap="router.push('/pages/user/about')"
                />
 
                <cl-list-item
                    label="用户协议"
                    @tap="
                        router.push({
                            path: '/pages/user/doc',
                            query: {
                                key: 'userAgreement',
                                title: '用户协议',
                            },
                        })
                    "
                />
                <cl-list-item
                    label="隐私政策"
                    @tap="
                        router.push({
                            path: '/pages/user/doc',
                            query: {
                                key: 'privacyPolicy',
                                title: '隐私政策',
                            },
                        })
                    "
                />
            </cl-list>
 
            <cl-text value="反馈" :margin="[30, 0, 20, 20]" block />
 
            <cl-list :radius="16">
                <cl-list-item
                    label="意见反馈"
                    @tap="router.push('/uni_modules/cool-app/pages/feedback/list')"
                />
                <cl-list-item
                    label="投诉举报"
                    @tap="router.push('/uni_modules/cool-app/pages/complain/list')"
                />
            </cl-list>
 
            <cl-list :radius="16">
                <cl-list-item label="切换账号" @tap="router.push('/pages/user/login')" />
                <cl-list-item label="退出登录" :arrow-icon="false" @tap="user.logout()">
                    <cl-icon :size="36" name="exit" />
                </cl-list-item>
            </cl-list>
        </view>
    </cl-page>
</template>
 
<script lang="ts" setup>
import { onReady } from "@dcloudio/uni-app";
import { useApp, useCool, useStore } from "/@/cool";
import { useUi } from "/$/cool-ui";
 
const { router, upload } = useCool();
const { user } = useStore();
const ui = useUi();
const app = useApp();
 
// 上传头像
function uploadAvatar(e?: { detail: { avatarUrl: string } }) {
    function next(path: string) {
        upload({ path }).then((url) => {
            ui.showToast("头像更新成功");
 
            user.update({
                avatarUrl: url,
            });
        });
    }
 
    if (e) {
        next(e.detail.avatarUrl);
    } else {
        uni.chooseImage({
            count: 1,
            success(res) {
                next(res.tempFiles[0].path);
            },
        });
    }
}
 
onReady(() => {
    user.get();
});
</script>
 
<style lang="scss" scoped>
.page-set {
    padding: 20rpx 24rpx;
 
    .avatar {
        padding: 10rpx 0;
        height: 88rpx;
 
        button {
            padding: 0;
            margin: 0;
            line-height: normal;
            background-color: transparent;
 
            &::after {
                border: 0;
            }
        }
    }
}
</style>