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