Ldc
2024-04-07 0652600959e5e3b5796fb6e8da129704ca95347a
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/**
 * 文件上传和修改
 * @author wangting
 * @date 2021-5-11
 */
layui.define(['layer','element','BaseAction'],function(exports){
    var webUtil = $webUtil;
    var Class = function() {
        this.MODELNAME = "BaseFileUploadAction";
        this.moduleKey = "BaseFileUploadAction";
 
        this.getContent = function (id) {
            var that = this;
            that.id = id;
            var html = [
                '<div class="FileUpload" id="FileUpload_', id, ' lay-filter="FileUpload_', id, '" style="display:block; text-align: center"></div>'
            ].join("");
            return html;
        };
 
        this.doAction = function (options) {
            var that = this;
            webUtil.copyConfig(that, that.moduleKey);
            that.id = options.id;
            var paramVOS = {
                url: 'vciFileUploadController/uploadFile',
                backPath: configData.compatibility ? path : configData.fileServicePath,
                method: 'post'
            }
            $.extend(paramVOS, options.paramVOS);
            options.paramVOS = paramVOS;
 
            var baseAction = layui['BaseAction'];
            baseAction.callPreEvent(options, that, function (options) {
                that.doUpload(options, function () {
                    baseAction.callPostEvent(options, that, options.callback);
                });
            });
        };
 
 
        this.doUpload = function (options,callback) {
            var that = this;
            var paramVOS = $webUtil.paramLow(options.paramVOS);
            var selectData = options.dataStore;
 
            if (paramVOS.updatefileflag == true || paramVOS.updatefileflag == "true") {
                if (selectData.length < 1) {
                    $webUtil.showErrorMsg("请选择一条需要修改的数据");
                    return false;
                }
                if (selectData[0].btmname != 'fileobject') {
                    $webUtil.showErrorMsg("修改的数据需是文件对象");
                    return false;
                }
                if (!paramVOS.multi && selectData.length > 1) {
                    $webUtil.showErrorMsg("仅能选择一条数据来操作");
                    return false;
                }
            }
            if (!options.sourceData) {
                $webUtil.showErrorMsg("请选择来源数据");
                return false;
            }
            var filter = "aFileUpload_" + options.id;
            var form = layui.form;
            var content = ['<div id="', filter, '" lay-filter="', filter, '" class="layui-form" style="margin:15px 30px 15px 0;" ></div>'
            ].join('');
            var addSaveIndex = layer.open({
                type: 1,
                title: paramVOS.title ? $webUtil.replaceFreeMarker(paramVOS.title, selectData, options.sourceData[0]) : '上传文件',
                btn: ['开始上传', '关闭'],
                //skin: 'layui-layer-lan',
                content: content,
                area: [paramVOS.width || '800px', paramVOS.height || '500px'],
                closeBtn: 1,
                shade: true,
                shadeClose: true,
                resize: true,
                resizing: function (layero) {
                },
                success: function (layero, layerIndex, classP) {
                    var attachHtml = [
                        '<div class="layui-upload" style="margin-left: 30px;">',
                        '<form id="form_', filter, '" lay-filter="form_', filter, '" class="layui-form" style="margin:15px 30px 0 -80px;" ></form>',
                        '<button id="', filter, '_selectBtn" type="button" class="layui-btn layui-btn-sm layui-btn-normal">选择文件</button>',
                        //'<button id="',filter,'_uploadAction" type="button" class="layui-btn layui-btn-sm" style="margin-left: 15px;">开始上传</button>',
                        '<input type="hidden" name="releaseFileOids">',
                        '<div class="layui-upload-list  layui-table-view">',
                        '<table cellspacing="0" cellpadding="0" border="0" class="layui-table" style="width: 100%;">',
                        '<thead>',
                        '<tr><th>文件名</th><th>大小</th><th>状态</th><th style="width: 90px">操作</th></tr>' +
                        '</thead>',
                        '<tbody id="', filter, '_uploadList"></tbody>',
                        '</table>',
                        '</div>',
                        '</div>'
                    ]
                    $('#' + filter + '').append(attachHtml.join(''))
                    if (configData.controlSecret == true || configData.controlSecret == 'true') {
                        $webUtil.get('webEnumController/getDataEnum', {
                            oid: $webUtil.replaceFreeMarker(options.sourceData.oid, options.sourceData, {}),
                            btmname: (options.sourceData.btmname && $webUtil.replaceFreeMarker(options.sourceData.btmname, options.sourceData, {})) || paramVOS.linktype || ''
                        }, function (result) {
                            if (result.success) {
                                layui.form.addItems('form_' + filter, [{
                                    name: 'secretGrade',
                                    text: '密级',
                                    type: 'combox',
                                    verify: 'number',
                                    defaultValue: 1,
                                    data: result.obj,
                                }], function () {
                                }, {}, {
                                    defaultColumnOneRow: 1
                                });
                            } else {
                                $webUtil.showErrorMsg(result.msg || '获取表单失败');
                            }
 
                        }, function (xhr, error) {
                            $webUtil.showErrorMsg("获取表单出现了错误,可能是文件服务没有启动");
                        }, paramVOS.backpath)
 
                    }
                    var uploadListView = $('#' + filter + '_uploadList');
                    uploadListIns = layui.upload.render({
                        elem: '#' + filter + '_selectBtn'
                        , url: paramVOS.backpath + paramVOS.url
                        , accept: 'file'
                        , multiple: true
                        , auto: false//(layui.device().ie && layui.device().ie < 10)?true:false
                        , data: {}
                        , bindAction: '#' + filter + '_uploadAction'
                        , before: function (obj) {
                            var uploadData = {
                                fileDocClassify: paramVOS.filedocclassify,
                                fileDocClassifyName: paramVOS.filedocclassifyname,
                                ownbizOid: $webUtil.replaceFreeMarker(options.sourceData.oid, options.sourceData, {}),
                                ownBtmname: (options.sourceData.btmname && $webUtil.replaceFreeMarker(options.sourceData.btmname, options.sourceData, {})) || paramVOS.linktype || '',
                                updateFileFlag: paramVOS.updatefileflag || false,
                                effect: paramVOS.effect || true,
                                fileOid: paramVOS.updatefileflag == "true" ? selectData[0].oid : '',
                                name: 'file',
                                checkSameFile: true,
                                secretGrade: -1
                            }
                            if (configData.controlSecret == true || configData.controlSecret == 'true') {
                                uploadData.secretGrade = layui.form.getValues('form_' + filter, true).secretGrade;
                                if (uploadData.secretGrade == '') {
                                    $webUtil.showErrorMsg("请选择密级");
                                    return false;
                                }
                                if (options.sourceData.secretgrade || options.sourceData.secretGrade) {
                                    var selectGrade = options.sourceData.secretgrade || options.sourceData.secretGrade;
                                    selectGrade = parseInt(selectGrade);
                                    if (parseInt(uploadData.secretGrade) > selectGrade) {
                                        $webUtil.showErrorMsg("文件密级不能大于所选数据的密级");
                                        return false;
                                    }
                                }
                            }
                            obj.setData(uploadData)
                            $webUtil.showProgress("文件上传中……");
                        }
                        , choose: function (obj) {
                            var files = this.files = obj.pushFile();//将每次选择的文件追加到文件队列
                            var elemFiles= this.elemFiles = obj.getElemFiles()//针对ie
                            //读取本地文件
                            obj.preview(function (index, file, result) {
                                var tr = $(['<tr id="upload-' + index + '">'
                                    , '<td>' + file.name + '</td>'
                                    , '<td>' + (file.size ? (file.size / 1024).toFixed(1) + 'kb' : '') + '</td>'
                                    , '<td>等待上传</td>'
                                    , '<td>'
                                    , '<a class="layui-btn layui-btn-xs attach-reload layui-hide">重传</a>'
                                    , '<a class="layui-btn layui-btn-xs layui-btn-danger attach-delete">删除</a>'
                                    , '</td>'
                                    , '</tr>'].join(''));
 
                                //单个重传
                                tr.find('.attach-reload').on('click', function () {
                                    obj.upload(index, file);
                                });
 
                                //删除
                                tr.find('.attach-delete').on('click', function () {
                                    delete files[index]; //删除对应的文件
                                    if(layui.device().ie  && layui.device().ie<10){
                                        $('#'+elemFiles[index][0].id).remove()
                                        //elemFiles[index].parent()[0].removeChild(elemFiles[index][0])
                                        delete elemFiles[index];//针对ie
                                    }
 
                                    var oid = tr.attr('oid');
                                    if (oid) {
                                        var val = $('#' + filter + ' [name="releaseFileOids"]').val();
 
                                        val = val.replace(oid, '').replace(',,', ',')
                                        if (val.indexOf(',') == 0) {
                                            val = val.replace(',', '')
                                        }
                                        $('#' + filter + ' [name="releaseFileOids"]').val(val)
                                    }
                                    tr.remove();
                                    uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值,以免删除后出现同名文件不可选
                                    $('.layui-upload-choose').remove();
                                });
 
                                uploadListView.append(tr);
                            });
                        }
                        , done: function (res, index, upload) {
                            if (res.success) { //上传成功
                                var tr = uploadListView.find('tr#upload-' + index)
                                    , tds = tr.children();
                                tds.eq(2).html('<span style="color: #5FB878;">' + (paramVOS.effect == "false" ? '传输完成' : '已生效') + '</span>');
                                tr.attr('oid', res.obj.oid);
                                tds.eq(0).text(res.obj.id);
                                tds.eq(3).find('.attach-reload').addClass('layui-hide').html(''); //清空操作
                                tds.eq(3).find('.attach-delete').addClass('layui-hide')
                                var val = $('#' + filter + ' [name="releaseFileOids"]').val().split(',');
                                if (val[0] == '') {
                                    val[0] = res.obj.oid
                                } else {
                                    val.push(res.obj.oid)
                                }
 
                                $('#' + filter + ' [name="releaseFileOids"]').val(val.join(','))
                                delete this.files[index]; //删除文件队列已经上传成功的文件
                                if(layui.device().ie  && layui.device().ie<10){
                                    $('#'+this.elemFiles[index][0].id).remove()
                                    delete this.elemFiles[index];
                                }
 
                                return;
                            }
                            this.error(index, upload, res.msg);
                        },
                        allDone: function (obj) {
                            if (obj.total == obj.successful) {
                                if (callback) {
                                    callback()
                                }
                                if (options.callback) {
                                    options.callback()
                                }
                                $webUtil.closeProgress();
                                layer.close(addSaveIndex)
                            }
                        }
                        , error: function (index, upload, msg) {
                            var tr = uploadListView.find('tr#upload-' + index)
                                , tds = tr.children();
                            tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                            tds.eq(3).find('.attach-reload').removeClass('layui-hide'); //显示重传
                            $webUtil.showErrorMsg(msg);
                        }
                    });
                },
                yes: function (layero) {
                    if (paramVOS.updatefileflag == "true") {
                        var trs = $('#' + filter + '_uploadList tr');
                        if (trs.length > 1) {
                            $webUtil.showErrorMsg("修改文件只能上传1个文件");
                            return false;
                        }
                    }
                    uploadListIns.upload();
                },
                btn2: function (layero) {
                    if (options.callback) {
                        options.callback()
                    }
                    layer.close(addSaveIndex)
                },
                cancel: function (layero) {
                    if (options.callback) {
                        options.callback()
                    }
                }
            });
        }
 
        this.refresh = function () {
            var that = this;
 
        };
 
        this.destory = function () {
            var that = this;
            var filter = "FileUpload_" + that.id;
            $('#' + filter).remove()
        };
    };
    var cs = new Class();
    exports(cs.MODELNAME,cs);
});