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.

268 lines
6.3 KiB

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