message.js
2.17 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
58
59
60
61
62
63
64
65
66
67
68
69
70
/* eslint-disable */
import { Modal, message as antdMessage } from 'antd-v4';
import { Modal as mobileModal } from 'antd-mobile-v2';
import commonConfig from '../config';
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 = () => {
const userinfo = JSON.parse(localStorage.getItem(`${commonConfig.prefix}userinfo`)) || {};
const language = userinfo.sLanguage || 'sChinese'; // 默认简体中文
const isEnglish = language === 'sEnglish';
// 使用语言设置
const sTitle = isEnglish ? 'Reminder' : language === 'sBig5' ? '溫馨提示' : '温馨提示';
const okText = language === 'sEnglish' ? 'Confirm' : language === 'sBig5' ? '確認': '确认';
if (location.pathname.toLocaleLowerCase().includes('mobile')) {
antdMobileAlert(sTitle, secondContent || '出错了', [
{ text: '确认', },
])
} else {
warning({
title: sTitle,
content: <div style={{ maxHeight: '50vh', overflowY: 'auto' }} >{secondContent || '出错了'}</div>,
okText: okText,
zIndex: 1000,
width,
...rest,
});
}
}
debounceCount = setTimeout(() => {
fn();
secondContent = [];
});
};
/**
* 替换message.error信息提示方式为warning
*/
export const message = {
...antdMessage,
error: (content, ...rest) => {
const userinfo = JSON.parse(localStorage.getItem(`${commonConfig.prefix}userinfo`)) || {};
const language = userinfo.sLanguage || 'sChinese'; // 默认简体中文
const requiredText = language === 'sEnglish' ? 'is Required' :
(language === 'sBig5' ? '為必填項' : '为必填项');
const sContent = content?.replace('为必填项', requiredText);
openConfirm({ message: sContent, ...rest });
},
};