<template>
	<div class="content">

		<button class="btn" type="primary" @click="gotoNativePage">跳转原生Activity</button>
		<button class="btn" type="primary" @click="tcpAsyncFunc">[开启TcpServer]</button>
		<text class="tips">
			点击后将开启TcpServer. 本机IP: 192.168.1.64  端口：16666
		</text>
		<!-- <button type="primary" @click="testFun2">zmt-testFun2</button> -->
		
		<button class="btn" type="primary" @click="faceAsyncFunc">[百度人脸SDK授权]</button>
		<text class="tips">
			点击后将进行百度人脸SDK初始化及授权申请,该授权码写死在Android端zmt_module内faceClass,因已使用过,将返回已被占用提示.
		</text>
		
		<view class="console">
			<text class="log" v-for="i in logs">{{i}}</text>
		</view>
		<button class="btn" type="primary" @click="testAsyncFunc2">uniplugin_module_ox testAsyncFunc2</button>
		<button class="btn" type="primary" @click="testSyncFunc2">uniplugin_module_ox testSyncFunc2</button>
		<button class="btn" type="primary" @click="testAsyncFunc">uniplugin_module testAsyncFunc</button>
		<button class="btn" type="primary" @click="testSyncFunc">uniplugin_module testSyncFunc</button>
		
	</div>
</template>

<script>
	// #ifdef APP-PLUS
		// 获取 module
		var zmtModule = uni.requireNativePlugin("Zmt-Module")
		var testModule = uni.requireNativePlugin("TestModule") //uniplugin_module
		var uniplugin_module_ox = uni.requireNativePlugin("uniplugin_module_ox") //uniplugin_module_ox
		var faceModule = uni.requireNativePlugin("Face-Module") //百度人脸SDK, face_module
		const modal = uni.requireNativePlugin('modal');
	// #endif
	
	import {timeFormat} from "../../utils/timeFormat.js"
	
	export default {
		onLoad() {
			this.initAPPListener()
			
			
		},
		onReady() {
			this.logs.push("当前时间:"+this.getTime())
		},
		data() {
			return {
				logs:["LOG VIEW"]
			}
		},
		methods: {
			
			initAPPListener(){
				// #ifdef APP-PLUS
				let that = this
					// 原生平台事件监听,等待测试
					plus.globalEvent.addEventListener('myEvent', function(e){
						modal.toast({
							message: "TestEvent收到："+JSON.stringify(e),
							duration: 3.5
						});
						that.log("全局事件接收:"+JSON.stringify(e))
					});
				// #endif
			},
			//百度人脸SDK,初始化,并申请授权(授权码写死在android端 faceClass)
			faceAsyncFunc() {
				this.log("执行faceModule.faceAsyncFunc");
				// 调用异步方法
				faceModule.faceAsyncFunc({
						'name': 'unimp',
						'age': 1
					},
					(ret) => {
						modal.toast({
							message: ret,
							duration: 1.5
						});
						this.log(JSON.stringify(ret))
					})
			},
			tcpAsyncFunc(){
				// 调用异步方法
				this.log("Click Tcp Server.")
				zmtModule.tcpAsyncFunc({
						'port':"16666",
					},
					(ret) => {
						modal.toast({
							message: ret,
							duration: 2
						});
						this.log("invoke:"+JSON.stringify(ret))
					})
			},
			testFun2(){
				// 调用同步方法
				var ret = zmtModule.testSyncFunc({
					'name': 'unimp',
					'age': 1
				})
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			testAsyncFunc() {
				// 调用异步方法
				testModule.testAsyncFunc({
						'name': 'unimp',
						'age': 1
					},
					(ret) => {
						modal.toast({
							message: ret,
							duration: 1.5
						});
					})
			},
			testSyncFunc() {
				// 调用同步方法
				var ret = testModule.testSyncFunc({
					'name': 'unimp',
					'age': 1
				})
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			
			testAsyncFunc2() {
				// 调用异步方法
				uniplugin_module_ox.testAsyncFunc2({
						'name': 'unimp',
						'age': 1
					},
					(ret) => {
						modal.toast({
							message: ret,
							duration: 1.5
						});
					})
			},
			testSyncFunc2() {
				// 调用同步方法
				var ret = uniplugin_module_ox.testSyncFunc2({
					'name': 'unimp',
					'age': 1
				})
				modal.toast({
					message: ret,
					duration: 1.5
				});
			},
			//在Log View打印txt
			log(txt){
				this.logs.push(this.getTime()+` ${txt}`)
			},
			//返回当前时间
			getTime(){
				return timeFormat(new Date(),'mm/dd hh:MM:ss')
			},
			gotoNativePage() {
				testModule.gotoNativePage();
			}
		}
	}
</script>
<style lang="scss">
	
	.content{
		// width: 750rpx;
		// margin-top: 10rpx;
		// display: flex;
		// flex-wrap: nowrap;
		// align-items: flex-start;
		// flex-direction: column;
		// justify-content: center;
		font-size: 12px;
		
	}
	// button{
	// 	margin-top: 3px;
	// }
	.btn{
		margin: 3px;
		// width: 95%;
	}
	.tips{
		font-size: 11px;
		color: gray;
		font-weight: 800;
	}
	
	.console{
		// margin-left: 25rpx;
		// width: %;
		// height: auto;
		display: flex;
		flex-wrap: nowrap;
		flex-direction: column;
		align-items: flex-start;
		background-color: lightgray;
		padding: 20rpx;
	}
	.log{
		color: darkred;
		font-size: 11px;
		font-weight: 800;
	}
</style>