106 lines
2.3 KiB
JavaScript
106 lines
2.3 KiB
JavaScript
import R from '../../utils/request';
|
|
import C from '../../utils/constant';
|
|
Page({
|
|
data: {
|
|
cdnHost: C.cdnHost,
|
|
loadFlag: false,
|
|
swiperList: [],
|
|
list: [],
|
|
},
|
|
|
|
onShow() {
|
|
this.getTabBar().init();
|
|
// this.init();
|
|
this.fetchBanner();
|
|
},
|
|
|
|
onLoad() {
|
|
R.login().then(() => {
|
|
this.init();
|
|
})
|
|
},
|
|
fetchBanner() {
|
|
R.get('/index.php/api/v1/banner_list', {}).then(({ model }) => {
|
|
const swiperList = [];
|
|
model.forEach(item => {
|
|
swiperList.push({
|
|
...item,
|
|
value: C.cdnHost + item.img,
|
|
ariaLabel: item.title,
|
|
id: item.id,
|
|
});
|
|
});
|
|
if (JSON.stringify(swiperList) != JSON.stringify(this.data.swiperList)) {
|
|
this.setData({ swiperList });
|
|
}
|
|
});
|
|
},
|
|
init() {
|
|
if (this.data.loadFlag) return;
|
|
this.data.loadFlag = false;
|
|
this.fetchList(1);
|
|
this.fetchBanner();
|
|
},
|
|
fetchList(page) {
|
|
R.get('/index.php/api/v1/news_list', { page, pageSize: 5 }).then(({ model }) => {
|
|
const list = [];
|
|
model.forEach(item => {
|
|
list.push({
|
|
...item,
|
|
});
|
|
});
|
|
this.setData({ list });
|
|
});
|
|
},
|
|
goDetail(e) {
|
|
const { id } = e.currentTarget.dataset;
|
|
wx.navigateTo({
|
|
url: `/pages/detail/detail?id=${id}`
|
|
});
|
|
},
|
|
onSwiperTap(e) {
|
|
const { index } = e.detail;
|
|
this.data.swiperList.forEach((o, i) => {
|
|
if (i == index) {
|
|
console.log(o)
|
|
if(o.action_type == 'newsId'){
|
|
wx.navigateTo({
|
|
url: '/pages/detail/detail?id=' + o.action_item,
|
|
});
|
|
}
|
|
if(o.action_type == 'url'){
|
|
wx.navigateTo({
|
|
url: '/pages/webview/webview?url=' + encodeURIComponent(o.action_item),
|
|
});
|
|
}
|
|
if(o.action_type == 'path'){
|
|
wx.navigateTo({
|
|
url: o.action_item,
|
|
});
|
|
}
|
|
}
|
|
})
|
|
},
|
|
goUrl(e) {
|
|
const { url } = e.currentTarget.dataset;
|
|
wx.navigateTo({
|
|
url
|
|
});
|
|
},
|
|
goMore() {
|
|
wx.navigateTo({
|
|
url: '/pages/news_list/home'
|
|
});
|
|
},
|
|
refresh() {
|
|
this.fetchList(1);
|
|
this.fetchBanner();
|
|
wx.showToast({ icon: 'none', title: '刷新成功' });
|
|
},
|
|
onPullDownRefresh() {
|
|
this.init();
|
|
wx.stopPullDownRefresh();
|
|
},
|
|
onShareAppMessage() { },
|
|
onShareTimeline() { },
|
|
});
|