Files
doc-mini-app/pages/index/index.js
2024-08-29 00:30:49 +08:00

149 lines
4.0 KiB
JavaScript

// index.js
const request = require('../../utils/request')
const ui = require('../../utils/ui')
Page({
data: {
codes: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
codes_current_page: 1,
codes_has_prev: false,
codes_has_next: false,
codes_total_count: 0,
codes_total_pages: 0,
categorys: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
//获取接口数据
let that = this;
that.GetCodes()
that.GetIndexList()
that.GetLabelList()
},
GetLabelList() {
let that = this;
request.request({
method: "GET",
// https://app.19year.cn/api.php/doc/details?id=51
url: "/api.php/doc/label_list"
}).then(res => {
if (res.data.code === 1) {
let list = res.data.data.data
for(let j = 0, len=list.length; j < len; j++) {
that.setData({[`${list[j].name}`]:list[j].value})
}
// that.initContent()
}
}).catch(err => {
console.log('ERROR', err)
});
},
GetIndexList() {
let that = this;
request.request({
method: "GET",
url: "/api.php/doc/index_category"
}).then(res => {
if (res.data.code === 1) {
console.log(res.data.data);
that.setData({
categorys: res.data.data.data
})
}
// ui.showToast(res.data.errorMsg)
}).catch(err => {
console.log('ERROR')
});
},
codesPrev() {
let that = this;
console.log(that.data.codes_has_prev);
if (that.data.codes_has_prev) {
console.log("shang");
that.setData({
codes_current_page: that.data.codes_current_page - 1
})
that.GetCodes()
console.log("shang");
}
},
codesNext() {
let that = this;
if (that.data.codes_has_next) {
that.setData({
codes_current_page: that.data.codes_current_page + 1
})
that.GetCodes()
console.log("xia");
}
},
GetCodes() {
let that = this;
request.request({
method: "GET",
url: "/api.php/doc/index_codes?page=" + that.data.codes_current_page + "&pageSize=16"
}).then(res => {
if (res.data.code === 1) {
that.setData({
codes: res.data.data.data,
codes_current_page: res.data.data.current_page,
codes_has_next: res.data.data.has_next,
codes_has_prev: res.data.data.has_prev,
codes_total_count: res.data.data.total_count,
codes_total_pages: res.data.data.total_pages,
})
}
// ui.showToast(res.data.errorMsg)
}).catch(err => {
console.log('ERROR')
});
},
// 页面跳转
jumpPage(e) {
let jumpType = e.currentTarget.dataset.jumptype;
// 文章id
let aid = e.currentTarget.dataset.aid;
// 类目id
let cid = e.currentTarget.dataset.cid;
console.log(jumpType == 1);
console.log(aid);
console.log(cid);
// 类目
if (jumpType == 1 && cid) {
wx.navigateTo({
url: "/pages/list/list?cid=" + cid
})
}
if (jumpType == 2 && aid) {
wx.navigateTo({
url: "/pages/details/details?aid=" + aid
})
}
// 搜索页面
if (jumpType == 3) {
wx.navigateTo({
url: "/pages/search/index"
})
}
// 搜索页面
if (jumpType == 4) {
wx.navigateTo({
url: "/pages/about/about"
})
}
},
bindFocus(e) {
console.log(e);
}
})