Files
SOP/sop-website/sop-portal/utils/index.js
tanghc 6ab696dfaf - 新增ISV用户平台
- 新增门户网站(portal)
- 新增`C++`,`Rust`语言SDK
2020-11-07 10:55:12 +08:00

37 lines
829 B
JavaScript

/* eslint-disable import/prefer-default-export */
export const throttle = (fn, delay) => {
let timer = null;
return function(...args) {
const context = this;
clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(context, args);
}, delay);
};
};
export const getScrollTop = () => {
let scrollTop = 0;
if (document.documentElement && document.documentElement.scrollTop) {
scrollTop = document.documentElement.scrollTop;
} else if (document.body) {
scrollTop = document.body.scrollTop;
}
return scrollTop;
};
export const getLink = (link) => {
if (`${link}`.length > 1 && /^\/[^/]/.test(`${link}`)) {
return `${window.rootPath}${link}`;
}
return link;
};
export const parseJSONStr = (str) => {
try {
return JSON.parse(str);
} catch (err) {
return str;
}
}