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,69 @@
class ajax {
constructor() { // 类的参数初始化
this.baseUrl = config.checkBaseUrl();
this.xhr = new XMLHttpRequest();
}
/**
*
* @param {*} params
* {
* url: 'http://127.0.0.1:3000/api/index/threeMeals',
* data: {
* page: 1,
* id: 1
* },
* success: function() {}
* }
*/
get(params) {
return new Promise((resolve, reject) => {
if (params.hasOwnProperty("data")) {
var str = ""
for (const key in params.data) {
str += `&${key}=${params.data[key]}`
}
str = str.replace("&", "?")
// 设置请求地址
this.xhr.open("GET", `${this.baseUrl}${params.url}${str}`)
//
this.xhr.send();
// 状态监听
return this.onreadystatechange(resolve, reject)
} else {
throw new Error("data参数必传")
}
})
}
onreadystatechange(resolve, reject) {
this.xhr.onreadystatechange = () => {
if (this.xhr.readyState == 4) {
if (this.xhr.status == 200) {
var res = JSON.parse(this.xhr.response);
switch (res.status) {
case 200:
resolve(res.result)
break;
case 404:
alert(res.msg);
throw new Error(res.msg);
break;
}
} else {
alert("网络请求错误")
}
}
}
}
}
var http = new ajax();

View File

