// 获取当前时间
const currentTime = () => {
var date = new Date();
var year = date.getFullYear(); //月份从0~11,所以+1
let month = date.getMonth();
console.log("month", month);
var currentDateArr = [
date.getMonth() + 1,
date.getDate(),
date.getHours(),
date.getMinutes(),
date.getSeconds(),
];
//如果格式是MM则需要此步骤,如果是M格式则此循环注释掉
for (var i = 0; i < currentDateArr.length; i++) {
if (currentDateArr[i] >= 1 && currentDateArr[i] <= 9) {
currentDateArr[i] = "0" + currentDateArr[i];
}
}
var currentDate =year +"-" +currentDateArr[0] + "-" + currentDateArr[1]+" " +currentDateArr[2] +":" +currentDateArr[3] +":" +currentDateArr[4];
console.log("currentDate", currentDate);
};
// 时间戳转化为年月日
const timeFormate = (timeStamp) => {
let year = new Date(timeStamp).getFullYear();
let month = new Date(timeStamp).getMonth() + 1 < 10 ? "0" + (new Date(timeStamp).getMonth() + 1) : new Date(timeStamp).getMonth() + 1;
let date = new Date(timeStamp).getDate() < 10 ? "0" + new Date(timeStamp).getDate() : new Date(timeStamp).getDate();
let hh = new Date(timeStamp).getHours() < 10 ? "0" + new Date(timeStamp).getHours() : new Date(timeStamp).getHours();
let mm = new Date(timeStamp).getMinutes() < 10 ? "0" + new Date(timeStamp).getMinutes() : new Date(timeStamp).getMinutes();
let ss = new Date(timeStamp).getSeconds() < 10 ? "0" + new Date(timeStamp).getSeconds() : new Date(timeStamp).getSeconds();
return year + "-" + month + "-" + date + "" + " " + hh + ":" + mm + ":" + ss
}
//时间戳转为几天-几个小时-几分钟-几秒
getTimeLongDisc(timeMS) {
if(timeMS<=0){
return "0秒";
}
const days = timeMS / 1000 / 60 / 60 / 24;
const daysRound = Math.floor(days);
const hours = timeMS/ 1000 / 60 / 60 - (24 * daysRound);
const hoursRound = Math.floor(hours);
const minutes = timeMS / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
const minutesRound = Math.floor(minutes);
const seconds = timeMS/ 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
const secondsRound = Math.floor(seconds);
let resultDisc="";
if(daysRound > 0){
resultDisc+=daysRound+"天";
if(hoursRound>0){
resultDisc+=hoursRound+"时";
}
}else {
if(hoursRound>0){
resultDisc+=hoursRound+"时";
if(minutesRound>0){
resultDisc+=minutesRound+"分";
}
}else {
if(minutesRound>0){
resultDisc+=minutesRound+"分";
}
resultDisc+=secondsRound+"秒";
}
}
return resultDisc;
}
// 保留几位小数
export function formatDecimalFraction(num, decimalPlaces) {
// 如果是整数,保持原状
if (Number.isInteger(num)) {
return num.toString();
} else {
// 如果是小数,根据传入的小数位数保留相应位数
if (typeof decimalPlaces === 'number' && decimalPlaces >= 0) {
return num.toFixed(decimalPlaces);
} else {
// 默认保留一位小数
return num.toFixed(1);
}
}
}
// 数字添加千分号
export function formatNumber(number) {
if (typeof number === 'number') {
// 如果是数字类型,先转换为字符串
number = number.toString();
} else if (typeof number !== 'string') {
// 如果不是数字或字符串类型,返回原始值
return number;
}
// 使用正则表达式添加千分位逗号
return number.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
//当input框类型为number 值为0时,点击input框内容为空
<el-input v-model="reportData.reportCount" type="number" @focus="reportCheckFrequencyFunction(reportData.reportCount)" />
const reportCheckFrequencyFunction = () => {
if (reportData.reportCount == 0) {
reportData.reportCount = ''
}
}
//判断数组对象里的某一个值是否全部相同
arr.flat().every(item => item.type === 4)
//数组转字符串
arr.join(',')
//判断input框里面是否全为空格
if (passward.value.replace(/(^\s*)|(\s*$)/g, "") == "") {
console.log("未输入或者输入为空格");
} else {
console.log("输入:", userNewSet.password);
}
//input框不能输入小数点
<el-input type="number" @input="handleInput" :step="1" :min="1" v-model="modelReportData.reportCount" />
const handleInput = (value) => {
console.log('v',value)
if(value.includes('.')){
modelReportData.reportCount = parseInt(value)
}
};
//onkeyup="value=value.replace(/[^\d]/g,'')" 只允许输入数字(整数:小数点不能输入)
//onkeyup="value=value.replace(/^\D (\d (?:.\d{0,2})?). 1')" 允许输入小数(两位小数)
//onkeyup="value=value.replace(/^\D (\d (?:.\d{0,1})?). 1')" 允许输入小数(1位小数)
//onkeyup="value=value.replace(/[ \d]/g,'').replace(/ 0{1,}/g,'')" 开头不能为0,且不能输入小数
//在表格中使用input 为空时该值为0
// @blur="blurNumber(row)"
const blurNumber=(row)=>{
if(!row.unclearCount){
row.unclearCount=0
}else{
row.unclearCount=row.unclearCount*1
}
}
截取最后一个特殊字符后面的全部内容
字符串.substring(字符串.lastIndexOf("/")+1);
判断数组中的某个字段是否全部相同
multipleSelectionList.value.flat().every((item) => item.purchaseType === 2
后面会继续补充