Commit 391cecd1 authored by jyx's avatar jyx

代码优化

parent 75db8e75
<template> <template>
<view> <z-paging style="height: 100%;">
<c-navi id='navi'></c-navi> <c-navi id='navi'></c-navi>
<book-search-box id='search' :searchType='searchType'></book-search-box> <book-search-box id='search' :searchType='searchType'></book-search-box>
<read-time-count-row id='count' ref='timeCount' @resize='resizeTimeCount'></read-time-count-row> <read-time-count-row id='count' ref='timeCount' @resize='resizeTimeCount'></read-time-count-row>
<BookshelfList ref='bookList' :height='listHeight'></BookshelfList> <BookshelfList ref='bookList' :height='listHeight'></BookshelfList>
<c-login></c-login> <c-login></c-login>
</view> </z-paging>
</template> </template>
<script> <script>
import BookshelfList from "./components/bookshelf-list.vue"; import BookshelfList from "./components/bookshelf-list.vue";
import SystemInfoMixin from "../../common/mixins/system-info-mixin.js" import SystemInfoMixin from "../../common/mixins/system-info-mixin.js"
import { import {
watchUserInfoChange, watchUserInfoChange,
removeUserInfoChangeWatch removeUserInfoChangeWatch
} from "../../common/services/userServices.js"; } from "../../common/services/userServices.js";
import { import {
ENUM_SEARCH_TYPE ENUM_SEARCH_TYPE
} from "../../static/enums/enum_value"; } from "../../static/enums/enum_value";
import { import {
removeCollectionChangeWatch, removeCollectionChangeWatch,
watchCollectionChange watchCollectionChange
} from "../../common/services"; } from "../../common/services";
export default { export default {
mixins: [SystemInfoMixin], mixins: [SystemInfoMixin],
components: { components: {
BookshelfList BookshelfList
}, },
data() { data() {
return { return {
searchType: ENUM_SEARCH_TYPE.BOOKSHELF, searchType: ENUM_SEARCH_TYPE.BOOKSHELF,
listHeight: 0 listHeight: 0
}; };
}, },
onReady() { onReady() {
this.initHeight();
// 监听用户变动
watchUserInfoChange((info) => {
if (info.userInfo) {
this.initData();
}
}, this)
// 监听收藏变动
watchCollectionChange(() => {
this.refreshList();
}, this);
},
onShow() {
// 更新阅读时间统计
this.refreshTimeCount();
},
onUnload() {
// 移除监听
removeUserInfoChangeWatch(this);
removeCollectionChangeWatch(this);
},
methods: {
show() {
this.initHeight(); this.initHeight();
// 监听用户变动 // 监听用户变动
watchUserInfoChange((info) => { watchUserInfoChange((info) => {
...@@ -45,66 +68,53 @@ ...@@ -45,66 +68,53 @@
watchCollectionChange(() => { watchCollectionChange(() => {
this.refreshList(); this.refreshList();
}, this); }, this);
},
show(){
},
hide(){
},
onShow() {
// 更新阅读时间统计
this.refreshTimeCount();
},
onUnload() {
// 移除监听
removeUserInfoChangeWatch(this);
removeCollectionChangeWatch(this);
},
methods: {
resizeTimeCount() {
this.initHeight();
},
initData() {
this.refreshList();
},
// 初始化刷新
initRefresh() {
let ref = this.$refs.bookList;
if (ref) {
ref.initRefresh();
}
},
// 刷新数据列表
refreshList() {
let ref = this.$refs.bookList;
if (ref) {
ref.refreshList();
}
}, },
refreshTimeCount() { hide() {
let ref = this.$refs.timeCount;
if (ref) { },
ref.refresh(); resizeTimeCount() {
} this.initHeight();
}, },
initHeight() { initData() {
const query = uni.createSelectorQuery().in(this); this.refreshList();
query.select("#navi").boundingClientRect(); },
query.select("#search").boundingClientRect(); // 初始化刷新
query.select("#count").boundingClientRect(); initRefresh() {
query.exec((res) => { let ref = this.$refs.bookList;
let result = 0; if (ref) {
res.forEach(item => { ref.initRefresh();
result = result + item.height; }
}) },
this.listHeight = this.windowHeight - result; // 刷新数据列表
}) refreshList() {
}, let ref = this.$refs.bookList;
} if (ref) {
} ref.refreshList();
</script> }
},
<style lang="scss"> refreshTimeCount() {
let ref = this.$refs.timeCount;
if (ref) {
ref.refresh();
}
},
initHeight() {
const query = uni.createSelectorQuery().in(this);
query.select("#navi").boundingClientRect();
query.select("#search").boundingClientRect();
query.select("#count").boundingClientRect();
query.exec((res) => {
let result = 0;
res.forEach(item => {
result = result + item.height;
})
this.listHeight = this.windowHeight - result;
})
},
}
}
</script>
<style lang="scss">
</style> </style>
\ No newline at end of file
<template> <template>
<view> <z-paging style="height: 100%;">
<c-navi id='navi'></c-navi> <c-navi id='navi'></c-navi>
<book-search-box id='search'></book-search-box> <book-search-box id='search'></book-search-box>
<CategoryBar id='category' :range='categorys' :current='currentIndex' @change='changeCategory' <CategoryBar id='category' :range='categorys' :current='currentIndex' @change='changeCategory'
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
</swiper> </swiper>
</view> </view>
<c-login></c-login> <c-login></c-login>
</view> </z-paging>
</template> </template>
<script> <script>
...@@ -32,9 +32,9 @@ ...@@ -32,9 +32,9 @@
} from "./services/index.js" } from "./services/index.js"
import { import {
isEmpty isEmpty
} from "../../common/utils/util"; } from "../../common/utils/util";
import { import {
toastMessage toastMessage
} from "../../common/utils/toastUtil.js"; } from "../../common/utils/toastUtil.js";
export default { export default {
mixins: [SystemInfoMixin], mixins: [SystemInfoMixin],
...@@ -50,22 +50,7 @@ ...@@ -50,22 +50,7 @@
}; };
}, },
onLoad(options) { onLoad(options) {
setTimeout(() => {
// 匹配用户直接跳转小说
if (options.bookId != '' && options.bookId != undefined) {
gotoBookContentPage(options.bookId);
}
}, 800);
this.getCategoryData();
if(wx.setVisualEffectOnCapture){
wx.setVisualEffectOnCapture({
visualEffect: 'hidden',
success:(res) => {
},
})
}
}, },
computed: { computed: {
showEmpty: function() { showEmpty: function() {
...@@ -100,12 +85,27 @@ ...@@ -100,12 +85,27 @@
deep: true deep: true
} }
}, },
methods: { methods: {
show(){ show() {
setTimeout(() => {
}, // 匹配用户直接跳转小说
hide(){ if (options.bookId != '' && options.bookId != undefined) {
gotoBookContentPage(options.bookId);
}
}, 800);
this.getCategoryData();
if (wx.setVisualEffectOnCapture) {
wx.setVisualEffectOnCapture({
visualEffect: 'hidden',
success: (res) => {
},
})
}
},
hide() {
}, },
readyCategory() { readyCategory() {
setTimeout(() => { setTimeout(() => {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
@click="tabChange(0)"> @click="tabChange(0)">
<view style="margin: 16rpx 0 11rpx;"> <view style="margin: 16rpx 0 11rpx;">
<image v-if="currentPage==0" class="tabs-image" src="/static/tab/index_selected.png" <image v-if="currentPage==0" class="tabs-image" src="/static/tab/index_selected.png"
mode="heightFix"> mode="heightFix">
</image> </image>
<image v-else class="tabs-image" src="/static/tab/index_unselected.png" mode="heightFix"></image> <image v-else class="tabs-image" src="/static/tab/index_unselected.png" mode="heightFix"></image>
</view> </view>
...@@ -67,8 +67,8 @@ ...@@ -67,8 +67,8 @@
let index = options.index ?? '' let index = options.index ?? ''
if (index != '' && index != undefined) { if (index != '' && index != undefined) {
this.currentPage = index this.currentPage = index
} }
}, },
onShow() { onShow() {
try { try {
...@@ -97,15 +97,9 @@ ...@@ -97,15 +97,9 @@
loadComponentData() { loadComponentData() {
if (this.currentPage == 0) { if (this.currentPage == 0) {
this.$refs.index.show(); this.$refs.index.show();
this.$refs.recommend.hide();
this.$refs.user.hide();
} else if (this.currentPage == 1) { } else if (this.currentPage == 1) {
this.$refs.index.hide();
this.$refs.recommend.show(); this.$refs.recommend.show();
this.$refs.user.hide();
} else if (this.currentPage == 2) { } else if (this.currentPage == 2) {
this.$refs.index.hide();
this.$refs.recommend.hide();
this.$refs.user.show(); this.$refs.user.show();
} }
} }
...@@ -115,7 +109,7 @@ ...@@ -115,7 +109,7 @@
<style lang="scss"> <style lang="scss">
.body { .body {
height: 100%; height: 100%;
background-color: white; background-color: white;
} }
</style> </style>
\ No newline at end of file
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