Unverified Commit 8b6c469d authored by Zzm0809's avatar Zzm0809 Committed by GitHub

support enable or disable model error (#2693)

* support-auto-open-model * Spotless Apply --------- Co-authored-by: 's avatarZzm0809 <Zzm0809@users.noreply.github.com>
parent 177330db
......@@ -18,11 +18,18 @@
*/
import { chooseTenantSubmit, outLogin } from '@/services/BusinessCrud';
import { setTenantStorageAndCookie } from '@/utils/function';
import { ENABLE_MODEL_TIP } from '@/services/constants';
import {
getValueFromLocalStorage,
setKeyToLocalStorage,
setTenantStorageAndCookie
} from '@/utils/function';
import { l } from '@/utils/intl';
import { ErrorNotification, SuccessNotification } from '@/utils/messages';
import { ErrorNotification, SuccessNotification, WarningNotification } from '@/utils/messages';
import {
BugOutlined,
ClearOutlined,
CloseCircleOutlined,
LogoutOutlined,
TeamOutlined,
UserOutlined,
......@@ -35,7 +42,7 @@ import { Avatar, Modal, Spin } from 'antd';
import { stringify } from 'querystring';
import { ItemType } from 'rc-menu/es/interface';
import type { MenuInfo } from 'rc-menu/lib/interface';
import { useCallback } from 'react';
import { useCallback, useState } from 'react';
import HeaderDropdown from '../HeaderDropdown';
export const loginOut = async () => {
......@@ -120,6 +127,10 @@ const AvatarDropdown = () => {
});
const { initialState, setInitialState } = useModel('@@initialState');
const [enableModelTip, setEnableModelTip] = useState<boolean>(
Boolean(getValueFromLocalStorage(ENABLE_MODEL_TIP))
);
const loginOutHandler = useCallback(
async (event: MenuInfo) => {
const { key } = event;
......@@ -188,6 +199,16 @@ const AvatarDropdown = () => {
return chooseTenantList;
};
const handleClickEnableModelTip = () => {
setKeyToLocalStorage(ENABLE_MODEL_TIP, String(!enableModelTip));
setEnableModelTip(!enableModelTip);
if (!enableModelTip) {
SuccessNotification(l('menu.account.openGlobalMessageTip'));
} else {
WarningNotification(l('menu.account.closeGlobalMessageTip'));
}
};
const menuItems = [
{
key: 'currentTenant',
......@@ -226,6 +247,14 @@ const AvatarDropdown = () => {
window.location.reload();
}
},
{
key: 'enableModelTip',
icon: enableModelTip ? <CloseCircleOutlined /> : <BugOutlined />,
label: enableModelTip
? l('menu.account.closeGlobalMessage')
: l('menu.account.openGlobalMessage'),
onClick: () => handleClickEnableModelTip()
},
{
type: 'divider' as const
},
......
......@@ -37,6 +37,12 @@ export default {
'menu.account.changePassword': 'Change Password',
'menu.account.checkTenant': 'Switch Tenant',
'menu.account.checkTenantConfirm': 'Are you sure to switch tenant [ {tenantCode} ] ?',
'menu.account.closeGlobalMessage': 'Close developer mode',
'menu.account.openGlobalMessage': 'Turn on developer mode',
'menu.account.closeGlobalMessageTip':
'You have turned off the developer mode and will not receive all exception information returned by the background. You can only receive warning information.',
'menu.account.openGlobalMessageTip':
'Developer mode is turned on. You can receive all exception/warning information returned by the background. If you do not want to receive the exception stack, please turn off this function.',
'menu.datastudio': 'Data Studio',
......
......@@ -37,6 +37,12 @@ export default {
'menu.account.changePassword': '修改密码',
'menu.account.checkTenant': '切换租户',
'menu.account.checkTenantConfirm': '你确定切换租户【{tenantCode}】吗?',
'menu.account.closeGlobalMessage': '关闭开发者模式',
'menu.account.openGlobalMessage': '开启开发者模式',
'menu.account.closeGlobalMessageTip':
'你已关闭开发者模式,将不会接收到后台返回的所有异常信息,只能收到警告信息.',
'menu.account.openGlobalMessageTip':
'已开启开发者模式,你可以接收到后台返回的所有异常/警告信息,如果你不想接收异常堆栈,请关闭此功能.',
'menu.datastudio': '数据开发',
......
......@@ -17,6 +17,12 @@
*
*/
import { ENABLE_MODEL_TIP } from '@/services/constants';
import {
hasKeyofLocalStorage,
setKeyToLocalStorage,
setLocalThemeToStorage
} from '@/utils/function';
import { history } from '@@/core/history';
/** 此方法会跳转到 redirect 参数所在的位置 */
......@@ -32,3 +38,12 @@ export const redirectToLogin = () => {
//TODO: 弹出确认框
window.location.href = '/login';
};
export const initSomeThing = () => {
// 初始化设置主题
setLocalThemeToStorage();
// 取出本地存储是否有启用消息提示的 key , 没有的话设置一下
if (hasKeyofLocalStorage(ENABLE_MODEL_TIP)) {
setKeyToLocalStorage(ENABLE_MODEL_TIP, 'true');
}
};
......@@ -19,13 +19,13 @@
import Footer from '@/components/Footer';
import ChooseModal from '@/pages/Other/Login/ChooseModal';
import { gotoRedirectUrl, redirectToLogin } from '@/pages/Other/Login/function';
import { gotoRedirectUrl, initSomeThing, redirectToLogin } from '@/pages/Other/Login/function';
import LangSwitch from '@/pages/Other/Login/LangSwitch';
import { chooseTenantSubmit, login, queryDataByParams } from '@/services/BusinessCrud';
import { API } from '@/services/data';
import { API_CONSTANTS } from '@/services/endpoints';
import { UserBaseInfo } from '@/types/AuthCenter/data';
import { setLocalThemeToStorage, setTenantStorageAndCookie } from '@/utils/function';
import { setTenantStorageAndCookie } from '@/utils/function';
import { useLocalStorage } from '@/utils/hook/useLocalStorage';
import { l } from '@/utils/intl';
import { ErrorMessage, SuccessMessageAsync } from '@/utils/messages';
......@@ -90,8 +90,6 @@ const Login: React.FC = () => {
tenantCode: chooseTenantResult.data.tenantCode
})
);
// 补偿设置,设置主题色
setLocalThemeToStorage();
/**
* After the selection is complete, refresh all user information
*/
......@@ -177,7 +175,8 @@ const Login: React.FC = () => {
await handleChooseTenant(result);
handleTenantVisible(false);
};
// 进入登录页初始化一些东西
initSomeThing();
return (
<div className={containerClassName}>
<HelmetTitle />
......
......@@ -17,7 +17,9 @@
*
*/
import { ENABLE_MODEL_TIP } from '@/services/constants';
import { API_CONSTANTS } from '@/services/endpoints';
import { getValueFromLocalStorage } from '@/utils/function';
import { l } from '@/utils/intl';
import { ErrorNotification, WarningNotification } from '@/utils/messages';
import { history } from '@@/core/history';
......@@ -43,6 +45,8 @@ interface ResponseStructure {
const handleBizError = (result: ResponseStructure) => {
const { msg, code, data } = result;
console.log(JSON.stringify(msg));
switch (code) {
case ErrorCode.SUCCESS:
//don't deal with it, just be happy
......@@ -52,7 +56,9 @@ const handleBizError = (result: ResponseStructure) => {
break;
case ErrorCode.EXCEPTION:
//TODO 可配置化,dev换弹出错误,release不弹
//ErrorNotification(JSON.stringify(data), l('app.response.error'));
if (Boolean(getValueFromLocalStorage(ENABLE_MODEL_TIP))) {
ErrorNotification(JSON.stringify(data), l('app.response.error'));
}
break;
case ErrorCode.PARAMS_ERROR:
ErrorNotification(msg, l('app.response.error'));
......@@ -83,6 +89,8 @@ export const errorConfig: RequestConfig = {
},
// 错误接收及处理
errorHandler: (error: any, opts: any) => {
console.log(error);
if (opts?.skipErrorHandler) throw error;
// 我们的 errorThrower 抛出的错误。
if (error.name === 'BizError') {
......
......@@ -41,6 +41,8 @@ export const LANGUAGE_EN = 'en-US';
export const DATE_FORMAT = 'YYYY-MM-DD';
export const DATETIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
export const ENABLE_MODEL_TIP = 'enableModelTip';
/**
* REQUEST METHOD CONSTANTS
*/
......
......@@ -66,6 +66,10 @@ export function setKeyToLocalStorage(key: string, value: string) {
localStorage.setItem(key, value);
}
export function hasKeyofLocalStorage(key: string): boolean {
return localStorage.getItem(key) === undefined || localStorage.getItem(key) === null;
}
/**
* get value by localStorage's key
* @param key
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment