index.vue 5.9 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2
<template>
	<view class="content">
杜庆泉's avatar
杜庆泉 已提交
3 4 5 6 7 8 9 10 11

		
		<button @tap="testStartWifi" style="width: 100%;">初始化wifi模块</button>
		<button @tap="testGetWifiList" style="width: 100%;">获取当前wifi列表</button>
		<button @tap="testOffGetWifiList" style="width: 100%;">移除wifi列表监听</button>
		<button @tap="testGetConnnectWifi" style="width: 100%;">获取当前连接的wifi</button>
		<button @tap="testConnnectWifi" style="width: 100%;">链接wifi</button>
		<button @tap="testStopWifi" style="width: 100%;">关闭wifi模块</button>
		
12
		<button @tap="testScreenShotListen">开启截屏监听</button>
13
		<button @tap="testScreenShotOff">关闭截屏监听</button>
14 15
		<button @tap="testSetUserCaptureScreen">{{setUserCaptureScreenText}}</button>
		
16 17 18
		<button @tap="testGetBatteryInfo">获取电池电量</button>
		<button @tap="testonMemoryWarning">开启内存不足告警监听</button>
		<button @tap="testoffMemoryWarning">关闭内存不足告警监听</button>
19
		
杜庆泉's avatar
杜庆泉 已提交
20
		
DCloud-yyl's avatar
DCloud-yyl 已提交
21 22 23 24
	</view>
</template>

<script>
25

