提交 f4c96be4 编写于 作者: DCloud_iOS_XHY's avatar DCloud_iOS_XHY

添加 uts alert 示例

上级 9cedb423
...@@ -26,6 +26,14 @@ ...@@ -26,6 +26,14 @@
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
},
{
"path" : "pages/SystemAPI/Alert/alert",
"style" :
{
"navigationBarTitleText": ""
}
}, },
{ {
"path" : "pages/SDKIntegration/SDKIntegration", "path" : "pages/SDKIntegration/SDKIntegration",
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
uni.navigateTo({ uni.navigateTo({
url:'/pages/SDKIntegration/TencentMap/TencentMap' url:'/pages/SDKIntegration/TencentMap/TencentMap'
}) })
}, }
} }
} }
</script> </script>
......
<template>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<button @tap="testShowAlert">确认框</button>
<button @tap="testShowPrompt">输入框</button>
</view>
</template>
<script>
import { showAlert,showPrompt } from '@/uni_modules/uts-alert'
export default {
data() {
return {
title:"Alert 示例"
}
},
methods:{
testShowAlert(){
showAlert("提示框","这是一个提示框", (index)=> {
var title = null
if (index == 0) {
title = "点击了确认"
} else{
title = "点击了取消"
}
uni.showToast({
title: title,
icon:'none'
})
})
},
testShowPrompt() {
showPrompt("输入框","这是一个输入框","请输入内容", (content)=>{
let title = content.length > 0 ? content : "没有输入内容"
uni.showToast({
title: title,
icon:'none'
})
})
}
}
}
</script>
<style>
</style>
\ No newline at end of file
...@@ -17,6 +17,14 @@ ...@@ -17,6 +17,14 @@
</uni-collapse-item> </uni-collapse-item>
</uni-collapse> </uni-collapse>
<uni-collapse>
<uni-collapse-item title="Alert系统弹窗" :border="false">
<uni-list>
<uni-list-item @tap="gotoAlert" title="Alert弹窗" class="itemButton" :clickable="true" link/>
</uni-list>
</uni-collapse-item>
</uni-collapse>
<uni-collapse> <uni-collapse>
<uni-collapse-item title="android平台" :border="false"> <uni-collapse-item title="android平台" :border="false">
<uni-list> <uni-list>
...@@ -57,11 +65,14 @@ ...@@ -57,11 +65,14 @@
url:'/pages/SystemAPI/ScreenListen/screenlisten' url:'/pages/SystemAPI/ScreenListen/screenlisten'
}) })
}, },
gotoAlert(){
uni.navigateTo({
url:'/pages/SystemAPI/Alert/alert'
})
},
testGotoDemoActivity() { testGotoDemoActivity() {
gotoDemoActivity(); gotoDemoActivity();
}, }
} }
} }
</script> </script>
......
// 引用 iOS 原生平台 api // 引用 iOS 原生平台 api
import { UIDevice } from "UIKit"; import { UIDevice } from "UIKit";
import { Int } from 'Swift';
/** /**
* 定义 接口参数 * 定义 接口参数
...@@ -21,7 +22,7 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) { ...@@ -21,7 +22,7 @@ export default function getBatteryInfo(options: GetBatteryInfoOptions) {
// 返回数据 // 返回数据
const res = { const res = {
errMsg: "getBatteryInfo:ok", errMsg: "getBatteryInfo:ok",
level: Number(UIDevice.current.batteryLevel * 10), level: new Int(UIDevice.current.batteryLevel * 100),
isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging, isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging,
}; };
options.success?.(res); options.success?.(res);
......
{
"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
# 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
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) {}
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册