Bläddra i källkod

用户名做水印,并开启配置化

徐少年 3 år sedan
förälder
incheckning
bd3d78cf17

+ 5 - 0
Admin.NET/Admin.NET.Core/Admin.NET.Core.xml

@@ -193,6 +193,11 @@
             </summary>
         </member>
         <!-- Badly formed XML comment ignored for member "F:Admin.NET.Core.CommonConst.SysCaptcha" -->
+        <member name="F:Admin.NET.Core.CommonConst.SysWartermarkText">
+            <summary>
+            开启水印
+            </summary>
+        </member>
         <member name="F:Admin.NET.Core.CommonConst.SysOpLog">
             <summary>
             开启操作日志

+ 5 - 0
Admin.NET/Admin.NET.Core/Const/CommonConst.cs

@@ -27,6 +27,11 @@ public class CommonConst
     /// </summary>
     public const string SysCaptcha = "sys_captcha";
 
+    /// <summary>
+    /// 开启水印
+    /// </summary>
+    public const string SysWartermarkText = "sys_wartermark_text";
+
     /// <summary>
     /// 开启操作日志
     /// </summary>

+ 1 - 0
Admin.NET/Admin.NET.Core/SeedData/SysConfigSeedData.cs

@@ -21,6 +21,7 @@ public class SysConfigSeedData : ISqlSugarEntitySeedData<SysConfig>
             new SysConfig{ Id=252885263003804, Name="单点登录", Code="sys_single_login", Value="True", SysFlag=YesNoEnum.Y, Remark="开启单点登录", OrderNo=5, GroupCode="Default", CreateTime=DateTime.Parse("2022-02-10 00:00:00") },
             new SysConfig{ Id=252885263003805, Name="登录二次验证", Code="sys_second_ver", Value="True", SysFlag=YesNoEnum.Y, Remark="登录二次验证", OrderNo=6, GroupCode="Default", CreateTime=DateTime.Parse("2022-02-10 00:00:00") },
             new SysConfig{ Id=252885263003806, Name="开启图形验证码", Code="sys_captcha", Value="True", SysFlag=YesNoEnum.Y, Remark="开启图形验证码", OrderNo=7, GroupCode="Default", CreateTime=DateTime.Parse("2022-02-10 00:00:00") },
+            new SysConfig{ Id=252885263003807, Name="开启水印", Code="sys_wartermark_text", Value="True", SysFlag=YesNoEnum.Y, Remark="开启水印", OrderNo=8, GroupCode="Default", CreateTime=DateTime.Parse("2022-02-10 00:00:00") },
         };
     }
 }

+ 2 - 1
Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs

@@ -208,7 +208,8 @@ public class SysAuthService : IDynamicApiController, ITransient
     {
         var secondVerEnabled = await _sysConfigService.GetConfigValue<bool>(CommonConst.SysSecondVer);
         var captchaEnabled = await _sysConfigService.GetConfigValue<bool>(CommonConst.SysCaptcha);
-        return new { SecondVerEnabled = secondVerEnabled, CaptchaEnabled = captchaEnabled };
+        var wartermarkTextEnabled = await _sysConfigService.GetConfigValue<bool>(CommonConst.SysWartermarkText);
+        return new { SecondVerEnabled = secondVerEnabled, CaptchaEnabled = captchaEnabled, WartermarkTextEnabled = wartermarkTextEnabled };
     }
 
     /// <summary>

+ 40 - 15
Web/src/views/login/component/account.vue

@@ -10,20 +10,24 @@
 			</el-input>
 		</el-form-item>
 		<el-form-item class="login-animation2" prop="password">
-			<el-input :type="state.isShowPassword ? 'text' : 'password'" placeholder="请输入密码" v-model="state.ruleForm.password" autocomplete="off">
+			<el-input :type="state.isShowPassword ? 'text' : 'password'" placeholder="请输入密码"
+				v-model="state.ruleForm.password" autocomplete="off">
 				<template #prefix>
 					<el-icon>
 						<ele-Unlock />
 					</el-icon>
 				</template>
 				<template #suffix>
-					<i class="iconfont el-input__icon login-content-password" :class="state.isShowPassword ? 'icon-yincangmima' : 'icon-xianshimima'" @click="state.isShowPassword = !state.isShowPassword"> </i>
+					<i class="iconfont el-input__icon login-content-password"
+						:class="state.isShowPassword ? 'icon-yincangmima' : 'icon-xianshimima'"
+						@click="state.isShowPassword = !state.isShowPassword"> </i>
 				</template>
 			</el-input>
 		</el-form-item>
 		<el-form-item class="login-animation3" prop="captcha" v-show="state.captchaEnabled">
 			<el-col :span="15">
-				<el-input text maxlength="4" :placeholder="$t('message.account.accountPlaceholder3')" v-model="state.ruleForm.code" clearable autocomplete="off">
+				<el-input text maxlength="4" :placeholder="$t('message.account.accountPlaceholder3')"
+					v-model="state.ruleForm.code" clearable autocomplete="off">
 					<template #prefix>
 						<el-icon>
 							<ele-Position />
