From 4583c434475c37aada7bc7881dff0a83b80475d4 Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Fri, 27 Feb 2026 16:59:33 +0800 Subject: [PATCH] tupian --- src/views/activity/component/addActivity.vue | 63 +++++-------------- .../productService/components/addProduct.vue | 62 +++++------------- 2 files changed, 33 insertions(+), 92 deletions(-) diff --git a/src/views/activity/component/addActivity.vue b/src/views/activity/component/addActivity.vue index bf0f72c..76c5a43 100644 --- a/src/views/activity/component/addActivity.vue +++ b/src/views/activity/component/addActivity.vue @@ -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( + /(]+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( + /(]+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 { } } + diff --git a/src/views/productService/components/addProduct.vue b/src/views/productService/components/addProduct.vue index aa4a7d7..4e0ae44 100644 --- a/src/views/productService/components/addProduct.vue +++ b/src/views/productService/components/addProduct.vue @@ -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( + /(]+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( + /(]+src=["'])(?:\.\.\/)?\/?storage\/files\/([^"']+)(["'][^>]*>)/g, + (match, prefix, filePath, suffix) => { + return `${prefix}${baseUrl}${filePath}${suffix}` } - return baseUrl - }) + ) return content })() }).then(res => {