|
@@ -4,6 +4,7 @@ import { FormData, File, FileUpload } from "@ohos/commons-fileupload"
|
|
import fs from '@ohos.file.fs';
|
|
import fs from '@ohos.file.fs';
|
|
import { ProgressDialog } from '../components/ProgressDialog';
|
|
import { ProgressDialog } from '../components/ProgressDialog';
|
|
import JGRequest, { JGRequestBaseUrl } from './Request';
|
|
import JGRequest, { JGRequestBaseUrl } from './Request';
|
|
|
|
+import web_webview from '@ohos.web.webview';
|
|
|
|
|
|
const TAG = "openHarmonyBridge upload"
|
|
const TAG = "openHarmonyBridge upload"
|
|
|
|
|
|
@@ -18,6 +19,7 @@ interface BridgeParams {
|
|
apiUrlPath?: string //上传完成后调的接口 不包含baseurl
|
|
apiUrlPath?: string //上传完成后调的接口 不包含baseurl
|
|
method?: string
|
|
method?: string
|
|
stationIP?: string
|
|
stationIP?: string
|
|
|
|
+ messageKey?: string //web端会进行window.addEventListener('messageKey' 然后把url整体传回去, 为了后续定义传回去对象的json {fullUrl: ''}
|
|
}
|
|
}
|
|
|
|
|
|
// 上传文件后,返回一个图片的url,然后再调用其他接口上传url和一些值, 如果有其他接口需要key,在这里添加,然后在下面赋值就行了
|
|
// 上传文件后,返回一个图片的url,然后再调用其他接口上传url和一些值, 如果有其他接口需要key,在这里添加,然后在下面赋值就行了
|
|
@@ -38,7 +40,10 @@ interface FileDataModel {
|
|
|
|
|
|
class UploadUtil {
|
|
class UploadUtil {
|
|
private baseUrl: string = JGRequestBaseUrl
|
|
private baseUrl: string = JGRequestBaseUrl
|
|
|
|
+ private fileUrl: string = "http://10.88.11.201:9000" //上传完成后可以查看的
|
|
private uploadPath: string = "/api/v1/base/upload"
|
|
private uploadPath: string = "/api/v1/base/upload"
|
|
|
|
+ controller: web_webview.WebviewController | null = null
|
|
|
|
+ ports: web_webview.WebMessagePort[] = [];
|
|
|
|
|
|
private constructor() {
|
|
private constructor() {
|
|
}
|
|
}
|
|
@@ -60,6 +65,8 @@ class UploadUtil {
|
|
}
|
|
}
|
|
|
|
|
|
startUpload(uri: string, callBack: () => void) {
|
|
startUpload(uri: string, callBack: () => void) {
|
|
|
|
+
|
|
|
|
+
|
|
// console.log(TAG, "token", this.token === this.uploadParams)
|
|
// console.log(TAG, "token", this.token === this.uploadParams)
|
|
// 开始上传
|
|
// 开始上传
|
|
try {
|
|
try {
|
|
@@ -120,6 +127,15 @@ class UploadUtil {
|
|
data: data
|
|
data: data
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (this.uploadParams.messageKey) {
|
|
|
|
+ uploadInstance.ports = uploadInstance.controller!.createWebMessagePorts();
|
|
|
|
+ uploadInstance.controller!.postMessage(JSON.stringify({
|
|
|
|
+ fullUrl: this.fileUrl + result.data?.fileUrl ?? "",
|
|
|
|
+ messageKey: this.uploadParams.messageKey ?? ""
|
|
|
|
+ }), [uploadInstance.ports[0]], '*');
|
|
|
|
+ }
|
|
|
|
+
|
|
callBack()
|
|
callBack()
|
|
|
|
|
|
//上传完成后浏览器可以产看的图片地址 http://10.88.11.201:9000
|
|
//上传完成后浏览器可以产看的图片地址 http://10.88.11.201:9000
|