diff --git a/zh-cn/application-dev/reference/apis/js-apis-window.md b/zh-cn/application-dev/reference/apis/js-apis-window.md index 60c96d20ffe602dcba44b424be2b778239e34e46..03c730ae9055d858eb52e5f680a8b2bc06de01c4 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-window.md +++ b/zh-cn/application-dev/reference/apis/js-apis-window.md @@ -1384,7 +1384,7 @@ off(type: 'windowSizeChange', callback?: Callback<Size >): void | 参数名 | 类型 | 必填 | 说明 | | -------- | ----------------------------- | ---- | ------------------------------------------------------------ | - | type | string | 是 | 设置监听类型。
- type为'windowSizeChange'7+时表示监听类型为窗口尺寸变化监听; | + | type | string | 是 | 设置监听类型。
- type为'windowSizeChange'时表示监听类型为窗口尺寸变化监听; | | callback | Callback<[Size](#size)> | 否 | 回调返回监听到的信息。 | - 示例 @@ -1455,7 +1455,7 @@ on(type: 'keyboardHeightChange', callback: Callback<number>): void | 参数名 | 类型 | 必填 | 说明 | | -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | type | string | 是 | 设置监听类型。
- type为'keyboardHeightChange'时表示监听类型为键盘高度变化监听。 | - | callback | Callback<[AvoidArea](#avoidarea)> | 是 | 回调返回监听到的信息。 | + | callback | Callback<number> | 是 | 回调返回监听到的信息。 | - 示例 @@ -2160,4 +2160,301 @@ setTouchable(isTouchable: boolean): Promise<void> }); ``` -### \ No newline at end of file +## WindowStageEventType9+ + +WindowStage生命周期。 + +**系统能力**:以下各项对应的系统能力均为SystemCapability.WindowManager.WindowManager.Core + +| 名称 | 默认值 | 说明 | +| ---------- | ------ | -------- | +| FOREGROUND | 1 | 切到前台 | +| ACTIVE | 2 | 获焦状态 | +| INACTIVE | 3 | 失焦状态 | +| BACKGROUND | 4 | 切到后台 | + +## WindowStage9+ + +下列API示例中都需在[onWindowStageCreate()](js-apis-application-ability.md#abilityonwindowstagecreate)函数中使用WindowStage的实例调用对应方法。 + +### getMainWindow9+ + +getMainWindow(): Promise<Window> + +获取该WindowStage实例下的主窗口,使用Promise方式作为异步方法。 + +**系统能力**:SystemCapability.WindowManager.WindowManager.Core + +- 返回值 + + | 类型 | 说明 | + | -------------------------------- | ---------------------------------------------------------- | + | Promise<[Window](#window)> | 以Promise形式返回结果,返回当前WindowStage下的主窗口对象。 | + +- 示例 + + ``` + class myAbility extends Ability { + onWindowStageCreate(windowStage) { + console.log('onWindowStageCreate'); + var windowClass = null; + let promise = windowStage.getMainWindow(); + promise.then((data)=> { + windowClass = data; + console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)) + }).catch((err)=>{ + console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); + }); + } + } + ``` + +### getMainWindow9+ + +getMainWindow(callback: AsyncCallback<Window>): void + +获取该WindowStage实例下的主窗口,使用callback方式作为异步方法。 + +**系统能力**:SystemCapability.WindowManager.WindowManager.Core + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------------------------------------- | ---- | --------------------------------------- | + | callback | AsyncCallback<[Window](#window)> | 是 | 回调返回当前WindowStage下的主窗口对象。 | + +- 示例 + + ``` + class myAbility extends Ability { + onWindowStageCreate(windowStage) { + console.log('onWindowStageCreate'); + var windowClass = null; + windowStage.getMainWindow((err, data) => { + if (err.code) { + console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err)); + return; + } + windowClass = data; + console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data)); + }); + } + } + ``` + +### createSubWindow9+ + +createSubWindow(name: string): Promise<Window> + +创建该WindowStage实例下的子窗口,使用Promise方式作为异步方法。 + +**系统能力**:SystemCapability.WindowManager.WindowManager.Core +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | ------ | ------ | ---- | -------------- | + | name | String | 是 | 子窗口的名字。 | +- 返回值 + + | 类型 | 说明 | + | -------------------------------- | ------------------------------------------------- | + | Promise<[Window](#window)> | 以Promise形式返回结果,返回当前创建的子窗口对象。 | +- 示例 + + ``` + class myAbility extends Ability { + onWindowStageCreate(windowStage) { + console.log('onWindowStageCreate'); + var windowClass = null; + let promise = windowStage.createSubWindow("mySubWindow"); + promise.then((data)=> { + windowClass = data; + console.info('Succeeded in create sub window. Data: ' + JSON.stringify(data)) + }).catch((err)=>{ + console.error('Failed to create sub window. Cause: ' + JSON.stringify(err)); + }) + } + } + ``` + +### createSubWindow9+ + +createSubWindow(name: string, callback: AsyncCallback<Window>): void + +创建该WindowStage实例下的子窗口,使用callback方式作为异步方法。 + +**系统能力**:SystemCapability.WindowManager.WindowManager.Core + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | -------------------------------------- | ---- | ------------------------------ | + | name | String | 是 | 子窗口的名字。 | + | callback | AsyncCallback<[Window](#window)> | 是 | 回调返回当前创建的子窗口对象。 | + +- 示例 + + ``` + class myAbility extends Ability { + onWindowStageCreate(windowStage) { + console.log('onWindowStageCreate'); + var windowClass = null; + windowStage.createSubWindow("mySubWindow", (err, data) => { + if (err.code) { + console.error('Failed to create sub window. Cause: ' + JSON.stringify(err)); + return; + } + windowClass = data; + console.info('Succeeded in create sub window. Data: ' + JSON.stringify(data)); + windowClass.resetSize(500, 1000); + }); + } + } + ``` + +### getSubWindow9+ + +getSubWindow(): Promise<Array<Window>> + +获取该WindowStage实例下的所有子窗口,使用Promise方式作为异步方法。 + +**系统能力**:SystemCapability.WindowManager.WindowManager.Core +- 返回值 + + | 类型 | 说明 | + | --------------------------------------------- | ------------------------------------------------------------ | + | Promise<Array<[Window](#window)>> | 以Promise形式返回结果,返回当前WindowStage下的所有子窗口对象。 | + +- 示例 + + ``` + class myAbility extends Ability { + onWindowStageCreate(windowStage) { + console.log('onWindowStageCreate'); + var windowClass = null; + let promise = windowStage.getSubWindow(); + promise.then((data)=> { + windowClass = data; + console.info('Succeeded in obtaining the sub window. Data: ' + JSON.stringify(data)) + }).catch((err)=>{ + console.error('Failed to obtain the sub window. Cause: ' + JSON.stringify(err)); + }) + } + } + ``` + +### getSubWindow9+ + +getSubWindow(callback: AsyncCallback<Array<Window>>): void + +获取该WindowStage实例下的所有子窗口,使用callback方式作为异步方法。 + +**系统能力**:SystemCapability.WindowManager.WindowManager.Core +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | --------------------------------------------------- | ---- | ------------------------------------------- | + | callback | AsyncCallback<Array<[Window](#window)>> | 是 | 回调返回当前WindowStage下的所有子窗口对象。 | + +- 示例 + + ``` + class myAbility extends Ability { + onWindowStageCreate(windowStage) { + console.log('onWindowStageCreate'); + var windowClass = null; + windowStage.getSubWindow((err, data) => { + if (err.code) { + console.error('Failed to obtain the sub window. Cause: ' + JSON.stringify(err)); + return; + } + windowClass = data; + console.info('Succeeded in obtaining the sub window. Data: ' + JSON.stringify(data)); + }); + } + } + ``` + +### loadContent9+ + +loadContent(path: string, callback: AsyncCallback<void>): void + +为当前WindowStage的主窗口加载具体页面内容,使用callback方式作为异步方法。 + +**系统能力**:SystemCapability.WindowManager.WindowManager.Coretype为'windowSizeChange' + +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------------- | ---- | -------------------- | + | path | string | 是 | 设置加载页面的路径。 | + | callback | AsyncCallback<void> | 是 | 回调函数。 | + +- 示例 + + ``` + class myAbility extends Ability { + onWindowStageCreate(windowStage) { + console.log('onWindowStageCreate'); + windowStage.loadContent("pages/page2", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }); + } + } + ``` +### on('windowStageEvent')9+ + +on(eventType: 'windowStageEvent', callback: Callback<WindowStageEventType>): void + +开启WindowStage生命周期变化的监听。 + +**系统能力**:SystemCapability.WindowManager.WindowManager.Core +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | + | type | string | 是 | 设置监听类型。
- type为'windowStageEvent'时表示监听类型为WindowStage生命周期变化监听。 | + | callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 是 | 回调返回监听到的信息。 | + +- 示例 + + ``` + class myAbility extends Ability { + onWindowStageCreate(windowStage) { + console.log('onWindowStageCreate'); + var type = 'windowStageEvent'; + windowStage.on(type, (data) => { + console.info('Succeeded in enabling the listener for window stage event changes. Data: ' + JSON.stringify(data)); + }); + } + } + ``` + +### off('windowStageEvent')9+ + +off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void + +关闭WindowStage生命周期变化的监听。 + +**系统能力**:SystemCapability.WindowManager.WindowManager.Core +- 参数 + + | 参数名 | 类型 | 必填 | 说明 | + | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | + | type | string | 是 | 设置监听类型。
- type为'windowStageEvent'时表示监听类型为WindowStage生命周期变化监听。 | + | callback | Callback<[WindowStageEventType](#windowstageeventtype9)> | 否 | 回调返回监听到的信息。 | +- 示例 + + ``` + class myAbility extends Ability { + onWindowStageCreate(windowStage) { + console.log('onWindowStageCreate'); + var type = 'windowStageEvent'; + windowStage.off(type); + } + } + ``` \ No newline at end of file