Commit 62cb8ae5 authored by jyx's avatar jyx

代码优化

parent 772c36dc
......@@ -15,11 +15,11 @@ export default class User {
bookLegumes
} = param || {}
this.id = id;
this.name = name || "微信用户";
this.name = name || "用户";
this.phone = phone;
this.sign = sign || '书中自有颜如玉,书中自有黄金屋,书中自有千钟黍';
this.avater = '/static/images/logo.png';
this.nickName = nickName || "微信用户";
this.nickName = nickName || "用户";
this.roleId = roleId;
this.sex = sex;
this.status = status;
......
......@@ -53,10 +53,10 @@ function successHandler(url, param, res, callback) {
uni.setStorageSync('showLoginModal', false)
}
})
}
}
console.log(res)
if (res.statusCode != 200) {
if (res.statusCode != 200) {
toastMessage(`服务器异常,${res.statusCode}`)
printError("请求失败", url, param, res.statusCode, res.errMsg);
if (typeof callback == 'function') callback(false, res.errMsg)
......@@ -66,7 +66,7 @@ function successHandler(url, param, res, callback) {
} else if (res.data.code == 401) {
tokenExpireFn()
if (typeof callback == 'function') callback(false, res.data.message);
} else {
} else {
toastMessage(`服务器异常,${res.data.code}`)
printError("请求失败", url, param, res.data.code);
if (typeof callback == 'function') callback(false, res.data.code)
......@@ -103,16 +103,16 @@ function login(data, callback) {
// 更新用户数据
function refreshUserInfo() {
requestUserInfo((success, userData) => {
if (success) {
if (success) {
console.log(userData)
let user = new User({
...userData,
name: userData.username,
nickName: userData.nickname,
name: userData.nickName,
nickName: userData.nickName,
avater: userData.avatar,
isVip: userData.expireTime > 0
})
console.log(user)
console.log(userData)
id: userData.idcode,
memberExpirationDate: userData.expireTime
})
saveNickname(userData.nickname);
saveUserInfo(user); // 存储用户数据
postNotification(KEY_NOTIFICATION_LOGIN_SUCCESS); // 通知登录成功
......@@ -176,10 +176,10 @@ function requestUserInfo(callback) {
url,
header,
method: "POST",
success: (res) => {
success: (res) => {
successHandler(url, {}, res, callback);
},
fail: (error) => {
fail: (error) => {
failHandler(url, data, error, callback);
}
})
......
......@@ -55,22 +55,22 @@
removeUserInfoChangeWatch(this);
removeCollectionChangeWatch(this);
},
methods: {
show() {
this.initHeight();
// 监听用户变动
watchUserInfoChange((info) => {
if (info.userInfo) {
this.initData();
}
}, this)
// 监听收藏变动
watchCollectionChange(() => {
this.refreshList();
}, this);
},
hide() {
methods: {
show() {
this.initHeight();
// 监听用户变动
watchUserInfoChange((info) => {
if (info.userInfo) {
this.initData();
}
}, this)
// 监听收藏变动
watchCollectionChange(() => {
this.refreshList();
}, this);
},
hide() {
},
resizeTimeCount() {
this.initHeight();
......
......@@ -137,9 +137,6 @@
const query = uni.createSelectorQuery().in(this);
query.select("#count").boundingClientRect();
},
onShow(){
},
show() {
// 更新阅读时间统计
this.refreshTimeCount();
......
......@@ -11,7 +11,7 @@
<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>
<WarehouseList :ref="`bookList${index}`" :category='item' :height='listHeight'></WarehouseList>
</swiper-item>
</swiper>
</view>
......@@ -76,10 +76,11 @@
categroyChange: {
handler: function(n, o) {
this.$nextTick(() => {
let ref = this.$refs.bookList;
if (ref) {
ref[n.currentIndex].initRefresh();
}
this.$refs[`bookList${n.currentIndex}`][0].initRefresh();
// let ref = this.$refs.bookList;
// if (ref) {
// ref[n.currentIndex].initRefresh();
// }
})
},
deep: true
......
......@@ -10,10 +10,14 @@
@tapVip='tapVipPop' @tapBean='tapBeanPop'></detail-new-buy>
<detail-bottom :detail='bookData' :userInfo='userInfo' @tapBottomItem='tapBottomItem'></detail-bottom>
<setting-pop :show='showSetting' @close='closePop'></setting-pop>
<vip-pop v-if="bookData.isUnlock==0 && !isVip()" :show='showVip' @close='closeVipPop'></vip-pop>
<!-- <vip-pop v-if="bookData.isUnlock==0 && !isVip()" :show='showVip' @close='closeVipPop'></vip-pop>
<bean-pop v-if="bookData.isUnlock==0 && userInfo.bookLegumes<bookData.bookLegumes" :show='showBean'
@close='closeBeanPop'></bean-pop>
@close='closeBeanPop'></bean-pop> -->
<recommend-pop :show='showRecommend' @close='closeRecommendPop' :bookId="bookId"></recommend-pop>
<coin-popup v-if="bookData.isUnlock==0 && !isVip()" :show="showVip" @close="closeVipPop"
@paySuccess="paySuccess">
</coin-popup>
</template>
<c-login :isShareLink="true"></c-login>
<popup :show="showMoibleLogin" @close="showMoibleLogin=false">
......@@ -126,12 +130,9 @@
// 用户已登录需要记录阅读记录
if (info.userInfo) {
addReadRecord(this.bookId)
}
console.log(info)
console.log(this.userInfo)
// this.showVipOpen = data.openVips
}
// this.showVipOpen = data.openVips
// // 用户变动,需要刷新数据
// this.$nextTick(() => {
// uni.startPullDownRefresh({})
......@@ -259,10 +260,8 @@
setTimeout(() => {
uni.stopPullDownRefresh();
if (success) {
this.bookData = new BookDetail(data);
console.log('bookData=' + JSON.stringify(this.bookData));
// console.log('bookData=' + JSON.stringify(this.bookData));
}
}, 1000)
})
......@@ -290,10 +289,8 @@
}
},
isVip() {
if (this.userInfo != null && this.userInfo.memberFlag) {
let cDate = new Date();
cDate = cDate.getTime();
return this.userInfo.memberExpirationDate >= cDate;
if (this.userInfo != null && this.userInfo.memberExpirationDate > 0) {
return true;
}
return false;
},
......
......@@ -68,7 +68,6 @@
if (index != '' && index != undefined) {
this.currentPage = index
}
},
onShow() {
// try {
......@@ -92,16 +91,16 @@
tabChange(index) {
if (this.currentPage == index) return
this.currentPage = index;
// this.loadComponentData();
this.loadComponentData();
},
loadComponentData() {
loadComponentData() {
if (this.currentPage == 0) {
this.$refs.index.show();
this.$refs.index.show();
} else if (this.currentPage == 1) {
this.$refs.recommend.show();
} else if (this.currentPage == 2) {
this.$refs.user.show();
}
}
}
}
}
......
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