@@ -34,12 +38,14 @@
 			<el-col :span="1"></el-col>
 			<el-col :span="8">
 				<div class="login-content-code">
-					<img class="login-content-code-img" @click="getCaptcha" width="130px" height="38px" :src="state.captchaImage" style="cursor: pointer" />
+					<img class="login-content-code-img" @click="getCaptcha" width="130px" height="38px"
+						:src="state.captchaImage" style="cursor: pointer" />
 				</div>
 			</el-col>
 		</el-form-item>
 		<el-form-item class="login-animation4">
-			<el-button type="primary" class="login-content-submit" round v-waves @click="state.secondVerEnabled ? openRotateVerify() : onSignIn()" :loading="state.loading.signIn">
+			<el-button type="primary" class="login-content-submit" round v-waves
+				@click="state.secondVerEnabled ? openRotateVerify() : onSignIn()" :loading="state.loading.signIn">
 				<span>{{ $t('message.account.accountBtnText') }}</span>
 			</el-button>
 		</el-form-item>
@@ -48,16 +54,9 @@
 
 	<div class="dialog-header">
 		<el-dialog v-model="state.rotateVerifyVisible" :show-close="false">
-			<DragVerifyImgRotate
-				ref="dragRef"
-				:imgsrc="state.rotateVerifyImg"
-				v-model:isPassing="state.isPassRotate"
-				text="请按住滑块拖动"
-				successText="验证通过"
-				handlerIcon="fa fa-angle-double-right"
-				successIcon="fa fa-hand-peace-o"
-				@passcallback="passRotateVerify"
-			/>
+			<DragVerifyImgRotate ref="dragRef" :imgsrc="state.rotateVerifyImg" v-model:isPassing="state.isPassRotate"
+				text="请按住滑块拖动" successText="验证通过" handlerIcon="fa fa-angle-double-right"
+				successIcon="fa fa-hand-peace-o" @passcallback="passRotateVerify" />
 		</el-dialog>
 	</div>
 </template>
@@ -75,10 +74,16 @@ import { NextLoading } from '/@/utils/loading';
 import { clearTokens, feature, getAPI } from '/@/utils/axios-utils';
 import { SysAuthApi } from '/@/api-services/api';
 
+import { storeToRefs } from 'pinia';
+import { Local } from '/@/utils/storage';
+import { useThemeConfig } from '/@/stores/themeConfig';
+import Watermark from '/@/utils/wartermark';
 // 旋转图片滑块组件
 import verifyImg from '/@/assets/logo-mini.svg';
 const DragVerifyImgRotate = defineAsyncComponent(() => import('/@/components/dragVerify/dragVerifyImgRotate.vue'));
 
+const storesThemeConfig = useThemeConfig();
+const { themeConfig } = storeToRefs(storesThemeConfig);
 const { t } = useI18n();
 const route = useRoute();
 const router = useRouter();
@@ -106,6 +111,7 @@ const state = reactive({
 	rotateVerifyVisible: false,
 	rotateVerifyImg: verifyImg,
 	captchaEnabled: true,
+	wartermarkTextEnabled: true,
 	isPassRotate: false,
 });
 onMounted(async () => {
@@ -113,9 +119,19 @@ onMounted(async () => {
 	var res1 = await getAPI(SysAuthApi).loginConfigGet();
 	state.secondVerEnabled = res1.data.result.secondVerEnabled ?? true;
 	state.captchaEnabled = res1.data.result.captchaEnabled ?? true;
+	state.wartermarkTextEnabled = res1.data.result.wartermarkTextEnabled ?? true;
 
 	getCaptcha();
 });
+// 获取布局配置信息
+const getThemeConfig = computed(() => {
+	return themeConfig.value;
+});
+// 存储布局配置
+const setLocalThemeConfig = () => {
+	Local.remove('themeConfig');
+	Local.set('themeConfig', getThemeConfig.value);
+};
 // 获取验证码
 const getCaptcha = async () => {
 	state.ruleForm.code = '';
@@ -167,6 +183,13 @@ const signInSuccess = (isNoPower: boolean | undefined) => {
 		} else {
 			router.push('/');
 		}
+		// 设置水印
+		if (state.wartermarkTextEnabled) {
+			getThemeConfig.value.wartermarkText = state.ruleForm.account;
+			getThemeConfig.value.isWartermark = true;
+			if (getThemeConfig.value.isWartermark) Watermark.set(getThemeConfig.value.wartermarkText);
+			setLocalThemeConfig();
+		}
 		// 登录成功提示
 		const signInText = t('message.signInText');
 		ElMessage.success(`${currentTimeInfo},${signInText}`);
@@ -195,9 +218,11 @@ const passRotateVerify = () => {
 		.el-dialog__header {
 			display: none;
 		}
+
 		.el-dialog__wrapper {
 			position: absolute !important;
 		}
+
 		.v-modal {
 			position: absolute !important;
 		}