SOURCE

/**
 * 图片路径适配器
 * @param photoUrl
 */
export function photoUrlAdapter(photoUrl) {
  if (photoUrl.startsWith('http://mz.go577.com/')) {
    return photoUrl.replace('http://mz.go577.com/', 'https://wzbzdm.wzmz.wenzhou.gov.cn/mz_qiniu/');
  }

  if (photoUrl.startsWith('https://wzbzdm.wzmz.wenzhou.gov.cn/mz_qiniu/')) {
    return photoUrl;
  }

  if (photoUrl.startsWith('https://static.dingtalk.com/')) {
    return photoUrl;
  }

  if (photoUrl.startsWith('http')) {
    return `https://wzbzdm.wzmz.wenzhou.gov.cn/qiniu/${new URL(photoUrl).pathname}`;
  }

  if (photoUrl.startsWith('/mz_qiniu')) {
    return `https://wzbzdm.wzmz.wenzhou.gov.cn/${photoUrl}`;
  }

  return `https://wzbzdm.wzmz.wenzhou.gov.cn/qiniu/${photoUrl}`;
}

export function formPhotoAdapter(photo) {
  if (photo == null) {
    return [];
  }
  const arr = typeof photo === 'string' ? photo?.split(';') ?? [] : photo;
  return arr.map((item) => {
    let url = '';
    if (typeof item == 'string') {
      url = item;
    } else {
      url = item.url;
    }
    return photoUrlAdapter(url);
  });
}

// 使用例子:
// const photoUrl = formPhotoAdapter(photo)
console 命令行工具 X clear

                    
>
console