提交 ad27f1c6 编写于 作者: Q qiang

feat(App): getFileInfo

上级 0ae312ea
......@@ -39,7 +39,7 @@
"node": ">=10.0.0"
},
"devDependencies": {
"@dcloudio/types": "^2.2.7",
"@dcloudio/types": "^2.2.8",
"@microsoft/api-extractor": "^7.13.2",
"@rollup/plugin-alias": "^3.1.1",
"@rollup/plugin-commonjs": "^17.0.0",
......
......@@ -52,8 +52,14 @@ function invokeSuccess(id: number, name: string, res: unknown) {
return invokeCallback(id, extend(res || {}, { errMsg: name + ':ok' }))
}
function invokeFail(id: number, name: string, err: string) {
return invokeCallback(id, { errMsg: name + ':fail' + (err ? ' ' + err : '') })
function invokeFail(id: number, name: string, errMsg: string, errRes?: any) {
return invokeCallback(
id,
Object.assign(
{ errMsg: name + ':fail' + (errMsg ? ' ' + errMsg : '') },
errRes
)
)
}
function beforeInvokeApi<T extends ApiLike>(
......@@ -141,7 +147,8 @@ function wrapperTaskApi<T extends ApiLike>(
}
return fn(args, {
resolve: (res: unknown) => invokeSuccess(id, name, res),
reject: (err: string) => invokeFail(id, name, err),
reject: (errMsg: string, errRes?: any) =>
invokeFail(id, name, errMsg, errRes),
})
}
}
......@@ -223,7 +230,7 @@ export function defineAsyncApi<T extends AsyncApiLike, P = AsyncApiOptions<T>>(
args: Omit<P, CALLBACK_TYPES>,
res: {
resolve: (res?: AsyncApiRes<P>) => void
reject: (err?: string) => void
reject: (errMsg: string, errRes?: any) => void
}
) => void,
protocol?: ApiProtocols<T>,
......
interface PlusResult extends Record<string, any> {
code?: number
message?: string
}
type PlusError = PlusResult
export function warpPlusSuccessCallback(
resolve: (res: any) => void,
after?: (res: any) => any
) {
return function successCallback(data: PlusResult) {
delete data.code
delete data.message
if (typeof after === 'function') {
data = after(data)
}
resolve(data)
}
}
export function warpPlusErrorCallback(
reject: (errMsg: string, errRes?: any) => void,
errMsg?: string
) {
return function errorCallback(error: PlusError) {
error = error || {}
// 一键登录errorCallback新增 appid、metadata、uid 参数返回
errMsg = error.message || errMsg || ''
delete error.message
reject(errMsg, Object.assign({ code: 0 }, error))
}
}
import {
defineAsyncApi,
API_GET_FILE_INFO,
API_TYPE_GET_FILE_INFO,
GetFileInfoProtocol,
GetFileInfoOptions,
} from '@dcloudio/uni-api'
import {
warpPlusSuccessCallback,
warpPlusErrorCallback,
} from '../../../helpers/plus'
export const getFileInfo = <API_TYPE_GET_FILE_INFO>defineAsyncApi(
API_GET_FILE_INFO,
(options, { resolve, reject }) => {
plus.io.getFileInfo(
Object.assign(options, {
success: warpPlusSuccessCallback(resolve),
fail: warpPlusErrorCallback(reject),
})
)
},
GetFileInfoProtocol,
GetFileInfoOptions
)
export * from './file/getFileInfo'
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册