From dd8ad8033f5d2980664c5065b456de08ff67fd29 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 21 Mar 2023 18:19:21 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=BF=9B=E9=98=B6=E8=AF=AD?= =?UTF-8?q?=E6=B3=95=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/SyntaxCase/index.vue | 665 ++++++++++-------- uni_modules/uts-syntaxcase/index.uts | 103 --- .../utssdk/app-android/index.uts | 86 --- .../uts-syntaxcase/utssdk/app-ios/index.uts | 110 --- .../uts-syntaxcase/utssdk/app-ios/utils.uts | 3 - uni_modules/uts-syntaxcase/utssdk/index.uts | 133 ++++ .../uts-syntaxcase/utssdk/interface.uts | 11 + .../utssdk/{app-android => }/utils.uts | 0 8 files changed, 502 insertions(+), 609 deletions(-) delete mode 100644 uni_modules/uts-syntaxcase/index.uts delete mode 100644 uni_modules/uts-syntaxcase/utssdk/app-android/index.uts delete mode 100644 uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts delete mode 100644 uni_modules/uts-syntaxcase/utssdk/app-ios/utils.uts create mode 100644 uni_modules/uts-syntaxcase/utssdk/index.uts create mode 100644 uni_modules/uts-syntaxcase/utssdk/interface.uts rename uni_modules/uts-syntaxcase/utssdk/{app-android => }/utils.uts (100%) diff --git a/pages/SyntaxCase/index.vue b/pages/SyntaxCase/index.vue index 0acfca6..2a8689c 100644 --- a/pages/SyntaxCase/index.vue +++ b/pages/SyntaxCase/index.vue @@ -1,322 +1,373 @@ + \ No newline at end of file diff --git a/uni_modules/uts-syntaxcase/index.uts b/uni_modules/uts-syntaxcase/index.uts deleted file mode 100644 index 1a86e82..0000000 --- a/uni_modules/uts-syntaxcase/index.uts +++ /dev/null @@ -1,103 +0,0 @@ -type AsyncOptions = { - type: string; - success: (res: string) => void; - fail: (res: string) => void; - complete: (res: string) => void; -}; - -type SyntaxResult = { - name: string -}; - -type SyncResult = { - msg: string -} - - -/** - * 导出一个属性 - */ -export const MAX = 100; - -/** - * 导出一个同步方法 - * @returns - */ -export function testSync(msg: string): SyncResult { - console.log("log test"); - const res: SyncResult = { - msg: `hello ${msg}` - } - return res -} -/** - * 导出一个同步方法(触发了数组越界异常) - */ -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"); - - const res: SyntaxResult = { - name: "testSyncWithCallback" - } - return res -} -/** - * 导出一个异步方法 - * @returns - */ -export async function testAsync(opts: AsyncOptions): Promise { - if (opts.type == "success") { - opts.success("success"); - } else { - opts.fail("fail"); - } - opts.complete("complete"); - - const res: SyntaxResult = { - name: "testAsync" - } - return res -} - -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): SyntaxResult { - return testSyncWithCallback(opts); - } - static async testClassStaticAsync(opts: AsyncOptions): Promise { - const res = await testAsync(opts); - return res; - } - testClassSyncWithCallback(opts: AsyncOptions): SyntaxResult { - return testSyncWithCallback(opts); - } - async testClassAsync(opts: AsyncOptions): Promise { - const res = await testAsync(opts); - return res; - } -} diff --git a/uni_modules/uts-syntaxcase/utssdk/app-android/index.uts b/uni_modules/uts-syntaxcase/utssdk/app-android/index.uts deleted file mode 100644 index dfdc29f..0000000 --- a/uni_modules/uts-syntaxcase/utssdk/app-android/index.uts +++ /dev/null @@ -1,86 +0,0 @@ -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 deleted file mode 100644 index ae77730..0000000 --- a/uni_modules/uts-syntaxcase/utssdk/app-ios/index.uts +++ /dev/null @@ -1,110 +0,0 @@ -import { log } from "./utils.uts"; -type AsyncOptions = { - type: string; - success: (res: string) => void; - fail: (res: string) => void; - complete: (res: string) => void; -}; - -type SyntaxResult = { - name: string -}; - -type SyncResult = { - msg: string -} - -/** - * 导出一个属性 - */ -export const MAX = 100; - -/** - * 导出一个同步方法 - * @returns - */ -export function testSync(msg: string): SyncResult { - console.log("log test"); - log("log test1"); - - const res: SyncResult = { - msg: `hello ${msg}` - } - return res - // return { - // msg: `hello ${msg}`, - // }; -} -/** - * 导出一个同步方法(触发了数组越界异常) - */ -export function testSyncError() { - const arr: string[] = []; - console.log(arr[1]); -} -/** - * 导出一个带callback的同步方法 - * @param opts - */ -export function testSyncWithCallback(opts: AsyncOptions): SyntaxResult { - if (opts.type == "success") { - opts.success("success"); - } else { - opts.fail("fail"); - } - opts.complete("complete"); - - const res: SyntaxResult = { - name: "testSyncWithCallback" - } - return res; - // return { name: "testSyncWithCallback" }; -} -/** - * 导出一个异步方法 - * @returns - */ -export async function testAsync(opts: AsyncOptions): Promise { - if (opts.type == "success") { - opts.success("success"); - } else { - opts.fail("fail"); - } - opts.complete("complete"); - - const res: SyntaxResult = { - name: "testAsync" - } - return res; - // 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): SyntaxResult { - return testSyncWithCallback(opts); - } - static async testClassStaticAsync(opts: AsyncOptions): Promise { - const res = await testAsync(opts); - return res; - } - testClassSyncWithCallback(opts: AsyncOptions): SyntaxResult { - 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 deleted file mode 100644 index 71050f5..0000000 --- a/uni_modules/uts-syntaxcase/utssdk/app-ios/utils.uts +++ /dev/null @@ -1,3 +0,0 @@ -export function log(msg: string) { - console.log(msg); -} diff --git a/uni_modules/uts-syntaxcase/utssdk/index.uts b/uni_modules/uts-syntaxcase/utssdk/index.uts new file mode 100644 index 0000000..c6b78f3 --- /dev/null +++ b/uni_modules/uts-syntaxcase/utssdk/index.uts @@ -0,0 +1,133 @@ +import { RequestTask, SyncOptions } from "./interface.uts"; +import { log } from "./utils.uts"; +type AsyncOptions = { + type : string; + success : (res : string) => void; + fail : (res : string) => void; + complete : (res : string) => void; +}; + +type SyntaxResult = { + name : string +}; + +type SyncResult = { + msg : string +} + +/** + * 导出一个属性 + */ +export const MAX = 100; + +/** + * 导出一个同步方法 + * @returns + */ +export function testSync(msg : string) : SyncResult { + console.log("log test"); + log("log test1"); + + const res : SyncResult = { + msg: `hello ${msg}` + } + return res + // return { + // msg: `hello ${msg}`, + // }; +} +/** + * 导出一个同步方法(触发了数组越界异常) + */ +export function testSyncError() { + const arr : string[] = []; + console.log(arr[1]); +} +/** + * 导出一个带callback的同步方法 + * @param opts + */ +export function testSyncWithCallback(opts : AsyncOptions) : SyntaxResult { + if (opts.type == "success") { + opts.success("success"); + } else { + opts.fail("fail"); + } + opts.complete("complete"); + + const res : SyntaxResult = { + name: "testSyncWithCallback" + } + return res; + // return { name: "testSyncWithCallback" }; +} +/** + * 导出一个异步方法 + * @returns + */ +export async function testAsync(opts : AsyncOptions) : Promise { + if (opts.type == "success") { + opts.success("success"); + } else { + opts.fail("fail"); + } + opts.complete("complete"); + + const res : SyntaxResult = { + name: "testAsync" + } + return res; + // 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) : SyntaxResult { + return testSyncWithCallback(opts); + } + static async testClassStaticAsync(opts : AsyncOptions) : Promise { + const res = await testAsync(opts); + return res; + } + testClassSyncWithCallback(opts : AsyncOptions) : SyntaxResult { + return testSyncWithCallback(opts); + } + async testClassAsync(opts : AsyncOptions) : Promise { + const res = await testAsync(opts); + return res; + } +} + +class RequestTaskImpl implements RequestTask { + url : string + constructor(url : string) { + this.url = url + } + abort() : RequestTask { + return this + } + onCallback(callback : (res : string) => void) { + callback("onCallback") + } + sync(options : SyncOptions) : string { + options.success?.("success") + options.complete?.("success") + return "sync" + } +} + +export function request(url : string) : RequestTask { + return new RequestTaskImpl(url) +} \ No newline at end of file diff --git a/uni_modules/uts-syntaxcase/utssdk/interface.uts b/uni_modules/uts-syntaxcase/utssdk/interface.uts new file mode 100644 index 0000000..3a29e46 --- /dev/null +++ b/uni_modules/uts-syntaxcase/utssdk/interface.uts @@ -0,0 +1,11 @@ +export type SyncOptions = { + success ?: (res : string) => void + fail ?: (res : string) => void + complete ?: (res : string) => void +} +export interface RequestTask { + url : string + abort() : RequestTask + onCallback(callback : (res : string) => void) : void + sync(options : SyncOptions) : string +} \ No newline at end of file diff --git a/uni_modules/uts-syntaxcase/utssdk/app-android/utils.uts b/uni_modules/uts-syntaxcase/utssdk/utils.uts similarity index 100% rename from uni_modules/uts-syntaxcase/utssdk/app-android/utils.uts rename to uni_modules/uts-syntaxcase/utssdk/utils.uts -- GitLab