118 lines
2.9 KiB
JavaScript
Raw Normal View History

2025-04-14 10:57:27 +08:00
import Base64 from './base64';
export const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}
export const formatNumber = n => {
n = n.toString()
return n[1] ? n : `0${n}`
}
export const getGUID = () => {
let guid = "";
for (let ii = 1; ii <= 32; ii++) {
let n = Math.floor(Math.random() * 16.0).toString(16).toUpperCase();
guid += n;
if ((ii == 8) || (ii == 12) || (ii == 16) || (ii == 20)) guid += "-";
}
return guid.toUpperCase();
}
// 显示消息提示框
export const showMessage = (title, icon, time) => {
uni.showToast({
title: title,
icon: icon,
duration: time
});
}
// 显示 loading 提示框。需主动调用 uni.hideLoading 才能关闭提示框
export const loading = (title, time) => {
if (time == null) time = 5000;
uni.showLoading(title);
if (time && time != false) {
setTimeout(function() {
uni.hideLoading();
}, time);
}
}
// 显示模态提示框
export const showModelMessage = (content, title, showCancel, confirmText = "确定") => {
if (title == null || title == "") title = "提示";
if (showCancel == null) showCancel = false;
return new Promise((resolve, reject) => {
uni.showModal({
title,
content,
showCancel,
confirmText,
success: function(res) {
resolve(res);
}
});
});
}
export function dataFormat(date, fmt) {
var o = {
"M+": date.getMonth() + 1, //月份
"d+": date.getDate(), //日
"H+": date.getHours(), //小时
"m+": date.getMinutes(), //分
"s+": date.getSeconds(), //秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"S": date.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : ((
"00" + o[k]).substr(("" + o[k]).length)));
}
return fmt;
}
//格式话长日期
export function longToDateFormat(value) {
return value ? dataFormat((new Date(value)), 'yyyy-MM-dd') : "";
};
//格式话长日期(有时间)
export function longToDateFormatTime(value) {
return value ? dataFormat((new Date(value)), 'yyyy-MM-dd HH:mm:ss') : "";
};
export function base64Encode(text) {
return Base64.encode(text);
}
export function base64Decode(text) {
return Base64.decode(text);
}
export function getUrlParams(url) {
const paramsRegex = /[?&]+([^=&]+)=([^&]*)/gi;
const params = {};
let match;
while (match = paramsRegex.exec(url)) {
params[match[1]] = match[2];
}
return params;
}
export function isNullOrEmpty(value){
if(typeof(value) == "undefined" || value == null || value == "")
return true;
else
return false;
}