- {(statistics.tourismRanking || []).map((item: any, index: number) => (
+ {statistics.tourismRanking?.map((item: { id: string; name: string; value: number }, index: number) => (
-
+
{index + 1}
{item.name}
diff --git a/zlt-web/react-web/src/main/frontend/src/pages/user/Login/index.tsx b/zlt-web/react-web/src/main/frontend/src/pages/user/Login/index.tsx
index fc226271..6792fa20 100644
--- a/zlt-web/react-web/src/main/frontend/src/pages/user/Login/index.tsx
+++ b/zlt-web/react-web/src/main/frontend/src/pages/user/Login/index.tsx
@@ -3,7 +3,7 @@ import { login } from '@/services/login/api';
import { InfoCircleOutlined, LockOutlined, UserOutlined, AppstoreOutlined } from '@ant-design/icons';
import { LoginForm, ProFormCaptcha, ProFormText, ProFormCheckbox } from '@ant-design/pro-components';
import { message, Tooltip, Spin, Form } from 'antd';
-import React, { useState, useEffect } from 'react';
+import React, { useState, useEffect, useRef } from 'react';
import { FormattedMessage, history, useIntl, useModel } from 'umi';
import { v4 as uuidv4 } from 'uuid';
import styles from './index.less';
@@ -14,18 +14,27 @@ const Login: React.FC = () => {
const { initialState, setInitialState } = useModel('@@initialState');
const intl = useIntl();
const [form] = Form.useForm();
+ const mountedRef = useRef(true);
+
+ useEffect(() => {
+ return () => {
+ mountedRef.current = false;
+ };
+ }, []);
const fetchUserInfo = async () => {
try {
const userInfo = await initialState?.fetchUserInfo?.();
- if (userInfo) {
+ if (userInfo && mountedRef.current) {
await setInitialState((s) => ({
...s,
currentUser: userInfo,
}));
}
} catch (error) {
- message.error('获取用户信息失败');
+ if (mountedRef.current) {
+ message.error('获取用户信息失败');
+ }
}
};
@@ -42,7 +51,7 @@ const Login: React.FC = () => {
// 自动填充缓存的租户标识
useEffect(() => {
const clientId = getCachedTenantId();
- if (clientId) {
+ if (clientId && mountedRef.current) {
form.setFieldsValue({
clientId,
});
@@ -51,27 +60,36 @@ const Login: React.FC = () => {
const handleSubmit = async (values: API.LoginParams) => {
try {
+ if (!mountedRef.current) return;
setLoading(true);
const msg = await login({ ...values, deviceId: uuid });
- debugger;
if (msg.resp_code === 0 && msg.data?.access_token) {
sessionStorage.setItem('access_token', msg.data.access_token);
- message.success('登录成功!');
- await fetchUserInfo();
-
- const { query } = history.location;
- const { redirect } = query as { redirect: string };
- history.push(redirect || '/');
- return;
+ if (mountedRef.current) {
+ message.success('登录成功!');
+ await fetchUserInfo();
+ await initialState?.fetchUserInfo?.();
+
+ const { query } = history.location;
+ const { redirect } = query as { redirect: string };
+ history.push(redirect || '/');
+ return;
+ }
}
- message.error(msg.resp_msg || '登录失败');
- setUuid(uuidv4());
+ if (mountedRef.current) {
+ message.error(msg.resp_msg || '登录失败');
+ setUuid(uuidv4());
+ }
} catch (error) {
- message.error('登录失败,请重试!');
+ if (mountedRef.current) {
+ message.error('登录失败,请重试!');
+ }
} finally {
- setLoading(false);
+ if (mountedRef.current) {
+ setLoading(false);
+ }
}
};
@@ -151,6 +169,10 @@ const Login: React.FC = () => {
onClick={() => setUuid(uuidv4())}
/>
)}
+ onGetCaptcha={async () => {
+ // 由于我们使用的是图片验证码,这里不需要实现
+ return Promise.resolve();
+ }}
rules={[
{
required: true,
diff --git a/zlt-web/react-web/src/main/frontend/src/services/login/typings.d.ts b/zlt-web/react-web/src/main/frontend/src/services/login/typings.d.ts
index e0835d3f..fc231cb9 100644
--- a/zlt-web/react-web/src/main/frontend/src/services/login/typings.d.ts
+++ b/zlt-web/react-web/src/main/frontend/src/services/login/typings.d.ts
@@ -6,12 +6,14 @@ declare namespace API {
resp_code?: number;
resp_msg?: number;
datas?: T[];
+ data?: T;
};
type OptionalResult = {
resp_code?: number;
resp_msg?: number;
datas?: T;
+ data?: T;
};
type CurrentUser = SYSTEM.User & {
diff --git a/zlt-web/react-web/src/main/frontend/src/services/message/api.ts b/zlt-web/react-web/src/main/frontend/src/services/message/api.ts
index 4ab54c05..c282c431 100644
--- a/zlt-web/react-web/src/main/frontend/src/services/message/api.ts
+++ b/zlt-web/react-web/src/main/frontend/src/services/message/api.ts
@@ -3,7 +3,7 @@ import { request } from 'umi';
/** 获取消息列表 */
export async function getMessages(params: any) {
const { current, pageSize, ...restParams } = params;
- return request>('/api-order/messages', {
+ return request>('/api-order/messages', {
method: 'GET',
params: {
page: params.page || 1,