wuxw
2020-01-14 69e2baf5518079bfc16cfadc2fb29842fb3de85d
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
(function (vc) {
 
    var photoUrl = '/callComponent/download/getFile/file';
 
    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            uploadImageInfo: {
                photos: [],
            }
        },
        watch: {
            uploadImageInfo: {
                deep: true,
                handler: function () {
                    vc.emit($props.callBackListener, $props.callBackFunction, this.uploadImageInfo.photos);
                }
            }
        },
        _initMethod: function () {
 
        },
        _initEvent: function () {
            vc.on('uploadImage', 'openAddApplicationKeyModal', function () {
 
            });
            vc.on('uploadImage', 'clearImage', function () {
                this.uploadImageInfo = {
                    photos: []
                }
            });
 
            vc.on('uploadImage', 'notifyPhotos', function (_photos) {
                this.uploadImageInfo = {
                    photos: []
                };
                _photos.forEach(function (_photo) {
                    //?objId=772019092507000013&communityId=7020181217000001&fileTypeCd=10000
                    vc.urlToBase64(photoUrl + "?fileId=" + _photo + "&communityId=" + vc.getCurrentCommunity().communityId + "&time=" + new Date(), function (_base64Data) {
                        this.uploadImageInfo.photos.push(_base64Data);
                    })
                });
            });
 
        },
        methods: {
            _uploadPhoto: function (event) {
                $("#uploadImage").trigger("click")
            },
            _choosePhoto: function (event) {
                var photoFiles = event.target.files;
                if (photoFiles && photoFiles.length > 0) {
                    // 获取目前上传的文件
                    var file = photoFiles[0];// 文件大小校验的动作
                    if (file.size > 1024 * 1024 * 1) {
                        vc.toast("图片大小不能超过 2MB!")
                        return false;
                    }
                    var reader = new FileReader(); //新建FileReader对象
                    reader.readAsDataURL(file); //读取为base64
                    reader.onloadend = function (e) {
                        this.uploadImageInfo.photos.push(reader.result);
                    }
                }
                event.target.value = null;
            },
            _removeImage: function (_photo) {
                var _tmpPhotos = this.uploadImageInfo.photos;
                this.uploadImageInfo.photos = [];
                for (var _photoIndex = 0; _photoIndex < _tmpPhotos.length; _photoIndex++) {
                    if (_tmpPhotos[_photoIndex] != _photo) {
                        this.uploadImageInfo.photos.push(_tmpPhotos[_photoIndex]);
                    }
                }
            }
        }
    });
 
})(window.vc);