DCloud-yyl's avatar
DCloud-yyl 已提交
26 27 28
	export default {
		data() {
			return {
杜庆泉's avatar
杜庆泉 已提交
29
				memListener:null,
30
				setUserCaptureScreenFlag: false,
31
				setUserCaptureScreenText: '禁止截屏'
DCloud-yyl's avatar
DCloud-yyl 已提交
32 33 34 35 36 37
			}
		},
		onLoad() {

		},
		methods: {
杜庆泉's avatar
杜庆泉 已提交
38 39 40
			onMemoryWarning:function(res){
				console.log(res);
			},
杜庆泉's avatar
杜庆泉 已提交
41
			testConnnectWifi(){
杜庆泉's avatar
杜庆泉 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
				
				uni.startWifi({
					success:(res)=> {
						console.log("success: " + JSON.stringify(res));
						uni.connectWifi({
							maunal:false,
							SSID:"Xiaomi_20D0",
							password:"BBB111",
							complete:(res)=>{
								console.log(res);
							}
						});
					},fail:(res)=>{
						console.log("fail: " + JSON.stringify(res));
					},complete:(res)=>{
						console.log("complete: " + JSON.stringify(res));
杜庆泉's avatar
杜庆泉 已提交
58
					}
杜庆泉's avatar
杜庆泉 已提交
59 60 61
				})

				
62
				
杜庆泉's avatar
杜庆泉 已提交
63
			},
杜庆泉's avatar
杜庆泉 已提交
64
			testGetConnnectWifi(){
65
				uni.getConnectedWifi({
杜庆泉's avatar
杜庆泉 已提交
66 67 68
					partialInfo:false,
					complete:(res)=>{
						console.log(res);
69 70 71 72 73 74 75 76 77 78 79 80
						if (res.errCode == 0) {
							uni.showToast({
								icon:'none',
								title:res.wifi.SSID
							})
						} else{
							uni.showToast({
								icon:'none',
								title:res.errMsg
							})
						}
						
杜庆泉's avatar
杜庆泉 已提交
81
					}
杜庆泉's avatar
杜庆泉 已提交
82 83 84 85 86 87
				});
			},
			testStartWifi(){
				uni.startWifi({
					success:(res)=> {
						console.log("success: " + JSON.stringify(res));
88
						// wifi 开启成功后,注册wifi链接状态监听和wifi列表获取监听
杜庆泉's avatar
杜庆泉 已提交
89
						uni.onGetWifiList(function(res){
90
							console.log("onGetWifiList");
杜庆泉's avatar
杜庆泉 已提交
91 92
							console.log(res);
						});
杜庆泉's avatar
杜庆泉 已提交
93
						uni.onWifiConnected(function(res){
94 95
							console.log("onWifiConnected");
							console.log(res);
杜庆泉's avatar
杜庆泉 已提交
96
						});
杜庆泉's avatar
杜庆泉 已提交
97 98 99 100
						uni.onWifiConnectedWithPartialInfo(function(res){
							console.log("onWifiConnectedWithPartialInfo");
							console.log(res);
						});
杜庆泉's avatar
杜庆泉 已提交
101
						
杜庆泉's avatar
杜庆泉 已提交
102 103 104 105
					},fail:(res)=>{
						console.log("fail: " + JSON.stringify(res));
					},complete:(res)=>{
						console.log("complete: " + JSON.stringify(res));
106 107 108
					}
				})
			},
杜庆泉's avatar
杜庆泉 已提交
109
			testStopWifi() {
杜庆泉's avatar
杜庆泉 已提交
110 111 112
				uni.offWifiConnected()
				uni.offWifiConnectedWithPartialInfo()
				
杜庆泉's avatar
杜庆泉 已提交
113 114 115 116 117 118 119 120
				uni.stopWifi({
					success:(res)=> {
						console.log("success: " + JSON.stringify(res));
					},fail:(res)=>{
						console.log("fail: " + JSON.stringify(res));
					},complete:(res)=>{
						console.log("complete: " + JSON.stringify(res));
					}
121
				})
杜庆泉's avatar
杜庆泉 已提交
122
				
123
			},
杜庆泉's avatar
杜庆泉 已提交
124 125 126 127 128 129 130 131 132
			testGetWifiList() {
				uni.getWifiList({
					success:(res)=> {
						console.log("success: " + JSON.stringify(res));
					},fail:(res)=>{
						console.log("fail: " + JSON.stringify(res));
					},complete:(res)=>{
						console.log("complete: " + JSON.stringify(res));
					}
133
				})
杜庆泉's avatar
杜庆泉 已提交
134 135
				
			},
杜庆泉's avatar
杜庆泉 已提交
136 137 138 139 140 141 142
			
			testOffGetWifiList(){
				uni.offGetWifiList()
			},
			
	
			
杜庆泉's avatar
杜庆泉 已提交
143 144
			testonMemoryWarning() {
				uni.onMemoryWarning(this.onMemoryWarning)
145 146 147 148
				uni.showToast({
					icon:'none',
					title:'已监听,注意控制台输出'
				})
杜庆泉's avatar
杜庆泉 已提交
149 150
			},
			testoffMemoryWarning(){
151 152 153 154 155
				uni.offMemoryWarning(this.onMemoryWarning)
				uni.showToast({
					icon:'none',
					title:'监听已移除'
				})
156
			},
157 158 159 160
			testScreenShotListen() {
				var that = this;
				uni.onUserCaptureScreen(function(res) {
						console.log(res);
161 162 163 164 165
						uni.showToast({
							icon:"none",
							title:'捕获截屏事件'
						})
						that.screenImage = res.path
166
				});
167
					
168
				if (uni.getSystemInfoSync().platform != "android") {
169 170 171 172 173 174
					// 除android 之外的平台,直接提示监听已开启
					uni.showToast({
						icon:"none",
						title:'截屏监听已开启'
					})
				}
175 176 177 178 179 180 181 182 183 184 185 186 187 188
			},
			testScreenShotOff() {
				uni.offUserCaptureScreen(function(res) {
						console.log(res);
				});
				// 提示已经开始监听,注意观察
				uni.showToast({
					icon:"none",
					title:'截屏监听已关闭'
				})
			},
			testGetBatteryInfo() {
				uni.getBatteryInfo({
					success(res) {
189
						console.log(res);
190 191 192 193 194 195 196
						uni.showToast({
							title: "当前电量:" + res.level + '%',
							icon: 'none'
						});
					}
				})
			},
197 198 199
			testSetUserCaptureScreen() {
				let flag = this.setUserCaptureScreenFlag;
				uni.setUserCaptureScreen({
200
					enable: flag,
201
					success: (res) => {
202
						console.log("setUserCaptureScreen enable: " + flag + " success: " + JSON.stringify(res));
203 204
					},
					fail: (res) => {
205
						console.log("setUserCaptureScreen enable: " + flag + " fail: " + JSON.stringify(res));
206 207
					},
					complete: (res) => {
208
						console.log("setUserCaptureScreen enable: " + flag + " complete: " + JSON.stringify(res));
209 210 211 212 213 214 215 216 217
					}
				});
				uni.showToast({
					icon:"none",
					title: this.setUserCaptureScreenText
				});
				this.setUserCaptureScreenFlag = !this.setUserCaptureScreenFlag;
				if (this.setUserCaptureScreenFlag) {
					this.setUserCaptureScreenText = '允许截屏';
218 219
				} else {
					this.setUserCaptureScreenText = '禁止截屏';
220 221
				}
			},
DCloud-yyl's avatar
DCloud-yyl 已提交
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>