提交 7abc014a 编写于 作者: fxy060608's avatar fxy060608

wip(uts): update tests

上级 6e931a91
import IUniLogin, { OnConnect, RegisterOptions } from '../interface'
export default class UniLogin implements IUniLogin {
//@UniJSMethod({ uiThread: true })
login(name: string, code: number) {
console.log(name, code)
}
// {"name":"fxy","callback1":{__type__:"fun",id:1},"callback2":{__type__:"fun",id:1}}
// => RegisterOptions
async register(opts: RegisterOptions) {
opts.callback1(true)
opts.callback2(true)
opts.abc.callback3(true)
}
onConnect(callback: OnConnect) {}
}
......@@ -4,12 +4,12 @@ import UniModule from "io.dcloud.feature.uniapp.common.UniModule";
import UniJSMethod from "io.dcloud.feature.uniapp.annotation.UniJSMethod";
import UniJSCallback from "io.dcloud.feature.uniapp.bridge.UniJSCallback";
import log from "./log";
export default class TestModule extends UniModule() {
export default class TestModule implements UniLogin {
TAG = "TestModule";
static REQUEST_CODE = 1000;
//run ui thread
@UniJSMethod({ uiThread: true })
testAsyncFunc(options: JSONObject, callback?: UniJSCallback) {
async testAsyncFunc(options: JSONObject, callback?: UniJSCallback) {
log(this.TAG, "testAsyncFunc--$options");
if (callback != null) {
const data = new JSONObject();
......
import { login as Login, register as Register } from '../interface.fun'
export const login: Login = (name, code) => {
console.log(name, code)
}
// import { login } from '@/uni_modules/uni-login'
// => const uniLogin = require('class')
// import { UniLogin, test } from '@/uni_modules/uni-login'
// new UniLogin()
import { RegisterOptions, OnConnect } from './interface'
export interface login {
(name: string, code: number): void
}
export interface register {
(opts: RegisterOptions): Promise<void>
}
export interface onConnect {
(callback: OnConnect): void
}
export type RegisterOptions = {
name: string
callback1: (res: boolean) => void
callback2: (res: boolean) => void
abc: {
callback3: (res: boolean) => void
}
}
export type OnConnect = () => void
export default interface IUniLogin {
login: (name: string, code: number) => void
register: (opts: RegisterOptions) => Promise<void>
onConnect: (callback: OnConnect) => void
}
// import UniLogin from '@uni_modules/uni-login'
// new UniLogin()
......@@ -3,6 +3,7 @@
"id": "DCloud-UTSPlugin",
"version": "0.0.1",
"description": "UTS示例插件",
"main":"interface",
"_dp_type":"nativeplugin",
"_dp_nativeplugin":{
"android": {
......
import IUniLogin, { OnConnect, RegisterOptions } from '../interface.uts'
export default class UniLogin implements IUniLogin {
//@UniJSMethod({ uiThread: true })
override login(name, code) {
console.log(name, code)
}
// {"name":"fxy","callback1":{__type__:"fun",id:1},"callback2":{__type__:"fun",id:1}}
// => RegisterOptions
async register(opts: RegisterOptions) {
opts.callback1(true)
opts.callback2(true)
opts.abc.callback3(true)
}
override onConnect(callback: OnConnect) {}
}
export type RegisterOptions = {
name: string
callback1: (res: boolean) => void
callback2: (res: boolean) => void
abc: {
callback3: (res: boolean) => void
}
}
export type OnConnect = () => void
export default interface IUniLogin {
login: (name: string, code: number) => void
register: (opts: RegisterOptions) => Promise<void>
onConnect: (callback: OnConnect) => void
}
// import UniLogin from '@uni_modules/uni-login'
// new UniLogin()
{
"name": "UTS Plugin",
"id": "DCloud-UTSPlugin",
"version": "0.0.1",
"description": "UTS示例插件",
"main":"interface.uts",
"_dp_type":"nativeplugin",
"_dp_nativeplugin":{
"android": {
"plugins": [
{
"type": "module",
"name": "DCloud-UTSPlugin",
"class": "io.dcloud.uniplugin.TestModule"
},
{
"type": "component",
"name": "uts-richtext",
"class": "io.dcloud.uniplugin.TestComponent"
}
],
"integrateType": "uts",
"dependencies":[
{
"id": "com.zzhoujay.richtext:richtext",
"source": "implementation 'com.zzhoujay.richtext:richtext:3.0.7'"
}
],
"minSdkVersion" : 21
}
}
}
\ No newline at end of file
// 接口
interface IUniLogin {
login(): void
}
// 父类/基类
class BaseUniLogin {
register() {}
}
// 子类实现
class UniLogin extends BaseUniLogin implements IUniLogin {
// 实现接口的方法,不能写 override 关键词,因为 override 关键词仅能在实现父类的属性或方法上使用
login() {}
// 实现或覆盖父类的方法,可写可不写 override
override register(): void {}
}
async function testAsync(): Promise<number> {
return 1
}
async function main() {
const res = await testAsync()
return res
}
......@@ -5,10 +5,10 @@ import io.dcloud.feature.uniapp.common.UniModule;
import io.dcloud.feature.uniapp.annotation.UniJSMethod;
import io.dcloud.feature.uniapp.bridge.UniJSCallback;
import io.dcloud.uniplugin.log.log;
open class TestModule : UniModule() {
open class TestModule : UniLogin {
open var TAG = "TestModule";
@UniJSMethod( uiThread = true )
open fun testAsyncFunc(options: JSONObject, callback: UniJSCallback?) {
open fun async testAsyncFunc(options: JSONObject, callback: UniJSCallback?) {
log(this.TAG, "testAsyncFunc--$options");
if (callback != null) {
val data = JSONObject();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册