|
@@ -57,13 +57,16 @@ export function getNewsShareUrl(id: number | string = 0) {
|
|
|
* @param text
|
|
* @param text
|
|
|
* @returns
|
|
* @returns
|
|
|
*/
|
|
*/
|
|
|
-export function formatHtmlString(text: string) {
|
|
|
|
|
- const html = text.replace(/[\n\r]/g, '<br />')
|
|
|
|
|
- return html.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, (match, capture) => {
|
|
|
|
|
- // 替换img标签src地址为绝对路径
|
|
|
|
|
- const url = getUrl(capture)
|
|
|
|
|
- return `<img src="${url.href}" alt=""/>`
|
|
|
|
|
- })
|
|
|
|
|
|
|
+export function formatHtmlString(text?: string) {
|
|
|
|
|
+ if (text) {
|
|
|
|
|
+ const html = text.toString().replace(/[\n\r]/g, '<br />')
|
|
|
|
|
+ return html.replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, (match, capture) => {
|
|
|
|
|
+ // 替换img标签src地址为绝对路径
|
|
|
|
|
+ const url = getUrl(capture)
|
|
|
|
|
+ return `<img src="${url.href}" alt=""/>`
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ return ''
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -173,12 +176,12 @@ export function round(value: number, precision = 2) {
|
|
|
* @param exponent
|
|
* @param exponent
|
|
|
* @returns
|
|
* @returns
|
|
|
*/
|
|
*/
|
|
|
-export function pow(base:number, exponent:number) {
|
|
|
|
|
- let result = 1;
|
|
|
|
|
- for (let i = 0; i < Math.abs(exponent); i++) {
|
|
|
|
|
|
|
+export function pow(base: number, exponent: number) {
|
|
|
|
|
+ let result = 1;
|
|
|
|
|
+ for (let i = 0; i < Math.abs(exponent); i++) {
|
|
|
result *= base
|
|
result *= base
|
|
|
- }
|
|
|
|
|
- if (exponent < 0) {
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ if (exponent < 0) {
|
|
|
return 1 / result
|
|
return 1 / result
|
|
|
}
|
|
}
|
|
|
return result
|
|
return result
|
|
@@ -239,7 +242,7 @@ export function formatDate(value?: string, format = 'YYYY-MM-DD HH:mm:ss') {
|
|
|
* @param format
|
|
* @param format
|
|
|
* @returns
|
|
* @returns
|
|
|
*/
|
|
*/
|
|
|
-export function displayname(item?: Model.Marketsectionconfignew ) {
|
|
|
|
|
|
|
+export function displayname(item?: Model.Marketsectionconfignew) {
|
|
|
switch (i18n.global.locale) {
|
|
switch (i18n.global.locale) {
|
|
|
case 'zh-CN':
|
|
case 'zh-CN':
|
|
|
return item?.displayname ?? ''
|
|
return item?.displayname ?? ''
|
|
@@ -269,10 +272,10 @@ export function diffDays(value?: string) {
|
|
|
* @returns
|
|
* @returns
|
|
|
*/
|
|
*/
|
|
|
export function formatMsgDate(value?: string) {
|
|
export function formatMsgDate(value?: string) {
|
|
|
- if ( moment(value).isSame(moment(), "day") ) {
|
|
|
|
|
|
|
+ if (moment(value).isSame(moment(), "day")) {
|
|
|
return formatDate(value, 'HH:mm:ss')
|
|
return formatDate(value, 'HH:mm:ss')
|
|
|
} else if (moment(value).isSame(moment().subtract(1, 'day'), "day")) {
|
|
} else if (moment(value).isSame(moment().subtract(1, 'day'), "day")) {
|
|
|
- return formatDate(value, '昨日 '+'HH:mm:ss')
|
|
|
|
|
|
|
+ return formatDate(value, '昨日 ' + 'HH:mm:ss')
|
|
|
} else {
|
|
} else {
|
|
|
return formatDate(value, 'YYYY-MM-DDs')
|
|
return formatDate(value, 'YYYY-MM-DDs')
|
|
|
}
|
|
}
|
|
@@ -402,23 +405,23 @@ export function getIdCardAge(cardnum: string) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 金额转大写
|
|
// 金额转大写
|
|
|
-export function numberToChinese(num: undefined | string) {
|
|
|
|
|
|
|
+export function numberToChinese(num: undefined | string) {
|
|
|
/// 数据错误
|
|
/// 数据错误
|
|
|
- if (num === null) { return '' }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if (num === null) { return '' }
|
|
|
|
|
+
|
|
|
const chineseNums = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
const chineseNums = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
|
|
|
const unitSection = ['', '拾', '佰', '仟'];
|
|
const unitSection = ['', '拾', '佰', '仟'];
|
|
|
const bigSection = ['', '万', '亿'];
|
|
const bigSection = ['', '万', '亿'];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 将金额转换为字符串并确保去除前导零
|
|
// 将金额转换为字符串并确保去除前导零
|
|
|
let amountStr = String(num).replace(/^0*(\d+)/, '$1')
|
|
let amountStr = String(num).replace(/^0*(\d+)/, '$1')
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 处理小数部分(可选)
|
|
// 处理小数部分(可选)
|
|
|
let decimalPart = ''
|
|
let decimalPart = ''
|
|
|
if (amountStr.includes('.')) {
|
|
if (amountStr.includes('.')) {
|
|
|
- const parts = amountStr.split('.')
|
|
|
|
|
- amountStr = parts[0]
|
|
|
|
|
- decimalPart = '.' + parts[1].padEnd(2, '0') // 假设最多两位小数
|
|
|
|
|
|
|
+ const parts = amountStr.split('.')
|
|
|
|
|
+ amountStr = parts[0]
|
|
|
|
|
+ decimalPart = '.' + parts[1].padEnd(2, '0') // 假设最多两位小数
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 转换小数部分
|
|
// 转换小数部分
|
|
@@ -431,17 +434,17 @@ export function numberToChinese(num: undefined | string) {
|
|
|
// 遍历整数部分进行转换
|
|
// 遍历整数部分进行转换
|
|
|
let result = '';
|
|
let result = '';
|
|
|
for (let i = amountStr.length - 1; i >= 0; i--) {
|
|
for (let i = amountStr.length - 1; i >= 0; i--) {
|
|
|
- result = chineseNums[parseInt(amountStr[i])] + unitSection[amountStr.length - 1 - i] + result
|
|
|
|
|
- // 在万和亿的分隔处添加单位
|
|
|
|
|
- if ((amountStr.length - i - 1) % 4 === 0 && i !== 0) {
|
|
|
|
|
- result = bigSection[(amountStr.length - i - 1) / 4] + result
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ result = chineseNums[parseInt(amountStr[i])] + unitSection[amountStr.length - 1 - i] + result
|
|
|
|
|
+ // 在万和亿的分隔处添加单位
|
|
|
|
|
+ if ((amountStr.length - i - 1) % 4 === 0 && i !== 0) {
|
|
|
|
|
+ result = bigSection[(amountStr.length - i - 1) / 4] + result
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 去除末尾的零
|
|
// 去除末尾的零
|
|
|
result = result.replace(/零+$/, '零')
|
|
result = result.replace(/零+$/, '零')
|
|
|
// 添加分隔符“元”和小数部分的大写
|
|
// 添加分隔符“元”和小数部分的大写
|
|
|
result = result.replace(/亿万/, '亿零') + '元' + decimalPart
|
|
result = result.replace(/亿万/, '亿零') + '元' + decimalPart
|
|
|
|
|
|
|
|
return result.trim()
|
|
return result.trim()
|
|
|
- }
|
|
|
|
|
|
|
+}
|