From e28d84dc6b2f5413f0170c0aa06b0077ad562c9a Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Mon, 24 May 2021 23:29:35 +0800 Subject: [PATCH] =?UTF-8?q?antd=20notification=E6=94=B9=E4=B8=BAmessage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/loaders/initData.ts | 2 +- src/layouts/index.less | 10 ++++++++++ src/pages/config/index.tsx | 10 ++++------ src/pages/cookie/index.tsx | 28 +++++++++------------------- src/pages/cookie/modal.tsx | 12 ++++-------- src/pages/crontab/index.tsx | 34 +++++++++------------------------- src/pages/crontab/modal.tsx | 10 +++------- src/pages/diff/index.tsx | 2 +- src/pages/diy/index.tsx | 6 ++---- src/pages/log/index.tsx | 2 +- src/pages/login/index.tsx | 10 +++------- src/utils/http.ts | 8 ++++---- 12 files changed, 51 insertions(+), 83 deletions(-) diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index 99485edf..927df7f5 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -12,7 +12,7 @@ const initData = [ 6, 1, ).toString()} * * *`, - status: CrontabStatus.idle, + status: CrontabStatus.disabled, }, { name: '删除日志', diff --git a/src/layouts/index.less b/src/layouts/index.less index 01730bfa..d9cc761e 100644 --- a/src/layouts/index.less +++ b/src/layouts/index.less @@ -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; diff --git a/src/pages/config/index.tsx b/src/pages/config/index.tsx index 763d59f3..0b2ad1c9 100644 --- a/src/pages/config/index.tsx +++ b/src/pages/config/index.tsx @@ -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'; @@ -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)); @@ -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); }); }; diff --git a/src/pages/cookie/index.tsx b/src/pages/cookie/index.tsx index 70e7a5fc..0624aae8 100644 --- a/src/pages/cookie/index.tsx +++ b/src/pages/cookie/index.tsx @@ -1,7 +1,7 @@ import React, { useCallback, useRef, useState, useEffect } from 'react'; import { Button, - notification, + message, Modal, Table, Tag, @@ -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('更新状态失败'); } }); }; @@ -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]; @@ -274,9 +272,7 @@ const Config = () => { }); setValue(result); } else { - notification.error({ - message: data, - }); + message.error(data); } }); }, @@ -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); } }); }, @@ -377,9 +369,7 @@ const Config = () => { }) .then((data: any) => { if (data.code !== 200) { - notification.error({ - message: data, - }); + message.error(data); } }); }, diff --git a/src/pages/cookie/modal.tsx b/src/pages/cookie/modal.tsx index a735e0ee..5459d5de 100644 --- a/src/pages/cookie/modal.tsx +++ b/src/pages/cookie/modal.tsx @@ -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'; @@ -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; } @@ -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); diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index df841b03..4baad979 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -1,7 +1,7 @@ import React, { PureComponent, Fragment, useState, useEffect } from 'react'; import { Button, - notification, + message, Modal, Table, Tag, @@ -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); } }); }, @@ -274,9 +270,7 @@ const Crontab = () => { }); setValue(result); } else { - notification.error({ - message: data, - }); + message.error(data); } }); }, @@ -311,9 +305,7 @@ const Crontab = () => { }); setValue(result); } else { - notification.error({ - message: data, - }); + message.error(data); } }); }, @@ -356,9 +348,7 @@ const Crontab = () => { }); setValue(result); } else { - notification.error({ - message: data, - }); + message.error(data); } }); }, @@ -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); } }); }, @@ -515,9 +501,7 @@ const Crontab = () => { if (data.code === 200) { getCrons(); } else { - notification.error({ - message: data, - }); + message.error(data); } }); }, diff --git a/src/pages/crontab/modal.tsx b/src/pages/crontab/modal.tsx index 6163afb7..f365ee3e 100644 --- a/src/pages/crontab/modal.tsx +++ b/src/pages/crontab/modal.tsx @@ -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'; @@ -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); diff --git a/src/pages/diff/index.tsx b/src/pages/diff/index.tsx index 43ff3d28..e5d79a0c 100644 --- a/src/pages/diff/index.tsx +++ b/src/pages/diff/index.tsx @@ -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'; diff --git a/src/pages/diy/index.tsx b/src/pages/diy/index.tsx index 21879f03..92440e79 100644 --- a/src/pages/diy/index.tsx +++ b/src/pages/diy/index.tsx @@ -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'; @@ -28,9 +28,7 @@ const Crontab = () => { data: { content: value, name: 'extra.sh' }, }) .then((data) => { - notification.success({ - message: data.msg, - }); + message.success(data.msg); }); }; diff --git a/src/pages/log/index.tsx b/src/pages/log/index.tsx index ff65a8a2..9bc8b238 100644 --- a/src/pages/log/index.tsx +++ b/src/pages/log/index.tsx @@ -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'; diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index fe4cf969..ca67de21 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -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'; @@ -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) { diff --git a/src/utils/http.ts b/src/utils/http.ts index a2aa0024..7c473e6e 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -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(); @@ -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); }