From b34fdbe6e4e0a2079f3f40bcdbdf4d98c292a41a Mon Sep 17 00:00:00 2001 From: qiang Date: Mon, 19 Apr 2021 15:01:22 +0800 Subject: [PATCH] fix(h5): filePath --- .../uni-api/src/protocols/file/getFileInfo.ts | 10 ++++++++ .../src/protocols/file/openDocument.ts | 10 ++++++++ .../src/protocols/network/uploadFile.ts | 7 ++++++ packages/uni-h5/dist/uni-h5.esm.js | 23 +++++++++++++++++-- .../src/service/api/file/getFileInfo.ts | 4 +++- .../src/service/api/file/openDocument.ts | 4 +++- 6 files changed, 54 insertions(+), 4 deletions(-) diff --git a/packages/uni-api/src/protocols/file/getFileInfo.ts b/packages/uni-api/src/protocols/file/getFileInfo.ts index 4556e4e3c..e4aec8d88 100644 --- a/packages/uni-api/src/protocols/file/getFileInfo.ts +++ b/packages/uni-api/src/protocols/file/getFileInfo.ts @@ -1,6 +1,16 @@ +import { getRealPath } from '@dcloudio/uni-platform' + export const API_GET_FILE_INFO = 'getFileInfo' export type API_TYPE_GET_FILE_INFO = typeof uni.getFileInfo +export const GetFileInfoOptions: ApiOptions = { + formatArgs: { + filePath(filePath, params) { + params.filePath = getRealPath(filePath) + }, + }, +} + export const GetFileInfoProtocol: ApiProtocol = { filePath: { type: String, diff --git a/packages/uni-api/src/protocols/file/openDocument.ts b/packages/uni-api/src/protocols/file/openDocument.ts index be37ae790..18387045c 100644 --- a/packages/uni-api/src/protocols/file/openDocument.ts +++ b/packages/uni-api/src/protocols/file/openDocument.ts @@ -1,6 +1,16 @@ +import { getRealPath } from '@dcloudio/uni-platform' + export const API_OPEN_DOCUMENT = 'openDocument' export type API_TYPE_OPEN_DOCUMENT = typeof uni.openDocument +export const OpenDocumentOptions: ApiOptions = { + formatArgs: { + filePath(filePath, params) { + params.filePath = getRealPath(filePath) + }, + }, +} + export const OpenDocumentProtocol: ApiProtocol = { filePath: { type: String, diff --git a/packages/uni-api/src/protocols/network/uploadFile.ts b/packages/uni-api/src/protocols/network/uploadFile.ts index 89d8d1b5e..d4e2dc021 100644 --- a/packages/uni-api/src/protocols/network/uploadFile.ts +++ b/packages/uni-api/src/protocols/network/uploadFile.ts @@ -1,7 +1,14 @@ +import { getRealPath } from '@dcloudio/uni-platform' + export const API_UPLOAD_FILE = 'uploadFile' export type API_TYPE_UPLOAD_FILE = typeof uni.uploadFile export const UploadFileOptions: ApiOptions = { formatArgs: { + filePath(filePath, params) { + if (filePath) { + params.filePath = getRealPath(filePath) + } + }, header(value: Record, params: Record) { params.header = value || {} }, diff --git a/packages/uni-h5/dist/uni-h5.esm.js b/packages/uni-h5/dist/uni-h5.esm.js index 1093468a1..3750df2cf 100644 --- a/packages/uni-h5/dist/uni-h5.esm.js +++ b/packages/uni-h5/dist/uni-h5.esm.js @@ -4550,6 +4550,13 @@ const API_REMOVE_STORAGE = "removeStorage"; const RemoveStorageProtocol = GetStorageProtocol; const RemoveStorageSyncProtocol = GetStorageSyncProtocol; const API_GET_FILE_INFO = "getFileInfo"; +const GetFileInfoOptions = { + formatArgs: { + filePath(filePath, params) { + params.filePath = getRealPath(filePath); + } + } +}; const GetFileInfoProtocol = { filePath: { type: String, @@ -4557,6 +4564,13 @@ const GetFileInfoProtocol = { } }; const API_OPEN_DOCUMENT = "openDocument"; +const OpenDocumentOptions = { + formatArgs: { + filePath(filePath, params) { + params.filePath = getRealPath(filePath); + } + } +}; const OpenDocumentProtocol = { filePath: { type: String, @@ -4797,6 +4811,11 @@ const DownloadFileProtocol = { const API_UPLOAD_FILE = "uploadFile"; const UploadFileOptions = { formatArgs: { + filePath(filePath, params) { + if (filePath) { + params.filePath = getRealPath(filePath); + } + }, header(value, params) { params.header = value || {}; }, @@ -11078,11 +11097,11 @@ const getFileInfo = defineAsyncApi(API_GET_FILE_INFO, ({filePath}, {resolve, rej }).catch((err) => { reject(String(err)); }); -}, GetFileInfoProtocol); +}, GetFileInfoProtocol, GetFileInfoOptions); const openDocument = defineAsyncApi(API_OPEN_DOCUMENT, ({filePath}, {resolve}) => { window.open(filePath); return resolve(); -}, OpenDocumentProtocol); +}, OpenDocumentProtocol, OpenDocumentOptions); function getServiceAddress() { return window.location.protocol + "//" + window.location.host; } diff --git a/packages/uni-h5/src/service/api/file/getFileInfo.ts b/packages/uni-h5/src/service/api/file/getFileInfo.ts index a5d0f4410..04143ac6c 100644 --- a/packages/uni-h5/src/service/api/file/getFileInfo.ts +++ b/packages/uni-h5/src/service/api/file/getFileInfo.ts @@ -3,6 +3,7 @@ import { API_GET_FILE_INFO, API_TYPE_GET_FILE_INFO, GetFileInfoProtocol, + GetFileInfoOptions, } from '@dcloudio/uni-api' import { urlToFile } from '../../../helpers/file' @@ -20,5 +21,6 @@ export const getFileInfo = defineAsyncApi( reject(String(err)) }) }, - GetFileInfoProtocol + GetFileInfoProtocol, + GetFileInfoOptions ) diff --git a/packages/uni-h5/src/service/api/file/openDocument.ts b/packages/uni-h5/src/service/api/file/openDocument.ts index ccd2195cd..1ebe54a7d 100644 --- a/packages/uni-h5/src/service/api/file/openDocument.ts +++ b/packages/uni-h5/src/service/api/file/openDocument.ts @@ -3,6 +3,7 @@ import { API_TYPE_OPEN_DOCUMENT, defineAsyncApi, OpenDocumentProtocol, + OpenDocumentOptions, } from '@dcloudio/uni-api' export const openDocument = defineAsyncApi( @@ -11,5 +12,6 @@ export const openDocument = defineAsyncApi( window.open(filePath) return resolve() }, - OpenDocumentProtocol + OpenDocumentProtocol, + OpenDocumentOptions ) -- GitLab