You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
1.8 KiB
81 lines
1.8 KiB
/*
|
|
* 公共方法
|
|
*
|
|
*/
|
|
import moment from 'moment';
|
|
|
|
const base64ToFile = (dataurl, filename = 'file') => {
|
|
let arr = dataurl.split(',')
|
|
let mime = arr[0].match(/:(.*?);/)[1]
|
|
let suffix = mime.split('/')[1]
|
|
let bstr = atob(arr[1])
|
|
let n = bstr.length
|
|
let u8arr = new Uint8Array(n)
|
|
while (n--) {
|
|
u8arr[n] = bstr.charCodeAt(n)
|
|
}
|
|
return new File([u8arr], `${filename}.${suffix}`, {
|
|
type: mime
|
|
})
|
|
|
|
}
|
|
const toast = (msg,time,callback) => {
|
|
uni.showToast({
|
|
icon: "none",
|
|
title: msg,
|
|
duration: time||1500,
|
|
success:function(res){
|
|
if(callback && typeof(callback)=='function'){
|
|
console.log(callback)
|
|
callback()
|
|
}
|
|
}
|
|
})
|
|
}
|
|
// 转换日期为日月
|
|
const formatDateToMonthDay = (dateString) => {
|
|
const month = moment(dateString).format('MM')
|
|
const day = moment(dateString).format('DD')
|
|
return `${month}月${day}日`;
|
|
}
|
|
// 比较当前时间是否在活动期间 在true 不在false
|
|
const isCurrentTimeBetween = (startTime, endTime) => {
|
|
let that = this
|
|
const now = moment().valueOf()
|
|
const start = moment(startTime).valueOf();
|
|
const end = moment(endTime).valueOf();
|
|
return now < start || now > end;
|
|
}
|
|
// 验证是否填写的是中文
|
|
const isOnlyChinese = (str)=>{
|
|
const chineseRegex = /^[\u4e00-\u9fa5]+$/;
|
|
return chineseRegex.test(str);
|
|
}
|
|
|
|
// 验证是否为空
|
|
const isNull = (p)=>{
|
|
return p == '' || p == undefined || p == null || p == 'undefined' || p == 'null';
|
|
}
|
|
|
|
// 验证手机号
|
|
const isMobile = (phoneNumber) => {
|
|
const regex = /^1[3-9]\d{9}$/;
|
|
return regex.test(phoneNumber);
|
|
}
|
|
|
|
const shareInfo = {
|
|
title:"斜塘街道基层党员冬训",
|
|
imageUrl:"/static/share.jpg"
|
|
}
|
|
|
|
export {
|
|
base64ToFile,
|
|
toast,
|
|
formatDateToMonthDay,
|
|
isCurrentTimeBetween,
|
|
isOnlyChinese,
|
|
isNull,
|
|
isMobile,
|
|
shareInfo
|
|
}
|