田源
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
/**
 * 文件下载
 * @author wangting
 * @date 2021-5-11
 */
layui.define(['layer','element','BaseAction'],function(exports){
    var webUtil = $webUtil;
    var Class = function() {
        this.MODELNAME = "BaseFileDownloadAction";
        this.moduleKey = "BaseFileDownloadAction";
        this.doAction = function (options) {
            var that = this;
            webUtil.copyConfig(that, that.moduleKey);
            that.id = options.id;
            var paramVOS = {
                url: 'vciFileDownloadController/downloadByFileOid',//下载的后台接口
                posturl: 'vciFileDownloadController/downloadByFileOidPost',
                backPath: configData.compatibility ? path : configData.fileServicePath
            }
            $.extend(paramVOS, options.paramVOS);
            options.paramVOS = paramVOS;
 
            var baseAction = layui['BaseAction'];
            baseAction.callPreEvent(options, that, function (options) {
                that.doDOWNLOADFILE(options, function () {
                    baseAction.callPostEvent(options, that, options.callback);
                });
            });
        };
 
 
        this.doDOWNLOADFILE = function (options,callback) {
            var that = this;
            var paramVOS = $webUtil.paramLow(options.paramVOS);
            var selectData = options.dataStore;
            if(selectData.length<1){
                $webUtil.showErrorMsg("请选择需要下载的文件");
                return false;
            }
            var data = {}
            layui.each(paramVOS, function (i, item) {
                if (item && item.constructor === Object) {
                    layui.each(item, function (j, jitem) {
                        data['sourceData["' + i + '"]["' + j + '"]'] = jitem;
                    })
                }
                ;
                if (i == 'url' || i == 'posturl' || i == 'backpath' || i == 'beforeevent' || i == 'afterevent') return;
                data['sourceData["' + i + '"]'] = item;
            });
            var fileOids = [];
            layui.each(selectData, function (i, item) {
                fileOids.push(item.oid)
            });
            data['fileOid'] = fileOids.join(',')
            $webUtil.fileDownloadPost(paramVOS.backpath + paramVOS.posturl, data,callback)
        }
 
        this.PREVIEW = function (oid, param, errorCallback) {
            var that = this;
            //param:{fileOid:rowData.fileOid}
            if (!oid) {
                return false;
            }
            that.checkData(oid, 'vciFileQueryController/previewFileOld', param, function (fileUrl, result, oid) {
                that.preViewDialog(fileUrl, result, oid);
            }, function () {
                if (errorCallback) {
                    errorCallback()
                }
            });
        };
 
        this.checkData = function (oid, url, param, callback, errorCallback) {
            var that = this;
            $webUtil.post(url, param, function (result) {
                if (result.success) {
                    result.obj=$webUtil.paramLow(result.obj)
                    var fileUrl = result.obj.previewsystemurl;
                    that.viewFileData = {//为了iframe获取参数 写为全局变量
                        previewkey: result.obj.previewkey,
                        invalidtime: result.obj.invalidTime,
                        systemkey: result.obj.systemkey
                    };
                    if ($webUtil.isNull(fileUrl)) {
                        //$webUtil.showErrorMsg("服务器端返回的信息不正确,没有预览服务的地址,请联系管理员");
                        if (errorCallback) {
                            errorCallback()
                        }
                        return false;
                    }
                    if ($webUtil.isNull(result.obj.previewkey)) {
                        //    $webUtil.showErrorMsg("服务器端返回的信息不正确,没有预览服务的许可信息,请联系管理员");
                        if (errorCallback) {
                            errorCallback()
                        }
                        return false;
                    }
                    if ($webUtil.isNull(result.obj.invalidtime)) {
                        //    $webUtil.showErrorMsg("服务器端返回的信息不正确,没有预览的许可时间,请联系管理员");
                        if (errorCallback) {
                            errorCallback()
                        }
                        return false;
                    }
                    if ($webUtil.isNull(result.obj.systemkey)) {
                        //$webUtil.showErrorMsg("服务器端返回的信息不正确,没有预览服务的许可码,请联系管理员");
                        if (errorCallback) {
                            errorCallback()
                        }
                        return false;
                    }
                    if (fileUrl.indexOf("?") > -1) {
                        fileUrl = fileUrl + "&";
                    } else {
                        fileUrl = fileUrl + "?";
                    }
                    fileUrl = fileUrl + "fileOids=" + result.obj.fileoids
                        + "&systemKey=" + result.obj.systemkey
                        + "&previewKey=" + result.obj.previewkey
                        + "&invalidTime=" + result.obj.invalidtime
                        + "&reswitch=true"
                        + "&currentUserId=" + $webUtil.getSystemVar($webUtil.systemValueKey.userId)
                        + "&viewType=pdf"
                    ;
                    if (callback) {
                        callback(fileUrl, result, oid);
                    }
                } else if (result.code == "notsupportpreview") {
                    $webUtil.showMsg("您选择的文件不支持预览");
                } else {
                    if (errorCallback) {
                        errorCallback()
                    }
                    $webUtil.showErrorMsg(result.msg);
                }
            });
        };
        this.preViewDialog = function (fileUrl, result, oid) {
            var that = this;
            if ("popup" == result.showType) {
                window.open(fileUrl, $webUtil.uuid(), "location=no,menubar=no,directories=no,toolbar=no,left=0,top=0,width=" + document.body.clientWidth + "px,height=" + document.body.clientHeight + "px");
            } else {
                var windowArea = [];
                if (window.innerWidth) {
                    windowArea = [(window.innerWidth - 50) + "px", (window.innerHeight - 50) + "px"];
                } else {
                    windowArea = [(document.documentElement.clientWidth - 50) + "px", (document.documentElement.clientHeight - 50) + "px"];
                }
                var iframeWidth = windowArea[0].substring(0, windowArea[0].indexOf("px"));
                var iframeHeight = windowArea[1].substring(0, windowArea[1].indexOf("px")) - 50;
                var content = '<iframe id="fileIframe_' + that.id + '" scrolling="auto" allowtransparency="true" frameborder="0" src=' + fileUrl + ' style="height: ' + iframeHeight + 'px;width:' + iframeWidth + 'px;"></iframe>';
                // '<div id="previewinfo_' + that.id + '" class="layui-layout-east" style="display:block;position:absolute;top:0;right:0;margin-top:10px;margin-right:5px;width:450px;max-width:450px;min-width:150px;border:1px solid #e1e1e1"></div>';
 
                layer.open({
                    type: 1,
                    title: '预览文件-请不要刷新当前页面;如果您没有安装PDF软件,请先安装;',
                    content: content,
                    area: windowArea,
                    closeBtn: 1,
                    shade: true,
                    shadeClose: true,
                    resize: false,
                    success: function () {
                        //that.previewPanelInit(oid);
                    },
                    end: function () {
                        that.viewFileData = {};
                    }
                });
            }
        };
    };
    var cs = new Class();
    exports(cs.MODELNAME,cs);
});