This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function loadScript(url, callback) { | |
try { | |
let script = document.createElement("script"); | |
if (script.readyState) { | |
// IE | |
script.onreadystatechange = function () { | |
if ( | |
script.readyState === "loaded" || | |
script.readyState === "complete" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 处理文件大小 | |
function handleSize(file, size) { | |
const isLimitSize = file.size / 1024 / 1024 < size | |
if (!isLimitSize) { | |
Message.error(`上传图片大小不能超过${size}M`) | |
return false | |
} | |
return true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 不刷新页面, 清除 url 参数 */ | |
function clearAutoParams(name) { | |
try { | |
// 获取正则结果 | |
const getRegRes = function(name) { | |
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); | |
var result = window.location.search.substr(1).match(reg); | |
return result | |
} | |
const result = getRegRes(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('scroll', function(){ | |
// todo 添加距离底部位置 | |
// const isBottom = getScrollHeight() <= getDocumentTop() + getWindowHeight() | |
if(getScrollHeight() == getDocumentTop() + getWindowHeight()){ | |
//当滚动条到底时,触发内容 | |
alert("滑动到的底部"); | |
} | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 校验表格 */ | |
export function validForm(formObj, success, error) { | |
if (!formObj) return | |
formObj.validate(valid => { | |
console.log('valid: ', valid); | |
if (valid) { | |
success && success() | |
} else { | |
error && error(valid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getUsefulWidthCount({ | |
containerWidth, | |
cardWidth=356, | |
borderWidth=10, | |
}={}) { | |
if(!containerWidth || containerWidth<=0) return [0, 0] | |
let maxCountPer = 0, resultWith = 0 | |
const addNewCardWidth = () => (maxCountPer + 1) * (cardWidth + borderWidth) - borderWidth | |
while(cardWidth>0 && containerWidth>0 && addNewCardWidth() <= containerWidth) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 解决 node 不能接收 try catch 的 promise | |
if(process) { | |
process.on('unhandledRejection', (reason, p) => { | |
console.warn('Unhandled Rejection at: Promise', p, 'reason:', reason); | |
// application specific logging, throwing an error, or other logic here | |
}); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createRandom(start, end) { | |
const range = end - start | |
return start + Math.round(range * Math.random()) | |
} | |
function createList(max=100) { | |
const getInt = ()=> createRandom(1, max) | |
const result = [] | |
let count = 0 | |
while(count < max) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parseStrParam(url) { | |
const paramsStr = /.+\?(.+)$/.exec(url)[1] // 将 ? 后面的字符串取出来 | |
const paramsArr = paramsStr.split('&') // 将字符串以 & 分割后存到数组中 | |
let paramsObj = {} | |
// 将 params 存到对象中 | |
paramsArr.forEach(param => { | |
if (/=/.test(param)) { // 处理有 value 的参数 | |
let [key, val] = param.split('=') // 分割 key 和 value | |
val = decodeURIComponent(val) // 解码 | |
val = /^\d+$/.test(val) ? parseFloat(val) : val // 判断是否转为数字 |
NewerOlder