新闻跳转地址修改

This commit is contained in:
@fawn-nine
2024-07-08 10:23:38 +08:00
parent 55227e230c
commit 9843424e1c
5 changed files with 172 additions and 3 deletions

View File

@@ -5,8 +5,8 @@ if (process.env.NODE_ENV === 'development') {
// baseUrl = "http://localhost:7001/";
// socketUrl = "ws://localhost:6001/";
// baseUrl = "https://twin-ui.com/demo/";
baseUrl = "https://testapi.nuttyreading.com/"; // 线上测试环境
// baseUrl = "https://api.nuttyreading.com/"; // 线上正式
// baseUrl = "https://testapi.nuttyreading.com/"; // 线上测试环境
baseUrl = "https://api.nuttyreading.com/"; // 线上正式
// baseUrl = "http://192.168.110.100:9200/pb/"; // 开发用电脑
// baseUrl = "http://59.110.212.44:9200/pb/";
// baseUrl = "http://192.168.110.100:9100/pb/"; // 开发用电脑

View File

@@ -609,6 +609,13 @@
{
"navigationBarTitleText" : "新闻播报"
}
},
{
"path" : "pages/news/newsForwebview",
"style" :
{
"navigationBarTitleText" : "新闻播报webView"
}
}
// {
// "path": "pages/agreement/yszcPage",

View File

@@ -0,0 +1,158 @@
<template>
<view>
<!-- 公共组件-每个页面必须引入 -->
<public-module></public-module>
<!-- <z-nav-bar title="新闻详情"></z-nav-bar> -->
<web-view v-if="urlVisible" :webview-styles="webviewStyles" :src="surl"></web-view>
<!-- <music-play :playData="playData"></music-play> -->
</view>
</template>
<script>
// import musicPlay from '@/components/music.vue'
import $http from '@/config/requestConfig.js';
var clear;
import {
mapState
} from 'vuex';
export default {
data() {
return {
playData: {},
newsObj: null,
news: {
content: '',
title: ''
},
source:'',
urlVisible:false,
surl:'',
type:null,
webviewStyles: {
progress: {
color: '#55aaff'
}
},
};
},
//第一次加载
onLoad(e) {
// 隐藏原生的tabbar
uni.hideTabBar();
this.newsId = e.newsId
this.type = e.type
this.surl = e.url
this.source = e.source
console.log(e, '------')
// #ifdef APP-PLUS
const pages = getCurrentPages()
const page = pages[pages.length - 1];
const currentWebview = page.$getAppWebview()
currentWebview.setStyle({
titleNView: {
buttons: [{
float: 'right',
type: 'close',
onclick: function() {
uni.navigateBack({
delta: 1
});
}
}]
}
})
// #endif
},
computed: {
...mapState(['userInfo'])
},
//页面显示
onShow() {
// 隐藏原生的tabbar
uni.hideTabBar();
if(this.type == 1 && this.surl != ''){
// this.surl = this.newsObj.url
this.urlVisible = true
this.news = {}
}
},
onPullDownRefresh() {
uni.stopPullDownRefresh()
},
components: {
// musicPlay
},
//方法
methods: {
getData() {
var _url = "common/message/getMessageById"
if(this.source = 'taihuzhiguang'){ // 太湖之光
_url = "common/taihuWelfare/getTaihuWelfareArticleDetail"
$http.request({
url: `${_url}`,
method: "POST", // POST、GET、PUT、DELETE具体说明查看官方文档
data: {
id: this.newsId
},
header: { //默认 无 说明:请求头
'Content-Type': 'application/json'
},
}).then(res => {
if (res.code == 0) {
this.news.content = res.result.content
this.news.title = res.result.title
}
}).catch(e => {
console.log(e, '获取新闻详情报错')
});
}else{
this.$http
.post(`${_url}?id=${this.newsId}`)
.then(res => {
if (res.code == 0) {
this.news.content = res.result.content
this.news.title = res.result.title
}
}).catch(e => {
console.log(e, '获取新闻详情报错')
});
}
},
formatRichText(html) { //控制图片大小
let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) {
match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
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%;');
return match;
});
// newContent = newContent.replace(/<img[^>]*>/gi, function(match, capture) {
// match = match.replace(/<img[^>]*>/gi, "@click='1111'").replace(/<img[^>]*>/gi, "@click='1111'");
// 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;"');
return newContent;
},
},
};
</script>
<style lang="scss" scoped>
@import '@/style/mixin.scss';
.box {
background-color: #fff;
// @include pleft_right(10px);
min-height: calc(100vh - 270rpx);
}
.title{font-size: 32rpx; font-weight: bold; display: block; text-align: center;}
.content { font-size: 26rpx; line-height: 48rpx; margin-top: 10rpx;}
</style>

View File

@@ -529,7 +529,11 @@
newsClick(item) {
if (item.type == 1) { // url跳转
if (item.url != '') {
this.openURL(item.url)
console.log('item',item);
// this.openURL(item.url)
uni.navigateTo({
url:`/pages/news/newsForwebview?id=${item.id}&url=${item.url}&type=1`
})
} else {
console.log('跳转链接为空')
}

Binary file not shown.