1 line
4.7 KiB
Plaintext
1 line
4.7 KiB
Plaintext
|
{"version":3,"file":"utils.js","sources":["../../../../../src/sheep/helper/utils.js"],"sourcesContent":["export function isArray(value) {\r\n if (typeof Array.isArray === 'function') {\r\n return Array.isArray(value)\r\n } else {\r\n return Object.prototype.toString.call(value) === '[object Array]'\r\n }\r\n}\r\n\r\nexport function isObject(value) {\r\n return Object.prototype.toString.call(value) === '[object Object]'\r\n}\r\n\r\nexport function isNumber(value) {\r\n return !isNaN(Number(value))\r\n}\r\n\r\nexport function isFunction(value) {\r\n return typeof value === 'function'\r\n}\r\n\r\nexport function isString(value) {\r\n return typeof value === 'string'\r\n}\r\n\r\nexport function isEmpty(value) {\r\n if (value === '' || value === undefined || value === null) {\r\n return true\r\n }\r\n\r\n if (isArray(value)) {\r\n return value.length === 0\r\n }\r\n\r\n if (isObject(value)) {\r\n return Object.keys(value).length === 0\r\n }\r\n\r\n return false\r\n}\r\n\r\nexport function isBoolean(value) {\r\n return typeof value === 'boolean'\r\n}\r\n\r\nexport function last(data) {\r\n if (isArray(data) || isString(data)) {\r\n return data[data.length - 1]\r\n }\r\n}\r\n\r\nexport function cloneDeep(obj) {\r\n const d = isArray(obj) ? [...obj] : {}\r\n\r\n if (isObject(obj)) {\r\n for (const key in obj) {\r\n if (obj[key]) {\r\n if (obj[key] && typeof obj[key] === 'object') {\r\n d[key] = cloneDeep(obj[key])\r\n } else {\r\n d[key] = obj[key]\r\n }\r\n }\r\n }\r\n }\r\n\r\n return d\r\n}\r\n\r\nexport function clone(obj) {\r\n return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj))\r\n}\r\n\r\nexport function deepMerge(a, b) {\r\n let k\r\n for (k in b) {\r\n a[k] = a[k] && a[k].toString() === '[object Object]' ? deepMerge(a[k], b[k]) : (a[k] = b[k])\r\n }\r\n return a\r\n}\r\n\r\nexport function contains(parent, node) {\r\n while (node && (node = node.parentNode)) if (node === parent) return true\r\n return false\r\n}\r\n\r\nexport function orderBy(list, key) {\r\n return list.sort((a, b) => a[key] - b[key])\r\n}\r\n\r\nexport function deepTree(list) {\r\n const newList = []\r\n const map = {}\r\n\r\n list.forEach((e) => (map[e.id] = e))\r\n\r\n list.forEach((e) => {\r\n const parent = map[e.parentId]\r\n\r\n if (parent) {\r\n ;(parent.children || (parent.children = [])).push(e)\r\n } else {\r\n newList.push(e)\r\n }\r\n })\r\n\r\n const fn = (list) => {\r\n list.map((e) => {\r\n if (e.children instanceof Array) {\r\n e.children = orderBy(e.children, 'orderNum')\r\n\r\n fn(e.children)\r\n }\r\n })\r\n }\r\n\r\n fn(newList)\r\n\r\n return orderBy(newList, 'orderNum')\r\n}\r\n\r\nexport function revDeepTree(list = []) {\r\n const d = []\r\n let id = 0\r\n\r\n const deep = (list, parentId) => {\r\n list.forEach((e) => {\r\n if (!e.id) {\r\n e.id = id++\r\n }\r\n\r\n e.parentId = parentId\r\n\r\n d.push(e)\r\n\r\n if (e.children && isArray(e.children)) {\r\n deep(e.children, e.id)\r\n }\r\n })\r\n }\r\n\r\n deep(list || [], null)\r\n\r\n return d\r\n}\r\n\r\nexport function basename(path) {\r\n let index = path.lastIndexOf('/')\r\n index = index > -1 ? index : path.lastIndexOf('\\\\')\r\n if (index < 0) {\r\n return path\r\n }\r\n return path.substring(index + 1)\r\n}\r\n\r\nexport function isWxBrowser() {\r\n const ua = navigator.userAgent.toLowerCase()\r\n if (ua.match(/MicroMessenger/i) == 'micromessenger') {\r\n return true\r\n } else {\r\n return false\r\n }\r\n}\r\n\r\n/**\r\n * @description 如果value小于min,取min;如果value大于max,取max\r\n * @param {number} min\r\n * @param {number} max\r\n * @param {number} value\r\n */\r\nexport function range(min = 0, max = 0, value = 0) {\r\n return Math.max(min, Math.min(max, Number(value)))\r\n}\r\n"],"names":[],"mappings":";AAAO,SAAS,QAAQ,OAAO;AAC7B,MAAI,OAAO,MAAM,YAAY,YAAY;AACvC,WAAO,MAAM,QAAQ
|