Skip to content

Commit

Permalink
fix: 解决 svg 或非 base64 格式的 Data URI 无法使用的问题 fixed #668
Browse files Browse the repository at this point in the history
  • Loading branch information
zhetengbiji committed Sep 5, 2019
1 parent 402c2f2 commit 3a6811d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/core/view/components/canvas/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export default {
if (window.plus && src.indexOf('http://') !== 0 && src.indexOf('https://') !==
0) {
loadFile(src)
} else if (/^data:[a-z-]+\/[a-z-]+;base64,/.test(src)) {
} else if (/^data:.*,.*/.test(src)) {
sefl._images[src].src = src
} else {
loadUrl(src)
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/app-plus/helpers/get-real-path.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import getRealRoute from 'uni-helpers/get-real-route'

const SCHEME_RE = /^([a-z-]+:)?\/\//i
const BASE64_RE = /^data:[a-z-]+\/[a-z-]+;base64,/
const DATA_RE = /^data:.*,.*/

function addBase (filePath) {
return filePath
Expand All @@ -16,7 +16,7 @@ export default function getRealPath (filePath) {
}
}
// 网络资源或base64
if (SCHEME_RE.test(filePath) || BASE64_RE.test(filePath) || filePath.indexOf('blob:') === 0) {
if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf('blob:') === 0) {
return filePath
}

Expand Down
4 changes: 2 additions & 2 deletions src/platforms/app-plus/service/api/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ const _handleLocalPath = filePath => {

export function getRealPath (filePath) {
const SCHEME_RE = /^([a-z-]+:)?\/\//i
const BASE64_RE = /^data:[a-z-]+\/[a-z-]+;base64,/
const DATA_RE = /^data:.*,.*/

// 无协议的情况补全 https
if (filePath.indexOf('//') === 0) {
filePath = 'https:' + filePath
}

// 网络资源或base64
if (SCHEME_RE.test(filePath) || BASE64_RE.test(filePath)) {
if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath)) {
return filePath
}

Expand Down
4 changes: 2 additions & 2 deletions src/platforms/h5/helpers/get-real-path.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import getRealRoute from 'uni-helpers/get-real-route'

const SCHEME_RE = /^([a-z-]+:)?\/\//i
const BASE64_RE = /^data:[a-z-]+\/[a-z-]+;base64,/
const DATA_RE = /^data:.*,.*/

function addBase (filePath) {
if (__uniConfig.router.base) {
Expand All @@ -19,7 +19,7 @@ export default function getRealPath (filePath) {
}
}
// 网络资源或base64
if (SCHEME_RE.test(filePath) || BASE64_RE.test(filePath) || filePath.indexOf('blob:') === 0) {
if (SCHEME_RE.test(filePath) || DATA_RE.test(filePath) || filePath.indexOf('blob:') === 0) {
return filePath
}

Expand Down

0 comments on commit 3a6811d

Please sign in to comment.