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[345678]\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; } }