From 4310d2dea332c53970e130565e7e6d82129f00cf Mon Sep 17 00:00:00 2001 From: yanyilin Date: Mon, 30 Oct 2023 15:23:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=BA=90uni.exit=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uni-exit/changelog.md | 0 uni_modules/uni-exit/package.json | 93 +++++++++++++++++++ uni_modules/uni-exit/readme.md | 6 ++ .../uni-exit/utssdk/app-android/index.uts | 15 +++ uni_modules/uni-exit/utssdk/app-ios/index.uts | 13 +++ uni_modules/uni-exit/utssdk/interface.uts | 63 +++++++++++++ uni_modules/uni-exit/utssdk/unierror.uts | 20 ++++ 7 files changed, 210 insertions(+) create mode 100644 uni_modules/uni-exit/changelog.md create mode 100644 uni_modules/uni-exit/package.json create mode 100644 uni_modules/uni-exit/readme.md create mode 100644 uni_modules/uni-exit/utssdk/app-android/index.uts create mode 100644 uni_modules/uni-exit/utssdk/app-ios/index.uts create mode 100644 uni_modules/uni-exit/utssdk/interface.uts create mode 100644 uni_modules/uni-exit/utssdk/unierror.uts diff --git a/uni_modules/uni-exit/changelog.md b/uni_modules/uni-exit/changelog.md new file mode 100644 index 0000000..e69de29 diff --git a/uni_modules/uni-exit/package.json b/uni_modules/uni-exit/package.json new file mode 100644 index 0000000..88b270d --- /dev/null +++ b/uni_modules/uni-exit/package.json @@ -0,0 +1,93 @@ +{ + "id": "uni-exit", + "displayName": "uni-exit", + "version": "1.0.0", + "description": "uni-exit", + "keywords": [ + "uni-exit" + ], + "repository": "", + "engines": { + "HBuilderX": "^3.6.8" + }, + "dcloudext": { + "type": "uts", + "sale": { + "regular": { + "price": "0.00" + }, + "sourcecode": { + "price": "0.00" + } + }, + "contact": { + "qq": "" + }, + "declaration": { + "ads": "", + "data": "", + "permissions": "" + }, + "npmurl": "" + }, + "uni_modules": { + "dependencies": [], + "uni-ext-api": { + "uni": { + "exit": { + "name": "exit", + "app": { + "js": true, + "kotlin": true, + "swift": true + } + } + } + }, + "encrypt": [], + "platforms": { + "cloud": { + "tcb": "u", + "aliyun": "u" + }, + "client": { + "Vue": { + "vue2": "y", + "vue3": "y" + }, + "App": { + "app-android": "y", + "app-ios": "u" + }, + "H5-mobile": { + "Safari": "u", + "Android Browser": "u", + "微信浏览器(Android)": "u", + "QQ浏览器(Android)": "u" + }, + "H5-pc": { + "Chrome": "u", + "IE": "u", + "Edge": "u", + "Firefox": "u", + "Safari": "u" + }, + "小程序": { + "微信": "u", + "阿里": "u", + "百度": "u", + "字节跳动": "u", + "QQ": "u", + "钉钉": "u", + "快手": "u", + "飞书": "u", + "京东": "u" + }, + "快应用": { + "华为": "u", + "联盟": "u" + } + } + } + } +} \ No newline at end of file diff --git a/uni_modules/uni-exit/readme.md b/uni_modules/uni-exit/readme.md new file mode 100644 index 0000000..5f87433 --- /dev/null +++ b/uni_modules/uni-exit/readme.md @@ -0,0 +1,6 @@ +# uni-quit +### 开发文档 +[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html) +[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html) +[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html) +[Hello UTS](https://gitcode.net/dcloud/hello-uts) \ No newline at end of file diff --git a/uni_modules/uni-exit/utssdk/app-android/index.uts b/uni_modules/uni-exit/utssdk/app-android/index.uts new file mode 100644 index 0000000..a999812 --- /dev/null +++ b/uni_modules/uni-exit/utssdk/app-android/index.uts @@ -0,0 +1,15 @@ +import { ExitOptions, ExitSuccess, ExitCompleteCallback, Exit } from "../interface.uts" + + +/** + * 实现uni.exit + */ +export const exit : Exit = function (options: ExitOptions | null) { + let ret : ExitSuccess ={ + errMsg: "exit:ok" + } + options?.success?.(ret) + options?.complete?.(ret) + UTSAndroid.exit() +} + diff --git a/uni_modules/uni-exit/utssdk/app-ios/index.uts b/uni_modules/uni-exit/utssdk/app-ios/index.uts new file mode 100644 index 0000000..77a5905 --- /dev/null +++ b/uni_modules/uni-exit/utssdk/app-ios/index.uts @@ -0,0 +1,13 @@ +import { ExitOptions, ExitFailCallback, ExitCompleteCallback, Exit} from "../interface.uts" +import { UniErrorSubject, UniErrors } from "../unierror.uts" + + +/** + * 实现uni.exit + * iOS平台不支持,触发错误回调 + */ +export const exit : Exit = function (options: ExitOptions | null) { + let err = new UniError(UniErrorSubject, 12001, UniErrors.get(12001)!); + options?.fail?.(err) + options?.complete?.(err) +} diff --git a/uni_modules/uni-exit/utssdk/interface.uts b/uni_modules/uni-exit/utssdk/interface.uts new file mode 100644 index 0000000..0df1394 --- /dev/null +++ b/uni_modules/uni-exit/utssdk/interface.uts @@ -0,0 +1,63 @@ +/** + * uni.exit成功回调参数 + */ +export type ExitSuccess = { + errMsg: string +} + +/** + * uni.exit成功回调函数定义 + */ +export type ExitSuccessCallback = (res: ExitSuccess) => void +/** + * uni.exit失败回调函数定义 + */ +export type ExitFailCallback = (res: UniError) => void +/** + * uni.exit完成回调函数定义 + */ +export type ExitCompleteCallback = (res: any) => void + +/** + * uni.exit参数定义 + */ +export type ExitOptions = { + /** + * 接口调用成功的回调函数 + */ + success?: ExitSuccessCallback | null, + /** + * 接口调用失败的回调函数 + */ + fail?: ExitFailCallback | null, + /** + * 接口调用结束的回调函数(调用成功、失败都会执行) + */ + complete?: ExitCompleteCallback | null +} + + +export interface Uni { + + /** + * 退出当前应用 + * @uniPlatform { + * "app": { + * "android": { + * "osVer": "4.4.4", + * "uniVer": "3.8.15", + * "unixVer": "3.9.0" + * }, + * "ios": { + * "osVer": "x", + * "uniVer": "x", + * "unixVer": "x" + * } + * } + * } + * @uniVueVersion 2,3 //支持的vue版本 + */ + exit(options?: ExitOptions | null):void; +} + +export type Exit = (options?: ExitOptions | null) => void; diff --git a/uni_modules/uni-exit/utssdk/unierror.uts b/uni_modules/uni-exit/utssdk/unierror.uts new file mode 100644 index 0000000..68bbd48 --- /dev/null +++ b/uni_modules/uni-exit/utssdk/unierror.uts @@ -0,0 +1,20 @@ +/** + * 错误主题 + */ +export const UniErrorSubject = 'uni-exit'; + + +/** + * 错误码 + * @UniError + */ +export const UniErrors:Map = new Map([ + /** + * 系统不支持 + */ + [12001, 'system not support'], + /** + * 未知错误 + */ + [12002, 'unknown error'] +]); -- GitLab