详情页加超链接

main
fanfan 7 months ago
parent 0f76dc0da4
commit 985f1279d5
  1. 3
      config.js
  2. 2
      manifest.json
  3. 7
      pages.json
  4. 40
      pages/goods/detail.vue
  5. 28
      pages/goods/webView.vue
  6. 2
      project.config.json

@ -14,7 +14,8 @@ export default {
* 商城ID (必填)
* 可在超管后台-商城列表中查看10025
*/
storeId: 10001,
// storeId: 10001,
storeId: 10045,
// storeId: 10037,

@ -92,7 +92,7 @@
"quickapp" : {},
/* */
"mp-weixin" : {
"appid" : "wx68d198de972a9e9d",
"appid" : "wxe843b6d7a4bd3389",
"libVersion" : "latest",
"setting" : {
// TLS

@ -745,6 +745,13 @@
"enablePullDownRefresh": true
}
},
{
"path": "webView",
"style": {
"navigationBarTitleText": "商品详情",
"enablePullDownRefresh": true
}
},
{
"path": "detail",
"style": {

@ -204,7 +204,9 @@
</view>
</view>
</view>
<view class="detail-content" v-html="goods.content"></view>
<view class="detail-content" @click="onLook(goods.isLink,goods.contentLink)" v-if="goods.isLink"
v-html="goods.content"></view>
<view class="detail-content" v-else v-html="goods.content"></view>
<view class="footer">
<view class="fooLeft">
<view class="footerCus firstBtn" v-if="isLogin == false" @click="addCar()">
@ -557,6 +559,13 @@
}
},
methods: {
onLook(isLink, url) {
if (isLink) {
uni.navigateTo({
url: '/pages/goods/webView?src=' + encodeURIComponent(url) //urlh5pageB
})
}
},
async getGoodsStockInfor() {
let params = {
list: [{
@ -878,6 +887,29 @@
}
})
},
getLinksFromRichText(richText) {
// ahref
const regex = /<a[^>]*href="?([^">]+)"?[^>]*>(.*?)<\/a>/gim;
let matches, links = '';
//
while ((matches = regex.exec(richText)) !== null) {
// matches[1]hrefmatches[2]
links = matches[1];
}
return links;
},
getValueAfterSymbol(str, symbol) {
const parts = str.split(symbol);
if (parts.length > 1) {
return parts[1].trim(); // 使trim()
}
return str; //
},
containsLetterMix(str, mix) {
return new RegExp(mix.split('').join('\\w*')).test(str)
},
//
getGoodsDetail(type) {
const that = this
@ -897,10 +929,11 @@
.replace(/style=""/g, '')
.replace(/<img " src=/g, '<img src=')
.replace(/<img src=/g, '<img style="width: 100%; display:block" src=')
// that.goods = info;
info.contentLink = that.getValueAfterSymbol(that.getLinksFromRichText(info
.content), 'client://')
info.isLink = that.containsLetterMix(info.contentLink, 'jd.com') ? true : false
Object.keys(info).forEach(item => {
this.$set(this.goods, item, info[item])
// that.goods[item] = info[item]
})
that.isTodo = true;
@ -1009,7 +1042,6 @@
return;
}
//
console.log(this.token, '登录信息')
if (this.goods.stock_total == 0) {
return this.$toast('库存不足,请选择其他商品购买')
}

@ -0,0 +1,28 @@
//PageWebview.vue
<template>
<web-view v-if='src' :src='src' @message='message'></web-view>
</template>
<script>
export default {
data() {
return {
src: "",
};
},
onLoad(options) {
options.src = decodeURIComponent(options.src);
setTimeout(() => {
this.src = `${options.src}`;
}, 500);
},
methods: {
message(e) {
console.log(message, 'webView----message')
},
},
};
</script>
<style lang="scss" scoped>
</style>

@ -1,5 +1,5 @@
{
"appid": "wx68d198de972a9e9d",
"appid": "wxe843b6d7a4bd3389",
"compileType": "miniprogram",
"libVersion": "3.3.3",
"packOptions": {

Loading…
Cancel
Save