当前位置:网站首页>Web watermark
Web watermark
2022-06-11 02:18:00 【Little mushroom lady in brick moving world】
// Outermost div Add Or add... To the part that needs watermark
<div id="mainTable"></div>
import waterMark from '../../common/js/waterMark.js';
export default {
mixins: [waterMark],
mounted() {
this.canvasWMByWMConfig('PASSENGE_FLOW_EPIDEMIC_EN', this, {
selector: '#mainTable',
});
}
}
import apis from '../../api/board';
/* * Set the method set of watermark , According to the need to use * User account name , Display name , Last four digits of mobile phone */
const contentMap = {
isAddUserName: 'userName',
isAddShowName: 'showName',
isAddEmployee: 'mobilePhone',
};
export default {
data() {
return {
userInfo: {
}, // User information
}
},
methods: {
// Get user information interface
async getMyInfoApi() {
try {
const res = await apis.getMyInfo();
return res;
} catch(e) {
console.log(e);
}
},
// Whether there is a watermark configuration interface on this page
async getWatermarkByGroupIdApi(){
let params = {
groupId: this.userInfo.data.groupId || 0
}
try {
const res = await apis.getWatermarkByGroupId(params);
return res;
}catch(e) {
console.log(e);
}
},
/** * * @param {*} key Unique identification of the watermark configuration item * @param {*} vm vue example * @param {*} opt Configuration item * @returns */
async canvasWMByWMConfig(key, vm, opt = {
}) {
this.userInfo = await this.getMyInfoApi(); // Get user information
let watermarkConfigList = await this.getWatermarkByGroupIdApi(); // Whether there is a watermark configuration interface on this page
setTimeout(() => {
canvasWMByWMConfig(key, vm, opt)
}, 100);
const activeItem = watermarkConfigList.find(item => item.watermarkFieldAliasName === key);
if(!activeItem) {
console.log(` This page is not configured with a watermark key=${
key}`);
return;
}
const contentOpt = {
isAddUserName: activeItem.isAddUserName,
isAddShowName: activeItem.isAddShowName,
isAddEmployee: activeItem.isAddEmployee,
};
this.canvasWM(contentOpt, vm, opt);
},
/** * * @param {*} params objec Configuration item * @param {*} vm vue example * @param {*} opt Configuration item */
canvasWM(params, vm, opt = {
}) {
console.log("params, vm, opt = {}",params, vm, opt); //{isAddEmployee: 1, isAddShowName: 1,isAddUserName: 1} VueComponent{...} {selector: '#mainTable',content: 'whh 1233'}
const contentArr = [];
for(let key in params) {
if(params[key]) {
if(key === 'isAddEmployee') {
let mobilePhone = this.userInfo.data[contentMap[key]] || ''; // User information telephone writing
contentArr.push(mobilePhone.slice(-4));
} else {
let str = this.userInfo.data[contentMap[key]] || '';
contentArr.push(str);
}
}
}
opt.content = contentArr.join(' ');
this._canvasWM(opt);
},
/** * canvas Realization watermark Internal methods * @param {*} param0 Configuration item */
_canvasWM({
selector = 'body',
width = '200px',
height = '150px',
textAlign = 'center',
textBaseline = 'middle',
font = '14px Microsoft Yahei',
fillStyle = 'rgba(229, 229, 229, 0.6)',
content = ' Please don't spread it out ',
rotate = '-10',
zIndex = 1000,
} = {
}) {
const container = document.querySelector(selector);
const canvas = document.createElement('canvas');
canvas.setAttribute('width', width);
canvas.setAttribute('height', height);
const ctx = canvas.getContext('2d');
ctx.textAlign = textAlign;
ctx.textBaseline = textBaseline;
ctx.font = font;
ctx.fillStyle = fillStyle;
ctx.rotate((Math.PI / 180) * rotate);
ctx.fillText(content, parseFloat(width) / 2, parseFloat(height) / 2);
const base64Url = canvas.toDataURL();
const __wm = document.querySelector(`${
selector} .__wm`);
const watermarkDiv = __wm || document.createElement('div');
const styleStr = ` position:absolute; top:0; left:0; width:100%; height:100%; z-index:${
zIndex}; pointer-events:none; background-repeat:repeat; background-image:url('${
base64Url}')`;
watermarkDiv.setAttribute('style', styleStr);
watermarkDiv.classList.add('__wm');
if(!__wm){
container.style.position = 'relative';
container.insertBefore(watermarkDiv, container.firstChild);
}
}
}
}
边栏推荐
- Merge sort ()
- 3P5 Industrial Engineering Lecture 1-2: Method of Study
- Knowledge competition of safety production month -- how much do you know about new safety law
- Alibaba cloud Tianchi online programming training camp_ Task arrangement
- CRS-4544 & ORA-09925
- CRS-5017
- Asemi FET 12n65 parameters, 12n65 specifications, 12n65 features
- Oracle tablespaces, users, and authorization to users
- Virtual joystick of QT quick QML instance
- 优化调度(火电、风能、储能)【matlab代码实现】
猜你喜欢

Analysis of common ADB commands

Introduction and practice of QT tcp/udp network protocol (supplementary)

Tencent test development post interview programming questions

力扣刷题篇——哈希表

SAP smartforms text content manual wrap output

InfoQ 极客传媒 15 周年庆征文|容器运行时技术深度剖析

The annual salary of testers in large factories ranges from 300000 to 8K a month. Roast complained that the salary was too low, but he was ridiculed by netizens?

In the past 10 years, from zero foundation testing to test architect, he has made himself successful

Method of using dism command to backup driver in win11 system

Project sorting of Online Exercise System Based on gin and Gorm
随机推荐
2022 high altitude installation, maintenance and removal of simulated examination platform of theoretical question bank
可扩/减容线程池C语言原理讲解及代码实现
378. 有序矩阵中第 K 小的元素
Secret
CRS-5017
[music] playing blue and white porcelain based on MATLAB [including Matlab source code 1873]
Can the soft exam certificate be settled in Shanghai? Many people don't know
[3.delphi common components] 8 dialog box
2022 safety officer-b certificate examination question bank and answers
Find - (block find)
The annual salary of testers in large factories ranges from 300000 to 8K a month. Roast complained that the salary was too low, but he was ridiculed by netizens?
ASEMI场效应管12N65参数,12N65规格书,12N65特征
Software testing interview reply: the technical side is not difficult for me, but the HR side is a hang up
Return function of different return values
What should be paid attention to in PMP registration? Special reminder
Switch case uses enumeration classes to compare
ABAP CDS实现多行字段内容拼接
switch case使用枚举类来比较
NFT Insider #61:Animoca Brands 在 340 项投资中持有 15 亿美元的加密资产
During SSH configuration key login, you need to pay attention to whether the private key is set with a password