Commit 5a8927e4 authored by jyx's avatar jyx

代码优化

parent bbcc2f19
......@@ -11,6 +11,9 @@ import {
readStorage,
saveStorage
} from "../utils/storageUtil.js";
import {
reLaunch
} from "../../utils/fun.js";
import User from "../models/User.js";
import {
isEmpty,
......@@ -245,10 +248,10 @@ function saveToken(token) {
saveStorage(KEY_STORAGE_TOKEN, token);
}
function readToken() {
function readToken() {
if (!LOCAL_TOKEN) {
LOCAL_TOKEN = readStorage(KEY_STORAGE_TOKEN)
}
}
return LOCAL_TOKEN;
}
......@@ -312,10 +315,13 @@ function removeUserInfoChangeWatch(observer) {
}
// 展示登录弹窗
function showLoginView() {
postNotification(KEY_NOTIFICATION_LOGIN_SHOW, {
show: true
})
function showLoginView() {
reLaunch(`loading`)
// postNotification(KEY_NOTIFICATION_LOGIN_SHOW, {
// show: true
// })
}
module.exports = {
......
......@@ -12,7 +12,7 @@ import {
appendParam,
} from "./util";
import {
PAKEAGE_NAME,
PAKEAGE_NAME,
VERSION_CODE
} from "../../utils/utils";
import {
......@@ -112,7 +112,7 @@ let apiRequest = function({
option.header = {
pkgName: PAKEAGE_NAME,
token: `${token}`,
token: `${token}`,
version: VERSION_CODE,
proChannel: uniChannel
}
......@@ -254,7 +254,7 @@ function apiUPLOAD({
option.url = `${option.url}?t=${new Date().getTime()}`; // 路径
option.header = {
pkgName: PAKEAGE_NAME,
pkgName: PAKEAGE_NAME,
version: VERSION_CODE,
token: `${token}`
}
......
<template>
<view class="detail-content">
<template v-if='showVIPContent'>
<!-- <view class="content-paragraph" :style="[contentStyle]" v-for='(item, index) in contentSources'
:key='index'>
{{item}}
</view> -->
<yingbing-flip type="cover" :data="contentSources" style="height: 100vh;">
<!-- #ifndef MP -->
<template v-slot="{item, index}">
<!-- #endif -->
<!-- #ifdef MP -->
<template v-for="(item, index) in contentSources" :slot="index">
<!-- #endif -->
<view style="height: 100%">
<text style="font-size: 28rpx;color: #fff;">{{item}}</text>
</view>
</template>
</yingbing-flip>
</template>
<template v-else>
<yingbing-flip :data="preContentSources" style="height: 100vh;">
<!-- #ifndef MP -->
<template v-slot="{item, index}">
<!-- #endif -->
<!-- #ifdef MP -->
<template v-for="(item, index) in list" :slot="index">
<!-- #endif -->
<view style="height: 100%">
<text style="font-size: 50px;font-weight: bold;color: #fff;">{{item}}</text>
</view>
</template>
</yingbing-flip>
<!-- <view class="content-paragraph" :style="[contentStyle]" v-for='(item, index) in preContentSources'
:key="index">
{{item}}
</view> -->
<view class="limit-button-box" @click="tapLimitButton">
{{limitButtonTitle}}
</view>
</template>
</view>
</template>
<script>
import {
watchContentFormatChange,
removeContentFormatChangeWatch
} from "../services/index.js"
import {
showLoginView
} from "../../../../common/services/userServices.js"
import {
gotoVIPApplyPage
} from "../../../../common/services/page-route.js"
import User from "../../../../common/models/User.js";
const PRECENT_VALUE = 40;
export default {
props: {
userInfo: {
type: Object,
default: function() {
return null
}
},
detail: {
type: Object,
default: function() {
return {}
}
}
},
data: function() {
return {
user: null,
fontSize: `18px`,
}
},
mounted() {
watchContentFormatChange((data) => {
let result = data.getFormatValue();
if (this.fontSize != result.fontSize) {
this.fontSize = result.fontSize
}
}, this)
},
destroyed() {
removeContentFormatChangeWatch(this);
},
watch: {
userInfo: {
handler: function(n) {
if (n) {
this.user = new User(n)
} else {
this.user = null
}
},
deep: true,
immediate: true
}
},
computed: {
contentSources: function() {
return this.detail && this.detail.content ? this.detail.content : [];
},
preContentSources: function() {
let result = this.detail && this.detail.content ? [...this.detail.content] : [];
let length = result.length;
if (length >= 2) {
let precent = PRECENT_VALUE / 100;
let preLength = Math.floor(length * precent);
return result.splice(0, preLength);
} else {
return result;
}
},
limitButtonTitle: function() {
let result = `~剩余${100-PRECENT_VALUE}%内容`;
if (!this.user) {
result = `${result},点击登录后继续阅读`;
} else if (!this.user.isVip()) {
result = `${result}为会员章节内容,请前往购买会员`
}
result = `${result}~`;
return result;
},
contentStyle: function() {
return {
fontSize: this.fontSize
}
},
showVIPContent: function() {
return (this.user && this.user.isVip()) || this.detail.isUnlock
}
},
methods: {
tapLimitButton() {
if (!this.user) {
showLoginView()
} else if (!this.user.isVip()) {
let isIOS = wx.getSystemInfoSync().platform;
if (isIOS === 'ios') {
uni.showToast({
title: '暂不支持IOS系统',
icon: 'none'
})
return
}
gotoVIPApplyPage()
}
}
}
}
</script>
<style lang="scss" scoped>
.detail-content {
paading: 20rpx 30rpx;
margin: 20rpx 30rpx;
display: flex;
flex-direction: column;
.content-paragraph {
text-indent: 1em;
word-wrap: break-word;
word-break: break-all;
white-space: normal;
line-height: 1.5em;
margin-bottom: 1em;
color: #333;
}
.content-paragraph:last-child {
margin-bottom: 0;
}
.limit-button-box {
text-indent: 0;
height: 120rpx;
line-height: 120rpx;
text-align: center;
color: goldenrod;
font-size: 28rpx;
}
}
</style>
\ No newline at end of file
......@@ -2,10 +2,11 @@
<view :style="[bgStyle]">
<c-empty v-if='showEmpty'></c-empty>
<template v-else>
<detail-content :detail='bookData' :userInfo='userInfo' @tabVip2="tapVipPop"></detail-content>
<detail-content ref="content" :detail='bookData' @tabVip2="tapVipPop"
@changeCurrent="changeCurrent"></detail-content>
<detail-bottom :detail='bookData' :userInfo='userInfo' @tapBottomItem='tapBottomItem'></detail-bottom>
<setting-pop :show='showSetting' @close='closePop'></setting-pop>
<catalogue-pop :detail='bookData' :show='showCatalogue' @close='closeCataPop'
<catalogue-pop :detail='bookData' :show='showCatalogue' @close='closeCataPop' :current="current"
@tabVip='tapVipPop'></catalogue-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'
......@@ -15,15 +16,6 @@
:vedioId="bookData.id" @paySuccess="paySuccess">
</coin-popup>
</template>
<!-- <c-login :isShareLink="true"></c-login> -->
<popup :show="showMoibleLogin" @close="showMoibleLogin=false">
<view>
<button open-type="getPhoneNumber" @getphonenumber="MygetPhonenumber">
<view>请先绑定手机号</view>
<view style="color:green;">去绑定</view>
</button>
</view>
</popup>
</view>
</template>
......@@ -34,8 +26,6 @@
import BookDetail from "./models/BookDetail.js";
import {
getBookDetailData,
watchContentFormatChange,
removeContentFormatChangeWatch,
addReadRecord
} from "./services/index.js"
import {
......@@ -90,7 +80,6 @@
return {
bookId: null,
bookData: null,
backgroundColor: "#fff",
showSetting: false,
showCatalogue: false,
showVip: false,
......@@ -99,8 +88,7 @@
userInfo: null,
showVipOpen: 0,
showBeanOpen: 0,
showMoibleLogin: false,
mobileLoginLock: false,
current: 1
};
},
onLoad(options) {
......@@ -114,13 +102,6 @@
}
},
onReady() {
// 监听样式变动
watchContentFormatChange((data) => {
let result = data.getFormatValue();
if (this.backgroundColor != result.backgroundColor) {
this.backgroundColor = result.backgroundColor
}
}, this)
// 监听用户变动
watchUserInfoChange((info) => {
this.userInfo = info.userInfo;
......@@ -128,12 +109,13 @@
if (info.userInfo && this.bookId) {
addReadRecord(this.bookId)
}
// // 用户变动,需要刷新数据
// this.$nextTick(() => {
// uni.startPullDownRefresh({})
// })
}, this)
// 用户变动,需要刷新数据
this.$nextTick(() => {
uni.startPullDownRefresh({})
})
......@@ -160,7 +142,6 @@
// 停止记录阅读时长,部分情况下页面无法响应onHide事件
endCountReadTime();
// 移除监听
removeContentFormatChangeWatch(this);
removeUserInfoChangeWatch(this);
// 取消绑定分享参数
......@@ -193,7 +174,6 @@
return {
minHeight: `${height}px`,
position: "relative",
background: this.backgroundColor
}
}
},
......@@ -209,39 +189,11 @@
}
},
methods: {
async MygetPhonenumber(e) {
console.log(e.detail.code) // 动态令牌
console.log(e.detail.errMsg) // 回调信息(成功失败都会返回)
console.log(e.detail.errno) // 错误码(失败时返回)
if (e.detail.code == undefined || e.detail.code == '') {
uni.showModal({
title: "提示",
content: e.detail.errMsg
})
return
}
var params = {
userId: this.userInfo.userid,
code: e.detail.code,
}
postPhone(params, (success, result) => {
if (success) {
saveStorage("KEY_NEED_PHONE", false);
this.mobileLoginLock = false
this.tapPayPop()
} else {
uni.showModal({
title: "提示",
content: "网络错误!"
})
}
})
},
// 解锁回调
unlockBook() {
this.$set(this.bookData, "isUnlock", true);
paySuccess() {
this.$set(this.bookData, "isUnlock", 1);
this.$set(this.bookData, "freeNum", this.bookData.articleChapterList.length);
this.$refs.content.reloadChapterinfoData()
},
// 文章数据刷新
refreshBookData(bookId) {
......@@ -250,13 +202,15 @@
// this.showVipOpen = data.openVips
// })
getBookDetailData(bookId, (success, data) => {
// setTimeout(() => {
uni.stopPullDownRefresh();
if (success) {
if (data.isUnlock) {
data.freeNum = data.articleChapterList.length
}
this.bookData = new BookDetail(data);
console.log('bookData=' + JSON.stringify(this.bookData));
}
// }, 300)
})
},
// 点击底部按钮
......@@ -305,7 +259,6 @@
},
// 展示充值书豆弹框
tapBeanPop() {
this.showBean = true;
},
// 关闭设置弹窗
......@@ -319,9 +272,11 @@
// 关闭会员弹窗
closeVipPop(e) {
this.showVip = false;
setTimeout(() => {
this.showRecommend = true;
}, 300);
if (this.bookData.isUnlock == 0) {
setTimeout(() => {
this.showRecommend = true;
}, 300);
}
},
// 关闭书豆弹窗
closeBeanPop(e) {
......@@ -334,6 +289,9 @@
closeRecommendPop(e) {
this.showRecommend = false;
},
changeCurrent(current) {
this.current = current
}
}
}
</script>
......
......@@ -43,6 +43,10 @@
detail: {
type: Object,
default: 0
},
current: {
type: Number,
default: 0
}
},
data: function() {
......@@ -55,6 +59,11 @@
},
computed: {},
watch: {
current: function(n) {
if (n != this.currentCatalogue) {
this.changeCatalogue(n)
}
},
show: function(n) {
this.showPop = n;
},
......@@ -71,8 +80,14 @@
this.initColorList();
this.currentContentFormat = readContentFormat()
for (let i in this.currentContentFormat.catalogueList) {
if (this.currentContentFormat.catalogueList[i].id == this.detail.id) {
this.currentCatalogue = this.currentContentFormat.catalogueList[i].catalogue
if (this.currentContentFormat.catalogueList[i].id == this.detail.id) {
// 处理特殊情况,下标错误
let current_e = this.currentContentFormat.catalogueList[i].catalogue
if (!this.detail.isUnlock && current_e > this.detail.freeNum) {
this.currentCatalogue = this.detail.freeNum
return
}
this.currentCatalogue = current_e
}
}
},
......@@ -110,8 +125,8 @@
id: this.detail.id,
catalogue: e
})
}
}
this.currentCatalogue = e
saveContentFormat(this.currentContentFormat);
......
<template>
<view class="pages">
<yingbing-text-reader ref="reader" :total-chapter="detail.articleChapterList.length" preloadable selectable
<yingbing-text-reader ref="reader" :total-chapter="detail.articleChapterList.length" :preloadable="isPreload"
:background="background" :fontSize="fontSize" :lineGap="30" :color="color" :page-type="pageType"
:loadPageNum="1" @back="handleBack" @change="handleChange" @loadmore="handleLoadmore">
<template v-for="(item, index) in chapters" :slot="`vip:${item.index}`">
<view class="slots">{{item.index}}章节付费阅读提示页</view>
bottomGap="60" :footerShow="false" :loadPageNum="2" @change="handleChange" @loadmore="handleLoadmore">
<template v-if="!detail.isUnlock" :slot="`vip:${catalogue}`">
<view class="slots">
<view class="line-box">
<view class="line"></view>
<view class="text">全本订阅超优惠</view>
<view class="line"></view>
</view>
<view class="section">
<button class="btn2" :disabled="false" :loading="false" @click="tapVip">开通会员,免费阅读本书</button>
</view>
<view class="warn-box">
<view class="warn-p">
1.目前充值会员暂不支持退款,一经购买不可退换
</view>
<view class="warn-p">
2.未满18岁的未成年人需要在监护人主导,同意下进行相关付费操作
</view>
<view class="warn-p">
3.充值一般在5分钟内到账,如未到账请提供支付截图在"我的"页面联系客服
</view>
<view class="warn-p">
4.之前充值账户请登录后继续阅读
</view>
</view>
</view>
</template>
<!-- <template v-for="(item, index) in chapters" :slot="`end:${item.index}`">
......@@ -23,12 +48,6 @@
export default {
props: {
userInfo: {
type: Object,
default: function() {
return null
}
},
detail: {
type: Object,
default: function() {
......@@ -38,7 +57,6 @@
},
data() {
return {
chapters: [],
pageType: 'real',
split: '',
background: '#fff',
......@@ -46,13 +64,10 @@
fontSize: 18,
pageType: 'cover',
catalogue: 1,
isFisrt: true
isFisrt: true,
isPreload: false
}
},
onReady() {
let total = this.detail.articleChapterList.length
for (let i = 0; i < total; i++) this.chapters.push(this.getChapter(i + 1))
},
destroyed() {
removeContentFormatChangeWatch(this);
},
......@@ -74,15 +89,31 @@
}
}
if (this.catalogue != resultCatalogue) {
this.catalogue = resultCatalogue
if (!this.detail.isUnlock && resultCatalogue > this.detail.freeNum) {
this.catalogue = 3
} else {
if (this.catalogue != resultCatalogue) {
this.catalogue = resultCatalogue
this.refreshChapterinfoData(this.catalogue)
}
}
if (this.isFisrt) {
this.isFisrt = false
this.isPreload = true
this.refreshChapterinfoData(this.catalogue)
}
}, this)
},
methods: {
reloadChapterinfoData() {
this.isPreload = true
this.refreshChapterinfoData()
},
// 文章数据刷新
refreshChapterinfoData(chapterId) {
refreshChapterinfoData(chapterId = this.catalogue) {
this.catalogue = chapterId
let id = this.detail.articleChapterList[chapterId - 1].id
getChapterinfoData(this.detail.id, id, (success, data) => {
if (success) {
......@@ -91,51 +122,46 @@
})
},
changeChapterinfo(chapterId, content) {
this.catalogue = chapterId
// let mycontent = content.replace(/<(\/)?p>/g, '').replace(/<(\/)?sub>/g, '').replace(/<(\/)?pre>/g, '')
// .replace(/<(\/)?code>/g, '')
if (this.isFisrt) {
// for (let i = 0; i < this.chapters.length; i++) {
// this.chapters[chapterId - 1].content = content
// }
this.chapters = [this.getChapter(chapterId, content)]
this.isFisrt = false
this.$refs.reader.init({
chapters: this.chapters,
title: this.detail.title,
current: chapterId,
start: 1
})
} else {
this.chapters.push(this.getChapter(chapterId, content))
// for (let i = 0; i < this.chapters.length; i++) {
// this.chapters[chapterId - 1].content = content
// }
this.$refs.reader.change({
chapters: this.chapters,
current: chapterId
})
}
this.chapters = [this.getChapter(chapterId, content)]
this.$refs.reader.change({
chapters: this.chapters,
title: this.detail.title,
current: chapterId,
start: 1
})
},
handleChange(e) {
console.log('change', e);
if (this.catalogue != e.detail.index) {
this.catalogue = e.detail.index
if (this.detail.isUnlock) {
this.changeCurrent()
} else if (!this.detail.isUnlock && this.catalogue < this.detail.freeNum) {
this.changeCurrent()
}
}
},
handleLoadmore(current, callback) {
if (current > this.detail.freeNum || current > this.detail.articleChapterList.length) {
if (!this.detail.isUnlock && current == this.detail.freeNum + 1) {
callback('success', this.getChapter(current))
return
}
callback('fail')
return
}
let id = this.detail.articleChapterList[current - 1].id
getChapterinfoData(this.detail.id, id, (success, data) => {
if (success) {
callback('success', this.getChapter(current, data.contentMd))
} else {
if (current < this.detail.freeNum + 1) {
callback('success', this.getChapter(current, ""))
}
return
}
callback('fail')
})
},
getChapter(index, content) {
const showVip = index > this.detail.freeNum
const showVip = !this.detail.isUnlock && index > this.detail.freeNum
return {
title: '第' + index + '章',
content: content,
......@@ -143,14 +169,24 @@
// backSlots: ['end'],
index: index,
isStart: index == 1,
isEnd: index == 10
isEnd: index == this.detail.articleChapterList.length
}
}
},
tapVip() {
setTimeout(() => {
this.$emit('tabVip2')
}, 200)
},
changeCurrent() {
setTimeout(() => {
this.$emit('changeCurrent', this.catalogue)
}, 200)
},
}
}
</script>
<style>
<style lang="scss">
.pages {
/* #ifdef APP-NVUE */
flex: 1;
......@@ -169,22 +205,63 @@
left: 0;
right: 0;
bottom: 0;
color: blue;
/* #ifndef APP-NVUE */
display: flex;
flex-direction: column;
/* #endif */
align-items: center;
justify-content: center;
}
.btns {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
position: fixed;
left: 0;
right: 0;
.section {
width: 80%;
margin-top: 30rpx;
display: flex;
flex-direction: column;
.btn2 {
color: #DCBD3B;
border: #DCBD3B solid 1rpx;
width: 100%;
text-align: center;
border-radius: 80rpx;
height: 80rpx;
line-height: 80rpx;
}
}
.line-box {
width: 80%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
.line {
width: 30%;
background-color: lightgray;
height: 1rpx;
}
.text {
text-align: center;
width: 36%;
color: lightgray;
font-size: 26rpx;
}
}
.warn-box {
color: #956244;
font-size: 26rpx;
display: flex;
flex-direction: column;
padding: 30rpx;
.warn-p {
margin-bottom: 15rpx;
}
.warn-p:last-child {
margin-bottom: 0;
}
}
}
</style>
\ No newline at end of file
......@@ -44,6 +44,10 @@
openUrl
} from '@/utils/app+.js';
import {
gotoBookContentPage
} from '../../common/services/page-route.js';
const app = getApp();
export default {
......@@ -76,15 +80,17 @@
});
},
handleInfo(item) {
var bookId = item.id;
uni.navigateTo({
url: `/page-subs/sub_A/book-content/book-content`,
success: (res) => {
res.eventChannel.emit("openBookContentPage", {
bookId
})
}
})
gotoBookContentPage(item.id, item.shortis)
// var bookId = item.id;
// uni.navigateTo({
// url: `/page-subs/sub_A/book-content/book-content`,
// success: (res) => {
// res.eventChannel.emit("openBookContentPage", {
// bookId
// })
// }
// })
},
handleXing(item) {
var that = this;
......
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