增加动态注入

This commit is contained in:
aixianling
2022-08-08 09:59:15 +08:00
parent 5f80bfc8ef
commit 6a1fb43883

View File

@@ -1,5 +1,5 @@
import dict from "./dict"; import dict from "./dict"
import dayjs from './monent'; import dayjs from './monent'
import qs from 'query-string' import qs from 'query-string'
const confirm = (content, title, config) => { const confirm = (content, title, config) => {
@@ -87,146 +87,146 @@ const idCardNoUtil = {
/*校验地址码*/ /*校验地址码*/
checkAddressCode: function (addressCode) { checkAddressCode: function (addressCode) {
const check = /^[1-9]\d{5}$/.test(addressCode); const check = /^[1-9]\d{5}$/.test(addressCode)
if (!check) return false; if (!check) return false
return !!idCardNoUtil.provinceAndCitys[parseInt(addressCode.substring(0, 2))]; return !!idCardNoUtil.provinceAndCitys[parseInt(addressCode.substring(0, 2))]
}, },
/*校验日期码*/ /*校验日期码*/
checkBirthDayCode: function (birDayCode) { checkBirthDayCode: function (birDayCode) {
const check = /^[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))$/.test(birDayCode); const check = /^[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))$/.test(birDayCode)
if (!check) return false; if (!check) return false
const yyyy = parseInt(birDayCode.substring(0, 4), 10); const yyyy = parseInt(birDayCode.substring(0, 4), 10)
const mm = parseInt(birDayCode.substring(4, 6), 10); const mm = parseInt(birDayCode.substring(4, 6), 10)
const dd = parseInt(birDayCode.substring(6), 10); const dd = parseInt(birDayCode.substring(6), 10)
const xdata = new Date(yyyy, mm - 1, dd); const xdata = new Date(yyyy, mm - 1, dd)
if (xdata > new Date()) { if (xdata > new Date()) {
return false; //生日不能大于当前日期 return false //生日不能大于当前日期
} else return (xdata.getFullYear() == yyyy) && (xdata.getMonth() == mm - 1) && (xdata.getDate() == dd); } else return (xdata.getFullYear() == yyyy) && (xdata.getMonth() == mm - 1) && (xdata.getDate() == dd)
}, },
/*计算校检码*/ /*计算校检码*/
getParityBit: function (idCardNo) { getParityBit: function (idCardNo) {
const id17 = idCardNo.substring(0, 17); const id17 = idCardNo.substring(0, 17)
/*加权 */ /*加权 */
let power = 0; let power = 0
for (let i = 0; i < 17; i++) { for (let i = 0; i < 17; i++) {
power += parseInt(id17.charAt(i), 10) * parseInt(idCardNoUtil.powers[i]); power += parseInt(id17.charAt(i), 10) * parseInt(idCardNoUtil.powers[i])
} }
/*取模*/ /*取模*/
const mod = power % 11; const mod = power % 11
return idCardNoUtil.parityBit[mod]; return idCardNoUtil.parityBit[mod]
}, },
/*验证校检码*/ /*验证校检码*/
checkParityBit: function (idCardNo) { checkParityBit: function (idCardNo) {
const parityBit = idCardNo.charAt(17).toUpperCase(); const parityBit = idCardNo.charAt(17).toUpperCase()
return idCardNoUtil.getParityBit(idCardNo) == parityBit; return idCardNoUtil.getParityBit(idCardNo) == parityBit
}, },
/*校验15位或18位的身份证号码*/ /*校验15位或18位的身份证号码*/
checkIdCardNo: function (idCardNo) { checkIdCardNo: function (idCardNo) {
//15位和18位身份证号码的基本校验 //15位和18位身份证号码的基本校验
const check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo); const check = /^\d{15}|(\d{17}(\d|x|X))$/.test(idCardNo)
if (!check) return false; if (!check) return false
//判断长度为15位或18位 //判断长度为15位或18位
if (idCardNo.length == 15) { if (idCardNo.length == 15) {
return idCardNoUtil.check15IdCardNo(idCardNo); return idCardNoUtil.check15IdCardNo(idCardNo)
} else if (idCardNo.length == 18) { } else if (idCardNo.length == 18) {
return idCardNoUtil.check18IdCardNo(idCardNo); return idCardNoUtil.check18IdCardNo(idCardNo)
} else { } else {
return false; return false
} }
}, },
//校验15位的身份证号码 //校验15位的身份证号码
check15IdCardNo: function (idCardNo) { check15IdCardNo: function (idCardNo) {
//15位身份证号码的基本校验 //15位身份证号码的基本校验
let check = /^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(idCardNo); let check = /^[1-9]\d{7}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}$/.test(idCardNo)
if (!check) return false; if (!check) return false
//校验地址码 //校验地址码
const addressCode = idCardNo.substring(0, 6); const addressCode = idCardNo.substring(0, 6)
check = idCardNoUtil.checkAddressCode(addressCode); check = idCardNoUtil.checkAddressCode(addressCode)
if (!check) return false; if (!check) return false
const birDayCode = '19' + idCardNo.substring(6, 12); const birDayCode = '19' + idCardNo.substring(6, 12)
//校验日期码 //校验日期码
return idCardNoUtil.checkBirthDayCode(birDayCode); return idCardNoUtil.checkBirthDayCode(birDayCode)
}, },
//校验18位的身份证号码 //校验18位的身份证号码
check18IdCardNo: function (idCardNo) { check18IdCardNo: function (idCardNo) {
//18位身份证号码的基本格式校验 //18位身份证号码的基本格式校验
let check = /^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(idCardNo); let check = /^[1-9]\d{5}[1-9]\d{3}((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))\d{3}(\d|x|X)$/.test(idCardNo)
if (!check) return false; if (!check) return false
//校验地址码 //校验地址码
const addressCode = idCardNo.substring(0, 6); const addressCode = idCardNo.substring(0, 6)
check = idCardNoUtil.checkAddressCode(addressCode); check = idCardNoUtil.checkAddressCode(addressCode)
if (!check) return false; if (!check) return false
//校验日期码 //校验日期码
const birDayCode = idCardNo.substring(6, 14); const birDayCode = idCardNo.substring(6, 14)
check = idCardNoUtil.checkBirthDayCode(birDayCode); check = idCardNoUtil.checkBirthDayCode(birDayCode)
if (!check) return false; if (!check) return false
//验证校检码 //验证校检码
return idCardNoUtil.checkParityBit(idCardNo); return idCardNoUtil.checkParityBit(idCardNo)
}, },
formateDateCN: function (day) { formateDateCN: function (day) {
const yyyy = day.substring(0, 4); const yyyy = day.substring(0, 4)
const mm = day.substring(4, 6); const mm = day.substring(4, 6)
const dd = day.substring(6); const dd = day.substring(6)
return yyyy + '-' + mm + '-' + dd; return yyyy + '-' + mm + '-' + dd
}, },
//获取信息 //获取信息
getIdCardInfo: function (idCardNo) { getIdCardInfo: function (idCardNo) {
let aday; let aday
let idCardInfo = { let idCardInfo = {
gender: "", //性别 gender: "", //性别
birthday: "", // 出生日期(yyyy-mm-dd) birthday: "", // 出生日期(yyyy-mm-dd)
sex: ""//系统性别码 sex: ""//系统性别码
}; }
if (idCardNo.length == 15) { if (idCardNo.length == 15) {
aday = '19' + idCardNo.substring(6, 12); aday = '19' + idCardNo.substring(6, 12)
idCardInfo.birthday = idCardNoUtil.formateDateCN(aday); idCardInfo.birthday = idCardNoUtil.formateDateCN(aday)
if (parseInt(idCardNo.charAt(14)) % 2 == 0) { if (parseInt(idCardNo.charAt(14)) % 2 == 0) {
idCardInfo.gender = idCardNoUtil.genders.female; idCardInfo.gender = idCardNoUtil.genders.female
} else { } else {
idCardInfo.gender = idCardNoUtil.genders.male; idCardInfo.gender = idCardNoUtil.genders.male
} }
} else if (idCardNo.length == 18) { } else if (idCardNo.length == 18) {
aday = idCardNo.substring(6, 14); aday = idCardNo.substring(6, 14)
idCardInfo.birthday = idCardNoUtil.formateDateCN(aday); idCardInfo.birthday = idCardNoUtil.formateDateCN(aday)
if (parseInt(idCardNo.charAt(16)) % 2 == 0) { if (parseInt(idCardNo.charAt(16)) % 2 == 0) {
idCardInfo.gender = idCardNoUtil.genders.female; idCardInfo.gender = idCardNoUtil.genders.female
} else { } else {
idCardInfo.gender = idCardNoUtil.genders.male; idCardInfo.gender = idCardNoUtil.genders.male
} }
idCardInfo.sex = "" + Number(idCardNo.substring(16, 17)) % 2 idCardInfo.sex = "" + Number(idCardNo.substring(16, 17)) % 2
} }
return idCardInfo; return idCardInfo
}, },
/*18位转15位*/ /*18位转15位*/
getId15: function (idCardNo) { getId15: function (idCardNo) {
if (idCardNo.length == 15) { if (idCardNo.length == 15) {
return idCardNo; return idCardNo
} else if (idCardNo.length == 18) { } else if (idCardNo.length == 18) {
return idCardNo.substring(0, 6) + idCardNo.substring(8, 17); return idCardNo.substring(0, 6) + idCardNo.substring(8, 17)
} else { } else {
return null; return null
} }
}, },
/*15位转18位*/ /*15位转18位*/
getId18: function (idCardNo) { getId18: function (idCardNo) {
if (idCardNo.length == 15) { if (idCardNo.length == 15) {
const id17 = idCardNo.substring(0, 6) + '19' + idCardNo.substring(6); const id17 = idCardNo.substring(0, 6) + '19' + idCardNo.substring(6)
const parityBit = idCardNoUtil.getParityBit(id17); const parityBit = idCardNoUtil.getParityBit(id17)
return id17 + parityBit; return id17 + parityBit
} else if (idCardNo.length == 18) { } else if (idCardNo.length == 18) {
return idCardNo; return idCardNo
} else { } else {
return null; return null
} }
}, },
hideId(code) { hideId(code) {
@@ -255,11 +255,21 @@ export default {
dict, dict,
confirm, confirm,
calcAge, calcAge,
injectLib: (url, cb = () => 0) => {
const scriptList = document.body.querySelectorAll('script')
if (Object.values(scriptList || {}).findIndex(e => e.src == url) == -1) {
const script = document.createElement('script')
script.type = 'text/javascript'
script.src = url
script.addEventListener('load', () => cb())
document.body.appendChild(script)
} else cb()
},
dateFormat: (time, format) => { dateFormat: (time, format) => {
return dayjs(time).format(format || 'YYYY-MM-DD').replace("Invalid Date", "") return dayjs(time).format(format || 'YYYY-MM-DD').replace("Invalid Date", "")
}, },
formatName: (name) => { formatName: (name) => {
return Array.from(name)?.slice(-2)?.toString() || ""; return Array.from(name)?.slice(-2)?.toString() || ""
}, },
loading: title => { loading: title => {
uni.showLoading({ uni.showLoading({
@@ -272,24 +282,24 @@ export default {
}, },
colorUtils: { colorUtils: {
Hex2RGBA(color, alpha = 1) { Hex2RGBA(color, alpha = 1) {
let hex = 0; let hex = 0
if (color.charAt(0) == "#") { if (color.charAt(0) == "#") {
if (color.length == 4) { if (color.length == 4) {
//检测诸如#FFF简写格式 //检测诸如#FFF简写格式
color = "#" + color.charAt(1).repeat(2) + color = "#" + color.charAt(1).repeat(2) +
color.charAt(2).repeat(2) + color.charAt(2).repeat(2) +
color.charAt(3).repeat(2); color.charAt(3).repeat(2)
} }
hex = parseInt(color.slice(1), 16); hex = parseInt(color.slice(1), 16)
} }
let r = hex >> 16 & 0xFF; let r = hex >> 16 & 0xFF
let g = hex >> 8 & 0xFF; let g = hex >> 8 & 0xFF
let b = hex & 0xFF; let b = hex & 0xFF
return `rgba(${r},${g},${b},${alpha})`; return `rgba(${r},${g},${b},${alpha})`
}, },
RGBtoHex(r, g, b) { RGBtoHex(r, g, b) {
let hex = r << 16 | g << 8 | b; let hex = r << 16 | g << 8 | b
return "#" + hex.toString(16); return "#" + hex.toString(16)
} }
}, },
dayjs, dayjs,