Browse Source

水印逻辑修改

李文 4 years ago
parent
commit
6b840b5dc2
3 changed files with 56 additions and 39 deletions
  1. 42 0
      src/mock/modules/sys-user.js
  2. 10 38
      src/utils/shuiyin.js
  3. 4 1
      src/views/main/main-navbar-user.vue

+ 42 - 0
src/mock/modules/sys-user.js

@@ -49,6 +49,48 @@ export function info () {
   }
 }
 
+// 水印信息
+export function shuiyin () {
+  return {
+    // isOpen: false,
+    url: '/idaas/sso/user/watermark/info',
+    type: 'get',
+    data: {
+      'msg': 'success',
+      'code': 0,
+      'data': {
+        'currentTime': '2021-02-07 17:25:33',
+        'username': 'testuser',
+        'ip': '127.0.0.1'
+      }
+    }
+
+  }
+}
+
+// 通知公告和待办任务数量
+export function tzgg () {
+  return {
+    // isOpen: false,
+    url: '/csb/user/messageNewsCount/new',
+    type: 'get',
+    data: {
+      'msg': 'success',
+      'code': 0,
+      'data': [
+        {
+          'type': 'news',
+          'count': 0
+        },
+        {
+          'type': 'message',
+          'count': 0
+        }
+      ]
+    }
+  }
+}
+
 // 修改密码
 export function updatePassword () {
   return {

+ 10 - 38
src/utils/shuiyin.js

@@ -4,6 +4,9 @@ export default function (strArr) {
   // if (str.length > 16) {
   //   cpyName = str.substring(0, 16)
   // }
+  if (window.$('.shuiyincanvas')[0]) {
+    window.$('.shuiyincanvas')[0].remove()
+  }
   let win = window.$(window)
   let winW = win.width()
   let winH = win.height()
@@ -11,54 +14,25 @@ export default function (strArr) {
   let boxH = 200
   let boxWL = Math.ceil(winW / boxW)
   let boxHL = Math.ceil(winH / boxH)
-  let canvas = document.createElement('canvas')
+  let canvas = window.$('<canvas class="shuiyincanvas"></canvas>')
   let report = window.$('body')
   report.append(canvas)
-  console.log(winW, winH)
-  window.$(canvas).css({
+  canvas.css({
     zIndex: '999',
     position: 'fixed',
     top: 0,
     left: 0,
     'pointer-events': 'none'
   })
-  canvas.width = winW
-  canvas.height = winH
-  let ctx = canvas.getContext('2d')
-  // ctx.translate(0, rectCenterPoint.y)
-  // ctx.rotate(45 * Math.PI / 180)
+  canvas[0].width = winW
+  canvas[0].height = winH
+  let ctx = canvas[0].getContext('2d')
   ctx.globalAlpha = 0.3
-  ctx.fillStyle = '#fff'
+  ctx.fillStyle = '#000'
   ctx.textAlign = 'left'
   ctx.textBaseline = 'top'
   let fontSize = 16
-  ctx.font = '800 ' + fontSize + 'px ' + ' Microsoft Yahei'
-  // if (ctx.measureText(cpyName).width > boxW) {
-  //   ctx.font = '800 ' + 20 + 'px ' + ' Microsoft Yahei'
-  // }
-  // for (let max = 41; ;) {
-  //   max--
-  //   // console.log(max)
-  //   if (max <= 20) {
-  //     break
-  //   }
-  //   ctx.font = '800 ' + max + 'px ' + ' Microsoft Yahei'
-  //   // console.log(ctx.measureText(cpyName).width)
-  //   if (ctx.measureText(cpyName).width > boxW * 1.35) {
-  //     continue
-  //   } else {
-  //     break
-  //   }
-  // }
-
-  // ctx.measureText(cpyName).width
-  // ctx.translate(0, 0)
-  // ctx.rotate(45 * Math.PI / 180)
-  // ctx.fillText(cpyName, 0, 0)
-  // ctx.rotate(-45 * Math.PI / 180)
-  // ctx.translate(300, 0)
-  // ctx.rotate(45 * Math.PI / 180)
-  // ctx.fillText(cpyName, 0, 0)
+  ctx.font = '200 ' + fontSize + 'px ' + ' Microsoft Yahei'
   for (let i = 0; i < boxWL; i++) {
     for (let j = 0; j < boxHL; j++) {
       // console.log(i, j)
@@ -67,12 +41,10 @@ export default function (strArr) {
       ctx.translate(i * boxW + suijix, j * boxH + suijiy)
       ctx.rotate(45 * Math.PI / 180)
       setName(strArr, ctx)
-      // ctx.fillText()
       ctx.rotate(-45 * Math.PI / 180)
       ctx.translate(-1 * i * boxW - suijix, -1 * j * boxH - suijiy)
     }
   }
-  // report.style.backgroundImage = 'url(' + canvas.toDataURL('image/png') + ')'
 }
 function setName (arr, ctx) {
   let h = 24

+ 4 - 1
src/views/main/main-navbar-user.vue

@@ -69,7 +69,10 @@ export default {
             return this.$message.error(res.msg)
           }
           clearLoginInfo()
-          this.$router.push({ name: 'login' })
+          // console.log(this.$router)
+          this.$router.replace({ name: 'login' }, (e) => {
+            window.location.reload()
+          })
         }).catch(() => {})
       }).catch(() => {})
     }