This commit is contained in:
@fawn-nine
2023-09-22 13:42:32 +08:00
parent 8f970b3d0e
commit ce389485d6
2 changed files with 455 additions and 309 deletions

View File

@@ -14,16 +14,18 @@
</view> </view>
<view class="commodityContent"> <view class="commodityContent">
<view class="commodityPrice" v-if="productInfo.activityPrice && productInfo.activityPrice > 0"> <view class="commodityPrice" v-if="productInfo.activityPrice && productInfo.activityPrice > 0">
<span style="font-size: 28rpx;" ></span><em>{{productInfo.activityPrice}}</em> <span style="font-size: 28rpx;"></span><em>{{productInfo.activityPrice}}</em>
<span class="oldPrice " >原价<span style="font-size: 20rpx;padding-left:10rpx;"></span>{{productInfo.price}}</span> <span class="oldPrice ">原价<span
style="font-size: 20rpx;padding-left:10rpx;"></span>{{productInfo.price}}</span>
</view> </view>
<view class="commodityPrice" v-else> <view class="commodityPrice" v-else>
<span style="font-size: 28rpx;" ></span><em>{{productInfo.price}}</em> <span style="font-size: 28rpx;"></span><em>{{productInfo.price}}</em>
</view> </view>
<view class="commodityyName"> <view class="commodityyName">
{{productInfo.productName}} {{productInfo.productName}}
<span v-if="productInfo.productStock==0" style="color: #aaa;font-size:26rpx;">无货</span> <span v-if="productInfo.productStock==0" style="color: #aaa;font-size:26rpx;">无货</span>
<view><text class="SoldNumber">已售<span style="padding-left:10rpx;">{{productInfo.sumSales}}</span></text></view> <view><text class="SoldNumber">已售<span
style="padding-left:10rpx;">{{productInfo.sumSales}}</span></text></view>
</view> </view>
<view class="pingjia" v-if="linkProducts && linkProducts.length > 0 && linkProducts[0]"> <view class="pingjia" v-if="linkProducts && linkProducts.length > 0 && linkProducts[0]">
<view class=""> <view class="">
@@ -38,7 +40,8 @@
<image :src="item.productImages" mode="aspectFit"></image> <image :src="item.productImages" mode="aspectFit"></image>
</view> </view>
<text class="username nowrap ">{{item.productName}}</text> <text class="username nowrap ">{{item.productName}}</text>
<text class="price" v-if="item.activityPrice && item.activityPrice > 0">{{item.activityPrice}}</text> <text class="price"
v-if="item.activityPrice && item.activityPrice > 0">{{item.activityPrice}}</text>
<text class="price" v-else>{{item.price}}</text> <text class="price" v-else>{{item.price}}</text>
</view> </view>
</view> </view>
@@ -49,13 +52,11 @@
</view> </view>
<view class="contentButton"> <view class="contentButton">
<u-tabs :scrollable="false" :list="contentButtonList" @click="contentButtonClick" <u-tabs :scrollable="false" :list="contentButtonList" @click="contentButtonClick" :activeStyle="{
:activeStyle="{
color: '#303133', color: '#303133',
fontWeight: 'bold', fontWeight: 'bold',
fontSize: '28rpx' fontSize: '28rpx'
}" }" :inactiveStyle="{
:inactiveStyle="{
color: '#606266', color: '#606266',
fontSize: '28rpx' fontSize: '28rpx'
}"></u-tabs> }"></u-tabs>
@@ -64,47 +65,54 @@
<view v-if="contentShow == 0"> <view v-if="contentShow == 0">
<view class="pingjia"> <view class="pingjia">
<!-- <h4></h4> --> <!-- <h4></h4> -->
<view class="" v-if="listenList.length > 0 && listenList[0]" style="margin:0rpx 0rpx 30rpx;"> <view class="" v-if="listenList.length > 0 && listenList[0]" style="margin:0rpx 0rpx 30rpx;">
<view class=""> <view class="">
<view style="font-weight: 600;margin-bottom: 30rpx;color:#71d5a1;">赠送听书权益</view> <view style="font-weight: 600;margin-bottom: 30rpx;color:#71d5a1;">赠送听书权益</view>
</view> </view>
<view class="item flexbox aligncenter" v-for="item in listenList" :key="item.id" style="padding-bottom:10rpx;"> <view class="item flexbox aligncenter" v-for="item in listenList" :key="item.id"
style="padding-bottom:10rpx;">
<view class="spbhimg" @click="previewImage(item.images)"> <view class="spbhimg" @click="previewImage(item.images)">
<image :src="item.images" mode="aspectFit"></image> <image :src="item.images" mode="aspectFit"></image>
</view> </view>
<text style="padding-right: 10rpx;">{{item.name}}</text> <text style="padding-right: 10rpx;">{{item.name}}</text>
<u-icon v-if="item.canListen == 'true'" name="volume" color="#71d5a1" size="24" @click="goToListen(item.id)"></u-icon> <u-icon v-if="item.canListen == 'true'" name="volume" color="#71d5a1" size="24"
<u-icon v-else name="volume" color="#71d5a1" size="24" @click="goToListenNone(item.id)"></u-icon> @click="goToListen(item.id)"></u-icon>
<u-icon v-else name="volume" color="#71d5a1" size="24"
@click="goToListenNone(item.id)"></u-icon>
</view> </view>
</view> </view>
<view class=""> <view class="">
<view style="font-weight: 600;margin:0rpx 0rpx 30rpx;">商品详情</view> <view style="font-weight: 600;margin:0rpx 0rpx 30rpx;">商品详情</view>
</view> </view>
<view class="bookInfo" > <view class="bookInfo">
<u-row customStyle="margin-bottom: 10px"> <u-row customStyle="margin-bottom: 10px">
<u-col ><span>书名{{productInfo.productName}}</span></u-col> <u-col><span>书名{{productInfo.productName}}</span></u-col>
</u-row> </u-row>
<u-row customStyle="margin-bottom: 10px"> <u-row customStyle="margin-bottom: 10px">
<u-col v-if="productInfo.author"><span>作者{{productInfo.author}}</span></u-col> <u-col v-if="productInfo.author"><span>作者{{productInfo.author}}</span></u-col>
</u-row> </u-row>
<u-row customStyle="margin-bottom: 10px"> <u-row customStyle="margin-bottom: 10px">
<u-col span="12" v-if="productInfo.publisher"><span>出版社{{productInfo.publisher}}</span></u-col> <u-col span="12"
v-if="productInfo.publisher"><span>出版社{{productInfo.publisher}}</span></u-col>
</u-row> </u-row>
<u-row customStyle="margin-bottom: 10px"> <u-row customStyle="margin-bottom: 10px">
<u-col span="12" v-if="productInfo.pubDate"><span>出版时间{{ productInfo.pubDate | formatDate }}</span></u-col> <u-col span="12"
v-if="productInfo.pubDate"><span>出版时间{{ productInfo.pubDate | formatDate }}</span></u-col>
</u-row> </u-row>
<u-row customStyle="margin-bottom: 10px"> <u-row customStyle="margin-bottom: 10px">
<u-col span="6" v-if="productInfo.format"><span>开本{{productInfo.format}}</span></u-col> <u-col span="6" v-if="productInfo.format"><span>开本{{productInfo.format}}</span></u-col>
<u-col span="6" v-if="productInfo.pageNum"><span>页数{{productInfo.pageNum}}</span></u-col> <u-col span="6" v-if="productInfo.pageNum"><span>页数{{productInfo.pageNum}}</span></u-col>
</u-row> </u-row>
<u-row customStyle="margin-bottom: 10px"> <u-row customStyle="margin-bottom: 10px">
<u-col span="6" v-if="productInfo.quality"><span>内文用纸材质{{productInfo.quality}}</span></u-col> <u-col span="6"
v-if="productInfo.quality"><span>内文用纸材质{{productInfo.quality}}</span></u-col>
</u-row> </u-row>
</view> </view>
<!-- <view class="commodityIntroduce" v-html="productInfo.productDetails"> --> <!-- <view class="commodityIntroduce" v-html="productInfo.productDetails"> -->
<view class="commodityIntroduce" > <view class="commodityIntroduce">
<view v-if="productInfo.productDetails" > <view v-if="productInfo.productDetails">
<rich-text v-if="productInfo.productDetails" class="xiangqing" :nodes="productInfo.productDetails|formatRichText"></rich-text> <rich-text v-if="productInfo.productDetails" class="xiangqing"
:nodes="productInfo.productDetails|formatRichText"></rich-text>
</view> </view>
</view> </view>
</view> </view>
@@ -114,7 +122,8 @@
</view> </view>
<view class="pingjia" v-else> <view class="pingjia" v-else>
<view class=""> <view class="">
<view style="font-weight: 600;margin-bottom: 30rpx;">评价({{commentsList?commentsList.length:0}})</view> <view style="font-weight: 600;margin-bottom: 30rpx;">评价({{commentsList?commentsList.length:0}})
</view>
<!-- <view class="icon-del rotate"></view> --> <!-- <view class="icon-del rotate"></view> -->
</view> </view>
<!-- 商品评价 --> <!-- 商品评价 -->
@@ -136,7 +145,8 @@
<view class="contentBox"> <view class="contentBox">
<div class="pjimgs flexbox"> <div class="pjimgs flexbox">
<view class="item" v-for="(item1,index) in item.images"> <view class="item" v-for="(item1,index) in item.images">
<image v-if="item1.length > 10" @click="previewImage(item1)" :src="item1" mode="aspectFill" style="width:100%; height: 50px;"></image> <image v-if="item1.length > 10" @click="previewImage(item1)" :src="item1"
mode="aspectFill" style="width:100%; height: 50px;"></image>
</view> </view>
</div> </div>
<view class="content" v-html="item.phtml"></view> <view class="content" v-html="item.phtml"></view>
@@ -165,25 +175,29 @@
<view class="tanchu"> <view class="tanchu">
<view class="list"> <view class="list">
<view class="imgBox"> <view class="imgBox">
<image v-if="linkimg == ''" src="../../static/icon/wufeng.jpg" mode="aspectFit" style="width: 100%; height: 100%;"></image> <image v-if="linkimg == ''" src="../../static/icon/wufeng.jpg" mode="aspectFit"
style="width: 100%; height: 100%;"></image>
<image v-else :src="linkimg" mode="aspectFit" style="width: 100%; height: 100%;"></image> <image v-else :src="linkimg" mode="aspectFit" style="width: 100%; height: 100%;"></image>
<view class="xiangxi" v-if="productId != linkProducts[linkCur].productId" @click="gotoDetail(linkProducts[linkCur])"> <view class="xiangxi" v-if="productId != linkProducts[linkCur].productId"
@click="gotoDetail(linkProducts[linkCur])">
<text>查看详情</text> <text>查看详情</text>
</view> </view>
</view> </view>
<view :class="['spbh', linkCur == index ? 'cur' :'']" v-for="(item, index) in linkProducts" :key="item.id"> <view :class="['spbh', linkCur == index ? 'cur' :'']" v-for="(item, index) in linkProducts"
:key="item.id">
<view class="flexbox aligncenter" @click="previewProduct(item,index)"> <view class="flexbox aligncenter" @click="previewProduct(item,index)">
<view class="spbhimg"> <view class="spbhimg">
<image :src="item.productImages" mode="aspectFit"></image> <image :src="item.productImages" mode="aspectFit"></image>
</view> </view>
<text class="username nowrap ">{{item.productName}}</text> <text class="username nowrap ">{{item.productName}}</text>
<text class="price" v-if="item.activityPrice && item.activityPrice > 0">{{item.activityPrice}}</text> <text class="price"
v-if="item.activityPrice && item.activityPrice > 0">{{item.activityPrice}}</text>
<text class="price" v-else>{{item.price}}</text> <text class="price" v-else>{{item.price}}</text>
</view> </view>
</view> </view>
</view> </view>
<uni-goods-nav style="left: 0;" class="goods_nav" :fill="true" :options="options" :buttonGroup="buttonGroup" @click="onClick" <uni-goods-nav style="left: 0;" class="goods_nav" :fill="true" :options="options"
@buttonClick="buttonClickLink" /> :buttonGroup="buttonGroup" @click="onClick" @buttonClick="buttonClickLink" />
</view> </view>
</u-popup> </u-popup>
</view> </view>
@@ -205,9 +219,9 @@
export default { export default {
data() { data() {
return { return {
linkimg:'', // 选中的关联商品图片 linkimg: '', // 选中的关联商品图片
playData:{}, playData: {},
contentShow:0, contentShow: 0,
options: [{ options: [{
icon: 'cart', icon: 'cart',
text: '购物车' text: '购物车'
@@ -236,12 +250,12 @@
productInfo: {}, productInfo: {},
productAmount: 1, // 商品数量 productAmount: 1, // 商品数量
cartList: [], // 购物车列表 cartList: [], // 购物车列表
commentsList:[], // 评论列表 commentsList: [], // 评论列表
productId:null, // 商品评论 productId: null, // 商品评论
listenList:[], // 关联得听书 listenList: [], // 关联得听书
linkProducts:[], // 关联的商品, linkProducts: [], // 关联的商品,
upoShow:false, // 显示底部购买选项 upoShow: false, // 显示底部购买选项
linkCur : 0, // 当前选中的关联项 linkCur: 0, // 当前选中的关联项
} }
}, },
onLoad(e) { onLoad(e) {
@@ -258,108 +272,112 @@
musicPlay musicPlay
}, },
methods: { methods: {
gotoDetail(item){ gotoDetail(item) {
// console.log(item,'gotoDetail') // console.log(item,'gotoDetail')
uni.navigateTo({ uni.navigateTo({
url: '../bookShop/commodityDetail?id=' + item.productId url: '../bookShop/commodityDetail?id=' + item.productId
}); });
}, },
closeUpo(){ closeUpo() {
console.log('关闭弹窗') console.log('关闭弹窗')
this.upoShow = false this.upoShow = false
}, },
// 点击其他套餐 // 点击其他套餐
previewProduct(item,index){ previewProduct(item, index) {
console.log(item,'item') console.log(item, 'item')
this.linkimg = item.productImages this.linkimg = item.productImages
this.upoShow = true this.upoShow = true
this.linkCur = index this.linkCur = index
}, },
// 获取商品关联商品 // 获取商品关联商品
getLinkPros(id){ getLinkPros(id) {
this.$http this.$http
.post('book/shopproduct/getGlProductList',{ .post('book/shopproduct/getGlProductList', {
'productId': id 'productId': id
}) })
.then(res => { .then(res => {
console.log('关联商品', res) console.log('关联商品', res)
if(res.code == 0){ if (res.code == 0) {
this.linkProducts = res.result if (res.result.length > 0) {
if(this.linkProducts.length > 0){ this.linkProducts = res.result
this.linkimg = this.linkProducts[0].productImages this.linkimg = this.linkProducts[0].productImages
this.linkCur = 0 this.linkCur = 0
}else{
this.linkProducts = []
} }
} }
}) })
.catch(e => { .catch(e => {
console.log(e,'e') console.log(e, 'e')
}) })
}, },
goToListen(id){ goToListen(id) {
// 跳转到听书 // 跳转到听书
uni.navigateTo({ uni.navigateTo({
url: "../listen/listen?bookid="+ id url: "../listen/listen?bookid=" + id
}); });
}, },
// 放大图片 // 放大图片
previewImage(url){ previewImage(url) {
console.log(url) console.log(url)
uni.previewImage({ uni.previewImage({
urls: [url] urls: [url]
}); });
}, },
// 获取html格式的评论1 // 获取html格式的评论1
getHtmlComment(comment){ getHtmlComment(comment) {
// 格式化html // 格式化html
// console.log(comment,'comment') // console.log(comment,'comment')
// 这里处理 链接 换行符 // 这里处理 链接 换行符
let replacedStr = comment.replace(/\[([^(\]|\[)]*)\]/g, (item, index) => { let replacedStr = comment.replace(/\[([^(\]|\[)]*)\]/g, (item, index) => {
// console.log(item, index) // console.log(item, index)
var indexss = emojiList1.findIndex(item1 => item1.alt === item) var indexss = emojiList1.findIndex(item1 => item1.alt === item)
// console.log(indexss, 'indexss') // console.log(indexss, 'indexss')
return '<img src="https://www.nuttyreading.com/emojis/emojis/qq/' + emojiList1[indexss].url + '" width="18rpx">'; return '<img src="https://www.nuttyreading.com/emojis/emojis/qq/' + emojiList1[indexss].url +
}); '" width="18rpx">';
// console.log(replacedStr,'replacedStr') });
return replacedStr.replace(/(\r\n)|(\n)/g, '<br>'); // console.log(replacedStr,'replacedStr')
return replacedStr.replace(/(\r\n)|(\n)/g, '<br>');
}, },
// 获取评价 // 获取评价
getComments(){ getComments() {
$http.request({ $http.request({
url: "buy/record/All", url: "buy/record/All",
method: "POST", // POST、GET、PUT、DELETE具体说明查看官方文档1 method: "POST", // POST、GET、PUT、DELETE具体说明查看官方文档1
data: { data: {
'bookid': this.productId 'bookid': this.productId
}, },
header: { //默认 无 说明:请求头 header: { //默认 无 说明:请求头
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}, },
}) })
.then(res => { .then(res => {
if(res.code == 0){ if (res.code == 0) {
console.log(res.list, 'res.list') console.log(res.list, 'res.list')
this.commentsList = res.list.map(item => { this.commentsList = res.list.map(item => {
var imgList = [] var imgList = []
if(item.images !== null){ if (item.images !== null) {
imgList = item.images.split(',') imgList = item.images.split(',')
item.images = imgList item.images = imgList
return item return item
}else { } else {
return item return item
} }
}) })
// 评论格式化 // 评论格式化
var newarr = [] var newarr = []
this.commentsList.forEach((item1)=>{ this.commentsList.forEach((item1) => {
var pjstr = '' var pjstr = ''
var zpstr = '' var zpstr = ''
pjstr = this.getHtmlComment(item1.content) pjstr = this.getHtmlComment(item1.content)
item1.followUpcontent == '' ? zpstr = '' : zpstr = this.getHtmlComment(item1.followUpcontent) item1.followUpcontent == '' ? zpstr = '' : zpstr = this.getHtmlComment(item1
//console.log(pjstr,'99999999999----------') .followUpcontent)
item1.phtml = pjstr //console.log(pjstr,'99999999999----------')
item1.zphtml = zpstr item1.phtml = pjstr
newarr.push(item1) item1.zphtml = zpstr
newarr.push(item1)
}) })
this.commentsList = newarr this.commentsList = newarr
@@ -368,16 +386,16 @@
} }
}) })
}, },
getProDetail(e){ getProDetail(e) {
// 获取商品详情 // 获取商品详情
uni.showLoading({ uni.showLoading({
title: '加载中' title: '加载中'
}); });
console.log(e.id,'e.id') console.log(e.id, 'e.id')
this.$http this.$http
.post('/book/shopproduct/info/' + e.id) .post('/book/shopproduct/info/' + e.id)
.then(res => { .then(res => {
console.log('shopproduct',res) console.log('shopproduct', res)
this.productInfo = res.shopProduct this.productInfo = res.shopProduct
this.listenList = res.shopProduct.bookidsimages this.listenList = res.shopProduct.bookidsimages
if (this.productInfo.productImageList == null || this.productInfo.productImageList == '') { if (this.productInfo.productImageList == null || this.productInfo.productImageList == '') {
@@ -394,21 +412,21 @@
} }
uni.hideLoading(); uni.hideLoading();
}).catch(e => { }).catch(e => {
console.log(e,'e') console.log(e, 'e')
uni.hideLoading(); uni.hideLoading();
if(e.msg == '该商品不存在,看看其他商品吧'){ if (e.msg == '该商品不存在,看看其他商品吧') {
setTimeout(() => { setTimeout(() => {
uni.navigateBack({ uni.navigateBack({
delta: 1 delta: 1
}); });
},2000) }, 2000)
} }
}) })
}, },
contentButtonClick(e){ contentButtonClick(e) {
this.contentShow = e.index this.contentShow = e.index
}, },
// 点击购物车 // 点击购物车
@@ -419,10 +437,10 @@
}); });
}, },
// 关联商品点击按钮组件 // 关联商品点击按钮组件
buttonClickLink(e){ buttonClickLink(e) {
console.log('点击的是关联商品的组件') console.log('点击的是关联商品的组件')
if(e.index == 0){ if (e.index == 0) {
// 点击的是加入购物车 // 点击的是加入购物车
if (this.linkProducts[this.linkCur].productStock == 0) { if (this.linkProducts[this.linkCur].productStock == 0) {
uni.showToast({ uni.showToast({
title: '商品库存不足', title: '商品库存不足',
@@ -437,45 +455,46 @@
this.isAddLink(this.linkProducts[this.linkCur]) this.isAddLink(this.linkProducts[this.linkCur])
}) })
} }
}else{ } else {
// 点击的是立即购买 // 点击的是立即购买
if (this.linkProducts[this.linkCur].productStock == 0) { if (this.linkProducts[this.linkCur].productStock == 0) {
uni.showToast({ uni.showToast({
title: '商品库存不足', title: '商品库存不足',
icon: "none", icon: "none",
duration: 1000, duration: 1000,
}); });
} else { } else {
uni.navigateTo({ uni.navigateTo({
url: '../bookShop/settlement?type=2&list=' + this.linkProducts[this.linkCur].productId url: '../bookShop/settlement?type=2&list=' + this.linkProducts[this.linkCur].productId
}); });
} }
} }
}, },
// 点击按钮组间 // 点击按钮组间
buttonClick(e) { buttonClick(e) {
// console.log(e) // console.log(e)
if(e.index == 0){ if (e.index == 0) {
// 点击的是加入购物车 // 点击的是加入购物车
if(this.linkProducts.length > 0){ console.log('+.........',this.linkProducts,'this.linkProducts')
this.upoShow = true if (this.linkProducts.length == 0) {
}else{ this.addCart()
this.addCart() } else {
} this.upoShow = true
}
}else{ } else {
// 点击的是立即购买 // 点击的是立即购买
if(this.linkProducts.length > 0){ if (this.linkProducts.length == 0) {
this.upoShow = true this.goPurse()
}else{ } else {
this.goPurse() this.upoShow = true
} }
} }
}, },
goToListenNone(){ goToListenNone() {
uni.showToast({ uni.showToast({
title:'该书暂未生成音频内容,敬请期待!', title: '该书暂未生成音频内容,敬请期待!',
icon:'none' icon: 'none'
}) })
}, },
// 加入购物车 // 加入购物车
@@ -664,21 +683,23 @@
} }
}, },
formatRichText (html) { //控制小程序中图片大小 formatRichText(html) { //控制小程序中图片大小
let newContent= html.replace(/<img[^>]*>/gi,function(match,capture){ let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
return match; return match;
}); });
newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){ newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;'); match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
return match; 'max-width:100%;');
}); return match;
newContent = newContent.replace(/<br[^>]*\/>/gi, ''); });
newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"'); newContent = newContent.replace(/<br[^>]*\/>/gi, '');
return newContent; newContent = newContent.replace(/\<img/gi,
}, '<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
return newContent;
},
// 去购物车 // 去购物车
goCard() { goCard() {
uni.switchTab({ uni.switchTab({
@@ -687,139 +708,278 @@ formatRichText (html) { //控制小程序中图片大小
}, },
}, },
filters: {/** filters: {
* 处理富文本里的图片宽度自适应 /**
* 1.去掉img标签里的style、width、height属性 * 处理富文本里的图片宽度自适应
* 2.img标签添加style属性max-width:100%;height:auto * 1.去掉img标签里的style、width、height属性
* 3.修改所有style里的width属性max-width:100% * 2.img标签添加style属性max-width:100%;height:auto
* 4.去掉<br/>标签 * 3.修改所有style里的width属性为max-width:100%
* @param html * 4.去掉<br/>标签
* @returns {void|string|*} * @param html
*/ * @returns {void|string|*}
formatRichText (html) { //控制小程序中图片大小 */
let newContent= html.replace(/<img[^>]*>/gi,function(match,capture){ formatRichText(html) { //控制小程序中图片大小
match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, ''); let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, ''); match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, ''); match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
return match; match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
}); return match;
newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){ });
match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;'); newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
return match; match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
}); 'max-width:100%;');
newContent = newContent.replace(/<br[^>]*\/>/gi, ''); return match;
newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"'); });
return newContent; newContent = newContent.replace(/<br[^>]*\/>/gi, '');
}, newContent = newContent.replace(/\<img/gi,
// 时间格式化 '<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
formatDate(date){ return newContent;
console.log(date) },
let newDate = new Date(date); // 时间格式化
let year = newDate.getFullYear(); formatDate(date) {
let month = newDate.getMonth().toString().padStart(2,0); console.log(date)
let day = newDate.getDay().toString().padStart(2,0); let newDate = new Date(date);
return year + '-' + month + '-' + day; let year = newDate.getFullYear();
} let month = newDate.getMonth().toString().padStart(2, 0);
} let day = newDate.getDay().toString().padStart(2, 0);
return year + '-' + month + '-' + day;
}
}
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.tanchu { background: #fff;position: relative; .tanchu {
background: #fff;
position: relative;
padding: 40rpx 30rpx 40rpx 30rpx; padding: 40rpx 30rpx 40rpx 30rpx;
position: relative; position: relative;
.list{margin-bottom: 140rpx; .list {
.imgBox{height: 500rpx; width: 100%; margin-bottom: 10rpx; position: relative; margin-bottom: 140rpx;
.xiangxi{text-align: center; position: absolute; left: 0; bottom: 20rpx; width: 100%;
text{padding: 10rpx 20rpx; font-size: 32rpx; background-color: rgba(235, 160, 11, .9); color: #def0ea; border-radius: 10px;} .imgBox {
height: 500rpx;
width: 100%;
margin-bottom: 10rpx;
position: relative;
.xiangxi {
text-align: center;
position: absolute;
left: 0;
bottom: 20rpx;
width: 100%;
text {
padding: 10rpx 20rpx;
font-size: 32rpx;
background-color: rgba(235, 160, 11, .9);
color: #def0ea;
border-radius: 10px;
}
} }
} }
} }
.spbh{ border: 2rpx solid #fff;
.spbhimg { .spbh {
image{ border: 2rpx solid #fff;
border: none !important;
.spbhimg {
image {
border: none !important;
}
} }
} }
}
.spbh.cur{ .spbh.cur {
border: 2rpx solid #eba00b; border: 2rpx solid #eba00b;
border-radius: 10rpx; border-radius: 10rpx;
overflow: hidden; overflow: hidden;
}
} }
.tingshuList{margin-top: 20rpx; background-color: #fff; padding: 20rpx;
border-radius: 20rpx; margin-bottom: 20rpx; padding-top: 40rpx;
background-image: linear-gradient(0deg, #f7fffc 0%, #def0ea 100%);
.item{margin-bottom: 20rpx; vertical-align: middle; }
h4{color: #5fb386; font-size: 40rpx; margin-bottom: 20rpx;}
text{color: #444; font-size: 32rpx; padding-left: 20rpx;}
} }
.pjimgs{ margin: 0;flex-wrap: wrap; display: flex; justify-content: space-between;
.item{ .tingshuList {
margin-top: 20rpx;
background-color: #fff;
padding: 20rpx;
border-radius: 20rpx;
margin-bottom: 20rpx;
padding-top: 40rpx;
background-image: linear-gradient(0deg, #f7fffc 0%, #def0ea 100%);
.item {
margin-bottom: 20rpx;
vertical-align: middle;
}
h4 {
color: #5fb386;
font-size: 40rpx;
margin-bottom: 20rpx;
}
text {
color: #444;
font-size: 32rpx;
padding-left: 20rpx;
}
}
.pjimgs {
margin: 0;
flex-wrap: wrap;
display: flex;
justify-content: space-between;
.item {
width: 23%; width: 23%;
padding-right: 20rpx; padding-right: 20rpx;
margin-top: 10rpx; margin-top: 10rpx;
image{
image {
border-radius: 15rpx; border-radius: 15rpx;
} }
} }
} }
.star{display: inline-block; width: 15px; height: 15px; margin-right: 6rpx;}
.starGray{ background : url(../../static/icon/star_greey.png) no-repeat; background-size: contain; } .star {
.starLight{ background : url(../../static/icon/star_light.png) no-repeat; background-size: contain;} display: inline-block;
.quesheng{text-align: center; margin-top: 0rpx; color: #8b8a91;} width: 15px;
.pingjia{ height: 15px;
margin-right: 6rpx;
}
.starGray {
background: url(../../static/icon/star_greey.png) no-repeat;
background-size: contain;
}
.starLight {
background: url(../../static/icon/star_light.png) no-repeat;
background-size: contain;
}
.quesheng {
text-align: center;
margin-top: 0rpx;
color: #8b8a91;
}
.pingjia {
background-color: #f5f5f5; background-color: #f5f5f5;
border-radius: 20rpx; border-radius: 20rpx;
// margin-top: 20rpx; // margin-top: 20rpx;
padding: 30rpx 30rpx 20rpx; padding: 30rpx 30rpx 20rpx;
} }
.pingjiaBox{color: #555; margin-bottom: 20rpx;}
.flexbox{display: flex;} .pingjiaBox {
.contentBox{width: 100%;box-sizing: border-box; padding: 0rpx 10rpx 30rpx 6rpx; color: #555;
.content{font-size: 28rpx; line-height: 40rpx;margin-top: 10rpx;} margin-bottom: 20rpx;
.time{font-size: 24rpx; color: #999; padding-top: 6rpx; float: right;}
} }
.spbh{
.flexbox {
display: flex;
}
.contentBox {
width: 100%;
box-sizing: border-box;
padding: 0rpx 10rpx 30rpx 6rpx;
.content {
font-size: 28rpx;
line-height: 40rpx;
margin-top: 10rpx;
}
.time {
font-size: 24rpx;
color: #999;
padding-top: 6rpx;
float: right;
}
}
.spbh {
padding-bottom: 10rpx; padding-bottom: 10rpx;
font-size: 26rpx; padding: 0 10rpx; font-size: 26rpx;
padding: 0 10rpx;
} }
.spbhimg{
width:40px; overflow: hidden; text-align: center; .spbhimg {
image{ width: 40px;
width:40px !important; overflow: hidden;
text-align: center;
image {
width: 40px !important;
padding: 3px; padding: 3px;
height: 40px !important; height: 40px !important;
border: 1px solid #eee; border: 1px solid #eee;
border-radius: 6rpx; border-radius: 6rpx;
overflow: hidden; overflow: hidden;
} }
} }
.username{ margin-left: 10rpx; }
.price{margin-left: 5px; .username {
color: #ffa200; margin-left: 10rpx;
font-weight: bold;}
.nowrap {
white-space: nowrap;
overflow-x: hidden;
text-overflow: ellipsis;
}
.touxiang{width:40px; overflow: hidden; text-align: center;
image{width:40px !important; padding: 3px; height: 40px !important; border: 1px solid #eee; border-radius: 64px; overflow: hidden;;}
.username{font-size: 24rpx; color: #999; margin-top: 6rpx; }
} }
.aligncenter{
.price {
margin-left: 5px;
color: #ffa200;
font-weight: bold;
}
.nowrap {
white-space: nowrap;
overflow-x: hidden;
text-overflow: ellipsis;
}
.touxiang {
width: 40px;
overflow: hidden;
text-align: center;
image {
width: 40px !important;
padding: 3px;
height: 40px !important;
border: 1px solid #eee;
border-radius: 64px;
overflow: hidden;
;
}
.username {
font-size: 24rpx;
color: #999;
margin-top: 6rpx;
}
}
.aligncenter {
align-items: center; align-items: center;
} }
.xiangqing { .xiangqing {
overflow: hidden; overflow-x: hidden; overflow: hidden;
img{display: block; max-width: 100%;} overflow-x: hidden;
p{max-width: 100%;}
img {
display: block;
max-width: 100%;
}
p {
max-width: 100%;
}
} }
.goods_nav { .goods_nav {
z-index: 1; z-index: 1;
position: fixed; position: fixed;
@@ -881,7 +1041,8 @@ formatRichText (html) { //控制小程序中图片大小
} }
.oldPrice { .oldPrice {
background-color: #ff000013;; background-color: #ff000013;
;
padding: 4rpx 14rpx; padding: 4rpx 14rpx;
border-radius: 20rpx; border-radius: 20rpx;
margin-left: 20rpx; margin-left: 20rpx;

View File

@@ -34,26 +34,13 @@
</view> </view>
<view class="wrap" v-if="contentShow == 1"> <view class="wrap" v-if="contentShow == 1">
<view v-if="1==1"> <u-row gutter="16" justify="flex-start" v-if="tjBookLIst.length > 0">
接口正在调试
</view>
<u-row gutter="16" justify="flex-start" v-if="tjBookLIst.length > 0 && 6==3">
<u-col span="4" v-for="(item,index) in tjBookLIst" :key="index"> <u-col span="4" v-for="(item,index) in tjBookLIst" :key="index">
<view class="videoBox demo-layout bg-purple" @click="goDetail(item)"> <view class="videoBox demo-layout bg-purple" @click="goDetail(item)">
<image :src="item.images" mode="scaleToFill"></image> <image :src="item.images" mode="scaleToFill"></image>
<!-- <u-icon class="playButton" name="play-circle" color="#54a966" size="40"></u-icon> --> <!-- <u-icon class="playButton" name="play-circle" color="#54a966" size="40"></u-icon> -->
</view> </view>
<text class="bookName">{{item.name}}</text> <text class="bookName">{{item.name}}</text>
<!-- <view class="btns flexbox">
<view class="item flexbox" @click="goToListen(item)">
<u-icon name="volume" color="#71d5a1" size="24"></u-icon>
<text> </text>
</view>
<view class="item flexbox" @click="wgGoPingshu(item)">
<u-icon name="chat" color="#fcbd71" size="24"></u-icon>
<text> </text>
</view>
</view> -->
</u-col> </u-col>
</u-row> </u-row>
<u-divider v-else text="暂无推荐书籍~"></u-divider> <u-divider v-else text="暂无推荐书籍~"></u-divider>
@@ -94,6 +81,7 @@
ygtotalPage: 1, ygtotalPage: 1,
tjPage: 1, tjPage: 1,
tjTotalPage: 1, tjTotalPage: 1,
tjPageSize:9,
tjBookLIst: [], tjBookLIst: [],
contentButtonList: [{ contentButtonList: [{
name: '已购图书' name: '已购图书'
@@ -112,16 +100,11 @@
}, },
onPullDownRefresh() { onPullDownRefresh() {
console.log('下拉刷新了') console.log('下拉刷新了')
this.tjBookLIst = []
this.getListDate()
this.bookList = []
this.getfreeBook()
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
if (this.contentShow == 0) {
// this.page=1, // 页码
this.bookList = []
this.getfreeBook()
} else if (this.contentShow == 1) {
// this.tjPage=1, // 页码
this.tjBookLIst = []
this.getListDate()
}
}, },
onReachBottom() { onReachBottom() {
this.loadingNow = true this.loadingNow = true
@@ -144,7 +127,7 @@
// } // }
if (this.contentShow == 1) { if (this.contentShow == 1) {
if (this.tjPage < this.tjTotalPage) { if (this.tjPage+1 < this.tjTotalPage) {
this.tjPage++ this.tjPage++
console.log('加载', this.tjPage) console.log('加载', this.tjPage)
this.status = 0 this.status = 0
@@ -233,21 +216,23 @@
.post('book/book/getUserNobuyBooks', { // 磊哥新写 .post('book/book/getUserNobuyBooks', { // 磊哥新写
// .post('book/shopproduct/booklist', { // 原接口 // .post('book/shopproduct/booklist', { // 原接口
'userId': this.userInfo.id, 'userId': this.userInfo.id,
'limit': 9, 'limit': this.tjPageSize,
'page': this.tjPage 'page': this.tjPage
}) })
.then(res => { .then(res => {
console.log(res) console.log(res,'推荐听书列表')
if (res.code == 0 && res.books.length > 0) { if (res.code == 0 && res.page.records.length > 0) {
console.log(res,'推荐听书列表') this.tjBookLIst = this.tjBookLIst.concat(res.page.records)
this.tjBookLIst = res.books // 计算总页数
var yu = res.count % 9 var yu = res.page.total % this.tjPageSize
if(yu != 0){ console.log(yu,'yu')
this.tjTotalPage = parseInt(res.count / 9) + 1 if(yu > 0){
this.tjTotalPage = parseInt(res.page.total / this.tjPageSize) +1
// console.log(this.tjTotalPage,'总页数this.tjTotalPage')
}else{ }else{
this.tjTotalPage = parseInt(res.count / 9) this.tjTotalPage = parseInt(res.page.total / this.tjPageSize)
// console.log(this.tjTotalPage,'总页数this.tjTotalPage')
} }
console.log(this.tjTotalPage,'tjTotalPage')
this.status = 3 this.status = 3
}else{ }else{
this.tjTotalPage = 0 this.tjTotalPage = 0