|
@@ -8,6 +8,7 @@ Page({
|
|
* 页面的初始数据
|
|
* 页面的初始数据
|
|
*/
|
|
*/
|
|
data: {
|
|
data: {
|
|
|
|
+ bannerList:[], //轮播图列表
|
|
newNoticeTitle:'' //滚动显示的公告标题
|
|
newNoticeTitle:'' //滚动显示的公告标题
|
|
},
|
|
},
|
|
|
|
|
|
@@ -15,23 +16,31 @@ Page({
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
onLoad:async function(options) {
|
|
onLoad:async function(options) {
|
|
- let result = await request('/front/notificationFront') //获取公告列表
|
|
|
|
|
|
+ //获取轮播图列表
|
|
|
|
+ let banners = await request('/front/banner')
|
|
|
|
+ // console.log(banners);
|
|
|
|
+ this.setData({
|
|
|
|
+ bannerList:banners
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ //获取公告列表
|
|
|
|
+ let result = await request('/front/notificationFront')
|
|
// console.log(result);
|
|
// console.log(result);
|
|
// 对公告列表按id降序排序(即按发布时间由近到远排序)
|
|
// 对公告列表按id降序排序(即按发布时间由近到远排序)
|
|
- if(result.length == 0){
|
|
|
|
|
|
+ if(result.length == 0){ //如果公告列表长度为0,则显示无公告
|
|
this.setData({
|
|
this.setData({
|
|
newNoticeTitle:'暂无公告内容'
|
|
newNoticeTitle:'暂无公告内容'
|
|
})
|
|
})
|
|
- }else if(result.length == 1 && result[0].status == 1){
|
|
|
|
|
|
+ }else if(result.length == 1 && result[0].status == 1){ //如果有一条公告,且状态为1,则展示标题
|
|
this.setData({
|
|
this.setData({
|
|
newNoticeTitle:result[0].title
|
|
newNoticeTitle:result[0].title
|
|
})
|
|
})
|
|
- }else if(result.length == 1 && result[0].status == 0){
|
|
|
|
|
|
+ }else if(result.length == 1 && result[0].status == 0){ //如果有一条公告,且状态为0,则展示无公告
|
|
this.setData({
|
|
this.setData({
|
|
newNoticeTitle:'暂无公告内容'
|
|
newNoticeTitle:'暂无公告内容'
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- else{
|
|
|
|
|
|
+ else{ //超过2条公告时,根据公告id进行降序排序(即根据时间由近到远排序)
|
|
for(let i = 0;i < result.length-1;i++){
|
|
for(let i = 0;i < result.length-1;i++){
|
|
for(let j = 0;j < result.length-1-i;j++){
|
|
for(let j = 0;j < result.length-1-i;j++){
|
|
if(result[j].id < result[j+1].id){
|
|
if(result[j].id < result[j+1].id){
|
|
@@ -42,7 +51,7 @@ Page({
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// console.log(result);
|
|
// console.log(result);
|
|
- // 遍历重新排序后的列表,取出第一个状态为1的标题
|
|
|
|
|
|
+ // 遍历重新排序后的列表,取出第一个状态为1的标题,即为最新发布的公告
|
|
for(let i = 0;i < result.length;i++){
|
|
for(let i = 0;i < result.length;i++){
|
|
if(result[i].status == 1){
|
|
if(result[i].status == 1){
|
|
this.setData({
|
|
this.setData({
|