From d15ee193905ac4515c1e75e107eb7c517234aebc Mon Sep 17 00:00:00 2001 From: yoe Date: Thu, 21 May 2020 18:37:15 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=A2=9E=E5=8A=A0=E6=B0=B4=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 2 +- src/main.js | 2 ++ src/utils/watermark.js | 52 ++++++++++++++++++++++++++++++++ src/views/common/login.vue | 2 +- src/views/layout/main-navbar.vue | 2 +- src/views/layout/main.vue | 2 ++ 6 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 src/utils/watermark.js diff --git a/index.html b/index.html index a64d7f1..5ccdee3 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ - 数字化管理系统 + 企业数字化管理系统 diff --git a/src/main.js b/src/main.js index c77261d..3c4d2a6 100644 --- a/src/main.js +++ b/src/main.js @@ -9,6 +9,7 @@ import { isAuth } from '@/utils' import echarts from 'echarts' import '@/assets/scss/index.scss' import '@/element-ui-theme' +import watermark from '@/utils/watermark' import VCharts from 'v-charts' Vue.use(VCharts) @@ -17,6 +18,7 @@ Vue.use(VueCookie) Vue.config.productionTip = false // 挂载全局 +Vue.prototype.$watermark = watermark // 水印 Vue.prototype.$echarts = echarts // echarts画图 Vue.prototype.isAuth = isAuth // 权限方法 diff --git a/src/utils/watermark.js b/src/utils/watermark.js new file mode 100644 index 0000000..891c2b0 --- /dev/null +++ b/src/utils/watermark.js @@ -0,0 +1,52 @@ +/** + * 水印画布 + */ +const watermark = {} + +const setWatermark = (str) => { + const id = '1.23452384164.123412415' + + if (document.getElementById(id) !== null) { + document.body.removeChild(document.getElementById(id)) + } + + const can = document.createElement('canvas') + can.width = 150 + can.height = 120 + + const cans = can.getContext('2d') + cans.rotate(-20 * Math.PI / 180) + cans.font = '15px Vedana' + cans.fillStyle = 'rgba(0, 0, 0, 0.05)' + cans.textAlign = 'left' + cans.textBaseline = 'Middle' + cans.fillText(str, can.width / 20, can.height) + + const div = document.createElement('div') + div.id = id + div.style.pointerEvents = 'none' + div.style.top = '3px' + div.style.left = '0px' + div.style.position = 'fixed' + div.style.zIndex = '100000' + div.style.width = document.documentElement.clientWidth + 'px' + div.style.height = document.documentElement.clientHeight + 'px' + div.style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat' + document.body.appendChild(div) + return id +} + +// 该方法只允许调用一次 +watermark.set = (str) => { + let id = setWatermark(str) + setInterval(() => { + if (document.getElementById(id) === null) { + id = setWatermark(str) + } + }, 2000) + window.onresize = () => { + setWatermark(str) + } +} + +export default watermark diff --git a/src/views/common/login.vue b/src/views/common/login.vue index 7683459..dbc1dd6 100644 --- a/src/views/common/login.vue +++ b/src/views/common/login.vue @@ -3,7 +3,7 @@
-

数字化管理系统

+

企业数字化管理系统