diff --git a/src/core/view/components/canvas/index.vue b/src/core/view/components/canvas/index.vue
index 0af208f61a814e0845f87d0c3aa8bde70875f427..491dc871299e400d12e49682fb83149a66be9c9e 100644
--- a/src/core/view/components/canvas/index.vue
+++ b/src/core/view/components/canvas/index.vue
@@ -9,7 +9,16 @@
width="300"
height="150"
/>
-
+
{
+ image.src = src
+ }).catch(() => {
+ image.src = src
+ })
}
})
},
diff --git a/src/platforms/app-plus/helpers/file.js b/src/platforms/app-plus/helpers/file.js
new file mode 100644
index 0000000000000000000000000000000000000000..b2b122b1391b10c723bf337d5a4fbf5f848c075c
--- /dev/null
+++ b/src/platforms/app-plus/helpers/file.js
@@ -0,0 +1,52 @@
+function getBase64 (path) {
+ return new Promise(function (resolve, reject) {
+ // H5+ 沙箱外路径在iOS无法使用 plus.io 读取
+ function onError () {
+ const bitmap = new plus.nativeObj.Bitmap(`bitmap_${Date.now()}_${Math.random()}}`)
+ bitmap.load(path, function () {
+ resolve(bitmap.toBase64Data())
+ bitmap.clear()
+ }, function (err) {
+ bitmap.clear()
+ reject(err)
+ })
+ }
+ plus.io.resolveLocalFileSystemURL(path, function (entry) {
+ entry.file(function (file) {
+ var fileReader = new plus.io.FileReader()
+ fileReader.onload = function (data) {
+ resolve(data.target.result)
+ }
+ fileReader.onerror = onError
+ fileReader.readAsDataURL(file)
+ }, onError)
+ }, onError)
+ })
+}
+
+function download (url) {
+ return new Promise(function (resolve, reject) {
+ if (url.indexOf('http://') !== 0 && url.indexOf('https://') !== 0) {
+ resolve(url)
+ }
+ plus.downloader.createDownload(url, {
+ filename: '_doc/uniapp_temp/download/'
+ }, function (d, status) {
+ if (status === 200) {
+ resolve(d.filename)
+ } else {
+ reject(new Error('network fail'))
+ }
+ }).start()
+ })
+}
+
+export function getSameOriginUrl (url) {
+ return download(url).then(function (url) {
+ // WKWebView
+ if (window.webkit && window.webkit.messageHandlers) {
+ return getBase64(url)
+ }
+ return url
+ })
+}
diff --git a/src/platforms/h5/helpers/file.js b/src/platforms/h5/helpers/file.js
index 861ed8307927d8544cd623e9660e04aca8d2cf34..010852ad8f69ddddf7af4faa9129e11755ad5f4f 100644
--- a/src/platforms/h5/helpers/file.js
+++ b/src/platforms/h5/helpers/file.js
@@ -93,6 +93,15 @@ export function fileToUrl (file) {
return url
}
+export function getSameOriginUrl (url) {
+ const a = document.createElement('a')
+ a.href = url
+ if (a.origin === location.origin) {
+ return Promise.resolve(url)
+ }
+ return urlToFile(url).then(fileToUrl)
+}
+
export function revokeObjectURL (url) {
(window.URL || window.webkitURL).revokeObjectURL(url)
delete files[url]