@icreate/ics-mui
Version:
京东风格的轻量级移动端 Vue2、Vue3 组件库(支持小程序开发)
156 lines (155 loc) • 4.53 kB
JavaScript
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __objRest = (source, exclude) => {
var target = {};
for (var prop in source)
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
target[prop] = source[prop];
if (source != null && __getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(source)) {
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
target[prop] = source[prop];
}
return target;
};
import { h, toRaw } from "vue";
const TypeOfFun = (value) => {
if (null === value) {
return "null";
}
const type = typeof value;
if ("undefined" === type || "string" === type) {
return type;
}
const typeString = toString.call(value);
switch (typeString) {
case "[object Array]":
return "array";
case "[object Date]":
return "date";
case "[object Boolean]":
return "boolean";
case "[object Number]":
return "number";
case "[object Function]":
return "function";
case "[object RegExp]":
return "regexp";
case "[object Object]":
if (void 0 !== value.nodeType) {
if (3 == value.nodeType) {
return /\S/.test(value.nodeValue) ? "textnode" : "whitespace";
} else {
return "element";
}
} else {
return "object";
}
default:
return "unknow";
}
};
const isArray = Array.isArray;
const isDate = (val) => val instanceof Date;
const isFunction = (val) => typeof val === "function";
const isString = (val) => typeof val === "string";
const isObject = (val) => val !== null && typeof val === "object";
const isPromise = (val) => {
return isObject(val) && isFunction(val.then) && isFunction(val.catch);
};
const docu = document;
const body = docu.body;
const getPropByPath = (obj, keyPath) => {
try {
return keyPath.split(".").reduce((prev, curr) => prev[curr], obj);
} catch (error) {
return "";
}
};
const floatData = (format, dataOp, mapOps) => {
const mergeFormat = Object.assign({}, format);
const mergeMapOps = Object.assign({}, mapOps);
if (Object.keys(dataOp).length > 0) {
Object.keys(mergeFormat).forEach((keys) => {
if (Object.prototype.hasOwnProperty.call(mergeMapOps, keys)) {
const tof = TypeOfFun(mergeMapOps[keys]);
if (tof == "function") {
mergeFormat[keys] = mergeMapOps[keys](dataOp);
}
if (tof == "string") {
mergeFormat[keys] = dataOp[mergeMapOps[keys]];
}
} else {
if (dataOp[keys])
mergeFormat[keys] = dataOp[keys];
}
});
return mergeFormat;
}
return format;
};
function myFixed(num, digit = 2) {
if (Object.is(parseFloat(num), NaN)) {
return console.log(`传入的值:${num}不是一个数字`);
}
num = parseFloat(num);
return (Math.round((num + Number.EPSILON) * Math.pow(10, digit)) / Math.pow(10, digit)).toFixed(digit);
}
function preventDefault(event, isStopPropagation) {
if (typeof event.cancelable !== "boolean" || event.cancelable) {
event.preventDefault();
}
if (isStopPropagation) {
event.stopPropagation();
}
}
const padZero = (num, length = 2) => {
num += "";
while (num.length < length) {
num = "0" + num;
}
return num.toString();
};
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
const getScrollTopRoot = () => {
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
};
function isVnode(element) {
return element && typeof element === "object" && "componentOptions" in element && "context" in element && element.tag !== void 0;
}
const resolveComponent = (_a) => {
var _b = _a, { child } = _b, props = __objRest(_b, ["child"]);
if (child) {
if (typeof child === "string" || typeof child === "number") {
return child;
} else if (typeof child === "function") {
return child(props);
} else if (isVnode(child)) {
console.log("isVnode", child);
return child;
} else {
console.log("toRaw", child);
return h(toRaw(child), props);
}
}
return null;
};
export {
TypeOfFun as T,
isArray as a,
body as b,
isDate as c,
preventDefault as d,
clamp as e,
isPromise as f,
getPropByPath as g,
isString as h,
isFunction as i,
getScrollTopRoot as j,
isObject as k,
floatData as l,
myFixed as m,
padZero as p,
resolveComponent as r
};