文件
OmniCard/mpuniapp/pages/API/get-native-view/element-getnativeview.uvue

136 行
3.3 KiB
Plaintext

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view id="view">
<input id="input" value="input" class="input" />
<textarea id="textarea" value="textarea" class="textarea" />
<web-view id="webview" src="/hybrid/html/local.html" class="web-view"></web-view>
// 注意:iOS平台真机运行时需要安装 Xcode 开发工具具备 UTS 开发环境,或提交自定基座打包后 checkNativeView 相关方法才会生效
<button class="button" type="primary" @click="checkViewNativeView">检测view标签原生View</button>
<button class="button" type="primary" @click="checkInputNativeView">检测input标签原生View</button>
<button class="button" type="primary" @click="checkTextareaNativeView">检测textarea标签原生View</button>
<button class="button" type="primary" @click="checkWebViewNativeView">检测webview标签原生View</button>
</view>
</template>
<script setup lang="uts">
import { checkWebViewNativeView as checkWebView, checkInputNativeView as checkInput, checkTextareaNativeView as checkTextarea, checkViewNativeView as checkView } from '@/uni_modules/uts-get-native-view';
function showTip(title : string) {
console.log("title===" + title)
uni.showToast({
title: title,
icon: "none"
})
}
function checkViewNativeView() : boolean {
var msg = "检测view组件对应原生"
// #ifdef APP-ANDROID
msg += "ViewGroup"
// #endif
// #ifdef APP-IOS
msg += "UIView"
// #endif
if (checkView("view")) {
showTip(msg + "成功")
return true
}
showTip(msg + "失败")
return false
}
function checkInputNativeView() : boolean {
var msg = "检测input组件对应原生"
// #ifdef APP-ANDROID
msg += "EditText"
// #endif
// #ifdef APP-IOS
msg += "UITextField"
// #endif
if (checkInput("input")) {
showTip(msg + "成功")
return true
}
showTip(msg + "失败")
return false
}
function checkTextareaNativeView() : boolean {
var msg = "检测textarea组件对应原生"
// #ifdef APP-ANDROID
msg += "EditText"
// #endif
// #ifdef APP-IOS
msg += "UITextView"
// #endif
if (checkTextarea("textarea")) {
showTip(msg + "成功")
return true
}
showTip(msg + "失败")
return false
}
function checkWebViewNativeView() : boolean {
var msg = "检测web-view组件对应原生"
// #ifdef APP-ANDROID
msg += "WebView"
// #endif
// #ifdef APP-IOS
msg += "WKWebView"
// #endif
if (checkWebView("webview")) {
showTip(msg + "成功")
return true
}
showTip(msg + "失败")
return false
}
defineExpose({
checkViewNativeView,
checkInputNativeView,
checkTextareaNativeView,
checkWebViewNativeView
})
</script>
<style>
.input {
width: 300px;
height: 40px;
border-radius: 4px;
border-width: 1px;
border-color: black;
border-style: solid;
margin: 20px auto;
}
.textarea {
width: 300px;
height: 80px;
border-radius: 4px;
border-width: 1px;
border-color: black;
border-style: solid;
margin: 20px auto;
}
.web-view {
width: 300px;
height: 120px;
margin: 20px auto;
border-radius: 4px;
border-width: 1px;
border-color: black;
border-style: solid;
}
.button {
margin: 10px 20px;
}
</style>