一,vue3使用kkFiewView预览及加动态水印的代码
// 预览
function pdfPreviews(record: Recordable) {
const dars = JSON.parse(JSON.stringify(record));
var urlpdf = globSetting.domainUrl + '/sys/common/static/' + dars.filePath;
urlpdf = urlpdf.replace(/\\/g, '/');//反斜杠替换为正斜杠
let base64 = encryptByBase64(urlpdf);//转码为base64
console.log(base64, "base64");
window.open(globSetting.viewUrl + 'onlinePreview?url=' + (base64) + '&watermarkTxt=' + encodeURIComponent(UserName));
}
注:1.UserName 为登录人用户名作为水印
2.encryptByBase64为jeecgboot自带的转码功能下载安装js-base64使用Base64.encode 可以实现开发情况下正常使用发布上线转码提示有问题
二,vue2使用kkFiewView预览及加动态水印的代码
const UserName = this.$store.getters.username
console.log(window._CONFIG, "window._CONFIG");
let rowpath = row.filePath.replace(/\\/g, '/');
var urlpdf = window._CONFIG.onlinePreviewDomainURL + '/' + rowpath
let base = window._CONFIG.onlinePreviewDomainURL + "/onlinePreview?url="
let codename = Base64.encode(urlpdf);
let url = base + codename + '&watermarkTxt=' + encodeURIComponent(UserName)
window.open(url, '_blank')
注:暂时没有找到vue2自带的base64转码解码,下载安装的js-base64可以正常使用
附:下载依赖js-base64
1、安装js-base64:
npm install js-base64 --save-dev
vue2下载失败用yarn add js-base64 --save-dev
2.在使用Base64的组件中引入Base64
import { Base64 } from 'js-base64';
//使用
base64.encode(url)
base64.decode(url)