Files
yunzerwebsiteallinone/uniapp/api/config.js
T
2026-11-16 17:22:50 +08:00

95 lines
2.2 KiB
JavaScript

export const GEETEST4_CAPTCHA_ID = '75e8a175c43b9ecfa15372c658be05e5'
const DEFAULT_PROD_API = 'https://api.yunzer.cn'
function sanitizeMiniProgramBase(base) {
const b = String(base || '')
if (!b || b.startsWith('/') || !/^https:\/\//i.test(b) || /(localhost|127\.0\.0\.1)/i.test(b)) {
return DEFAULT_PROD_API
}
return b
}
export function resolveBaseURL() {
let fromEnv = ''
try {
fromEnv =
(typeof import.meta !== 'undefined' &&
import.meta.env &&
import.meta.env.VITE_API_BASE_URL) ||
''
} catch (e) {
fromEnv = ''
}
if (fromEnv && fromEnv !== 'undefined' && fromEnv !== 'null') {
// #ifdef MP
return sanitizeMiniProgramBase(String(fromEnv))
// #endif
// #ifndef MP
return String(fromEnv).replace(/\/$/, '')
// #endif
}
// #ifdef H5
if (typeof window !== 'undefined' && window.location) {
const { hostname, protocol } = window.location
if (hostname.includes('yunzer.cn')) {
return DEFAULT_PROD_API
}
if (
(hostname === 'localhost' || hostname === '127.0.0.1') &&
typeof import.meta !== 'undefined' &&
import.meta.env &&
import.meta.env.DEV
) {
return '/proxy-api'
}
if (hostname === 'localhost' || hostname === '127.0.0.1') {
return `${protocol}//${hostname}:9000`.replace(/\/$/, '')
}
}
// #endif
return DEFAULT_PROD_API
}
export function getBaseURL() {
return resolveBaseURL()
}
export function getWebConsoleBase() {
let base = ''
try {
base =
(typeof import.meta !== 'undefined' &&
import.meta.env &&
import.meta.env.VITE_WEB_CONSOLE_BASE) ||
''
} catch (e) {
base = ''
}
if (!base || base === 'undefined' || base === 'null') {
base = 'https://back.yunzer.cn'
}
return String(base).replace(/\/$/, '')
}
export function resolveWebConsoleURL(path) {
const p = String(path || '').trim()
if (!p) return ''
return `${getWebConsoleBase()}/#${p.startsWith('/') ? p : `/${p}`}`
}
export function resolveWebSSOURL(path, ticket) {
const p = String(path || '').trim()
if (!p) return ''
const target = p.startsWith('/') ? p : `/${p}`
if (!ticket) return resolveWebConsoleURL(target)
return `${getWebConsoleBase()}/#/app-login?ticket=${encodeURIComponent(ticket)}&redirect=${encodeURIComponent(target)}`
}