MrShi
2025-09-12 f222a7fbe8f5a9f279467f986a1e4ca9a86217e6
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<template>
    <view class="setup">
        <div class="setup-tx">
            <view class="setup-tx-image">
                <image v-if="fullCoverImage && fullCoverImage !=''" :src="fullCoverImage" mode="widthFix"></image>
                <image v-else src="/static/icon/img@2x.png" mode="widthFix"></image>
            </view>
            <button open-type="chooseAvatar"  @chooseavatar="onChooseAvatar" class="setup-tx-btn">更换头像</button>
        </div>
        <view class="setup-list">
            <view class="setup-list-item">
                <view class="label">昵称</view>
                <view class="val">
                    <input type="text"  v-model='nickName' placeholder="请输入" />
                </view>
            </view>
            <view class="setup-list-item">
                <view class="label">真实姓名</view>
                <view class="val">
                    <input type="text" v-model='name' placeholder="请输入" />
                </view>
            </view>
            <view class="setup-list-item">
                <view class="label">绑定手机号</view>
                <view class="val">
                     {{userInfo.telephone}}
                </view>
            </view>
        </view>
        <view class="setup-sub" @click="updateMemberInfo">保存</view>
    </view>
</template>
 
<script>
    import { mapState } from 'vuex'
    export default {
        computed: {
            ...mapState(['navHeight', 'statusbarHeight','userInfo','token','openid'])
        },
        data() {
            return {
                name:null,
                coverImage:null,
                nickName:null,
                fullCoverImage:null
            };
        },
        onShow(options){ 
            console.log(this.userInfo)
            this.coverImage = this.userInfo.coverImage
            this.nickName = this.userInfo.nickName
            this.fullCoverImage = this.userInfo.fullCoverImage
            this.name = this.userInfo.name
        },
        methods: {
            onChooseAvatar(e){
             const { detail } = e
             var that =this
              uni.compressImage({
                src: detail.avatarUrl,
                quality: 80,
                success: res => {
                  that.uploadFile(res.tempFilePath);
                }
              })
            },
            uploadFile(fileUrl) {
              var that = this
              console.log(fileUrl, 'fileUrl')
              uni.uploadFile({
                    url: this.$baseUrl + 'web/public/upload',
                    filePath: fileUrl,
                    name: 'file',
                    formData: {
                        'folder': 'member'
                    },
                    success:(data)=>{
                         const res = JSON.parse(data.data)
                         that.coverImage = res.data.imgaddr
                         that.fullCoverImage = res.data.url
                         that.updateMemberInfo()
                    },
                    fail:(e)=>{
                        uni.showToast({
                            title: '上传失败',
                            duration: 2000,
                            icon: "none"
                        });
                    }
              }) 
            },
            updateMemberInfo() {
              if((!this.name ||this.name.trim() =='' )
                  &&(!this.nickName ||this.nickName.trim() =='')
                  &&(!this.coverImage ||this.coverImage.trim() =='')){
                  uni.showToast({
                        title: '对不起,请按要求填写信息!',
                        icon: "none",
                        duration: 2000
                  });
                  return
              }
              var that = this
              this.$u.api.editMemberInfo({
                    name:that.name,
                    nickName:that.nickName,
                    coverImage:that.coverImage,
               }).then(res =>{
                    that.userInfo.name = this.name
                    that.userInfo.nickName = this.nickName
                    that.userInfo.coverImage = this.coverImage
                    that.userInfo.fullCoverImage = this.fullCoverImage
                    uni.showToast({
                        title: '更新成功',
                        icon: "none",
                        duration: 2000
                     });
               })
            } 
        }
    }
</script>
 
<style lang="scss" scoped>
    .setup {
        width: 100%;
        padding: 0 40rpx;
        box-sizing: border-box;
        .setup-tx {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            margin-top: 64rpx;
            .setup-tx-image {
                width: 160rpx;
                height: 160rpx;
                border-radius: 50%;
                display: flex;
                align-items: center;
                justify-content: center;
                overflow: hidden;
                background: rgba(91,190,56,0.3);
                border: 2rpx solid rgba(91,190,56,0.35);
                image {
                    width: 100%;
                }
            }
            .setup-tx-btn {
                width: 176rpx;
                height: 48rpx;
                line-height: 48rpx;
                text-align: center;
                border-radius: 32rpx;
                font-weight: 400;
                font-size: 26rpx;
                color: #5BBE38;
                border: 1rpx solid #5BBE38;
                background-color: #ffffff;
                margin-top: 24rpx;
            }
        }
        .setup-list {
            width: 100%;
            display: flex;
            flex-direction: column;
            margin-top: 40rpx;
            .setup-list-item {
                width: 100%;
                height: 112rpx;
                display: flex;
                align-items: center;
                justify-content: space-between;
                border-bottom: 1rpx solid #E5E5E5;
                .label {
                    font-weight: 400;
                    font-size: 30rpx;
                    color: #222222;
                    flex-shrink: 0;
                    width: 150rpx;
                    margin-right: 30rpx;
                }
                .val {
                    flex: 1;
                    height: 100%;
                    display: flex;
                    align-items: center;
                    justify-content: flex-end;
                    input {
                        width: 100%;
                        height: 100%;
                        font-weight: 400;
                        font-size: 28rpx;
                        color: #222222;
                        text-align: right;
                    }
                    button {
                        width: 148rpx;
                        height: 60rpx;
                        line-height: 60rpx;
                        text-align: center;
                        background: #5BBE38;
                        border-radius: 30rpx;
                        font-weight: 500;
                        font-size: 28rpx;
                        color: #FFFFFF;
                        margin: 0 !important;
                    }
                }
            }
        }
        .setup-sub {
            width: 100%;
            height: 88rpx;
            line-height: 88rpx;
            text-align: center;
            box-shadow: 0rpx 8rpx 12rpx 0rpx rgba(91,190,56,0.16);
            border-radius: 44rpx;
            font-weight: 500;
            font-size: 32rpx;
            color: white;
            background-color: #15CF52;
            margin-top: 80rpx;
            border: 1rpx solid #15CF52;
        }
    }
</style>