Lou
2023-12-23 77bb088d2a1bd0092b0fba5ccd24ceccbfe95606
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
<template>
    <view class="">
        <view class="bgc-ff">
            <view class="form-item flex j-c-s-b a-i-c">
                <text class="f-30">头像</text>
                <button class="avatar-wrapper"  open-type="chooseAvatar"   @chooseavatar="chooseAvatar" >
                    <u-avatar   :src="avatar"  size="50"></u-avatar>
                </button>
            </view>
            <view class="form-item flex j-c-s-b a-i-c">
                <text class="f-30">昵称</text>
                <view class="nickname">
                    <input class="nickname-value" type="nickname"  placeholder="请输入昵称"  v-model="info.nick_name"  @blur="getInputValue"  />
                </view>
                
            </view>
        </view>
        <footer-btn text="确定"   @click="submitInfo"  />
    </view>
</template>
 
<script>
    
    import { updateUserInfo } from "@/api/user.js"
    import {
        Base64
    } from '@/utils/base64.js';
    import {
        prodUrl,
        clientId,
        clientSecret
    } from '@/common/setting'
    export default {
        data(){
            return{
                avatar:"",
                info:{
                    avatar:"",
                    nick_name:"",
                    id:""
                },
                header: {},
                uploadConfig: {
                    url: prodUrl + "/blade-resource/oss/endpoint/put-file",
                    header: {},
                },
            }
        },
        onLoad() {
            this.getHeader()
            this.avatar = this.userInfo.avatar;
            this.info.avatar = this.userInfo.avatar;
            this.info.nick_name = this.userInfo.nick_name;
            this.info.id = uni.getStorageSync("userInfo").user_id
            this.info.deptId = uni.getStorageSync("userInfo").dept_id
        },
        methods:{
            
            //获取头部
            getHeader() {
                let accessToken = uni.getStorageSync('accessToken');
                let myHeader = {}
                if (accessToken) {
                    myHeader['Blade-Auth'] = 'bearer ' + accessToken;
                }
                // 客户端认证参数
                myHeader['Authorization'] = 'Basic ' + Base64.encode(clientId + ':' + clientSecret);
                this.uploadConfig.header = myHeader
            },
            
            chooseAvatar(e){
                let {
                    avatarUrl
                } = e.detail
                this.uploadAvatar(avatarUrl)
            },
            
            uploadAvatar(url){
                uni.uploadFile({
                    url:this.uploadConfig.url, 
                    filePath: url,
                    name: 'file',
                    header: this.uploadConfig.header,
                    success:(res)=> {
                        let data = JSON.parse(res.data);
                        console.log(data.data);
                        this.info.avatar = data.data.name;
                        this.avatar = data.data.link;
                    }
                })
            },
            
            getInputValue(e){
                console.log(e);
                this.info.nickname = e.detail.value;
            },
            
            
            submitInfo(){
                updateUserInfo(this.info).then(res=>{
                    if(res.code == 200){
                        uni.showToast({
                            title:res.msg
                        })
                        setTimeout(()=>{
                            uni.navigateBack()
                        },300)
                    }
                })
            }
            
        }
    }
</script>
 
<style lang="scss">
    page{
        background-color:#f5f5f5;
    }
    .form-item{
        padding:30rpx;
        border-bottom:1px solid #f5f5f5;
    }
    .avatar-wrapper{
        border:none;
        background: transparent;
        margin:0;
        padding:0;
    }
    .avatar-wrapper::after{
        border:none;
        margin:0;
    }
    .nickname{
        width:80%;
        .nickname-value{
            width:100%;
            text-align: right;
        }
    }
</style>