常用的utils
export function stopFun(){
try{
window._axiosPromiseArr.forEach((ele, index) => {
ele.cancel();
delete window._axiosPromiseArr[index];
});
}catch(e){
console.log(e)
}
}
getFormData: {
var t = this.lastTime
var result = []
if (t > 0) {
result.push(Math.floor(t / (3600 * 24)))
result.push(Math.floor((t % (3600 * 24)) / 3600))
result.push(Math.floor((t % 3600) / 60))
result.push(Math.floor(t % 60))
} else {
result[1] = 0
result[2] = 0
result[3] = 0
}
result.forEach(function (item, index) {
if (item < 10 && index > 0) {
result[index] = '0' + result[index]
}
})
return result
},
getUrlParam: function (paramName) {
var reg = new RegExp("(^|&)" + paramName + "=([^&]*)(&|$)", "i"),
arr = window.location.search.substr(1).match(reg);
if (arr) {
return arr[2];
}
return null;
},
enrArray.sort(this.conpare('orderId'))
compare(prop){
return function(a,b){
var val1 = a[prop]
var val2 = b[prop]
return val1 - val2
}
}
statusFilter(val){
let obj ={
1 : "直播前",
2 : "直播中",
3 : "直播结束"
}
return obj[val]
}
setHeighlight() {
if (this.search && this.search.length > 0) {
let that = this
this.searchList.forEach(item => {
let replaceReg = new RegExp(that.search, 'ig')
let replaceStr = '<span class="search_text">' + that.search + '</span>'
item.subject = item.subject.replace(replaceReg, replaceStr)
return item
})
}
}
let obj = {
a: undefined,
b: function () {},
c: Symbol("foo"),
d: null,
e: "hello",
arr: [{
uname: "lili",
arr2: [1, 2, 3]
},
[1, 2, 3]
]
}
function deepCopy(obj, type = {}) {
for (const key in obj) {
if (typeof obj[key] === "object") {
type[key] = Array.isArray(obj[key]) ? [] : {};
deepCopy(obj[key], type[key])
} else {
type[key] = obj[key];
}
}
return type;
}
let x = new deepCopy(obj);
x.arr[1][0] = "hi";
console.log(x,obj);