双重预防项目-国泰新华二开定制版
SZH
2022-08-20 f9f0687195e0fe349185437d22c495d74c8d4a20
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
(function ($) {
    $.extend({
        //thatFile
        //thatUrl
        fileinput_package: {
            //新增页面
            add: function (thatFile, thatUrl, callback) {
                //图片上传
                var params = {
                    'theme': 'explorer-fas',
                    'uploadUrl': ctx + 'common/defUpload',
                    'deleteUrl': '#',
                    showUpload: false,
                    overwriteInitial: false,
                    initialPreviewAsData: true,
                    language: 'zh',
                    uploadAsync: true,
                    dropZoneEnabled: false,
                    maxFileCount: 1,
                    autoReplace: true,
                    resizeImage: false,
                    showCaption: false,
                    showPreview: true,
                    browseClass: "btn btn-primary btn-lg",
                    allowedFileExtensions: ['jpg', 'png', 'gif', 'jpeg', 'bmp'],
                    previewFileIcon: ""
                };
                var lastThatFile =
                    $(thatFile).fileinput(params)
                        .on("filebatchselected", function (event, data) {
                            //选择即上传
                            $(thatFile).fileinput("upload");
                        })
                        .on('fileuploaded', function (event, data, previewId, index) {
                            //处理上传后数据,上传后插件会将现有上传文件previewId重排,此时需对现有地址数据做重排处理
                            let count = 0;
                            let imgUrl = {};
                            if ($(thatUrl).val()) {
                                let temp = JSON.parse($(thatUrl).val());
                                for(let key in temp){
                                    imgUrl[previewId.substr(0, previewId.length - 1) + count] = temp[key];
                                    count++;
                                }
                            };
                            previewId = previewId.substr(0, previewId.length - 1) + count;
                            imgUrl[previewId] = data.response.url;
                            $(thatUrl).val(JSON.stringify(imgUrl));
                        })
                        .on('filesuccessremove', function (event, previewId) {
                            //点击缩略图中删除按钮触发此事件
                            var imgUrl = JSON.parse($(thatUrl).val());
                            delete imgUrl[previewId];
                            $(thatUrl).val(JSON.stringify(imgUrl));
                        })
                        .on('filecleared', function (event) {
                            //点击左下角移除或者右上角×号按钮触发此事件
                            $(thatUrl).val("");
                        });
            },
            //编辑页面
            edit: function (thatFile, thatUrl, callback) {
                //处理预览数据
                var urlObj = $(thatUrl).val();
                var previewUrl = [];
                var config = [];
                var previewKeys = [];
                if (urlObj) {
                    urlObj = JSON.parse(urlObj);
                    for (var key in urlObj) {
                        previewUrl.push(urlObj[key]);
                        var tem = {};
                        tem['key'] = key;
                        config.push(tem);
                        previewKeys.push(key);
                    }
                }
                ;
 
                //图片上传
                var params = {
                    'theme': 'explorer-fas',
                    'uploadUrl': ctx + 'common/defUpload',
                    'deleteUrl': '#',
                    showUpload: false,
                    overwriteInitial: false,
                    initialPreviewAsData: true,
                    language: 'zh',
                    uploadAsync: true,
                    dropZoneEnabled: false,
                    maxFileCount: 1,
                    resizeImage: false,
                    showCaption: false,
                    showPreview: true,
                    browseClass: "btn btn-primary btn-lg",
                    allowedFileExtensions: ['jpg', 'png', 'gif', 'jpeg', 'bmp'],
                    previewFileIcon: "",
                    initialPreviewConfig: config,
                    initialPreview: previewUrl
                };
                var lastThatFile =
                    $(thatFile).fileinput(params)
                        .on("filebatchselected", function (event, data) {
                            //选择即上传
                            $(thatFile).fileinput("upload");
                        })
                        .on('fileuploaded', function (event, data, previewId, index) {
                            //处理上传后数据,上传后插件会将现有上传文件previewId重排,,此时需对现有地址数据做重排处理,此时有预览数据,预览数据不做处理
                            let count = 0;
                            let imgUrl = {};
                            if ($(thatUrl).val()) {
                                let temp = JSON.parse($(thatUrl).val());
                                for(let key in temp){
                                    if (previewKeys.indexOf(key) == -1){
                                        imgUrl[previewId.substr(0, previewId.length - 1) + count] = temp[key];
                                        count++;
                                    }else {
                                        imgUrl[key] = temp[key];
                                    }
                                }
                            };
                            previewId = previewId.substr(0, previewId.length - 1) + count;
                            imgUrl[previewId] = data.response.url;
                            $(thatUrl).val(JSON.stringify(imgUrl));
                        })
                        .on('filesuccessremove', function (event, previewId) {
                            //点击缩略图中删除按钮触发此事件(此事件是新上传图片缩略图触发)
                            var imgUrl = JSON.parse($(thatUrl).val());
                            delete imgUrl[previewId];
                            $(thatUrl).val(JSON.stringify(imgUrl));
                        })
                        .on('filedeleted', function (event, key) {
                            //点击缩略图中删除按钮触发此事件(此事件是初始化预览图片缩略图触发)
                            var tem = JSON.parse($(thatUrl).val());
                            delete tem[key];
                            let index = previewKeys.indexOf(key);
                            if (index != -1)
                                delete previewKeys[index];
                            $(thatUrl).val(JSON.stringify(tem));
                        })
                        .on('filecleared', function (event) {
                            //点击左下角移除或者右上角×号按钮触发此事件,此时需把初始化预览图片置空
                            $(thatUrl).val("");
                            $(thatFile).fileinput('refresh', {initialPreview: []});
                        });
            },
            //查看页面
            detail: function (thatFile, thatUrl, callback) {
                var urlObj = $(thatUrl).val();
                var previewUrl = [];
                var config = [];
                if (urlObj) {
                    urlObj = JSON.parse(urlObj);
                    for (var key in urlObj) {
                        previewUrl.push(urlObj[key]);
                        var tem = {};
                        tem['key'] = key;
                        config.push(tem)
                    }
                }
                ;
                var lastThatFile =
                    $(thatFile).fileinput({
                        'theme': 'explorer-fas',
                        showUpload: false,
                        overwriteInitial: false,
                        initialPreviewAsData: true,
                        language: 'zh',
                        dropZoneEnabled: false,
                        resizeImage: false,
                        showCaption: false,
                        showPreview: true,
                        showRemove: false,
                        showClose: false,
                        browseClass: "btn btn-primary btn-lg",
                        allowedFileExtensions: ['jpg', 'png', 'gif', 'jpeg', 'bmp'],
                        previewFileIcon: '',
                        initialPreviewConfig: config,
                        initialPreview: previewUrl
                    });
            }
        }
    });
})(jQuery);