1e41f4b71Sopenharmony_ci# Service Widget Development in FA Model 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Widget Overview 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciA service widget (also called widget) is a set of UI components that display important information or operations specific to an application. It provides users with direct access to a desired application service, without the need to open the application first. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ciA widget usually appears as a part of the UI of another application (which currently can only be a system application) and provides basic interactive features such as opening a UI page or sending a message. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ciBefore you get started, it would be helpful if you have a basic understanding of the following concepts: 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci- Widget host: an application that displays the widget content and controls the widget location. 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci- Widget Manager: a resident agent that provides widget management features such as periodic widget updates. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci- Widget provider: an atomic service that provides the widget content to display and controls how widget components are laid out and how they interact with users. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## Working Principles 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ciFigure 1 shows the working principles of the widget framework. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**Figure 1** Widget framework working principles in the FA model 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ciThe widget host consists of the following modules: 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci- Widget usage: provides operations such as creating, deleting, or updating a widget. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci- Communication adapter: provided by the OpenHarmony SDK for communication with the Widget Manager. It sends widget-related operations to the Widget Manager. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ciThe Widget Manager consists of the following modules: 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci- Periodic updater: starts a scheduled task based on the update policy to periodically update a widget after it is added to the Widget Manager. 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci- Cache manager: caches view information of a widget after it is added to the Widget Manager to directly return the cached data when the widget is obtained next time. This reduces the latency greatly. 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci- Lifecycle manager: suspends update when a widget is switched to the background or is blocked, and updates and/or clears widget data during upgrade and deletion. 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci- Object manager: manages RPC objects of the widget host. It is used to verify requests from the widget host and process callbacks after the widget update. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci- Communication adapter: communicates with the widget host and provider through RPCs. 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ciThe widget provider consists of the following modules: 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci- Widget service: implemented by the widget provider developer to process requests on widget creation, update, and deletion, and to provide corresponding widget services. 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci- Instance manager: implemented by the widget provider developer for persistent management of widget instances allocated by the Widget Manager. 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci- Communication adapter: provided by the OpenHarmony SDK for communication with the Widget Manager. It pushes update data to the Widget Manager. 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci> **NOTE** 54e41f4b71Sopenharmony_ci> 55e41f4b71Sopenharmony_ci> You only need to develop the widget provider. The system automatically handles the work of the widget host and Widget Manager. 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci## Available APIs 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ciThe **FormAbility** has the following APIs. 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci| API | Description | 63e41f4b71Sopenharmony_ci| -------- | -------- | 64e41f4b71Sopenharmony_ci| onCreate(want: Want): formBindingData.FormBindingData | Called to notify the widget provider that a widget has been created. | 65e41f4b71Sopenharmony_ci| onCastToNormal(formId: string): void | Called to notify the widget provider that a temporary widget has been converted to a normal one. | 66e41f4b71Sopenharmony_ci| onUpdate(formId: string): void | Called to notify the widget provider that a widget has been updated. | 67e41f4b71Sopenharmony_ci| onVisibilityChange(newStatus: Record<string, number>): void | Called to notify the widget provider of the change in widget visibility. | 68e41f4b71Sopenharmony_ci| onEvent(formId: string, message: string): void | Called to instruct the widget provider to receive and process a widget event. | 69e41f4b71Sopenharmony_ci| onDestroy(formId: string): void | Called to notify the widget provider that a widget has been destroyed. | 70e41f4b71Sopenharmony_ci| onAcquireFormState?(want: Want): formInfo.FormState | Called to instruct the widget provider to receive the status query result of a widget. | 71e41f4b71Sopenharmony_ci| onShare?(formId: string): {[key: string]: any} | Called by the widget provider to receive shared widget data. | 72e41f4b71Sopenharmony_ci| onShareForm?(formId: string): Record<string, Object> | Called by the widget provider to receive shared widget data. You are advised to use this API, instead of **onShare()**. If this API is implemented, **onShare()** will not be triggered. | 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ciThe **FormProvider** class has the following APIs. For details, see [FormProvider](../reference/apis-form-kit/js-apis-app-form-formProvider.md). 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci| API | Description | 78e41f4b71Sopenharmony_ci| -------- | -------- | 79e41f4b71Sopenharmony_ci| setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback<void>): void; | Sets the next refresh time for a widget. This API uses an asynchronous callback to return the result. | 80e41f4b71Sopenharmony_ci| setFormNextRefreshTime(formId: string, minute: number): Promise<void>; | Sets the next refresh time for a widget. This API uses a promise to return the result. | 81e41f4b71Sopenharmony_ci| updateForm(formId: string, formBindingData: FormBindingData, callback: AsyncCallback<void>): void; | Updates a widget. This API uses an asynchronous callback to return the result. | 82e41f4b71Sopenharmony_ci| updateForm(formId: string, formBindingData: FormBindingData): Promise<void>; | Updates a widget. This API uses a promise to return the result. | 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ciThe **FormBindingData** class has the following APIs. For details, see [FormBindingData](../reference/apis-form-kit/js-apis-app-form-formBindingData.md). 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci| API | Description | 89e41f4b71Sopenharmony_ci| -------- | -------- | 90e41f4b71Sopenharmony_ci| createFormBindingData(obj?: Object \ string): FormBindingData| | Creates a **FormBindingData** object. | 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci## How to Develop 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ciThe widget provider development based on the [FA model](../application-models/fa-model-development-overview.md) involves the following key steps: 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci- [Implementing Widget Lifecycle Callbacks](#implementing-widget-lifecycle-callbacks): Develop the **FormAbility** lifecycle callback functions. 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci- [Configuring the Widget Configuration File](#configuring-the-widget-configuration-file): Configure the application configuration file **config.json**. 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci- [Persistently Storing Widget Data](#persistently-storing-widget-data): Perform persistent management on widget information. 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci- [Updating Widget Data](#updating-widget-data): Call **updateForm()** to update the information displayed on a widget. 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci- [Developing the Widget UI Page](#developing-the-widget-ui-page): Use HML+CSS+JSON to develop a JS widget UI page. 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci- [Developing Widget Events](#developing-widget-events): Add the router and message events for a widget. 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci### Implementing Widget Lifecycle Callbacks 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ciTo create a widget in the FA model, implement the widget lifecycle callbacks. Generate a widget template by referring to <!--RP1-->[Developing a Service Widget](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-development-service-widget-0000001263280425)<!--RP1End-->. 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci1. Import related modules to **form.ts**. 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci ```ts 117e41f4b71Sopenharmony_ci import type featureAbility from '@ohos.ability.featureAbility'; 118e41f4b71Sopenharmony_ci import type Want from '@ohos.app.ability.Want'; 119e41f4b71Sopenharmony_ci import formBindingData from '@ohos.app.form.formBindingData'; 120e41f4b71Sopenharmony_ci import formInfo from '@ohos.app.form.formInfo'; 121e41f4b71Sopenharmony_ci import formProvider from '@ohos.app.form.formProvider'; 122e41f4b71Sopenharmony_ci import dataPreferences from '@ohos.data.preferences'; 123e41f4b71Sopenharmony_ci import hilog from '@ohos.hilog'; 124e41f4b71Sopenharmony_ci ``` 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci2. Implement the widget lifecycle callbacks in **form.ts**. 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci ```ts 129e41f4b71Sopenharmony_ci const TAG: string = '[Sample_FAModelAbilityDevelop]'; 130e41f4b71Sopenharmony_ci const domain: number = 0xFF00; 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci const DATA_STORAGE_PATH: string = 'form_store'; 133e41f4b71Sopenharmony_ci let storeFormInfo = async (formId: string, formName: string, tempFlag: boolean, context: featureAbility.Context): Promise<void> => { 134e41f4b71Sopenharmony_ci // Only the widget ID (formId), widget name (formName), and whether the widget is a temporary one (tempFlag) are persistently stored. 135e41f4b71Sopenharmony_ci let formInfo: Record<string, string | number | boolean> = { 136e41f4b71Sopenharmony_ci 'formName': 'formName', 137e41f4b71Sopenharmony_ci 'tempFlag': 'tempFlag', 138e41f4b71Sopenharmony_ci 'updateCount': 0 139e41f4b71Sopenharmony_ci }; 140e41f4b71Sopenharmony_ci try { 141e41f4b71Sopenharmony_ci const storage = await dataPreferences.getPreferences(context, DATA_STORAGE_PATH); 142e41f4b71Sopenharmony_ci // Put the widget information. 143e41f4b71Sopenharmony_ci await storage.put(formId, JSON.stringify(formInfo)); 144e41f4b71Sopenharmony_ci hilog.info(domain, TAG, `storeFormInfo, put form info successfully, formId: ${formId}`); 145e41f4b71Sopenharmony_ci await storage.flush(); 146e41f4b71Sopenharmony_ci } catch (err) { 147e41f4b71Sopenharmony_ci hilog.error(domain, TAG, `failed to storeFormInfo, err: ${JSON.stringify(err as Error)}`); 148e41f4b71Sopenharmony_ci } 149e41f4b71Sopenharmony_ci }; 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci let deleteFormInfo = async (formId: string, context: featureAbility.Context) => { 152e41f4b71Sopenharmony_ci try { 153e41f4b71Sopenharmony_ci const storage = await dataPreferences.getPreferences(context, DATA_STORAGE_PATH); 154e41f4b71Sopenharmony_ci // Delete the widget information. 155e41f4b71Sopenharmony_ci await storage.delete(formId); 156e41f4b71Sopenharmony_ci hilog.info(domain, TAG, `deleteFormInfo, del form info successfully, formId: ${formId}`); 157e41f4b71Sopenharmony_ci await storage.flush(); 158e41f4b71Sopenharmony_ci } catch (err) { 159e41f4b71Sopenharmony_ci hilog.error(domain, TAG, `failed to deleteFormInfo, err: ${JSON.stringify(err)}`); 160e41f4b71Sopenharmony_ci } 161e41f4b71Sopenharmony_ci } 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci class LifeCycle { 164e41f4b71Sopenharmony_ci onCreate: (want: Want) => formBindingData.FormBindingData = (want) => ({ data: '' }); 165e41f4b71Sopenharmony_ci onCastToNormal: (formId: string) => void = (formId) => { 166e41f4b71Sopenharmony_ci }; 167e41f4b71Sopenharmony_ci onUpdate: (formId: string) => void = (formId) => { 168e41f4b71Sopenharmony_ci }; 169e41f4b71Sopenharmony_ci onVisibilityChange: (newStatus: Record<string, number>) => void = (newStatus) => { 170e41f4b71Sopenharmony_ci let obj: Record<string, number> = { 171e41f4b71Sopenharmony_ci 'test': 1 172e41f4b71Sopenharmony_ci }; 173e41f4b71Sopenharmony_ci return obj; 174e41f4b71Sopenharmony_ci }; 175e41f4b71Sopenharmony_ci onEvent: (formId: string, message: string) => void = (formId, message) => { 176e41f4b71Sopenharmony_ci }; 177e41f4b71Sopenharmony_ci onDestroy: (formId: string) => void = (formId) => { 178e41f4b71Sopenharmony_ci }; 179e41f4b71Sopenharmony_ci onAcquireFormState?: (want: Want) => formInfo.FormState = (want) => (0); 180e41f4b71Sopenharmony_ci onShareForm?: (formId: string) => Record<string, Object> = (formId) => { 181e41f4b71Sopenharmony_ci let obj: Record<string, number> = { 182e41f4b71Sopenharmony_ci 'test': 1 183e41f4b71Sopenharmony_ci }; 184e41f4b71Sopenharmony_ci return obj; 185e41f4b71Sopenharmony_ci }; 186e41f4b71Sopenharmony_ci } 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci let obj: LifeCycle = { 189e41f4b71Sopenharmony_ci onCreate(want: Want) { 190e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onCreate'); 191e41f4b71Sopenharmony_ci if (want.parameters) { 192e41f4b71Sopenharmony_ci let formId = String(want.parameters['ohos.extra.param.key.form_identity']); 193e41f4b71Sopenharmony_ci let formName = String(want.parameters['ohos.extra.param.key.form_name']); 194e41f4b71Sopenharmony_ci let tempFlag = Boolean(want.parameters['ohos.extra.param.key.form_temporary']); 195e41f4b71Sopenharmony_ci // Persistently store widget data for subsequent use, such as instance acquisition and update. 196e41f4b71Sopenharmony_ci // Implement this API based on project requirements. 197e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onCreate' + formId); 198e41f4b71Sopenharmony_ci storeFormInfo(formId, formName, tempFlag, this.context); 199e41f4b71Sopenharmony_ci } 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci // Called when the widget is created. The widget provider should return the widget data binding class. 202e41f4b71Sopenharmony_ci let obj: Record<string, string> = { 203e41f4b71Sopenharmony_ci 'title': 'titleOnCreate', 204e41f4b71Sopenharmony_ci 'detail': 'detailOnCreate' 205e41f4b71Sopenharmony_ci }; 206e41f4b71Sopenharmony_ci let formData: formBindingData.FormBindingData = formBindingData.createFormBindingData(obj); 207e41f4b71Sopenharmony_ci return formData; 208e41f4b71Sopenharmony_ci }, 209e41f4b71Sopenharmony_ci onCastToNormal(formId: string) { 210e41f4b71Sopenharmony_ci // Called when the widget host converts the temporary widget into a normal one. The widget provider should do something to respond to the conversion. 211e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onCastToNormal'); 212e41f4b71Sopenharmony_ci }, 213e41f4b71Sopenharmony_ci onUpdate(formId: string) { 214e41f4b71Sopenharmony_ci // Override this method to support scheduled updates, periodic updates, or updates requested by the widget host. 215e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onUpdate'); 216e41f4b71Sopenharmony_ci let obj: Record<string, string> = { 217e41f4b71Sopenharmony_ci 'title': 'titleOnUpdate', 218e41f4b71Sopenharmony_ci 'detail': 'detailOnUpdate' 219e41f4b71Sopenharmony_ci }; 220e41f4b71Sopenharmony_ci let formData: formBindingData.FormBindingData = formBindingData.createFormBindingData(obj); 221e41f4b71Sopenharmony_ci // Call the updateForm() method to update the widget. Only the data passed through the input parameter is updated. Other information remains unchanged. 222e41f4b71Sopenharmony_ci formProvider.updateForm(formId, formData).catch((error: Error) => { 223e41f4b71Sopenharmony_ci hilog.error(domain, TAG, 'FormAbility updateForm, error:' + JSON.stringify(error)); 224e41f4b71Sopenharmony_ci }); 225e41f4b71Sopenharmony_ci }, 226e41f4b71Sopenharmony_ci onVisibilityChange(newStatus: Record<string, number>) { 227e41f4b71Sopenharmony_ci // Called when the widget host initiates an event about visibility changes. The widget provider should do something to respond to the notification. This callback takes effect only for system applications. 228e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onVisibilityChange'); 229e41f4b71Sopenharmony_ci }, 230e41f4b71Sopenharmony_ci onEvent(formId: string, message: string) { 231e41f4b71Sopenharmony_ci // If the widget supports event triggering, override this method and implement the trigger. 232e41f4b71Sopenharmony_ci let obj: Record<string, string> = { 233e41f4b71Sopenharmony_ci 'title': 'titleOnEvent', 234e41f4b71Sopenharmony_ci 'detail': 'detailOnEvent' 235e41f4b71Sopenharmony_ci }; 236e41f4b71Sopenharmony_ci let formData: formBindingData.FormBindingData = formBindingData.createFormBindingData(obj); 237e41f4b71Sopenharmony_ci // Call the updateForm() method to update the widget. Only the data passed through the input parameter is updated. Other information remains unchanged. 238e41f4b71Sopenharmony_ci formProvider.updateForm(formId, formData).catch((error: Error) => { 239e41f4b71Sopenharmony_ci hilog.error(domain, TAG, 'FormAbility updateForm, error:' + JSON.stringify(error)); 240e41f4b71Sopenharmony_ci }); 241e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onEvent'); 242e41f4b71Sopenharmony_ci }, 243e41f4b71Sopenharmony_ci onDestroy(formId: string) { 244e41f4b71Sopenharmony_ci // Delete widget data. 245e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onDestroy'); 246e41f4b71Sopenharmony_ci // Delete the persistent widget instance data. 247e41f4b71Sopenharmony_ci // Implement this API based on project requirements. 248e41f4b71Sopenharmony_ci deleteFormInfo(formId, this.context); 249e41f4b71Sopenharmony_ci }, 250e41f4b71Sopenharmony_ci onAcquireFormState(want: Want) { 251e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onAcquireFormState'); 252e41f4b71Sopenharmony_ci return formInfo.FormState.READY; 253e41f4b71Sopenharmony_ci } 254e41f4b71Sopenharmony_ci }; 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci export default obj; 257e41f4b71Sopenharmony_ci ``` 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci> **NOTE** 260e41f4b71Sopenharmony_ci> 261e41f4b71Sopenharmony_ci> FormAbility cannot reside in the background. Therefore, continuous tasks cannot be processed in the widget lifecycle callbacks. 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci### Configuring the Widget Configuration File 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ciThe widget configuration file is named **config.json**. Find the **config.json** file for the widget and edit the file depending on your need. 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci- The **js** module in the **config.json** file provides JavaScript resources of the widget. The internal structure is described as follows: 268e41f4b71Sopenharmony_ci | Name | Description | Data Type | Initial Value Allowed | 269e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 270e41f4b71Sopenharmony_ci | name | Name of a JavaScript component. The default value is **default**. | String | No | 271e41f4b71Sopenharmony_ci | pages | Route information about all pages in the JavaScript component, including the page path and page name. The value is an array, in which each element represents a page. The first element in the array represents the home page of the JavaScript FA. | Array | No | 272e41f4b71Sopenharmony_ci | window | Window-related configurations. | Object | Yes | 273e41f4b71Sopenharmony_ci | type | Type of the JavaScript component. The value can be:<br>**normal**: indicates an application instance.<br>**form**: indicates a widget instance. | String | Yes (initial value: **normal**) | 274e41f4b71Sopenharmony_ci | mode | Development mode of the JavaScript component. | Object | Yes (initial value: left empty) | 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci Example configuration: 277e41f4b71Sopenharmony_ci 278e41f4b71Sopenharmony_ci 279e41f4b71Sopenharmony_ci ```json 280e41f4b71Sopenharmony_ci "js": [ 281e41f4b71Sopenharmony_ci ... 282e41f4b71Sopenharmony_ci { 283e41f4b71Sopenharmony_ci "name": "widget", 284e41f4b71Sopenharmony_ci "pages": [ 285e41f4b71Sopenharmony_ci "pages/index/index" 286e41f4b71Sopenharmony_ci ], 287e41f4b71Sopenharmony_ci "window": { 288e41f4b71Sopenharmony_ci "designWidth": 720, 289e41f4b71Sopenharmony_ci "autoDesignWidth": true 290e41f4b71Sopenharmony_ci }, 291e41f4b71Sopenharmony_ci "type": "form" 292e41f4b71Sopenharmony_ci } 293e41f4b71Sopenharmony_ci ] 294e41f4b71Sopenharmony_ci ``` 295e41f4b71Sopenharmony_ci 296e41f4b71Sopenharmony_ci- The **abilities** module in the **config.json** file corresponds to **FormAbility** of the widget. The internal structure is described as follows: 297e41f4b71Sopenharmony_ci | Name | Description | Data Type | Initial Value Allowed | 298e41f4b71Sopenharmony_ci | -------- | -------- | -------- | -------- | 299e41f4b71Sopenharmony_ci | name | Class name of a widget. The value is a string with a maximum of 127 bytes. | String | No | 300e41f4b71Sopenharmony_ci | description | Description of the widget. The value can be a string or a resource index to descriptions in multiple languages. The value is a string with a maximum of 255 bytes. | String | Yes (initial value: left empty) | 301e41f4b71Sopenharmony_ci | isDefault | Whether the widget is a default one. Each ability has only one default widget.<br>**true**: The widget is the default one.<br>**false**: The widget is not the default one. | Boolean | No | 302e41f4b71Sopenharmony_ci | type | Type of the widget. The value can be:<br>**JS**: indicates a JavaScript-programmed widget. | String | No | 303e41f4b71Sopenharmony_ci | colorMode | Color mode of the widget.<br>**auto**: The widget adopts the auto-adaptive color mode.<br>**dark**: The widget adopts the dark color mode.<br>**light**: The widget adopts the light color mode. | String | Yes (initial value: **auto**) | 304e41f4b71Sopenharmony_ci | supportDimensions | Grid styles supported by the widget.<br>**1 * 2**: indicates a grid with one row and two columns.<br>**2 * 2**: indicates a grid with two rows and two columns.<br>**2 * 4**: indicates a grid with two rows and four columns.<br>**4 * 4**: indicates a grid with four rows and four columns. | String array | No | 305e41f4b71Sopenharmony_ci | defaultDimension | Default grid style of the widget. The value must be available in the **supportDimensions** array of the widget. | String | No | 306e41f4b71Sopenharmony_ci | updateEnabled | Whether the widget can be updated periodically.<br>**true**: The widget can be updated at a specified interval (**updateDuration**) or at the scheduled time (**scheduledUpdateTime**). **updateDuration** takes precedence over **scheduledUpdateTime**.<br>**false**: The widget cannot be updated periodically. | Boolean | No | 307e41f4b71Sopenharmony_ci | scheduledUpdateTime | Scheduled time to update the widget. The value is in 24-hour format and accurate to minute.<br>**updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used. | String | Yes (initial value: **0:0**) | 308e41f4b71Sopenharmony_ci | updateDuration | Interval to update the widget. The value is a natural number, in the unit of 30 minutes.<br>If the value is **0**, this field does not take effect.<br>If the value is a positive integer *N*, the interval is calculated by multiplying *N* and 30 minutes.<br>**updateDuration** takes precedence over **scheduledUpdateTime**. If both are specified, the value specified by **updateDuration** is used. | Number | Yes (initial value: **0**) | 309e41f4b71Sopenharmony_ci | formConfigAbility | Link to a specific page of the application. The value is a URI. | String | Yes (initial value: left empty) | 310e41f4b71Sopenharmony_ci | formVisibleNotify | Whether the widget is allowed to use the widget visibility notification. | String | Yes (initial value: left empty) | 311e41f4b71Sopenharmony_ci | jsComponentName | Component name of the widget. The value is a string with a maximum of 127 bytes. | String | No | 312e41f4b71Sopenharmony_ci | metaData | Metadata of the widget. This field contains the array of the **customizeData** field. | Object | Yes (initial value: left empty) | 313e41f4b71Sopenharmony_ci | customizeData | Custom information about the widget. | Object array | Yes (initial value: left empty) | 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci Example configuration: 316e41f4b71Sopenharmony_ci 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci ```json 319e41f4b71Sopenharmony_ci "abilities": [ 320e41f4b71Sopenharmony_ci ... 321e41f4b71Sopenharmony_ci { 322e41f4b71Sopenharmony_ci "name": ".FormAbility", 323e41f4b71Sopenharmony_ci "srcPath": "FormAbility", 324e41f4b71Sopenharmony_ci "description": "$string:FormAbility_desc", 325e41f4b71Sopenharmony_ci "icon": "$media:icon", 326e41f4b71Sopenharmony_ci "label": "$string:FormAbility_label", 327e41f4b71Sopenharmony_ci "type": "service", 328e41f4b71Sopenharmony_ci "formsEnabled": true, 329e41f4b71Sopenharmony_ci "srcLanguage": "ets", 330e41f4b71Sopenharmony_ci "forms": [ 331e41f4b71Sopenharmony_ci { 332e41f4b71Sopenharmony_ci "jsComponentName": "widget", 333e41f4b71Sopenharmony_ci "isDefault": true, 334e41f4b71Sopenharmony_ci "scheduledUpdateTime": "10:30", 335e41f4b71Sopenharmony_ci "defaultDimension": "2*2", 336e41f4b71Sopenharmony_ci "name": "widget", 337e41f4b71Sopenharmony_ci "description": "This is a service widget.", 338e41f4b71Sopenharmony_ci "colorMode": "auto", 339e41f4b71Sopenharmony_ci "type": "JS", 340e41f4b71Sopenharmony_ci "formVisibleNotify": true, 341e41f4b71Sopenharmony_ci "supportDimensions": [ 342e41f4b71Sopenharmony_ci "2*2" 343e41f4b71Sopenharmony_ci ], 344e41f4b71Sopenharmony_ci "updateEnabled": true, 345e41f4b71Sopenharmony_ci "updateDuration": 1 346e41f4b71Sopenharmony_ci } 347e41f4b71Sopenharmony_ci ] 348e41f4b71Sopenharmony_ci }, 349e41f4b71Sopenharmony_ci ... 350e41f4b71Sopenharmony_ci ] 351e41f4b71Sopenharmony_ci ``` 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci### Persistently Storing Widget Data 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ciA widget provider is usually started when it is needed to provide information about a widget. The Widget Manager supports multi-instance management and uses the widget ID to identify an instance. If the widget provider supports widget data modification, it must persistently store the data based on the widget ID, so that it can access the data of the target widget when obtaining, updating, or starting a widget. You should override **onDestroy** to implement widget data deletion. 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci```ts 360e41f4b71Sopenharmony_ciconst TAG: string = '[Sample_FAModelAbilityDevelop]'; 361e41f4b71Sopenharmony_ciconst domain: number = 0xFF00; 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ciconst DATA_STORAGE_PATH: string = 'form_store'; 364e41f4b71Sopenharmony_cilet storeFormInfo = async (formId: string, formName: string, tempFlag: boolean, context: featureAbility.Context): Promise<void> => { 365e41f4b71Sopenharmony_ci // Only the widget ID (formId), widget name (formName), and whether the widget is a temporary one (tempFlag) are persistently stored. 366e41f4b71Sopenharmony_ci let formInfo: Record<string, string | number | boolean> = { 367e41f4b71Sopenharmony_ci 'formName': 'formName', 368e41f4b71Sopenharmony_ci 'tempFlag': 'tempFlag', 369e41f4b71Sopenharmony_ci 'updateCount': 0 370e41f4b71Sopenharmony_ci }; 371e41f4b71Sopenharmony_ci try { 372e41f4b71Sopenharmony_ci const storage = await dataPreferences.getPreferences(context, DATA_STORAGE_PATH); 373e41f4b71Sopenharmony_ci // Put the widget information. 374e41f4b71Sopenharmony_ci await storage.put(formId, JSON.stringify(formInfo)); 375e41f4b71Sopenharmony_ci hilog.info(domain, TAG, `storeFormInfo, put form info successfully, formId: ${formId}`); 376e41f4b71Sopenharmony_ci await storage.flush(); 377e41f4b71Sopenharmony_ci } catch (err) { 378e41f4b71Sopenharmony_ci hilog.error(domain, TAG, `failed to storeFormInfo, err: ${JSON.stringify(err as Error)}`); 379e41f4b71Sopenharmony_ci } 380e41f4b71Sopenharmony_ci}; 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_cilet deleteFormInfo = async (formId: string, context: featureAbility.Context) => { 383e41f4b71Sopenharmony_ci try { 384e41f4b71Sopenharmony_ci const storage = await dataPreferences.getPreferences(context, DATA_STORAGE_PATH); 385e41f4b71Sopenharmony_ci // Delete the widget information. 386e41f4b71Sopenharmony_ci await storage.delete(formId); 387e41f4b71Sopenharmony_ci hilog.info(domain, TAG, `deleteFormInfo, del form info successfully, formId: ${formId}`); 388e41f4b71Sopenharmony_ci await storage.flush(); 389e41f4b71Sopenharmony_ci } catch (err) { 390e41f4b71Sopenharmony_ci hilog.error(domain, TAG, `failed to deleteFormInfo, err: ${JSON.stringify(err)}`); 391e41f4b71Sopenharmony_ci } 392e41f4b71Sopenharmony_ci} 393e41f4b71Sopenharmony_ci 394e41f4b71Sopenharmony_ci... 395e41f4b71Sopenharmony_ci onCreate(want: Want) { 396e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onCreate'); 397e41f4b71Sopenharmony_ci if (want.parameters) { 398e41f4b71Sopenharmony_ci let formId = String(want.parameters['ohos.extra.param.key.form_identity']); 399e41f4b71Sopenharmony_ci let formName = String(want.parameters['ohos.extra.param.key.form_name']); 400e41f4b71Sopenharmony_ci let tempFlag = Boolean(want.parameters['ohos.extra.param.key.form_temporary']); 401e41f4b71Sopenharmony_ci // Persistently store widget data for subsequent use, such as instance acquisition and update. 402e41f4b71Sopenharmony_ci // Implement this API based on project requirements. 403e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onCreate' + formId); 404e41f4b71Sopenharmony_ci storeFormInfo(formId, formName, tempFlag, this.context); 405e41f4b71Sopenharmony_ci } 406e41f4b71Sopenharmony_ci 407e41f4b71Sopenharmony_ci // Called when the widget is created. The widget provider should return the widget data binding class. 408e41f4b71Sopenharmony_ci let obj: Record<string, string> = { 409e41f4b71Sopenharmony_ci 'title': 'titleOnCreate', 410e41f4b71Sopenharmony_ci 'detail': 'detailOnCreate' 411e41f4b71Sopenharmony_ci }; 412e41f4b71Sopenharmony_ci let formData: formBindingData.FormBindingData = formBindingData.createFormBindingData(obj); 413e41f4b71Sopenharmony_ci return formData; 414e41f4b71Sopenharmony_ci }, 415e41f4b71Sopenharmony_ci... 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_cilet deleteFormInfo = async (formId: string, context: featureAbility.Context): Promise<void> => { 418e41f4b71Sopenharmony_ci try { 419e41f4b71Sopenharmony_ci const storage = await dataPreferences.getPreferences(context, DATA_STORAGE_PATH); 420e41f4b71Sopenharmony_ci // Delete the widget information. 421e41f4b71Sopenharmony_ci await storage.delete(formId); 422e41f4b71Sopenharmony_ci hilog.info(domain, TAG, `deleteFormInfo, del form info successfully, formId: ${formId}`); 423e41f4b71Sopenharmony_ci await storage.flush(); 424e41f4b71Sopenharmony_ci } catch (err) { 425e41f4b71Sopenharmony_ci hilog.error(domain, TAG, `failed to deleteFormInfo, err: ${JSON.stringify(err)}`); 426e41f4b71Sopenharmony_ci } 427e41f4b71Sopenharmony_ci}; 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci... 430e41f4b71Sopenharmony_ci // Override onDestroy to implement widget data deletion. 431e41f4b71Sopenharmony_ci onDestroy(formId: string) { 432e41f4b71Sopenharmony_ci // Delete widget data. 433e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onDestroy'); 434e41f4b71Sopenharmony_ci // Delete the persistent widget instance data. 435e41f4b71Sopenharmony_ci // Implement this API based on project requirements. 436e41f4b71Sopenharmony_ci deleteFormInfo(formId, this.context); 437e41f4b71Sopenharmony_ci } 438e41f4b71Sopenharmony_ci... 439e41f4b71Sopenharmony_ci``` 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ciFor details about how to implement persistent data storage, see [Application Data Persistence Overview](../database/app-data-persistence-overview.md). 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ciThe **Want** object passed in by the widget host to the widget provider contains a flag that specifies whether the requested widget is normal or temporary. 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ci- Normal widget: a widget persistently used by the widget host, for example, a widget added to the home screen. 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci- Temporary widget: a widget temporarily used by the widget host, for example, the widget displayed when you swipe up on a widget application. 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ciConverting a temporary widget to a normal one: After you swipe up on a widget application, a temporary widget is displayed. If you touch the pin button on the widget, it is displayed as a normal widget on the home screen. 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ciData of a temporary widget will be deleted on the Widget Manager if the widget framework is killed and restarted. The widget provider, however, is not notified of the deletion and still keeps the data. Therefore, the widget provider needs to clear the data of temporary widgets proactively if the data has been kept for a long period of time. If the widget host has converted a temporary widget into a normal one, the widget provider should change the widget data from temporary storage to persistent storage. Otherwise, the widget data may be deleted by mistake. 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_ci### Updating Widget Data 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ciWhen an application initiates a scheduled or periodic update, the application obtains the latest data and calls **updateForm()** to update the widget. 457e41f4b71Sopenharmony_ci 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci```ts 460e41f4b71Sopenharmony_ciconst TAG: string = '[Sample_FAModelAbilityDevelop]'; 461e41f4b71Sopenharmony_ciconst domain: number = 0xFF00; 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_cionUpdate(formId: string) { 464e41f4b71Sopenharmony_ci // Override this method to support scheduled updates, periodic updates, or updates requested by the widget host. 465e41f4b71Sopenharmony_ci hilog.info(domain, TAG, 'FormAbility onUpdate'); 466e41f4b71Sopenharmony_ci let obj: Record<string, string> = { 467e41f4b71Sopenharmony_ci 'title': 'titleOnUpdate', 468e41f4b71Sopenharmony_ci 'detail': 'detailOnUpdate' 469e41f4b71Sopenharmony_ci }; 470e41f4b71Sopenharmony_ci let formData: formBindingData.FormBindingData = formBindingData.createFormBindingData(obj); 471e41f4b71Sopenharmony_ci // Call the updateForm() method to update the widget. Only the data passed through the input parameter is updated. Other information remains unchanged. 472e41f4b71Sopenharmony_ci formProvider.updateForm(formId, formData).catch((error: Error) => { 473e41f4b71Sopenharmony_ci hilog.error(domain, TAG, 'FormAbility updateForm, error:' + JSON.stringify(error)); 474e41f4b71Sopenharmony_ci }); 475e41f4b71Sopenharmony_ci} 476e41f4b71Sopenharmony_ci``` 477e41f4b71Sopenharmony_ci 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci### Developing the Widget UI Page 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ciYou can use the web-like paradigm (HML+CSS+JSON) to develop JS widget pages. This section describes how to develop a page shown below. 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci> **NOTE** 486e41f4b71Sopenharmony_ci> 487e41f4b71Sopenharmony_ci> In the FA model, only the JavaScript-based web-like development paradigm is supported when developing the widget UI. 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci- HML: uses web-like paradigm components to describe the widget page information. 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci ```html 492e41f4b71Sopenharmony_ci <div class="container"> 493e41f4b71Sopenharmony_ci <stack> 494e41f4b71Sopenharmony_ci <div class="container-img"> 495e41f4b71Sopenharmony_ci <image src="/common/widget.png" class="bg-img"></image> 496e41f4b71Sopenharmony_ci <image src="/common/rect.png" class="bottom-img"></image> 497e41f4b71Sopenharmony_ci </div> 498e41f4b71Sopenharmony_ci <div class="container-inner"> 499e41f4b71Sopenharmony_ci <text class="title" onclick="routerEvent">{{title}}</text> 500e41f4b71Sopenharmony_ci <text class="detail_text" onclick="messageEvent">{{detail}}</text> 501e41f4b71Sopenharmony_ci </div> 502e41f4b71Sopenharmony_ci </stack> 503e41f4b71Sopenharmony_ci </div> 504e41f4b71Sopenharmony_ci ``` 505e41f4b71Sopenharmony_ci 506e41f4b71Sopenharmony_ci- CSS: defines style information about the web-like paradigm components in HML. 507e41f4b71Sopenharmony_ci 508e41f4b71Sopenharmony_ci ```css 509e41f4b71Sopenharmony_ci .container { 510e41f4b71Sopenharmony_ci flex-direction: column; 511e41f4b71Sopenharmony_ci justify-content: center; 512e41f4b71Sopenharmony_ci align-items: center; 513e41f4b71Sopenharmony_ci } 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ci .bg-img { 516e41f4b71Sopenharmony_ci flex-shrink: 0; 517e41f4b71Sopenharmony_ci height: 100%; 518e41f4b71Sopenharmony_ci z-index: 1; 519e41f4b71Sopenharmony_ci } 520e41f4b71Sopenharmony_ci 521e41f4b71Sopenharmony_ci .bottom-img { 522e41f4b71Sopenharmony_ci position: absolute; 523e41f4b71Sopenharmony_ci width: 150px; 524e41f4b71Sopenharmony_ci height: 56px; 525e41f4b71Sopenharmony_ci top: 63%; 526e41f4b71Sopenharmony_ci background-color: rgba(216, 216, 216, 0.15); 527e41f4b71Sopenharmony_ci filter: blur(20px); 528e41f4b71Sopenharmony_ci z-index: 2; 529e41f4b71Sopenharmony_ci } 530e41f4b71Sopenharmony_ci 531e41f4b71Sopenharmony_ci .container-inner { 532e41f4b71Sopenharmony_ci flex-direction: column; 533e41f4b71Sopenharmony_ci justify-content: flex-end; 534e41f4b71Sopenharmony_ci align-items: flex-start; 535e41f4b71Sopenharmony_ci height: 100%; 536e41f4b71Sopenharmony_ci width: 100%; 537e41f4b71Sopenharmony_ci padding: 12px; 538e41f4b71Sopenharmony_ci } 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_ci .title { 541e41f4b71Sopenharmony_ci font-family: HarmonyHeiTi-Medium; 542e41f4b71Sopenharmony_ci font-size: 14px; 543e41f4b71Sopenharmony_ci color: rgba(255,255,255,0.90); 544e41f4b71Sopenharmony_ci letter-spacing: 0.6px; 545e41f4b71Sopenharmony_ci } 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_ci .detail_text { 548e41f4b71Sopenharmony_ci font-family: HarmonyHeiTi; 549e41f4b71Sopenharmony_ci font-size: 12px; 550e41f4b71Sopenharmony_ci color: rgba(255,255,255,0.60); 551e41f4b71Sopenharmony_ci letter-spacing: 0.51px; 552e41f4b71Sopenharmony_ci text-overflow: ellipsis; 553e41f4b71Sopenharmony_ci max-lines: 1; 554e41f4b71Sopenharmony_ci margin-top: 6px; 555e41f4b71Sopenharmony_ci } 556e41f4b71Sopenharmony_ci ``` 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci- JSON: defines data and event interaction on the widget UI page. 559e41f4b71Sopenharmony_ci 560e41f4b71Sopenharmony_ci ```json 561e41f4b71Sopenharmony_ci { 562e41f4b71Sopenharmony_ci "data": { 563e41f4b71Sopenharmony_ci "title": "TitleDefault", 564e41f4b71Sopenharmony_ci "detail": "TextDefault" 565e41f4b71Sopenharmony_ci }, 566e41f4b71Sopenharmony_ci "actions": { 567e41f4b71Sopenharmony_ci "routerEvent": { 568e41f4b71Sopenharmony_ci "action": "router", 569e41f4b71Sopenharmony_ci "abilityName": "com.samples.famodelabilitydevelop.MainAbility", 570e41f4b71Sopenharmony_ci "params": { 571e41f4b71Sopenharmony_ci "message": "add detail" 572e41f4b71Sopenharmony_ci } 573e41f4b71Sopenharmony_ci }, 574e41f4b71Sopenharmony_ci "messageEvent": { 575e41f4b71Sopenharmony_ci "action": "message", 576e41f4b71Sopenharmony_ci "params": { 577e41f4b71Sopenharmony_ci "message": "add detail" 578e41f4b71Sopenharmony_ci } 579e41f4b71Sopenharmony_ci } 580e41f4b71Sopenharmony_ci } 581e41f4b71Sopenharmony_ci } 582e41f4b71Sopenharmony_ci ``` 583e41f4b71Sopenharmony_ci 584e41f4b71Sopenharmony_ci 585e41f4b71Sopenharmony_ci### Developing Widget Events 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_ciYou can set router and message events for components on a widget. The router event applies to ability redirection, and the message event applies to custom click events. The key steps are as follows: 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ci1. Set the **onclick** field in the HML file to **routerEvent** or **messageEvent**, depending on the **actions** settings in the JSON file. 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci2. Set the router event. 592e41f4b71Sopenharmony_ci - **action**: **"router"**, which indicates a router event. 593e41f4b71Sopenharmony_ci - **abilityName**: name of the ability to redirect to (PageAbility component in the FA model and UIAbility component in the stage model). For example, the default UIAbility name created by DevEco Studio in the FA model is com.example.entry.EntryAbility. 594e41f4b71Sopenharmony_ci - **params**: custom parameters passed to the target ability. Set them as required. The value can be obtained from **parameters** in **want** used for starting the target ability. For example, in the lifecycle function **onCreate** of the EntryAbility in the FA model, **featureAbility.getWant()** can be used to obtain **want** and its **parameters** field. 595e41f4b71Sopenharmony_ci 596e41f4b71Sopenharmony_ci3. Set the message event. 597e41f4b71Sopenharmony_ci - **action**: **"message"**, which indicates a message event. 598e41f4b71Sopenharmony_ci - **params**: custom parameters of the message event. Set them as required. The value can be obtained from **message** in the widget lifecycle function **onEvent**. 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ciThe following is an example: 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_ci- HML file: 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_ci ```html 605e41f4b71Sopenharmony_ci <div class="container"> 606e41f4b71Sopenharmony_ci <stack> 607e41f4b71Sopenharmony_ci <div class="container-img"> 608e41f4b71Sopenharmony_ci <image src="/common/widget.png" class="bg-img"></image> 609e41f4b71Sopenharmony_ci <image src="/common/rect.png" class="bottom-img"></image> 610e41f4b71Sopenharmony_ci </div> 611e41f4b71Sopenharmony_ci <div class="container-inner"> 612e41f4b71Sopenharmony_ci <text class="title" onclick="routerEvent">{{title}}</text> 613e41f4b71Sopenharmony_ci <text class="detail_text" onclick="messageEvent">{{detail}}</text> 614e41f4b71Sopenharmony_ci </div> 615e41f4b71Sopenharmony_ci </stack> 616e41f4b71Sopenharmony_ci </div> 617e41f4b71Sopenharmony_ci ``` 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ci- CSS file: 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci ```css 622e41f4b71Sopenharmony_ci .container { 623e41f4b71Sopenharmony_ci flex-direction: column; 624e41f4b71Sopenharmony_ci justify-content: center; 625e41f4b71Sopenharmony_ci align-items: center; 626e41f4b71Sopenharmony_ci } 627e41f4b71Sopenharmony_ci 628e41f4b71Sopenharmony_ci .bg-img { 629e41f4b71Sopenharmony_ci flex-shrink: 0; 630e41f4b71Sopenharmony_ci height: 100%; 631e41f4b71Sopenharmony_ci z-index: 1; 632e41f4b71Sopenharmony_ci } 633e41f4b71Sopenharmony_ci 634e41f4b71Sopenharmony_ci .bottom-img { 635e41f4b71Sopenharmony_ci position: absolute; 636e41f4b71Sopenharmony_ci width: 150px; 637e41f4b71Sopenharmony_ci height: 56px; 638e41f4b71Sopenharmony_ci top: 63%; 639e41f4b71Sopenharmony_ci background-color: rgba(216, 216, 216, 0.15); 640e41f4b71Sopenharmony_ci filter: blur(20px); 641e41f4b71Sopenharmony_ci z-index: 2; 642e41f4b71Sopenharmony_ci } 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ci .container-inner { 645e41f4b71Sopenharmony_ci flex-direction: column; 646e41f4b71Sopenharmony_ci justify-content: flex-end; 647e41f4b71Sopenharmony_ci align-items: flex-start; 648e41f4b71Sopenharmony_ci height: 100%; 649e41f4b71Sopenharmony_ci width: 100%; 650e41f4b71Sopenharmony_ci padding: 12px; 651e41f4b71Sopenharmony_ci } 652e41f4b71Sopenharmony_ci 653e41f4b71Sopenharmony_ci .title { 654e41f4b71Sopenharmony_ci font-family: HarmonyHeiTi-Medium; 655e41f4b71Sopenharmony_ci font-size: 14px; 656e41f4b71Sopenharmony_ci color: rgba(255,255,255,0.90); 657e41f4b71Sopenharmony_ci letter-spacing: 0.6px; 658e41f4b71Sopenharmony_ci } 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci .detail_text { 661e41f4b71Sopenharmony_ci font-family: HarmonyHeiTi; 662e41f4b71Sopenharmony_ci font-size: 12px; 663e41f4b71Sopenharmony_ci color: rgba(255,255,255,0.60); 664e41f4b71Sopenharmony_ci letter-spacing: 0.51px; 665e41f4b71Sopenharmony_ci text-overflow: ellipsis; 666e41f4b71Sopenharmony_ci max-lines: 1; 667e41f4b71Sopenharmony_ci margin-top: 6px; 668e41f4b71Sopenharmony_ci } 669e41f4b71Sopenharmony_ci ``` 670e41f4b71Sopenharmony_ci 671e41f4b71Sopenharmony_ci- JSON file: 672e41f4b71Sopenharmony_ci 673e41f4b71Sopenharmony_ci ```json 674e41f4b71Sopenharmony_ci { 675e41f4b71Sopenharmony_ci "data": { 676e41f4b71Sopenharmony_ci "title": "TitleDefault", 677e41f4b71Sopenharmony_ci "detail": "TextDefault" 678e41f4b71Sopenharmony_ci }, 679e41f4b71Sopenharmony_ci "actions": { 680e41f4b71Sopenharmony_ci "routerEvent": { 681e41f4b71Sopenharmony_ci "action": "router", 682e41f4b71Sopenharmony_ci "abilityName": "com.samples.famodelabilitydevelop.MainAbility", 683e41f4b71Sopenharmony_ci "params": { 684e41f4b71Sopenharmony_ci "message": "add detail" 685e41f4b71Sopenharmony_ci } 686e41f4b71Sopenharmony_ci }, 687e41f4b71Sopenharmony_ci "messageEvent": { 688e41f4b71Sopenharmony_ci "action": "message", 689e41f4b71Sopenharmony_ci "params": { 690e41f4b71Sopenharmony_ci "message": "add detail" 691e41f4b71Sopenharmony_ci } 692e41f4b71Sopenharmony_ci } 693e41f4b71Sopenharmony_ci } 694e41f4b71Sopenharmony_ci } 695e41f4b71Sopenharmony_ci ``` 696