Commit 772c36dc authored by jyx's avatar jyx

代码优化

parent 64d49eb9
<template>
<view style="padding-top: 50rpx;">
<profile-header :userInfo='userInfo'></profile-header>
<CategoryBar id='category' :range='categorys' :current='currentIndex' @change='changeCategory'
@ready='readyCategory'></CategoryBar>
<view :style="[listStyle]" v-if='showEmpty'>
<c-empty emptyTitle="暂无数据"></c-empty>
</view>
<view :style="[listStyle]" v-else>
<swiper :style="[listStyle]" :indicator-dots="false" :autoplay="false" :current="currentIndex"
@change="changeSwiper">
<swiper-item v-for='(item, index) in categorys' :key='index'>
<WarehouseList ref='bookList' :category='item' :height='listHeight'></WarehouseList>
</swiper-item>
</swiper>
</view>
<c-login></c-login>
</view>
</template>
<script>
import ProfileHeader from "./components/profile-headertemp.vue";
import {
watchUserInfoChange,
refreshUserInfo
} from "../../common/services/userServices.js"
import CategoryBar from "./components/category-bar.vue";
import WarehouseList from "./components/warehouse-list.vue";
import SystemInfoMixin from "../../common/mixins/system-info-mixin.js";
import Category from "./models/Category.js";
import {
getCategorys
} from "./services/index.js"
import {
isEmpty
} from "../../common/utils/util";
import {
readStorage,
saveStorage
} from '../../common/utils/storageUtil';
export default {
mixins: [SystemInfoMixin],
components: {
CategoryBar,
ProfileHeader,
WarehouseList
},
data() {
return {
userInfo: null,
listHeight: 0,
categorys: [],
currentIndex: 0
};
},
onLoad() {
this.getCategoryData();
watchUserInfoChange((info) => {
this.userInfo = info.userInfo
}, this);
},
onShow() {
this.refreshUserData();
},
computed: {
showEmpty: function() {
return isEmpty(this.categorys);
},
listStyle: function() {
return {
height: `${this.listHeight}px`
}
},
categroyChange: function() {
const {
categorys,
currentIndex
} = this;
return {
categorys,
currentIndex
}
}
},
watch: {
categroyChange: {
handler: function(n, o) {
this.$nextTick(() => {
let ref = this.$refs.bookList;
if (ref) {
ref[n.currentIndex].initRefresh();
}
})
},
deep: true
}
},
methods: {
readyCategory() {
setTimeout(() => {
this.initHeight()
}, 300)
},
getCategoryData() {
getCategorys((success, data) => {
if (success) {
let result = data ? data.map(item => {
return new Category(item)
}).sort((a, b) => {
return a.sort - b.sort
}) : [];
result.unshift(new Category({
name: "全部",
id: ""
}))
this.categorys = result;
}
})
},
initHeight() {
const query = uni.createSelectorQuery().in(this);
// query.select("#navi").boundingClientRect();
// query.select("#search").boundingClientRect();
query.select("#category").boundingClientRect();
query.exec((res) => {
let result = 0;
res.forEach(item => {
result = result + item.height;
})
this.listHeight = this.windowHeight - result;
})
},
changeCategory(e) {
this.changeCurrent(e.index);
},
changeSwiper(e) {
this.changeCurrent(e.detail.current);
},
changeCurrent(index) {
if (index != this.currentIndex) {
this.currentIndex = index;
}
},
refreshUserData() {
if (this.userInfo) {
refreshUserInfo();
}
}
}
}
</script>
<style lang="scss">
.name {
font-size: 34rpx;
font-weight: 700;
}
<template>
<view style="padding-top: 50rpx;">
<profile-header :userInfo='userInfo'></profile-header>
<CategoryBar id='category' :range='categorys' :current='currentIndex' @change='changeCategory'
@ready='readyCategory'></CategoryBar>
<view :style="[listStyle]" v-if='showEmpty'>
<c-empty emptyTitle="暂无数据"></c-empty>
</view>
<view :style="[listStyle]" v-else>
<swiper :style="[listStyle]" :indicator-dots="false" :autoplay="false" :current="currentIndex"
@change="changeSwiper">
<swiper-item v-for='(item, index) in categorys' :key='index'>
<WarehouseList ref='bookList' :category='item' :height='listHeight'></WarehouseList>
</swiper-item>
</swiper>
</view>
<c-login></c-login>
</view>
</template>
<script>
import ProfileHeader from "./components/profile-headertemp.vue";
import {
watchUserInfoChange,
refreshUserInfo
} from "../../common/services/userServices.js"
import CategoryBar from "./components/category-bar.vue";
import WarehouseList from "./components/warehouse-list.vue";
import SystemInfoMixin from "../../common/mixins/system-info-mixin.js";
import Category from "./models/Category.js";
import {
getCategorys
} from "./services/index.js"
import {
isEmpty
} from "../../common/utils/util";
import {
readStorage,
saveStorage
} from '../../common/utils/storageUtil';
export default {
mixins: [SystemInfoMixin],
components: {
CategoryBar,
ProfileHeader,
WarehouseList
},
data() {
return {
userInfo: null,
listHeight: 0,
categorys: [],
currentIndex: 0
};
},
onLoad() {
this.getCategoryData();
watchUserInfoChange((info) => {
this.userInfo = info.userInfo
}, this);
},
onShow() {
this.refreshUserData();
},
computed: {
showEmpty: function() {
return isEmpty(this.categorys);
},
listStyle: function() {
return {
height: `${this.listHeight}px`
}
},
categroyChange: function() {
const {
categorys,
currentIndex
} = this;
return {
categorys,
currentIndex
}
}
},
watch: {
categroyChange: {
handler: function(n, o) {
this.$nextTick(() => {
let ref = this.$refs.bookList;
if (ref) {
ref[n.currentIndex].initRefresh();
}
})
},
deep: true
}
},
methods: {
readyCategory() {
setTimeout(() => {
this.initHeight()
}, 300)
},
getCategoryData() {
getCategorys((success, data) => {
if (success) {
let result = data ? data.map(item => {
return new Category(item)
}).sort((a, b) => {
return a.sort - b.sort
}) : [];
result.unshift(new Category({
name: "全部",
id: ""
}))
this.categorys = result;
}
})
},
initHeight() {
const query = uni.createSelectorQuery().in(this);
// query.select("#navi").boundingClientRect();
// query.select("#search").boundingClientRect();
query.select("#category").boundingClientRect();
query.exec((res) => {
let result = 0;
res.forEach(item => {
result = result + item.height;
})
this.listHeight = this.windowHeight - result;
})
},
changeCategory(e) {
this.changeCurrent(e.index);
},
changeSwiper(e) {
this.changeCurrent(e.detail.current);
},
changeCurrent(index) {
if (index != this.currentIndex) {
this.currentIndex = index;
}
},
refreshUserData() {
if (this.userInfo) {
refreshUserInfo();
}
}
}
}
</script>
<style lang="scss">
.name {
font-size: 34rpx;
font-weight: 700;
}
</style>
\ No newline at end of file
......@@ -4,7 +4,8 @@ export default {
share: {
title: '更多小说,等你来看',
imageUrl: 'https://mints-pkg.oss-cn-beijing.aliyuncs.com/pkg/img/book_bg_splash.png',
path: '/pages/loading?shareId='+getApp().globalData.userId
// path: '/pages/loading?shareId='+getApp().globalData.userId
path: '/pages/loading?shareId='
}
}
},
......
......@@ -71,18 +71,18 @@
},
onShow() {
try {
// 在子组件重写show()代替onShow()
if (this.currentPage == 0) {
this.$refs.index.show();
} else if (this.currentPage == 1) {
this.$refs.recommend.show();
} else if (this.currentPage == 2) {
this.$refs.user.show();
}
} catch (e) {
// try {
// // 在子组件重写show()代替onShow()
// if (this.currentPage == 0) {
// this.$refs.index.show();
// } else if (this.currentPage == 1) {
// this.$refs.recommend.show();
// } else if (this.currentPage == 2) {
// this.$refs.user.show();
// }
// } catch (e) {
}
// }
},
mounted() {
// 渲染完成 初始化首页数据
......@@ -92,7 +92,7 @@
tabChange(index) {
if (this.currentPage == index) return
this.currentPage = index;
this.loadComponentData();
// this.loadComponentData();
},
loadComponentData() {
if (this.currentPage == 0) {
......
......@@ -70,14 +70,14 @@
}
// app.globalData.userId = data.idcode;
// uni.setStorage({
// key: 'token',
// data: 'D6E76AC8E89ABE548B56568B8814D578D6980EAB68926EB1E7C07BF9E96A316F5F433703067DF5142735505C42F58997'
// });
// setTimeout(() => {
// redirectTo('home');
// }, 1000);
// return
uni.setStorage({
key: 'token',
data: 'D6E76AC8E89ABE548B56568B8814D578D6980EAB68926EB1E7C07BF9E96A316F5F433703067DF5142735505C42F58997'
});
setTimeout(() => {
redirectTo('home');
}, 1000);
return
tt.login({
force: true,
......
@font-face {
font-family: "readiconfont";
/* Project id 4264833 */
src: url('/static/fonts/readiconfont.ttf') format('truetype');
}
.readiconfont {
font-family: "readiconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-vip:before {
content: "\e60d";
}
.icon-share:before {
content: "\e60e";
}
.icon-setting:before {
content: "\e64a";
}
.icon-undiss:before {
content: "\e686";
}
.icon-unlike:before {
content: "\ec7f";
}
.icon-like:before {
content: "\ec8c";
}
.icon-uncollection:before {
content: "\e602";
}
.icon-collection:before {
content: "\e7ef";
}
.icon-diss:before {
content: "\e68f";
}
.icon-love:before {
content: "\e638";
}
.icon-author:before {
content: "\e668";
}
.icon-server:before {
content: "\e6aa";
}
.icon-read:before {
content: "\e633";
}
.icon-logout:before {
content: "\e677";
}
.icon-bookshelf:before {
content: "\e604";
}
.icon-person:before {
content: "\e605";
}
.icon-cloud:before {
content: "\e606";
}
\ No newline at end of file
export const PAKEAGE_NAME = 'com.duben.dybookhm'
// export const PAKEAGE_NAME = 'com.test.test'
export function trim(str) {
return str ? str.replace(/(^\s*)|(\s*$)/g, "") : ''
......
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