first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
// 全局js配置,一般用来配置接口的基地址,和 短地址 等一些...
var config = {
// 开发阶段
devBaseUrl: 'http://127.0.0.1:3000/api/json',
// 测试阶段
testBaseUrl: 'http://127.0.0.2:8080/api/json',
// 正式阶段
prodBaseUrl: 'http://www.anc.com/api/json',
stage: 'dev', // dev test prod
switchStage: function () {
switch (this.stage) {
case "dev":
return this.devBaseUrl
break;
case "test":
return this.testBaseUrl
break;
case "prod":
return this.prodBaseUrl
break;
default:
break;
}
},
apiList: {
index: '/index',
info: '/info',
mechanism: '/mechanism',
type: '/class',
classList: '/classList',
mechanismList:'/mechanismList'
},
footerArr: [
{ title: '首页', href: 'index.html', icon: 'icon-home' },
{ title: '机构', href: 'mechanism.html', icon: 'icon-jigou' },
{ title: '模特', href: 'model.html', icon: 'icon-me' },
{ title: '我的', href: 'me.html', icon: 'icon-wo' },
]
}

View File

@@ -0,0 +1,58 @@
class Http {
constructor() {
this.xhr = new XMLHttpRequest();
}
get(params) {
return new Promise((success, error) => {
var par = ""
for (const key in params.data) {
par += `&${key}=${params.data[key]}`
}
par = par.replace("&", "?")
this.xhr.open("GET", `${config.switchStage()}${params.url}${par}`)
this.xhr.send()
this.ReadyState(success, error)
})
}
post(params) {
return new Promise((success, error) => {
this.xhr.open("POST", `${params.url}`)
this.xhr.setRequestHeader('Content-Type', 'application/json');
this.xhr.send(JSON.stringify(params.data))
this.ReadyState(success, error)
})
}
ReadyState(success, error) {
this.xhr.onreadystatechange = () => {
if (this.xhr.readyState == 4) {
if (this.xhr.status == 200) {
var data = JSON.parse(this.xhr.response);
switch (data.status) {
case 200:
success(data.result)
break;
case 404:
alert(data.msg)
throw new Error(data.msg)
break;
default:
break;
}
} else {
error(this.xhr)
}
}
}
}
}

View File

@@ -0,0 +1,37 @@
class Collection {
constructor() {
title("我的收藏")
this.likeArr = JSON.stringify(localStorage.getItem("like"))
this.likeArr
}
async getLike() {
var self = this;
if (localStorage.setItem("like") == null) {
var res = await IndexService.classList();
this.likeArr = res.likeArr
localStorage.setItem("like", JSON.stringify(this.likeArr))
}
else {
this.likeArr = JSON.parse(localStorage.setItem("like"))
}
}
renderlikeArr() {
this.likeArr.forEach(v => {
$(".content").innerHTML += `
<li>${v}</li>
`
});
}
}
new Collection()

View File

@@ -0,0 +1,53 @@
class Edit {
constructor() {
title("分类管理")
this.principal = JSON.parse(localStorage.getItem("principal"))
this.additional = JSON.parse(localStorage.getItem("additional"))
this.renderPage()
}
renderPage() {
$(".selected ul").innerHTML = ""
this.principal.forEach(v => {
$(".selected ul").innerHTML += `
<li>${v.title}</li>
`
});
$(".optional ul").innerHTML = ""
this.additional.forEach(v => {
$(".optional ul").innerHTML += `
<li>${v.title}</li>
`
});
click(".selected ul li", (v,i) => {
if (i != 0) {
this.additional.push(this.principal[i])
this.principal = this.principal.filter((val,index) => {
return index != i
});
localStorage.setItem("principal", JSON.stringify(this.principal))
localStorage.setItem("additional", JSON.stringify(this.additional))
this.renderPage()
}
})
click(".optional ul li", (v,i) => {
this.principal.push(this.additional[i])
this.additional = this.additional.filter((val,index) => {
return index != i
});
localStorage.setItem("principal", JSON.stringify(this.principal))
localStorage.setItem("additional", JSON.stringify(this.additional))
this.renderPage()
})
}
}
new Edit()

View File

