Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
a92452ad
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1625
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
a92452ad
编写于
7月 15, 2024
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加android 混编 kotlin/java 代码示例
上级
8ded75ca
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
142 addition
and
44 deletion
+142
-44
pages.json
pages.json
+8
-0
pages/SyntaxCase/MixNativeCode.uvue
pages/SyntaxCase/MixNativeCode.uvue
+48
-0
pages/SyntaxCase/consoleTest.uvue
pages/SyntaxCase/consoleTest.uvue
+13
-17
pages/SyntaxCase/consoleTest.vue
pages/SyntaxCase/consoleTest.vue
+18
-25
pages/advance/advance.uvue
pages/advance/advance.uvue
+6
-1
uni_modules/uts-syntaxcase/utssdk/app-android/JavaUser.java
uni_modules/uts-syntaxcase/utssdk/app-android/JavaUser.java
+18
-0
uni_modules/uts-syntaxcase/utssdk/app-android/kotlinCode.kt
uni_modules/uts-syntaxcase/utssdk/app-android/kotlinCode.kt
+21
-0
uni_modules/uts-syntaxcase/utssdk/index.uts
uni_modules/uts-syntaxcase/utssdk/index.uts
+10
-1
未找到文件。
pages.json
浏览文件 @
a92452ad
...
...
@@ -149,6 +149,14 @@
}
},
{
"path"
:
"pages/SyntaxCase/MixNativeCode"
,
"style"
:
{
"navigationBarTitleText"
:
""
,
"enablePullDownRefresh"
:
false
}
},
{
"path"
:
"pages/SyntaxCase/instanceTest"
,
"style"
:
{
...
...
pages/SyntaxCase/MixNativeCode.uvue
0 → 100644
浏览文件 @
a92452ad
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-btn-v uni-common-mt">
// #ifdef APP-ANDROID && UNI-APP-X
<button @tap="callKotlinMethodGetInfoTest">调用kotlin方法</button>
<button @tap="callJavaMethodGetInfoTest">调用java方法(需自定义基座)</button>
// #endif
</view>
</view>
</template>
<script>
// #ifdef APP-ANDROID && UNI-APP-X
import { callKotlinMethodGetInfo, callJavaMethodGetInfo} from "../../uni_modules/uts-syntaxcase";
// #endif
export default {
data() {
return {
title: 'UTS混编示例',
}
},
methods: {
// #ifdef APP-ANDROID && UNI-APP-X
callKotlinMethodGetInfoTest: function () {
let phoneInfo = callKotlinMethodGetInfo();
uni.showToast({
title:phoneInfo
})
},
callJavaMethodGetInfoTest: function () {
let javaInfo = callJavaMethodGetInfo();
uni.showToast({
title:javaInfo
})
},
// #endif
}
}
</script>
<style>
</style>
\ No newline at end of file
pages/SyntaxCase/consoleTest.uvue
浏览文件 @
a92452ad
...
...
@@ -21,52 +21,48 @@
doLogTest() {
if(getLog("") != '{"type":"string","value":""}'){
this.testRet = "测试失败"
this.testRet = "测试失败
1
"
return;
}
if(getLog("字符串打印测试") != '{"type":"string","value":"字符串打印测试"}'){
this.testRet = "测试失败"
this.testRet = "测试失败
2
"
return;
}
if(getLog(2023) != '{"subType":"number","type":"
number
","value":"2023"}'){
this.testRet = "测试失败"
if(getLog(2023) != '{"subType":"number","type":"
Int
","value":"2023"}'){
this.testRet = "测试失败
3
"
return;
}
// console.log(getLog(2023.0))
// if(getLog(2023.0) != '{"type":"number","value":"2023"}'){
// this.testRet = "测试失败"
// return;
// }
if(getLog(2023.002 as number) != '{"subType":"number","type":"number","value":"2023.002"}'){
this.testRet = "测试失败"
if(getLog(2023.002 as number) != '{"subType":"number","type":"Double","value":"2023.002"}'){
this.testRet = "测试失败4"
return;
}
if(logObjectTest() != '{"className":"uts.sdk.modules.utsApiTest.ParamOptions","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"array","subType":"array","className":"io.dcloud.uts.UTSArray","type":"object","value":{"properties":[{"name":
0,"type":"string","value":"1"},{"name":1,"type":"string","value":"2"},{"name":2
,"type":"string","value":"3"}]}},{"name":"title","type":"string","value":"logObjectTest"}]}}'){
this.testRet = "测试失败"
if(logObjectTest() != '{"className":"uts.sdk.modules.utsApiTest.ParamOptions","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"array","subType":"array","className":"io.dcloud.uts.UTSArray","type":"object","value":{"properties":[{"name":
{"value":{"value":0}},"type":"string","value":"1"},{"name":{"value":{"value":1}},"type":"string","value":"2"},{"name":{"value":{"value":2}}
,"type":"string","value":"3"}]}},{"name":"title","type":"string","value":"logObjectTest"}]}}'){
this.testRet = "测试失败
5
"
return;
}
if(logFunctionTest() != '{"parameter":[],"type":"function"}'){
this.testRet = "测试失败"
this.testRet = "测试失败
6
"
return;
}
if(logClassTest() != '{"className":"uts.sdk.modules.utsApiTest.C","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"name","type":"string","value":"ccc"},{"parameter":["string"],"name":"sayBye","type":"function"}]}}'){
this.testRet = "测试失败"
this.testRet = "测试失败
7
"
return;
}
/**
* uvue 和 vue 因为 java 版本不同,所以这里的打印格式可能存在差异
*/
if(logFileTest() != '{"className":"java.io.File","subType":"object","type":"object","value":{"methods":[],"properties":[]}}'){
this.testRet = "测试失败"
this.testRet = "测试失败
8
"
return;
}
if(logDateTest() != '{"className":"io.dcloud.uts.Date","subType":"date","type":"object","value":"Sat Aug 08 1998 08:00:00 GMT+0800"}'){
this.testRet = "测试失败"
this.testRet = "测试失败
9
"
return;
}
...
...
pages/SyntaxCase/consoleTest.vue
浏览文件 @
a92452ad
...
...
@@ -7,7 +7,7 @@
<
script
>
import
{
getLog
,
logObjectTest
,
logClassTest
,
logFunctionTest
,
logFileTest
,
logDateTest
,
frequently
ObjectTest
}
from
'
../../uni_modules/uts-api-test
'
import
{
getLog
,
logObjectTest
,
logClassTest
,
logFunctionTest
,
logFileTest
,
logDateTest
,
logUTSJSON
ObjectTest
}
from
'
../../uni_modules/uts-api-test
'
export
default
{
...
...
@@ -21,58 +21,51 @@
doLogTest
()
{
if
(
getLog
(
""
)
!=
'
{"type":"string","value":""}
'
){
this
.
testRet
=
"
测试失败
"
this
.
testRet
=
"
测试失败
1
"
return
;
}
if
(
getLog
(
"
字符串打印测试
"
)
!=
'
{"type":"string","value":"字符串打印测试"}
'
){
this
.
testRet
=
"
测试失败
"
this
.
testRet
=
"
测试失败
2
"
return
;
}
if
(
getLog
(
2023
)
!=
'
{"type":"number","value":"2023"}
'
){
this
.
testRet
=
"
测试失败
"
return
;
}
if
(
getLog
(
2023.0
)
!=
'
{"type":"number","value":"2023"}
'
){
this
.
testRet
=
"
测试失败
"
if
(
getLog
(
2023
)
!=
'
{"subType":"number","type":"Int","value":"2023"}
'
){
this
.
testRet
=
"
测试失败3
"
return
;
}
if
(
getLog
(
2023.002
)
!=
'
{"type":"number
","value":"2023.002"}
'
){
this
.
testRet
=
"
测试失败
"
if
(
getLog
(
2023.002
as
number
)
!=
'
{"subType":"number","type":"Double
","value":"2023.002"}
'
){
this
.
testRet
=
"
测试失败
4
"
return
;
}
if
(
logObjectTest
()
!=
'
{"className":"uts.sdk.modules.utsApiTest.ParamOptions","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"array","subType":"array","className":"io.dcloud.uts.UTSArray","type":"object","value":{"properties":[{"name":
0,"type":"string","value":"1"},{"name":1,"type":"string","value":"2"},{"name":2
,"type":"string","value":"3"}]}},{"name":"title","type":"string","value":"logObjectTest"}]}}
'
){
this
.
testRet
=
"
测试失败
"
if
(
logObjectTest
()
!=
'
{"className":"uts.sdk.modules.utsApiTest.ParamOptions","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"array","subType":"array","className":"io.dcloud.uts.UTSArray","type":"object","value":{"properties":[{"name":
{"value":{"value":0}},"type":"string","value":"1"},{"name":{"value":{"value":1}},"type":"string","value":"2"},{"name":{"value":{"value":2}}
,"type":"string","value":"3"}]}},{"name":"title","type":"string","value":"logObjectTest"}]}}
'
){
this
.
testRet
=
"
测试失败
5
"
return
;
}
if
(
logFunctionTest
()
!=
'
{"parameter":[],"type":"function"}
'
){
this
.
testRet
=
"
测试失败
"
this
.
testRet
=
"
测试失败
6
"
return
;
}
if
(
logClassTest
()
!=
'
{"className":"uts.sdk.modules.utsApiTest.C","subType":"object","__$originalPosition":"","type":"object","value":{"methods":[],"properties":[{"name":"name","type":"string","value":"ccc"},{"parameter":["string"],"name":"sayBye","type":"function"}]}}
'
){
this
.
testRet
=
"
测试失败
"
this
.
testRet
=
"
测试失败
7
"
return
;
}
if
(
logFileTest
()
!=
'
{"className":"java.io.File","subType":"object","type":"object","value":{"methods":[],"properties":[{"name":"filePath","type":"null","value":"null"},{"name":"path","type":"string","value":"/sdcard/temp/1.txt"},{"name":"prefixLength","subType":"number","type":"Int","value":"1"},{"name":"status","type":"null","value":"null"}]}}
'
){
this
.
testRet
=
"
测试失败
"
/**
* uvue 和 vue 因为 java 版本不同,所以这里的打印格式可能存在差异
*/
if
(
logFileTest
()
!=
'
{"className":"java.io.File","subType":"object","type":"object","value":{"methods":[],"properties":[]}}
'
){
this
.
testRet
=
"
测试失败8
"
return
;
}
if
(
logDateTest
()
!=
'
{"className":"io.dcloud.uts.Date","subType":"date","type":"object","value":"Sat Aug 08 1998 08:00:00 GMT+0800"}
'
){
this
.
testRet
=
"
测试失败
"
this
.
testRet
=
"
测试失败
9
"
return
;
}
if
(
!
frequentlyObjectTest
()){
this
.
testRet
=
"
测试失败
"
return
;
}
this
.
testRet
=
"
测试完成
"
}
...
...
pages/advance/advance.uvue
浏览文件 @
a92452ad
...
...
@@ -78,7 +78,12 @@
}, {
name: "实例测试示例",
url: "SyntaxCase/instanceTest"
}] as Page[]
},
{
name: "混编测试示例",
url: "SyntaxCase/MixNativeCode"
},
] as Page[]
},
{
name: "日志打印",
...
...
uni_modules/uts-syntaxcase/utssdk/app-android/JavaUser.java
0 → 100644
浏览文件 @
a92452ad
package
uts.sdk.modules.utsSyntaxcase
;
public
class
JavaUser
{
public
String
name
;
public
int
age
;
public
JavaUser
(
String
name
,
int
age
)
{
this
.
name
=
name
;
this
.
age
=
age
;
}
public
String
toString
()
{
return
"Name: "
+
name
+
", Age: "
+
age
;
}
}
uni_modules/uts-syntaxcase/utssdk/app-android/kotlinCode.kt
0 → 100644
浏览文件 @
a92452ad
package
uts.sdk.modules.utsSyntaxcase
import
android.os.Build
import
io.dcloud.uts.UTSAndroid
object
NativeCode
{
fun
getPhoneInfo
():
String
{
return
"${Build.BOARD}-${Build.USER}"
}
fun
finishActivity
(){
UTSAndroid
.
getUniActivity
()
?.
finish
()
}
fun
getJavaUser
():
JavaUser
{
return
JavaUser
(
"张三"
,
12
)
}
}
\ No newline at end of file
uni_modules/uts-syntaxcase/utssdk/index.uts
浏览文件 @
a92452ad
...
...
@@ -145,7 +145,16 @@ export function request(url : string) : RequestTask | null {
return
new
RequestTaskImpl
(
url
)
}
// #ifdef APP-ANDROID
// #ifdef UNI-APP-X
// #ifdef UNI-APP-X
export
function
callKotlinMethodGetInfo
():
String
{
return
NativeCode
.
getPhoneInfo
()
}
export
function
callJavaMethodGetInfo
():
String
{
return
new
JavaUser
(
"jack"
,
12
)
.
name
}
import
KeyEvent
from
'android.view.KeyEvent'
;
import
Configuration
from
'android.content.res.Configuration'
;
import
Bundle
from
'android.os.Bundle'
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录