'f'
mh-two-thousand-and-two
2024-04-12 26f2711ef9461961fb953e2b497bd314ef95e345
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import getRealRoute from 'uni-helpers/get-real-route'
 
const SCHEME_RE = /^([a-z-]+:)?\/\//i
const DATA_RE = /^data:.*,.*/
 
function addBase (filePath) {
  const base = __uniConfig.router.base
  if (!base) {
    return filePath
  }
  if (base !== '/') {
    // 部分地址已经带了base(如被webpack处理过的资源自动带了publicPath)
    if (('/' + filePath).indexOf(base) === 0) {
      return '/' + filePath
    }
  }
  return base + filePath
}
 
export default function getRealPath (filePath) {
  // 相对路径模式对静态资源路径特殊处理
  if (__uniConfig.router.base === './') {
    filePath = filePath.replace(/^\.\/static\//, '/static/')
  }
  if (filePath.indexOf('/') === 0) {
    if (filePath.indexOf('//') === 0) {
      filePath = 'https:' + filePath
    } else {
      return addBase(filePath.substr(1))
    }
  }
  // 网络资源或base64
  if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf('blob:') === 0) {
    return filePath
  }
 
  const pages = getCurrentPages()
  if (pages.length) {
    return addBase(getRealRoute(pages[pages.length - 1].$page.route, filePath).substr(1))
  }
 
  return filePath
}