@@ -0,0 +1,125 @@
class Index {
constructor() {
this.index = 0;
this.principa = []
footer();
this.initSwiper();
this.getType().then(() => this.getIndex());
}
async getType() {
// 本地无数值,那么发送请求
if (localStorage.getItem("principal") == null) {
var { principal, additional } = await indexService.type()
localStorage.setItem("principal", JSON.stringify(principal))
localStorage.setItem("additional", JSON.stringify(additional))
} else {
var principal = JSON.parse(localStorage.getItem("principal"))
var additional = JSON.parse(localStorage.getItem("additional"))
}
this.principal = principal;
console.log(this.principal);
// TODO 改造这个代码,实现下面的作业
this.principal.forEach((v, i) => {
$(".header_menu ul").innerHTML += `<li class="${i == 0 ? 'active' : ''}">${v.title}</li>`;
$(".swiper .swiper-wrapper").innerHTML += `
<div class="swiper-slide">
<div class="list">
</div>
</div>
`;
});
click(".header_menu ul li", (v, i) => {
_(".header_menu ul li").forEach(v => v.classList.remove("active"))
v.classList.add("active")
this.index = i
this.getClassList()
this.mySwiper.slideTo(i)
})
_(".swiper .swiper-wrapper .swiper-slide").forEach((v,i) => {
if (i != 0) {
v.onscroll = () => {
const {clientHeight, scrollHeight, scrollTop} = v;
var distance = scrollHeight- scrollTop - clientHeight;
if (distance <= 0.5) {
this.principal[this.index].page += 1
if (this.principal[this.index].page <= this.principal[this.index].total_page) {
this.getClassList("loadMore")
}
}
}
}
})
}
async getIndex() {
var res = await indexService.index()
this.principal[this.index].content = res.list
item(
_(".swiper .swiper-wrapper .swiper-slide .list")[this.index],
this.principal[this.index].content
)
}
async getClassList(type = "click") {
var getList = async () => {
var res = await indexService.classList({
page: this.principal[this.index].page,
id: this.principal[this.index].id
});
this.principal[this.index].content = [
...this.principal[this.index].content,
...res.data
]
this.principal[this.index].total_page = res.total_page
console.log("getClassList: ", this.principal);
// 渲染页面(注意:把指定数组下标的content渲染到对应下标的 swiper-slide)
item(
_(".swiper .swiper-wrapper .swiper-slide .list")[this.index],
this.principal[this.index].content
)
}
if (type == "click") {
if (this.principal[this.index].content.length == 0 && this.index != 0) {
getList();
}
} else {
getList();
}
}
initSwiper() {
var self = this;
this.mySwiper = new Swiper('.swiper', {
direction: 'horizontal',
on: {
slideChangeTransitionEnd: function () {
_(".header_menu ul li").forEach(v => v.classList.remove("active"))
_(".header_menu ul li")[this.activeIndex].classList.add("active")
self.index = this.activeIndex
self.getClassList()
},
},
})
}
}
new Index()

View File

@@ -0,0 +1,71 @@
class Info {
constructor() {
this.infoArr = []
this.likeArr = JSON.parse(JSON.stringify(localStorage.getItem("like")) ) == null
? []
: JSON.parse(JSON.stringify(localStorage.getItem("like")))
title(query("title"), `<i class="like iconfont icon-xin"></i>`)
this.getInfo()
this.like()
}
async getInfo() {
this.infoArr = await indexService.info({
id: query("id"),
quantity: query("quantity")
});
this.infoArr.forEach((v,i) => {
var img = document.createElement("img")
img.src = v;
img.onload = () => {
$(".imgList").innerHTML += `
<figure>
<a href="${v}" data-size="${img.width}x${img.height}">
<img src="${v}" alt="${v}" />
</a>
<figcaption itemprop="caption description">${query("title")} ${i+1}P</figcaption>
</figure>
`
}
});
initPhotoSwipeFromDOM('.imgList');
}
like() {
var res = this.likeArr.filter((v,i) => {
return query("id") == v.id
});
if (res.length != 0) {
$(".like").classList.replace("icon-xin", "icon-aixin")
}
click(".like", () => {
if ($(".like").classList.contains("icon-xin")) {
$(".like").classList.replace("icon-xin", "icon-aixin")
this.likeArr.push({
id: query("id"),
quantity: query("quantity"),
img: this.infoArr[0]
});
} else {
$(".like").classList.replace("icon-aixin", "icon-xin")
this.likeArr = this.likeArr.filter((v,i) => {
return query("id") != v.id
});
}
localStorage.setItem("like", JSON.stringify(this.likeArr))
})
}
}
new Info();

View File

@@ -0,0 +1,10 @@
class Me {
constructor() {
footer()
title("我的收藏")
}
}
new Me()

View File

@@ -0,0 +1,10 @@
class Mechanism {
constructor() {
footer()
}
}
new Mechanism()

View File

