Browse Source

fix: 修复“开启水印”参数无效的问题,并优化配置的读取时机

sys_watermark
许俊杰 3 years ago
parent
commit
b9ce18d053

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

@@ -184,8 +184,20 @@ 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 };
+    }
+
+    /// <summary>
+    /// 获取用户配置
+    /// </summary>
+    /// <returns></returns>
+    [SuppressMonitor]
+    [DisplayName("获取用户配置")]
+    public async Task<dynamic> GetUserConfig()
+    {
+        //返回用户和通用配置
         var watermarkEnabled = await _sysConfigService.GetConfigValue<bool>(CommonConst.SysWatermark);
-        return new { SecondVerEnabled = secondVerEnabled, CaptchaEnabled = captchaEnabled, WatermarkEnabled = watermarkEnabled };
+        return new { WatermarkEnabled = watermarkEnabled };
     }
 
     /// <summary>

+ 68 - 0
Web/src/api-services/apis/sys-auth-api.ts

@@ -308,6 +308,42 @@ export const SysAuthApiAxiosParamCreator = function (configuration?: Configurati
                 options: localVarRequestOptions,
             };
         },
+        /**
+         * 
+         * @summary 获取用户配置
+         * @param {*} [options] Override http request option.
+         * @throws {RequiredError}
+         */
+        apiSysAuthUserConfigGet: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
+            const localVarPath = `/api/sysAuth/userConfig`;
+            // use dummy base URL string because the URL constructor only accepts absolute URLs.
+            const localVarUrlObj = new URL(localVarPath, 'https://example.com');
+            let baseOptions;
+            if (configuration) {
+                baseOptions = configuration.baseOptions;
+            }
+            const localVarRequestOptions :AxiosRequestConfig = { method: 'GET', ...baseOptions, ...options};
+            const localVarHeaderParameter = {} as any;
+            const localVarQueryParameter = {} as any;
+
+            // authentication Bearer required
+
+            const query = new URLSearchParams(localVarUrlObj.search);
+            for (const key in localVarQueryParameter) {
+                query.set(key, localVarQueryParameter[key]);
+            }
+            for (const key in options.params) {
+                query.set(key, options.params[key]);
+            }
+            localVarUrlObj.search = (new URLSearchParams(query)).toString();
+            let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
+            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
+
+            return {
+                url: localVarUrlObj.pathname + localVarUrlObj.search + localVarUrlObj.hash,
+                options: localVarRequestOptions,
+            };
+        },
         /**
          * 
          * @summary 获取登录账号
@@ -448,6 +484,19 @@ export const SysAuthApiFp = function(configuration?: Configuration) {
                 return axios.request(axiosRequestArgs);
             };
         },
+        /**
+         * 
+         * @summary 获取用户配置
+         * @param {*} [options] Override http request option.
+         * @throws {RequiredError}
+         */
+        async apiSysAuthUserConfigGet(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => Promise<AxiosResponse<AdminResultObject>>> {
+            const localVarAxiosArgs = await SysAuthApiAxiosParamCreator(configuration).apiSysAuthUserConfigGet(options);
+            return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => {
+                const axiosRequestArgs :AxiosRequestConfig = {...localVarAxiosArgs.options, url: basePath + localVarAxiosArgs.url};
+                return axios.request(axiosRequestArgs);
+            };
+        },
         /**
          * 
          * @summary 获取登录账号
@@ -537,6 +586,15 @@ export const SysAuthApiFactory = function (configuration?: Configuration, basePa
         async apiSysAuthRefreshTokenAccessTokenGet(accessToken: string, options?: AxiosRequestConfig): Promise<AxiosResponse<AdminResultString>> {
             return SysAuthApiFp(configuration).apiSysAuthRefreshTokenAccessTokenGet(accessToken, options).then((request) => request(axios, basePath));
         },
+        /**
+         * 
+         * @summary 获取用户配置
+         * @param {*} [options] Override http request option.
+         * @throws {RequiredError}
+         */
+        async apiSysAuthUserConfigGet(options?: AxiosRequestConfig): Promise<AxiosResponse<AdminResultObject>> {
+            return SysAuthApiFp(configuration).apiSysAuthUserConfigGet(options).then((request) => request(axios, basePath));
+        },
         /**
          * 
          * @summary 获取登录账号
@@ -630,6 +688,16 @@ export class SysAuthApi extends BaseAPI {
     public async apiSysAuthRefreshTokenAccessTokenGet(accessToken: string, options?: AxiosRequestConfig) : Promise<AxiosResponse<AdminResultString>> {
         return SysAuthApiFp(this.configuration).apiSysAuthRefreshTokenAccessTokenGet(accessToken, options).then((request) => request(this.axios, this.basePath));
     }
+    /**
+     * 
+     * @summary 获取用户配置
+     * @param {*} [options] Override http request option.
+     * @throws {RequiredError}
+     * @memberof SysAuthApi
+     */
+    public async apiSysAuthUserConfigGet(options?: AxiosRequestConfig) : Promise<AxiosResponse<AdminResultObject>> {
+        return SysAuthApiFp(this.configuration).apiSysAuthUserConfigGet(options).then((request) => request(this.axios, this.basePath));
+    }
     /**
      * 
      * @summary 获取登录账号

+ 1 - 1
Web/src/api-services/models/add-menu-input.ts

@@ -69,7 +69,7 @@ export interface AddMenuInput {
      */
     type?: MenuTypeEnum;
     /**
-     * 名称
+     * 路由名称
      * @type {string}
      * @memberof AddMenuInput
      */

+ 6 - 0
Web/src/api-services/models/file-output.ts

@@ -59,4 +59,10 @@ export interface FileOutput {
      * @memberof FileOutput
      */
     filePath?: string | null;
+    /**
+     * 文件名称
+     * @type {string}
+     * @memberof FileOutput
+     */
+    fileName?: string | null;
 }

+ 12 - 0
Web/src/api-services/models/send-subscribe-message-input.ts

@@ -36,4 +36,16 @@ export interface SendSubscribeMessageInput {
      * @memberof SendSubscribeMessageInput
      */
     data: { [key: string]: DataItem; };
+    /**
+     * 跳转小程序类型
+     * @type {string}
+     * @memberof SendSubscribeMessageInput
+     */
+    miniprogramState?: string | null;
+    /**
+     * 语言类型
+     * @type {string}
+     * @memberof SendSubscribeMessageInput
+     */
+    language?: string | null;
 }

+ 2 - 2
Web/src/api-services/models/sys-menu.ts

@@ -69,7 +69,7 @@ export interface SysMenu {
      */
     type?: MenuTypeEnum;
     /**
-     * 名称
+     * 路由名称
      * @type {string}
      * @memberof SysMenu
      */
@@ -99,7 +99,7 @@ export interface SysMenu {
      */
     permission?: string | null;
     /**
-     * 标题
+     * 菜单名称
      * @type {string}
      * @memberof SysMenu
      */

+ 1 - 1
Web/src/api-services/models/update-menu-input.ts

@@ -69,7 +69,7 @@ export interface UpdateMenuInput {
      */
     type?: MenuTypeEnum;
     /**
-     * 名称
+     * 路由名称
      * @type {string}
      * @memberof UpdateMenuInput
      */

+ 20 - 3
Web/src/stores/userInfo.ts

@@ -1,5 +1,7 @@
 import { defineStore } from 'pinia';
-import { Session } from '/@/utils/storage';
+import { Local, Session } from '/@/utils/storage';
+import Watermark from '/@/utils/watermark';
+import { useThemeConfig } from '/@/stores/themeConfig';
 
 import { getAPI } from '/@/utils/axios-utils';
 import { SysAuthApi, SysConstApi } from '/@/api-services/api';
@@ -32,11 +34,11 @@ export const useUserInfo = defineStore('userInfo', {
 			}
 		},
 		// 获取当前用户信息
-		async getApiUserInfo() {
+		getApiUserInfo() {
 			return new Promise((resolve) => {
 				getAPI(SysAuthApi)
 					.apiSysAuthUserInfoGet()
-					.then((res: any) => {
+					.then(async (res: any) => {
 						if (res.data.result == null) return;
 						var d = res.data.result;
 						const userInfos = {
@@ -52,6 +54,21 @@ export const useUserInfo = defineStore('userInfo', {
 							authBtnList: d.buttons,
 							time: new Date().getTime(),
 						};
+
+						// 读取用户配置
+						const configRes: any = await getAPI(SysAuthApi).apiSysAuthUserConfigGet();
+						if (configRes.data.result == null) return;
+
+						const configData = configRes.data.result;
+						const storesThemeConfig = useThemeConfig();
+
+						// storesThemeConfig.themeConfig.watermarkText = d.account;
+						storesThemeConfig.themeConfig.isWatermark = configData.watermarkEnabled;
+						Watermark.set(storesThemeConfig.themeConfig.watermarkText);
+
+						Local.remove('themeConfig');
+						Local.set('themeConfig', storesThemeConfig.themeConfig);
+
 						resolve(userInfos);
 					});
 			});

+ 1 - 27
Web/src/views/login/component/account.vue

@@ -68,14 +68,10 @@ import { useRoute, useRouter } from 'vue-router';
 import { ElMessage } from 'element-plus';
 import { useI18n } from 'vue-i18n';
 import { initBackEndControlRoutes } from '/@/router/backEnd';
-import { Local, Session } from '/@/utils/storage';
+import { Session } from '/@/utils/storage';
 import { formatAxis } from '/@/utils/formatTime';
 import { NextLoading } from '/@/utils/loading';
 
-import { storeToRefs } from 'pinia';
-import { useThemeConfig } from '/@/stores/themeConfig';
-import Watermark from '/@/utils/watermark';
-
 import { clearTokens, feature, getAPI } from '/@/utils/axios-utils';
 import { SysAuthApi } from '/@/api-services/api';
 
@@ -83,8 +79,6 @@ import { SysAuthApi } from '/@/api-services/api';
 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();
@@ -112,7 +106,6 @@ const state = reactive({
 	rotateVerifyImg: verifyImg,
 	secondVerEnabled: true,
 	captchaEnabled: true,
-	watermarkEnabled: true,
 	isPassRotate: false,
 });
 onMounted(async () => {
@@ -120,26 +113,9 @@ onMounted(async () => {
 	var res1 = await getAPI(SysAuthApi).apiSysAuthLoginConfigGet();
 	state.secondVerEnabled = res1.data.result.secondVerEnabled ?? true;
 	state.captchaEnabled = res1.data.result.captchaEnabled ?? true;
-	state.watermarkEnabled = res1.data.result.watermarkEnabled ?? true;
 
 	getCaptcha();
 });
-// 获取布局配置信息
-const getThemeConfig = computed(() => {
-	return themeConfig.value;
-});
-// 存储布局配置
-const setLocalThemeConfig = () => {
-	// 是否显示水印
-	if (!state.watermarkEnabled) return;
-
-	// getThemeConfig.value.watermarkText = state.ruleForm.account;
-	getThemeConfig.value.isWatermark = true;
-	Watermark.set(getThemeConfig.value.watermarkText);
-
-	Local.remove('themeConfig');
-	Local.set('themeConfig', getThemeConfig.value);
-};
 // 获取验证码
 const getCaptcha = async () => {
 	state.ruleForm.code = '';
@@ -191,8 +167,6 @@ const signInSuccess = (isNoPower: boolean | undefined) => {
 		} else {
 			router.push('/');
 		}
-		// // 设置水印
-		// setLocalThemeConfig();
 
 		// 登录成功提示
 		const signInText = t('message.signInText');