From 00b4e27a9bbb85107d66cbb8fa64aecbac2e2511 Mon Sep 17 00:00:00 2001 From: taohebin Date: Fri, 27 Oct 2023 18:02:21 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E9=81=B5=E5=BE=AAunierror=E8=A7=84?= =?UTF-8?q?=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uni-installApk/changelog.md | 2 + uni_modules/uni-installApk/package.json | 2 +- .../utssdk/app-android/index.uts | 5 +- .../uni-installApk/utssdk/interface.uts | 71 +++++++++++-------- .../uni-installApk/utssdk/unierror.uts | 25 +++++++ 5 files changed, 72 insertions(+), 33 deletions(-) create mode 100644 uni_modules/uni-installApk/utssdk/unierror.uts diff --git a/uni_modules/uni-installApk/changelog.md b/uni_modules/uni-installApk/changelog.md index d499b3c..f6c9583 100644 --- a/uni_modules/uni-installApk/changelog.md +++ b/uni_modules/uni-installApk/changelog.md @@ -1,3 +1,5 @@ +## 1.0.3(2023-10-27) +遵循UniError规范 ## 1.0.2(2023-10-27) 修改文档 ## 1.0.1(2023-10-27) diff --git a/uni_modules/uni-installApk/package.json b/uni_modules/uni-installApk/package.json index 70bb882..c388920 100644 --- a/uni_modules/uni-installApk/package.json +++ b/uni_modules/uni-installApk/package.json @@ -1,7 +1,7 @@ { "id": "uni-installApk", "displayName": "uni-installApk", - "version": "1.0.2", + "version": "1.0.3", "description": "uni-installApk", "keywords": [ "uni-installApk" diff --git a/uni_modules/uni-installApk/utssdk/app-android/index.uts b/uni_modules/uni-installApk/utssdk/app-android/index.uts index 4e2c22b..cfdef2e 100644 --- a/uni_modules/uni-installApk/utssdk/app-android/index.uts +++ b/uni_modules/uni-installApk/utssdk/app-android/index.uts @@ -1,4 +1,5 @@ -import { InstallApkOptions, InstallApkSuccess } from "../interface.uts" +import { InstallApkOptions, InstallApkSuccess } from "../interface.uts" +import { InstallApkFailImpl } from "../unierror.uts" import Intent from 'android.content.Intent'; import Build from 'android.os.Build'; import File from 'java.io.File'; @@ -11,7 +12,7 @@ export function installApk(options : InstallApkOptions) : void { const filePath = UTSAndroid.convert2AbsFullPath(options.filePath) const apkFile = new File(filePath) if (!apkFile.exists() && !apkFile.isFile()) { - let error = new UniError("uni-installApk", -1, "filePath is illegal"); + let error = new InstallApkFailImpl(1300002); options.fail?.(error) options.complete?.(error) return diff --git a/uni_modules/uni-installApk/utssdk/interface.uts b/uni_modules/uni-installApk/utssdk/interface.uts index e377fb7..35edfcd 100644 --- a/uni_modules/uni-installApk/utssdk/interface.uts +++ b/uni_modules/uni-installApk/utssdk/interface.uts @@ -1,33 +1,33 @@ export interface Uni { - /** - * installApk() - * @description - * 安装apk - * @param {InstallApkOptions} - * @return {void} - * @uniPlatform { - * "app": { - * "android": { - * "osVer": "4.4", - * "uniVer": "3.94+", - * "unixVer": "3.94+" - * }, - * "ios": { - * "osVer": "x", - * "uniVer": "x", - * "unixVer": "x" - * } - * } - * } - * @example - ```typescript - uni.installApk({ - filePath: "/xx/xx/xx.apk", - complete: (res: any) => { - console.log("complete => " + JSON.stringify(res)); - } - }); - ``` + /** + * installApk() + * @description + * 安装apk + * @param {InstallApkOptions} + * @return {void} + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4", + * "uniVer": "3.94+", + * "unixVer": "3.94+" + * }, + * "ios": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * } + * @example + ```typescript + uni.installApk({ + filePath: "/xx/xx/xx.apk", + complete: (res: any) => { + console.log("complete => " + JSON.stringify(res)); + } + }); + ``` */ installApk(options : InstallApkOptions) : void } @@ -39,7 +39,18 @@ export type InstallApkSuccess = { } export type InstallApkComplete = any export type InstallApkSuccessCallback = (res : InstallApkSuccess) => void -export type InstallApkFailCallback = (err : UniError) => void +/** + * 错误码 + * - 1300002 找不到文件 + */ +export type InstallApkErrorCode = 1300002 +/** + * 网络请求失败的错误回调参数 + */ +export interface InstallApkFail extends IUniError { + errCode : InstallApkErrorCode +}; +export type InstallApkFailCallback = (err : InstallApkFail) => void export type InstallApkCompleteCallback = (res : InstallApkComplete) => void export type InstallApkOptions = { diff --git a/uni_modules/uni-installApk/utssdk/unierror.uts b/uni_modules/uni-installApk/utssdk/unierror.uts new file mode 100644 index 0000000..a10c730 --- /dev/null +++ b/uni_modules/uni-installApk/utssdk/unierror.uts @@ -0,0 +1,25 @@ +import { InstallApkErrorCode, InstallApkFail } from "./interface.uts" + +/** + * 错误主题 + */ +export const UniErrorSubject = 'uni-installApk'; +/** + * 错误码 + * @UniError + */ +export const UniErrors : Map = new Map([ + /** + * 找不到文件 + */ + [1300002, 'No such file'], +]); + +export class InstallApkFailImpl extends UniError implements InstallApkFail { + constructor(errCode : InstallApkErrorCode) { + super(); + this.errSubject = UniErrorSubject; + this.errCode = errCode; + this.errMsg = UniErrors[errCode] ?? ""; + } +} \ No newline at end of file -- GitLab