提交 29cf2a08 编写于 作者: Q qiang

fix: 支持传入平台绝对路径

上级 fa4ba943
...@@ -22,10 +22,13 @@ function addBase (filePath) { ...@@ -22,10 +22,13 @@ function addBase (filePath) {
export default function getRealPath (filePath) { export default function getRealPath (filePath) {
if (filePath.indexOf('/') === 0) { if (filePath.indexOf('/') === 0) {
if (filePath.indexOf('//') === 0) { if (filePath.indexOf('//') === 0) {
filePath = 'https:' + filePath return 'https:' + filePath
} else {
return addBase(filePath.substr(1))
} }
// 平台绝对路径 安卓、iOS
if (filePath.startsWith('/storage/') || filePath.includes('/Containers/Data/Application/')) {
return 'file://' + filePath
}
return addBase(filePath.substr(1))
} }
// 网络资源或base64 // 网络资源或base64
if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf('blob:') === 0) { if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf('blob:') === 0) {
...@@ -43,4 +46,4 @@ export default function getRealPath (filePath) { ...@@ -43,4 +46,4 @@ export default function getRealPath (filePath) {
} }
return filePath return filePath
} }
...@@ -60,7 +60,7 @@ export function getRealPath (filePath) { ...@@ -60,7 +60,7 @@ export function getRealPath (filePath) {
// 无协议的情况补全 https // 无协议的情况补全 https
if (filePath.indexOf('//') === 0) { if (filePath.indexOf('//') === 0) {
filePath = 'https:' + filePath return 'https:' + filePath
} }
// 网络资源或base64 // 网络资源或base64
...@@ -75,6 +75,10 @@ export function getRealPath (filePath) { ...@@ -75,6 +75,10 @@ export function getRealPath (filePath) {
const wwwPath = 'file://' + _handleLocalPath('_www') const wwwPath = 'file://' + _handleLocalPath('_www')
// 绝对路径转换为本地文件系统路径 // 绝对路径转换为本地文件系统路径
if (filePath.indexOf('/') === 0) { if (filePath.indexOf('/') === 0) {
// 平台绝对路径 安卓、iOS
if (filePath.startsWith('/storage/') || filePath.includes('/Containers/Data/Application/')) {
return 'file://' + filePath
}
return wwwPath + filePath return wwwPath + filePath
} }
// 相对资源 // 相对资源
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册