新增专区,调整分页bug

This commit is contained in:
2024-09-05 14:05:14 +08:00
parent b990456593
commit 9a6c4d30f4
24 changed files with 448 additions and 9 deletions

View File

@@ -0,0 +1,59 @@
import { getEncyclopediaList } from "../../../../service/system";
import { alertInfo, alertSuccess, loadingFunc, wxLogin } from "../../../../utils/index";
import request from "../../../../utils/request"
const { OK } = request;
// pages/encyclopedia/components/item/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
id: String
},
/**
* 组件的初始数据
*/
data: {
page: 1,
list: [],
},
lifetimes: {
attached() {
console.log('----------=========')
this.getData();
}
},
/**
* 组件的方法列表
*/
methods: {
async getData() {
console.log(this.data.page, this.data.id, this.id)
const page = this.data.page;
const id = this.id;
const { code, data, message, total } = await getEncyclopediaList(id, page);
if (code !== OK) {
alertInfo(message)
return;
}
this.setData({ list: data, totalPage: Math.ceil(total / 20) });
},
jumpToDetail(e) {
console.log('e', e)
wx.navigateTo({
url: `/pages/encyclopediaDetail/index?id=${e.currentTarget.dataset.data.id}`,
})
},
async onChangePage(e) {
const page = e.detail.currentIndex;
const that = this;
this.setData({
page
}, () => {
that.getData();
})
},
}
})

View File

@@ -0,0 +1,9 @@
{
"component": true,
"usingComponents": {
"pagination": "/components/pagination/index",
"navigator": "/components/navigator/index",
"van-field": "@vant/weapp/field/index"
},
"navigationStyle": "custom"
}

View File

@@ -0,0 +1,15 @@
<!--pages/encyclopedia/components/item/index.wxml-->
<van-field
wx:for="{{list}}"
value="{{ item.title }}"
readonly
border="{{ true }}"
wx:key="id"
bind:tap="jumpToDetail"
data-data="{{item}}"
/>
<pagination
currentIndex="{{page}}"
totalPage="{{totalPage}}"
bind:pagingChange="onChangePage"
/>

View File

@@ -0,0 +1 @@
/* pages/encyclopedia/components/item/index.wxss */

View File

@@ -0,0 +1,87 @@
// pages/encyclopedia/index.js
import { getCategoryList } from '../../service/system'
import { alertInfo, alertSuccess, loadingFunc, wxLogin } from "../../utils/index";
import request from "../../utils/request"
const { OK } = request;
Page({
/**
* 页面的初始数据
*/
data: {
categoryList: [],
active: 0,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.init();
},
async init() {
const { data, code, message } = await getCategoryList();
if (code !== OK) {
alertInfo(message);
return
}
this.setData({
categoryList: data
})
},
onChange(e) {
console.log('e', e)
this.setData({
active: e.detail.index,
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

View File

@@ -0,0 +1,9 @@
{
"usingComponents": {
"navigator": "/components/navigator/index",
"van-tab": "@vant/weapp/tab/index",
"van-tabs": "@vant/weapp/tabs/index",
"item": "./components/item/index"
},
"navigationStyle": "custom"
}

View File

@@ -0,0 +1,7 @@
<!--pages/encyclopedia/index.wxml-->
<navigator title="电力百科" canBack="{{true}}" />
<van-tabs active="{{ active }}" bind:change="onChange">
<van-tab wx:for="{{categoryList}}" wx:key="id" title="{{item.name}}">
<item id="{{item.id}}" wx:if="{{index === active}}" />
</van-tab>
</van-tabs>

View File

@@ -0,0 +1 @@
/* pages/encyclopedia/index.wxss */