Files
xiezheng_jq/js/page/info.js
2024-12-10 12:20:05 +08:00

97 lines
2.5 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.

class Info {
title = "";
defaultArr = []
allArr = [];
like = JSON.parse(localStorage.getItem("like")) || [];
constructor() {
this.init()
}
async init() {
await this.getInfoListData()
header(
`<div class="header_title flex1 ellipsis">${this.title}</div>`,
`
<div class="ilist">
<i class="iconfont icon-wujiaoxing"></i>
<i class="iconfont icon-fenxiang"></i>
</div>
`
)
this.event()
}
async getInfoListData() {
let { title, src_list, recommend } = await infoServe.infoList({
id: query("id")
})
this.title = title
this.defaultArr = src_list.splice(0, 2)
this.allArr = src_list
eachHtml(
".info_img_list .img_list",
this.defaultArr,
(v) => `<img src="${v}" alt="">`
)
eachHtml(
".default-model ul",
recommend,
(v) => item(v)
)
}
event() {
this.like.filter(v => v.id == query("id")).length != 0
? $(".icon-wujiaoxing").addClass("icon-wujiaoxing1")
: null
$(".icon-fenxiang").click(async () => {
await navigator.clipboard.writeText(`
我这有个好看的,快来看看 ${this.title}
${location.href}
`)
alert("内容已复制")
})
$(".icon-wujiaoxing").click(() => {
// 如果有icon-wujiaoxing1表示收藏过了
if ($(".icon-wujiaoxing").hasClass("icon-wujiaoxing1")) {
this.like = this.like.filter(v => v.id != query("id"))
// 没有 icon-wujiaoxing1表示未收藏过了
} else {
this.like.push({
"id": query("id"),
"thumbnail": this.defaultArr[0],
"title": this.title,
"time": query("time"),
"view": "42"
})
}
localStorage.setItem("like", JSON.stringify(this.like))
$(".icon-wujiaoxing").toggleClass("icon-wujiaoxing1")
})
$(".view_all").click(() => {
$(".img_list").css({ height: 'auto' })
eachHtml(
".info_img_list .img_list",
this.allArr,
(v) => `<img src="${v}" alt="">`
)
$(".view_all").css({ display: 'none' })
})
}
}
new Info