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,49 @@
// 全局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',
model: '/allModel',
search:'/search',
modelList:'/modelList'
},
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,47 @@
// 全局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: '/classList'
},
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,56 @@
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,130 @@
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")
}
}
}
}
})
// 作业:在utils里面 实现下面这种封装
// principal.html(".header_menu ul", (v,i) => {
// return `<li class="${i == 0 ? 'active' : ''}">${v.title}</li>`
// })
}
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,72 @@
class Info {
constructor() {
this.infoArr = []
this.likeArr = JSON.parse(localStorage.getItem("like")) == null
? []
: JSON.parse(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,24 @@
class Mechanism {
constructor () {
footer()
title('机构')
this.getmechanism()
}
async getmechanism() {
var res = await indexService.mechanism({ });
console.log("test:",res)
res.forEach((v) => {
$(".list").innerHTML += `
<a href="./mechanisminfo.html?id=${v.id}&title=${v.title}" class="shuliang">
<div class="title">${v.title}</div>
<div class="number">${v.id}套</div>
</a>
`
})
}
}
new Mechanism()

View File

@@ -0,0 +1,35 @@
// class Model {
// constructor () {
// footer()
// }
// }
// new Model()
class Model {
constructor() {
footer()
title("模特")
this.getModel()
//this.renderModelPage()
}
async getModel() {
var res = await modelService.model();
console.log("list接口数据",res);
res.forEach((v => {
$(".model_list").innerHTML += `
<a href="./modelinfo.html?id=${v.id}&title=${v.title}">
<i>44张</i>
<img src="${v.img}" alt="">
<span class="ellipsis">${v.title}</span>
</a>
`
}))
}
}
new Model()

View File

@@ -0,0 +1,53 @@
class Modelinfo {
constructor() {
this.list = [];
title(query("title"))
this.appear = true
this.page = 1
this.getmodelList();
}
async getmodelList() {
var self = this;
var res = await indexService.modelList({
id: query("id"),
page: this.page
})
//每次请求接口得到结果,把数组累加
res.data.forEach(element => {
this.list.push(element)
});
//判断是否第一次请求,是 === 渲染简介 否 === 不渲染
if (this.appear) {this.modelList($('.title'),res) }
this.testModelList($('.test'), this.list)
}
modelList(father, data) {
father.innerHTML +=`
<img src="${data.model_info.portrait}" alt="">
<div class="name">
<p>${data.model_info.name}</p>
<p>${data.model_info.explain} </p>
</div>
`
}
testModelList(father, data) {
data.forEach((value, index) => {
father.innerHTML +=
`
<img src="${value.img_src}" alt="">
`
})
}
}
new Modelinfo();

View File

@@ -0,0 +1,67 @@
class Search {
constructor() {
footer()
this.getSearch()
this.seek()
}
async seek(newKey) {
var res = await indexService.search({
keyword: newKey,
page: 1
});
item($(".recommend .list"), res)
}
hidden (){
$(".suggest").style.display = "none"
$(".recommend").style.display = "block"
}
show (){
$(".suggest").style.display = "block"
$(".recommend").style.display = "none"
}
async getSearch() {
var res = await indexService.search({
keyword: "长裙",
page: 1
});
res.forEach(v => {
$(".suggest_list").innerHTML += `
<li class="ellipsis">${v.biaoqianlist[0].name}</li>
`
});
// item($(".recommend .list"), res)
//获取输入框值
$(".search_box").oninput = () => {
if ($(".search_box").value.length > 0) {
this.seek($(".search_box").value)
}
}
//input获得焦点
$(".search_box").onfocus = () => {
this.show()
}
$(".content").onclick = () => {
this.hidden()
}
//标签绑定点击事件
click(".suggest_list li", (v, i) => {
$(".search_box").value = v.innerText
this.seek($(".search_box").value)
this.hidden()
})
//绑定搜索按钮
click(".icon-search", async (v, i) => {
this.seek($(".search_box").value)
this.hidden()
})
click(".icon-back1", () => {
history.back()
})
}
}
new Search()

View File

@@ -0,0 +1,21 @@
class Tags {
constructor() {
title(query("name"))
footer()
this.getTags()
}
async getTags() {
this.res = await indexService.classList({
id: query("id"),
page: 1,
});
this.res.data.forEach((v, i) => {
item($(".swiper-slide .list"),this.res.data)
});
}
}
new Tags()

View File

@@ -0,0 +1,80 @@
class IndexService {
async index(params = {}) {
return await (new Http()).get({
url: config.apiList.index,
data: params
});
}
async search (params = {}) {
return await (new Http()).get({
url: config.apiList.search,
data: params
});
}
async info(params = {}) {
return await (new Http()).get({
url: config.apiList.info,
data: params
});
}
async classList(params = {}) {
return await (new Http()).get({
url: config.apiList.classList,
data: params
});
}
async mechanism(params = {}) {
return await (new Http()).get({
url: config.apiList.mechanism,
data: params
});
}
async mechanisminfo(params = {}) {
return await (new Http()).get({
url: config.apiList.mechanisminfo,
data: params
});
}
Mechanisminfo
async modelList(params = {}) {
return await (new Http()).get({
url: config.apiList.modelList,
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,11 @@
class ModelService {
async model(params = {}) {
return await (new Http()).get({
url: config.apiList.model,
data: params
});
}
}
var modelService = new ModelService()

View File

@@ -0,0 +1,126 @@
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>
${(v.tags || v.biaoqianlist) == undefined
? ''
: `<div class="tags">
${
(v.tags || v.biaoqianlist).forH(val => {
return `
<a href="./../page/tags.html?id=${val.id}&name=${val.title || val.name}">${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() {
// 对map进行重写
// map的实现原理
// function a(callback) {
// return callback(v).toString()
// }
// var c = a( function (v) {
// return "v"
// } )
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)