uni_android_plugin_project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
4.7 KiB

  1. <template>
  2. <div class="content">
  3. <button class="btn" type="primary" @click="gotoNativePage">跳转原生Activity</button>
  4. <button class="btn" type="primary" @click="tcpAsyncFunc">[开启TcpServer]</button>
  5. <text class="tips">
  6. 点击后将开启TcpServer. 本机IP: 192.168.1.64 端口:16666
  7. </text>
  8. <!-- <button type="primary" @click="testFun2">zmt-testFun2</button> -->
  9. <button class="btn" type="primary" @click="faceAsyncFunc">[百度人脸SDK授权]</button>
  10. <text class="tips">
  11. 点击后将进行百度人脸SDK初始化及授权申请,该授权码写死在Android端zmt_module内faceClass,因已使用过,将返回已被占用提示.
  12. </text>
  13. <view class="console">
  14. <text class="log" v-for="i in logs">{{i}}</text>
  15. </view>
  16. <button class="btn" type="primary" @click="testAsyncFunc2">uniplugin_module_ox testAsyncFunc2</button>
  17. <button class="btn" type="primary" @click="testSyncFunc2">uniplugin_module_ox testSyncFunc2</button>
  18. <button class="btn" type="primary" @click="testAsyncFunc">uniplugin_module testAsyncFunc</button>
  19. <button class="btn" type="primary" @click="testSyncFunc">uniplugin_module testSyncFunc</button>
  20. </div>
  21. </template>
  22. <script>
  23. // #ifdef APP-PLUS
  24. // 获取 module
  25. var zmtModule = uni.requireNativePlugin("Zmt-Module")
  26. var testModule = uni.requireNativePlugin("TestModule") //uniplugin_module
  27. var uniplugin_module_ox = uni.requireNativePlugin("uniplugin_module_ox") //uniplugin_module_ox
  28. var faceModule = uni.requireNativePlugin("Face-Module") //百度人脸SDK, face_module
  29. const modal = uni.requireNativePlugin('modal');
  30. // #endif
  31. import {timeFormat} from "../../utils/timeFormat.js"
  32. export default {
  33. onLoad() {
  34. this.initAPPListener()
  35. },
  36. onReady() {
  37. this.logs.push("当前时间:"+this.getTime())
  38. },
  39. data() {
  40. return {
  41. logs:["LOG VIEW"]
  42. }
  43. },
  44. methods: {
  45. initAPPListener(){
  46. // #ifdef APP-PLUS
  47. // 原生平台事件监听,等待测试
  48. plus.globalEvent.addEventListener('TestEvent', function(e){
  49. modal.toast({
  50. message: "TestEvent收到:"+e.msg,
  51. duration: 1.5
  52. });
  53. });
  54. // #endif
  55. },
  56. //百度人脸SDK,初始化,并申请授权(授权码写死在android端 faceClass)
  57. faceAsyncFunc() {
  58. this.log("执行faceModule.faceAsyncFunc");
  59. // 调用异步方法
  60. faceModule.faceAsyncFunc({
  61. 'name': 'unimp',
  62. 'age': 1
  63. },
  64. (ret) => {
  65. modal.toast({
  66. message: ret,
  67. duration: 1.5
  68. });
  69. this.log(JSON.stringify(ret))
  70. })
  71. },
  72. tcpAsyncFunc(){
  73. // 调用异步方法
  74. this.log("开启Tcp Server.")
  75. zmtModule.tcpAsyncFunc({
  76. 'name': 'unimp',
  77. 'age': 1
  78. },
  79. (ret) => {
  80. modal.toast({
  81. message: ret,
  82. duration: 2
  83. });
  84. // this.logs.push(this.getTime()+" tcp接收:"+ret.code)
  85. this.log("tcp接收:"+ret.code)
  86. })
  87. },
  88. testFun2(){
  89. // 调用同步方法
  90. var ret = zmtModule.testSyncFunc({
  91. 'name': 'unimp',
  92. 'age': 1
  93. })
  94. modal.toast({
  95. message: ret,
  96. duration: 1.5
  97. });
  98. },
  99. testAsyncFunc() {
  100. // 调用异步方法
  101. testModule.testAsyncFunc({
  102. 'name': 'unimp',
  103. 'age': 1
  104. },
  105. (ret) => {
  106. modal.toast({
  107. message: ret,
  108. duration: 1.5
  109. });
  110. })
  111. },
  112. testSyncFunc() {
  113. // 调用同步方法
  114. var ret = testModule.testSyncFunc({
  115. 'name': 'unimp',
  116. 'age': 1
  117. })
  118. modal.toast({
  119. message: ret,
  120. duration: 1.5
  121. });
  122. },
  123. testAsyncFunc2() {
  124. // 调用异步方法
  125. uniplugin_module_ox.testAsyncFunc2({
  126. 'name': 'unimp',
  127. 'age': 1
  128. },
  129. (ret) => {
  130. modal.toast({
  131. message: ret,
  132. duration: 1.5
  133. });
  134. })
  135. },
  136. testSyncFunc2() {
  137. // 调用同步方法
  138. var ret = uniplugin_module_ox.testSyncFunc2({
  139. 'name': 'unimp',
  140. 'age': 1
  141. })
  142. modal.toast({
  143. message: ret,
  144. duration: 1.5
  145. });
  146. },
  147. //在Log View打印txt
  148. log(txt){
  149. this.logs.push(this.getTime()+` ${txt}`)
  150. },
  151. //返回当前时间
  152. getTime(){
  153. return timeFormat(new Date(),'mm/dd hh:MM:ss')
  154. },
  155. gotoNativePage() {
  156. testModule.gotoNativePage();
  157. }
  158. }
  159. }
  160. </script>
  161. <style lang="scss">
  162. .content{
  163. // width: 750rpx;
  164. // margin-top: 10rpx;
  165. // display: flex;
  166. // flex-wrap: nowrap;
  167. // align-items: flex-start;
  168. // flex-direction: column;
  169. // justify-content: center;
  170. font-size: 12px;
  171. }
  172. // button{
  173. // margin-top: 3px;
  174. // }
  175. .btn{
  176. margin: 3px;
  177. // width: 95%;
  178. }
  179. .tips{
  180. font-size: 11px;
  181. color: gray;
  182. font-weight: 800;
  183. }
  184. .console{
  185. // margin-left: 25rpx;
  186. // width: %;
  187. // height: auto;
  188. background-color: lightgray;
  189. padding: 20rpx;
  190. }
  191. .log{
  192. color: darkred;
  193. font-size: 11px;
  194. font-weight: 800;
  195. }
  196. </style>