新增水印

This commit is contained in:
zouzhibing 2022-06-10 17:40:15 +08:00
parent 0e2da2d401
commit 5eb7aba333
6 changed files with 227 additions and 6 deletions

View File

@ -1,5 +1,5 @@
{
"name": "ad",
"name": "vue-admin-perfect",
"version": "0.1.0",
"private": true,
"scripts": {

View File

@ -54,6 +54,12 @@ const othersRouter = {
name: 'qrcode',
meta: { title: '生成二维码' }
},
// {
// path: 'water-marker',
// component: () => import('@/views/other/water-marker.vue'),
// name: 'water-marker',
// meta: { title: '生成水印' }
// },
{
path: 'right-menu',
component: () => import('@/views/other/right-menu.vue'),

View File

@ -0,0 +1,40 @@
export const cityIconData = [
{
adcode: 650000,
name: "新疆维吾尔自治区",
value:[88.999903,43.607078]
},{
adcode: 150000,
name: "内蒙古自治区",
value:[119.24787,42.205741]
},
,{
adcode: 150000,
name: "内蒙古自治区",
value:[110.627161,41.16628]
},
{
adcode: 540000,
name: "西藏自治区",
value:[89.483714,30.251951]
},
{
adcode: 630000,
name: "青海省",
value:[102.064693,37.084008]
},
{
adcode: 530000,
name: "云南省",
value:[102.187665,25.083688]
},
{
adcode: 610000,
name: "陕西省",
value:[109.20663,35.018625]
},
]

View File

@ -1,4 +1,3 @@
<template>
<div :id="id" :class="className" :style="{height:height,width:width}" />
</template>
@ -7,7 +6,8 @@ import { geoJson } from './get.js'
import * as echarts from 'echarts'
import { EChartsType } from 'echarts/core'
import { onMounted } from 'vue'
import {cityIconData} from '../js/data.js'
import logo from '@/assets/logo.png'
const props = defineProps({
className: {
type: String,
@ -132,6 +132,12 @@ var convertToLineData = function (data, gps) {
}
const options = {
tooltip:{
trigger: 'item',
formatter(val){
// console.log('val==========',val)
}
},
backgroundColor: '#001540',
geo: {
show: true,
@ -194,6 +200,7 @@ const options = {
}
}
},
roam: true,
itemStyle: {
normal: {
@ -258,7 +265,41 @@ const options = {
}
},
data: convertToLineData(mapData, geoGpsMap)
}
},
{
type:'scatter',
zlevel: 16,
coordinateSystem: 'geo',
symbolSize:30,
symbol:`image://${logo}`,
data:cityIconData,
rippleEffect: {
period: 4, brushType: 'stroke', scale: 4
},
tooltip:{
trigger:'item',
padding:0,
borderColor:'black',
background:'rgba(0,0,0,0.7)',
textStyle: {
fontSize:20
},
formatter(val){
console.log('val=======',val)
let tipHtml = `
<div class="m-info" style=" opacity: 0.95;background: rgba(25,27,29,1);" >
<div class="title" style="padding-left: 12px;
padding-top: 10px;
padding-bottom: 10px;
background: rgba(25,27,29,1);font-size: 20px;color: white;padding-right: 20px">${val.name}</div>
<!-- <div class="content" style=" padding: 12px; background: rgba(0,2,4,1);">-->
<!-- <div style=" font-size: 22px; color: #ff0000;">258944</div>-->
<!-- </div>-->
</div>`
return tipHtml
}
}
},
]
}
let chart:EChartsType

View File

@ -1,8 +1,8 @@
<template>
<div class="echarts-map">
<el-card class="info">Echarts 实现飞线图地图增加图标高亮</el-card>
<migration-charts height="100%" width="100%" id="migration"/>
</div>
</template>
<script setup lang="ts">
@ -10,8 +10,19 @@ import MigrationCharts from './components/migration/index.vue'
</script>
<style>
<style lang="scss" scoped>
.echarts-map{
height: calc(100vh - 93px);
position: relative;
.info{
position: absolute;
left: 0;
width: 100%;
font-weight: bold;
z-index: 999;
}
::v-deep(.el-card){
border-radius: 0;
}
}
</style>

View File

@ -0,0 +1,123 @@
<template>
<div class="m-water-marker"></div>
</template>
<script lang="ts" setup>
import { nextTick, onMounted } from 'vue'
function watermark (options) {
const {
container = document.body, //
width = '100', // canvas
height = '100', // canvas
textAlign = 'left', //
textBaseline = 'bottom', // 线
font = '16px Microsoft Yahei', //
fillStyle = '#000', //
content = '内部文档,请勿外传', //
globalAlpha = 0.1, //
rotate = 16, //
zIndex = 1000, //
} = options;
let canvas = document.createElement('canvas');
canvas.setAttribute('width', width);
canvas.setAttribute('height', height);
let ctx = canvas.getContext('2d'); // canvas2d
ctx.globalAlpha = globalAlpha;
ctx.textAlign = textAlign;
ctx.textBaseline = textBaseline;
ctx.font = font;
ctx.fillStyle = fillStyle;
ctx.rotate((Math.PI * rotate) / 180);
ctx.fillText(content, 50, 50);
const base64Url = canvas.toDataURL(); // data URI
const __wm = document.querySelector('.__wm');//
const watermarkDiv = __wm || document.createElement("div");
const styleStr = `
position:absolute;
top:0px;
left:0px;
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'); // __wm
document.body.style.position = 'relative';
if (!__wm) {
document.body.appendChild(watermarkDiv); //
}
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
// API
if (MutationObserver) {
const args = arguments[0];
let mo = new MutationObserver(function () {
const __wm = document.querySelector('.__wm');
// __wm
if ((__wm && __wm.getAttribute('style') !== styleStr) || !__wm || document.body.style.position !== 'relative') {
//
mo.disconnect();
mo = null;
watermark(args);
}
});
mo.observe(document.body, {
attributes: true, //
subtree: true, //
childList: true, //
})
}
}
onMounted(()=>{
nextTick(()=>{
const canvas = document.createElement('canvas')
const width = 100
const height = 100
canvas.width = width
canvas.height = height
const context = canvas.getContext('2d')
context.font = "normal small-caps lighter 16px sans-serif";
context.fillStyle = "#666";
context.textAlign = "center";
context.textBaseline = "Middle";
context.rotate(-10 * Math.PI / 140);
context.fillText('content', parseFloat(width) / 2, parseFloat(height) / 2);
context.fillText('content', 60, 100);
var base64Url = canvas.toDataURL();
const watermarkDiv = document.getElementsByClassName('m-water-marker')[0]
watermarkDiv.style.backgroundAttachment = "fixed";
watermarkDiv.style.backgroundPosition = "center";
watermarkDiv.style.backgroundImage = "url(" + canvas.toDataURL("image/png") + ")";
// const options = {
// container : document.body, //
// width : '100', // canvas
// height : '100', // canvas
// textAlign : 'left', //
// textBaseline : 'bottom', // 线
// font : '16px Microsoft Yahei', //
// fillStyle : '#000', //
// content : '', //
// globalAlpha : 0.1, //
// rotate : 16, //
// zIndex : 1000, //
// }
watermark(options)
})
})
</script>
<style>
.m-water-marker{
width: 1000px;
height: 500px;
}
</style>