Skip to content

Commit

Permalink
api 详情页接入
Browse files Browse the repository at this point in the history
  • Loading branch information
richard1015 committed Jun 25, 2018
1 parent da14b5c commit a2d9f13
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 35 deletions.
132 changes: 117 additions & 15 deletions pages/content/content.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,97 @@
// pages/content/content.js
var apiHelper = require("../../utils/api.js");
Page({

/**
* 页面的初始数据
*/
data: {
imgUrls: [
'1', '2', '3', '4'
],
animation: ''
},
toPage: function () {
wx.navigateTo({ //保留当前页面,跳转到应用内的某个页面(最多打开5个页面,之后按钮就没有响应的)
url: `/pages/contentDetails/contentDetails?id=1`
newsArray: [],
animation: '',
shareId: 0,
swiperIndex: 0,
previousMargin: 35,//swiper 前边距,可用于露出前一项的一小部分,接受 px 和 rpx 值
nextMargin: 35,//swiper 后边距,可用于露出后一项的一小部分,接受 px 和 rpx 值
isBusy: false,//是否正在请求数据中
backButton: false,// 返回首页 按钮显示状态,识别二维码进入显示 ,否则不显示
currentPageIndex: 1,//当前请求全局页数
currentDateIsNoData: true,//当前天是否还有数据
},
toPage: function (event) {
wx.navigateTo({
url: `/pages/contentDetails/contentDetails?id=${event.target.id}`
})
},
toPageIndex: function (event) {
wx.redirectTo({
url: '/pages/index/index',
})
},
loadData: function () {
if (!this.data.isBusy) {
//查看当天是否还有数据
if (this.data.currentDateIsNoData) {
this.data.currentPageIndex = this.data.newsArray[this.data.newsArray.length - 1].order;
this.getListNew(this.data.currentPageIndex);
}
}
},

swiperChange: function (event) {
console.log(event);
if (event.detail.current == this.data.newsArray.length - 1) {
this.loadData();
}
},
/* new */
getListNew(pageIndex, pageSize = 10) {
this.data.isBusy = true;
var self = this;
apiHelper.paramData.cmd = "news"; //cmd
apiHelper.paramData.loadingState = false;
apiHelper.paramData.param = {
pageIndex,
pageSize
};
apiHelper.post((res) => {
if (res.State == 0) {
res.Value = res.Value.data;
if (res.Value.length == 0) {
//标识数据已被全部请求完
self.data.currentDateIsNoData = false;
} else {
self.data.newsArray = self.data.newsArray.concat(res.Value);
//数据 剩余条数不超过请求条数,说明下一页已没有数据
if (res.Value.length < pageSize) {
//标识数据已被全部请求完
self.data.currentDateIsNoData = false;
} else {
self.data.currentDateIsNoData = true;
}
}
}
self.setData({
newsArray: self.data.newsArray
});
this.data.isBusy = false;
},'get');
},
nothing: function () { },
/**
* 保存分享事件
*/
saveShare: function () {
console.log('save share event !')
saveShare: function (event) {
console.log('save share event !' + this.data.shareId)
this.cancelShare();
wx.navigateTo({ //保留当前页面,跳转到应用内的某个页面(最多打开5个页面,之后按钮就没有响应的)
url: `/pages/contentShare/contentShare?id=1`
wx.navigateTo({
url: `/pages/contentShare/contentShare?id=${this.data.shareId}`
})
},
/**
* 分享事件
*/
share: function () {
share: function (event) {
this.data.shareId = event.target.id;
//弹出
this.animation.translate3d(0, 0, 0).step();
this.setData({
Expand All @@ -51,7 +113,46 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {

// options 中的 scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
if (options.scene) {
var scene = decodeURIComponent(options.scene)
options.id = scene;
this.setData({
backButton: true
});
}
var pages = getCurrentPages();
var currPage = pages[pages.length - 1]; //当前页面
var prevPage = pages[pages.length - 2]; //上一个页面
//判断入口
if (prevPage) {
//直接调用上一个页面的setData()方法,把数据存到上一个页面即编辑款项页面中去
let swiperIndex = prevPage.data.newsArray.findIndex(item => { return item.id == options.id });
this.setData({
swiperIndex: swiperIndex,
currentPageIndex: prevPage.data.currentPageIndex,
currentDateIsNoData: prevPage.data.currentDateIsNoData
});
this.setData({
newsArray: prevPage.data.newsArray //当前选择的好友名字赋值给编辑款项中的姓名临时变量
});
} else {
let id = options.id;
var self = this;
self.setData({ id });
apiHelper.paramData.cmd = "studyAbroadNews/getNewsDetail"; //cmd
apiHelper.paramData.param = {
id
};
apiHelper.post((res) => {
if (res.State == 0 && res.Value) {
self.setData({
newsArray: [res.Value] //当前选择的好友名字赋值给编辑款项中的姓名临时变量
});
self.loadData();
}
});
}
},

/**
Expand Down Expand Up @@ -96,10 +197,11 @@ Page({

},


/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
onShareAppMessage: function (res) {

}
})
25 changes: 13 additions & 12 deletions pages/content/content.wxml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<!--pages/content/content.wxml-->
<swiper next-margin="40rpx" indicator-dots="false" current='1'>
<block wx:for="{{imgUrls}}" wx:key="{{index}}">
<!--pages/content/content.wxml -->
<swiper previous-margin="{{previousMargin}}rpx" next-margin="{{nextMargin}}rpx" indicator-dots="{{false}}" bindchange="swiperChange" current='{{swiperIndex}}'>
<block wx:for="{{newsArray}}" wx:for-item="item" wx:key="{{index}}">
<swiper-item>
<view class="content">
<view class='content_header'>
</view>
<scroll-view scroll-y="true" class='content_view'>
<text class='title'>2018年QS排名最新出炉,悉尼大学的毕业生就业能力在全澳大利亚排名第1</text>
<view class='content_view'>
<text class='title'>{{item.title}}</text>
<view class='page-head-line'></view>
<view class='content_font'>2018年QS全球毕业生就业能力排名榜于近期公布,其中,悉尼大学发挥稳定,与去年排名同为第4,超过麻省理工、剑桥、牛津等国内大学生心中的梦想大学。而墨尔本大学紧随其后屈居第7,新南威尔士大学排名36,昆士兰大学排名49、悉尼科技大学排名69,美国斯坦福大学毫无意外地占据榜首。值得一提的是,在本次的榜单中,澳洲共有8所大学进入全球前100名,其国民教育水平可见一斑。 2018年QS全球毕业生就业能力排名榜于近期公布,其中,悉尼大学发挥稳定,与去年排名同为第4,超过麻省理工、剑桥、牛津等国单中,澳洲共有8所大学进入全球前100名,其国民教育水平可见一斑。
2018年QS全球毕业生就业能力排名榜于近期公布,其中,悉尼大学发挥稳定,与去年排名同为第4,超过麻省理工、剑桥、牛津等国
</view>
</scroll-view>
<view class='content_font'>{{item.summary}}</view>
</view>
<view class='content_foot'>
<view class='page-head-line'></view>
<button bindtap='toPage'>查看全文</button>
<image bindtap='share' mode="aspectFill" src='/imgs/share.png'></image>
<button bindtap='toPage' id="{{item.id}}">查看全文</button>
<button wx:if="{{backButton}}" class='back_index' bindtap='toPageIndex'>返回首页</button>
<view class='share-img' id="{{item.id}}" bindtap='share'>
<image mode="aspectFill" src='/imgs/share.png' id="{{item.id}}" bindtap='share'></image>
</view>
</view>
</view>
</swiper-item>
Expand All @@ -31,4 +32,4 @@
</button>
<button bindtap='cancelShare'>取消</button>
</view>
</view>
</view>
32 changes: 30 additions & 2 deletions pages/content/content.wxss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ swiper {
.content .content_view {
width: 100%;
height: 100%;
overflow-y: auto;
background: #fff;
border-radius: 6rpx;
padding: 0rpx 30rpx 0 30rpx;
Expand All @@ -43,7 +44,23 @@ swiper {
text-align: justify;
line-height: 60rpx;
display: block;
margin-top: 50rpx;
margin-top: 50rpx;
margin-bottom: 40rpx;
}

.content .content_view .title2 {
font-size: 30rpx;
color: #999;
text-align: justify;
overflow: hidden;
}

.content .content_view .title2 .left {
float: left;
}

.content .content_view .title2 .right {
float: right;
}

.content .content_view .content_font {
Expand Down Expand Up @@ -82,7 +99,7 @@ swiper {
position: fixed;
box-sizing: border-box;
background: #fff;
padding: 0 30rpx;
padding-left: 30rpx;
}

.content .content_foot .page-head-line {
Expand All @@ -107,6 +124,17 @@ swiper {
transform: translateY(-50%);
}

.content .content_foot button.back_index {
left: 230rpx;
}

.content .content_foot .share-img {
height: 100%;
width: 80rpx;
float: right;
padding-right: 30rpx;
}

.content .content_foot image {
height: 32rpx;
width: 32rpx;
Expand Down
7 changes: 1 addition & 6 deletions pages/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ Page({
newsArray: []//所有文章存放数组
},
toPage: function (event) {
// let array = this.data.array.map(item => { return item.array });
// for (let i = 0; i < array.length; i++)
// for (let j = 0; j < array[i].length; j++)
// this.data.newsArray.push(array[i][j])
//保留当前页面,跳转到应用内的某个页面(最多打开5个页面,之后按钮就没有响应的)
wx.navigateTo({
url: `/pages/content/content?id=${event.target.id}`
url: `/pages/content/content?id=${event.currentTarget.id}`
})
},
/**
Expand Down

0 comments on commit a2d9f13

Please sign in to comment.