Skip to content

Commit

Permalink
Merge pull request #568 from beansmile/feat-update-redame
Browse files Browse the repository at this point in the history
feat: 更新 readme 水印信息
  • Loading branch information
xggaxlc authored May 28, 2024
2 parents 273b3a2 + 624d9eb commit 80b2498
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
## alert env tips
## env watermark 水印
非正式环境显示提示,防止客户将 staging 环境,误认为是正式环境。
通过以下环境变量控制

VUE_APP_ENV: 不为 production 时,会有弹窗
VUE_APP_ENV: 不为 production 时,会有水印提示

VUE_APP_CLOSE_ENV_TIPS: 可在开发环境控制,关闭提示
VUE_APP_CLOSE_ENV_WATERMARK: 可在开发环境控制,关闭提示

VUE_APP_ENV_TIPS_DURATION:控制动画快慢,默认 10

VUE_APP_ENV_TIPS_TEXT: 自定义提示文案,默认 `This is the ${VUE_APP_ENV} environment`
VUE_APP_ENV_WATERMARK_TEXT: 自定义提示文案,默认 `This is the ${VUE_APP_ENV} environment`
21 changes: 5 additions & 16 deletions src/plugin/utils/env-watermark.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
import { MessageBox, Alert } from 'element-ui';
import Vue from 'vue'
import Watermark from '../components/watermark.vue';

const VUE_APP_ENV = process.env.VUE_APP_ENV || 'development';
const closeEnvTips = Boolean(process.env.VUE_APP_CLOSE_ENV_TIPS);
const envTipsDuration = parseInt(process.env.VUE_APP_ENV_TIPS_DURATION) || 10;
const envTipsText = parseInt(process.env.VUE_APP_ENV_TIPS_TEXT) || `This is the ${VUE_APP_ENV} environment`;

function translateColor(color) {
try {
const [r, g, b, a] = color.match(/rgba?\((.*)\)/)[1].split(/, ?/);
return `rgba(${r}, ${g}, ${b}, ${(a || 1) / 4})`
} catch (e) {
return 'rgba(144, 147, 153, 0.5)';
}
}
const vueAppEnv = process.env.VUE_APP_ENV || 'development';
const closeEnvWatermark = Boolean(process.env.VUE_APP_CLOSE_ENV_WATERMARK);
const envWatermarkText = process.env.VUE_APP_ENV_WATERMARK_TEXT || `This is the ${vueAppEnv} environment`;

export default function alertEnvTips() {
// 如果是正式环境,或者 VUE_APP_CLOSE_ENV_TIPS 为 true,就不要显示环境提示
if (VUE_APP_ENV === 'production' || closeEnvTips) {
if (vueAppEnv === 'production' || closeEnvWatermark) {
return;
}

const instance = new (Vue.extend(Watermark))().$mount();
Object.assign(instance.$props, {
text: envTipsText,
text: envWatermarkText,
});
if (document.body.firstChild.before) {
document.body.firstChild.before(instance.$el);
Expand Down

0 comments on commit 80b2498

Please sign in to comment.