完成bug的更改

master
wangchenguang 2 years ago
parent 893267c2e3
commit 9bcc0a80ef
  1. 1
      App.vue
  2. 81
      team/article/article.vue

@ -33,5 +33,4 @@
<style lang="scss"> <style lang="scss">
@import '@/uni_modules/uni-scss/index.scss'; @import '@/uni_modules/uni-scss/index.scss';
@import url("/components/gaoyia-parse/parse.css");
</style> </style>

@ -17,9 +17,8 @@
</view> </view>
</view> </view>
<view class="text" v-html="form.mainBody"> <view class="text">
<!-- <rich-text :nodes="form.mainBody"></rich-text> --> <u-parse :content="form.mainBody" ></u-parse>
<u-parse :content="form.mainBody" />
</view> </view>
<view v-if="form.fileList" class="files"> <view v-if="form.fileList" class="files">
@ -45,6 +44,9 @@
} }
} }
}, },
components: {
uParse
},
onShow() { onShow() {
const pages = getCurrentPages() const pages = getCurrentPages()
const { options } = pages[pages.length - 1] const { options } = pages[pages.length - 1]
@ -59,8 +61,13 @@
title: '加载中' title: '加载中'
}) })
findById(this.id).then(({ message }) => { findById(this.id).then(({ message }) => {
const imgStr= this.convert(message.mainBody) const str = message.mainBody
// message.mainBody = this.getVideo(imgStr) const newStyle = 'width: 85% !important; height: auto;';
const regex = /(<img[^>]*?\s+style=")([^"]*)("[^>]*?>)/g;
const newStr = str.replace(regex, `$1${newStyle}$3`);
const brStr = str.replace(/\r\n/g,"<br />")
const videoStr = this.replaceAllVideoTagStyles(brStr, "width: 95%; height: 450rpx;display: block;margin:0 auto")
const imgStr = videoStr.replace(regex, `$1${newStyle}$3`);
message.mainBody = imgStr message.mainBody = imgStr
this.form = message this.form = message
uni.hideLoading() uni.hideLoading()
@ -68,43 +75,34 @@
uni.hideLoading() uni.hideLoading()
}) })
}, },
convert (options) { getAllVideoTagIndices(str) {
let str = options.replace(/<img[^>]*>/gi, function (match, capture) { const regex = /<video.*?>.*?<\/video>/gs;
return match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/ig, 'style="width:90%;margin: 0 auto;height:auto;"') // style const indices = [];
}) let match;
console.log(str) while ((match = regex.exec(str)) !== null) {
return str indices.push(match.index);
}
return indices;
},
// videostyle
replaceVideoTagStyle(str, index, newStyle) {
const startIndex = str.indexOf("<video", index);
const endIndex = str.indexOf("</video>", startIndex) + 7;
const videoTag = str.substring(startIndex, endIndex);
const newVideoTag = videoTag.replace(/style="(.*?)"/, `style="${newStyle}"`);
return str.substring(0, startIndex) + newVideoTag + str.substring(endIndex);
},
// videostyle
replaceAllVideoTagStyles(str, newStyle) {
const indices = this.getAllVideoTagIndices(str);
let newStr = str;
for (let i = indices.length - 1; i >= 0; i--) {
newStr = this.replaceVideoTagStyle(newStr, indices[i], newStyle);
}
return newStr;
}, },
//
getVideo(data) {
let videoList = [];
let videoReg = /<video.*?(?:>|\/>)/gi; // video
let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; // video
let arr = data.match(videoReg) || []; // arr video
let articleList = data.split('</video>') //
arr.forEach((item, index) => {
var src = item.match(srcReg);
console.log(src)
videoList.push(src[1]) // video
})
let needArticleList = [];
articleList.forEach((item, index) => {
if (item != "" && item != undefined) { //
needArticleList.push({
type: 'rich-text',
value: item + "</video>"
});
}
let articleListLength = articleList.length; // video
if (index < articleListLength && videoList[index] != undefined) {
needArticleList.push({
type: 'video',
value: videoList[index]
})
}
})
return needArticleList
},
// //
download(item) { download(item) {
this.$util.to(`../send/send?url=${item.filePath}&copyWriting=${item.fileName}`) this.$util.to(`../send/send?url=${item.filePath}&copyWriting=${item.fileName}`)
@ -138,6 +136,7 @@
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@import url("/components/gaoyia-parse/parse.css");
.wrap { .wrap {
padding: 30rpx; padding: 30rpx;
background-color: #fff; background-color: #fff;

Loading…
Cancel
Save