提交 fc1a78cb 编写于 作者: lizhongyi_'s avatar lizhongyi_

fix: uni-usercapturescreen / uni-syntaxcase 部分uts语法更改

上级 638c27e1
import { NotificationCenter} from 'Foundation'; import { NotificationCenter} from 'Foundation';
import { UIApplication } from "UIKit" import { UIApplication } from "UIKit"
import { OnUserCaptureScreen, OffUserCaptureScreen, UserCaptureScreenCallback } from "../interface.uts"
/** /**
* 定义监听截屏事件工具类 * 定义监听截屏事件工具类
*/ */
class CaptureScreenTool { class CaptureScreenTool {
static listener?: UTSCallback; static listener: UserCaptureScreenCallback | null;
// 监听截屏 // 监听截屏
static listenCaptureScreen(callback?: UTSCallback) { static listenCaptureScreen(callback: UserCaptureScreenCallback | null) {
this.listener = callback this.listener = callback
// 注册监听截屏事件及回调方法 // 注册监听截屏事件及回调方法
...@@ -20,30 +22,41 @@ class CaptureScreenTool { ...@@ -20,30 +22,41 @@ class CaptureScreenTool {
// 捕获截屏回调的方法 // 捕获截屏回调的方法
// target-action 的方法前需要添加 @objc 前缀 // target-action 的方法前需要添加 @objc 前缀
@objc static userDidTakeScreenshot() { @objc static userDidTakeScreenshot() {
const obj = new UTSJSONObject()
// 回调 // 回调
this.listener?.(obj) this.listener?.({})
} }
// 移除监听事件 // 移除监听事件
static removeListen(callback?: UTSCallback) { static removeListen(callback: UserCaptureScreenCallback | null) {
this.listener = null this.listener = null
NotificationCenter.default.removeObserver(this) NotificationCenter.default.removeObserver(this)
const obj = new UTSJSONObject()
callback?.(obj)
} }
} }
// /**
// * 开启截图监听
// */
// export function onUserCaptureScreen(callback?: UTSCallback) {
// CaptureScreenTool.listenCaptureScreen(callback)
// }
// /**
// * 关闭截屏监听
// */
// export function offUserCaptureScreen(callback?: UTSCallback) {
// CaptureScreenTool.removeListen(callback)
// }
/** /**
* 开启截图监听 * 开启截图监听
*/ */
export function onUserCaptureScreen(callback?: UTSCallback) { export const onUserCaptureScreen : OnUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) {
CaptureScreenTool.listenCaptureScreen(callback) CaptureScreenTool.listenCaptureScreen(callback)
} }
/** /**
* 关闭截屏监听 * 关闭截屏监听
*/ */
export function offUserCaptureScreen(callback?: UTSCallback) { export const offUserCaptureScreen : OffUserCaptureScreen = function (callback : UserCaptureScreenCallback | null) {
CaptureScreenTool.removeListen(callback) CaptureScreenTool.removeListen(callback)
} }
export type UserCaptureScreenCallback = (res: any) => void
/**
* 开启截屏监听
*
* @param {UTSCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.8
*/
export type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
/**
* 关闭截屏监听
*
* @param {UTSCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
* @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
* @since 3.6.8
*/
export type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
\ No newline at end of file
...@@ -4,6 +4,16 @@ type AsyncOptions = { ...@@ -4,6 +4,16 @@ type AsyncOptions = {
fail: (res: string) => void; fail: (res: string) => void;
complete: (res: string) => void; complete: (res: string) => void;
}; };
type SyntaxResult = {
name: string
};
type SyncResult = {
msg: string
}
/** /**
* 导出一个属性 * 导出一个属性
*/ */
...@@ -13,11 +23,12 @@ export const MAX = 100; ...@@ -13,11 +23,12 @@ export const MAX = 100;
* 导出一个同步方法 * 导出一个同步方法
* @returns * @returns
*/ */
export function testSync(msg: string) { export function testSync(msg: string): SyncResult {
console.log("log test"); console.log("log test");
return { const res: SyncResult = {
msg: `hello ${msg}`, msg: `hello ${msg}`
}; }
return res
} }
/** /**
* 导出一个同步方法(触发了数组越界异常) * 导出一个同步方法(触发了数组越界异常)
...@@ -37,20 +48,28 @@ export function testSyncWithCallback(opts: AsyncOptions) { ...@@ -37,20 +48,28 @@ export function testSyncWithCallback(opts: AsyncOptions) {
opts.fail("fail"); opts.fail("fail");
} }
opts.complete("complete"); opts.complete("complete");
return { name: "testSyncWithCallback" };
const res: SyntaxResult = {
name: "testSyncWithCallback"
}
return res
} }
/** /**
* 导出一个异步方法 * 导出一个异步方法
* @returns * @returns
*/ */
export async function testAsync(opts: AsyncOptions) { export async function testAsync(opts: AsyncOptions): Promise<SyntaxResult> {
if (opts.type == "success") { if (opts.type == "success") {
opts.success("success"); opts.success("success");
} else { } else {
opts.fail("fail"); opts.fail("fail");
} }
opts.complete("complete"); opts.complete("complete");
return { name: "testAsync" };
const res: SyntaxResult = {
name: "testAsync"
}
return res
} }
type TestOptions = { type TestOptions = {
...@@ -67,17 +86,17 @@ export class Test { ...@@ -67,17 +86,17 @@ export class Test {
this.name = options.name; this.name = options.name;
options.callback("Test.constructor"); options.callback("Test.constructor");
} }
static testClassStaticSyncWithCallback(opts: AsyncOptions): UTSJSONObject { static testClassStaticSyncWithCallback(opts: AsyncOptions): SyntaxResult {
return testSyncWithCallback(opts); return testSyncWithCallback(opts);
} }
static async testClassStaticAsync(opts: AsyncOptions): Promise<UTSJSONObject> { static async testClassStaticAsync(opts: AsyncOptions): Promise<SyntaxResult> {
const res = await testAsync(opts); const res = await testAsync(opts);
return res; return res;
} }
testClassSyncWithCallback(opts: AsyncOptions): UTSJSONObject { testClassSyncWithCallback(opts: AsyncOptions): SyntaxResult {
return testSyncWithCallback(opts); return testSyncWithCallback(opts);
} }
async testClassAsync(opts: AsyncOptions): Promise<UTSJSONObject> { async testClassAsync(opts: AsyncOptions): Promise<SyntaxResult> {
const res = await testAsync(opts); const res = await testAsync(opts);
return res; return res;
} }
......
...@@ -5,6 +5,15 @@ type AsyncOptions = { ...@@ -5,6 +5,15 @@ type AsyncOptions = {
fail: (res: string) => void; fail: (res: string) => void;
complete: (res: string) => void; complete: (res: string) => void;
}; };
type SyntaxResult = {
name: string
};
type SyncResult = {
msg: string
}
/** /**
* 导出一个属性 * 导出一个属性
*/ */
...@@ -14,12 +23,17 @@ export const MAX = 100; ...@@ -14,12 +23,17 @@ export const MAX = 100;
* 导出一个同步方法 * 导出一个同步方法
* @returns * @returns
*/ */
export function testSync(msg: string) { export function testSync(msg: string): SyncResult {
console.log("log test"); console.log("log test");
log("log test1"); log("log test1");
return {
msg: `hello ${msg}`, const res: SyncResult = {
}; msg: `hello ${msg}`
}
return res
// return {
// msg: `hello ${msg}`,
// };
} }
/** /**
* 导出一个同步方法(触发了数组越界异常) * 导出一个同步方法(触发了数组越界异常)
...@@ -32,27 +46,37 @@ export function testSyncError() { ...@@ -32,27 +46,37 @@ export function testSyncError() {
* 导出一个带callback的同步方法 * 导出一个带callback的同步方法
* @param opts * @param opts
*/ */
export function testSyncWithCallback(opts: AsyncOptions) { export function testSyncWithCallback(opts: AsyncOptions): SyntaxResult {
if (opts.type == "success") { if (opts.type == "success") {
opts.success("success"); opts.success("success");
} else { } else {
opts.fail("fail"); opts.fail("fail");
} }
opts.complete("complete"); opts.complete("complete");
return { name: "testSyncWithCallback" };
const res: SyntaxResult = {
name: "testSyncWithCallback"
}
return res;
// return { name: "testSyncWithCallback" };
} }
/** /**
* 导出一个异步方法 * 导出一个异步方法
* @returns * @returns
*/ */
export async function testAsync(opts: AsyncOptions) { export async function testAsync(opts: AsyncOptions): Promise<SyntaxResult> {
if (opts.type == "success") { if (opts.type == "success") {
opts.success("success"); opts.success("success");
} else { } else {
opts.fail("fail"); opts.fail("fail");
} }
opts.complete("complete"); opts.complete("complete");
return { name: "testAsync" };
const res: SyntaxResult = {
name: "testAsync"
}
return res;
// return { name: "testAsync" };
} }
type TestOptions = { type TestOptions = {
...@@ -69,17 +93,17 @@ export class Test { ...@@ -69,17 +93,17 @@ export class Test {
this.name = options.name; this.name = options.name;
options.callback("Test.constructor"); options.callback("Test.constructor");
} }
static testClassStaticSyncWithCallback(opts: AsyncOptions): UTSJSONObject { static testClassStaticSyncWithCallback(opts: AsyncOptions): SyntaxResult {
return testSyncWithCallback(opts); return testSyncWithCallback(opts);
} }
static async testClassStaticAsync(opts: AsyncOptions): Promise<UTSJSONObject> { static async testClassStaticAsync(opts: AsyncOptions): Promise<SyntaxResult> {
const res = await testAsync(opts); const res = await testAsync(opts);
return res; return res;
} }
testClassSyncWithCallback(opts: AsyncOptions): UTSJSONObject { testClassSyncWithCallback(opts: AsyncOptions): SyntaxResult {
return testSyncWithCallback(opts); return testSyncWithCallback(opts);
} }
async testClassAsync(opts: AsyncOptions): Promise<UTSJSONObject> { async testClassAsync(opts: AsyncOptions): Promise<SyntaxResult> {
const res = await testAsync(opts); const res = await testAsync(opts);
return res; return res;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册