# @ohos.app.form.formProvider (formProvider) FormProvider模块提供了卡片提供方相关接口的能力,开发者在开发卡片时,可通过该模块提供接口实现更新卡片、设置卡片更新时间、获取卡片信息、请求发布卡片等。 > **说明:** > > 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 ## 导入模块 ```ts import { formProvider } from '@kit.FormKit'; ``` ## setFormNextRefreshTime setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback<void>): void 设置指定卡片的下一次更新时间,使用callback异步回调。 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 **系统能力:** SystemCapability.Ability.Form **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- | ------------------------------------- | | formId | string | 是 | 卡片标识。 | | minute | number | 是 | 指定多久之后更新。单位分钟,大于等于5。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** | 错误码ID | 错误信息 | | -------- | -------- | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | | 16500050 | IPC connection error. | | 16500060 | Service connection error. | | 16500100 | Failed to obtain the configuration information. | | 16501000 | An internal functional error occurred. | | 16501001 | The ID of the form to be operated does not exist. | | 16501002 | The number of forms exceeds the maximum allowed. | | 16501003 | The form cannot be operated by the current application. | 以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 **示例:** ```ts import { formProvider } from '@kit.FormKit'; import { BusinessError } from '@kit.BasicServicesKit'; let formId: string = '12400633174999288'; try { formProvider.setFormNextRefreshTime(formId, 5, (error: BusinessError) => { if (error) { console.error(`callback error, code: ${error.code}, message: ${error.message})`); return; } console.log(`formProvider setFormNextRefreshTime success`); }); } catch (error) { console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); } ``` ## setFormNextRefreshTime setFormNextRefreshTime(formId: string, minute: number): Promise<void> 设置指定卡片的下一次更新时间,使用Promise异步回调。 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 **系统能力:** SystemCapability.Ability.Form **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- | ------------------------------------- | | formId | string | 是 | 卡片标识。 | | minute | number | 是 | 指定多久之后更新。单位分钟,大于等于5。 | **返回值:** | 类型 | 说明 | | ------------- | ---------------------------------- | | Promise\ | 无返回结果的Promise对象。 | **错误码:** | 错误码ID | 错误信息 | | -------- | -------- | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | | 16500050 | IPC connection error. | | 16500060 | Service connection error. | | 16500100 | Failed to obtain the configuration information. | | 16501000 | An internal functional error occurred. | | 16501001 | The ID of the form to be operated does not exist. | | 16501002 | The number of forms exceeds the maximum allowed. | | 16501003 | The form cannot be operated by the current application. | 以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 **示例:** ```ts import { formProvider } from '@kit.FormKit'; import { BusinessError } from '@kit.BasicServicesKit'; let formId: string = '12400633174999288'; try { formProvider.setFormNextRefreshTime(formId, 5).then(() => { console.log(`formProvider setFormNextRefreshTime success`); }).catch((error: BusinessError) => { console.error(`promise error, code: ${error.code}, message: ${error.message})`); }); } catch (error) { console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); } ``` ## updateForm updateForm(formId: string, formBindingData: formBindingData.FormBindingData,callback: AsyncCallback<void>): void 更新指定的卡片,使用callback异步回调。 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 **系统能力:** SystemCapability.Ability.Form **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ---------------------------------------------------------------------- | ---- | ---------------- | | formId | string | 是 | 请求更新的卡片标识。 | | formBindingData | [formBindingData.FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | 是 | 用于更新的数据。 | | callback | AsyncCallback<void> | 是 | 回调函数。 | **错误码:** | 错误码ID | 错误信息 | | -------- | -------- | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | | 16500050 | IPC connection error. | | 16500060 | Service connection error. | | 16500100 | Failed to obtain the configuration information. | | 16501000 | An internal functional error occurred. | | 16501001 | The ID of the form to be operated does not exist. | | 16501003 | The form cannot be operated by the current application. | 以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 **示例:** ```ts import { formBindingData, formProvider } from '@kit.FormKit'; import { BusinessError } from '@kit.BasicServicesKit'; let formId: string = '12400633174999288'; try { let param: Record = { 'temperature': '22c', 'time': '22:00' } let obj: formBindingData.FormBindingData = formBindingData.createFormBindingData(param); formProvider.updateForm(formId, obj, (error: BusinessError) => { if (error) { console.error(`callback error, code: ${error.code}, message: ${error.message})`); return; } console.log(`formProvider updateForm success`); }); } catch (error) { console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); } ``` ## updateForm updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise<void> 更新指定的卡片,使用Promise异步回调。 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 **系统能力:** SystemCapability.Ability.Form **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ---------------------------------------------------------------------- | ---- | ---------------- | | formId | string | 是 | 请求更新的卡片标识。 | | formBindingData | [formBindingData.FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | 是 | 用于更新的数据。 | **返回值:** | 类型 | 说明 | | -------------- | ----------------------------------- | | Promise\ | 无返回结果的Promise对象。 | **错误码:** | 错误码ID | 错误信息 | | -------- | -------- | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | | 16500050 | IPC connection error. | | 16500060 | Service connection error. | | 16500100 | Failed to obtain the configuration information. | | 16501000 | An internal functional error occurred. | | 16501001 | The ID of the form to be operated does not exist. | | 16501003 | The form cannot be operated by the current application. | 以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 **示例:** ```ts import { formBindingData, formProvider } from '@kit.FormKit'; import { BusinessError } from '@kit.BasicServicesKit'; let formId: string = '12400633174999288'; let param: Record = { 'temperature': '22c', 'time': '22:00' } let obj: formBindingData.FormBindingData = formBindingData.createFormBindingData(param); try { formProvider.updateForm(formId, obj).then(() => { console.log(`formProvider updateForm success`); }).catch((error: BusinessError) => { console.error(`promise error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); }); } catch (error) { console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); } ``` ## getFormsInfo getFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>): void 获取设备上当前应用程序的卡片信息,使用callback异步回调。 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 **系统能力:** SystemCapability.Ability.Form **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- | ------- | | callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | 是 | 回调函数。返回查询到的卡片信息。 | **错误码:** | 错误码ID | 错误信息 | | -------- | -------- | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | | 16500050 | IPC connection error. | | 16500100 | Failed to obtain the configuration information. | | 16501000 | An internal functional error occurred. | 以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 **示例:** ```ts import { formProvider } from '@kit.FormKit'; import { BusinessError } from '@kit.BasicServicesKit'; try { formProvider.getFormsInfo((error, data) => { if (error) { console.error(`callback error, code: ${error.code}, message: ${error.message})`); return; } console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`); }); } catch (error) { console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); } ``` ## getFormsInfo getFormsInfo(filter: formInfo.FormInfoFilter, callback: AsyncCallback<Array<formInfo.FormInfo>>): void 获取设备上当前应用程序的卡片信息,并筛选符合条件的信息,使用callback异步回调。 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 **系统能力:** SystemCapability.Ability.Form **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- | ------- | | filter | [formInfo.FormInfoFilter](js-apis-app-form-formInfo.md#forminfofilter) | 是 | 卡片信息过滤器。 | | callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | 是 | 回调函数。返回查询到符合条件的卡片信息。 | **错误码:** | 错误码ID | 错误信息 | | -------- | -------- | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | | 16500050 | IPC connection error. | | 16500100 | Failed to obtain the configuration information. | | 16501000 | An internal functional error occurred. | 以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 **示例:** ```ts import { formInfo, formProvider } from '@kit.FormKit'; import { BusinessError } from '@kit.BasicServicesKit'; const filter: formInfo.FormInfoFilter = { // get info of forms belong to module entry. moduleName: 'entry' }; try { formProvider.getFormsInfo(filter, (error, data) => { if (error) { console.error(`callback error, code: ${error.code}, message: ${error.message})`); return; } console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`); }); } catch (error) { console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); } ``` ## getFormsInfo getFormsInfo(filter?: formInfo.FormInfoFilter): Promise<Array<formInfo.FormInfo>> 获取设备上当前应用程序的卡片信息,使用Promise异步回调。 **原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 **系统能力:** SystemCapability.Ability.Form **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- | ------- | | filter | [formInfo.FormInfoFilter](js-apis-app-form-formInfo.md#forminfofilter) | 否 | 卡片信息过滤器, 默认为空,不进行过滤。 | **返回值:** | 类型 | 说明 | | :------------ | :---------------------------------- | | Promise<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Promise对象。返回查询到符合条件的卡片信息。 | **错误码:** | 错误码ID | 错误信息 | | -------- | -------- | | 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | | 16500050 | IPC connection error. | | 16500100 | Failed to obtain the configuration information. | | 16501000 | An internal functional error occurred. | 以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 **示例:** ```ts import { formInfo, formProvider } from '@kit.FormKit'; import { BusinessError } from '@kit.BasicServicesKit'; const filter: formInfo.FormInfoFilter = { // get info of forms belong to module entry. moduleName: 'entry' }; try { formProvider.getFormsInfo(filter).then((data: formInfo.FormInfo[]) => { console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`); }).catch((error: BusinessError) => { console.error(`promise error, code: ${error.code}, message: ${error.message})`); }); } catch (error) { console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); } ```