提交 a7e8f4ee authored 作者: supj's avatar supj

1、克隆外部库,将多个仓库合并为一个仓库

上级
.idea/
node_modules/
dist/
docs/
/package-lock.json
/yarn.lock
/jest.config.js
// import typescript from "rollup-plugin-typescript2";
// import resolve from 'rollup-plugin-node-resolve';
// import commonjs from 'rollup-plugin-commonjs';
import typescript from "rollup-plugin-typescript";
import {terser} from 'rollup-plugin-terser';
import dts from "rollup-plugin-dts";
import path from "path";
const pkg = require('../package.json')
const resolveFile = (...args) => path.resolve(...args);
let inputFile=resolveFile("./src/index.ts")
let libName = "generalTools"
export default [
{
// 生成 .d.ts 类型声明文件
input: inputFile,
output: {
file: resolveFile(pkg.types),
format: 'es',
},
plugins: [dts()],
},
{
input: inputFile,
output: [
{
file: resolveFile(pkg.main),
format: "cjs",
exports:"default"
},
{
file:resolveFile(pkg.module),
format: "es",
},
{
file:resolveFile(pkg.browser),
format: "umd",
name: libName,
},
],
plugins: [
typescript({
exclude: "node_modules/**",
typescript: require("typescript"),
}),
terser()
],
}
];
"use strict";var t={dayMillis:864e5,hourMillis:36e5,minuteMillis:6e4,secondMillis:1e3},e=function(){function e(e){var n=e%t.dayMillis,r=e%t.hourMillis,o=e%t.minuteMillis;this.time=e,this.day=Math.floor(e/t.dayMillis),this.hour=Math.floor(n/t.hourMillis),this.minute=Math.floor(r/t.minuteMillis),this.second=Math.floor(o/t.secondMillis)}return e.prototype.format=function(t){return t>=10?t+"":"0"+t},e}(),n=function(){function t(t,e){this.millisInFuture=t,this.mInterval=e,this.onCountDownFinishListener=void 0,this.onCountDownListener=void 0,this.timeOutId=void 0}return t.prototype.addCountDownListener=function(t){t&&"function"==typeof t&&(this.onCountDownListener=t)},t.prototype.addFinishListener=function(t){t&&"function"==typeof t&&(this.onCountDownFinishListener=t)},t.prototype.start=function(){var e=this;this.timeOutId||null==this.onCountDownListener||(this.timeOutId=setInterval((function(){e.millisInFuture=e.millisInFuture-e.mInterval,e.millisInFuture>0?e.onCountDownListener(t.getTimeInfo(e.millisInFuture)):(e.cancel(),void 0!==e.onCountDownFinishListener&&e.onCountDownFinishListener())}),this.mInterval))},t.prototype.cancel=function(){this.timeOutId&&(clearTimeout(this.timeOutId),this.timeOutId=void 0)},t.getTimeInfo=function(t){return new e(t)},t}(),r=[{symbolList:["yyyy","YYYY"],getValue:function(t){return o.formatNumber(t.getFullYear())}},{symbolList:["MM"],getValue:function(t){return o.formatNumber(t.getMonth()+1)}},{symbolList:["DD","dd"],getValue:function(t){return o.formatNumber(t.getDate())}},{symbolList:["HH","hh"],getValue:function(t){return o.formatNumber(t.getHours())}},{symbolList:["mm"],getValue:function(t){return o.formatNumber(t.getMinutes())}},{symbolList:["SS","ss"],getValue:function(t){return o.formatNumber(t.getSeconds())}}],o=function(){function e(){}return e.getDateInstance=function(t){if(t instanceof Date)return t;if("string"==typeof t&&t.indexOf("-")>0){var e=new RegExp("-","g");t=t.replace(e,"/")}return new Date(t)},e.getWeekDay=function(t,e){return new Date(t,e-1,1).getDay()},e.formatNumber=function(t){return t>9?t+"":"0"+t},e.isToday=function(t){var n=new Date,r=e.getDateInstance(t);return n.getFullYear()===r.getFullYear()&&r.getMonth()===n.getMonth()&&r.getDate()===n.getDate()},e.getFormatDate=function(t){var n=e.getDateInstance(t);return n.getFullYear()+"-"+e.formatNumber(n.getMonth()+1)+"-"+e.formatNumber(n.getDate())},e.getCurrentFormatDate=function(){return e.getFormatDate(new Date)},e.getDaysInMonth=function(t){var n=e.getDateInstance(t),r=n.getMonth()+1;return e.getMonthDays(n.getFullYear(),r)},e.getWeekName=function(t,n){void 0===n&&(n=!1);var r=e.getDateInstance(t).getDay();return 0===r?n?"Sunday":"周日":1===r?n?"Monday":"周一":2===r?n?"Tuesday":"周二":3===r?n?"Wednesday":"周三":4===r?n?"Thursday":"周四":5===r?n?"Friday":"周五":6===r?n?"Saturday":"周六":""},e.isLeapYear=function(t){return t%400==0||t%4==0&&t%100!=0},e.getMonthDays=function(t,n){if(2===n)return e.isLeapYear(t)?29:28;return[1,3,5,7,8,10,12].includes(n)?31:30},e.getNextMonthInfo=function(t,e){return{year:e>=12?t+1:t,month:e>=12?1:e+1}},e.getLastMonthInfo=function(t,e){return{year:1==e?t-1:t,month:1==e?12:e-1}},e.diffTime=function(t,e,n){var r=e-t;return Math.floor(r/n*100)/100},e.diffYears=function(t,n){var r=e.diffMonths(t,n);return Math.floor(r/12*100)/100},e.diffMonths=function(t,n){var r=Math.min(t,n),o=Math.max(t,n),i=e.getDateInstance(r),a=e.getDateInstance(o),u=a.getFullYear()-i.getFullYear(),s=i.getMonth()+1,f=a.getMonth()+1;return f<s&&(u-=1,f+=12),Number.parseInt((12*u+f-s).toFixed(0))},e.diffDays=function(n,r){return e.diffTime(n,r,t.dayMillis)},e.diffHours=function(n,r){return e.diffTime(n,r,t.hourMillis)},e.diffMinutes=function(n,r){return e.diffTime(n,r,t.minuteMillis)},e.diffSeconds=function(n,r){return e.diffTime(n,r,t.secondMillis)},e.formatDateString=function(t,n){var o=String(n);if(n){var i=e.getDateInstance(t);r.forEach((function(t){for(var e=0,n=t.symbolList.length;e<n;e++)if(o.indexOf(t.symbolList[e])>=0){o=o.replace(t.symbolList[e],t.getValue(i));break}}))}return o},e}(),i=function(){function t(t,e,n){this.year=t,this.month=e,this.day=n,this.isSupplementDay=!1,this.titleName=String(n),this.formatDay="".concat(t,"-").concat(o.formatNumber(e),"-").concat(o.formatNumber(n));var r=new Date(this.formatDay);r.setHours(0,0,0,0),this.time=r.getTime()}return t.prototype.equals=function(t){return this.year===t.year&&this.month===t.month&&this.day===t.day},t.prototype.toString=function(){return"year= "+this.year+" year= "+this.year+" year= "+this.year},t}(),a=function(){function t(t,e){this.titleName=String(e),this.year=t,this.month=e;var n=o.getMonthDays(t,e);this.dayItems=[];for(var r=1;r<=n;r++){var a=new i(this.year,this.month,r);this.dayItems.push(a)}}return t.prototype.toString=function(){return"year= "+this.year+" month= "+this.month},t}(),u=function(){function t(e,n,r){this.monthCount=e,this.startYear=n&&n>=1970?n:(new Date).getFullYear(),this.startMonth=r&&r>0&&r<=12?r:(new Date).getMonth()+1;var o=new Array,i=t.getCalendarMonth(this.startYear,this.startMonth);o.push(i);for(var a=1;a<e;a++)i=t.getNextMonth(i.year,i.month),o.push(i);this.monthDataList=o}return t.getCurrentFormatDateString=function(){var t=new Date;return t.getFullYear()+"-"+o.formatNumber(t.getMonth()+1)+"-"+o.formatNumber(t.getDate())},t.getCalendarMonth=function(t,e){var n=new a(t,e),r=o.getWeekDay(t,e);if(r>0)for(var u=o.getLastMonthInfo(t,e),s=o.getMonthDays(u.year,u.month),f=0;f<r;f++){var c=s-r+1+f;(h=new i(u.year,u.month,c)).isSupplementDay=!0,n.dayItems.unshift(h)}var l=7-n.dayItems.length%7;if(l<7){var g=o.getNextMonthInfo(t,e);for(f=0;f<l;f++){var h;(h=new i(g.year,g.month,f+1)).isSupplementDay=!0,n.dayItems.push(h)}}return n},t.getLastMonthData=function(e,n){var r=o.getLastMonthInfo(e,n);return t.getCalendarMonth(r.year,r.month)},t.getNextMonth=function(e,n){var r=o.getNextMonthInfo(e,n);return t.getCalendarMonth(r.year,r.month)},t.getCurrentMonth=function(){var e=new Date;return t.getCalendarMonth(e.getFullYear(),e.getMonth()+1)},t.getCalendarMonthList=function(e){var n=[],r=t.getCurrentMonth();n.push(r);for(var o=1;o<e;o++)r=t.getNextMonth(r.year,r.month),n.push(r);return n},t}(),s=function(){function t(t){this.enableDebug=t}return t.prototype.getTag=function(t){return t+"===================="},t.prototype.debug=function(t){this.enableDebug&&console.debug(t)},t.prototype.debugWithTag=function(t,e){this.enableDebug&&console.debug(this.getTag(t),e)},t.prototype.info=function(t){this.enableDebug&&console.info(t)},t.prototype.infoWithTag=function(t,e){this.enableDebug&&console.info(this.getTag(t),e)},t.prototype.log=function(t){this.enableDebug&&console.log(t)},t.prototype.logWithTag=function(t,e){this.enableDebug&&console.log(this.getTag(t),e)},t.prototype.error=function(t){this.enableDebug&&console.error(t)},t.prototype.errorWithTag=function(t,e){this.enableDebug&&console.error(this.getTag(t),e)},t.prototype.warn=function(t){this.enableDebug&&console.warn(t)},t.prototype.warnWithTag=function(t,e){this.enableDebug&&console.warn(this.getTag(t),e)},t}(),f={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"},c=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],l=["1","0","X","9","8","7","6","5","4","3","2"];var g=function(){function t(){}return t.replaceAll=function(t,e,n){var r=new RegExp(e,"g");return t.replace(r,n)},t.isEmpty=function(t){return!t||t.trim().length<1},t.isOrganizationCode=function(t){return new RegExp("^[0-9A-HJ-NPQRTUWXY]{8}-[0-9A-HJ-NPQRTUWXY]$").test(t)},t.isUnifiedCreditCode=function(t){return new RegExp("^[0-9A-HJ-NPQRTUWXY]{2}\\d{6}[0-9A-HJ-NPQRTUWXY]{10}$").test(t)},t.isPhoneNumber=function(t){var e=String(t);return!!new RegExp("^1[38][0-9]{9}$").test(e)||(!!new RegExp("^14[56789][0-9]{8}$").test(e)||(!!new RegExp("^15[012356789][0-9]{8}$").test(e)||(!!new RegExp("^16[567][0-9]{8}$").test(e)||(!!new RegExp("^17[012345678][0-9]{8}$").test(e)||!!new RegExp("^19[1589][0-9]{8}$").test(e)))))},t.isEmail=function(t){return!!t&&new RegExp("^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*\\.[a-z]{2,}$").test(t)},t.filterRichText=function(t){if(!t)return"";var e=new RegExp("<[^<>]+>","g");return t.replace(e,"")},t.getImageListFromRichText=function(t){var e=new Array,n=new RegExp("<img[^>]*>","g"),r=t.match(n);if(r&&r.length>0){var o=new RegExp("http\\S*((.jpg)|(.jpeg)|(.png))","g");r.forEach((function(t){var n=t.match(o);n&&n.length>0&&!e.includes(n[0])&&e.push(n[0])}))}return e},t.colorRbgToHex=function(t){var e=t.toLowerCase(),n=new RegExp("^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6 })$");if(new RegExp("^(rgb|RGB)").test(e)){for(var r=new RegExp("(?:\\(|\\)|rgb|RGB)*","g"),o=e.replace(r,"").split(","),i="#",a=0;a<o.length;a++){var u=Number(o[a]).toString(16);"0"===u&&(u+=u),i+=u}return 7!==i.length&&(i=e),i}if(n.test(e)){var s=e.replace("#","").split("");if(6===s.length)return e;if(3===s.length){var f="#";for(a=0;a<s.length;a+=1)f+=s[a]+s[a];return f}}return e},t.colorHexToRgb=function(t){var e=t.toLowerCase(),n=new RegExp("^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$");if(e&&n.test(e)){if(4===e.length){for(var r="#",o=1;o<4;o+=1)r+=e.slice(o,o+1).concat(e.slice(o,o+1));e=r}var i=[];for(o=1;o<7;o+=2)i.push(parseInt("0x"+e.slice(o,o+2)));return"rgb("+i.join(",")+")"}return e},t.formatNumber=function(t){if(!t)return"0";var e=String(t).split("."),n=new RegExp("(\\d)(?=(?:\\d{3})+$)"),r=String(e[0]).replace(n,"$1,");return e.length>1?"".concat(r,".").concat(e[1]):r},t.desensitize=function(t){if(new RegExp("[一-龥]").test(t))return t[0]+"***";var e=String(t);if(11===e.length)return"".concat(e.slice(0,3),"****").concat(e.slice(7,11));var n=new RegExp("^(.{6})(?:\\d+)(.{4})$");return e.replace(n,"$1********$2")},t.generateUUID=function(){var t=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var n=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?n:3&n|8).toString(16)}))},t}(),h=function(){return h=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},h.apply(this,arguments)};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function p(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}var y=function(){function t(){}return t.makeUpGroupList=function(t,e){if(t&&t.length>0){var n=p([],t,!0);if(e<2)return n;var r=n.length%e;if(r>0)for(var o=0,i=e-r;o<i;o++)n.push({});return n}return t},t.grouping=function(t,e){if(t&&e>0){for(var n=[],r=t.length,o=0,i=e;o<r;)n.push(t.slice(o,i)),o+=e,i+=e;return n}return[]},t}(),m=function(){function t(){}return t.cloneFunction=function(t){var e=new RegExp("(?<={)(.|\\n)+(?=})","m"),n=new RegExp("(?<=\\().+(?=\\)\\s+{)"),r=t.toString(),o=n.exec(r),i=e.exec(r);if(o){var a=o[0].split(",");return i&&i[0]?new(Function.bind.apply(Function,p(p([void 0],a,!1),[i[0]],!1))):new(Function.bind.apply(Function,p([void 0],a,!1)))}return i&&i[0]?new Function(i[0]):new Function},t.cloneDeep=function(e,n){if(null==e)return e;if(e instanceof Function)return t.cloneFunction(e);if("object"!=typeof e)return e;if(e instanceof Date)return new Date(e);if(e instanceof RegExp)return new RegExp(e);if(e instanceof Symbol)return Symbol(e.description);if(e instanceof Map){var r=new Map;return e.forEach((function(e,n){r.set(n,t.cloneDeep(e))})),r}if(e instanceof Set){var o=new Set;return e.forEach((function(e,n){o.add(t.cloneDeep(e))})),o}if(e instanceof Array){for(var i=new Array,a=0,u=e.length;a<u;a++)i.push(t.cloneDeep(e[a]));return i}if(e instanceof Object){var s=n||new WeakMap;if(s.get(e))return n.get(e);var f={};for(var c in e)f[c]=t.cloneDeep(e[c],s);return s.set(e,f),f}},t.extendObject=function(e,n){return n&&"object"==typeof n?(e&&"object"==typeof n&&Object.keys(n).forEach((function(r){void 0===e[r]?e[r]=n[r]:"object"==typeof e[r]&&t.extendObject(e[r],n[r])})),e):e},t.containObject=function(e,n){if(!e||e.length<1)return!1;for(var r=0,o=e.length;r<o;r++)if(t.equalDeep(e[r],n))return!0;return!1},t.equalDeep=function(e,n){var r=typeof e;if(r!==typeof n)return!1;if("string"===r||"number"===r||"undefined"===r||"boolean"===r)return e===n;if("object"===r){if(e instanceof Array)return e.length==e.length&&(!!e.every((function(e){return t.containObject(n,e)}))&&n.every((function(n){return t.containObject(e,n)})));var o=Object.keys(e),i=Object.keys(n);if(o.length!==i.length)return!1;if(i.filter((function(t){return o.includes(t)})).length!==o.length)return!1;for(var a=0,u=o.length;a<u;a++){if(!t.equalDeep(e[o[a]],n[o[a]]))return!1}return!0}return!1},t.getObjectByList=function(t,e){var n={};if(t&&t.length>0&&e&&"object"==typeof e)for(var r=0,o=t.length;r<o;r++){var i=t[r];i&&(n[i]=e[i])}return n},t.getObjectByObject=function(e,n){if(e&&n&&"object"==typeof e&&"object"==typeof n){var r=Object.keys(e);return t.getObjectByList(r,n)}return{}},t.getValueFromObject=function(e,n){if("object"==typeof e&&n&&"string"==typeof n){if(e[n])return e[n];if(n.indexOf(".")<0)return e[n];var r=n.split(".");if(e[r[0]]&&e[r[0]]instanceof Object){var o=r.slice(1).join(".");return t.getValueFromObject(e[r[0]],o)}}return""},t.addWatcher=function(e,n){Object.keys(n).forEach((function(r){t.observe(e,r,n[r])}))},t.observe=function(e,n,r){if(e&&"object"==typeof e){var o=e[n];if(o)Object.defineProperty(e,n,{configurable:!0,enumerable:!0,set:function(t){var e=o;o=t,r(t,e)},get:function(){return o}});else{var i=n.indexOf(".");if(i>0){var a=n.substring(0,i),u=n.substring(i+1);t.observe(e[a],u,r)}}}},t}(),d=function(){function t(){}return t.getQueryMapFromUrl=function(t){var e=new Map;if(t&&t.indexOf("?")>0){var n=t.substring(t.indexOf("?")+1).split("&");n&&n.length>0&&n.forEach((function(t){var n=t.split("=");n&&n.length>1&&e.set(n[0],n[1])}))}return e},t.getQueryUrl=function(t,e){var n=-1!==t.indexOf("?");if(void 0!==e&&e instanceof Object){var r=t;for(var o in e)void 0!==e[o]&&(r.endsWith("?")?r="".concat(r).concat(o,"=").concat(e[o]):(r="".concat(r).concat(n?"&":"?").concat(o,"=").concat(e[o]),n||(n=!0)));return r}return t},t}(),v="get",b="post",D="delete",x="head",M="CONNECT",w="options",I="put",R="patch",C="TRACE",F="LINK",q="unlink",O=function(){function t(t,e,n,r){this.platform=t,this.baseUrl=n,this.requestInterceptorsConfig=r,this.taskMap=new Map,this.isMiniApp=e}return t.prototype.post=function(t,e,n,r){return this.request(t,b,e,n,r)},t.prototype.get=function(e,n,r,o){var i=t.getTargetUrl(e,n);return this.request(i,v,{},r,o)},t.prototype.put=function(t,e,n,r){return this.request(t,I,e,n,r)},t.prototype.delete=function(t,e,n,r){return this.request(t,D,e,n,r)},t.prototype.head=function(t,e,n,r){return this.request(t,x,e,n,r)},t.prototype.options=function(t,e,n,r){return this.request(t,w,e,n,r)},t.prototype.connect=function(t,e,n,r){return this.request(t,M,e,n,r)},t.prototype.trace=function(t,e,n,r){return this.request(t,C,e,n,r)},t.prototype.patch=function(t,e,n,r){return this.request(t,R,e,n,r)},t.prototype.link=function(t,e,n,r){return this.request(t,F,e,n,r)},t.prototype.unlink=function(t,e,n,r){return this.request(t,q,e,n,r)},t.getTargetUrl=function(t,e){if(e&&Object.keys(e).length>0){var n=-1!==t.indexOf("?"),r=t;for(var o in e)void 0!==e[o]&&(r.endsWith("?")?r="".concat(r).concat(o,"=").concat(e[o]):(r="".concat(r).concat(n?"&":"?").concat(o,"=").concat(e[o]),n||(n=!0)));return r}return t},t.prototype.request=function(t,e,n,r,o){if(this.requestInterceptorsConfig&&"function"==typeof this.requestInterceptorsConfig.getCacheData){var i=this.requestInterceptorsConfig.getCacheData(this.baseUrl,t,n);if(void 0!==i)return Promise.resolve(i)}var a=h({"Content-Type":"application/json"},r),u=this.requestInterceptorsConfig&&this.requestInterceptorsConfig.onRequestInterceptor?this.requestInterceptorsConfig.onRequestInterceptor(a):a,s={baseURL:"",url:this.getRequestUrl(t),method:e,data:n,header:h({},u)};return this.isMiniApp&&this.platform&&this.platform.request&&"function"==typeof this.platform.request?this.miniAppRequest(s,o,t,n):this.platform&&"function"==typeof this.platform?this.commonRequest(s,o,t,n):void 0},t.prototype.getRequestUrl=function(t){if(t.startsWith("https://")||t.startsWith("http://"))return t;if(this.baseUrl){var e=this.baseUrl.endsWith("/"),n=t.startsWith("/");return e&&n?this.baseUrl.substring(0,this.baseUrl.length-1)+t:e||n?this.baseUrl+t:this.baseUrl+"/"+t}return t},t.prototype.miniAppRequest=function(t,e,n,r){var o=this;return new Promise((function(i,a){var u=h(h({},t),{fail:function(t){e&&o.taskMap.delete(e),a(t)},success:function(t){e&&o.taskMap.delete(e),o.successHandler(i,a,t,n,r)}}),s=o.platform.request(u);e&&s&&o.taskMap.set(e,s)}))},t.prototype.successHandler=function(t,e,n,r,o){var i=this.getResponseData(n,r,o);i.success?t(i.data):e(i.data)},t.prototype.getResponseData=function(t,e,n){var r={success:!0,data:t};return this.requestInterceptorsConfig&&"function"==typeof this.requestInterceptorsConfig.onResponseInterceptor&&(r=this.requestInterceptorsConfig.onResponseInterceptor(t)),r.success&&this.requestInterceptorsConfig&&"function"==typeof this.requestInterceptorsConfig.updateResponseCache&&this.requestInterceptorsConfig.updateResponseCache(t,this.baseUrl,e,n),r},t.prototype.commonRequest=function(t,e,n,r){var o=this;return new Promise((function(e,i){o.platform(t).then((function(t){o.successHandler(e,i,t,n,r)})).catch((function(t){i(t)}))}))},t}(),T=new Map,j=function(){function t(){}return t.getHttpClient=function(t,e,n,r){if(T.has(n)){var o=T.get(n);if(void 0!==o)return o}var i=r(),a=new O(t,e,n,i||{});return T.set(n,a),a},t}(),E={DateConstants:t,CountDownTimer:n,CalendarData:u,LogUtils:s,isIdCard:function(t){if(!new RegExp("(^\\d{15}$)|(^\\d{17}(\\d|X|x)$)").test(t))return console.log("身份证长度或格式错误"),!1;var e=String(t);if(15===e.length&&(e=function(t){if(t&&15===t.length){for(var e=t.substring(0,6)+"19"+t.substring(6),n=0,r=0;r<17;r++)n+=Number.parseInt(e[r])*c[r];return e+l[n%11]}}(e)),!f[e.substring(0,2)])return console.log("身份证地区非法"),!1;var n=(e.substring(6,10)+"-"+Number(e.substring(10,12))+"-"+Number(e.substring(12,14))).replace(/-/g,"/"),r=new Date(n);if(n!=r.getFullYear()+"/"+(r.getMonth()+1)+"/"+r.getDate())return console.log("身份证上的出生日期非法"),!1;var o=new Date;if(o.setHours(23,59,59),r.setHours(23,59,59),o.getTime()-r.getTime()<0)return console.log("身份证上的出生日期非法,出生日期大于当前日期"),!1;var i=o.getFullYear()-r.getFullYear();if(i<0||i>150)return console.log("出生日期岁数不合理"),!1;for(var a=0,u=0;u<e.length-1;u++)a+=Number.parseInt(e[u])*c[u];var s=l[a%11];return e[e.length-1]==s||(console.log("你输入的身份证号非法"),!1)},StringHelper:g,ObjectHelper:m,DateHelper:o,ArrayHelper:y,UrlHelper:d,HttpRequest:j,HttpClient:O};module.exports=E;
var t={dayMillis:864e5,hourMillis:36e5,minuteMillis:6e4,secondMillis:1e3},e=function(){function e(e){var n=e%t.dayMillis,r=e%t.hourMillis,o=e%t.minuteMillis;this.time=e,this.day=Math.floor(e/t.dayMillis),this.hour=Math.floor(n/t.hourMillis),this.minute=Math.floor(r/t.minuteMillis),this.second=Math.floor(o/t.secondMillis)}return e.prototype.format=function(t){return t>=10?t+"":"0"+t},e}(),n=function(){function t(t,e){this.millisInFuture=t,this.mInterval=e,this.onCountDownFinishListener=void 0,this.onCountDownListener=void 0,this.timeOutId=void 0}return t.prototype.addCountDownListener=function(t){t&&"function"==typeof t&&(this.onCountDownListener=t)},t.prototype.addFinishListener=function(t){t&&"function"==typeof t&&(this.onCountDownFinishListener=t)},t.prototype.start=function(){var e=this;this.timeOutId||null==this.onCountDownListener||(this.timeOutId=setInterval((function(){e.millisInFuture=e.millisInFuture-e.mInterval,e.millisInFuture>0?e.onCountDownListener(t.getTimeInfo(e.millisInFuture)):(e.cancel(),void 0!==e.onCountDownFinishListener&&e.onCountDownFinishListener())}),this.mInterval))},t.prototype.cancel=function(){this.timeOutId&&(clearTimeout(this.timeOutId),this.timeOutId=void 0)},t.getTimeInfo=function(t){return new e(t)},t}(),r=[{symbolList:["yyyy","YYYY"],getValue:function(t){return o.formatNumber(t.getFullYear())}},{symbolList:["MM"],getValue:function(t){return o.formatNumber(t.getMonth()+1)}},{symbolList:["DD","dd"],getValue:function(t){return o.formatNumber(t.getDate())}},{symbolList:["HH","hh"],getValue:function(t){return o.formatNumber(t.getHours())}},{symbolList:["mm"],getValue:function(t){return o.formatNumber(t.getMinutes())}},{symbolList:["SS","ss"],getValue:function(t){return o.formatNumber(t.getSeconds())}}],o=function(){function e(){}return e.getDateInstance=function(t){if(t instanceof Date)return t;if("string"==typeof t&&t.indexOf("-")>0){var e=new RegExp("-","g");t=t.replace(e,"/")}return new Date(t)},e.getWeekDay=function(t,e){return new Date(t,e-1,1).getDay()},e.formatNumber=function(t){return t>9?t+"":"0"+t},e.isToday=function(t){var n=new Date,r=e.getDateInstance(t);return n.getFullYear()===r.getFullYear()&&r.getMonth()===n.getMonth()&&r.getDate()===n.getDate()},e.getFormatDate=function(t){var n=e.getDateInstance(t);return n.getFullYear()+"-"+e.formatNumber(n.getMonth()+1)+"-"+e.formatNumber(n.getDate())},e.getCurrentFormatDate=function(){return e.getFormatDate(new Date)},e.getDaysInMonth=function(t){var n=e.getDateInstance(t),r=n.getMonth()+1;return e.getMonthDays(n.getFullYear(),r)},e.getWeekName=function(t,n){void 0===n&&(n=!1);var r=e.getDateInstance(t).getDay();return 0===r?n?"Sunday":"周日":1===r?n?"Monday":"周一":2===r?n?"Tuesday":"周二":3===r?n?"Wednesday":"周三":4===r?n?"Thursday":"周四":5===r?n?"Friday":"周五":6===r?n?"Saturday":"周六":""},e.isLeapYear=function(t){return t%400==0||t%4==0&&t%100!=0},e.getMonthDays=function(t,n){if(2===n)return e.isLeapYear(t)?29:28;return[1,3,5,7,8,10,12].includes(n)?31:30},e.getNextMonthInfo=function(t,e){return{year:e>=12?t+1:t,month:e>=12?1:e+1}},e.getLastMonthInfo=function(t,e){return{year:1==e?t-1:t,month:1==e?12:e-1}},e.diffTime=function(t,e,n){var r=e-t;return Math.floor(r/n*100)/100},e.diffYears=function(t,n){var r=e.diffMonths(t,n);return Math.floor(r/12*100)/100},e.diffMonths=function(t,n){var r=Math.min(t,n),o=Math.max(t,n),i=e.getDateInstance(r),a=e.getDateInstance(o),u=a.getFullYear()-i.getFullYear(),s=i.getMonth()+1,f=a.getMonth()+1;return f<s&&(u-=1,f+=12),Number.parseInt((12*u+f-s).toFixed(0))},e.diffDays=function(n,r){return e.diffTime(n,r,t.dayMillis)},e.diffHours=function(n,r){return e.diffTime(n,r,t.hourMillis)},e.diffMinutes=function(n,r){return e.diffTime(n,r,t.minuteMillis)},e.diffSeconds=function(n,r){return e.diffTime(n,r,t.secondMillis)},e.formatDateString=function(t,n){var o=String(n);if(n){var i=e.getDateInstance(t);r.forEach((function(t){for(var e=0,n=t.symbolList.length;e<n;e++)if(o.indexOf(t.symbolList[e])>=0){o=o.replace(t.symbolList[e],t.getValue(i));break}}))}return o},e}(),i=function(){function t(t,e,n){this.year=t,this.month=e,this.day=n,this.isSupplementDay=!1,this.titleName=String(n),this.formatDay="".concat(t,"-").concat(o.formatNumber(e),"-").concat(o.formatNumber(n));var r=new Date(this.formatDay);r.setHours(0,0,0,0),this.time=r.getTime()}return t.prototype.equals=function(t){return this.year===t.year&&this.month===t.month&&this.day===t.day},t.prototype.toString=function(){return"year= "+this.year+" year= "+this.year+" year= "+this.year},t}(),a=function(){function t(t,e){this.titleName=String(e),this.year=t,this.month=e;var n=o.getMonthDays(t,e);this.dayItems=[];for(var r=1;r<=n;r++){var a=new i(this.year,this.month,r);this.dayItems.push(a)}}return t.prototype.toString=function(){return"year= "+this.year+" month= "+this.month},t}(),u=function(){function t(e,n,r){this.monthCount=e,this.startYear=n&&n>=1970?n:(new Date).getFullYear(),this.startMonth=r&&r>0&&r<=12?r:(new Date).getMonth()+1;var o=new Array,i=t.getCalendarMonth(this.startYear,this.startMonth);o.push(i);for(var a=1;a<e;a++)i=t.getNextMonth(i.year,i.month),o.push(i);this.monthDataList=o}return t.getCurrentFormatDateString=function(){var t=new Date;return t.getFullYear()+"-"+o.formatNumber(t.getMonth()+1)+"-"+o.formatNumber(t.getDate())},t.getCalendarMonth=function(t,e){var n=new a(t,e),r=o.getWeekDay(t,e);if(r>0)for(var u=o.getLastMonthInfo(t,e),s=o.getMonthDays(u.year,u.month),f=0;f<r;f++){var c=s-r+1+f;(h=new i(u.year,u.month,c)).isSupplementDay=!0,n.dayItems.unshift(h)}var l=7-n.dayItems.length%7;if(l<7){var g=o.getNextMonthInfo(t,e);for(f=0;f<l;f++){var h;(h=new i(g.year,g.month,f+1)).isSupplementDay=!0,n.dayItems.push(h)}}return n},t.getLastMonthData=function(e,n){var r=o.getLastMonthInfo(e,n);return t.getCalendarMonth(r.year,r.month)},t.getNextMonth=function(e,n){var r=o.getNextMonthInfo(e,n);return t.getCalendarMonth(r.year,r.month)},t.getCurrentMonth=function(){var e=new Date;return t.getCalendarMonth(e.getFullYear(),e.getMonth()+1)},t.getCalendarMonthList=function(e){var n=[],r=t.getCurrentMonth();n.push(r);for(var o=1;o<e;o++)r=t.getNextMonth(r.year,r.month),n.push(r);return n},t}(),s=function(){function t(t){this.enableDebug=t}return t.prototype.getTag=function(t){return t+"===================="},t.prototype.debug=function(t){this.enableDebug&&console.debug(t)},t.prototype.debugWithTag=function(t,e){this.enableDebug&&console.debug(this.getTag(t),e)},t.prototype.info=function(t){this.enableDebug&&console.info(t)},t.prototype.infoWithTag=function(t,e){this.enableDebug&&console.info(this.getTag(t),e)},t.prototype.log=function(t){this.enableDebug&&console.log(t)},t.prototype.logWithTag=function(t,e){this.enableDebug&&console.log(this.getTag(t),e)},t.prototype.error=function(t){this.enableDebug&&console.error(t)},t.prototype.errorWithTag=function(t,e){this.enableDebug&&console.error(this.getTag(t),e)},t.prototype.warn=function(t){this.enableDebug&&console.warn(t)},t.prototype.warnWithTag=function(t,e){this.enableDebug&&console.warn(this.getTag(t),e)},t}(),f={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"},c=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],l=["1","0","X","9","8","7","6","5","4","3","2"];var g=function(){function t(){}return t.replaceAll=function(t,e,n){var r=new RegExp(e,"g");return t.replace(r,n)},t.isEmpty=function(t){return!t||t.trim().length<1},t.isOrganizationCode=function(t){return new RegExp("^[0-9A-HJ-NPQRTUWXY]{8}-[0-9A-HJ-NPQRTUWXY]$").test(t)},t.isUnifiedCreditCode=function(t){return new RegExp("^[0-9A-HJ-NPQRTUWXY]{2}\\d{6}[0-9A-HJ-NPQRTUWXY]{10}$").test(t)},t.isPhoneNumber=function(t){var e=String(t);return!!new RegExp("^1[38][0-9]{9}$").test(e)||(!!new RegExp("^14[56789][0-9]{8}$").test(e)||(!!new RegExp("^15[012356789][0-9]{8}$").test(e)||(!!new RegExp("^16[567][0-9]{8}$").test(e)||(!!new RegExp("^17[012345678][0-9]{8}$").test(e)||!!new RegExp("^19[1589][0-9]{8}$").test(e)))))},t.isEmail=function(t){return!!t&&new RegExp("^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*\\.[a-z]{2,}$").test(t)},t.filterRichText=function(t){if(!t)return"";var e=new RegExp("<[^<>]+>","g");return t.replace(e,"")},t.getImageListFromRichText=function(t){var e=new Array,n=new RegExp("<img[^>]*>","g"),r=t.match(n);if(r&&r.length>0){var o=new RegExp("http\\S*((.jpg)|(.jpeg)|(.png))","g");r.forEach((function(t){var n=t.match(o);n&&n.length>0&&!e.includes(n[0])&&e.push(n[0])}))}return e},t.colorRbgToHex=function(t){var e=t.toLowerCase(),n=new RegExp("^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6 })$");if(new RegExp("^(rgb|RGB)").test(e)){for(var r=new RegExp("(?:\\(|\\)|rgb|RGB)*","g"),o=e.replace(r,"").split(","),i="#",a=0;a<o.length;a++){var u=Number(o[a]).toString(16);"0"===u&&(u+=u),i+=u}return 7!==i.length&&(i=e),i}if(n.test(e)){var s=e.replace("#","").split("");if(6===s.length)return e;if(3===s.length){var f="#";for(a=0;a<s.length;a+=1)f+=s[a]+s[a];return f}}return e},t.colorHexToRgb=function(t){var e=t.toLowerCase(),n=new RegExp("^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$");if(e&&n.test(e)){if(4===e.length){for(var r="#",o=1;o<4;o+=1)r+=e.slice(o,o+1).concat(e.slice(o,o+1));e=r}var i=[];for(o=1;o<7;o+=2)i.push(parseInt("0x"+e.slice(o,o+2)));return"rgb("+i.join(",")+")"}return e},t.formatNumber=function(t){if(!t)return"0";var e=String(t).split("."),n=new RegExp("(\\d)(?=(?:\\d{3})+$)"),r=String(e[0]).replace(n,"$1,");return e.length>1?"".concat(r,".").concat(e[1]):r},t.desensitize=function(t){if(new RegExp("[一-龥]").test(t))return t[0]+"***";var e=String(t);if(11===e.length)return"".concat(e.slice(0,3),"****").concat(e.slice(7,11));var n=new RegExp("^(.{6})(?:\\d+)(.{4})$");return e.replace(n,"$1********$2")},t.generateUUID=function(){var t=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var n=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?n:3&n|8).toString(16)}))},t}(),h=function(){return h=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},h.apply(this,arguments)};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function p(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}var y=function(){function t(){}return t.makeUpGroupList=function(t,e){if(t&&t.length>0){var n=p([],t,!0);if(e<2)return n;var r=n.length%e;if(r>0)for(var o=0,i=e-r;o<i;o++)n.push({});return n}return t},t.grouping=function(t,e){if(t&&e>0){for(var n=[],r=t.length,o=0,i=e;o<r;)n.push(t.slice(o,i)),o+=e,i+=e;return n}return[]},t}(),m=function(){function t(){}return t.cloneFunction=function(t){var e=new RegExp("(?<={)(.|\\n)+(?=})","m"),n=new RegExp("(?<=\\().+(?=\\)\\s+{)"),r=t.toString(),o=n.exec(r),i=e.exec(r);if(o){var a=o[0].split(",");return i&&i[0]?new(Function.bind.apply(Function,p(p([void 0],a,!1),[i[0]],!1))):new(Function.bind.apply(Function,p([void 0],a,!1)))}return i&&i[0]?new Function(i[0]):new Function},t.cloneDeep=function(e,n){if(null==e)return e;if(e instanceof Function)return t.cloneFunction(e);if("object"!=typeof e)return e;if(e instanceof Date)return new Date(e);if(e instanceof RegExp)return new RegExp(e);if(e instanceof Symbol)return Symbol(e.description);if(e instanceof Map){var r=new Map;return e.forEach((function(e,n){r.set(n,t.cloneDeep(e))})),r}if(e instanceof Set){var o=new Set;return e.forEach((function(e,n){o.add(t.cloneDeep(e))})),o}if(e instanceof Array){for(var i=new Array,a=0,u=e.length;a<u;a++)i.push(t.cloneDeep(e[a]));return i}if(e instanceof Object){var s=n||new WeakMap;if(s.get(e))return n.get(e);var f={};for(var c in e)f[c]=t.cloneDeep(e[c],s);return s.set(e,f),f}},t.extendObject=function(e,n){return n&&"object"==typeof n?(e&&"object"==typeof n&&Object.keys(n).forEach((function(r){void 0===e[r]?e[r]=n[r]:"object"==typeof e[r]&&t.extendObject(e[r],n[r])})),e):e},t.containObject=function(e,n){if(!e||e.length<1)return!1;for(var r=0,o=e.length;r<o;r++)if(t.equalDeep(e[r],n))return!0;return!1},t.equalDeep=function(e,n){var r=typeof e;if(r!==typeof n)return!1;if("string"===r||"number"===r||"undefined"===r||"boolean"===r)return e===n;if("object"===r){if(e instanceof Array)return e.length==e.length&&(!!e.every((function(e){return t.containObject(n,e)}))&&n.every((function(n){return t.containObject(e,n)})));var o=Object.keys(e),i=Object.keys(n);if(o.length!==i.length)return!1;if(i.filter((function(t){return o.includes(t)})).length!==o.length)return!1;for(var a=0,u=o.length;a<u;a++){if(!t.equalDeep(e[o[a]],n[o[a]]))return!1}return!0}return!1},t.getObjectByList=function(t,e){var n={};if(t&&t.length>0&&e&&"object"==typeof e)for(var r=0,o=t.length;r<o;r++){var i=t[r];i&&(n[i]=e[i])}return n},t.getObjectByObject=function(e,n){if(e&&n&&"object"==typeof e&&"object"==typeof n){var r=Object.keys(e);return t.getObjectByList(r,n)}return{}},t.getValueFromObject=function(e,n){if("object"==typeof e&&n&&"string"==typeof n){if(e[n])return e[n];if(n.indexOf(".")<0)return e[n];var r=n.split(".");if(e[r[0]]&&e[r[0]]instanceof Object){var o=r.slice(1).join(".");return t.getValueFromObject(e[r[0]],o)}}return""},t.addWatcher=function(e,n){Object.keys(n).forEach((function(r){t.observe(e,r,n[r])}))},t.observe=function(e,n,r){if(e&&"object"==typeof e){var o=e[n];if(o)Object.defineProperty(e,n,{configurable:!0,enumerable:!0,set:function(t){var e=o;o=t,r(t,e)},get:function(){return o}});else{var i=n.indexOf(".");if(i>0){var a=n.substring(0,i),u=n.substring(i+1);t.observe(e[a],u,r)}}}},t}(),d=function(){function t(){}return t.getQueryMapFromUrl=function(t){var e=new Map;if(t&&t.indexOf("?")>0){var n=t.substring(t.indexOf("?")+1).split("&");n&&n.length>0&&n.forEach((function(t){var n=t.split("=");n&&n.length>1&&e.set(n[0],n[1])}))}return e},t.getQueryUrl=function(t,e){var n=-1!==t.indexOf("?");if(void 0!==e&&e instanceof Object){var r=t;for(var o in e)void 0!==e[o]&&(r.endsWith("?")?r="".concat(r).concat(o,"=").concat(e[o]):(r="".concat(r).concat(n?"&":"?").concat(o,"=").concat(e[o]),n||(n=!0)));return r}return t},t}(),v="get",b="post",D="delete",x="head",M="CONNECT",w="options",I="put",R="patch",C="TRACE",F="LINK",q="unlink",O=function(){function t(t,e,n,r){this.platform=t,this.baseUrl=n,this.requestInterceptorsConfig=r,this.taskMap=new Map,this.isMiniApp=e}return t.prototype.post=function(t,e,n,r){return this.request(t,b,e,n,r)},t.prototype.get=function(e,n,r,o){var i=t.getTargetUrl(e,n);return this.request(i,v,{},r,o)},t.prototype.put=function(t,e,n,r){return this.request(t,I,e,n,r)},t.prototype.delete=function(t,e,n,r){return this.request(t,D,e,n,r)},t.prototype.head=function(t,e,n,r){return this.request(t,x,e,n,r)},t.prototype.options=function(t,e,n,r){return this.request(t,w,e,n,r)},t.prototype.connect=function(t,e,n,r){return this.request(t,M,e,n,r)},t.prototype.trace=function(t,e,n,r){return this.request(t,C,e,n,r)},t.prototype.patch=function(t,e,n,r){return this.request(t,R,e,n,r)},t.prototype.link=function(t,e,n,r){return this.request(t,F,e,n,r)},t.prototype.unlink=function(t,e,n,r){return this.request(t,q,e,n,r)},t.getTargetUrl=function(t,e){if(e&&Object.keys(e).length>0){var n=-1!==t.indexOf("?"),r=t;for(var o in e)void 0!==e[o]&&(r.endsWith("?")?r="".concat(r).concat(o,"=").concat(e[o]):(r="".concat(r).concat(n?"&":"?").concat(o,"=").concat(e[o]),n||(n=!0)));return r}return t},t.prototype.request=function(t,e,n,r,o){if(this.requestInterceptorsConfig&&"function"==typeof this.requestInterceptorsConfig.getCacheData){var i=this.requestInterceptorsConfig.getCacheData(this.baseUrl,t,n);if(void 0!==i)return Promise.resolve(i)}var a=h({"Content-Type":"application/json"},r),u=this.requestInterceptorsConfig&&this.requestInterceptorsConfig.onRequestInterceptor?this.requestInterceptorsConfig.onRequestInterceptor(a):a,s={baseURL:"",url:this.getRequestUrl(t),method:e,data:n,header:h({},u)};return this.isMiniApp&&this.platform&&this.platform.request&&"function"==typeof this.platform.request?this.miniAppRequest(s,o,t,n):this.platform&&"function"==typeof this.platform?this.commonRequest(s,o,t,n):void 0},t.prototype.getRequestUrl=function(t){if(t.startsWith("https://")||t.startsWith("http://"))return t;if(this.baseUrl){var e=this.baseUrl.endsWith("/"),n=t.startsWith("/");return e&&n?this.baseUrl.substring(0,this.baseUrl.length-1)+t:e||n?this.baseUrl+t:this.baseUrl+"/"+t}return t},t.prototype.miniAppRequest=function(t,e,n,r){var o=this;return new Promise((function(i,a){var u=h(h({},t),{fail:function(t){e&&o.taskMap.delete(e),a(t)},success:function(t){e&&o.taskMap.delete(e),o.successHandler(i,a,t,n,r)}}),s=o.platform.request(u);e&&s&&o.taskMap.set(e,s)}))},t.prototype.successHandler=function(t,e,n,r,o){var i=this.getResponseData(n,r,o);i.success?t(i.data):e(i.data)},t.prototype.getResponseData=function(t,e,n){var r={success:!0,data:t};return this.requestInterceptorsConfig&&"function"==typeof this.requestInterceptorsConfig.onResponseInterceptor&&(r=this.requestInterceptorsConfig.onResponseInterceptor(t)),r.success&&this.requestInterceptorsConfig&&"function"==typeof this.requestInterceptorsConfig.updateResponseCache&&this.requestInterceptorsConfig.updateResponseCache(t,this.baseUrl,e,n),r},t.prototype.commonRequest=function(t,e,n,r){var o=this;return new Promise((function(e,i){o.platform(t).then((function(t){o.successHandler(e,i,t,n,r)})).catch((function(t){i(t)}))}))},t}(),T=new Map,j=function(){function t(){}return t.getHttpClient=function(t,e,n,r){if(T.has(n)){var o=T.get(n);if(void 0!==o)return o}var i=r(),a=new O(t,e,n,i||{});return T.set(n,a),a},t}(),E={DateConstants:t,CountDownTimer:n,CalendarData:u,LogUtils:s,isIdCard:function(t){if(!new RegExp("(^\\d{15}$)|(^\\d{17}(\\d|X|x)$)").test(t))return console.log("身份证长度或格式错误"),!1;var e=String(t);if(15===e.length&&(e=function(t){if(t&&15===t.length){for(var e=t.substring(0,6)+"19"+t.substring(6),n=0,r=0;r<17;r++)n+=Number.parseInt(e[r])*c[r];return e+l[n%11]}}(e)),!f[e.substring(0,2)])return console.log("身份证地区非法"),!1;var n=(e.substring(6,10)+"-"+Number(e.substring(10,12))+"-"+Number(e.substring(12,14))).replace(/-/g,"/"),r=new Date(n);if(n!=r.getFullYear()+"/"+(r.getMonth()+1)+"/"+r.getDate())return console.log("身份证上的出生日期非法"),!1;var o=new Date;if(o.setHours(23,59,59),r.setHours(23,59,59),o.getTime()-r.getTime()<0)return console.log("身份证上的出生日期非法,出生日期大于当前日期"),!1;var i=o.getFullYear()-r.getFullYear();if(i<0||i>150)return console.log("出生日期岁数不合理"),!1;for(var a=0,u=0;u<e.length-1;u++)a+=Number.parseInt(e[u])*c[u];var s=l[a%11];return e[e.length-1]==s||(console.log("你输入的身份证号非法"),!1)},StringHelper:g,ObjectHelper:m,DateHelper:o,ArrayHelper:y,UrlHelper:d,HttpRequest:j,HttpClient:O};export{E as default};
declare class CountDownInfo {
time: number;
day: number;
hour: number;
minute: number;
second: number;
constructor(time: number);
format(value: number): string;
}
declare type CountDownFinishCallback = () => void;
declare type CountDownCallback = (info: CountDownInfo) => void;
declare class CountDownTimer {
private millisInFuture;
private readonly mInterval;
private onCountDownFinishListener;
private onCountDownListener;
private timeOutId;
/**
* @param millisInFuture 时间毫秒数
* @param countDownInterval 时间毫秒数(单位间隔)
*/
constructor(millisInFuture: number, countDownInterval: number);
addCountDownListener(listener: CountDownCallback): void;
addFinishListener(listener: CountDownFinishCallback): void;
start(): void;
cancel(): void;
static getTimeInfo(time: number): CountDownInfo;
}
declare class DayData {
year: number;
month: number;
day: number;
isSupplementDay: boolean;
titleName: string;
formatDay: string;
time: number;
constructor(year: number, month: number, day: number);
equals(object: DayData): boolean;
toString(): string;
}
declare class MonthData {
titleName: string;
year: number;
month: number;
dayItems: Array<DayData>;
constructor(year: number, month: number);
toString(): string;
}
declare class CalendarData {
monthCount: number;
startYear: number;
startMonth: number;
monthDataList: Array<MonthData>;
/**
* @param monthCount 月份个数
* @param startYear 起始年
* @param startMonth 起始月
*/
constructor(monthCount: number, startYear?: number, startMonth?: number);
/**
* 获取当前时间 (2018-08-15)
*/
static getCurrentFormatDateString(): string;
/**
* 获取日历数据
* @param year
* @param month
*/
static getCalendarMonth(year: number, month: number): MonthData;
/**
* 获取上个月的数据
* @param year
* @param month
*/
static getLastMonthData(year: number, month: number): MonthData;
/**
* 获取下个月的数据
* @param year
* @param month
*/
static getNextMonth(year: number, month: number): MonthData;
/**
* 获取当前月份的日历数据
*/
static getCurrentMonth(): MonthData;
/**
* 获取日历基础数据(从当前月,往后推)
* @param count
* @returns {Array}
*/
static getCalendarMonthList(count: number): Array<MonthData>;
}
declare class LogUtils {
private readonly enableDebug;
constructor(debug: any);
getTag(tag: string): string;
debug(msg: any): void;
debugWithTag(tag: string, msg: any): void;
info(msg: any): void;
infoWithTag(tag: string, msg: any): void;
log(msg: any): void;
logWithTag(tag: string, msg: any): void;
error(msg: any): void;
errorWithTag(tag: string, msg: any): void;
warn(msg: any): void;
warnWithTag(tag: string, msg: any): void;
}
/**
* 判断身份证是否合法
* @param cardNo
*/
declare function isIdCard(cardNo: string): boolean;
declare class StringHelper {
/**
* 替换所有
* @param content 当前文本
* @param pattern 旧字符串或者正则表达式
* @param newStr 要替换的内容
* @returns {*} 返回新的字符串
*/
static replaceAll(content: string, pattern: string, newStr: string): string;
static isEmpty(str: string): boolean;
/**
* 是否是组织机构代码
* @param code
* @returns {*|boolean}
*/
static isOrganizationCode(code: string): boolean;
/**
* 18位的统一信用代码
* @param code
* @returns {*|boolean}
*/
static isUnifiedCreditCode(code: string): boolean;
/**
* 校验手机号(严格校验)
* //移动号段:134 135 136 137 138 139 147 148 150 151 152 157 158 159 165 172 178 182 183 184 187 188 195 198
* // 联通号段:130 131 132 145 146 155 156 166 167 171 175 176 185 186
* // 电信号段:133 149 153 173 174 177 180 181 189 191 199
* // 虚拟运营商:170
* 分组如下
* //130 131 132 133 134 135 136 137 138 139
* //145 146 147 148 149
* //150 151 152 153 155 156 157 158 159
* // 165 166 167
* //170 171 172 173 174 175 176 177 178
* //180 181 182 183 184 185 186 187 188 189
* // 191 195 198 199
* @param phone
* @returns {boolean}
*/
static isPhoneNumber(phone: number | string): boolean;
/**
* 判断是否是邮件地址
* @param email
* @returns {boolean}
*/
static isEmail(email: string): boolean;
/**
* 获取文本(过滤副文本标签)
* @param richText
*/
static filterRichText(richText: string): string;
/**
* 从富文本中,查找img 标签,收集图片地址(只支持.png .jpg .jpeg 结尾)
* @param text 富文本
* @returns {[]} 返回图片列表
*/
static getImageListFromRichText(text: string): Array<string>;
static colorRbgToHex(rgbColor: string): string;
/**
*16进制颜色转为RGB格式
* @param hexColor 16进制颜色
* @returns {string} RGB格式颜色
*/
static colorHexToRgb(hexColor: string): string;
/**
* 将整数部分逢三一断
* @param value
* @returns {string}
*/
static formatNumber(value: String | number): string;
/**
* 通用脱敏
*
* 中文名字:只展示姓名第一个字
* 手机号:前三后四不脱敏,中间脱敏
* 身份证号:前6后4不脱敏,年月日脱敏
* 银行卡:前6位和后4位不脱敏,中间脱敏
* 其他 前6位和后4位不脱敏
* @param codeStr
* @return {string}
*/
static desensitize(codeStr: any): string;
/**
* 生成唯一的uuid;
*/
static generateUUID(): string;
}
declare class ArrayHelper {
static makeUpGroupList(list: Array<any>, groupNumber: number): Array<any>;
/**
* 将数据分组
* @param value 数据源
* @param groupNumber 分组的个数
* @returns {[]|*} 返回分组后的列表
*/
static grouping(value: Array<any> | string, groupNumber: number): Array<Array<any>>;
}
declare type WatchFun = (newVal: any, oldVal: any) => void;
declare class ObjectHelper {
/**
* 克隆函数
* @param func
*/
static cloneFunction(func: Function): any;
/**
* 深度克隆对象
* @param obj
* @param cache
*/
static cloneDeep(obj: object | Array<any>, cache?: WeakMap<object, object>): any;
/**
* 将某个对象追加到当前对象中(扩展对象,类似java中的继承)
* @param targetObject
* @param sourceObject
*/
static extendObject(targetObject: object, sourceObject: object): object;
/**
* 判断列表是是否包含特定的对象
* @param list
* @param object
*/
static containObject(list: Array<any>, object: any): boolean;
/**
* 深入比较对象(判断对象是否相等)
* @param object_1
* @param object_2
*/
static equalDeep(object_1: any, object_2: any): boolean;
/**
*
* @param keysList 取值字段列表 ["a","b"]
* @param valuesObject 目标对象{a:"a",b:"11",c:"aaaa",d:"dd"}
* @return {} //如{a:"a",b:"11"}
*/
static getObjectByList(keysList: Array<string>, valuesObject: object): object;
/**
* 根据当前对象的key,从目标对象中取值
* @param keysObject {a:""}
* @param targetObject 目标对象{a:"a",b:"11",c:"aaaa",d:"dd"}
* @return {} //如{a:"a"}
*/
static getObjectByObject(keysObject: object, targetObject: object): object;
/**
* 从对象中获取值 (支持 "a.b.c" 获取值)
* @param obj
* @param keyWords
*/
static getValueFromObject(obj: object, keyWords: any): any;
/**
* 设置监听器
*/
static addWatcher(data: object, watch: Record<string, (...args: any[]) => any>): void;
/**
* 监听属性 并执行监听函数
*/
static observe(obj: object, key: string, watchFun: WatchFun): void;
}
declare class UrlHelper {
/**
* 从地址中截取参数
* @param url
* @returns {Map<any, any>}
*/
static getQueryMapFromUrl(url: string): Map<string, any>;
/**
* 获取跳转目标路径
* @param baseUrl
* @param params
* @returns {*}
*/
static getQueryUrl(baseUrl: string, params: object): string;
}
declare type DateType = string | number | Date;
declare type MonthDayNumber = 29 | 28 | 31 | 30;
declare class DateHelper {
/**
* 获取日期实例
* 兼容ios new Date('2020-10-10') 返回Invalid Date
* @param date
*/
static getDateInstance(date: DateType): Date;
/**
* 获取某年某月第一天是星期几
* @param year
* @param month
*/
static getWeekDay(year: number, month: number): number;
/**
* 格式化数字符串
* @param num
*/
static formatNumber(num: number): string;
static isToday(date: DateType): boolean;
static getFormatDate(date: DateType): string;
static getCurrentFormatDate(): string;
/**
* 获取当前日期所在月份的天数
* @param date
*/
static getDaysInMonth(date: DateType): MonthDayNumber;
/**
* 获取星期名称
* @param date 日期
* @param isEnglish true 表示是英文
*/
static getWeekName(date: DateType, isEnglish?: boolean): string;
/**
* 是否是闰年
* @param year
*/
static isLeapYear(year: number): boolean;
/**
* 获取指定月份天数
* @param year
* @param month
* @returns {number}
*/
static getMonthDays(year: number, month: number): MonthDayNumber;
/**
*获取下个月信息
* @param year
* @param month
*/
static getNextMonthInfo(year: number, month: number): {
year: number;
month: number;
};
/**
* 获取上个月信息
* @param year
* @param month
*/
static getLastMonthInfo(year: number, month: number): {
year: number;
month: number;
};
static diffTime(startTime: number, endTime: number, unitTime: number): number;
/**
*相差年份数
* @param startTime
* @param endTime
*/
static diffYears(startTime: number, endTime: number): number;
/**
* 相差月分数
* @param startTime
* @param endTime
*/
static diffMonths(startTime: number, endTime: number): number;
/**
* 相差天数
* @param startTime
* @param endTime
*/
static diffDays(startTime: number, endTime: number): number;
/**
* 相差小时数
* @param startTime
* @param endTime
*/
static diffHours(startTime: number, endTime: number): number;
/**
* 相差分数
* @param startTime
* @param endTime
*/
static diffMinutes(startTime: number, endTime: number): number;
/**
* 相差月秒数
* @param startTime
* @param endTime
*/
static diffSeconds(startTime: number, endTime: number): number;
/**
* 格式化时间
* @param date
* @param formatStyle
*/
static formatDateString(date: DateType, formatStyle: string): string;
}
interface ResponseInterceptor {
success: boolean;
data: any;
}
/**
* 拦截器配置信息
*/
interface InterceptorsConfig {
/**
* 接口请求拦截器
* @param header
*/
onRequestInterceptor?: (header: object) => object;
/**
* 接口响应拦截器
* @param response
*/
onResponseInterceptor?: (response: any) => ResponseInterceptor;
/**
* 获取缓存数据
* @param baseUrl
* @param url
* @param params
*/
getCacheData?: (baseUrl: string, url: string, params?: any) => any;
/**
* 更新响应数据缓存
* @param data
* @param baseUrl
* @param url
* @param params
*/
updateResponseCache?: (data: any, baseUrl: string, url: string, params?: any) => void;
/**
* 获取缓存的Key
* @param baseUrl
* @param url
* @param data
* @param params
*/
getCacheKey?: (baseUrl: string, url: string, data: any, params?: any) => string;
}
declare class HttpClient {
private readonly baseUrl;
private readonly platform;
private readonly requestInterceptorsConfig;
private readonly taskMap;
private readonly isMiniApp;
constructor(platform: object, isMiniApp: boolean, baseUrl: string, requestInterceptorsConfig: InterceptorsConfig);
post<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T>;
get<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T>;
put<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T>;
delete<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T>;
head<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T>;
options<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T>;
connect<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T>;
trace<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T>;
patch<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T>;
link<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T>;
unlink<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T>;
private static getTargetUrl;
private request;
private getRequestUrl;
private miniAppRequest;
private successHandler;
private getResponseData;
private commonRequest;
}
declare type ClientInterceptors = () => InterceptorsConfig;
declare class HttpRequest {
/**
* 获取求实例
* @param platform 平台
* @param isMiniApp 是不是小程序
* @param baseUrl 地址
* @param interceptors 拦截器信息
*/
static getHttpClient(platform: any, isMiniApp: boolean, baseUrl: string, interceptors?: ClientInterceptors): HttpClient;
}
declare const _default: {
DateConstants: {
dayMillis: number;
hourMillis: number;
minuteMillis: number;
secondMillis: number;
};
CountDownTimer: typeof CountDownTimer;
CalendarData: typeof CalendarData;
LogUtils: typeof LogUtils;
isIdCard: typeof isIdCard;
StringHelper: typeof StringHelper;
ObjectHelper: typeof ObjectHelper;
DateHelper: typeof DateHelper;
ArrayHelper: typeof ArrayHelper;
UrlHelper: typeof UrlHelper;
HttpRequest: typeof HttpRequest;
HttpClient: typeof HttpClient;
};
export { ArrayHelper, CalendarData, CountDownTimer, DateHelper, DayData, InterceptorsConfig, LogUtils, MonthData, ObjectHelper, ResponseInterceptor, StringHelper, UrlHelper, _default as default, isIdCard };
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).generalTools=e()}(this,(function(){"use strict";var t={dayMillis:864e5,hourMillis:36e5,minuteMillis:6e4,secondMillis:1e3},e=function(){function e(e){var n=e%t.dayMillis,r=e%t.hourMillis,o=e%t.minuteMillis;this.time=e,this.day=Math.floor(e/t.dayMillis),this.hour=Math.floor(n/t.hourMillis),this.minute=Math.floor(r/t.minuteMillis),this.second=Math.floor(o/t.secondMillis)}return e.prototype.format=function(t){return t>=10?t+"":"0"+t},e}(),n=function(){function t(t,e){this.millisInFuture=t,this.mInterval=e,this.onCountDownFinishListener=void 0,this.onCountDownListener=void 0,this.timeOutId=void 0}return t.prototype.addCountDownListener=function(t){t&&"function"==typeof t&&(this.onCountDownListener=t)},t.prototype.addFinishListener=function(t){t&&"function"==typeof t&&(this.onCountDownFinishListener=t)},t.prototype.start=function(){var e=this;this.timeOutId||null==this.onCountDownListener||(this.timeOutId=setInterval((function(){e.millisInFuture=e.millisInFuture-e.mInterval,e.millisInFuture>0?e.onCountDownListener(t.getTimeInfo(e.millisInFuture)):(e.cancel(),void 0!==e.onCountDownFinishListener&&e.onCountDownFinishListener())}),this.mInterval))},t.prototype.cancel=function(){this.timeOutId&&(clearTimeout(this.timeOutId),this.timeOutId=void 0)},t.getTimeInfo=function(t){return new e(t)},t}(),r=[{symbolList:["yyyy","YYYY"],getValue:function(t){return o.formatNumber(t.getFullYear())}},{symbolList:["MM"],getValue:function(t){return o.formatNumber(t.getMonth()+1)}},{symbolList:["DD","dd"],getValue:function(t){return o.formatNumber(t.getDate())}},{symbolList:["HH","hh"],getValue:function(t){return o.formatNumber(t.getHours())}},{symbolList:["mm"],getValue:function(t){return o.formatNumber(t.getMinutes())}},{symbolList:["SS","ss"],getValue:function(t){return o.formatNumber(t.getSeconds())}}],o=function(){function e(){}return e.getDateInstance=function(t){if(t instanceof Date)return t;if("string"==typeof t&&t.indexOf("-")>0){var e=new RegExp("-","g");t=t.replace(e,"/")}return new Date(t)},e.getWeekDay=function(t,e){return new Date(t,e-1,1).getDay()},e.formatNumber=function(t){return t>9?t+"":"0"+t},e.isToday=function(t){var n=new Date,r=e.getDateInstance(t);return n.getFullYear()===r.getFullYear()&&r.getMonth()===n.getMonth()&&r.getDate()===n.getDate()},e.getFormatDate=function(t){var n=e.getDateInstance(t);return n.getFullYear()+"-"+e.formatNumber(n.getMonth()+1)+"-"+e.formatNumber(n.getDate())},e.getCurrentFormatDate=function(){return e.getFormatDate(new Date)},e.getDaysInMonth=function(t){var n=e.getDateInstance(t),r=n.getMonth()+1;return e.getMonthDays(n.getFullYear(),r)},e.getWeekName=function(t,n){void 0===n&&(n=!1);var r=e.getDateInstance(t).getDay();return 0===r?n?"Sunday":"周日":1===r?n?"Monday":"周一":2===r?n?"Tuesday":"周二":3===r?n?"Wednesday":"周三":4===r?n?"Thursday":"周四":5===r?n?"Friday":"周五":6===r?n?"Saturday":"周六":""},e.isLeapYear=function(t){return t%400==0||t%4==0&&t%100!=0},e.getMonthDays=function(t,n){if(2===n)return e.isLeapYear(t)?29:28;return[1,3,5,7,8,10,12].includes(n)?31:30},e.getNextMonthInfo=function(t,e){return{year:e>=12?t+1:t,month:e>=12?1:e+1}},e.getLastMonthInfo=function(t,e){return{year:1==e?t-1:t,month:1==e?12:e-1}},e.diffTime=function(t,e,n){var r=e-t;return Math.floor(r/n*100)/100},e.diffYears=function(t,n){var r=e.diffMonths(t,n);return Math.floor(r/12*100)/100},e.diffMonths=function(t,n){var r=Math.min(t,n),o=Math.max(t,n),i=e.getDateInstance(r),u=e.getDateInstance(o),a=u.getFullYear()-i.getFullYear(),s=i.getMonth()+1,f=u.getMonth()+1;return f<s&&(a-=1,f+=12),Number.parseInt((12*a+f-s).toFixed(0))},e.diffDays=function(n,r){return e.diffTime(n,r,t.dayMillis)},e.diffHours=function(n,r){return e.diffTime(n,r,t.hourMillis)},e.diffMinutes=function(n,r){return e.diffTime(n,r,t.minuteMillis)},e.diffSeconds=function(n,r){return e.diffTime(n,r,t.secondMillis)},e.formatDateString=function(t,n){var o=String(n);if(n){var i=e.getDateInstance(t);r.forEach((function(t){for(var e=0,n=t.symbolList.length;e<n;e++)if(o.indexOf(t.symbolList[e])>=0){o=o.replace(t.symbolList[e],t.getValue(i));break}}))}return o},e}(),i=function(){function t(t,e,n){this.year=t,this.month=e,this.day=n,this.isSupplementDay=!1,this.titleName=String(n),this.formatDay="".concat(t,"-").concat(o.formatNumber(e),"-").concat(o.formatNumber(n));var r=new Date(this.formatDay);r.setHours(0,0,0,0),this.time=r.getTime()}return t.prototype.equals=function(t){return this.year===t.year&&this.month===t.month&&this.day===t.day},t.prototype.toString=function(){return"year= "+this.year+" year= "+this.year+" year= "+this.year},t}(),u=function(){function t(t,e){this.titleName=String(e),this.year=t,this.month=e;var n=o.getMonthDays(t,e);this.dayItems=[];for(var r=1;r<=n;r++){var u=new i(this.year,this.month,r);this.dayItems.push(u)}}return t.prototype.toString=function(){return"year= "+this.year+" month= "+this.month},t}(),a=function(){function t(e,n,r){this.monthCount=e,this.startYear=n&&n>=1970?n:(new Date).getFullYear(),this.startMonth=r&&r>0&&r<=12?r:(new Date).getMonth()+1;var o=new Array,i=t.getCalendarMonth(this.startYear,this.startMonth);o.push(i);for(var u=1;u<e;u++)i=t.getNextMonth(i.year,i.month),o.push(i);this.monthDataList=o}return t.getCurrentFormatDateString=function(){var t=new Date;return t.getFullYear()+"-"+o.formatNumber(t.getMonth()+1)+"-"+o.formatNumber(t.getDate())},t.getCalendarMonth=function(t,e){var n=new u(t,e),r=o.getWeekDay(t,e);if(r>0)for(var a=o.getLastMonthInfo(t,e),s=o.getMonthDays(a.year,a.month),f=0;f<r;f++){var c=s-r+1+f;(h=new i(a.year,a.month,c)).isSupplementDay=!0,n.dayItems.unshift(h)}var l=7-n.dayItems.length%7;if(l<7){var g=o.getNextMonthInfo(t,e);for(f=0;f<l;f++){var h;(h=new i(g.year,g.month,f+1)).isSupplementDay=!0,n.dayItems.push(h)}}return n},t.getLastMonthData=function(e,n){var r=o.getLastMonthInfo(e,n);return t.getCalendarMonth(r.year,r.month)},t.getNextMonth=function(e,n){var r=o.getNextMonthInfo(e,n);return t.getCalendarMonth(r.year,r.month)},t.getCurrentMonth=function(){var e=new Date;return t.getCalendarMonth(e.getFullYear(),e.getMonth()+1)},t.getCalendarMonthList=function(e){var n=[],r=t.getCurrentMonth();n.push(r);for(var o=1;o<e;o++)r=t.getNextMonth(r.year,r.month),n.push(r);return n},t}(),s=function(){function t(t){this.enableDebug=t}return t.prototype.getTag=function(t){return t+"===================="},t.prototype.debug=function(t){this.enableDebug&&console.debug(t)},t.prototype.debugWithTag=function(t,e){this.enableDebug&&console.debug(this.getTag(t),e)},t.prototype.info=function(t){this.enableDebug&&console.info(t)},t.prototype.infoWithTag=function(t,e){this.enableDebug&&console.info(this.getTag(t),e)},t.prototype.log=function(t){this.enableDebug&&console.log(t)},t.prototype.logWithTag=function(t,e){this.enableDebug&&console.log(this.getTag(t),e)},t.prototype.error=function(t){this.enableDebug&&console.error(t)},t.prototype.errorWithTag=function(t,e){this.enableDebug&&console.error(this.getTag(t),e)},t.prototype.warn=function(t){this.enableDebug&&console.warn(t)},t.prototype.warnWithTag=function(t,e){this.enableDebug&&console.warn(this.getTag(t),e)},t}(),f={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"},c=[7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2],l=["1","0","X","9","8","7","6","5","4","3","2"];var g=function(){function t(){}return t.replaceAll=function(t,e,n){var r=new RegExp(e,"g");return t.replace(r,n)},t.isEmpty=function(t){return!t||t.trim().length<1},t.isOrganizationCode=function(t){return new RegExp("^[0-9A-HJ-NPQRTUWXY]{8}-[0-9A-HJ-NPQRTUWXY]$").test(t)},t.isUnifiedCreditCode=function(t){return new RegExp("^[0-9A-HJ-NPQRTUWXY]{2}\\d{6}[0-9A-HJ-NPQRTUWXY]{10}$").test(t)},t.isPhoneNumber=function(t){var e=String(t);return!!new RegExp("^1[38][0-9]{9}$").test(e)||(!!new RegExp("^14[56789][0-9]{8}$").test(e)||(!!new RegExp("^15[012356789][0-9]{8}$").test(e)||(!!new RegExp("^16[567][0-9]{8}$").test(e)||(!!new RegExp("^17[012345678][0-9]{8}$").test(e)||!!new RegExp("^19[1589][0-9]{8}$").test(e)))))},t.isEmail=function(t){return!!t&&new RegExp("^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*\\.[a-z]{2,}$").test(t)},t.filterRichText=function(t){if(!t)return"";var e=new RegExp("<[^<>]+>","g");return t.replace(e,"")},t.getImageListFromRichText=function(t){var e=new Array,n=new RegExp("<img[^>]*>","g"),r=t.match(n);if(r&&r.length>0){var o=new RegExp("http\\S*((.jpg)|(.jpeg)|(.png))","g");r.forEach((function(t){var n=t.match(o);n&&n.length>0&&!e.includes(n[0])&&e.push(n[0])}))}return e},t.colorRbgToHex=function(t){var e=t.toLowerCase(),n=new RegExp("^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6 })$");if(new RegExp("^(rgb|RGB)").test(e)){for(var r=new RegExp("(?:\\(|\\)|rgb|RGB)*","g"),o=e.replace(r,"").split(","),i="#",u=0;u<o.length;u++){var a=Number(o[u]).toString(16);"0"===a&&(a+=a),i+=a}return 7!==i.length&&(i=e),i}if(n.test(e)){var s=e.replace("#","").split("");if(6===s.length)return e;if(3===s.length){var f="#";for(u=0;u<s.length;u+=1)f+=s[u]+s[u];return f}}return e},t.colorHexToRgb=function(t){var e=t.toLowerCase(),n=new RegExp("^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$");if(e&&n.test(e)){if(4===e.length){for(var r="#",o=1;o<4;o+=1)r+=e.slice(o,o+1).concat(e.slice(o,o+1));e=r}var i=[];for(o=1;o<7;o+=2)i.push(parseInt("0x"+e.slice(o,o+2)));return"rgb("+i.join(",")+")"}return e},t.formatNumber=function(t){if(!t)return"0";var e=String(t).split("."),n=new RegExp("(\\d)(?=(?:\\d{3})+$)"),r=String(e[0]).replace(n,"$1,");return e.length>1?"".concat(r,".").concat(e[1]):r},t.desensitize=function(t){if(new RegExp("[一-龥]").test(t))return t[0]+"***";var e=String(t);if(11===e.length)return"".concat(e.slice(0,3),"****").concat(e.slice(7,11));var n=new RegExp("^(.{6})(?:\\d+)(.{4})$");return e.replace(n,"$1********$2")},t.generateUUID=function(){var t=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var n=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?n:3&n|8).toString(16)}))},t}(),h=function(){return h=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},h.apply(this,arguments)};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function p(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}var y=function(){function t(){}return t.makeUpGroupList=function(t,e){if(t&&t.length>0){var n=p([],t,!0);if(e<2)return n;var r=n.length%e;if(r>0)for(var o=0,i=e-r;o<i;o++)n.push({});return n}return t},t.grouping=function(t,e){if(t&&e>0){for(var n=[],r=t.length,o=0,i=e;o<r;)n.push(t.slice(o,i)),o+=e,i+=e;return n}return[]},t}(),m=function(){function t(){}return t.cloneFunction=function(t){var e=new RegExp("(?<={)(.|\\n)+(?=})","m"),n=new RegExp("(?<=\\().+(?=\\)\\s+{)"),r=t.toString(),o=n.exec(r),i=e.exec(r);if(o){var u=o[0].split(",");return i&&i[0]?new(Function.bind.apply(Function,p(p([void 0],u,!1),[i[0]],!1))):new(Function.bind.apply(Function,p([void 0],u,!1)))}return i&&i[0]?new Function(i[0]):new Function},t.cloneDeep=function(e,n){if(null==e)return e;if(e instanceof Function)return t.cloneFunction(e);if("object"!=typeof e)return e;if(e instanceof Date)return new Date(e);if(e instanceof RegExp)return new RegExp(e);if(e instanceof Symbol)return Symbol(e.description);if(e instanceof Map){var r=new Map;return e.forEach((function(e,n){r.set(n,t.cloneDeep(e))})),r}if(e instanceof Set){var o=new Set;return e.forEach((function(e,n){o.add(t.cloneDeep(e))})),o}if(e instanceof Array){for(var i=new Array,u=0,a=e.length;u<a;u++)i.push(t.cloneDeep(e[u]));return i}if(e instanceof Object){var s=n||new WeakMap;if(s.get(e))return n.get(e);var f={};for(var c in e)f[c]=t.cloneDeep(e[c],s);return s.set(e,f),f}},t.extendObject=function(e,n){return n&&"object"==typeof n?(e&&"object"==typeof n&&Object.keys(n).forEach((function(r){void 0===e[r]?e[r]=n[r]:"object"==typeof e[r]&&t.extendObject(e[r],n[r])})),e):e},t.containObject=function(e,n){if(!e||e.length<1)return!1;for(var r=0,o=e.length;r<o;r++)if(t.equalDeep(e[r],n))return!0;return!1},t.equalDeep=function(e,n){var r=typeof e;if(r!==typeof n)return!1;if("string"===r||"number"===r||"undefined"===r||"boolean"===r)return e===n;if("object"===r){if(e instanceof Array)return e.length==e.length&&(!!e.every((function(e){return t.containObject(n,e)}))&&n.every((function(n){return t.containObject(e,n)})));var o=Object.keys(e),i=Object.keys(n);if(o.length!==i.length)return!1;if(i.filter((function(t){return o.includes(t)})).length!==o.length)return!1;for(var u=0,a=o.length;u<a;u++){if(!t.equalDeep(e[o[u]],n[o[u]]))return!1}return!0}return!1},t.getObjectByList=function(t,e){var n={};if(t&&t.length>0&&e&&"object"==typeof e)for(var r=0,o=t.length;r<o;r++){var i=t[r];i&&(n[i]=e[i])}return n},t.getObjectByObject=function(e,n){if(e&&n&&"object"==typeof e&&"object"==typeof n){var r=Object.keys(e);return t.getObjectByList(r,n)}return{}},t.getValueFromObject=function(e,n){if("object"==typeof e&&n&&"string"==typeof n){if(e[n])return e[n];if(n.indexOf(".")<0)return e[n];var r=n.split(".");if(e[r[0]]&&e[r[0]]instanceof Object){var o=r.slice(1).join(".");return t.getValueFromObject(e[r[0]],o)}}return""},t.addWatcher=function(e,n){Object.keys(n).forEach((function(r){t.observe(e,r,n[r])}))},t.observe=function(e,n,r){if(e&&"object"==typeof e){var o=e[n];if(o)Object.defineProperty(e,n,{configurable:!0,enumerable:!0,set:function(t){var e=o;o=t,r(t,e)},get:function(){return o}});else{var i=n.indexOf(".");if(i>0){var u=n.substring(0,i),a=n.substring(i+1);t.observe(e[u],a,r)}}}},t}(),d=function(){function t(){}return t.getQueryMapFromUrl=function(t){var e=new Map;if(t&&t.indexOf("?")>0){var n=t.substring(t.indexOf("?")+1).split("&");n&&n.length>0&&n.forEach((function(t){var n=t.split("=");n&&n.length>1&&e.set(n[0],n[1])}))}return e},t.getQueryUrl=function(t,e){var n=-1!==t.indexOf("?");if(void 0!==e&&e instanceof Object){var r=t;for(var o in e)void 0!==e[o]&&(r.endsWith("?")?r="".concat(r).concat(o,"=").concat(e[o]):(r="".concat(r).concat(n?"&":"?").concat(o,"=").concat(e[o]),n||(n=!0)));return r}return t},t}(),v="get",b="post",D="delete",x="head",M="CONNECT",w="options",I="put",R="patch",C="TRACE",T="LINK",F="unlink",q=function(){function t(t,e,n,r){this.platform=t,this.baseUrl=n,this.requestInterceptorsConfig=r,this.taskMap=new Map,this.isMiniApp=e}return t.prototype.post=function(t,e,n,r){return this.request(t,b,e,n,r)},t.prototype.get=function(e,n,r,o){var i=t.getTargetUrl(e,n);return this.request(i,v,{},r,o)},t.prototype.put=function(t,e,n,r){return this.request(t,I,e,n,r)},t.prototype.delete=function(t,e,n,r){return this.request(t,D,e,n,r)},t.prototype.head=function(t,e,n,r){return this.request(t,x,e,n,r)},t.prototype.options=function(t,e,n,r){return this.request(t,w,e,n,r)},t.prototype.connect=function(t,e,n,r){return this.request(t,M,e,n,r)},t.prototype.trace=function(t,e,n,r){return this.request(t,C,e,n,r)},t.prototype.patch=function(t,e,n,r){return this.request(t,R,e,n,r)},t.prototype.link=function(t,e,n,r){return this.request(t,T,e,n,r)},t.prototype.unlink=function(t,e,n,r){return this.request(t,F,e,n,r)},t.getTargetUrl=function(t,e){if(e&&Object.keys(e).length>0){var n=-1!==t.indexOf("?"),r=t;for(var o in e)void 0!==e[o]&&(r.endsWith("?")?r="".concat(r).concat(o,"=").concat(e[o]):(r="".concat(r).concat(n?"&":"?").concat(o,"=").concat(e[o]),n||(n=!0)));return r}return t},t.prototype.request=function(t,e,n,r,o){if(this.requestInterceptorsConfig&&"function"==typeof this.requestInterceptorsConfig.getCacheData){var i=this.requestInterceptorsConfig.getCacheData(this.baseUrl,t,n);if(void 0!==i)return Promise.resolve(i)}var u=h({"Content-Type":"application/json"},r),a=this.requestInterceptorsConfig&&this.requestInterceptorsConfig.onRequestInterceptor?this.requestInterceptorsConfig.onRequestInterceptor(u):u,s={baseURL:"",url:this.getRequestUrl(t),method:e,data:n,header:h({},a)};return this.isMiniApp&&this.platform&&this.platform.request&&"function"==typeof this.platform.request?this.miniAppRequest(s,o,t,n):this.platform&&"function"==typeof this.platform?this.commonRequest(s,o,t,n):void 0},t.prototype.getRequestUrl=function(t){if(t.startsWith("https://")||t.startsWith("http://"))return t;if(this.baseUrl){var e=this.baseUrl.endsWith("/"),n=t.startsWith("/");return e&&n?this.baseUrl.substring(0,this.baseUrl.length-1)+t:e||n?this.baseUrl+t:this.baseUrl+"/"+t}return t},t.prototype.miniAppRequest=function(t,e,n,r){var o=this;return new Promise((function(i,u){var a=h(h({},t),{fail:function(t){e&&o.taskMap.delete(e),u(t)},success:function(t){e&&o.taskMap.delete(e),o.successHandler(i,u,t,n,r)}}),s=o.platform.request(a);e&&s&&o.taskMap.set(e,s)}))},t.prototype.successHandler=function(t,e,n,r,o){var i=this.getResponseData(n,r,o);i.success?t(i.data):e(i.data)},t.prototype.getResponseData=function(t,e,n){var r={success:!0,data:t};return this.requestInterceptorsConfig&&"function"==typeof this.requestInterceptorsConfig.onResponseInterceptor&&(r=this.requestInterceptorsConfig.onResponseInterceptor(t)),r.success&&this.requestInterceptorsConfig&&"function"==typeof this.requestInterceptorsConfig.updateResponseCache&&this.requestInterceptorsConfig.updateResponseCache(t,this.baseUrl,e,n),r},t.prototype.commonRequest=function(t,e,n,r){var o=this;return new Promise((function(e,i){o.platform(t).then((function(t){o.successHandler(e,i,t,n,r)})).catch((function(t){i(t)}))}))},t}(),O=new Map,j=function(){function t(){}return t.getHttpClient=function(t,e,n,r){if(O.has(n)){var o=O.get(n);if(void 0!==o)return o}var i=r(),u=new q(t,e,n,i||{});return O.set(n,u),u},t}();return{DateConstants:t,CountDownTimer:n,CalendarData:a,LogUtils:s,isIdCard:function(t){if(!new RegExp("(^\\d{15}$)|(^\\d{17}(\\d|X|x)$)").test(t))return console.log("身份证长度或格式错误"),!1;var e=String(t);if(15===e.length&&(e=function(t){if(t&&15===t.length){for(var e=t.substring(0,6)+"19"+t.substring(6),n=0,r=0;r<17;r++)n+=Number.parseInt(e[r])*c[r];return e+l[n%11]}}(e)),!f[e.substring(0,2)])return console.log("身份证地区非法"),!1;var n=(e.substring(6,10)+"-"+Number(e.substring(10,12))+"-"+Number(e.substring(12,14))).replace(/-/g,"/"),r=new Date(n);if(n!=r.getFullYear()+"/"+(r.getMonth()+1)+"/"+r.getDate())return console.log("身份证上的出生日期非法"),!1;var o=new Date;if(o.setHours(23,59,59),r.setHours(23,59,59),o.getTime()-r.getTime()<0)return console.log("身份证上的出生日期非法,出生日期大于当前日期"),!1;var i=o.getFullYear()-r.getFullYear();if(i<0||i>150)return console.log("出生日期岁数不合理"),!1;for(var u=0,a=0;a<e.length-1;a++)u+=Number.parseInt(e[a])*c[a];var s=l[u%11];return e[e.length-1]==s||(console.log("你输入的身份证号非法"),!1)},StringHelper:g,ObjectHelper:m,DateHelper:o,ArrayHelper:y,UrlHelper:d,HttpRequest:j,HttpClient:q}}));
{
"name": "mf-lib",
"version": "1.0.0",
"description": "",
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.mjs",
"browser": "./lib/umd/index.umd.js",
"types": "./lib/index.d.ts",
"type": "commonjs",
"scripts": {
"lib": " rimraf ./lib && rollup -c ./build/rollup.config.js",
"build": "rimraf ./dist && tsc -p tsconfig.json",
"test": "jest --no-cache && exit 0",
"doc": "typedoc --options typedoc.json && npm run doc:gh-fix",
"doc:gh-fix": "touch docs/.nojekyll"
},
"author": "bluefox",
"license": "ISC",
"files": [
"lib"
],
"devDependencies": {
"@types/jest": "^27.0.3",
"dts": "^0.1.1",
"jest": "^27.4.3",
"rimraf": "^3.0.2",
"rollup": "^2.60.2",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-dts": "^4.0.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-typescript2": "^0.31.1",
"ts-jest": "^27.1.0",
"tslib": "^2.3.1",
"typedoc": "^0.19.2",
"typedoc-neo-theme": "^1.0.10",
"typescript": "^4.0.5",
"yargs": "^17.3.0"
}
}
import {DateHelper} from "../helper/DateHelper";
import {MonthData} from "./MonthData"
import {DayData} from "./DayData"
export class CalendarData {
monthCount: number
startYear: number
startMonth: number
monthDataList: Array<MonthData>
/**
* @param monthCount 月份个数
* @param startYear 起始年
* @param startMonth 起始月
*/
constructor(monthCount: number, startYear?: number, startMonth?: number) {
this.monthCount = monthCount;
this.startYear = startYear && startYear >= 1970 ? startYear : new Date().getFullYear();
this.startMonth = startMonth && startMonth > 0 && startMonth <= 12 ? startMonth : new Date().getMonth() + 1;
const months = new Array<MonthData>();
let monthData = CalendarData.getCalendarMonth(this.startYear, this.startMonth);
months.push(monthData)
for (let i = 1; i < monthCount; i++) {
monthData = CalendarData.getNextMonth(monthData.year, monthData.month);
months.push(monthData)
}
this.monthDataList = months;
}
/**
* 获取当前时间 (2018-08-15)
*/
static getCurrentFormatDateString(): string {
const date = new Date();
return date.getFullYear() + "-" + DateHelper.formatNumber(date.getMonth() + 1) + "-" + DateHelper.formatNumber(date.getDate());
}
/**
* 获取日历数据
* @param year
* @param month
*/
static getCalendarMonth(year: number, month: number): MonthData {
const monthInfo = new MonthData(year, month);
const weekDay = DateHelper.getWeekDay(year, month);
if (weekDay > 0) {
//月份的第一天不是表的第一天。需要在前面插入上个月数据
const lastMonthInfo = DateHelper.getLastMonthInfo(year, month);
const lastMonthDays = DateHelper.getMonthDays(lastMonthInfo.year, lastMonthInfo.month)
for (let j = 0; j < weekDay; j++) {
const currentDay = lastMonthDays - weekDay + 1 + j;
const dayInfo = new DayData(lastMonthInfo.year, lastMonthInfo.month, currentDay);
dayInfo.isSupplementDay = true;
monthInfo.dayItems.unshift(dayInfo)
}
}
const size = monthInfo.dayItems.length;
//为了列表显示(个数必须是7的倍数),必须补充空数据
const emptyDays = 7 - size % 7;
if (emptyDays < 7) {
const nextMonthInfo = DateHelper.getNextMonthInfo(year, month)
for (let j = 0; j < emptyDays; j++) {
let dayInfo = new DayData(nextMonthInfo.year, nextMonthInfo.month, (j + 1));
dayInfo.isSupplementDay = true;
monthInfo.dayItems.push(dayInfo)
}
}
return monthInfo;
}
/**
* 获取上个月的数据
* @param year
* @param month
*/
static getLastMonthData(year: number, month: number): MonthData {
const info = DateHelper.getLastMonthInfo(year, month);
return CalendarData.getCalendarMonth(info.year, info.month)
}
/**
* 获取下个月的数据
* @param year
* @param month
*/
static getNextMonth(year: number, month: number): MonthData {
const info = DateHelper.getNextMonthInfo(year, month);
return CalendarData.getCalendarMonth(info.year, info.month)
}
/**
* 获取当前月份的日历数据
*/
static getCurrentMonth(): MonthData {
const date = new Date();
return CalendarData.getCalendarMonth(date.getFullYear(), date.getMonth() + 1)
}
/**
* 获取日历基础数据(从当前月,往后推)
* @param count
* @returns {Array}
*/
static getCalendarMonthList(count: number): Array<MonthData> {
const months = [];
let data = CalendarData.getCurrentMonth();
months.push(data)
for (let i = 1; i < count; i++) {
data = CalendarData.getNextMonth(data.year, data.month);
months.push(data)
}
return months;
}
}
import {DateHelper} from '../helper/DateHelper'
export class DayData {
year: number;
month: number;
day: number;
isSupplementDay: boolean;
titleName: string;
formatDay: string;
time: number;
constructor(year: number, month: number, day: number) {
this.year = year;
this.month = month;
this.day = day;
this.isSupplementDay = false;
this.titleName = String(day);
this.formatDay = `${year}-${DateHelper.formatNumber(month)}-${DateHelper.formatNumber(day)}`;
const date = new Date(this.formatDay);
date.setHours(0, 0, 0, 0)
this.time = date.getTime();
}
equals(object: DayData) {
return this.year === object.year && this.month === object.month && this.day === object.day
}
toString() {
return "year= " + this.year + " year= " + this.year + " year= " + this.year;
}
}
import {DayData} from "./DayData";
import {DateHelper} from "../helper/DateHelper";
export class MonthData {
titleName: string;
year: number;
month: number;
dayItems: Array<DayData>;
constructor(year: number, month: number) {
this.titleName = String(month);
this.year = year;
this.month = month;
const days = DateHelper.getMonthDays(year, month);
this.dayItems = [];
for (let i = 1; i <= days; i++) {
const dayInfo = new DayData(this.year, this.month, i);
this.dayItems.push(dayInfo);
}
}
toString(): string {
return "year= " + this.year + " month= " + this.month;
}
}
export class ArrayHelper {
static makeUpGroupList(list: Array<any>, groupNumber: number): Array<any> {
if (list && list.length > 0) {
const newList = [...list]
if (groupNumber < 2) {
return newList;
}
let endCount = newList.length % groupNumber;
if (endCount > 0) {//补全数据
for (let i = 0, len = groupNumber - endCount; i < len; i++) {
newList.push({})
}
}
return newList;
}
return list;
}
/**
* 将数据分组
* @param value 数据源
* @param groupNumber 分组的个数
* @returns {[]|*} 返回分组后的列表
*/
static grouping(value: Array<any> | string, groupNumber: number): Array<Array<any>> {
if (value && groupNumber > 0) {
const groupList = [];
let endLength = value.length;
let startIndex = 0;
let endIndex = groupNumber;
while (startIndex < endLength) {
groupList.push(value.slice(startIndex, endIndex))
startIndex = startIndex + groupNumber
endIndex = endIndex + groupNumber
}
return groupList;
}
return [];
}
}
import {dateConstants} from './DateConstants'
class CountDownInfo {
time: number;
day: number;
hour: number;
minute: number;
second: number;
constructor(time: number) {
let hourTime = time % dateConstants.dayMillis;//剩余的小时部分时间
let minuteTime = time % dateConstants.hourMillis;//剩余的分钟部分时间
let secondTime = time % dateConstants.minuteMillis;//剩余的秒部分时间
this.time = time;
this.day = Math.floor(time / dateConstants.dayMillis);
this.hour = Math.floor(hourTime / dateConstants.hourMillis);
this.minute = Math.floor(minuteTime / dateConstants.minuteMillis);
this.second = Math.floor(secondTime / dateConstants.secondMillis);
}
format(value: number): string {
return value >= 10 ? value + '' : "0" + value;
}
}
type CountDownFinishCallback = () => void;
type CountDownCallback = (info: CountDownInfo) => void;
export class CountDownTimer {
private millisInFuture: number;
private readonly mInterval: number;
private onCountDownFinishListener: CountDownFinishCallback;
private onCountDownListener: CountDownCallback;
private timeOutId: NodeJS.Timeout;
/**
* @param millisInFuture 时间毫秒数
* @param countDownInterval 时间毫秒数(单位间隔)
*/
constructor(millisInFuture: number, countDownInterval: number) {
this.millisInFuture = millisInFuture;
this.mInterval = countDownInterval;
this.onCountDownFinishListener = undefined;
this.onCountDownListener = undefined;
this.timeOutId = undefined;
}
addCountDownListener(listener: CountDownCallback): void {
if (listener && typeof listener === 'function') {
this.onCountDownListener = listener;
}
}
addFinishListener(listener: CountDownFinishCallback): void {
if (listener && typeof listener === 'function') {
this.onCountDownFinishListener = listener;
}
}
start(): void {
if (!this.timeOutId && this.onCountDownListener != undefined) {
this.timeOutId = setInterval(() => {
this.millisInFuture = this.millisInFuture - this.mInterval;
if (this.millisInFuture > 0) {
this.onCountDownListener(CountDownTimer.getTimeInfo(this.millisInFuture));
} else {
this.cancel();
if (this.onCountDownFinishListener !== undefined) {
this.onCountDownFinishListener();
}
}
}, this.mInterval);
}
}
cancel(): void {
if (this.timeOutId) {
clearTimeout(this.timeOutId);
this.timeOutId = undefined;
}
}
static getTimeInfo(time: number): CountDownInfo {
return new CountDownInfo(time);
}
}
const dayMillis = 86400000;//一天的毫秒数
const hourMillis = 3600000;//小时的毫秒数
const minuteMillis = 60000;//分的毫秒数
const secondMillis = 1000;//秒的毫秒数
export const dateConstants = {
dayMillis:dayMillis,
hourMillis:hourMillis,
minuteMillis:minuteMillis,
secondMillis:secondMillis,
};
export type DateType = string | number | Date
export type MonthDayNumber = 29 | 28 | 31 | 30
export type Callback=(...args:any)=>void;
import {dateConstants, DateType, MonthDayNumber} from "./DateConstants"
///yyyy-MM-dd HH:mm:ss
const formatDateList = [
{
symbolList: ["yyyy", "YYYY"],
getValue: function (date: Date): string {
return DateHelper.formatNumber(date.getFullYear());
}
},
{
symbolList: ["MM"],
getValue: function (date: Date): string {
return DateHelper.formatNumber(date.getMonth() + 1);
}
},
{
symbolList: ["DD", "dd"],
getValue: function (date: Date): string {
return DateHelper.formatNumber(date.getDate());
}
},
{
symbolList: ["HH", "hh"],
getValue: function (date: Date): string {
return DateHelper.formatNumber(date.getHours());
}
},
{
symbolList: ["mm"],
getValue: function (date: Date): string {
return DateHelper.formatNumber(date.getMinutes());
}
},
{
symbolList: ["SS", "ss"],
getValue: function (date: Date): string {
return DateHelper.formatNumber(date.getSeconds());
}
},
]
export class DateHelper {
/**
* 获取日期实例
* 兼容ios new Date('2020-10-10') 返回Invalid Date
* @param date
*/
static getDateInstance(date: DateType): Date {
if (date instanceof Date) {
return date;
}
if (typeof date === 'string' && date.indexOf('-') > 0) {//兼容ios new Date('2020-10-10') 返回Invalid Date
const reg = new RegExp("-", "g");
date = date.replace(reg, '/')
}
return new Date(date);
}
/**
* 获取某年某月第一天是星期几
* @param year
* @param month
*/
static getWeekDay(year: number, month: number): number {
const date = new Date(year, month - 1, 1);
return date.getDay();
}
/**
* 格式化数字符串
* @param num
*/
static formatNumber(num: number): string {
return num > 9 ? num + '' : "0" + num;
}
static isToday(date: DateType): boolean {
let currentDate = new Date();
let orderDate = DateHelper.getDateInstance(date);
return currentDate.getFullYear() === orderDate.getFullYear() && orderDate.getMonth() === currentDate.getMonth() && orderDate.getDate() === currentDate.getDate();
}
//格式化日期 YYYY-MM-DD
static getFormatDate(date: DateType): string {
const dateInstance = DateHelper.getDateInstance(date);
return dateInstance.getFullYear() + "-" + DateHelper.formatNumber(dateInstance.getMonth() + 1) + "-" + DateHelper.formatNumber(dateInstance.getDate());
}
//获取当前日期
static getCurrentFormatDate(): string {
return DateHelper.getFormatDate(new Date())
}
/**
* 获取当前日期所在月份的天数
* @param date
*/
static getDaysInMonth(date: DateType): MonthDayNumber {
const dateInstance = DateHelper.getDateInstance(date);
const month = dateInstance.getMonth() + 1;
return DateHelper.getMonthDays(dateInstance.getFullYear(), month);
}
/**
* 获取星期名称
* @param date 日期
* @param isEnglish true 表示是英文
*/
static getWeekName(date: DateType, isEnglish: boolean = false): string {
const dateInstance = DateHelper.getDateInstance(date);
const weekDay = dateInstance.getDay()
if (weekDay === 0) {
return isEnglish ? 'Sunday' : '周日';
} else if (weekDay === 1) {
return isEnglish ? 'Monday' : "周一";
} else if (weekDay === 2) {
return isEnglish ? 'Tuesday' : '周二';
} else if (weekDay === 3) {
return isEnglish ? 'Wednesday' : '周三';
} else if (weekDay === 4) {
return isEnglish ? 'Thursday' : '周四';
} else if (weekDay === 5) {
return isEnglish ? 'Friday' : '周五';
} else if (weekDay === 6) {
return isEnglish ? 'Saturday' : '周六';
}
return '';
}
/**
* 是否是闰年
* @param year
*/
static isLeapYear(year: number): boolean {
return year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
}
/**
* 获取指定月份天数
* @param year
* @param month
* @returns {number}
*/
static getMonthDays(year: number, month: number): MonthDayNumber {
if (month === 2) {
return DateHelper.isLeapYear(year) ? 29 : 28;
}
const bigMonths = [1, 3, 5, 7, 8, 10, 12]
if (bigMonths.includes(month)) {
return 31;
}
return 30;
}
/**
*获取下个月信息
* @param year
* @param month
*/
static getNextMonthInfo(year: number, month: number) {
const newMonth = month >= 12 ? 1 : month + 1;
const newYear = month >= 12 ? year + 1 : year;
return {year: newYear, month: newMonth}
}
/**
* 获取上个月信息
* @param year
* @param month
*/
static getLastMonthInfo(year: number, month: number) {
//获取上个月实际月份
const newMonth = month == 1 ? 12 : month - 1;
//获取实际年份
const newYear = month == 1 ? year - 1 : year;
return {year: newYear, month: newMonth}
}
static diffTime(startTime: number, endTime: number, unitTime: number): number {
const diffTimeNum = endTime - startTime
return Math.floor((diffTimeNum / unitTime) * 100) / 100
}
/**
*相差年份数
* @param startTime
* @param endTime
*/
static diffYears(startTime: number, endTime: number) {
let number = DateHelper.diffMonths(startTime, endTime);
return Math.floor(number / 12 * 100) / 100;
}
/**
* 相差月分数
* @param startTime
* @param endTime
*/
static diffMonths(startTime: number, endTime: number) {
let miniTime = Math.min(startTime, endTime);
let maxTime = Math.max(startTime, endTime);
const startDate = DateHelper.getDateInstance(miniTime);
const endDate = DateHelper.getDateInstance(maxTime);
let diffYear = endDate.getFullYear() - startDate.getFullYear();
let startMonth = startDate.getMonth() + 1;
let endMonth = endDate.getMonth() + 1;
if (endMonth < startMonth) {
diffYear = diffYear - 1;
endMonth = endMonth + 12;
}
return Number.parseInt((diffYear * 12 + endMonth - startMonth).toFixed(0))
}
/**
* 相差天数
* @param startTime
* @param endTime
*/
static diffDays(startTime: number, endTime: number) {
return DateHelper.diffTime(startTime, endTime, dateConstants.dayMillis)
}
/**
* 相差小时数
* @param startTime
* @param endTime
*/
static diffHours(startTime: number, endTime: number) {
return DateHelper.diffTime(startTime, endTime, dateConstants.hourMillis)
}
/**
* 相差分数
* @param startTime
* @param endTime
*/
static diffMinutes(startTime: number, endTime: number) {
return DateHelper.diffTime(startTime, endTime, dateConstants.minuteMillis)
}
/**
* 相差月秒数
* @param startTime
* @param endTime
*/
static diffSeconds(startTime: number, endTime: number) {
return DateHelper.diffTime(startTime, endTime, dateConstants.secondMillis)
}
/**
* 格式化时间
* @param date
* @param formatStyle
*/
static formatDateString(date: DateType, formatStyle: string): string {
let format = String(formatStyle);
if (formatStyle) {
let dateInstance = DateHelper.getDateInstance(date);
formatDateList.forEach(formatItem => {
for (let i = 0, len = formatItem.symbolList.length; i < len; i++) {
if (format.indexOf(formatItem.symbolList[i]) >= 0) {
format = format.replace(formatItem.symbolList[i], formatItem.getValue(dateInstance))
break;
}
}
})
}
return format;
}
}
const eventsHolder = {
observerList: [],//观察对象列表
stickyEvents: [],//粘性事件(消息)
}
function getRegisterType(eventType: string): string {
return eventType ? eventType : "defaultType"
}
/**
* 订阅回调
*/
type Subscriber = (params: any) => void;
export class EventBus {
/**
* 发送粘性事件消息(同一个类型,只保留最后一个)
* @param msg 消息
* @param eventType 事件类型
*/
static postSticky(msg: any, eventType: string): void {
const registerType = getRegisterType(eventType);
const findIndex = eventsHolder.stickyEvents.findIndex(item => item.eventType === registerType);
if (findIndex >= 0) {
eventsHolder.stickyEvents[findIndex].msg = msg;
} else {
eventsHolder.stickyEvents.push({
eventType: registerType,
msg: msg,
})
}
EventBus.post(msg, registerType);
}
/**
* 发送事件消息
* @param msg 消息
* @param eventType 事件类型
*/
static post(msg: any, eventType: string): void {
const postType = getRegisterType(eventType);
eventsHolder.observerList.forEach(item => {
if (postType === item.eventType && item.subscriber && typeof item.subscriber === "function") {
item.subscriber({eventType: item.eventType, msg: msg});
}
})
}
/**
* //注册一个事件(同一类型只能注册一次,即同一函数名称名称,只能注册一次)
* @param observer 需要观察的对象
* @param eventType 观察的对象事件类型,可确省,默认为 "defaultType"
* @param sticky 是否是粘性事件,可确省,默认为false
* @param subscriber 订阅回调
*/
static register(observer: any, sticky = false, eventType = 'defaultType', subscriber: Subscriber): void {
if (subscriber) {
const registerType = getRegisterType(eventType);
let findIndex = eventsHolder.observerList.findIndex(item => item.observer === observer && item.eventType === eventType);
if (findIndex < 0) {
if (sticky) {
let findEvent = eventsHolder.stickyEvents.find(item => item.eventType === registerType);
if (findEvent && subscriber && typeof subscriber === "function") {
subscriber(findEvent);
}
}
eventsHolder.observerList.push({
observer: observer,
subscriber: subscriber,
eventType: registerType,
})
}
}
}
/**
* 解除注册
* @param observer
*/
static unregister(observer: any): void {
eventsHolder.observerList = eventsHolder.observerList.filter(item => item.observer !== observer);
}
/**
* 销毁所有(谨慎调用)
*/
static destroy(): void {
eventsHolder.stickyEvents = []
eventsHolder.observerList = []
}
}
let area = {
11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古",
21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海", 32: "江苏",
33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南",
42: "湖北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆",
51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃",
63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外"
};
let weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];//权重
let checkCodes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];//校验码
/**
* 将15转为18位身份证
* @param cardNo
*/
function changeToEighteen(cardNo: string): string {
if (cardNo && cardNo.length === 15) {
//插入年月
let cardNo17 = cardNo.substring(0, 6) + '19' + cardNo.substring(6);
//计算组后一位
let sum = 0;
for (let i = 0; i < 17; i++) {
sum += Number.parseInt(cardNo17[i]) * weights[i];
}
return cardNo17 + checkCodes[sum % 11];
}
}
/**
* 判断身份证是否合法
* @param cardNo
*/
export function isIdCard(cardNo: string): boolean {
let regExp = new RegExp("(^\\d{15}$)|(^\\d{17}(\\d|X|x)$)");
// if (!/(^\d{15}$)|(^\d{17}(\d|X|x)$)/.test(cardNo)) {
if (!regExp.test(cardNo)) {
console.log('身份证长度或格式错误')
return false
}
let checkCode = String(cardNo);
if (checkCode.length === 15) {
checkCode = changeToEighteen(checkCode);
}
if (!area[checkCode.substring(0,2)]) {
console.log('身份证地区非法')
return false;
}
let birthday = (checkCode.substring(6, 10) + "-" + Number(checkCode.substring(10, 12)) + "-" + Number(checkCode.substring(12, 14))).replace(/-/g, "/");
let birthDate = new Date(birthday)
if (birthday != (birthDate.getFullYear() + "/" + (birthDate.getMonth() + 1) + "/" + birthDate.getDate())) {
console.log('身份证上的出生日期非法')
return false;
}
const currentDate = new Date();
currentDate.setHours(23,59,59)
birthDate.setHours(23,59,59)
if(currentDate.getTime()-birthDate.getTime()<0){
console.log('身份证上的出生日期非法,出生日期大于当前日期')
return false;
}
let time = currentDate.getFullYear() - birthDate.getFullYear();
if (time <0 || time > 150) {
console.log('出生日期岁数不合理')
return false;
}
// 身份证号码校验
let sum = 0;
for (let i = 0; i < checkCode.length - 1; i++) {
sum += Number.parseInt(checkCode[i]) * weights[i];
}
const lastCode = checkCodes[sum % 11]; //计算出来的最后一位身份证号码
if (checkCode[checkCode.length - 1] != lastCode) {
console.log('你输入的身份证号非法')
return false
}
return true;
}
export class LogUtils {
private readonly enableDebug;
constructor(debug) {
this.enableDebug = debug
}
getTag(tag: string): string {
return tag + '===================='
}
debug(msg: any): void {
if (this.enableDebug) {
console.debug(msg)
}
}
debugWithTag(tag: string, msg: any): void {
if (this.enableDebug) {
console.debug(this.getTag(tag), msg)
}
}
info(msg: any): void {
if (this.enableDebug) {
console.info(msg)
}
}
infoWithTag(tag: string, msg: any): void {
if (this.enableDebug) {
console.info(this.getTag(tag), msg)
}
}
log(msg: any): void {
if (this.enableDebug) {
console.log(msg)
}
}
logWithTag(tag: string, msg: any): void {
if (this.enableDebug) {
console.log(this.getTag(tag), msg)
}
}
error(msg: any): void {
if (this.enableDebug) {
console.error(msg)
}
}
errorWithTag(tag: string, msg: any): void {
if (this.enableDebug) {
console.error(this.getTag(tag), msg)
}
}
warn(msg: any): void {
if (this.enableDebug) {
console.warn(msg)
}
}
warnWithTag(tag: string, msg: any): void {
if (this.enableDebug) {
console.warn(this.getTag(tag), msg)
}
}
}
type WatchFun = (newVal: any, oldVal: any) => void
export class ObjectHelper {
/**
* 克隆函数
* @param func
*/
static cloneFunction(func: Function): any {
// const bodyReg = /(?<={)(.|\n)+(?=})/m;
const bodyReg = new RegExp("(?<={)(.|\\n)+(?=})","m");
// const paramReg = /(?<=\().+(?=\)\s+{)/;
const paramReg = new RegExp("(?<=\\().+(?=\\)\\s+{)");
const funcString = func.toString();
const param = paramReg.exec(funcString);
const body = bodyReg.exec(funcString);
if (param) {
const paramArr = param[0].split(',');
return body && body[0] ? new Function(...paramArr, body[0]) : new Function(...paramArr)
} else {
return body && body[0] ? new Function(body[0]) : new Function();
}
}
/**
* 深度克隆对象
* @param obj
* @param cache
*/
static cloneDeep(obj: object | Array<any>, cache?: WeakMap<object, object>): any {
if (obj === null || obj === undefined) {
return obj
}
if (obj instanceof Function) {
return ObjectHelper.cloneFunction(obj)
}
if (typeof obj !== 'object') {
return obj
} else {
if (obj instanceof Date) {
return new Date(obj)
}
if (obj instanceof RegExp) {
return new RegExp(obj)
}
if (obj instanceof Symbol) {
return Symbol(obj.description);
}
if (obj instanceof Map) {
let newMap = new Map<any, any>();
obj.forEach((value, key) => {
newMap.set(key, ObjectHelper.cloneDeep(value))
})
return newMap;
}
if (obj instanceof Set) {
let newSet = new Set<any>();
obj.forEach(((value, value2) => {
newSet.add(ObjectHelper.cloneDeep(value))
}))
return newSet;
}
if (obj instanceof Array) {
let newArray = new Array<any>();
for (let i = 0, len = obj.length; i < len; i++) {
newArray.push(ObjectHelper.cloneDeep(obj[i]));
}
return newArray;
}
if (obj instanceof Object) {
let weakMap = cache ? cache : new WeakMap<object, object>()
if (weakMap.get(obj)) {
// 防止循环引用,程序进入死循环
return cache.get(obj)
}
let newObject = {};
for (let key in obj) {
newObject[key] = ObjectHelper.cloneDeep(obj[key], weakMap)
}
weakMap.set(obj, newObject); // 缓存拷贝的对象,用于处理循环引用的情况
return newObject;
}
}
}
/**
* 将某个对象追加到当前对象中(扩展对象,类似java中的继承)
* @param targetObject
* @param sourceObject
*/
static extendObject(targetObject: object, sourceObject: object): object {
if (!sourceObject || typeof (sourceObject) !== 'object') {//源对象为空或者不是对象时
return targetObject;
}
if (targetObject && typeof (sourceObject) === 'object') {
Object.keys(sourceObject).forEach(sourceKey => {
if (typeof (targetObject[sourceKey]) === 'undefined') {//当前目标没有定义
targetObject[sourceKey] = sourceObject[sourceKey];
} else if (typeof (targetObject[sourceKey]) === 'object') {//当前目标不为空而且是对象时
ObjectHelper.extendObject(targetObject[sourceKey], sourceObject[sourceKey])
}
})
}
return targetObject;
}
/**
* 判断列表是是否包含特定的对象
* @param list
* @param object
*/
static containObject(list: Array<any>, object: any) {
if (!list || list.length < 1) {
return false
}
for (let i = 0, len = list.length; i < len; i++) {
if (ObjectHelper.equalDeep(list[i], object)) {
return true;
}
}
return false;
}
/**
* 深入比较对象(判断对象是否相等)
* @param object_1
* @param object_2
*/
static equalDeep(object_1: any, object_2: any): boolean {
let type1 = typeof object_1
let type2 = typeof object_2
if (type1 !== type2) {
return false
}
if (type1 === 'string' || type1 === 'number' || type1 === 'undefined' || type1 === 'boolean') {
return object_1 === object_2
}
if (type1 === 'object') {
if (object_1 instanceof Array) {
if (object_1.length !== object_1.length) {
return false
}
if (!object_1.every(item => ObjectHelper.containObject(object_2, item))) {
return false
}
return object_2.every(item => ObjectHelper.containObject(object_1, item));
} else {
let keys_1 = Object.keys(object_1)
let keys_2 = Object.keys(object_2)
if (keys_1.length !== keys_2.length) {
return false
}
let filterKeys = keys_2.filter(key => keys_1.includes(key))
if (filterKeys.length !== keys_1.length) {
return false
}
for (let i = 0, len = keys_1.length; i < len; i++) {
let equal = ObjectHelper.equalDeep(object_1[keys_1[i]], object_2[keys_1[i]])
if (!equal) {
return false
}
}
return true
}
}
return false;
}
/**
*
* @param keysList 取值字段列表 ["a","b"]
* @param valuesObject 目标对象{a:"a",b:"11",c:"aaaa",d:"dd"}
* @return {} //如{a:"a",b:"11"}
*/
static getObjectByList(keysList: Array<string>, valuesObject: object): object {
let newObject = {}
if (keysList && keysList.length > 0 && valuesObject && typeof valuesObject === 'object') {
for (let i = 0, len = keysList.length; i < len; i++) {
let key = keysList[i];
if (key) {
newObject[key] = valuesObject[key]
}
}
}
return newObject
}
/**
* 根据当前对象的key,从目标对象中取值
* @param keysObject {a:""}
* @param targetObject 目标对象{a:"a",b:"11",c:"aaaa",d:"dd"}
* @return {} //如{a:"a"}
*/
static getObjectByObject(keysObject: object, targetObject: object): object {
if (keysObject && targetObject && typeof keysObject === 'object' && typeof targetObject === 'object') {
let keys = Object.keys(keysObject)
return ObjectHelper.getObjectByList(keys, targetObject);
}
return {};
}
/**
* 从对象中获取值 (支持 "a.b.c" 获取值)
* @param obj
* @param keyWords
*/
static getValueFromObject(obj: object, keyWords): any {
if (typeof obj === 'object' && keyWords && typeof keyWords === 'string') {
if (obj[keyWords]) {
return obj[keyWords];
}
let indexOf = keyWords.indexOf(".");
if (indexOf < 0) {
return obj[keyWords]
} else {
const keys = keyWords.split(".")
if (obj[keys[0]] && obj[keys[0]] instanceof Object) {
const nextKeyWorks = keys.slice(1).join('.')
return ObjectHelper.getValueFromObject(obj[keys[0]], nextKeyWorks);
}
}
}
return "";
}
/**
* 设置监听器
*/
static addWatcher(data: object, watch: Record<string, (...args: any[]) => any>) {
Object.keys(watch).forEach(v => {
ObjectHelper.observe(data, v, watch[v]);
})
}
/**
* 监听属性 并执行监听函数
*/
static observe(obj: object, key: string, watchFun: WatchFun): void {
if (obj && typeof obj === 'object') {
let val = obj[key]; //给该属性设默认值
if (val) {
Object.defineProperty(obj, key, {
configurable: true,
enumerable: true,
set: function (value) {
let oldVal = val;
val = value;
watchFun(value, oldVal);
},
get: function () {
return val;
}
})
} else {
let indexOf = key.indexOf(".");
if (indexOf > 0) {
const objKey = key.substring(0, indexOf)
let newKey = key.substring(indexOf + 1);
ObjectHelper.observe(obj[objKey], newKey, watchFun)
}
}
}
}
}
export class StringHelper {
/**
* 替换所有
* @param content 当前文本
* @param pattern 旧字符串或者正则表达式
* @param newStr 要替换的内容
* @returns {*} 返回新的字符串
*/
static replaceAll(content: string, pattern: string, newStr: string) {
const reg = new RegExp(pattern, "g"); //创建正则RegExp对象
return content.replace(reg, newStr)
}
static isEmpty(str: string): boolean {
return !str || str.trim().length < 1;
}
/**
* 是否是组织机构代码
* @param code
* @returns {*|boolean}
*/
static isOrganizationCode(code: string): boolean {
// return /[0-9A-HJ-NPQRTUWXY]{8}-[0-9A-HJ-NPQRTUWXY]/g.test(code)
return new RegExp("^[0-9A-HJ-NPQRTUWXY]{8}-[0-9A-HJ-NPQRTUWXY]$").test(code)
}
/**
* 18位的统一信用代码
* @param code
* @returns {*|boolean}
*/
static isUnifiedCreditCode(code: string): boolean {
// return /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/.test(code)
return new RegExp("^[0-9A-HJ-NPQRTUWXY]{2}\\d{6}[0-9A-HJ-NPQRTUWXY]{10}$").test(code)
}
/**
* 校验手机号(严格校验)
* //移动号段:134 135 136 137 138 139 147 148 150 151 152 157 158 159 165 172 178 182 183 184 187 188 195 198
* // 联通号段:130 131 132 145 146 155 156 166 167 171 175 176 185 186
* // 电信号段:133 149 153 173 174 177 180 181 189 191 199
* // 虚拟运营商:170
* 分组如下
* //130 131 132 133 134 135 136 137 138 139
* //145 146 147 148 149
* //150 151 152 153 155 156 157 158 159
* // 165 166 167
* //170 171 172 173 174 175 176 177 178
* //180 181 182 183 184 185 186 187 188 189
* // 191 195 198 199
* @param phone
* @returns {boolean}
*/
static isPhoneNumber(phone: number | string): boolean {
const phoneStr = String(phone);
//手机号正则
// if (/^1[38][0-9]{9}$/.test(phoneStr)) {//校验//130 131 132 133 134 135 136 137 138 139 180 181 182 183 184 185 186 187 188 189号段
if (new RegExp("^1[38][0-9]{9}$").test(phoneStr)) {//校验//130 131 132 133 134 135 136 137 138 139 180 181 182 183 184 185 186 187 188 189号段
return true;
}
// if (/^14[56789][0-9]{8}$/.test(phoneStr)) {//校验14开头的号段
if (new RegExp("^14[56789][0-9]{8}$").test(phoneStr)) {//校验14开头的号段
return true
}
// if (/^15[012356789][0-9]{8}$/.test(phoneStr)) {//校验 1//150 151 152 153 155 156 157 158 159 开头的号段
if (new RegExp("^15[012356789][0-9]{8}$").test(phoneStr)) {//校验 1//150 151 152 153 155 156 157 158 159 开头的号段
return true;
}
// if (/^16[567][0-9]{8}$/.test(phoneStr)) {//校验 // 165 166 167 开头的号段
if (new RegExp("^16[567][0-9]{8}$").test(phoneStr)) {//校验 // 165 166 167 开头的号段
return true;
}
// if (/^17[012345678][0-9]{8}$/.test(phoneStr)) {//校验 //170 171 172 173 174 175 176 177 178 开头的号段
if (new RegExp("^17[012345678][0-9]{8}$").test(phoneStr)) {//校验 //170 171 172 173 174 175 176 177 178 开头的号段
return true;
}
// if (/^19[1589][0-9]{8}$/.test(phoneStr)) {//校验// 191 195 198 199 开头的号段
if (new RegExp("^19[1589][0-9]{8}$").test(phoneStr)) {//校验// 191 195 198 199 开头的号段
return true;
}
return false;
}
/**
* 判断是否是邮件地址
* @param email
* @returns {boolean}
*/
static isEmail(email: string): boolean {
if (email) {
// const regex = /^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*\.[a-z]{2,}$/
const regex = new RegExp("^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*\\.[a-z]{2,}$")
return regex.test(email)
}
return false
}
/**
* 获取文本(过滤副文本标签)
* @param richText
*/
static filterRichText(richText: string): string {
if (!richText) {
return ""
}
const regExp = new RegExp('<[^<>]+>', 'g');
return richText.replace(regExp, "");
}
/**
* 从富文本中,查找img 标签,收集图片地址(只支持.png .jpg .jpeg 结尾)
* @param text 富文本
* @returns {[]} 返回图片列表
*/
static getImageListFromRichText(text: string): Array<string> {
const list = new Array<string>();
// let regular = /<img[^>]*>/g
let regular = new RegExp("<img[^>]*>","g")
let keysWords = text.match(regular)
if (keysWords && keysWords.length > 0) {
let srcReg =new RegExp("http\\S*((.jpg)|(.jpeg)|(.png))",'g')
// let srcReg = /http\S*((.jpg)|(.jpeg)|(.png))/g
keysWords.forEach(words => {
let strings = words.match(srcReg);
if (strings && strings.length > 0 && !list.includes(strings[0])) {
list.push(strings[0])
}
})
}
return list;
}
/*RGB颜色转换为16进制*/
static colorRbgToHex(rgbColor: string): string {
let lowerCaseColor = rgbColor.toLowerCase();
// let reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
let reg = new RegExp("^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6 })$");
// if (/^(rgb|RGB)/.test(lowerCaseColor)) {
if (new RegExp("^(rgb|RGB)").test(lowerCaseColor)) {
let regExp = new RegExp("(?:\\(|\\)|rgb|RGB)*","g");
// let aColor = lowerCaseColor.replace(/(?:\(|\)|rgb|RGB)*/g, "").split(",");
let aColor = lowerCaseColor.replace(regExp, "").split(",");
let strHex = "#";
for (let i = 0; i < aColor.length; i++) {
let hex = Number(aColor[i]).toString(16);
if (hex === "0") {
hex += hex;
}
strHex += hex;
}
if (strHex.length !== 7) {
strHex = lowerCaseColor;
}
return strHex;
} else if (reg.test(lowerCaseColor)) {
// let aNum = lowerCaseColor.replace(/#/, "").split("");
let aNum = lowerCaseColor.replace("#", "").split("");
if (aNum.length === 6) {
return lowerCaseColor;
} else if (aNum.length === 3) {
let numHex = "#";
for (let i = 0; i < aNum.length; i += 1) {
numHex += (aNum[i] + aNum[i]);
}
return numHex;
}
}
return lowerCaseColor;
}
/**
*16进制颜色转为RGB格式
* @param hexColor 16进制颜色
* @returns {string} RGB格式颜色
*/
static colorHexToRgb(hexColor: string): string {
let sColor = hexColor.toLowerCase();
// let reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
let regExp = new RegExp("^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$");
if (sColor && regExp.test(sColor)) {
if (sColor.length === 4) {
let sColorNew = "#";
for (let i = 1; i < 4; i += 1) {
sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
}
sColor = sColorNew;
}
//处理六位的颜色值
let sColorChange = [];
for (let i = 1; i < 7; i += 2) {
sColorChange.push(parseInt("0x" + sColor.slice(i, i + 2)));
}
return "rgb(" + sColorChange.join(",") + ")";
}
return sColor;
};
/**
* 将整数部分逢三一断
* @param value
* @returns {string}
*/
static formatNumber(value: String | number): string {
if (!value) {
return '0'
}
let strings = String(value).split('.');
// const leftNum = String(strings[0]).replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
let regExp = new RegExp("(\\d)(?=(?:\\d{3})+$)");
const leftNum = String(strings[0]).replace(regExp, '$1,');
if (strings.length > 1) {
return `${leftNum}.${strings[1]}`
}
return leftNum;
}
/**
* 通用脱敏
*
* 中文名字:只展示姓名第一个字
* 手机号:前三后四不脱敏,中间脱敏
* 身份证号:前6后4不脱敏,年月日脱敏
* 银行卡:前6位和后4位不脱敏,中间脱敏
* 其他 前6位和后4位不脱敏
* @param codeStr
* @return {string}
*/
static desensitize(codeStr) {
// if (/[\u4e00-\u9fa5]/.test(codeStr)) {
if (new RegExp("[\u4e00-\u9fa5]").test(codeStr)) {
return codeStr[0] + "***"
}
const str = String(codeStr)
let length = str.length;
if (length === 11) {//脱敏手机
return `${str.slice(0, 3)}****${str.slice(7, 11)}`
}
let regExp = new RegExp("^(.{6})(?:\\d+)(.{4})$");
//身份证、银行卡
// return str.replace(/^(.{6})(?:\d+)(.{4})$/, "\$1********\$2");
return str.replace(regExp, "\$1********\$2");
}
/**
* 生成唯一的uuid;
*/
static generateUUID(): string {
let d = new Date().getTime();
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c: string) {
const r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
});
}
}
export class UrlHelper {
/**
* 从地址中截取参数
* @param url
* @returns {Map<any, any>}
*/
static getQueryMapFromUrl(url: string): Map<string, any> {
const map = new Map()
if (url && url.indexOf("?") > 0) {
let paramsStr = url.substring(url.indexOf("?") + 1)
let groupList = paramsStr.split("&");
if (groupList && groupList.length > 0) {
groupList.forEach(item => {
let strings = item.split("=");
if (strings && strings.length > 1) {
map.set(strings[0], strings[1])
}
})
}
}
return map;
}
/**
* 获取跳转目标路径
* @param baseUrl
* @param params
* @returns {*}
*/
static getQueryUrl(baseUrl: string, params: object): string {
let hasStartFlag = baseUrl.indexOf('?') !== -1
if (params !== undefined && params instanceof Object) {
let requestUtl = baseUrl
for (let key in params) {
if (params[key] !== undefined) {
if (requestUtl.endsWith("?")) {
requestUtl = `${requestUtl}${key}=${params[key]}`
} else {
requestUtl = `${requestUtl}${!hasStartFlag ? '?' : '&'}${key}=${params[key]}`
if (!hasStartFlag) {
hasStartFlag = true
}
}
}
}
return requestUtl
} else {
return baseUrl
}
}
}
import {InterceptorsConfig} from "./InterceptorsConfig";
import {ResponseInterceptor} from './ResponseInterceptor'
const Method = {
GET: 'get',
POST: 'post',
DELETE: 'delete',
HEAD: 'head',
CONNECT: 'CONNECT',
OPTIONS: 'options',
PUT: 'put',
PATCH: 'patch',
TRACE: 'TRACE',
LINK: 'LINK',
UNLINK: 'unlink',
}
export default class HttpClient {
private readonly baseUrl: string;
private readonly platform: object;
private readonly requestInterceptorsConfig: InterceptorsConfig;
private readonly taskMap: Map<string, any>;
private readonly isMiniApp: boolean;
constructor(platform: object, isMiniApp: boolean, baseUrl: string, requestInterceptorsConfig: InterceptorsConfig) {
this.platform = platform;
this.baseUrl = baseUrl;
this.requestInterceptorsConfig = requestInterceptorsConfig;
this.taskMap = new Map<string, any>();
this.isMiniApp = isMiniApp;
}
post<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
return this.request(path, Method.POST, params, headers, cancelToken)
}
get<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
const requestUrl = HttpClient.getTargetUrl(path, params);//get请求得手动拼接参数
return this.request(requestUrl, Method.GET, {}, headers, cancelToken)
}
put<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
return this.request(path, Method.PUT, params, headers, cancelToken)
}
delete<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
return this.request(path, Method.DELETE, params, headers, cancelToken)
}
head<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
return this.request(path, Method.HEAD, params, headers, cancelToken)
}
options<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
return this.request(path, Method.OPTIONS, params, headers, cancelToken)
}
connect<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
return this.request(path, Method.CONNECT, params, headers, cancelToken)
}
trace<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
return this.request(path, Method.TRACE, params, headers, cancelToken)
}
patch<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
return this.request(path, Method.PATCH, params, headers, cancelToken)
}
link<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
return this.request(path, Method.LINK, params, headers, cancelToken)
}
unlink<T>(path: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
return this.request(path, Method.UNLINK, params, headers, cancelToken)
}
private static getTargetUrl(baseUrl: string, params: object): string {
if (params && Object.keys(params).length > 0) {
let hasStartFlag = baseUrl.indexOf('?') !== -1;
let requestUtl = baseUrl
for (let key in params) {
if (params[key] !== undefined) {
if (requestUtl.endsWith("?")) {
requestUtl = `${requestUtl}${key}=${params[key]}`
} else {
requestUtl = `${requestUtl}${!hasStartFlag ? '?' : '&'}${key}=${params[key]}`
if (!hasStartFlag) {
hasStartFlag = true
}
}
}
}
return requestUtl
}
return baseUrl
}
private request<T>(url: string, method: string, params?: any, headers?: any, cancelToken?: string): Promise<T> {
if (this.requestInterceptorsConfig && typeof this.requestInterceptorsConfig.getCacheData === "function") {
let cacheData = this.requestInterceptorsConfig.getCacheData(this.baseUrl, url, params);
if (cacheData !== undefined) {
return Promise.resolve(cacheData)
}
}
const defaultHeaders = {
'Content-Type': 'application/json',
...headers
}
//通过请求拦截器,获取统一的自定义请求头
const headerConfig = this.requestInterceptorsConfig && this.requestInterceptorsConfig.onRequestInterceptor ? this.requestInterceptorsConfig.onRequestInterceptor(defaultHeaders) : defaultHeaders;
const requestUrl = this.getRequestUrl(url);
const defaultOptions = {
baseURL: '',
url: requestUrl,
method: method,
data: params,
header: {
...headerConfig
}
}
// @ts-ignore
if (this.isMiniApp && this.platform && this.platform.request && typeof this.platform.request === 'function') {
return this.miniAppRequest(defaultOptions, cancelToken, url, params);
} else if (this.platform && typeof this.platform === 'function') {
return this.commonRequest(defaultOptions, cancelToken, url, params)
}
}
private getRequestUrl(url: string): string {
if (url.startsWith('https://') || url.startsWith('http://')) {
return url;
}
if (this.baseUrl) {
let endsWith = this.baseUrl.endsWith("/");
let startsWith = url.startsWith('/');
if (endsWith && startsWith) {
return this.baseUrl.substring(0, this.baseUrl.length - 1) + url;
} else if (!endsWith && !startsWith) {
return this.baseUrl + '/' + url;
}
return this.baseUrl + url
}
return url;
}
private miniAppRequest<T>(options: object, cancelToken: string | undefined, url: string, params?: any): Promise<T> {
return new Promise((resolve, reject) => {
const requestOptions = {
...options,
fail: (res: any) => {
if (cancelToken) {
this.taskMap.delete(cancelToken);
}
reject(res);
},
success: (res: any) => {
if (cancelToken) {
this.taskMap.delete(cancelToken);
}
this.successHandler(resolve, reject, res, url, params);
}
}
// @ts-ignore
let requestTask = this.platform.request(requestOptions);
if (cancelToken && requestTask) {
this.taskMap.set(cancelToken, requestTask)
}
})
}
private successHandler<T>(resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void, res: any, url: string, params: any) {
let responseData = this.getResponseData(res, url, params);
if (responseData.success) {
resolve(responseData.data);
} else {
reject(responseData.data);
}
}
private getResponseData(res: any, url: string, params?: any): ResponseInterceptor {
let responseData = {success: true, data: res};
if (this.requestInterceptorsConfig && typeof this.requestInterceptorsConfig.onResponseInterceptor === 'function') {
responseData = this.requestInterceptorsConfig.onResponseInterceptor(res);
}
if (responseData.success && this.requestInterceptorsConfig && typeof this.requestInterceptorsConfig.updateResponseCache === 'function') {
this.requestInterceptorsConfig.updateResponseCache(res, this.baseUrl, url, params);//缓存数据
}
return responseData;
}
private commonRequest<T>(options: object, cancelToken: string | undefined, url: string, params?: any): Promise<T> {
return new Promise((resolve, reject) => {
// @ts-ignore
this.platform(options)
.then((res: any) => {
this.successHandler(resolve, reject, res, url, params);
})
.catch((reason: any) => {
reject(reason);
})
})
}
}
import {InterceptorsConfig} from "./InterceptorsConfig";
import HttpClient from "./HttpClient";
const clientMap = new Map<string, HttpClient>();
type ClientInterceptors=()=>InterceptorsConfig;
export class HttpRequest {
/**
* 获取求实例
* @param platform 平台
* @param isMiniApp 是不是小程序
* @param baseUrl 地址
* @param interceptors 拦截器信息
*/
static getHttpClient(platform: any,isMiniApp:boolean,baseUrl: string,interceptors?:ClientInterceptors): HttpClient {
if (clientMap.has(baseUrl)) {
const httpClient = clientMap.get(baseUrl);
if (httpClient !== undefined) {
return httpClient;
}
}
let config = interceptors();
let httpClient = new HttpClient(platform, isMiniApp, baseUrl,config?config:{});
clientMap.set(baseUrl, httpClient)
return httpClient;
}
}
import {ResponseInterceptor} from './ResponseInterceptor'
/**
* 拦截器配置信息
*/
export interface InterceptorsConfig {
/**
* 接口请求拦截器
* @param header
*/
onRequestInterceptor?: (header: object) => object;
/**
* 接口响应拦截器
* @param response
*/
onResponseInterceptor?: (response: any) => ResponseInterceptor;
/**
* 获取缓存数据
* @param baseUrl
* @param url
* @param params
*/
getCacheData?:(baseUrl: string, url: string, params?: any)=> any;
/**
* 更新响应数据缓存
* @param data
* @param baseUrl
* @param url
* @param params
*/
updateResponseCache?:(data: any,baseUrl: string, url: string,params?: any)=> void;
/**
* 获取缓存的Key
* @param baseUrl
* @param url
* @param data
* @param params
*/
getCacheKey?:(baseUrl: string, url: string, data: any, params?: any)=> string;
}
export interface ResponseInterceptor {
success:boolean,
data:any,
}
import {dateConstants} from './helper/DateConstants'
import {CountDownTimer} from './helper/CountDownTimer'
import {CalendarData} from './calendar/CalendarData'
import {EventBus} from './helper/EventBus'
import {LogUtils} from './helper/LogUtils'
import {isIdCard} from "./helper/IdCardHelper";
import {StringHelper} from "./helper/StringHelper";
import {ArrayHelper} from "./helper/ArrayHelper"
import {ObjectHelper} from "./helper/ObjectHelper"
import {UrlHelper} from "./helper/UrlHelper"
import {DateHelper} from "./helper/DateHelper"
export type {CountDownTimer} from './helper/CountDownTimer'
export type {CalendarData} from './calendar/CalendarData'
export type {DayData} from './calendar/DayData'
export type {MonthData} from './calendar/MonthData'
export type {LogUtils} from './helper/LogUtils'
export type {isIdCard} from "./helper/IdCardHelper";
export type {StringHelper} from "./helper/StringHelper";
export type {ArrayHelper} from "./helper/ArrayHelper"
export type {ObjectHelper} from "./helper/ObjectHelper"
export type {UrlHelper} from "./helper/UrlHelper"
export type {DateHelper} from "./helper/DateHelper"
import {HttpRequest} from "./https/HttpRequest";
import HttpClient from "./https/HttpClient";
export type {InterceptorsConfig} from './https/InterceptorsConfig'
export type {ResponseInterceptor} from './https/ResponseInterceptor'
export default {
DateConstants: dateConstants,
CountDownTimer,
CalendarData,
LogUtils,
isIdCard,
StringHelper,
ObjectHelper,
DateHelper,
ArrayHelper,
UrlHelper,
HttpRequest,
HttpClient,
}
{
"compilerOptions": {
"outDir": "dist",
"target": "es5",
"module": "es2015",
"lib": [
"es2015",
"es2016",
"es2017",
],
"sourceMap": false,
"declaration": true,
"removeComments":false,
"declarationDir": "dist/types",
"typeRoots": [
"node_modules/@types"
],
"moduleResolution": "node",
"esModuleInterop": true
},
"typeAcquisition": {
},
"include": [
"src/"
],
"exclude": [
"/test",
"/lib",
"node_modules/"
]
}
{
"inputFiles": ["./src"],
"mode": "modules",
"out": "docs",
"exclude": "src/index.ts",
"theme": "./node_modules/typedoc-neo-theme/bin/default"
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论