1 js
//【文件预览】
function preview(data) {
preViewUtil.preView('preView','/img/common/preview',{fileName:data.url});
}
2 layui -js自定义组件
layui.define(function (exports) {
var layer = layui.layer,
upload = layui.upload,
$ = layui.jquery,
setter = layui.setter,
request = setter.request,
thisName = 'preViewUtil',
utils = {};
/**
* @param data 需要传递的参数Object;例如{name:'123'}
*/
utils.preView = function (id,url, data) {
// 添加token
data.Authorization = layui.data(setter.tableName)[request.tokenName]
var href = url + "?" + $.param(data)
/* $('#'+id).attr('href',href);
document.getElementById(id).click()*/
var enUri = encodeURIComponent(href);
window.open("/start/pdf/web/viewer.html?file="
+ enUri);
}
// 获取URL地址根地址
function getUrlTop() {
var curWwwPath = window.document.location.href;
var pathName = window.document.location.pathname;
var pos = curWwwPath.indexOf(pathName)
var localhostPaht = curWwwPath.substring(0, pos);
return localhostPaht;
}
exports(thisName, utils);
});
3