/**
|
* 文件下载
|
* @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"
|
+ "¤tUserId=" + $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);
|
});
|