Commit 772c36dc authored by jyx's avatar jyx

代码优化

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