修复bug

This commit is contained in:
Your Name
2026-05-09 17:04:50 +08:00
parent 3330613254
commit 985916dea7
9 changed files with 582 additions and 54 deletions
+17 -2
View File
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
import { getConfig } from '@/api/app'
import configs from '@/config'
interface AppSate {
config: Record<string, any>
@@ -26,8 +27,22 @@ const useAppStore = defineStore({
getImageUrl(url: string) {
if (!url || typeof url !== 'string') return ''
if (url.startsWith('http://') || url.startsWith('https://')) return url
const domain = this.config.oss_domain || (typeof window !== 'undefined' ? window.location.origin + '/' : '')
return domain ? `${domain.replace(/\/$/, '')}${url.startsWith('/') ? url : '/' + url}` : url
const path = url.startsWith('/') ? url : '/' + url
const oss = String(this.config.oss_domain || '').replace(/\/$/, '')
if (oss) {
return `${oss}${path}`
}
// 开发环境:后台接口与 Vite 不同端口时,相对路径不能拼到 location.origin(应对接到 php 静态域名)
const apiRoot = String(configs.baseUrl || '/').replace(/\/+$/, '')
if (apiRoot.startsWith('http://') || apiRoot.startsWith('https://')) {
try {
return new URL(path, `${apiRoot}/`).href
} catch {
return `${apiRoot}${path}`
}
}
const origin = typeof window !== 'undefined' ? window.location.origin : ''
return origin ? `${origin}${path}` : path
},
getConfig() {
return new Promise((resolve, reject) => {