yunzerwebsiteallinone/platform/src/utils/url.js
2026-06-03 10:09:03 +08:00

43 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* URL工具函数
*/
/**
* 获取完整的文件URL
* 如果URL已经是完整URLhttp://或https://开头),直接返回
* 否则拼接API基础URL
* @param {string} url - 文件URL或路径
* @returns {string} 完整的URL
*/
export function getFileUrl(url) {
if (!url) return '';
// 如果URL已经是完整的URL以http://或https://开头),直接返回
if (url.startsWith('http://') || url.startsWith('https://')) {
return url;
}
// 否则拼接API基础URL
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || '';
return `${API_BASE_URL}${url}`;
}
/**
* 获取环境URLgetEnvUrl的别名
* @param {string} path - 文件路径
* @returns {string} 完整的URL
*/
export function getEnvUrl(path) {
return getFileUrl(path);
}
/**
* 判断URL是否是完整URL
* @param {string} url - URL字符串
* @returns {boolean} 是否是完整URL
*/
export function isFullUrl(url) {
if (!url) return false;
return url.startsWith('http://') || url.startsWith('https://');
}