// 返回单位
|
export const formatNumber = (num) => {
|
if (num >= 100000000) {
|
return (num / 100000000).toFixed(1) + "亿";
|
} else if (num >= 10000 && num < 100000000) {
|
return (num / 10000).toFixed(1) + "w";
|
} else if (num >= 1000) {
|
return (num / 1000).toFixed(1) + "k";
|
} else {
|
return num.toString();
|
}
|
}
|
|
// 安卓苹果日期格式转换
|
export const dateConversion = (date) => {
|
const systemInfo = uni.getSystemInfoSync();
|
if (systemInfo.osName === 'ios') {
|
return date.replace(/-/g, "/")
|
} else {
|
return date
|
}
|
}
|
|
/**
|
* 将手机号中间四位替换为*
|
* @param {string} phone - 手机号
|
* @returns {string} 格式化后的手机号
|
*/
|
export const formatPhoneStar = (phone) => {
|
if (!phone) return ''
|
|
// 移除非数字字符
|
const cleaned = phone.replace(/\D/g, '')
|
|
// 检查是否为11位手机号
|
if (cleaned.length !== 11) {
|
console.warn('手机号长度不正确')
|
return phone // 或者返回 cleaned,根据需求
|
}
|
|
// 保留前3位和后4位,中间4位用*代替
|
return cleaned.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
|
}
|