Commit 4c88717c by TengFengLian

对接首页相关接口

parent 59915b17
App({ App({
globalData: {
userInfo: null,
baseUrl: 'http://sm-web.meiqicloud.com',//测试
// baseUrl: 'https://zmj.zhengmao.net',//生产
debug: true,
},
onLaunch: function () { onLaunch: function () {
this.setUnitProportion() this.setUnitProportion()
// 登录
this.login()
}, },
onShow: function (options) { onShow: function (options) {
...@@ -15,12 +25,91 @@ App({ ...@@ -15,12 +25,91 @@ App({
}, },
globalData: {
},
setUnitProportion: function () { setUnitProportion: function () {
let funcProportion = wx.getSystemInfoSync().windowWidth / 750 let funcProportion = wx.getSystemInfoSync().windowWidth / 750
wx.setStorageSync('unitProportion', funcProportion) wx.setStorageSync('unitProportion', funcProportion)
}, },
wxRequest(obj) {
let that = this
var token = wx.getStorageSync('token')
var param = obj.data ? JSON.stringify(obj.data) : ""
wx.request({
url: that.globalData.baseUrl + obj.url,
data: param,
method: obj.method || "POST",
header: {
'token': token || '',
},
success: function (res) {
console.log("接口:", that.globalData.baseUrl + obj.url);
console.log("参数:", JSON.stringify(obj.data));
console.log("返回:", res);
let code = res.data.code * 1;
if (200 == code) {
if (obj.success) {
obj.success(res.data)
}
} else {
if (obj.fail) {
let err = {
statusCode: code,
msg: res.data.msg || '网络异常'
};
obj.fail(err)
}
}
},
fail: function (err) {
console.log("接口:", that.globalData.baseUrl + obj.url);
console.log("参数:", obj.data);
console.log("返回:", err);
if (obj.fail) {
let err = {
statusCode: 9999,
msg: '网络异常'
};
obj.fail(err)
} else {
wx.showToast({
title: '网络异常',
icon: 'none',
duration: 2000
})
}
}
});
},
login(obj) {
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
console.log('wx.login:', res);
var token = wx.getStorageSync('token')
if (!token) {
this.wxRequest({
url: '/api/v1/login/getSmallSession?code='+res.code,
method: 'GET',
success: function (res) {
wx.setStorageSync('expires_in', res.data.expires_in)
wx.setStorageSync('openid', res.data.openid)
wx.setStorageSync('refreshToken', res.data.refreshToken)
wx.setStorageSync('session_key', res.data.session_key)
wx.setStorageSync('token', res.data.token)
},
fail: function (err) {
}
})
}
}
})
}
}) })
import iUtils from '../../utils/utils.js' import iUtils from '../../utils/utils.js'
const app = getApp()
let logicData = { let logicData = {
pageScrollLock: false, pageScrollLock: false,
pageScrollTimer: 0, pageScrollTimer: 0,
...@@ -21,16 +23,28 @@ Page({ ...@@ -21,16 +23,28 @@ Page({
notice: [], notice: [],
// strategy 列表数据 // strategy 列表数据
strategyFirstItem: {
id: '1',
index: 0,
image: 'https://image-1256588539.cos.ap-shanghai.myqcloud.com/miniapp/home/strategy/strategy-00.jpg',
title: '凉爽一夏,在银湖湾听海踏浪',
date: '2020-07-10'
},
strategy: [], strategy: [],
strategyList: [], strategyList: [],
//接口参数
pageNo: 1,
pageSize: 10,
}, },
onLoad: function (options) { onLoad: function (options) {
this.queryBanner() this.queryBanner()
this.queryStrategy() // this.queryStrategy()
this.setNavigationLogo() this.setNavigationLogo()
// 游客攻略瀑布列表
wx.lin.renderWaterFlow(this.data.strategyList, false, () => {}) //
this.loadVisiterPlanList()
}, },
/** /**
...@@ -98,6 +112,8 @@ Page({ ...@@ -98,6 +112,8 @@ Page({
this.setData({ this.setData({
strategyList: response strategyList: response
}) })
// 游客攻略瀑布列表
wx.lin.renderWaterFlow(this.data.strategyList, false, () => {})
}, },
/** /**
...@@ -152,6 +168,11 @@ Page({ ...@@ -152,6 +168,11 @@ Page({
* @param {object} - funcItem * @param {object} - funcItem
* @returns * @returns
*/ */
onFirstStrategyDetail: function () {
wx.navigateTo({
url: '/pages/strategy/strategy?id=' + this.data.strategyFirstItem.id
})
},
onStrategyDetail: function (funcItem) { onStrategyDetail: function (funcItem) {
wx.navigateTo({ wx.navigateTo({
url: '/pages/strategy/strategy?id=' + funcItem.detail.item.id url: '/pages/strategy/strategy?id=' + funcItem.detail.item.id
...@@ -195,4 +216,56 @@ Page({ ...@@ -195,4 +216,56 @@ Page({
clearTimeout(logicData.pageScrollTimer) clearTimeout(logicData.pageScrollTimer)
}, 40) }, 40)
}, },
// 游客攻略列表
loadVisiterPlanList() {
var that = this
app.wxRequest({
url: '/api/v1/strategy/getList',
data: { pageSize: that.data.pageSize, pageNo: that.data.pageNo},
success: function (res) {
if (res.data.list.length > 0) {
let tempArray = []
res.data.list.forEach(item => {
let strategy = {
id: item.id,
image: item.cover,
title: item.title,
date: item.updateDate,
}
tempArray.push(strategy)
})
console.log('tempArray', tempArray)
if (that.data.pageNo == 1) {
var newArr = tempArray.slice(1)
var firstItem = tempArray[0]
console.log('firstItem', firstItem)
that.setData({
['strategyFirstItem.id']: firstItem.id,
['strategyFirstItem.image']: firstItem.image,
['strategyFirstItem.title']: firstItem.title,
['strategyFirstItem.date']: firstItem.date,
strategyList: newArr
})
} else {
that.setData({
strategyList: that.data.strategyList.concat(tempArray)
})
}
// 游客攻略瀑布列表
wx.lin.renderWaterFlow(that.data.strategyList, false, () => {})
} else {
}
}
})
},
}) })
\ No newline at end of file
...@@ -78,12 +78,12 @@ ...@@ -78,12 +78,12 @@
</view> </view>
<!-- 游客攻略 --> <!-- 游客攻略 -->
<view class="strategy detail-item"> <view class="strategy detail-item" bindtap="onFirstStrategyDetail">
<image src="./image/title-strategy.png"></image> <image src="./image/title-strategy.png"></image>
<view class="strategy-content"> <view class="strategy-content">
<image class="background-image" src="https://image-1256588539.cos.ap-shanghai.myqcloud.com/miniapp/home/strategy/strategy-00.jpg" mode="aspectFit"></image> <image class="background-image" src="{{strategyFirstItem.image}}" mode="aspectFit"></image>
<view class="operation col"> <view class="operation col">
<text>凉爽一夏,在银湖湾听海踏浪</text> <text>{{strategyFirstItem.title}}</text>
</view> </view>
</view> </view>
</view> </view>
......
const app = getApp()
Page({ Page({
data: { data: {
notice: {} notice: {},
// 接口参数
id: '',
}, },
onLoad: function (options) { onLoad: function (options) {
this.queryNotice() // this.queryNotice()
console.log(options)
this.setData({
id: options.id
})
this.getNoticeDetail()
}, },
queryNotice: function () { queryNotice: function () {
...@@ -22,5 +31,28 @@ Page({ ...@@ -22,5 +31,28 @@ Page({
this.setData({ this.setData({
notice: response notice: response
}) })
},
// 最新动态详情
getNoticeDetail() {
var that = this
app.wxRequest({
url: '/api/v1/dynamic/getDetail',
data: { id: that.data.id },
success: function (res) {
var content = res.data.content.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block" ')
.replace(/<section/g, '<div')
.replace(/\/section>/g, '\div>');
var response = {
cover: res.data.imgs.length > 0 ? res.data.imgs[0] : '',
title: res.data.title,
date: res.data.releaseTime,
describe: content,
}
that.setData({
notice: response
})
}
})
} }
}) })
\ No newline at end of file
...@@ -12,10 +12,11 @@ ...@@ -12,10 +12,11 @@
<image src="{{notice.cover}}" mode="center"></image> <image src="{{notice.cover}}" mode="center"></image>
</view> </view>
<view class="describe"> <view class="describe">
<block wx:for="{{notice.describe}}" wx:for-index="index" wx:for-item="item" wx:key="index"> <rich-text nodes="{{notice.describe}}"></rich-text>
<!-- <block wx:for="{{notice.describe}}" wx:for-index="index" wx:for-item="item" wx:key="index">
<view> <view>
<text>{{item}}</text> <text>{{item}}</text>
</view> </view>
</block> </block> -->
</view> </view>
</view> </view>
\ No newline at end of file
import iMiment from '../../npm/miment.js' import iMiment from '../../npm/miment.js'
const app = getApp()
Page({ Page({
data: { data: {
notice: [] notice: [],
// 接口参数
pageSize: 10,
pageNo: 1,
}, },
onLoad: function () { onLoad: function () {
this.queryNotice() // this.queryNotice()
this.getNoticeList()
}, },
queryNotice: function () { queryNotice: function () {
...@@ -38,7 +44,35 @@ Page({ ...@@ -38,7 +44,35 @@ Page({
onNoticeDetail: function (funcItem) { onNoticeDetail: function (funcItem) {
console.log(funcItem) console.log(funcItem)
wx.navigateTo({ wx.navigateTo({
url: '/pages/notice-detail/notice-detail' url: '/pages/notice-detail/notice-detail?id='+funcItem.currentTarget.dataset.id
})
},
// 最新动态列表
getNoticeList() {
var that = this
app.wxRequest({
url: '/api/v1/dynamic/getList',
data: { pageSize: that.data.pageSize, pageNo: that.data.pageNo},
success: function (res) {
var tmpArr = [];
res.data.list.forEach(item => {
var content = item.content.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block" ')
.replace(/<section/g, '<div')
.replace(/\/section>/g, '\div>');
var tmpItem = {
id: item.id,
cover: item.imgs.length > 0 ? item.imgs[0] : '',
title: item.title,
date: item.releaseTime,
describe: content,
}
tmpArr.push(tmpItem)
})
that.setData({
notice: tmpArr
})
}
}) })
} }
}) })
\ No newline at end of file
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
<text>{{item.date}}</text> <text>{{item.date}}</text>
</view> </view>
<view class="notice-describe"> <view class="notice-describe">
<text>{{item.describe}}</text> <rich-text nodes="{{item.describe}}"></rich-text>
<!-- <text>{{item.describe}}</text> -->
</view> </view>
<view class="notice-cover" wx:if="{{item.cover !== ''}}"> <view class="notice-cover" wx:if="{{item.cover !== ''}}">
<image src="{{item.cover}}" mode="center"></image> <image src="{{item.cover}}" mode="center"></image>
......
...@@ -3,6 +3,8 @@ let logicData = { ...@@ -3,6 +3,8 @@ let logicData = {
pageScrollTimer: 0, pageScrollTimer: 0,
} }
const app = getApp()
Page({ Page({
data: { data: {
testData: [ testData: [
...@@ -47,15 +49,25 @@ Page({ ...@@ -47,15 +49,25 @@ Page({
banner: [], banner: [],
bannerIndex: 0, bannerIndex: 0,
content: '', // 内容
detailImage: [], detailImage: [],
detailImageUrl: [], detailImageUrl: [],
detailIndex: 0, detailIndex: 0,
relation: [] relation: [],
//接口参数
id: '',
}, },
onLoad: function (options) { onLoad: function (options) {
console.log('onLoad', options) console.log('onLoad', options)
this.setInitData(Number(options.id) - 1) // this.setInitData(Number(options.id) - 1)
this.setData({
id: options.id,
})
this.loadStrategyDetail()
}, },
setInitData: function (funcIndex) { setInitData: function (funcIndex) {
...@@ -104,4 +116,64 @@ Page({ ...@@ -104,4 +116,64 @@ Page({
clearTimeout(logicData.pageScrollTimer) clearTimeout(logicData.pageScrollTimer)
}, 40) }, 40)
}, },
// 攻略详情
loadStrategyDetail() {
var that = this
app.wxRequest({
url: '/api/v1/strategy/getDetail',
data: { id: that.data.id },
success: function(res) {
/**
* 此代码段处理目的为,匹配富文本代码中的 <img> 标签,并将其图片的宽度修改为适应屏幕
* max-width:100% --- 图片宽度加以限制,避免超出屏幕
* height:auto --- 高度自适应
* display:block --- 此代码,可以去掉图片之间的空白间隔,个人觉得好用
*/
var content = res.data.content.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block" ')
.replace(/<section/g, '<div')
.replace(/\/section>/g, '\div>');
that.setData({
banner: res.data.banners,
content: content,
})
that.getParksByParkIds(res.data.smParkIds)
},
})
},
// 攻略详情文中提及
getParksByParkIds(parkIds) {
if (!parkIds) {
return
}
var that = this
app.wxRequest({
url: '/api/v1/park/getParksByParkIds',
data: { smParkIds: parkIds },
success: function(res) {
var tmpArr = [];
res.data.forEach(item => {
var tmpItem = {
'id': item.id,
'cover': item.guideImg,
'title': item.name,
'time': '营业时间 ' + item.businessTime,
'price': item.chargeStandard,
'describe': '',
}
tmpArr.push(tmpItem)
})
that.setData({
relation: tmpArr
})
}
})
}
}) })
\ No newline at end of file
...@@ -24,11 +24,12 @@ ...@@ -24,11 +24,12 @@
</view> </view>
<view class="detail"> <view class="detail">
<block wx:for="{{detailImageUrl}}" wx:for-index="index" wx:for-item="item" wx:key="index"> <!-- <block wx:for="{{detailImageUrl}}" wx:for-index="index" wx:for-item="item" wx:key="index">
<image mode="widthFix" src="{{item}}"></image> <image mode="widthFix" src="{{item}}"></image>
</block> </block> -->
<rich-text nodes="{{content}}"></rich-text>
<view class="relation"> <view class="relation" wx:if="{{relation.length>0}}">
<view class="relation-title"> <view class="relation-title">
<text>文中提及</text> <text>文中提及</text>
</view> </view>
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
.detail { .detail {
width: 750rpx; width: 750rpx;
padding: 6px;
} }
.detail > image { .detail > image {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment