From 062514f760c47b9ab6b5a799d41c5ed3f0fe8a7e Mon Sep 17 00:00:00 2001 From: XHY Date: Sat, 8 Oct 2022 12:40:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=20iOS=20=E7=AB=AF=20uts=20?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utssdk/app-ios/index.uts | 24 ++++++ .../uts-advance/utssdk/app-ios/index.uts | 56 ++++++++++++ .../uts-helloworld/utssdk/app-ios/index.uts | 46 ++++++++++ uni_modules/uts-syntaxcase/index.uts | 86 +++++++++++++++++++ .../uts-syntaxcase/utssdk/app-ios/index.uts | 86 +++++++++++++++++++ .../uts-syntaxcase/utssdk/app-ios/utils.uts | 3 + 6 files changed, 301 insertions(+) create mode 100644 uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts create mode 100644 uni_modules/uts-advance/utssdk/app-ios/index.uts create mode 100644 uni_modules/uts-helloworld/utssdk/app-ios/index.uts create mode 100644 uni_modules/uts-syntaxcase/index.uts create mode 100644 uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts create mode 100644 uni_modules/uts-syntaxcase/utssdk/app-ios/utils.uts diff --git a/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts new file mode 100644 index 0000000..1da9652 --- /dev/null +++ b/uni_modules/uni-getbatteryinfo/utssdk/app-ios/index.uts @@ -0,0 +1,24 @@ +import { UIDevice } from "UIKit"; + +type GetBatteryInfoOptions = { + success?: (res: UTSJSONObject) => void; + fail?: (res: UTSJSONObject) => void; + complete?: (res: UTSJSONObject) => void; +}; + +export default function getBatteryInfo(options: GetBatteryInfoOptions) { + + UIDevice.current.isBatteryMonitoringEnabled = true + + const res = { + errMsg: "getBatteryInfo:ok", + level: UIDevice.current.batteryLevel * 100, + isCharging: UIDevice.current.batteryState == UIDevice.BatteryState.charging, + }; + if (options.success != null) { + options.success!(res); + } + if (options.complete != null) { + options.complete!(res); + } +} diff --git a/uni_modules/uts-advance/utssdk/app-ios/index.uts b/uni_modules/uts-advance/utssdk/app-ios/index.uts new file mode 100644 index 0000000..10674ce --- /dev/null +++ b/uni_modules/uts-advance/utssdk/app-ios/index.uts @@ -0,0 +1,56 @@ +export function addViewToDecorView() { } +export function removeViewToDecorView() { } +export function initAppLifecycle() { } +export function getLogoPath() {} +export function playAssetAudio(){} + +/** + * 定时任务参数封装 + */ +type TimerOptions = { + /** + * 定时任务开始的回调 + * @res 回调参数 + */ + start: (res: string) => void; + /** + * 定时任务执行的回调 + * @res 回调参数 + */ + work: (res: string) => void; +}; + + +/** + * 执行延时任务 + */ +export function doTimerTask(opts:TimerOptions) { + opts.start('doTimerTask start'); + setTimeout(function() { + opts.work("doTimerTask work"); + }, 2000); + + return { name: "doTimerTask" }; +} + +/** + * 执行周期任务 + */ +export function doIntervalTask(opts:TimerOptions) { + + let taskRet = setInterval(function() { + opts.work("doIntervalTask work"); + }, 2000); + opts.start('doIntervalTask start'); + + return { name: "doIntervalTask",taskId:taskRet}; +} + +/** + * 清除周期任务 + */ +export function clearIntervalTask(taskId:number) { + + clearInterval(taskId); + return { name: "clearIntervalTask"}; +} \ No newline at end of file diff --git a/uni_modules/uts-helloworld/utssdk/app-ios/index.uts b/uni_modules/uts-helloworld/utssdk/app-ios/index.uts new file mode 100644 index 0000000..e42147d --- /dev/null +++ b/uni_modules/uts-helloworld/utssdk/app-ios/index.uts @@ -0,0 +1,46 @@ +/** + * json参数格式定义 + */ +type inputJSON = { + inputText: string, + errCode: number +} +/** + * json入参格式 + */ +type JsonParamOptions = { + input: inputJSON; + success: (res: string) => void; + fail: (res: string) => void; + complete: (res: string) => void; +}; + + +/** + * 导出无参的UTS函数 + * @param opts + */ +export function callWithoutParam(success: () => void) { + success(); + return { name: "doSthWithCallback" }; +} + +/** + * 导出一个字符串入参的UTS函数 + */ +export function callWithStringParam(input: string, success: (res: string) => void) { + success(input); + return { name: "doSthWithCallback" }; +} + +/** + * 导出一个JSON入参的UTS函数 + */ +export function callWithJSONParam(opts: JsonParamOptions) { + opts.input.errCode = 10; + opts.success(opts.input); + return { name: "doSthWithCallback" }; +} + + + diff --git a/uni_modules/uts-syntaxcase/index.uts b/uni_modules/uts-syntaxcase/index.uts new file mode 100644 index 0000000..dfdc29f --- /dev/null +++ b/uni_modules/uts-syntaxcase/index.uts @@ -0,0 +1,86 @@ +import { log } from "./utils.uts"; +type AsyncOptions = { + type: string; + success: (res: string) => void; + fail: (res: string) => void; + complete: (res: string) => void; +}; +/** + * 导出一个属性 + */ +export const MAX = 100; + +/** + * 导出一个同步方法 + * @returns + */ +export function testSync(msg: string) { + console.log("log test"); + log("log test1"); + return { + msg: `hello ${msg}`, + }; +} +/** + * 导出一个同步方法(触发了数组越界异常) + */ +export function testSyncError() { + const arr: string[] = []; + console.log(arr[1]); +} +/** + * 导出一个带callback的同步方法 + * @param opts + */ +export function testSyncWithCallback(opts: AsyncOptions) { + if (opts.type == "success") { + opts.success("success"); + } else { + opts.fail("fail"); + } + opts.complete("complete"); + return { name: "testSyncWithCallback" }; +} +/** + * 导出一个异步方法 + * @returns + */ +export async function testAsync(opts: AsyncOptions) { + if (opts.type == "success") { + opts.success("success"); + } else { + opts.fail("fail"); + } + opts.complete("complete"); + return { name: "testAsync" }; +} + +type TestOptions = { + name: string; + callback: (res: string) => void; +}; + +export class Test { + id: number; + name: string; + static type: string = "Test"; + constructor(id: number, options: TestOptions) { + this.id = id; + this.name = options.name; + options.callback("Test.constructor"); + } + static testClassStaticSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + return testSyncWithCallback(opts); + } + static async testClassStaticAsync(opts: AsyncOptions): Promise { + const res = await testAsync(opts); + return res; + } + testClassSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + return testSyncWithCallback(opts); + } + async testClassAsync(opts: AsyncOptions): Promise { + const res = await testAsync(opts); + return res; + } +} diff --git a/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts b/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts new file mode 100644 index 0000000..dfdc29f --- /dev/null +++ b/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts @@ -0,0 +1,86 @@ +import { log } from "./utils.uts"; +type AsyncOptions = { + type: string; + success: (res: string) => void; + fail: (res: string) => void; + complete: (res: string) => void; +}; +/** + * 导出一个属性 + */ +export const MAX = 100; + +/** + * 导出一个同步方法 + * @returns + */ +export function testSync(msg: string) { + console.log("log test"); + log("log test1"); + return { + msg: `hello ${msg}`, + }; +} +/** + * 导出一个同步方法(触发了数组越界异常) + */ +export function testSyncError() { + const arr: string[] = []; + console.log(arr[1]); +} +/** + * 导出一个带callback的同步方法 + * @param opts + */ +export function testSyncWithCallback(opts: AsyncOptions) { + if (opts.type == "success") { + opts.success("success"); + } else { + opts.fail("fail"); + } + opts.complete("complete"); + return { name: "testSyncWithCallback" }; +} +/** + * 导出一个异步方法 + * @returns + */ +export async function testAsync(opts: AsyncOptions) { + if (opts.type == "success") { + opts.success("success"); + } else { + opts.fail("fail"); + } + opts.complete("complete"); + return { name: "testAsync" }; +} + +type TestOptions = { + name: string; + callback: (res: string) => void; +}; + +export class Test { + id: number; + name: string; + static type: string = "Test"; + constructor(id: number, options: TestOptions) { + this.id = id; + this.name = options.name; + options.callback("Test.constructor"); + } + static testClassStaticSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + return testSyncWithCallback(opts); + } + static async testClassStaticAsync(opts: AsyncOptions): Promise { + const res = await testAsync(opts); + return res; + } + testClassSyncWithCallback(opts: AsyncOptions): UTSJSONObject { + return testSyncWithCallback(opts); + } + async testClassAsync(opts: AsyncOptions): Promise { + const res = await testAsync(opts); + return res; + } +} diff --git a/uni_modules/uts-syntaxcase/utssdk/app-ios/utils.uts b/uni_modules/uts-syntaxcase/utssdk/app-ios/utils.uts new file mode 100644 index 0000000..71050f5 --- /dev/null +++ b/uni_modules/uts-syntaxcase/utssdk/app-ios/utils.uts @@ -0,0 +1,3 @@ +export function log(msg: string) { + console.log(msg); +} -- GitLab