@mucfe/matui
Version:
基于Vue和ElementUi的PC组件库
612 lines (483 loc) • 16 kB
JavaScript
;
exports.__esModule = true;
exports.deepCopy = deepCopy;
exports.findIndex = findIndex;
exports.deepAssign = deepAssign;
exports.isArray = isArray;
exports.isString = isString;
exports.isError = isError;
exports.isNumber = isNumber;
exports.isObject = isObject;
exports.isNull = isNull;
exports.isUndefined = isUndefined;
exports.getFormatedImg = getFormatedImg;
exports.getApiData = getApiData;
exports.debounce = debounce;
exports.throttle = throttle;
exports.isNative = isNative;
exports.isMobile = isMobile;
exports.formatMobile = formatMobile;
exports.formatBankCard = formatBankCard;
exports.formatFontSize = formatFontSize;
exports.formatTitle = formatTitle;
exports.outerWidth = outerWidth;
exports.outerHeight = outerHeight;
exports.hexToRgb = hexToRgb;
exports.randomString = randomString;
exports.isMucWebAutoTester = exports.ua = void 0;
var _index = _interopRequireDefault(require("./fastcopy/index"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint-disable*/
function deepCopy(obj) {
if (!obj) return obj;
return (0, _index.default)(obj);
} //浏览器相关
var inBrowser = typeof window !== 'undefined';
var UA = inBrowser && window.navigator.userAgent.toLowerCase();
var isIE = UA && /msie|trident/.test(UA);
var isIE9 = UA && UA.indexOf('msie 9.0') > 0;
var isEdge = UA && UA.indexOf('edge/') > 0;
var isAndroid = UA && UA.indexOf('android') > 0;
var isIOS = UA && /iphone|ipad|ipod|ios/.test(UA);
var isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge;
var isWx = UA && /MicroMessenger/i.test(UA);
var isXysApp = UA && /mucxiaoyusan/i.test(UA);
var isKcbApp = UA && /muckacabao/i.test(UA);
var isApp = isXysApp || isKcbApp;
var isMobileDevice = (UA && /phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone/i).test(UA);
var ua = {
isIE: isIE,
isMobile: isMobileDevice,
isIE9: isIE9,
isEdge: isEdge,
isAndroid: isAndroid,
isIOS: isIOS,
isChrome: isChrome,
isWx: isWx,
isApp: isApp,
isXysApp: isXysApp,
isKcbApp: isKcbApp
};
exports.ua = ua;
var isMucWebAutoTester = /MucWebAutoTester/.test(window.navigator.userAgent); //工具函数
exports.isMucWebAutoTester = isMucWebAutoTester;
function findIndex(ary, fn) {
if (ary.findIndex) {
return ary.findIndex(fn);
}
/* istanbul ignore next */
var index = -1;
/* istanbul ignore next */
ary.some(function (item, i, ary) {
var ret = fn.call(this, item, i, ary);
if (ret) {
index = i;
return ret;
}
});
/* istanbul ignore next */
return index;
}
function deepAssign(to, from) {
for (var key in from) {
if (!to[key] || typeof to[key] !== 'object') {
to[key] = from[key];
} else {
deepAssign(to[key], from[key]);
}
}
}
function isArray(args) {
if (Array.isArray) {
return Array.isArray(args);
}
return Object.prototype.toString.call(args) === '[object Array]';
}
function isString(args) {
return Object.prototype.toString.call(args) === '[object String]';
}
function isError(args) {
return Object.prototype.toString.call(args) === '[object Error]';
}
function isNumber(args) {
return Object.prototype.toString.call(args) === '[object Number]';
}
function isObject(args) {
return Object.prototype.toString.call(args) === '[object Object]';
}
function isNull(args) {
return args === null;
}
function isUndefined(args) {
return args === undefined;
}
function getFormatedImg(imgArr) {
if (imgArr === void 0) {
imgArr = [];
}
var formatedImg = [];
var strRegex = new RegExp('https?://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]');
for (var i = 0; i < imgArr.length; i++) {
var currItem = imgArr[i];
if (strRegex.test(currItem)) {
formatedImg.push(currItem.split('?')[0]);
} else {
return;
}
}
return formatedImg;
} // 组装页面数据 获取gid,承保,核保都会用
function getApiData(pageData) {
var _JSON$parse = JSON.parse(JSON.stringify(pageData)),
_JSON$parse$attrModul = _JSON$parse.attrModules,
attrModules = _JSON$parse$attrModul === void 0 ? {} : _JSON$parse$attrModul,
plan = _JSON$parse.plan;
var applicant = attrModules.applicant,
insureds = attrModules.insureds,
hcpics = attrModules.hcpics,
hctext = attrModules.hctext,
makeup = attrModules.makeup,
apphctext = attrModules.apphctext,
apphcpics = attrModules.apphcpics;
var outData = {};
var bundle = function bundle(inObj) {
var certificate = null;
var socialIns = null;
var resident = null;
var office = null;
var outObj = {};
var companyCertificate = {};
var companyAddress = {};
for (var key in inObj) {
var defaultValue = inObj[key]['defaultValue'];
var required = inObj[key]['required'];
var display = inObj[key]['display'];
if (isArray(defaultValue)) {
var tranformedVakl = getFormatedImg(defaultValue);
if (tranformedVakl) {
defaultValue = tranformedVakl;
}
} // 如是必传或者是显示的元素
// 如是必传或者是显示的元素
if (Number(required) === 1 || Number(display) === 1) {
if (key === 'idType' || key === 'id' || key === 'idValidType' || key === 'idValidEndTime' || key === 'idValidStartTime') {
certificate = certificate || {};
certificate[key] = defaultValue;
} else if (key === 'socialInsAddr' || key === 'socialInsDetail' || key === 'socialInsPost' || key === 'socialInsTel') {
socialIns = socialIns || {};
socialIns[key] = defaultValue;
} else if (key === 'residentAddr' || key === 'residentDetail' || key === 'residentPost' || key === 'residentTel') {
resident = resident || {};
resident[key] = defaultValue;
} else if (key === 'officeAddr' || key === 'officeDetail' || key === 'officePost' || key === 'officeTel') {
office = office || {};
office[key] = defaultValue;
} else if (key === 'companyIdType' || key === 'companyId') {
companyCertificate = companyCertificate || {};
companyCertificate[key] = defaultValue;
} else if (key === 'detail') {
companyAddress = companyAddress || {};
companyAddress[key] = defaultValue;
} else {
outObj[key] = defaultValue;
}
}
}
if (certificate) outObj.certificate = certificate;
if (socialIns) outObj.socialIns = socialIns;
if (resident) outObj.resident = resident;
if (office) outObj.office = office;
return outObj;
}; // 待客核保plan放在了attrmodules中
if (attrModules.plan) {
plan = bundle(attrModules.plan);
} // 处理投保人数据
if (applicant) {
outData.applicant = {};
if (applicant) outData.applicant = bundle(applicant);
} // 处理被保人数据
if (insureds || plan) {
outData.insureds = [];
var forArr = insureds || [''];
for (var i = 0; i < forArr.length; i++) {
var insured = forArr[i];
var newInsured = null;
var obj = {};
if (insured) {
newInsured = bundle(insured);
}
if (newInsured) obj.insured = newInsured;
if (plan) obj.plan = plan;
outData.insureds.push(obj);
}
} // 被保人补充说明
if (hctext) {
outData.hctext = bundle(hctext);
} // 投保人补充说明
if (apphctext) {
outData.apphctext = bundle(apphctext);
} // 被保人补充图片
if (hcpics) {
outData.hcpics = bundle(hcpics);
} // 投保人补充图片
if (apphcpics) {
outData.apphcpics = bundle(apphcpics);
} //处理补充资料
if (makeup) {
outData.makeup = {};
var _forArr = makeup || [''];
for (var _i = 0; _i < _forArr.length; _i++) {
var makeupItem = _forArr[_i];
var newItem = null;
if (makeupItem) {
newItem = bundle(makeupItem);
}
if (newItem) {
outData.makeup = Object.assign(outData.makeup, newItem);
}
}
}
return outData;
}
/* @param {Function} func The function to debounce.
* @param {number} [wait=0]
* The number of milliseconds to delay; if omitted, `requestAnimationFrame` is
* used (if available).
* @param {Object} [options={}] The options object.
* @param {boolean} [options.leading=false]
* Specify invoking on the leading edge of the timeout.
* @param {number} [options.maxWait]
* The maximum time `func` is allowed to be delayed before it's invoked.
* @param {boolean} [options.trailing=true]
* Specify invoking on the trailing edge of the timeout.
* @returns {Function} Returns the new debounced function.
*/
function debounce(func, wait, options) {
var lastArgs, lastThis, maxWait, result, timerId, lastCallTime;
var lastInvokeTime = 0;
var leading = false;
var maxing = false;
var trailing = true; // Bypass `requestAnimationFrame` by explicitly setting `wait=0`.
var useRAF = !wait && wait !== 0 && typeof window.requestAnimationFrame === 'function';
if (typeof func !== 'function') {
throw new TypeError('Expected a function');
}
wait = +wait || 0;
if (isObject(options)) {
leading = !!options.leading;
maxing = 'maxWait' in options;
maxWait = maxing ? Math.max(+options.maxWait || 0, wait) : maxWait;
trailing = 'trailing' in options ? !!options.trailing : trailing;
}
function invokeFunc(time) {
var args = lastArgs;
var thisArg = lastThis;
lastArgs = lastThis = undefined;
lastInvokeTime = time;
result = func.apply(thisArg, args);
return result;
}
function startTimer(pendingFunc, wait) {
if (useRAF) {
window.cancelAnimationFrame(timerId);
return window.requestAnimationFrame(pendingFunc);
}
return setTimeout(pendingFunc, wait);
}
function cancelTimer(id) {
if (useRAF) {
return window.cancelAnimationFrame(id);
}
clearTimeout(id);
}
function leadingEdge(time) {
// Reset any `maxWait` timer.
lastInvokeTime = time; // Start the timer for the trailing edge.
timerId = startTimer(timerExpired, wait); // Invoke the leading edge.
return leading ? invokeFunc(time) : result;
}
function remainingWait(time) {
var timeSinceLastCall = time - lastCallTime;
var timeSinceLastInvoke = time - lastInvokeTime;
var timeWaiting = wait - timeSinceLastCall;
return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
}
function shouldInvoke(time) {
var timeSinceLastCall = time - lastCallTime;
var timeSinceLastInvoke = time - lastInvokeTime; // Either this is the first call, activity has stopped and we're at the
// trailing edge, the system time has gone backwards and we're treating
// it as the trailing edge, or we've hit the `maxWait` limit.
return lastCallTime === undefined || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
}
function timerExpired() {
var time = Date.now();
if (shouldInvoke(time)) {
return trailingEdge(time);
} // Restart the timer.
timerId = startTimer(timerExpired, remainingWait(time));
}
function trailingEdge(time) {
timerId = undefined; // Only invoke if we have `lastArgs` which means `func` has been
// debounced at least once.
if (trailing && lastArgs) {
return invokeFunc(time);
}
lastArgs = lastThis = undefined;
return result;
}
function cancel() {
if (timerId !== undefined) {
cancelTimer(timerId);
}
lastInvokeTime = 0;
lastArgs = lastCallTime = lastThis = timerId = undefined;
}
function flush() {
return timerId === undefined ? result : trailingEdge(Date.now());
}
function pending() {
return timerId !== undefined;
}
function debounced() {
var time = Date.now();
var isInvoking = shouldInvoke(time);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
lastArgs = args;
lastThis = this;
lastCallTime = time;
if (isInvoking) {
if (timerId === undefined) {
return leadingEdge(lastCallTime);
}
if (maxing) {
// Handle invocations in a tight loop.
timerId = startTimer(timerExpired, wait);
return invokeFunc(lastCallTime);
}
}
if (timerId === undefined) {
timerId = startTimer(timerExpired, wait);
}
return result;
}
debounced.cancel = cancel;
debounced.flush = flush;
debounced.pending = pending;
return debounced;
}
function throttle(func, wait, options) {
var leading = true;
var trailing = true;
if (typeof func !== 'function') {
throw new TypeError('Expected a function');
}
if (isObject(options)) {
leading = 'leading' in options ? !!options.leading : leading;
trailing = 'trailing' in options ? !!options.trailing : trailing;
}
return debounce(func, wait, {
leading: leading,
trailing: trailing,
maxWait: wait
});
}
function isNative(Ctor) {
return typeof Ctor === 'function' && /native code/.test(Ctor.toString());
}
function isMobile(value) {
if (!/^1\d{10}$/.test(value)) {
return false;
}
return true;
}
function formatMobile(val) {
var len = val.length;
if (len > 3 && len < 8) {
val = val.replace(/\s/g, '').replace(/^(.{3})/g, '$1 ');
} else if (len >= 8) {
val = val.replace(/\s/g, '').replace(/^(.{3})(.+)/g, function (all, first, second) {
return first + " " + second.replace(/(.{4})(?=.)/g, '$1 ');
});
}
return val;
}
function formatBankCard(val) {
return val.replace(/\s/g, '').replace(/(.{4})(?=.)/g, '$1 ');
}
function formatFontSize(value) {
// 判断传参是否是数字 不是加上默认单位 'px'
if (value === undefined && value === null) {
return undefined;
}
return /^\d+(\.\d+)?$/.test(value + '') ? value + "px" : value;
}
function formatTitle(tit) {
if (!tit) return '';
var length = tit.length;
if (length === 2) {
return tit.split('').join('  ');
} else if (length === 3) {
return tit.split('').join(' ');
}
return tit;
}
function outerWidth(el, includeMargin) {
if (includeMargin === void 0) {
includeMargin = true;
}
var width = el.offsetWidth;
if (includeMargin) {
var style = el.currentStyle || getComputedStyle(el);
width += parseInt(style.marginLeft || 0) + parseInt(style.marginRight || 0);
}
return width;
}
function outerHeight(el, includeMargin) {
if (includeMargin === void 0) {
includeMargin = true;
}
var height = el.offsetHeight;
if (includeMargin) {
var style = el.currentStyle || getComputedStyle(el);
height += parseInt(style.marginTop || 0) + parseInt(style.marginBottom || 0);
}
return height;
}
function hexToRgb(hex, alpha) {
var shortResult = /^#([a-f\d]{1})([a-f\d]{1})([a-f\d]{1})$/i.exec(hex);
var longResult = /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
var rgb = null;
if (shortResult) {
rgb = {
r: parseInt(shortResult[1] + shortResult[1], 16),
g: parseInt(shortResult[2] + shortResult[2], 16),
b: parseInt(shortResult[3] + shortResult[3], 16)
};
} else if (longResult) {
rgb = {
r: parseInt(longResult[1], 16),
g: parseInt(longResult[2], 16),
b: parseInt(longResult[3], 16)
};
}
if (!rgb) {
return '';
}
if (alpha !== undefined) {
return "rgba(" + rgb.r + ", " + rgb.g + ", " + rgb.b + ", " + alpha + ")";
} else {
return "rgb(" + rgb.r + ", " + rgb.g + ", " + rgb.b + ")";
}
} // 生成随机字符串
function randomString(len) {
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz';
var maxPos = chars.length;
var pwd = '';
len = len || 32;
for (var i = 0; i < len; i++) {
pwd += chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}