Commit f35d8b1f authored by jyx's avatar jyx

代码优化

parent b3fa5c61
...@@ -54,6 +54,9 @@ ...@@ -54,6 +54,9 @@
this.refreshList(); this.refreshList();
} }
}, },
isEmpty() {
return isEmpty(this.dataList)
},
refreshList() { refreshList() {
this.$nextTick(() => { this.$nextTick(() => {
let ref = this.$refs.list; let ref = this.$refs.list;
......
...@@ -76,18 +76,20 @@ ...@@ -76,18 +76,20 @@
watch: { watch: {
categroyChange: { categroyChange: {
handler: function(n, o) { handler: function(n, o) {
setTimeout(() => { if (this.$refs[`bookList${n.currentIndex}`]) {
this.$refs[`bookList${n.currentIndex}`][0].initRefresh(); this.$refs[`bookList${n.currentIndex}`][0].initRefresh();
}, 300) }
}, },
deep: true deep: true
} }
}, },
methods: { methods: {
show() { show() {
if (this.$refs[`bookList${this.currentIndex}`][0].isEmpty()) {
this.$refs[`bookList${this.currentIndex}`][0].initRefresh();
}
}, },
hide() { hide() {},
},
readyCategory() { readyCategory() {
setTimeout(() => { setTimeout(() => {
this.initHeight() this.initHeight()
......
...@@ -135,26 +135,9 @@ ...@@ -135,26 +135,9 @@
if (info.userInfo) { if (info.userInfo) {
addReadRecord(this.bookId) addReadRecord(this.bookId)
} }
// this.showVipOpen = data.openVips
// // 用户变动,需要刷新数据
// this.$nextTick(() => {
// uni.startPullDownRefresh({})
// })
}, this) }, this)
// 用户变动,需要刷新数据
this.$nextTick(() => {
uni.startPullDownRefresh({})
})
// 绑定分享参数 this.refreshBookData(this.bookId)
// #ifdef MP-WEIXIN
wx.onCopyUrl(() => {
return {
query: `bookId=${this.bookData.id}`
}
})
// #endif
}, },
onShow() { onShow() {
refreshUserInfo(); refreshUserInfo();
...@@ -177,9 +160,6 @@ ...@@ -177,9 +160,6 @@
wx.offCopyUrl() wx.offCopyUrl()
// #endif // #endif
}, },
onPullDownRefresh() {
this.refreshBookData(this.bookId)
},
// 文章分享 // 文章分享
onShareAppMessage() { onShareAppMessage() {
let result = { let result = {
...@@ -255,16 +235,10 @@ ...@@ -255,16 +235,10 @@
}, },
// 文章数据刷新 // 文章数据刷新
refreshBookData(bookId) { refreshBookData(bookId) {
// getOpens((success, data) => {
// // this.showBeanOpen = data.openBeans
// this.showVipOpen = data.openVips
// })
getBookDetailData(bookId, (success, data) => { getBookDetailData(bookId, (success, data) => {
setTimeout(() => { setTimeout(() => {
uni.stopPullDownRefresh();
if (success) { if (success) {
this.bookData = new BookDetail(data); this.bookData = new BookDetail(data);
// console.log('bookData=' + JSON.stringify(this.bookData));
} }
}, 100) }, 100)
}) })
......
...@@ -121,16 +121,9 @@ ...@@ -121,16 +121,9 @@
if (this.isVip() && this.bookData) { if (this.isVip() && this.bookData) {
this.paySuccess() this.paySuccess()
} }
// // 用户变动,需要刷新数据
// this.$nextTick(() => {
// uni.startPullDownRefresh({})
// })
}, this) }, this)
this.$nextTick(() => { this.refreshBookData(this.bookId)
uni.startPullDownRefresh({})
})
let that = this let that = this
uni.getSystemInfo({ uni.getSystemInfo({
...@@ -153,14 +146,6 @@ ...@@ -153,14 +146,6 @@
endCountReadTime(); endCountReadTime();
// 移除监听 // 移除监听
removeUserInfoChangeWatch(this); removeUserInfoChangeWatch(this);
// 取消绑定分享参数
// #ifdef MP-WEIXIN
wx.offCopyUrl()
// #endif
},
onPullDownRefresh() {
this.refreshBookData(this.bookId)
}, },
// 文章分享 // 文章分享
onShareAppMessage() { onShareAppMessage() {
...@@ -205,14 +190,12 @@ ...@@ -205,14 +190,12 @@
this.$set(this.bookData, "isUnlock", 1); this.$set(this.bookData, "isUnlock", 1);
this.$set(this.bookData, "freeNum", this.bookData.articleChapterList.length); this.$set(this.bookData, "freeNum", this.bookData.articleChapterList.length);
this.$nextTick(() => {
this.$refs.content.reloadChapterinfoData() this.$refs.content.reloadChapterinfoData()
})
}, },
// 文章数据刷新 // 文章数据刷新
refreshBookData(bookId) { refreshBookData(bookId) {
// getOpens((success, data) => {
// this.showBeanOpen = data.openBeans
// this.showVipOpen = data.openVips
// })
getBookDetailData(bookId, (success, data) => { getBookDetailData(bookId, (success, data) => {
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
if (success) { if (success) {
...@@ -285,16 +268,19 @@ ...@@ -285,16 +268,19 @@
}, 300); }, 300);
} else { } else {
this.showVip = false; this.showVip = false;
if (this.bookData.isUnlock == 0) {
setTimeout(() => { setTimeout(() => {
this.showRecommend = true; this.showRecommend = true;
}, 300); }, 300);
} }
}
}, },
vipbackClose() { vipbackClose() {
this.showVip = false; this.showVip = false;
this.showVipbackPop = false; this.showVipbackPop = false;
this.paySuccess()
if (this.bookData.isUnlock == 0) { if (this.bookData.isUnlock == 0) {
setTimeout(() => { setTimeout(() => {
this.showRecommend = true; this.showRecommend = true;
...@@ -307,7 +293,9 @@ ...@@ -307,7 +293,9 @@
this.$set(this.bookData, "isUnlock", 1); this.$set(this.bookData, "isUnlock", 1);
this.$set(this.bookData, "freeNum", this.bookData.articleChapterList.length); this.$set(this.bookData, "freeNum", this.bookData.articleChapterList.length);
this.$nextTick(() => {
this.$refs.content.reloadChapterinfoData() this.$refs.content.reloadChapterinfoData()
})
} }
} }
} }
......
...@@ -122,12 +122,6 @@ ...@@ -122,12 +122,6 @@
this.page = this.step / (this.size - 1) * 100 this.page = this.step / (this.size - 1) * 100
}, },
deep: true deep: true
},
cata: {
handler(val, oldVal) {
this.page = this.step / (this.size - 1) * 100
},
deep: true
} }
}, },
destroyed() { destroyed() {
...@@ -186,6 +180,8 @@ ...@@ -186,6 +180,8 @@
let id = this.detail.articleChapterList[chapterId - 1].id let id = this.detail.articleChapterList[chapterId - 1].id
getChapterinfoData(this.detail.id, id, (success, data) => { getChapterinfoData(this.detail.id, id, (success, data) => {
if (success) { if (success) {
this.read = 0
this.step = 0
this.info.data = [{ this.info.data = [{
id: chapterId, id: chapterId,
sub: data.chapterId, sub: data.chapterId,
...@@ -201,7 +197,7 @@ ...@@ -201,7 +197,7 @@
getHeight(prev) { getHeight(prev) {
let _this = this let _this = this
setTimeout(function() { setTimeout(function() {
const query = uni.createSelectorQuery().in(_this); const query = _this.createSelectorQuery().in(_this);
query.select('#html .content').boundingClientRect(data => { query.select('#html .content').boundingClientRect(data => {
let _size = Math.ceil(data.height / _this.height) let _size = Math.ceil(data.height / _this.height)
_this.size = Math.ceil((data.height + _size * (_this.lineHeight * 2)) / _this.size = Math.ceil((data.height + _size * (_this.lineHeight * 2)) /
...@@ -213,7 +209,7 @@ ...@@ -213,7 +209,7 @@
_this.step = _this.size - 1 _this.step = _this.size - 1
} }
}).exec(); }).exec();
}, 300) }, 500)
}, },
prev() { prev() {
let _this = this let _this = this
......
...@@ -111,6 +111,11 @@ ...@@ -111,6 +111,11 @@
mounted() { mounted() {
// 渲染完成 初始化首页数据 // 渲染完成 初始化首页数据
this.loadComponentData(); this.loadComponentData();
let that = this
uni.$on('goWareHouse', function(data) {
that.tabChange(1)
})
}, },
methods: { methods: {
tabChange(index) { tabChange(index) {
......
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 to comment