message.js
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* eslint-disable */
import { Modal, message as antdMessage } from 'antd';
import { Modal as mobileModal } from 'antd-mobile';
const { warning } = Modal;
const antdMobileAlert = mobileModal.alert;
let debounceCount;
let secondContent = [];
let width;
const queryWidth = () => {
width = document?.documentElement?.getBoundingClientRect()?.width <= 750 ? '80%' : 500;
}
const openConfirm = (config) => {
queryWidth();
const { message, ...rest } = config;
secondContent.push(<p style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word' }}>{message}</p>)
if (debounceCount) {
clearTimeout(debounceCount);
};
const fn = () => {
if (location.pathname.toLocaleLowerCase().includes('mobile')) {
antdMobileAlert('温馨提示', secondContent || '出错了', [
{ text: '确认', },
])
} else {
warning({
title: '温馨提示',
content: <div style={{ maxHeight: '50vh', overflowY: 'auto' }} >{secondContent || '出错了'}</div>,
okText: '确认',
zIndex: 1000,
width,
...rest,
});
}
}
debounceCount = setTimeout(() => {
fn();
secondContent = [];
});
};
/**
* 替换message.error信息提示方式为warning
*/
export const message = {
...antdMessage,
error: (content, ...rest) => {
openConfirm({ message: content, ...rest });
},
};