1# @ohos.app.form.formProvider (formProvider) 2 3FormProvider模块提供了卡片提供方相关接口的能力,开发者在开发卡片时,可通过该模块提供接口实现更新卡片、设置卡片更新时间、获取卡片信息、请求发布卡片等。 4 5> **说明:** 6> 7> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9## 导入模块 10 11```ts 12import { formProvider } from '@kit.FormKit'; 13``` 14 15## setFormNextRefreshTime 16 17setFormNextRefreshTime(formId: string, minute: number, callback: AsyncCallback<void>): void 18 19设置指定卡片的下一次更新时间,使用callback异步回调。 20 21**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 22 23**系统能力:** SystemCapability.Ability.Form 24 25**参数:** 26 27| 参数名 | 类型 | 必填 | 说明 | 28| ------ | ------ | ---- | ------------------------------------- | 29| formId | string | 是 | 卡片标识。 | 30| minute | number | 是 | 指定多久之后更新。单位分钟,大于等于5。 | 31| callback | AsyncCallback<void> | 是 | 回调函数。 | 32 33**错误码:** 34 35| 错误码ID | 错误信息 | 36| -------- | -------- | 37| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 38| 16500050 | IPC connection error. | 39| 16500060 | Service connection error. | 40| 16500100 | Failed to obtain the configuration information. | 41| 16501000 | An internal functional error occurred. | 42| 16501001 | The ID of the form to be operated does not exist. | 43| 16501002 | The number of forms exceeds the maximum allowed. | 44| 16501003 | The form cannot be operated by the current application. | 45 46以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 47 48**示例:** 49 50```ts 51import { formProvider } from '@kit.FormKit'; 52import { BusinessError } from '@kit.BasicServicesKit'; 53 54let formId: string = '12400633174999288'; 55try { 56 formProvider.setFormNextRefreshTime(formId, 5, (error: BusinessError) => { 57 if (error) { 58 console.error(`callback error, code: ${error.code}, message: ${error.message})`); 59 return; 60 } 61 console.log(`formProvider setFormNextRefreshTime success`); 62 }); 63} catch (error) { 64 console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); 65} 66``` 67 68## setFormNextRefreshTime 69 70setFormNextRefreshTime(formId: string, minute: number): Promise<void> 71 72设置指定卡片的下一次更新时间,使用Promise异步回调。 73 74**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 75 76**系统能力:** SystemCapability.Ability.Form 77 78**参数:** 79 80| 参数名 | 类型 | 必填 | 说明 | 81| ------ | ------ | ---- | ------------------------------------- | 82| formId | string | 是 | 卡片标识。 | 83| minute | number | 是 | 指定多久之后更新。单位分钟,大于等于5。 | 84 85**返回值:** 86 87| 类型 | 说明 | 88| ------------- | ---------------------------------- | 89| Promise\<void> | 无返回结果的Promise对象。 | 90 91**错误码:** 92 93| 错误码ID | 错误信息 | 94| -------- | -------- | 95| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 96| 16500050 | IPC connection error. | 97| 16500060 | Service connection error. | 98| 16500100 | Failed to obtain the configuration information. | 99| 16501000 | An internal functional error occurred. | 100| 16501001 | The ID of the form to be operated does not exist. | 101| 16501002 | The number of forms exceeds the maximum allowed. | 102| 16501003 | The form cannot be operated by the current application. | 103 104以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 105 106**示例:** 107 108```ts 109import { formProvider } from '@kit.FormKit'; 110import { BusinessError } from '@kit.BasicServicesKit'; 111 112let formId: string = '12400633174999288'; 113try { 114 formProvider.setFormNextRefreshTime(formId, 5).then(() => { 115 console.log(`formProvider setFormNextRefreshTime success`); 116 }).catch((error: BusinessError) => { 117 console.error(`promise error, code: ${error.code}, message: ${error.message})`); 118 }); 119} catch (error) { 120 console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); 121} 122``` 123 124## updateForm 125 126updateForm(formId: string, formBindingData: formBindingData.FormBindingData,callback: AsyncCallback<void>): void 127 128更新指定的卡片,使用callback异步回调。 129 130**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 131 132**系统能力:** SystemCapability.Ability.Form 133 134**参数:** 135 136| 参数名 | 类型 | 必填 | 说明 | 137| ------ | ---------------------------------------------------------------------- | ---- | ---------------- | 138| formId | string | 是 | 请求更新的卡片标识。 | 139| formBindingData | [formBindingData.FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | 是 | 用于更新的数据。 | 140| callback | AsyncCallback<void> | 是 | 回调函数。 | 141 142**错误码:** 143 144| 错误码ID | 错误信息 | 145| -------- | -------- | 146| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 147| 16500050 | IPC connection error. | 148| 16500060 | Service connection error. | 149| 16500100 | Failed to obtain the configuration information. | 150| 16501000 | An internal functional error occurred. | 151| 16501001 | The ID of the form to be operated does not exist. | 152| 16501003 | The form cannot be operated by the current application. | 153 154以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 155 156**示例:** 157 158```ts 159import { formBindingData, formProvider } from '@kit.FormKit'; 160import { BusinessError } from '@kit.BasicServicesKit'; 161 162let formId: string = '12400633174999288'; 163try { 164 let param: Record<string, string> = { 165 'temperature': '22c', 166 'time': '22:00' 167 } 168 let obj: formBindingData.FormBindingData = formBindingData.createFormBindingData(param); 169 formProvider.updateForm(formId, obj, (error: BusinessError) => { 170 if (error) { 171 console.error(`callback error, code: ${error.code}, message: ${error.message})`); 172 return; 173 } 174 console.log(`formProvider updateForm success`); 175 }); 176} catch (error) { 177 console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); 178} 179``` 180 181## updateForm 182 183updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Promise<void> 184 185更新指定的卡片,使用Promise异步回调。 186 187**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 188 189**系统能力:** SystemCapability.Ability.Form 190 191**参数:** 192 193| 参数名 | 类型 | 必填 | 说明 | 194| ------ | ---------------------------------------------------------------------- | ---- | ---------------- | 195| formId | string | 是 | 请求更新的卡片标识。 | 196| formBindingData | [formBindingData.FormBindingData](js-apis-app-form-formBindingData.md#formbindingdata) | 是 | 用于更新的数据。 | 197 198**返回值:** 199 200| 类型 | 说明 | 201| -------------- | ----------------------------------- | 202| Promise\<void> | 无返回结果的Promise对象。 | 203 204**错误码:** 205 206| 错误码ID | 错误信息 | 207| -------- | -------- | 208| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 209| 16500050 | IPC connection error. | 210| 16500060 | Service connection error. | 211| 16500100 | Failed to obtain the configuration information. | 212| 16501000 | An internal functional error occurred. | 213| 16501001 | The ID of the form to be operated does not exist. | 214| 16501003 | The form cannot be operated by the current application. | 215 216以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 217 218**示例:** 219 220```ts 221import { formBindingData, formProvider } from '@kit.FormKit'; 222import { BusinessError } from '@kit.BasicServicesKit'; 223 224let formId: string = '12400633174999288'; 225let param: Record<string, string> = { 226 'temperature': '22c', 227 'time': '22:00' 228} 229let obj: formBindingData.FormBindingData = formBindingData.createFormBindingData(param); 230try { 231 formProvider.updateForm(formId, obj).then(() => { 232 console.log(`formProvider updateForm success`); 233 }).catch((error: BusinessError) => { 234 console.error(`promise error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); 235 }); 236} catch (error) { 237 console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); 238} 239``` 240 241## getFormsInfo 242 243getFormsInfo(callback: AsyncCallback<Array<formInfo.FormInfo>>): void 244 245获取设备上当前应用程序的卡片信息,使用callback异步回调。 246 247**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 248 249**系统能力:** SystemCapability.Ability.Form 250 251**参数:** 252 253| 参数名 | 类型 | 必填 | 说明 | 254| ------ | ------ | ---- | ------- | 255| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | 是 | 回调函数。返回查询到的卡片信息。 | 256 257**错误码:** 258| 错误码ID | 错误信息 | 259| -------- | -------- | 260| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 261| 16500050 | IPC connection error. | 262| 16500100 | Failed to obtain the configuration information. | 263| 16501000 | An internal functional error occurred. | 264 265以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 266 267 268**示例:** 269 270```ts 271import { formProvider } from '@kit.FormKit'; 272import { BusinessError } from '@kit.BasicServicesKit'; 273 274try { 275 formProvider.getFormsInfo((error, data) => { 276 if (error) { 277 console.error(`callback error, code: ${error.code}, message: ${error.message})`); 278 return; 279 } 280 console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`); 281 }); 282} catch (error) { 283 console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); 284} 285``` 286## getFormsInfo 287 288getFormsInfo(filter: formInfo.FormInfoFilter, callback: AsyncCallback<Array<formInfo.FormInfo>>): void 289 290获取设备上当前应用程序的卡片信息,并筛选符合条件的信息,使用callback异步回调。 291 292**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 293 294**系统能力:** SystemCapability.Ability.Form 295 296**参数:** 297 298| 参数名 | 类型 | 必填 | 说明 | 299| ------ | ------ | ---- | ------- | 300| filter | [formInfo.FormInfoFilter](js-apis-app-form-formInfo.md#forminfofilter) | 是 | 卡片信息过滤器。 | 301| callback | AsyncCallback<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | 是 | 回调函数。返回查询到符合条件的卡片信息。 | 302 303**错误码:** 304 305| 错误码ID | 错误信息 | 306| -------- | -------- | 307| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 308| 16500050 | IPC connection error. | 309| 16500100 | Failed to obtain the configuration information. | 310| 16501000 | An internal functional error occurred. | 311 312以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 313 314**示例:** 315 316```ts 317import { formInfo, formProvider } from '@kit.FormKit'; 318import { BusinessError } from '@kit.BasicServicesKit'; 319 320const filter: formInfo.FormInfoFilter = { 321 // get info of forms belong to module entry. 322 moduleName: 'entry' 323}; 324try { 325 formProvider.getFormsInfo(filter, (error, data) => { 326 if (error) { 327 console.error(`callback error, code: ${error.code}, message: ${error.message})`); 328 return; 329 } 330 console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`); 331 }); 332} catch (error) { 333 console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); 334} 335``` 336 337## getFormsInfo 338 339getFormsInfo(filter?: formInfo.FormInfoFilter): Promise<Array<formInfo.FormInfo>> 340 341获取设备上当前应用程序的卡片信息,使用Promise异步回调。 342 343**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 344 345**系统能力:** SystemCapability.Ability.Form 346 347**参数:** 348 349| 参数名 | 类型 | 必填 | 说明 | 350| ------ | ------ | ---- | ------- | 351| filter | [formInfo.FormInfoFilter](js-apis-app-form-formInfo.md#forminfofilter) | 否 | 卡片信息过滤器, 默认为空,不进行过滤。 | 352 353**返回值:** 354 355| 类型 | 说明 | 356| :------------ | :---------------------------------- | 357| Promise<Array<[formInfo.FormInfo](js-apis-app-form-formInfo.md)>> | Promise对象。返回查询到符合条件的卡片信息。 | 358 359**错误码:** 360 361| 错误码ID | 错误信息 | 362| -------- | -------- | 363| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3.Parameter verification failed. | 364| 16500050 | IPC connection error. | 365| 16500100 | Failed to obtain the configuration information. | 366| 16501000 | An internal functional error occurred. | 367 368以上错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[卡片错误码](errorcode-form.md)。 369 370**示例:** 371 372```ts 373import { formInfo, formProvider } from '@kit.FormKit'; 374import { BusinessError } from '@kit.BasicServicesKit'; 375 376const filter: formInfo.FormInfoFilter = { 377 // get info of forms belong to module entry. 378 moduleName: 'entry' 379}; 380try { 381 formProvider.getFormsInfo(filter).then((data: formInfo.FormInfo[]) => { 382 console.log(`formProvider getFormsInfo, data: ${JSON.stringify(data)}`); 383 }).catch((error: BusinessError) => { 384 console.error(`promise error, code: ${error.code}, message: ${error.message})`); 385 }); 386} catch (error) { 387 console.error(`catch error, code: ${(error as BusinessError).code}, message: ${(error as BusinessError).message})`); 388} 389``` 390