yh-uniapp/utils/index.js

42 lines
766 B
JavaScript
Raw Normal View History

2024-12-06 14:01:20 +08:00
import {isExternal} from "@/utils/validate";
import {baseUrl} from "@/config";
/**
* 判断是否空字符串
*/
export function isBlank(str) {
return str == null || str === '';
}
/**
* 字符串转换为数组
*/
export function strToList(str, split = ',') {
if (isBlank(str)) {
return [];
}
if (str instanceof Array) {
return str;
}
return str.split(split);
}
export function getRealUrl(url) {
return url.substring(0, url.lastIndexOf('?'))
}
export function isEmpty(obj) {
return obj == null || obj.length === 0;
}
/**
* 转换本地URL若是本地URL则加前缀否则直接返回
* @param url
*/
export function parseLocalUrl(url) {
if (isEmpty(url) || isExternal(url)) {
return url;
}
return baseUrl + url;
}