| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- const utils = {
- throttle: function (fn, interval) {
- let lastRunTime = 0
- return function (...args) {
- let elapsedTime = Date.now() - lastRunTime
- if (elapsedTime < interval) {
- return
- }
- let context = this
- lastRunTime = Date.now()
- fn.apply(context, args)
- }
- },
- getImageUrl(name) {
- return new URL(`../assets/images/${name}`, import.meta.url).href
- },
- getQueryByName(key) {
- let querys = window.location.search.substring(1).split('&')
- for (let i = 0; i < querys.length; i++) {
- let keypair = querys[i].split('=')
- if (keypair.length === 2 && keypair[0] === key) {
- try {
- return decodeURIComponent(keypair[1])
- } catch (error) {
- return keypair[1]
- }
- }
- }
- return ''
- }
- }
- /**
- * 获取忽略指定属性的对象
- * @param {Object} obj 源对象
- * @param {...any} props 忽略属性
- */
- export function omit(obj, ...props) {
- const result = { ...obj }
- props.forEach(function (prop) {
- delete result[prop]
- })
- return result
- }
- export const objectToString = Object.prototype.toString
- export const toTypeString = value => objectToString.call(value)
- // 获取制定对象的类型比如toRawType(1) Number
- export const toRawType = value => toTypeString(value).slice(8, -1)
- /**
- * 判断是否函数
- * @param {any} target 参数对象
- */
- export const isFunction = target => toRawType(target) === 'Function'
- export default utils
|