基础相关
typescript
import core from 'cheese-core';
const base = core.base;
休眠: sleep(millisecond: number): void
✅
参数:
- ⭐
number
(millisecond):休眠时间(ms)
用法示例:
typescript
const timestamp = new Date();
console.log("开始休眠时间", timestamp.getTime());
base.sleep(3000)
console.log("结束休眠时间", timestamp.getTime());
吐司: toast(message: string): void
✅
参数:
- ⭐
string
(msg):消息
用法示例:
typescript
base.toast("欢迎使用Cheese")
日志: console.log(...args:any[]):void
🟩
参数:
- ⭐
any[]
(...args):消息
用法示例:
typescript
console.log("欢迎使用Cheese")
停止: exit(): void
✅
🚨 危险
用法示例:
typescript
console.log("开始运行")
base.exit()
base.sleep(1000)
console.log("正常运行完毕")
运行js: runJS(nodeName: string, js: string): void
✅
参数:
- ⭐
string
(nodeName):nodeName - ⭐
string
(js):js字符串
用法示例:
typescript
base.runJS(settings.nodeName, `
console.log("你好")`)
推到Ui进程运行: runOnUi(callback: Callback): void
✅
参数:
- ⭐
Callback
(callback):代码回调
用法示例:
typescript
base.runOnUi(()=>{
console.log("Ui线程")
})
运行WebView: runWebView(http: string): void
✅
参数:
- ⭐
string
(http):网址
用法示例:
typescript
base.runWebView("https://cheese.worldcore.cn")
启动Activity: startActivity(activityId:string,callback:Callback): void
✅
参数:
- ⭐
string
(activityId):内置Activity的对应Id [0...9] - ⭐
Callback
(callback):回调
用法示例:
typescript
xml.parseXml("/storage/emulated/0/Pictures/ui.xml")
base.startActivity("P0", (e) => {
console.log("onCreate", e)
e.context.setContentView(e.view)
})
重定向Python日志到Cheese日志: pythonLog(): void
✅
用法示例:
typescript
BaseApi.pythonLog()
将js字符串编译为V8字节码: makeJsb(jsString:string):string
✅
参数:
- ⭐
string
(jsString):js字符串
返回值:
- 🟢
string
:js字节码 - 🔴null
用法示例:
typescript
let jsb=base.makeJsb('console.log("111")')
console.log(jsb)
运行V8字节码: runJsb(jsbString:any):void
✅
参数:
- ⭐
string
(jsbString):js字节码
用法示例:
typescript
let jsb=base.makeJsb('console.log("111")')
base.runJsb(jsb)
Rect矩形: Rect(left: number, top: number, bottom: number, right: number): string
✅
参数:
- ⭐
number
(left):左 - ⭐
number
(top):上 - ⭐
number
(bottom):下 - ⭐
number
(right):右
用法示例:
typescript
console.log(base.Rect(1,2,3,4))
Rect矩形1: Rect1(left: number, top: number, bottom: number, right: number): any
✅
参数:
- ⭐
number
(left):左 - ⭐
number
(top):上 - ⭐
number
(bottom):下 - ⭐
number
(right):右
用法示例:
typescript
console.log(base.Rect1(1,2,3,4))