import ajax from '@/utils/request.js' export default { getuid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); }, // 提示信息 toast(msg, icon = 'none', duration = 2000, mask) { uni.showToast({ "icon": icon, "title": msg, "mask": mask || false, "duration": duration }) }, showLoading(msg) { uni.showLoading({ 'title': msg, 'mask': true }) }, hidingLoading() { uni.hideLoading(); }, // 提示信息 底部 toastBottom(msg, icon = 'none', duration = 2000, mask = false) { uni.showToast({ "icon": icon, "title": msg, "mask": mask, "duration": duration, "position": 'bottom' }) }, // 路由跳转 to(url) { uni.navigateTo({ url: url, animationType: 'slide-in-right', animationDuration: 300 }) }, toBar(url) { uni.switchTab({ url: url }) }, // 返回上一页 back() { uni.navigateBack({ delta: 1, animationType: 'pop-out', animationDuration: 200 }) }, // 验证邮箱 isEmail(email) { let reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/; if (!reg.test(email)) { this.$common.toast('请输入正确邮箱格式') } return reg.test(email) }, // 正则验证是否为手机号 isPhone(str) { str = str + ''; if ((/^1[3456789]\d{9}$/.test(str))) { return true; } return false; }, isNum(str) { str = str + ''; if ((/^[0-9]*$/.test(str)) || (/^[0-9]+(.[0-9]{1})?$/.test(str))) { return true; } return false; }, isCarNo(str) { str = str + ''; let reg = /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/ if (reg.test(str)) { return true; } return false; }, removeNull(obj) { var newObj = {}; if (obj != undefined && obj != null) { for (var key in obj) { if (obj[key] === undefined || obj[key] === null || obj[key] === '') { // } else { newObj[key] = obj[key]; } } } return newObj; }, isAuth(code) { let list = uni.getStorageSync('perList'); return list.indexOf(code) !== -1; }, // 将时间戳转化为指定时间 // way:方式(1=年月日,2=年月日时分秒)默认1, 也可以指定格式:yyyy-MM-dd HH:mm:ss forDate(inputTime, way) { var date = new Date(inputTime); var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? ('0' + m) : m; var d = date.getDate(); d = d < 10 ? ('0' + d) : d; var h = date.getHours(); h = h < 10 ? ('0' + h) : h; var minute = date.getMinutes(); var second = date.getSeconds(); minute = minute < 10 ? ('0' + minute) : minute; second = second < 10 ? ('0' + second) : second; var ms = date.getMilliseconds(); way = way || 1; // way == 1 年月日 if (way === 1) { return y + '-' + m + '-' + d; } // way == 1 年月日时分秒 if (way === 2) { return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second; } // way == 具体格式 标准格式: yyyy-MM-dd HH:mm:ss if (typeof way == 'string') { return way.replace("yyyy", y).replace("MM", m).replace("dd", d).replace("HH", h).replace("mm", minute).replace("ss", second).replace("ms", ms); } return y + '-' + m + '-' + d; } }