添加测试环境水印
Showing
7 changed files
with
91 additions
and
9 deletions
| ... | @@ -10,3 +10,4 @@ VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+ | ... | @@ -10,3 +10,4 @@ VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+ |
| 10 | VUE_APP_AES_IV = 'c5014a8dc3a341ac' | 10 | VUE_APP_AES_IV = 'c5014a8dc3a341ac' |
| 11 | VUE_APP_TOKEN_KEY = 'kd_template_token' | 11 | VUE_APP_TOKEN_KEY = 'kd_template_token' |
| 12 | VUE_APP_IS_POST_ENC = true | 12 | VUE_APP_IS_POST_ENC = true |
| 13 | VUE_APP_WATER_MARK = true | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -11,3 +11,4 @@ VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+ | ... | @@ -11,3 +11,4 @@ VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+ |
| 11 | VUE_APP_AES_IV = 'c5014a8dc3a341ac' | 11 | VUE_APP_AES_IV = 'c5014a8dc3a341ac' |
| 12 | VUE_APP_TOKEN_KEY = 'kd_template_token' | 12 | VUE_APP_TOKEN_KEY = 'kd_template_token' |
| 13 | VUE_APP_IS_POST_ENC = true | 13 | VUE_APP_IS_POST_ENC = true |
| 14 | VUE_APP_WATER_MARK = true | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -11,3 +11,4 @@ VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+ | ... | @@ -11,3 +11,4 @@ VUE_APP_RSA_PUBLIC_KEY = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxi7pNPRSc+ |
| 11 | VUE_APP_AES_IV = 'c5014a8dc3a341ac' | 11 | VUE_APP_AES_IV = 'c5014a8dc3a341ac' |
| 12 | VUE_APP_TOKEN_KEY = 'kd_template_token' | 12 | VUE_APP_TOKEN_KEY = 'kd_template_token' |
| 13 | VUE_APP_IS_POST_ENC = true | 13 | VUE_APP_IS_POST_ENC = true |
| 14 | VUE_APP_WATER_MARK = true | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -8,6 +8,39 @@ | ... | @@ -8,6 +8,39 @@ |
| 8 | </div> | 8 | </div> |
| 9 | </template> | 9 | </template> |
| 10 | 10 | ||
| 11 | <script> | ||
| 12 | import { setWaterMark } from "@/utils/watermark"; | ||
| 13 | |||
| 14 | export default { | ||
| 15 | name: "App", | ||
| 16 | data() { | ||
| 17 | return {}; | ||
| 18 | }, | ||
| 19 | methods: { | ||
| 20 | /** | ||
| 21 | * 192.168.3.2:8080 | ||
| 22 | * 显示测试服水印 | ||
| 23 | * 1、根据kd的环境 | ||
| 24 | * host中含dev或者sandbox的为测试环境 | ||
| 25 | * 2、VUE_APP_WATER_MARK设置为true | ||
| 26 | */ | ||
| 27 | initWaterMark() { | ||
| 28 | let host = location.host; | ||
| 29 | if ( | ||
| 30 | process.env.VUE_APP_WATER_MARK && | ||
| 31 | (host.indexOf("dev") != -1 || host.indexOf("sandbox") != -1) | ||
| 32 | ) { | ||
| 33 | setWaterMark("测试服", ""); | ||
| 34 | } | ||
| 35 | }, | ||
| 36 | }, | ||
| 37 | mounted() { | ||
| 38 | console.log("111"); | ||
| 39 | this.initWaterMark(); | ||
| 40 | }, | ||
| 41 | }; | ||
| 42 | </script> | ||
| 43 | |||
| 11 | <style lang="scss"> | 44 | <style lang="scss"> |
| 12 | #app { | 45 | #app { |
| 13 | /* font-family: 'Avenir', Helvetica, Arial, sans-serif; | 46 | /* font-family: 'Avenir', Helvetica, Arial, sans-serif; |
| ... | @@ -32,10 +65,6 @@ div { | ... | @@ -32,10 +65,6 @@ div { |
| 32 | width: 750px; | 65 | width: 750px; |
| 33 | } | 66 | } |
| 34 | 67 | ||
| 35 | .app__width { | ||
| 36 | width: 750px; | ||
| 37 | } | ||
| 38 | |||
| 39 | .app__inner { | 68 | .app__inner { |
| 40 | margin: 20px; | 69 | margin: 20px; |
| 41 | } | 70 | } | ... | ... |
| ... | @@ -14,12 +14,9 @@ import { | ... | @@ -14,12 +14,9 @@ import { |
| 14 | 14 | ||
| 15 | import 'amfe-flexible/index.js' | 15 | import 'amfe-flexible/index.js' |
| 16 | 16 | ||
| 17 | import '@/styles/index.scss' // global css | 17 | // import '@/styles/index.scss' // global css |
| 18 | |||
| 19 | import '@/styles/index.scss' // global css | ||
| 20 | import '@/styles/fonticon.scss' // 图标字体 | 18 | import '@/styles/fonticon.scss' // 图标字体 |
| 21 | import '@/assets/fonts/font.scss' // 字体引入 | 19 | import '@/assets/fonts/font.scss' // 字体引入 |
| 22 | |||
| 23 | // import '@styles/utils.scss' /*引入公共样式*/ | 20 | // import '@styles/utils.scss' /*引入公共样式*/ |
| 24 | 21 | ||
| 25 | Vue.config.productionTip = false | 22 | Vue.config.productionTip = false | ... | ... |
src/utils/watermark.js
0 → 100644
| 1 | /** 水印添加方法 */ | ||
| 2 | |||
| 3 | let setWatermark = (str1, str2) => { | ||
| 4 | let id = '1.23452384164.123412415' | ||
| 5 | |||
| 6 | if (document.getElementById(id) !== null) { | ||
| 7 | document.body.removeChild(document.getElementById(id)) | ||
| 8 | } | ||
| 9 | |||
| 10 | let can = document.createElement('canvas') | ||
| 11 | // 设置canvas画布大小 | ||
| 12 | can.width = 150 | ||
| 13 | can.height = 80 | ||
| 14 | |||
| 15 | let cans = can.getContext('2d') | ||
| 16 | cans.rotate(-20 * Math.PI / 180) // 水印旋转角度 | ||
| 17 | cans.font = '15px Vedana' | ||
| 18 | cans.fillStyle = '#666666' | ||
| 19 | cans.textAlign = 'center' | ||
| 20 | cans.textBaseline = 'Middle' | ||
| 21 | cans.fillText(str1, can.width / 2, can.height) // 水印在画布的位置x,y轴 | ||
| 22 | cans.fillText(str2, can.width / 2, can.height + 22) | ||
| 23 | |||
| 24 | let div = document.createElement('div') | ||
| 25 | div.id = id | ||
| 26 | div.style.pointerEvents = 'none' | ||
| 27 | div.style.top = '40px' | ||
| 28 | div.style.left = '0px' | ||
| 29 | div.style.opacity = '0.15' | ||
| 30 | div.style.position = 'fixed' | ||
| 31 | div.style.zIndex = '100000' | ||
| 32 | div.style.width = document.documentElement.clientWidth + 'px' | ||
| 33 | div.style.height = document.documentElement.clientHeight + 'px' | ||
| 34 | div.style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat' | ||
| 35 | document.body.appendChild(div) | ||
| 36 | return id | ||
| 37 | } | ||
| 38 | |||
| 39 | // 添加水印方法 | ||
| 40 | export const setWaterMark = (str1, str2) => { | ||
| 41 | let id = setWatermark(str1, str2) | ||
| 42 | if (document.getElementById(id) === null) { | ||
| 43 | id = setWatermark(str1, str2) | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | // 移除水印方法 | ||
| 48 | export const removeWatermark = () => { | ||
| 49 | let id = '1.23452384164.123412415' | ||
| 50 | if (document.getElementById(id) !== null) { | ||
| 51 | document.body.removeChild(document.getElementById(id)) | ||
| 52 | } | ||
| 53 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or sign in to post a comment