'''<template>
<view class="content">
webview
<uts-hello-view ref="helloView" buttontext="点击按钮内容" style="width:375px;height: 60px;background-color: aqua;"></uts-hello-view>
</view>
</template>
<script>
export default {
}
</script>
<style>
</style>'''
'''@file:Suppress("UNCHECKED_CAST", "USELESS_CAST", "INAPPLICABLE_JVM_NAME", "UNUSED_ANONYMOUS_PARAMETER", "SENSELESS_COMPARISON", "NAME_SHADOWING", "UNNECESSARY_NOT_NULL_ASSERTION")
package uts.sdk.modules.aiwnWebview
import android.text.TextUtils
import android.view.View
import android.widget.Button
import com.taobao.weex.annotation.JSMethod
import com.taobao.weex.ui.component.WXComponentProp
import io.dcloud.feature.uniapp.UniSDKInstance
import io.dcloud.feature.uniapp.ui.action.AbsComponentData
import io.dcloud.feature.uniapp.ui.component.AbsVContainer
import io.dcloud.uniapp.
import io.dcloud.uniapp.extapi.
import io.dcloud.uts.
import io.dcloud.uts.Map
import io.dcloud.uts.Set
import io.dcloud.uts.UTSAndroid
import io.dcloud.uts.component.
import io.dcloud.uts.component.UTSComponent
import io.dcloud.uts.component.UTSMeasureMode
import io.dcloud.uts.component.UTSSize
import kotlin.properties.Delegates
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
open class UtsHelloViewComponent : UTSComponent<Button> {
constructor(instance: UniSDKInstance?, parent: AbsVContainer<>?, componentData: AbsComponentData<>?) : super(instance, parent, componentData)
open var buttontext: String = "点击触发"
override fun created() {}
override fun NVBeforeLoad() {}
override fun NVLoad(): Button {
var button = Button($androidContext!!)
button.setText("点击触发")
button.setOnClickListener(ButtonClickListener(this))
return button
}
override fun NVLoaded() {}
override fun NVLayouted() {}
override fun NVBeforeUnload() {}
override fun NVUnloaded() {}
override fun unmounted() {}
override fun NVMeasure(size: UTSSize, mode: UTSMeasureMode): UTSSize {
return size
}
@JSMethod(uiThread = false)
open fun doSomething(param: String) {
console.log(param)
}
open fun privateMethod() {}
override fun $init() {
this.$watch<String>("buttontext", fun(newValue, oldValue){
if (!TextUtils.isEmpty(newValue) && newValue != oldValue) {
this.$el?.setText(newValue)
}
}
)
}
@WXComponentProp(name = "buttontext")
open fun componentSetButtontext(value: String) {
this.buttontext = value
this.$componentWatchDispatch("buttontext", value)
}
}
open class ButtonClickListener : View.OnClickListener {
private var comp: UTSComponent<Button>
constructor(comp: UTSComponent<Button>) : super() {
this.comp = comp
}
override fun onClick(v: View?) {
console.log("按钮被点击")
this.comp.$emit("buttonclick")
}
}
'''
'''
{
"nativePlugins": [
{
"plugins": [
{
"type": "component",
"name": "uts-hello-view",
"class": "uts.sdk.modules.aiwnWebview.UtsHelloViewComponent"
}
]
}
]
}
'''
1 个回复
Ask小助手 - Ask社区AI助手
感谢您的反馈。针对您提交的 Bug 反馈,我们进行了评审与分析,以下是具体的评审意见及排查建议:
1. Bug 反馈内容完整性评审
setting.gradle和build.gradle已配置,但未具体说明配置的内容。离线打包涉及诸多细节配置,建议补充具体的配置代码。uts原生代码与json配置直接混排,未明确区分文件。此外,根据官方文档,UTS 兼容模式组件的源码应编写在index.vue文件中,而您提供的是编译后的 Kotlin 代码,这不利于官方人员直接运行和排查。2. Bug 是否成立分析
根据知识库信息,该 Bug 暂无法直接判定为框架缺陷,更可能是离线打包配置或组件使用方式的问题。主要排查方向如下:
配置文件缺失或错误
根据社区经验,离线打包时 UTS 插件的配置容易遗漏。请重点检查以下内容:
nativePluginsJSON 结构似乎不完整。标准配置应包含plugins数组,并明确指定type、name和class。请确认该文件是否已正确放置在src/main/assets/apps/您的appid/www/目录下或按官方要求配置。uniappx模块或app模块下是否正确配置了 UTS 插件的依赖。参考 Uniappx 离线打包配置 和 uniappx 离线打包,确保io.dcloud.uts.kotlin插件已正确引入。build.gradle中配置buildConfigField 'String', 'UTSEasyCom', ...以注册组件,请检查是否遗漏。组件使用方式差异
根据 UTS 组件兼容模式文档,UTS 组件默认全局注册,但在
uvue页面和nvue页面中的使用方式存在差异:nvue页面中,可以通过this.$refs["helloView"].doSomething(...)直接调用方法。uvue页面中,需要引入对应的 Element 类型并进行类型转换,例如:(this.$refs["helloView"] as UtsHelloViewElement).doSomething(...)。组件源码结构
根据 UTS 组件结构解析,UTS 兼容模式组件应使用
export default {}的选项式 API 编写在index.vue中。请检查您的组件源码是否符合此规范,特别是NVLoad()方法是否正确返回了原生 View 对象。3. 后续建议
由于目前提供的信息不足以直接定位问题,建议您:
要回复问题请先登录或注册
公告
更多>相关问题