平板端快衣店
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.

130 lines
4.3 KiB

3 years ago
// 手机正则
3 years ago
export function reg(params1, params2) {
3 years ago
let phone = ''
let code = ''
3 years ago
3 years ago
let ret = /^1(3\d|4[5-9]|5[0-35-9]|6[567]|7[0-8]|8\d|9[0-35-9])\d{8}$/ // 手机正则
3 years ago
let intPattern = /^[0-9]*$/ // 整数正则
if (params1 === '') {
uni.showToast({
title: '请输入手机号',
icon: "none"
})
} else if (!ret.test(params1)) {
3 years ago
console.log(params1)
3 years ago
uni.showToast({
title: '手机号不正确',
icon: "none"
})
} else if (params2 === 0) {
uni.showToast({
title: '获取验证码',
icon: "none"
})
} else if (params2 === '') {
uni.showToast({
title: '请输入验证码',
icon: "none"
})
} else if (params2 !== 0 && !intPattern.test(params2)) {
uni.showToast({
title: '验证码不正确',
icon: "none"
})
} else if (params2 !== 0 && intPattern.test(params2)) {
3 years ago
phone = ret
code = intPattern
3 years ago
} else {
3 years ago
phone = ret
code = intPattern
}
3 years ago
3 years ago
return phone, code
}
//名称脱敏
export function maskShopName(str) {
var reg = /^(.).+(.)$/g;
if (str != null && str != "") {
if (str.length < 4) {
str = str.replace(reg, "$1*$2");
} else {
str = str.replace(reg, "$1***$2");
}
}
console.log('1111111111',str)
return str;
}
//电话脱敏
export function maskPhone(phone) {
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
}
/**
* 省市区、自治区分割
*/
export function getArea(str) {
let area = {}; //最终返回的地址
let un_pro_str = ''; //去掉省以后的地址
let un_city_str = ''; //去掉市以后的地址
// 第一个区域(省)截取开始
let _dominion = str.indexOf("自治区"); //自治区出现的位置(内蒙古自治区、广西壮族自治区、西藏自治区、宁夏回族自治区、新疆维吾尔自治区、)
let _district = str.indexOf('行政区'); //特别行政区出现的位置(香港特别行政区、澳门特别行政区)
let _province = str.indexOf("省"); //省出现的位置
let _city = str.indexOf('市'); //市出现的位置(北京市、天津市、上海市、重庆市)
if (_dominion != -1) { //有自治区
area.province = str.substring(0, _dominion + 3)
un_pro_str = str.substr(_dominion + 3);
} else if (_province != -1) { //有省
area.province = str.substring(0, _province + 1)
un_pro_str = str.substr(_province + 1);
} else if (_district != -1) { //有行政区
area.province = str.substring(0, _district + 3)
un_pro_str = str.substr(_district + 3);
} else if (_city != -1) { //有市
area.province = str.substring(0, _city + 1)
un_pro_str = str.substr(_city + 1);
}
console.log('去掉省以后的地址', un_pro_str)
// 第二个区域(市)截取开始
let _city1 = un_pro_str.indexOf('市'); //第二次出现市的位置
let _district1 = un_pro_str.indexOf('行政区'); //特别行政区出现的位置
let _county = un_pro_str.indexOf('县'); //县出现的位置
let _state = un_pro_str.indexOf('自治州'); //自治州出现的位置
let _region = un_pro_str.indexOf('区'); //区出现的位置
let _zoning = un_pro_str.indexOf('行政区划'); //行政区划出现的位置
let _alliance = un_pro_str.indexOf('盟'); //盟出现的位置
if (_zoning != -1) { //行政区划
area.city = un_pro_str.substring(0, _zoning + 4)
un_city_str = un_pro_str.substr(_zoning + 4);
} else if (_district1 != -1) { //行政区
area.city = un_pro_str.substring(0, _district1 + 3)
un_city_str = un_pro_str.substr(_district1 + 3);
} else if (_state != -1) { //自治州
area.city = un_pro_str.substring(0, _state + 3)
un_city_str = un_pro_str.substr(_state + 3);
} else if (_alliance != -1) { //盟
area.city = un_pro_str.substring(0, _alliance + 1)
un_city_str = un_pro_str.substr(_alliance + 1);
} else if (_city1 != -1) { //市
area.city = un_pro_str.substring(0, _city1 + 1)
un_city_str = un_pro_str.substr(_city1 + 1);
} else if (_region != -1) { //区
area.city = un_pro_str.substring(0, _region + 1)
un_city_str = un_pro_str.substr(_region + 1);
} else if (_county != -1) { //县
area.city = un_pro_str.substring(0, _county + 1)
un_city_str = un_pro_str.substr(_county + 1);
}
var reg = /.+?(市|县|区)/g;
var aaa;
aaa = un_city_str.match(reg);
area.country = aaa[0];
var xiangxi = str.substring(str.indexOf(aaa[0]) + 3)
area.address = xiangxi
return area;
}