@@ -0,0 +1,36 @@
class mechanismList {
constructor() {
title("机构详情")
this.page = 1
this.getmechanismList();
}
async getmechanismList() {
var self = this
var params = {
id: query("id"),
page: self.page
}
var res = await indexService.mechanismList(params)
console.log(res);
res.data.forEach((val) => {
$(".detailed").innerHTML +=`
<div class="photo">
<img src="${val.preview}" alt="">
<div class="introduce">
<span class="mo">${val.title}</span>
<p class="mec">${val.user}</p>
</div>
</div>
`
})
}
}
new mechanismList()

View File

@@ -0,0 +1,10 @@
class model {
constructor() {
footer()
}
}
new model()

View File

@@ -0,0 +1,60 @@
class IndexService {
async index(params = {}) {
return await (new Http()).get({
url: config.apiList.index,
data: params
});
}
async info(params = {}) {
return await (new Http()).get({
url: config.apiList.info,
data: params
});
}
async mechanismList(params = {}) {
return await (new Http()).get({
url: config.apiList.mechanismList,
data: params
});
}
async classList(params = {}) {
return await (new Http()).get({
url: config.apiList.classList,
data: params
});
}
async type(params = {}) {
var res = await (new Http()).get({
url: config.apiList.type,
data: params
});
res.principal.unshift({
id: null,
page: null,
title: "首页"
});
res.principal.forEach(v => {
v.content = []
v.total_page = 0
});
res.additional.forEach(v => {
v.content = []
v.total_page = 0
});
return res
}
}
var indexService = new IndexService()

View File

@@ -0,0 +1,116 @@
class Utils {
footer() {
var html = `
<ul class="footer top">
${config.footerArr.forH(v => {
return `<li>
<a href="${v.href}" class="${location.href.includes(v.href) ? 'active' : ''}">
<i class="iconfont ${v.icon}"></i>
<p>${v.title}</p>
</a>
</li>`
})}
</ul>
`
$("body").insertAdjacentHTML("beforeend", html);
}
item (father, data) {
father.innerHTML = ""
data.forEach(v => {
father.innerHTML+=
`
<div class="item">
<div class="img">
<a href="./info.html?id=${v.id}&quantity=${v.total || v.shuliang}&title=${encodeURIComponent(v.title)}">
<img src="${v.preview || v.img_src}" alt="">
<span>${v.total || v.shuliang}P</span>
</a>
</div>
<div class="text">
<a href="./info.html?id=${v.id}&quantity=${v.total || v.shuliang}&title=${encodeURIComponent(v.title)}">
<div class="title ellipsis">${v.title}</div>
<div class="model ellipsis">${v.user || `模特: ${v.renwulist[0].name}`}</div>
<div class="mechanism ellipsis">${v.source || `机构: ${v.jigoulist[0].name}`}</div>
</a>
</div>
<div class="tags">
${
(v.tags || v.biaoqianlist).forH(val => {
return `
<a href="">${val.title || val.name}</a>
`
})
}
</div>
</div>
`
})
}
title(text = "", rightIcon = "") {
var html = `
<div class="pub_title">
<i class="iconfont icon-back1"></i>
<span class="ellipsis">${text}</span>
${rightIcon}
</div>
`
$("body").insertAdjacentHTML("beforeend", html);
click(".icon-back1", () => {
history.back()
})
}
click(className, callback) {
_(className).forEach((v,i) => v.onclick = () => callback(v,i))
}
query(name) {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
let r = window.location.search.substr(1).match(reg);
if (r != null) {
return decodeURIComponent(r[2]);
};
return null;
}
cover() {
Array.prototype.forH = function (callback) {
var res = []
for (var index = 0; index < this.length; index++) {
res.push(callback(this[index]))
}
return res.toString().replaceAll(",", "")
}
// 其他很多重写
}
$(className) {
return document.querySelector(className)
}
_(className) {
return document.querySelectorAll(className)
}
}
var {
footer, $, _, query,
cover, click, item,
title
} = new Utils();
cover()

View File

@@ -0,0 +1,15 @@
(function (w, d) {
function setSize() {
// 获取屏幕的宽度 375px
var screenWidth = d.documentElement.clientWidth;
// 根据规则计算 html 的font-size数值
var currentFontSize = screenWidth * 100 / 750;
// 修改html上的font-size
d.documentElement.style.fontSize = currentFontSize + 'px';
}
w.addEventListener('resize', setSize);
w.addEventListener('pageShow', setSize)
w.addEventListener('DOMContentLoaded', setSize)
})(window, document)