李文 4 years ago
parent
commit
183f60c078
4 changed files with 95 additions and 2 deletions
  1. 1 1
      public/index.html
  2. 82 0
      src/utils/shuiyin.js
  3. 11 0
      src/views/main/main.vue
  4. 1 1
      src/views/pages/login.vue

+ 1 - 1
public/index.html

@@ -39,7 +39,7 @@
   <!-- 开发环境 -->
   <% if (process.env.VUE_APP_NODE_ENV === 'dev') { %>
     <script>window.SITE_CONFIG['apiURL'] = 'http://124.225.17.80:8156/api-idaas';</script>
-    <script>window.SITE_CONFIG['apiURL'] = 'http://10.110.35.55:9900/api-idaas';</script>
+    <!-- <script>window.SITE_CONFIG['apiURL'] = 'http://10.110.35.55:9900/api-idaas';</script> -->
     <!-- <script>window.SITE_CONFIG['apiURL'] = 'http://172.16.124.90:9900/api-idaas';</script> -->
   <% } %>
   <!-- 集成测试环境 -->

+ 82 - 0
src/utils/shuiyin.js

@@ -0,0 +1,82 @@
+// 添加水印方法
+export default function (strArr) {
+  // let cpyName = str
+  // if (str.length > 16) {
+  //   cpyName = str.substring(0, 16)
+  // }
+  let win = window.$(window)
+  let winW = win.width()
+  let winH = win.height()
+  let boxW = 300
+  let boxH = 200
+  let boxWL = Math.ceil(winW / boxW)
+  let boxHL = Math.ceil(winH / boxH)
+  let canvas = document.createElement('canvas')
+  let report = window.$('body')
+  report.append(canvas)
+  console.log(winW, winH)
+  window.$(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)
+  ctx.globalAlpha = 0.3
+  ctx.fillStyle = '#fff'
+  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)
+  for (let i = 0; i < boxWL; i++) {
+    for (let j = 0; j < boxHL; j++) {
+      // console.log(i, j)
+      let suijix = Math.random() * 50
+      let suijiy = Math.random() * 50
+      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
+  arr.forEach((e, i) => {
+    ctx.fillText(e, 0, i * h)
+  })
+}

+ 11 - 0
src/views/main/main.vue

@@ -35,6 +35,7 @@ import noticePop from './notice-pop'
 import taskPop from './task-pop'
 import basicCom from '@/views/modules/demo/basicComponent/basic-com'
 import { clearLoginInfo } from '@/utils'
+import shuiyin from '@/utils/shuiyin'
 let allComponent = {
   index: ''
 }
@@ -101,8 +102,18 @@ export default {
   mounted () {
     this.getMenuList()
     this.monitorChild()
+    this.setWaterMarker()
   },
   methods: {
+    setWaterMarker () {
+      // /api-idaas
+      this.$http.get('/idaas/sso/user/watermark/info').then(({ data: res }) => {
+        if (res.code !== 0) {
+          return this.$message.error(res.msg)
+        }
+        shuiyin([res.data.ip, res.data.username, res.data.currentTime])
+      }).catch(() => {})
+    },
     // 窗口改变大小
     // windowResizeHandle () {
     //   this.$store.state.sidebarFold = document.documentElement['clientWidth'] <= 992 || false

+ 1 - 1
src/views/pages/login.vue

@@ -99,7 +99,7 @@ export default {
         }
         this.$http.post('/idaas/sso/login', this.dataForm).then(({ data: res }) => {
           if (res.code !== 0) {
-            // this.getCaptcha()
+            this.getCaptcha()
             return this.$message.error(res.msg)
           }
           Cookies.set('token', res.sessionToken)