zhangxiaoxu123456
2021-12-20 301289e539c417995f95f5cb91fd1f6043bb7cfd
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
<template>
    <u-upload
       ref="upload"
       :action="action"
       :max-size="5 * 1024 * 1024" 
       max-count="1"
       :before-upload="beforeUpload"
       @on-success="onSuccess"
       :custom-btn="true"
       :auto-upload="autoUpload" 
       :show-progress="false"
       :form-data="formData"
       :multiple="false"
       :deletable="false"
       name="img"
       :show-upload-list="true">
       <u-avatar  slot="addBtn" :src="avatar" size="140"></u-avatar>
           <!-- <view  slot="addBtn" class="wrap">
                   <view class="u-avatar-wrap">
                       <image class="u-avatar-demo" v-if="avatar" :src="avatar" mode="aspectFill"></image>
                   </view>
                   <u-button @tap="chooseAvatar">选择图片</u-button> 
               </view> -->
       </u-upload>
</template>
 
<script>
    let _this = {}
    export default {
        name:"oss-upload",
        data() {
            return {
                avatar: require('../../static/img/touxiang.jpg'),
                formData:{},
                action:'http://Shuinigonghui.cn:8099/user/updateImg',
                userId:'',
                autoUpload:true,
                userInfo:'',
            };
        },
        created() {
        },
        mounted() {
            this.userInfo = this.getStore('userInfo')
            this.avatar = this.userInfo.img
            if(this.avatar == '') {
                this.avatar = '../../static/img/touxiang.jpg'
            }
            this.userId = this.userInfo.id
            this.formData.userId=this.userInfo.id
        },
        
        methods: {
            /* 上传前的钩子 */
            beforeUpload(index,list) {
                
                
            },
            onSuccess(data, index, lists, name) {
                this.$refs.upload.remove(0)
                this.avatar = data.obj.img
                this.userInfo.img = data.obj.img;
                // this.setStore("userInfo",data.obj)
                this.$u.toast('修改成功')
                
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .wrap {
        padding: 24rpx;
    }
 
    .u-avatar-wrap {
        overflow: hidden;
        margin-bottom: 20rpx;
    }
 
    /deep/.u-avatar-demo,.u-avatar__img {
        width: 150rpx;
        height: 150rpx;
        border-radius: 100rpx;
    }
    /deep/ .u-list-item{
        width: 150rpx!important;
        height: 150rpx!important;;
        border-radius: 100rpx;
    }
</style>