master
lion 8 months ago
parent 33bec2bf14
commit 4583c43447

@ -894,30 +894,16 @@ export default {
sort:this.form.sort,
content: (() => {
let content = this.form.content || ''
const baseUrl = `${process.env.VUE_APP_BASE_API}storage/files`
// 使用正则表达式,只替换不包含 http:// 或 https:// 的相对路径
// 替换 ../storage/files(排除已经包含 http:// 或 https:// 的情况)
content = content.replace(/\.\.\/storage\/files/g, (match, offset) => {
// 检查前面是否有 http:// 或 https://
const before = content.substring(Math.max(0, offset - 50), offset)
if (before.indexOf('http://') !== -1 || before.indexOf('https://') !== -1) {
return match
// 去掉末尾的 /,避免出现 //storage/files
const apiBase = (process.env.VUE_APP_BASE_API || '').replace(/\/$/, '')
const baseUrl = `${apiBase}/storage/files/`
// 只处理 img 标签中 src 以 /storage/files 或 ../storage/files 开头、且不是 http(s) 开头的情况
content = content.replace(
/(<img[^>]+src=["'])(?:\.\.\/)?\/?storage\/files\/([^"']+)(["'][^>]*>)/g,
(match, prefix, filePath, suffix) => {
return `${prefix}${baseUrl}${filePath}${suffix}`
}
return baseUrl
})
// 替换 /storage/files(排除已经包含 http:// 或 https:// 的情况,以及已经替换过的)
content = content.replace(/\/storage\/files/g, (match, offset) => {
// 检查前面是否有 http:// 或 https://
const before = content.substring(Math.max(0, offset - 50), offset)
if (before.indexOf('http://') !== -1 || before.indexOf('https://') !== -1) {
return match
}
// 检查是否已经包含基础URL(避免重复替换)
if (before.indexOf(baseUrl) !== -1) {
return match
}
return baseUrl
})
)
return content
})()
@ -966,30 +952,14 @@ export default {
sort:this.form.sort,
content: (() => {
let content = this.form.content || ''
const baseUrl = `${process.env.VUE_APP_BASE_API}storage/files`
// 使用正则表达式,只替换不包含 http:// 或 https:// 的相对路径
// 替换 ../storage/files(排除已经包含 http:// 或 https:// 的情况)
content = content.replace(/\.\.\/storage\/files/g, (match, offset) => {
// 检查前面是否有 http:// 或 https://
const before = content.substring(Math.max(0, offset - 50), offset)
if (before.indexOf('http://') !== -1 || before.indexOf('https://') !== -1) {
return match
const apiBase = (process.env.VUE_APP_BASE_API || '').replace(/\/$/, '')
const baseUrl = `${apiBase}/storage/files/`
content = content.replace(
/(<img[^>]+src=["'])(?:\.\.\/)?\/?storage\/files\/([^"']+)(["'][^>]*>)/g,
(match, prefix, filePath, suffix) => {
return `${prefix}${baseUrl}${filePath}${suffix}`
}
return baseUrl
})
// 替换 /storage/files(排除已经包含 http:// 或 https:// 的情况,以及已经替换过的)
content = content.replace(/\/storage\/files/g, (match, offset) => {
// 检查前面是否有 http:// 或 https://
const before = content.substring(Math.max(0, offset - 50), offset)
if (before.indexOf('http://') !== -1 || before.indexOf('https://') !== -1) {
return match
}
// 检查是否已经包含基础URL(避免重复替换)
if (before.indexOf(baseUrl) !== -1) {
return match
}
return baseUrl
})
)
return content
})(),
// audit_status:1
@ -1084,3 +1054,4 @@ export default {
}
}
</style>

@ -602,30 +602,16 @@
end_time: this.form.time[1],
content: (() => {
let content = this.form.content || ''
const baseUrl = `${process.env.VUE_APP_BASE_API}storage/files`
// 使用正则表达式,只替换不包含 http:// 或 https:// 的相对路径
// 替换 ../storage/files(排除已经包含 http:// 或 https:// 的情况)
content = content.replace(/\.\.\/storage\/files/g, (match, offset) => {
// 检查前面是否有 http:// 或 https://
const before = content.substring(Math.max(0, offset - 50), offset)
if (before.indexOf('http://') !== -1 || before.indexOf('https://') !== -1) {
return match
// 去掉末尾的 /,避免出现 //storage/files
const apiBase = (process.env.VUE_APP_BASE_API || '').replace(/\/$/, '')
const baseUrl = `${apiBase}/storage/files/`
// 只处理 img 标签中 src 以 /storage/files 或 ../storage/files 开头的情况
content = content.replace(
/(<img[^>]+src=["'])(?:\.\.\/)?\/?storage\/files\/([^"']+)(["'][^>]*>)/g,
(match, prefix, filePath, suffix) => {
return `${prefix}${baseUrl}${filePath}${suffix}`
}
return baseUrl
})
// 替换 /storage/files(排除已经包含 http:// 或 https:// 的情况,以及已经替换过的)
content = content.replace(/\/storage\/files/g, (match, offset) => {
// 检查前面是否有 http:// 或 https://
const before = content.substring(Math.max(0, offset - 50), offset)
if (before.indexOf('http://') !== -1 || before.indexOf('https://') !== -1) {
return match
}
// 检查是否已经包含基础URL(避免重复替换)
if (before.indexOf(baseUrl) !== -1) {
return match
}
return baseUrl
})
)
return content
})()
}).then(res => {
@ -664,30 +650,14 @@
end_time: this.form.time[1],
content: (() => {
let content = this.form.content || ''
const baseUrl = `${process.env.VUE_APP_BASE_API}storage/files`
// 使用正则表达式,只替换不包含 http:// 或 https:// 的相对路径
// 替换 ../storage/files(排除已经包含 http:// 或 https:// 的情况)
content = content.replace(/\.\.\/storage\/files/g, (match, offset) => {
// 检查前面是否有 http:// 或 https://
const before = content.substring(Math.max(0, offset - 50), offset)
if (before.indexOf('http://') !== -1 || before.indexOf('https://') !== -1) {
return match
}
return baseUrl
})
// 替换 /storage/files(排除已经包含 http:// 或 https:// 的情况,以及已经替换过的)
content = content.replace(/\/storage\/files/g, (match, offset) => {
// 检查前面是否有 http:// 或 https://
const before = content.substring(Math.max(0, offset - 50), offset)
if (before.indexOf('http://') !== -1 || before.indexOf('https://') !== -1) {
return match
}
// 检查是否已经包含基础URL(避免重复替换)
if (before.indexOf(baseUrl) !== -1) {
return match
const apiBase = (process.env.VUE_APP_BASE_API || '').replace(/\/$/, '')
const baseUrl = `${apiBase}/storage/files/`
content = content.replace(
/(<img[^>]+src=["'])(?:\.\.\/)?\/?storage\/files\/([^"']+)(["'][^>]*>)/g,
(match, prefix, filePath, suffix) => {
return `${prefix}${baseUrl}${filePath}${suffix}`
}
return baseUrl
})
)
return content
})()
}).then(res => {

Loading…
Cancel
Save