田源
2024-04-07 2ac55ce0edf4870a29691b56bfad59f4830a11a2
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/**
 * 文档的列表
 * @author xurc
 * @date 2020-10-23
 */
layui.define(['layer','element','form','table','upload','dynamicCondition' ],function(exports){
        var webUtil = $webUtil;
    var Class = function(){
        this.MODELNAME = "platform/fileManage/VciFileList";
        this.moduleKey = "VciFileList";
        this.backPath =  configData.compatibility?path:configData.fileServicePath;
        this.url = {
            // controller:'vciFileDocClassifyController/',
            controller:'vciFileQueryController/',
            dataGrid:'gridFiles',
            upload:'vciFileUploadController/uploadFile',//上传文件
            reviseByFileOid:'vciFileUploadController/uploadFile',//修改文件
            deleteUrl:'vciFileDownloadController/deleteFile',
            downloadByFileOid:'vciFileDownloadController/downloadByFileOid',//下载文件
        };
        this.getContent=function(){
            var that = this;
            var html = "";
            html = [
                '<div class="layui-layout" style="display:block;overflow-y: hidden">',
                    '<div class="layui-layout-border" style="display:block;margin-top:0px; " id="border_',that.id,'">',
                        '<div class="layui-center" style="overflow-y:auto;">',
                            that.getToolbarHtml(),
                            '<table id="table_', that.id , '" lay-filter="',that.id , '" style="overflow-x:auto;"></table>',
                            '<div id="toolbar_column_',that.id ,'" style="display:none;"></div>',
                        '</div>',
                    '</div>',
                '</div>'
            ].join("");
            return html;
        };
        this.getToolbarHtml =function(){
            var that = this;
            var html = [
                '<div layui-filter="toolbar_',that.id,'" class="layui-btn-container layui-buttons">',
                    '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_UPLOAD"><i class="layui-icon layui-icon-upload"></i>上传</button>',
                    '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_EDIT"><i class="layui-icon layui-icon-edit"></i>修改</button>',
                    '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_DEL"><i class="layui-icon layui-icon-delete"></i>删除</button>',
                    '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_DOWNLOADFILE"><i class="layui-icon layui-icon-export"></i>下载</button>',
                    '<button class="layui-btn layui-btn-sm" layui-filter="toolbar_',that.id,'_refresh"><i class="layui-icon layui-icon-refresh"></i>刷新</button>',
                '</div>'
            ].join("");
            return html;
        };
        this.createSearchHtml = function () {
            var that = this;
            webUtil.bindDefultButtonLisenter(that, that.id);
            webUtil.createSearchHtml({id:"编号",name:"名称"} ,$("[layui-filter='toolbar_" + that.id + "']"), "table_" + that.id);
        };
        this.init = function(){
            var that = this;
            webUtil.copyConfig(that,that.moduleKey);
            that.initMainTable();
            that.createSearchHtml();
        };
        this.initMainTable = function (parentFieldName) {
            var that = this;
            var table = layui.table;
            that.checkColumns();
            var tableWidth = $("#border_" + that.id).width();
            var options = {
                elem: '#table_' + that.id,
                id: 'table_' + that.id,
                backPath:that.backPath,
                url: that.url.controller + that.url.dataGrid,
                page: {
                    limit: 20,
                    page: 1
                },
                extraParams: {
                    ownbizOid: 'share',
                    ownbizBtm: 'share'
                  },
                width:tableWidth,
                cols: [that.columns],
                done:function(res,cur,total){
                    if(!that.fristMainLoad ){
                    }else{
                        if(total>0) {
                            table.selectRecord('table_' + that.id, {index:0});
                        }
                    }
                    that.fristMainLoad = true;
                }
            };
            if(parentFieldName){
                options.treeConfig = {
                    treepid:parentFieldName,
                    treeid:'id',
                    showField:'name'
                };
            }
            table.render(options);
        };
        this.checkColumns = function(){
            var that = this;
            var table = layui.table;
            if(that.columns==null || that.columns.length==0){
                that.columns = [table.getIndexColumn(),table.getCheckColumn(),
                    {
                        field:'name',
                        title:'文件名称',
                        width:250
                    },{
                        field:'fileSize',
                        title:'大小',
                        width:80,
                        templet:function(d){
                            if(!d.fileSize || d.fileSize == null || d.fileSize*1 == 0 || isNaN(d.fileSize*1) ){
                                return "未知大小";
                            }else{
                                //原始大小是B
                                var filesize = d.fileSize*1;
                                if(filesize>1024*1024*1024*1024){
                                    return parseInt(filesize/(1024*1024*1024*1024)) + "TB";
                                }else if(filesize> 1024*1024*1024){
                                    return parseInt(filesize/(1024*1024*1024)) + "GB";
                                }else if(filesize> 1024*1024){
                                    return parseInt(filesize/(1024*1024)) + "MB";
                                }else if(filesize> 1024){
                                    return parseInt(filesize/1024) + "KB";
                                }else {
                                    return filesize + "B";
                                }
                            }
                        }
                    },{
                        field:'secretGradeText',
                        title:'密级',
                        width:60
                    },{
                        field:'fileDocClassifyName',
                        title:'文档类型',
                        width:130
                    },{
                        field:'creator',
                        title:'上传人/时间',
                        width:210,
                        templet:function(d){
                            return d.creator + "(" + $webUtil.formateDateTimeNoSecond(d.createTime) + ")";
                        }
                    },{
                        field:'downloadCount',
                        title:'下载数量',
                        width:90
                    }];
            }
        };
 
        this.getFormItems = function(onlyShow) {
            var that = this;
            var table = layui.table;
            return [
                {
                    field:'name',
                    title:'文件名称',
                    required: true,
                    type: 'text',
                    readOnly:onlyShow
                },{
                    field: 'secretGrade',
                    title: '密级',
                    required: true,
                    readOnly:onlyShow,
                    type:'combox',
                    data:[{"key":"10","value":"内部"},{"key":"20","value":"一般"},{"key":"30","value":"重要"}]
                }];
        };
 
        this.UPLOAD = function(){
            var that = this;
            that.uploadOrEdit(true);
        };
 
        this.EDIT = function(){
            var that = this;
            var selectData  = layui.table.checkStatus("table_" + that.id).data[0];
            if(selectData == undefined) {
                webUtil.showErrorMsg('请选择一条数据!');
                return false;
            }
            that.uploadOrEdit(false,selectData.oid);
        };
 
        this.uploadOrEdit = function(add,fileoid){
            var that = this;
            var form = layui.form;
            var filter ='upload_form'+that.id;
            var uploadIndex = layer.open({
                type:1,
                title: add ? '上传文件(最大3G)' : '修改文件(最大3G)',
                skin:'layui-layer-lan',
                content:'<form id="form_' + filter + '" lay-filter="' + filter + '" class="layui-form" style="margin-top:55px" enctype="multipart/form-data"></form>',
                area:['350px','200px'],
                closeBtn:2,
                shade:true,
                shadeClose:true,
                resize: false,
                success:function(layero){
                    form.addItems(filter,[{
                        field:'ownBtmname',
                        title:'ownBtmname',
                        hidden:true
                    },{
                        field:'ownbizOid',
                        title:'ownbizOid',
                        hidden:true
                    },{
                        field:'fileDocClassify',
                        title:'文件类型',
                        hidden:true
                    },{
                        field:'fileDocClassifyName',
                        title:'文件类型名称',
                        hidden:true
                    }],
                    function(){
                       form.setValues({
                            ownBtmname: "share",
                            ownbizOid: "share",
                            fileDocClassify: "ADMIN_SHARE",
                            fileDocClassifyName: "管理员共享文件"
                        },filter);
                        if ($("#button_" + filter)) {
                            $("#button_" + filter).remove();
                        }
                        if($("#button_"+filter).length <= 0) {
                            $("#form_" + filter).append('<button type="button" class="layui-btn" id="button_' + filter + '" style="margin-left:100px"><i class="layui-icon">&#xe67c;</i>选择文件后自动上传</button>');
                        }
                        var upload = layui.upload;
                        //执行实例
                        var uploadForm = upload.render({
                            elem: '#button_' + filter //绑定元素
                            ,accept:'file'
                            ,auto:true
                            ,url: that.backPath + that.url.upload//上传接口
                            ,before:function(obj){
                                if(form.validata(filter)){
                                    var values = form.getValues(filter);
                                    if(!add) {
                                        values.fileOid = fileoid;
                                        values.oid = fileoid;
                                        values.updateFileFlag = true;
                                    }
                                    obj.setData(values);
                                    $webUtil.showProgress("文件上传中……");
                                    return true;
                                }else{
                                    $webUtil.showErrorMsg("请先输入内容后再选择文件");
                                    return false;
                                }
                            }  
                            ,done: function(result){
                                if(result.success){
                                   layer.close(uploadIndex);
                                    $webUtil.showMsg(add ? "文件上传成功" : "文件修改成功");
                                    that.refresh();
                                    $webUtil.closeProgress();
                                }else{
                                    $webUtil.showErrorMsg(result.msg);
                                    $webUtil.closeProgress();
                                }
                            }
                            ,error: function(){
                              //请求异常回调
                                $webUtil.showErrorMsg("上传文件出现了异常");
                            }
                        });
                    }
                    ,{},{
                        defaultColumnOneRow:1
                    });
                }
            });
        };
 
        this.DEL = function(){
            var that = this;
            var oid = webUtil.getOidFromGrid("table_" +that.id,true,true);
            if(!oid){
                return false;
            }
            var ts= webUtil.getOidFromGrid("table_" +that.id,false,false,"ts");
            webUtil.showConfirmMsg("是否删除这条数据?如果被引用将不能被删除!",function () {
                webUtil.deleteRequest(that.url.deleteUrl,{fileOids:oid,ts:ts},function(result){
                    if(result.success){
                        webUtil.showMsgFromResult(result,"删除成功");
                        that.refresh();
                    }else{
                        webUtil.showErrorMsg(result.msg);
                    }
                },function(xhr,err){
                    webUtil.showErrorMsg("请求服务出现了错误,可能服务器未开启");
                },that.backPath);
            });
        };
 
        this.DOWNLOADFILE = function(thisButtonPoint){
            //下载按钮
            var that = this;
            var selectData  = layui.table.checkStatus("table_" + that.id).data[0];
            if(selectData == undefined) {
                webUtil.showErrorMsg('请选择数据!');
                return false;
            }
            that.downloadFileByOid(selectData.oid);
        };
 
        this.downloadFileByOid =function(oid){
            var that = this;
            //下载文件
            var iframeId = MD5(oid + $webUtil.getSystemVar($webUtil.systemValueKey.userOid));
            $webUtil.fileDownload(that.backPath + that.url.downloadByFileOid + "?fileOid=" + oid +"&downloadUUID=" + iframeId);
        };
 
        this.refresh = function () {
            var that = this;
            var that = this;
            layui.table.reload("table_" + that.id);
        };
    };
    var cs = new Class();
    exports(cs.MODELNAME,cs);
});