Skip to content

Commit

Permalink
antd notification改为message
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhh committed May 24, 2021
1 parent d650a60 commit 7116fbd
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 83 deletions.
2 changes: 1 addition & 1 deletion back/loaders/initData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const initData = [
6,
1,
).toString()} * * *`,
status: CrontabStatus.idle,
status: CrontabStatus.disabled,
},
{
name: '删除日志',
Expand Down
10 changes: 10 additions & 0 deletions src/layouts/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ body {

@import '~codemirror/lib/codemirror.css';

.CodeMirror {
height: auto;
}

.CodeMirror-scroll {
height: auto;
overflow-y: hidden;
overflow-x: auto;
}

.ql-container-wrapper {
.CodeMirror {
position: absolute;
Expand Down
10 changes: 4 additions & 6 deletions src/pages/config/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { PureComponent, Fragment, useState, useEffect } from 'react';
import { Button, notification, Modal } from 'antd';
import { Button, message, Modal } from 'antd';
import config from '@/utils/config';
import { PageContainer } from '@ant-design/pro-layout';
import { Controlled as CodeMirror } from 'react-codemirror2';
Expand All @@ -16,7 +16,7 @@ const Config = () => {
setLoading(true);
request
.get(`${config.apiPrefix}config/config`)
.then((data) => {
.then((data: any) => {
setValue(data.data);
})
.finally(() => setLoading(false));
Expand All @@ -27,10 +27,8 @@ const Config = () => {
.post(`${config.apiPrefix}save`, {
data: { content: value, name: 'config.sh' },
})
.then((data) => {
notification.success({
message: data.msg,
});
.then((data: any) => {
message.success(data.msg);
});
};

Expand Down
28 changes: 9 additions & 19 deletions src/pages/cookie/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useRef, useState, useEffect } from 'react';
import {
Button,
notification,
message,
Modal,
Table,
Tag,
Expand Down Expand Up @@ -230,7 +230,7 @@ const Config = () => {
(value as any).splice(index, 1, data.data);
setValue([...(value as any)] as any);
} else {
notification.error({ message: '更新状态失败' });
message.error('更新状态失败');
}
});
};
Expand Down Expand Up @@ -260,11 +260,9 @@ const Config = () => {
)
.then((data: any) => {
if (data.code === 200) {
notification.success({
message: `${
record.status === Status.已禁用 ? '启用' : '禁用'
}成功`,
});
message.success(
`${record.status === Status.已禁用 ? '启用' : '禁用'}成功`,
);
const newStatus =
record.status === Status.已禁用 ? Status.未获取 : Status.已禁用;
const result = [...value];
Expand All @@ -274,9 +272,7 @@ const Config = () => {
});
setValue(result);
} else {
notification.error({
message: data,
});
message.error(data);
}
});
},
Expand Down Expand Up @@ -313,16 +309,12 @@ const Config = () => {
.delete(`${config.apiPrefix}cookies`, { data: [record._id] })
.then((data: any) => {
if (data.code === 200) {
notification.success({
message: '删除成功',
});
message.success('删除成功');
const result = [...value];
result.splice(index, 1);
setValue(result);
} else {
notification.error({
message: data,
});
message.error(data);
}
});
},
Expand Down Expand Up @@ -377,9 +369,7 @@ const Config = () => {
})
.then((data: any) => {
if (data.code !== 200) {
notification.error({
message: data,
});
message.error(data);
}
});
},
Expand Down
12 changes: 4 additions & 8 deletions src/pages/cookie/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { Modal, notification, Input, Form } from 'antd';
import { Modal, message, Input, Form } from 'antd';
import { request } from '@/utils/http';
import config from '@/utils/config';

Expand All @@ -22,7 +22,7 @@ const CookieModal = ({
let flag = false;
for (const coo of cookies) {
if (!/pt_key=\S*;\s*pt_pin=\S*;\s*/.test(coo)) {
notification.error({ message: `${coo}格式有误` });
message.error(`${coo}格式有误`);
flag = true;
break;
}
Expand All @@ -37,13 +37,9 @@ const CookieModal = ({
data: payload,
});
if (code === 200) {
notification.success({
message: cookie ? '更新Cookie成功' : '添加Cookie成功',
});
message.success(cookie ? '更新Cookie成功' : '添加Cookie成功');
} else {
notification.error({
message: data,
});
message.error(data);
}
setLoading(false);
handleCancel(cookie ? [data] : data);
Expand Down
34 changes: 9 additions & 25 deletions src/pages/crontab/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PureComponent, Fragment, useState, useEffect } from 'react';
import {
Button,
notification,
message,
Modal,
Table,
Tag,
Expand Down Expand Up @@ -231,16 +231,12 @@ const Crontab = () => {
.delete(`${config.apiPrefix}crons`, { data: [record._id] })
.then((data: any) => {
if (data.code === 200) {
notification.success({
message: '删除成功',
});
message.success('删除成功');
const result = [...value];
result.splice(index, 1);
setValue(result);
} else {
notification.error({
message: data,
});
message.error(data);
}
});
},
Expand Down Expand Up @@ -274,9 +270,7 @@ const Crontab = () => {
});
setValue(result);
} else {
notification.error({
message: data,
});
message.error(data);
}
});
},
Expand Down Expand Up @@ -311,9 +305,7 @@ const Crontab = () => {
});
setValue(result);
} else {
notification.error({
message: data,
});
message.error(data);
}
});
},
Expand Down Expand Up @@ -356,9 +348,7 @@ const Crontab = () => {
});
setValue(result);
} else {
notification.error({
message: data,
});
message.error(data);
}
});
},
Expand Down Expand Up @@ -484,15 +474,11 @@ const Crontab = () => {
.delete(`${config.apiPrefix}crons`, { data: selectedRowIds })
.then((data: any) => {
if (data.code === 200) {
notification.success({
message: '批量删除成功',
});
message.success('批量删除成功');
setSelectedRowIds([]);
getCrons();
} else {
notification.error({
message: data,
});
message.error(data);
}
});
},
Expand All @@ -515,9 +501,7 @@ const Crontab = () => {
if (data.code === 200) {
getCrons();
} else {
notification.error({
message: data,
});
message.error(data);
}
});
},
Expand Down
10 changes: 3 additions & 7 deletions src/pages/crontab/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { Modal, notification, Input, Form } from 'antd';
import { Modal, message, Input, Form } from 'antd';
import { request } from '@/utils/http';
import config from '@/utils/config';
import cronParse from 'cron-parser';
Expand Down Expand Up @@ -27,13 +27,9 @@ const CronModal = ({
data: payload,
});
if (code === 200) {
notification.success({
message: cron ? '更新Cron成功' : '添加Cron成功',
});
message.success(cron ? '更新Cron成功' : '添加Cron成功');
} else {
notification.error({
message: data,
});
message.error(data);
}
setLoading(false);
handleCancel(data);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/diff/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { PureComponent, Fragment, useState, useEffect } from 'react';
import { Button, notification, Modal } from 'antd';
import { Button, message, Modal } from 'antd';
import config from '@/utils/config';
import { PageContainer } from '@ant-design/pro-layout';
import { request } from '@/utils/http';
Expand Down
6 changes: 2 additions & 4 deletions src/pages/diy/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { PureComponent, Fragment, useState, useEffect } from 'react';
import { Button, notification, Modal } from 'antd';
import { Button, message, Modal } from 'antd';
import config from '@/utils/config';
import { PageContainer } from '@ant-design/pro-layout';
import { Controlled as CodeMirror } from 'react-codemirror2';
Expand Down Expand Up @@ -28,9 +28,7 @@ const Crontab = () => {
data: { content: value, name: 'extra.sh' },
})
.then((data) => {
notification.success({
message: data.msg,
});
message.success(data.msg);
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/pages/log/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { PureComponent, Fragment, useState, useEffect } from 'react';
import { Button, notification, Modal, TreeSelect } from 'antd';
import { Button, message, Modal, TreeSelect } from 'antd';
import config from '@/utils/config';
import { PageContainer } from '@ant-design/pro-layout';
import { Controlled as CodeMirror } from 'react-codemirror2';
Expand Down
10 changes: 3 additions & 7 deletions src/pages/login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Fragment, useEffect } from 'react';
import { Button, Row, Input, Form, notification } from 'antd';
import { Button, Row, Input, Form, message } from 'antd';
import config from '@/utils/config';
import { history, Link } from 'umi';
import styles from './index.less';
Expand All @@ -21,13 +21,9 @@ const Login = () => {
localStorage.setItem(config.authKey, data.token);
history.push('/crontab');
} else if (data.code === 100) {
notification.warn({
message: data.msg,
});
message.warn(data.msg);
} else {
notification.error({
message: data.msg,
});
message.error(data.msg);
}
})
.catch(function (error) {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/http.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { extend } from 'umi-request';
import { notification } from 'antd';
import { message } from 'antd';
import config from './config';

notification.config({
duration: 2,
message.config({
duration: 1.5,
});

const time = Date.now();
Expand All @@ -13,7 +13,7 @@ const errorHandler = function (error: any) {
? error.data.message || error.data
: error.response.statusText;
if (error.response.status !== 401 && error.response.status !== 502) {
notification.error({ message });
message.error(message);
} else {
console.log(error.response);
}
Expand Down

0 comments on commit 7116fbd

Please sign in to comment.