From f4c96be40e6e13ac63305e4a682a3aca03475b74 Mon Sep 17 00:00:00 2001 From: XHY Date: Sat, 12 Nov 2022 15:52:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20uts=20alert=20=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages.json | 8 ++ pages/SDKIntegration/SDKIntegration.vue | 3 +- pages/SystemAPI/Alert/alert.vue | 50 ++++++++++++ pages/SystemAPI/SystemAPI.vue | 17 +++- .../utssdk/app-ios/index.uts | 3 +- uni_modules/uts-alert/changelog.md | 0 uni_modules/uts-alert/package.json | 81 +++++++++++++++++++ uni_modules/uts-alert/readme.md | 5 ++ .../uts-alert/utssdk/app-android/index.uts | 2 + .../uts-alert/utssdk/app-ios/index.uts | 63 +++++++++++++++ 10 files changed, 226 insertions(+), 6 deletions(-) create mode 100644 pages/SystemAPI/Alert/alert.vue create mode 100644 uni_modules/uts-alert/changelog.md create mode 100644 uni_modules/uts-alert/package.json create mode 100644 uni_modules/uts-alert/readme.md create mode 100644 uni_modules/uts-alert/utssdk/app-android/index.uts create mode 100644 uni_modules/uts-alert/utssdk/app-ios/index.uts diff --git a/pages.json b/pages.json index 425243e..2f049ca 100644 --- a/pages.json +++ b/pages.json @@ -26,6 +26,14 @@ "enablePullDownRefresh": false } + }, + { + "path" : "pages/SystemAPI/Alert/alert", + "style" : + { + "navigationBarTitleText": "" + } + }, { "path" : "pages/SDKIntegration/SDKIntegration", diff --git a/pages/SDKIntegration/SDKIntegration.vue b/pages/SDKIntegration/SDKIntegration.vue index 2dfe211..38f1ac7 100644 --- a/pages/SDKIntegration/SDKIntegration.vue +++ b/pages/SDKIntegration/SDKIntegration.vue @@ -33,8 +33,7 @@ uni.navigateTo({ url:'/pages/SDKIntegration/TencentMap/TencentMap' }) - }, - + } } } diff --git a/pages/SystemAPI/Alert/alert.vue b/pages/SystemAPI/Alert/alert.vue new file mode 100644 index 0000000..566a12e --- /dev/null +++ b/pages/SystemAPI/Alert/alert.vue @@ -0,0 +1,50 @@ + + + + + \ No newline at end of file diff --git a/pages/SystemAPI/SystemAPI.vue b/pages/SystemAPI/SystemAPI.vue index d4b6015..ae1ff7d 100644 --- a/pages/SystemAPI/SystemAPI.vue +++ b/pages/SystemAPI/SystemAPI.vue @@ -17,6 +17,14 @@ + + + + + + + + @@ -57,11 +65,14 @@ url:'/pages/SystemAPI/ScreenListen/screenlisten' }) }, - + gotoAlert(){ + uni.navigateTo({ + url:'/pages/SystemAPI/Alert/alert' + }) + }, testGotoDemoActivity() { gotoDemoActivity(); - }, - + } } } diff --git a/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts index fbb3cb0..7cc8256 100644 --- a/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts +++ b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts @@ -1,5 +1,6 @@ // 引用 iOS 原生平台 api import { UIDevice } from "UIKit"; +import { Int } from 'Swift'; /** * 定义 接口参数 @@ -21,7 +22,7 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) { // 返回数据 const res = { errMsg: "getBatteryInfo:ok", - level: Number(UIDevice.current.batteryLevel * 10), + level: new Int(UIDevice.current.batteryLevel * 100), isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging, }; options.success?.(res); diff --git a/uni_modules/uts-alert/changelog.md b/uni_modules/uts-alert/changelog.md new file mode 100644 index 0000000..e69de29 diff --git a/uni_modules/uts-alert/package.json b/uni_modules/uts-alert/package.json new file mode 100644 index 0000000..e44b074 --- /dev/null +++ b/uni_modules/uts-alert/package.json @@ -0,0 +1,81 @@ +{ + "id": "uni-alert", + "displayName": "uni-alert", + "version": "1.0.0", + "description": "uni-alert", + "keywords": [ + "uni-alert" +], + "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": [], + "encrypt": [], + "platforms": { + "cloud": { + "tcb": "u", + "aliyun": "u" + }, + "client": { + "Vue": { + "vue2": "u", + "vue3": "u" + }, + "App": { + "app-android": "u", + "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/uts-alert/readme.md b/uni_modules/uts-alert/readme.md new file mode 100644 index 0000000..07cba57 --- /dev/null +++ b/uni_modules/uts-alert/readme.md @@ -0,0 +1,5 @@ +# uni-alert +### 开发文档 +[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html) +[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html) +[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev) \ No newline at end of file diff --git a/uni_modules/uts-alert/utssdk/app-android/index.uts b/uni_modules/uts-alert/utssdk/app-android/index.uts new file mode 100644 index 0000000..13546a2 --- /dev/null +++ b/uni_modules/uts-alert/utssdk/app-android/index.uts @@ -0,0 +1,2 @@ +export function showAlert(title: string|null, message: string|null, result: (index: Number) => void) {} +export function showPrompt(title: string|null, message: string|null,placeholder: string|null, result: (content: string)=>void) {} diff --git a/uni_modules/uts-alert/utssdk/app-ios/index.uts b/uni_modules/uts-alert/utssdk/app-ios/index.uts new file mode 100644 index 0000000..af18cfc --- /dev/null +++ b/uni_modules/uts-alert/utssdk/app-ios/index.uts @@ -0,0 +1,63 @@ +import { UIAlertController , UIAlertAction , UITextField } from "UIKit" +import { uniViewController } from "DCUTSPlugin" +import { DispatchQueue } from 'Dispatch'; + +export function showAlert(title: string|null, message: string|null, result: (index: Number) => void) { + // uts方法默认会在子线程中执行,涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行 + DispatchQueue.main.async(execute=():void => { + + // 初始化 UIAlertController 实例对象 alert + let alert = new UIAlertController(title=title,message=message,preferredStyle=UIAlertController.Style.alert) + + // 创建 UIAlertAction 按钮 + let okAction = new UIAlertAction(title="确认", style=UIAlertAction.Style.default, handler=(action: UIAlertAction):void => { + // 点击按钮的回调方法 + result(0) + }) + + // 创建 UIAlertAction 按钮 + let cancelAction = new UIAlertAction(title="取消", style=UIAlertAction.Style.cancel, handler=(action: UIAlertAction):void => { + // 点击按钮的回调方法 + result(1) + }) + + // 将 UIAlertAction 添加到 alert 上 + alert.addAction(okAction) + alert.addAction(cancelAction) + + // 从 uniViewController 打开 alert 弹窗 + uniViewController().present(alert, animated= true) + }) +} + +export function showPrompt(title: string|null, message: string|null,placeholder: string|null, result: (content: string)=>void) { + // uts方法默认会在子线程中执行,涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行 + DispatchQueue.main.async(execute=():void => { + + // 初始化 UIAlertController 实例对象 alert + let alert = new UIAlertController(title=title,message=message,preferredStyle=UIAlertController.Style.alert) + + // 在 alert 上添加输入框 + alert.addTextField(configurationHandler=(tf: UITextField):void => { + // 添加成功的回调 + // 设置输入框的 placeholder + tf.placeholder = placeholder + }) + + // 创建 UIAlertAction 按钮 + let okAction = new UIAlertAction(title="确认", style=UIAlertAction.Style.default, handler=(action: UIAlertAction):void => { + // 点击按钮的回调方法 + // 获取输入框中的内容 + let tf = alert.textFields?.[0] + if (tf != null) { + result(tf!.text != null ? tf!.text! : "没有输入任何内容") + } + }) + + // 将 UIAlertAction 添加到 alert 上 + alert.addAction(okAction) + + // 从 uniViewController 打开 alert 弹窗 + uniViewController().present(alert, animated= true) + }) +} \ No newline at end of file -- GitLab