// 返回单位
|
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
|
}
|
}
|
|
|
/**
|
* 获取两个时间段的所有选项,步长为15分钟
|
* @param {*} startTime 开始时间 时间格式为 12:00
|
* @param {*} endTime 结束时间 时间格式为 12:00
|
* 返回 可选的数组
|
*/
|
export const getOptions = (startTime, endTime) => {
|
const timeMap = {
|
'00': 0,
|
'15': 1,
|
'30': 2,
|
'45': 3
|
}
|
const numTotimeMap = ['00', '15', '30', '45']
|
let [startHours, startMin] = startTime.split(':')
|
let [endHours, endMin] = endTime.split(':')
|
let len = endHours - startHours
|
let res = []
|
for (let i = 0; i < len + 1; i++) {
|
let num = (i === 0 ? timeMap[startMin] : 0)
|
let inlen = (i === len) ? timeMap[endMin] + 1 : 4
|
for (let q = num; q < inlen; q++) {
|
let hours = parseInt(startHours) + parseInt(i)
|
let item = `${hours}:${numTotimeMap[q]}`
|
res.push(item)
|
}
|
}
|
return res;
|
}
|
|
// 对比时段大小
|
export const compareTime = (time1, time2) => {
|
// 假设时间格式为 "HH:MM"
|
const [hours1, minutes1] = time1.split(':').map(Number);
|
const [hours2, minutes2] = time2.split(':').map(Number);
|
|
// 转换为总分钟数
|
const totalMinutes1 = hours1 * 60 + minutes1;
|
const totalMinutes2 = hours2 * 60 + minutes2;
|
|
if (totalMinutes1 < totalMinutes2) {
|
return -1; // time1较小
|
} else if (totalMinutes1 > totalMinutes2) {
|
return 1; // time2较小
|
} else {
|
return 0; // 相等
|
}
|
}
|
|
// 获取当前时分
|
export const getCurrentTimeWithZeroes = () => {
|
const now = new Date();
|
return now.toLocaleTimeString('en-US', {
|
hour12: false,
|
hour: '2-digit',
|
minute: '2-digit'
|
});
|
}
|
|
// 获取当天年月日
|
export const getFormattedDate = () => {
|
const date = new Date();
|
const year = date.getFullYear();
|
const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份是从0开始的,所以+1
|
const day = date.getDate().toString().padStart(2, '0');
|
return `${year}-${month}-${day}`;
|
}
|
|
// 判断接单日期
|
export const getDayType = (days) => {
|
const weekdays = [1, 2, 3, 4, 5];
|
const weekends = [6, 7];
|
|
if (days.every(day => weekdays.includes(day))) {
|
return "周内";
|
} else if (days.every(day => weekends.includes(day))) {
|
return "周末";
|
} else if (days.every(day => weekdays.includes(day) || weekends.includes(day))) {
|
return "整周";
|
}
|
}
|
|
// 返回评分说明
|
export const returnUserRating = (userRating) => {
|
if (userRating > 4 && userRating <= 5) {
|
return '超棒'
|
} else if (userRating > 3 && userRating <= 4) {
|
return '很好'
|
} else if (userRating > 2 && userRating <= 3) {
|
return '一般'
|
} else if (userRating >= 0 && userRating <= 2) {
|
return '很差'
|
}
|
}
|
|
// 返回回复时长文字
|
export const rhuifuTimeName = (responseTime) => {
|
if (responseTime >= 0 && responseTime <= 10) {
|
return '回复很快'
|
} else if (responseTime > 10 && responseTime <= 30) {
|
return '回复一般'
|
} else {
|
return '回复较慢'
|
}
|
}
|