@@ -0,0 +1,30 @@
var config = {
devBaseUrl: 'http://127.0.0.1:3000/api/json',
testBaseUrl: 'http://127.0.0.1:3000/api/json/test',
prodBaseUrl: 'http://127.0.0.1:3000/api/json/prod',
stage: 'dev', // dev test prod
checkBaseUrl: function () {
switch (this.stage) {
case "dev":
return this.devBaseUrl;
break;
case "test":
return this.testBaseUrl;
break;
case "prod":
return this.prodBaseUrl;
break;
}
},
// 项目中的所有接口短地址
apiList: {
mechanismList: "/mechanismList",
mechanism: '/mechanism',
classApi: "/class",
index: '/index',
classList: '/classList',
info: '/info'
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,70 @@
class Edit {
constructor() {
this.principal = JSON.parse(localStorage.getItem("principal"));
this.additional = JSON.parse(localStorage.getItem("additional"));
header("分类编辑")
// console.log(this.principal)
// console.log(this.additional)
this.renderPrincipal();
this.renderAdditional();
}
// 已选菜单
renderPrincipal() {
$(".you_select ul").innerHTML = ""
this.principal.forEach((v, i) => {
$(".you_select ul").innerHTML += `
<li>${v.title}</li>
`
});
_(".you_select ul li").forEach((v, i) => {
v.onclick = () => {
if (i != 0) {
this.additional.push(this.principal[i])
localStorage.setItem("additional", JSON.stringify(this.additional))
this.renderAdditional()
this.principal = this.principal.filter((item, index) => {
if (this.principal[i].id != item.id) {
return item
}
})
localStorage.setItem("principal", JSON.stringify(this.principal))
this.renderPrincipal();
}
}
})
}
// 未选菜单
renderAdditional() {
$(".wait_select ul").innerHTML = ""
this.additional.forEach((v, i) => {
$(".wait_select ul").innerHTML += `
<li>${v.title}</li>
`
});
_(".wait_select ul li").forEach((v, i) => {
v.onclick = () => {
this.principal.splice(1, 0, this.additional[i])
localStorage.setItem("principal", JSON.stringify(this.principal))
this.renderPrincipal()
this.additional = this.additional.filter((item, index) => {
if (this.additional[i].id != item.id) {
return item
}
})
localStorage.setItem("additional", JSON.stringify(this.additional))
this.renderAdditional();
}
})
}
}
new Edit()

View File

@@ -0,0 +1,138 @@
class Index {
constructor() {
// 横向菜单的下标
this.index = 0;
// 默认横向菜单的数据
this.principal = []
footer()
this.getClassApi();
}
async getClassApi() {
// 第一次打开app,本地没有缓存,发送请求获取菜单
if (localStorage.getItem("principal") == null) {
// 请求横向 菜单的数据
var res = await index.classApi();
localStorage.setItem("principal", JSON.stringify(res.principal));
localStorage.setItem("additional", JSON.stringify(res.additional));
this.principal = res.principal
// 第二次打开,本地已经有缓存了, 直接使用本地缓存过的菜单数据
} else {
this.principal = JSON.parse(localStorage.getItem("principal"))
}
// 渲染生成横向菜单和对应的内容
this.principal.forEach((v, i) => {
// 生成横向菜单
$(".header_menu ul").innerHTML += `
<li class="${i == 0 ? 'active' : ''}">${v.title}</li>
`;
// 生成横向菜单对应列表内容
if (i > 0) {
$(".swiper-wrapper").innerHTML += `
<div class="swiper-slide">${v.title}</div>
`
}
});
// 为每一个内容绑定滚动事件
var slide = _(".swiper-wrapper .swiper-slide");
var self = this;
slide.forEach((v, i) => {
if (i > 0) {
v.addEventListener('scroll', function () {
if (Math.ceil(this.scrollHeight - this.scrollTop) == this.clientHeight) {
self.principal[self.index].page += 1;
if (self.principal[self.index].page <= self.principal[self.index].total_page) {
console.log("请求数据")
self.getClassList("loadMore")
}
}
})
}
})
// 初始化页面内容的轮播图
var self = this;
var mySwiper = new Swiper('.swiper', {
direction: 'horizontal',
on: {
slideChangeTransitionEnd: function () {
self.changeActive(this.activeIndex)
self.getClassList();
},
},
})
// 为菜单的li标签绑定点击事件
var liArr = _(".header_menu ul li")
liArr.forEach((v, i) => {
v.onclick = () => {
this.changeActive(i)
mySwiper.slideTo(i)
}
})
this.getIndex();
}
async getIndex() {
var res = await index.indexList();
var slide = _(".swiper-wrapper .swiper-slide");
item(slide[this.index], res.list)
}
async getClassList(type = "click") {
var loadData = async () => {
var res = await index.classList({
id: this.principal[this.index].id,
page: this.principal[this.index].page
})
this.principal[this.index].total_page = res.total_page;
// res.data.forEach(v => {
// this.principal[this.index].content.push(v)
// })
this.principal[this.index].content = [
...this.principal[this.index].content,
...res.data
];
console.log("this.principal[this.index]: ", this.principal[this.index])
var slide = _(".swiper-wrapper .swiper-slide");
item(slide[this.index], res.data)
}
if (this.principal[this.index].id != -1) {
// 滚动加载更多
if (type == "loadMore") {
loadData();
// 点击 和 滑动页面
} else {
if (this.principal[this.index].content.length == 0) {
loadData();
}
}
}
}
changeActive(index) {
this.index = index;
var liArr = _(".header_menu ul li")
liArr.forEach(item => item.classList.remove("active"))
liArr[index].classList.add("active")
}
}
new Index();

View File

@@ -0,0 +1,22 @@
class Info {
constructor() {
header(query("title"),`<i class="iconfont icon-xin"></i>`);
this.getInfo();
}
async getInfo() {
var res = await index.info({
id: query("id"),
quantity: query("quantity")
})
res.forEach(v => {
$(".content").innerHTML+= `
<img src="${v}" alt="">
`
})
}
}
new Info();

View File

@@ -0,0 +1,23 @@
class Mechanism {
constructor() {
footer()
header("机构")
this.getMechanism()
}
async getMechanism() {
var res = await index.mechanism();
res.forEach(v => {
$(".content ul").innerHTML += `
<li>
<a href="">${v.title}</a>
</li>
`
});
}
}
new Mechanism();

View File

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

View File

@@ -0,0 +1,7 @@
class my{
constructor(){
footer()
}
}
new my();

View File

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

View File

@@ -0,0 +1,88 @@
class Utils {
$(className) {
return document.querySelector(className);
}
_(className) {
return document.querySelectorAll(className);
}
query(name)
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)return decodeURI(r[2]); return null;
}
footer () {
var arr = [
{ text: '首页', icon: 'icon-home', href: 'index.html' },
{ text: '机构', icon: 'icon-jigou', href: 'mechanism.html' },
{ text: '模特', icon: 'icon-me', href: 'model.html' },
{ text: '我的', icon: 'icon-wo', href: 'my.html' },
];
var liArr = `
<ul class="footer">
${
arr.map((v,i) => {
return `
<li class="${ location.pathname.includes(v.href) ? 'active' : '' }">
<a href="${v.href}">
<i class="iconfont ${v.icon}"></i>
<p>${v.text}</p>
</a>
</li>
`
}).toString().replaceAll(",","")
}
</ul>
`
$("body").innerHTML += liArr
}
item(father, arr) {
arr.forEach(v => {
father.innerHTML += `
<div class="list_item">
<a href="./info.html?id=${v.id}&quantity=${v.shuliang || v.total}&title=${v.title}">
<div class="list_img">
<img src="${v.preview || v.img_src}" alt="">
<span>${v.shuliang || v.total}</span>
</div>
<div class="list_title ellipsis">${v.title}</div>
<div class="list_model ellipsis">模特: ${v.user || v.renwulist[0].name}</div>
<div class="list_source ellipsis">${v.source || '来源机构:'+v.jigoulist[0].name}</div>
</a>
<div class="list_tags">
${
(v.tags || v.biaoqianlist).map(item=>{
return `<div class="list_tags_item">${item.title || item.name}</div>`
}).toString().replaceAll(",", "")
}
</div>
</div>
`
})
}
header(title = "",rightHtml = "") {
$("body").innerHTML += `
<div class="pub_header">
<div class="left">
<i class="iconfont icon-back1"></i>
<span class="ellipsis">${title}</span>
</div>
${rightHtml}
</div>
`
$(".icon-back1").onclick = () => {
history.back();
}
}
}
var { $, _, footer, item, header, query } = new Utils();

View File

@@ -0,0 +1,11 @@
window.onload = function () {
getRem(750, 100)
};
window.onresize = function () {
getRem(750, 100)
};
function getRem(pwidth, prem) {
var html = document.getElementsByTagName("html")[0];
var oWidth = document.body.clientWidth || document.documentElement.clientWidth;
html.style.fontSize = oWidth / pwidth * prem + "px";
}