提交 929f308b 编写于 作者: lizhongyi_'s avatar lizhongyi_

feat: iOS showModal 插件

上级 432d69d0
{ // launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/
{
// launch.json 配置了启动调试时相关设置,configurations下节点名称可为 app-plus/h5/mp-weixin/mp-baidu/mp-alipay/mp-qq/mp-toutiao/mp-360/
// launchtype项可配置值为local或remote, local代表前端连本地云函数,remote代表前端连云端云函数
"version": "0.0",
"configurations": [{
"app-plus" :
"version" : "0.0",
"configurations" : [
{
"app-plus" : {
"launchtype" : "local"
},
"default" :
{
"default" : {
"launchtype" : "local"
},
"type" : "uniCloud"
},
{
"bundleId" : "io.dcloud.test123456",
"certificateFile" : "/Users/lizhongyi/Desktop/文件/证书/dev_123.p12",
"certificateProfileFile" : "/Users/lizhongyi/Desktop/文件/证书/io_dcloud_test123456.mobileprovision",
"type" : "uni-app:app-ios"
}
]
}
{
"name" : "uni-api",
"appid" : "__UNI__4F60974",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
"name": "uni-api",
"appid": "__UNI__ED9218B",
"description": "",
"versionName": "1.0.0",
"versionCode": "100",
"transformPx": false,
/* 5+App特有相关 */
"app-plus" : {
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
"app-plus": {
"usingComponents": true,
"nvueStyleCompiler": "uni-app",
"compilerVersion": 3,
"splashscreen": {
"alwaysShowBeforeRender": true,
"waiting": true,
"autoclose": true,
"delay": 0
},
/* 模块配置 */
"modules" : {},
"modules": {},
/* 应用发布信息 */
"distribute" : {
"distribute": {
/* android打包配置 */
"android" : {
"permissions" : [
"android": {
"permissions": [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
......@@ -41,32 +41,32 @@
]
},
/* ios打包配置 */
"ios" : {},
"ios": {},
/* SDK配置 */
"sdkConfigs" : {}
"sdkConfigs": {}
}
},
/* 快应用特有相关 */
"quickapp" : {},
"quickapp": {},
/* 小程序特有相关 */
"mp-weixin" : {
"appid" : "",
"setting" : {
"urlCheck" : false
"mp-weixin": {
"appid": "",
"setting": {
"urlCheck": false
},
"usingComponents" : true
"usingComponents": true
},
"mp-alipay" : {
"usingComponents" : true
"mp-alipay": {
"usingComponents": true
},
"mp-baidu" : {
"usingComponents" : true
"mp-baidu": {
"usingComponents": true
},
"mp-toutiao" : {
"usingComponents" : true
"mp-toutiao": {
"usingComponents": true
},
"uniStatistics" : {
"enable" : false
"uniStatistics": {
"enable": false
},
"vueVersion" : "2"
"vueVersion": "2"
}
......@@ -9,6 +9,8 @@
<button @tap="testGetBatteryInfo">获取电池电量</button>
<button @tap="testonMemoryWarning">开启内存不足告警监听</button>
<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
<button @tap="testShowModal">模态弹窗</button>
<button @tap="testShowModalWithTF">模态弹窗带输入框</button>
<button @tap="testStartWifi">初始化wifi模块</button>
<button @tap="testGetWifiList">获取当前wifi列表</button>
......@@ -19,85 +21,113 @@
</template>
<script>
import showModal from '@/uni_modules/uni-showmodal';
export default {
data() {
return {
title: 'Hello',
memListener:null,
memListener: null,
}
},
onLoad() {
},
methods: {
onMemoryWarning:function(res){
onMemoryWarning: function(res) {
console.log(res);
},
testConnnectWifi(){
testShowModal() {
showModal({
title: "温馨提示",
content: "这是一个模态弹窗",
cancelColor: "#ff0000",
confirmColor: "#00ff00",
showCancel: true,
success: function(res) {
console.log(res)
}
})
},
testShowModalWithTF() {
showModal({
title: "提示",
content: "带输入框的弹窗",
showCancel: false,
editable: true,
placeholderText: "请输入内容",
success: function(res) {
console.log(res)
}
})
},
testConnnectWifi() {
uni.connectWifi({
maunal:false,
SSID:"Xiaomi_20D0",
password:"BBBB",
complete:(res)=>{
maunal: false,
SSID: "Xiaomi_20D0",
password: "BBBB",
complete: (res) => {
console.log(res);
}
});
},
testGetConnnectWifi(){
testGetConnnectWifi() {
uni.getConnectedWifi({
partialInfo:false,
complete:(res)=>{
partialInfo: false,
complete: (res) => {
console.log(res);
if (res.errCode == 0) {
uni.showToast({
icon:'none',
title:res.wifi.SSID
icon: 'none',
title: res.wifi.SSID
})
} else{
} else {
uni.showToast({
icon:'none',
title:res.errMsg
icon: 'none',
title: res.errMsg
})
}
}
});
},
testStartWifi(){
testStartWifi() {
uni.startWifi({
success:(res)=> {
success: (res) => {
console.log("success: " + JSON.stringify(res));
// wifi 开启成功后,注册wifi链接状态监听和wifi列表获取监听
uni.onGetWifiList(function(res){
uni.onGetWifiList(function(res) {
console.log("onGetWifiList");
console.log(res);
});
uni.onWifiConnected(function(res){
uni.onWifiConnected(function(res) {
console.log("onWifiConnected");
console.log(res);
});
uni.onWifiConnectedWithPartialInfo(function(res){
uni.onWifiConnectedWithPartialInfo(function(res) {
console.log("onWifiConnectedWithPartialInfo");
console.log(res);
});
},fail:(res)=>{
},
fail: (res) => {
console.log("fail: " + JSON.stringify(res));
},complete:(res)=>{
},
complete: (res) => {
console.log("complete: " + JSON.stringify(res));
}
})
},
testStopWifi() {
uni.stopWifi({
success:(res)=> {
success: (res) => {
console.log("success: " + JSON.stringify(res));
},fail:(res)=>{
},
fail: (res) => {
console.log("fail: " + JSON.stringify(res));
},complete:(res)=>{
},
complete: (res) => {
console.log("complete: " + JSON.stringify(res));
}
})
......@@ -105,11 +135,13 @@
},
testGetWifiList() {
uni.getWifiList({
success:(res)=> {
success: (res) => {
console.log("success: " + JSON.stringify(res));
},fail:(res)=>{
},
fail: (res) => {
console.log("fail: " + JSON.stringify(res));
},complete:(res)=>{
},
complete: (res) => {
console.log("complete: " + JSON.stringify(res));
}
})
......@@ -118,15 +150,15 @@
testonMemoryWarning() {
uni.onMemoryWarning(this.onMemoryWarning)
uni.showToast({
icon:'none',
title:'已监听,注意控制台输出'
icon: 'none',
title: '已监听,注意控制台输出'
})
},
testoffMemoryWarning(){
testoffMemoryWarning() {
uni.offMemoryWarning(this.onMemoryWarning)
uni.showToast({
icon:'none',
title:'监听已移除'
icon: 'none',
title: '监听已移除'
})
},
testScreenShotListen() {
......@@ -136,26 +168,26 @@
if (uni.getSystemInfoSync().platform == "android") {
// 除android 之外的平台,不需要判断返回状态码
if(res.errCode == -1){
if (res.errCode == -1) {
// 启动失败
return ;
}else if(res.errCode == 0){
return;
} else if (res.errCode == 0) {
uni.showToast({
icon:"none",
title:'截屏监听已开启'
icon: "none",
title: '截屏监听已开启'
})
}else {
} else {
uni.showToast({
icon:"none",
title:'捕获截屏事件'
icon: "none",
title: '捕获截屏事件'
})
that.screenImage = res.image
}
}else{
} else {
// 除android 之外的平台,不需要判断返回状态码
uni.showToast({
icon:"none",
title:'捕获截屏事件'
icon: "none",
title: '捕获截屏事件'
})
}
......@@ -164,8 +196,8 @@
if (uni.getSystemInfoSync().platform != "android") {
// 除android 之外的平台,直接提示监听已开启
uni.showToast({
icon:"none",
title:'截屏监听已开启'
icon: "none",
title: '截屏监听已开启'
})
}
},
......@@ -175,8 +207,8 @@
});
// 提示已经开始监听,注意观察
uni.showToast({
icon:"none",
title:'截屏监听已关闭'
icon: "none",
title: '截屏监听已关闭'
})
},
testGetBatteryInfo() {
......
{
"id": "uni-showmodal",
"displayName": "uni-showmodal",
"version": "1.0.0",
"description": "uni-showmodal",
"keywords": [
"uni-showmodal"
],
"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-showmodal
### 开发文档
[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
import { UIAlertController, UIAlertAction, UITextField } from "UIKit"
import { UTSiOS } from "DCloudUTSFoundation"
import { DispatchQueue } from 'Dispatch';
type ShowModalResult = {
errCode: number,
errSubject: string,
errMsg: string,
confirm: boolean,
cancel: boolean,
content: string
}
type ShowModalOptions = {
title?: string,
content?: string,
showCancel: boolean,
cancelText?: string,
cancelColor?: string,
confirmText?: string,
confirmColor?: string,
editable: boolean,
placeholderText?: string,
success?: (res: ShowModalResult) => void,
fail?: (res: ShowModalResult) => void,
complete?: (res: ShowModalResult) => void
}
export default function showModal(options: ShowModalOptions) {
const title = options.title == null ? "" : options.title!
const message = options.content == null ? "" : options.content!
const showCancel = options.showCancel == null ? true : (options.showCancel != false)
const cancelText = options.cancelText == null ? "取消" : options.cancelText!
const confirmText = options.confirmText == null ? "确定" : options.confirmText!
const canEidt = options.editable == true
const placeholderText = options.placeholderText == null ? "" : options.placeholderText!
// uts方法默认会在子线程中执行,涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行
DispatchQueue.main.async(execute = (): void => {
// 初始化 UIAlertController 实例对象 alert
let alert = new UIAlertController(title = title, message = message, preferredStyle = UIAlertController.Style.alert)
if (canEidt == true) {
// 在 alert 上添加输入框
console.log("需要加上输入框")
alert.addTextField(configurationHandler = (tf: UITextField): void => {
// 添加成功的回调
// 设置输入框的 placeholder
tf.placeholder = placeholderText
})
}
// 创建 UIAlertAction 按钮
let okAction = new UIAlertAction(title = confirmText, style = UIAlertAction.Style.default, handler = (action: UIAlertAction): void => {
// 获取输入框中的内容
let inputText = ""
if (canEidt == true) {
let tf = alert.textFields?.[0]
if (tf != null) {
inputText = tf!.text != null ? tf!.text! : ""
}
}
// 点击按钮的回调方法
const res = new ShowModalResult()
res.errCode = 0
res.errSubject = ""
res.errMsg = ""
res.confirm = false
res.cancel = true
res.content = inputText
options.success?.(res)
options.complete?.(res)
})
if (options.confirmColor != null) {
const color = UTSiOS.colorWithString(options.confirmColor!)
okAction.setValue(color, forKey = "titleTextColor")
}
// 将 UIAlertAction 添加到 alert 上
alert.addAction(okAction)
if (showCancel == true) {
// 创建 UIAlertAction 按钮
let cancelAction = new UIAlertAction(title = cancelText, style = UIAlertAction.Style.cancel, handler = (action: UIAlertAction): void => {
// 点击按钮的回调方法
const res = new ShowModalResult()
res.errCode = 0
res.errSubject = ""
res.errMsg = ""
res.confirm = false
res.cancel = true
res.content = ""
options.success?.(res)
options.complete?.(res)
})
if (options.cancelColor != null) {
const color = UTSiOS.colorWithString(options.cancelColor!)
cancelAction.setValue(color, forKey = "titleTextColor")
}
alert.addAction(cancelAction)
}
// 打开 alert 弹窗
UTSiOS.getCurrentViewController().present(alert, animated = true)
})
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册