element-getnativeview.uvue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view id="view" style="flex: 1;">
  3. <input id="input" value="input" class="input" />
  4. <textarea id="textarea" value="textarea" class="textarea" />
  5. <web-view id="webview" src="/hybrid/html/local.html" class="web-view"></web-view>
  6. // 注意:iOS平台真机运行时需要安装 Xcode 开发工具具备 UTS 开发环境,或提交自定基座打包后 checkNativeView 相关方法才会生效
  7. <button class="button" type="primary" @click="checkViewNativeView">检测view标签原生View</button>
  8. <button class="button" type="primary" @click="checkInputNativeView">检测input标签原生View</button>
  9. <button class="button" type="primary" @click="checkTextareaNativeView">检测textarea标签原生View</button>
  10. <button class="button" type="primary" @click="checkWebViewNativeView">检测webview标签原生View</button>
  11. </view>
  12. </template>
  13. <script>
  14. import { checkWebViewNativeView, checkInputNativeView, checkTextareaNativeView, checkViewNativeView } from '@/uni_modules/uts-get-native-view';
  15. export default {
  16. data() {
  17. return {
  18. }
  19. },
  20. methods: {
  21. checkViewNativeView() : boolean {
  22. var viewName = "ViewGroup"
  23. // #ifdef APP-IOS
  24. viewName = "UIView"
  25. // #endif
  26. const msg = "检测view组件对应原生" + viewName
  27. if (checkViewNativeView("view")) {
  28. this.showTip(msg + "成功")
  29. return true
  30. }
  31. this.showTip(msg + "失败")
  32. return false
  33. },
  34. checkInputNativeView() : boolean {
  35. var viewName = "AppCompatEditText"
  36. // #ifdef APP-IOS
  37. viewName = "UITextField"
  38. // #endif
  39. const msg = "检测input组件对应原生" + viewName
  40. if (checkInputNativeView("input")) {
  41. this.showTip(msg + "成功")
  42. return true
  43. }
  44. this.showTip(msg + "失败")
  45. return false
  46. },
  47. checkTextareaNativeView() : boolean {
  48. var viewName = "AppCompatEditText"
  49. // #ifdef APP-IOS
  50. viewName = "UITextView"
  51. // #endif
  52. const msg = "检测textarea组件对应原生" + viewName
  53. if (checkTextareaNativeView("textarea")) {
  54. this.showTip(msg + "成功")
  55. return true
  56. }
  57. this.showTip(msg + "失败")
  58. return false
  59. },
  60. checkWebViewNativeView() : boolean {
  61. var viewName = "WebView"
  62. // #ifdef APP-IOS
  63. viewName = "WKWebView"
  64. // #endif
  65. const msg = "检测webview组件对应原生" + viewName
  66. if (checkWebViewNativeView("webview")) {
  67. this.showTip(msg + "成功")
  68. return true
  69. }
  70. this.showTip(msg + "失败")
  71. return false
  72. },
  73. showTip(title : string) {
  74. console.log("title===" + title)
  75. uni.showToast({
  76. title: title,
  77. icon: "none"
  78. })
  79. }
  80. }
  81. }
  82. </script>
  83. <style>
  84. .input {
  85. width: 300px;
  86. height: 40px;
  87. border-radius: 4px;
  88. border-width: 1px;
  89. border-color: black;
  90. border-style: solid;
  91. margin: 20px auto;
  92. }
  93. .textarea {
  94. width: 300px;
  95. height: 80px;
  96. border-radius: 4px;
  97. border-width: 1px;
  98. border-color: black;
  99. border-style: solid;
  100. margin: 20px auto;
  101. }
  102. .web-view {
  103. width: 300px;
  104. height: 120px;
  105. margin: 20px auto;
  106. border-radius: 4px;
  107. border-width: 1px;
  108. border-color: black;
  109. border-style: solid;
  110. }
  111. .button {
  112. margin: 10px 20px;
  113. }
  114. </style>