|
@@ -57,13 +57,26 @@ export default {
|
|
|
// 这里拿的是静态 HTML 文件,不是 JSON,关掉自动 JSON 解析,直接拿原始文本
|
|
// 这里拿的是静态 HTML 文件,不是 JSON,关掉自动 JSON 解析,直接拿原始文本
|
|
|
dataType: 'text',
|
|
dataType: 'text',
|
|
|
success: (res) => {
|
|
success: (res) => {
|
|
|
- this.article.content = typeof res.data === 'string' ? res.data : ''
|
|
|
|
|
|
|
+ const raw = typeof res.data === 'string' ? res.data : ''
|
|
|
|
|
+ this.article.content = this.resolveImgSrc(raw)
|
|
|
},
|
|
},
|
|
|
fail: (err) => {
|
|
fail: (err) => {
|
|
|
console.error('getContent failed', this.contentUrl, err)
|
|
console.error('getContent failed', this.contentUrl, err)
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
+ // 后台正文里的图片路径不统一:有的自己已经带了 /tingli/ 前缀,有的没带,
|
|
|
|
|
+ // 不能用 mp-html 的 domain 属性一次性拼(不管设成带不带 /tingli 都会对一半、错一半),
|
|
|
|
|
+ // 改成自己按每个 src 分别判断补全
|
|
|
|
|
+ resolveImgSrc(html) {
|
|
|
|
|
+ const originMatch = getApp().globalData.shareUrl.match(/^(https?:\/\/[^/]+)/)
|
|
|
|
|
+ const origin = originMatch ? originMatch[1] : ''
|
|
|
|
|
+ if (!origin) return html
|
|
|
|
|
+ return html.replace(/(<img[^>]*\bsrc=")(\/[^"]*)(")/g, (match, prefix, path, suffix) => {
|
|
|
|
|
+ const full = path.indexOf('/tingli/') === 0 ? (origin + path) : (origin + '/tingli' + path)
|
|
|
|
|
+ return prefix + full + suffix
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|
|
|
</script>
|
|
</script>
|