init
This commit is contained in:
62
utils/utils.js
Normal file
62
utils/utils.js
Normal file
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* yy-mm-dd
|
||||
*/
|
||||
export const dateFtt = date => {
|
||||
if (date == null) {
|
||||
return ''
|
||||
}
|
||||
let year = date.getFullYear()
|
||||
let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
||||
let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
/**
|
||||
* yy-mm-dd hh:mm:ss
|
||||
*/
|
||||
export const dateTimeFtt = date => {
|
||||
if (date == null) {
|
||||
return ''
|
||||
}
|
||||
let year = date.getFullYear()
|
||||
let month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
|
||||
let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
|
||||
let hh = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
|
||||
let mm = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
|
||||
let ss = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
|
||||
return `${year}-${month}-${day} ${hh}:${mm}:${ss}`
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串形式的日期转换成日期对象
|
||||
*/
|
||||
export const dateNew = date => {
|
||||
if (date === undefined || date === 'undefined') {
|
||||
return new Date()
|
||||
}
|
||||
return new Date(Date.parse(date))
|
||||
}
|
||||
/**
|
||||
* 二次确认弹框
|
||||
*/
|
||||
export function confirmAction(title = "确认操作", content = "确定要执行此操作吗?", confirmCallback) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.showModal({
|
||||
title: title,
|
||||
content: content,
|
||||
showCancel: true,
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
console.log("用户点击了“确定”按钮");
|
||||
resolve(true); // 调用确认回调
|
||||
if (confirmCallback) {
|
||||
confirmCallback();
|
||||
}
|
||||
} else if (res.cancel) {
|
||||
console.log("用户点击了“取消”按钮");
|
||||
resolve(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user