index.uts 1.2 KB
Newer Older
lizhongyi_'s avatar
lizhongyi_ 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/**
 * json参数格式定义
 */
export type inputJSON = {
	inputText: string,
	errCode: number
}
/**
 * json入参格式
 */
export type JsonParamOptions = {
	input: inputJSON;
	success: (res: inputJSON) => 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" };
}


杜庆泉's avatar
杜庆泉 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
/**
 * 导出多次回调UTS函数
 * @param opts
 */
export function onCallback(callback: (sth:string) => void) {
  /**
   * 模拟多次回调
   */
  let count = 1
  let taskId = -1
  taskId = setInterval(function() {
    callback(`第 ${count} 次回调`)
    count++;
	console.log("count",count)
	if(count > 3){
		clearInterval(taskId)
	}
  }, 500);
	
}