mirror of
https://gitee.com/yudaocode/yudao-mall-uniapp.git
synced 2025-12-30 09:42:25 +00:00
refactor(helper): 优化图片URL检查逻辑并增加空值处理
- 使用更清晰的startsWith方法替代substring进行URL检查 - 增加对空值和非法类型的处理 - 简化http到https的转换逻辑
This commit is contained in:
@@ -19,15 +19,19 @@ export default {
|
||||
* @param {String} url -图片地址
|
||||
*/
|
||||
checkMPUrl(url) {
|
||||
if (!url || typeof url !== 'string') {
|
||||
return url;
|
||||
}
|
||||
|
||||
// #ifdef MP
|
||||
if (
|
||||
url.substring(0, 4) === 'http' &&
|
||||
url.substring(0, 5) !== 'https' &&
|
||||
url.substring(0, 12) !== 'http://store' &&
|
||||
url.substring(0, 10) !== 'http://tmp' &&
|
||||
url.substring(0, 10) !== 'http://usr'
|
||||
url.startsWith('http://') &&
|
||||
!url.startsWith('https://') &&
|
||||
!url.startsWith('http://store') &&
|
||||
!url.startsWith('http://tmp') &&
|
||||
!url.startsWith('http://usr')
|
||||
) {
|
||||
url = 'https' + url.substring(4, url.length);
|
||||
url = url.replace('http://', 'https://');
|
||||
}
|
||||
// #endif
|
||||
return url;
|
||||
|
||||
Reference in New Issue
Block a user