Files
ClassContent/项目合集/最新写真app/fontend/js/utils/index.js
2025-03-16 23:01:07 +08:00

107 lines
3.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const footer = () => {
let currentHref = location.href
let html = `
<ul class="footer fixed flex jc-sb ai-c border-box border-top">
${config.footerArr.maps((v, i) => {
return `<li class="${location.href.includes(v.href) ? 'active' : ''}">
<a href="${v.href}">
<i class="iconfont ${v.icon}"></i>
<div>${v.title}</div>
</a>
</li>`
})}
</ul>
`
$("body").insertAdjacentHTML("beforeend", html)
}
const header = (right, center = "", left = `<i class="iconfont icon-fanhui"></i>`) => {
let html = `
<div class="header fixed flex ai-c jc-sb p18 border-box border-bottom">
${left}
<div class="header_title ellipsis">${center}</div>
${right}
</div>
`
$("body").insertAdjacentHTML("afterbegin", html)
_(".header .icon-fanhui").click(v => {
history.back()
})
}
const item = (father, data) => {
(typeof father == "string" ? $(father) : father).insertAdjacentHTML("beforeend",data.maps(v => {
return `
<li>
<a href="./info.html?id=${v.id}&time=${v.time}&view=${v.view}">
<img src="${v.thumbnail}" alt="">
<div class="desc">
<div class="name ellipsis">${v.title}</div>
<div class="time flex ai-c jc-sb">
<div class="text">${v.time}</div>
<div class="view flex ai-c">
<i class="iconfont icon-liulan"></i>
<span>${v.view}W+</span>
</div>
</div>
</div>
</a>
</li>
`
}))
}
const query = name =>{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return decodeURIComponent(r[2]); return null;
}
const stripIndents = (template, ...expressions) => {
let result = template.reduce((prev, next, i) => {
let expression = expressions[i - 1];
return prev + expression + next;
});
result = result.replace(/\n[^\S\n]*/g, '\n');
result = result.trim();
return result;
}
const innerMaps = (father, data, callback) => {
$(father).insertAdjacentHTML("afterbegin", data.maps((v,i) => {
return callback(v,i)
}))
}
const $ = className => {
return document.querySelector(className)
}
const _ = className => {
return document.querySelectorAll(className)
}
// prototype 原型
// js给我们提供的一个方法通过这个方法作为入口
// 我们可以直接对js进行修改
Array.prototype.maps = function (callback) {
let result = []
for (let i = 0; i < this.length; i++) {
result.push(callback(this[i], i, this))
}
return result.toString().replaceAll(",", "")
}
NodeList.prototype.click = function (callback) {
this.forEach((v,i) => v.onclick = () => callback(v,i))
}
NodeList.prototype.scroll = function (callback) {
this.forEach((v,i) => v.onscroll = () => callback(v,i))
}