Files
laws-sinotruk-client/src/utils/kkFilePreview.js
T

44 lines
1.3 KiB
JavaScript

import Vue from 'vue'
import { USER_INFO } from '../store/mutation-types'
import { Base64 } from 'js-base64'
import md5 from 'md5'
function fillZero (str) {
let realNum
if (str < 10) {
realNum = '0' + str
} else {
realNum = str
}
return realNum
}
export function dealUrl (fileUrl) {
const userInfo = Vue.ls.get(USER_INFO)
// 获取当前时间
const date = new Date()
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
const time = `${year}${fillZero(month)}${fillZero(day)}${fillZero(hour)}${fillZero(minute)}${fillZero(second)}`
// 水印内容
const watermarkTxt = `${userInfo.username} ${userInfo.realname} ${time}`
// 客户环境预览需要加的加密参数
const watermarkSign = md5(watermarkTxt + 'cnhtc')
// 路径增加时间戳
const timestamp = new Date().getTime()
fileUrl += `&time=${timestamp}`
return `${window._CONFIG.onlinePreviewDomainURL}?url=${encodeURIComponent(Base64.encode(fileUrl))}&watermarkTxt=${encodeURIComponent(watermarkTxt)}&watermarkSign=${watermarkSign}`
}
/**
* kkFile预览文件并添加水印
* @param fileUrl
*/
export const kkFilePreview = (fileUrl) => {
window.open(dealUrl(fileUrl))
}