1# @ohos.data.uniformDataStruct (标准化数据结构) 2 3本模块为统一数据管理框架(Unified Data Management Framework,UDMF)的组成部分,针对多对多跨应用数据共享的不同业务场景提供了部分标准化数据类型[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)对应的数据结构,方便不同应用间进行数据交互,减少数据类型适配的工作量。 4 5> **说明:** 6> 7> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8 9## 导入模块 10 11```js 12import { uniformDataStruct } from '@kit.ArkData'; 13``` 14 15## PlainText 16 17纯文本类型数据,用于描述纯文本类型数据。 18 19**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 20 21| 名称 | 类型 | 只读 | 可选 | 说明 | 22| ----------- | ------ | ---- | ---- |-----------------------| 23| uniformDataType | 'general.plain-text'| 是 | 否 | 统一数据类型标识,标识为纯文本类型数据,固定为“general.plain-text”,数据类型描述信息见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。 | 24| textContent | string | 否 | 否 | 纯文本内容。 | 25| abstract | string | 否 | 是 | 纯文本摘要,非必填字段,默认值为空字符串。 | 26| details | Record<string, string> | 否 | 是 | 是一个字典类型对象,key和value都是string类型,用于描述文本内容详细属性。例如,可生成一个details内容为<br />{<br />"title":"标题",<br />"content":"内容"<br />}<br />的数据对象,用于描述一篇文章的详细属性。非必填字段,默认值为空字典对象。 | 27 28**示例:** 29 30```ts 31let plainTextDetails : Record<string, string> = { 32 'attr1': 'value1', 33 'attr2': 'value2', 34} 35let plainText : uniformDataStruct.PlainText = { 36 uniformDataType: 'general.plain-text', 37 textContent : 'This is plainText textContent example', 38 abstract : 'this is abstract', 39 details : plainTextDetails, 40} 41console.info('plainText.uniformDataType: ' + plainText.uniformDataType); 42if(plainText.details != undefined){ 43 let plainTextDetailsObj : Record<string, string> = plainText.details; 44 for(let kv of Object.entries(plainTextDetailsObj)) { 45 console.info('plainText.details.attr: ' + kv[0] + ', value:' + kv[1]); 46 } 47} 48``` 49 50## Hyperlink 51 52超链接类型数据,用于描述超链接类型数据。 53 54**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 55 56| 名称 | 类型 | 只读 | 可选 | 说明 | 57| ----------- | ------ | ---- | ---- |--------------| 58| uniformDataType | 'general.hyperlink'| 是 | 否 | 统一数据类型标识为超链接类型数据,固定为“general.hyperlink”,数据类型描述信息见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。 59| url | string | 否 | 否 | 链接url。 | 60| description | string | 否 | 是 | 链接内容描述,非必填字段,默认值为空字符串。 | 61| details | Record<string, string> | 否 | 是 | 是一个字典类型对象,key和value都是string类型,用于描述Hyperlink的详细属性内容。例如,可生成一个details内容为<br />{<br />"title":"标题",<br />"content":"内容"<br />}<br />的数据对象。非必填字段,默认值为空字典对象。 | 62 63**示例:** 64 65```ts 66let hyperlinkDetails : Record<string, string> = { 67 'attr1': 'value1', 68 'attr2': 'value2', 69} 70let hyperlink : uniformDataStruct.Hyperlink = { 71 uniformDataType:'general.hyperlink', 72 url : 'www.XXX.com', 73 description : 'This is the description of this hyperlink', 74 details : hyperlinkDetails, 75} 76console.info('hyperlink.uniformDataType: ' + hyperlink.uniformDataType); 77``` 78 79## HTML 80 81HTML类型数据,用于描述超文本标记语言数据。 82 83**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 84 85| 名称 | 类型 | 只读 | 可选 | 说明 | 86| ------------ | ------ | ---- | ---- |-----------------------| 87| uniformDataType | 'general.html'| 是 | 否 | 统一数据类型标识为html类型数据,固定为“general.html”,数据类型描述信息见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。 88| htmlContent | string | 否 | 否 | html格式内容。 | 89| plainContent | string | 否 | 是 | 去除html标签后的纯文本内容,非必填字段,默认值为空字符串。 | 90| details | Record<string, string> | 否 | 是 | 是一个字典类型对象,key和value都是string类型,用于描述HTML的详细属性内容。例如,可生成一个details内容为<br />{<br />"title":"标题",<br />"content":"内容"<br />}<br />的数据对象。非必填字段,默认值为空字典对象。 | 91 92**示例:** 93 94```ts 95let htmlObjDetails : Record<string, string> = { 96 'attr1': 'value1', 97 'attr2': 'value2', 98} 99let htmlObj : uniformDataStruct.HTML = { 100 uniformDataType :'general.html', 101 htmlContent : '<div><p>标题</p></div>', 102 plainContent : 'this is plainContent', 103 details : htmlObjDetails, 104} 105console.info('htmlObj.uniformDataType: ' + htmlObj.uniformDataType); 106``` 107 108## OpenHarmonyAppItem 109 110系统定义的桌面图标类型数据。 111 112**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 113 114| 名称 | 类型 | 只读 | 可选 | 说明 | 115| ----------- | ------ | ---- | ---- |-----------------| 116| uniformDataType | 'openharmony.app-item'| 是 | 否 | 统一数据类型标识为桌面图标类型数据,固定为“openharmony.app-item”,数据类型描述信息见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。 117| appId | string | 否 | 否 | 图标对应的应用id。 | 118| appName | string | 否 | 否 | 图标对应的应用名。 | 119| appIconId | string | 否 | 否 | 图标的图片id。 | 120| appLabelId | string | 否 | 否 | 图标名称对应的标签id。 | 121| bundleName | string | 否 | 否 | 图标对应的应用bundle名。 | 122| abilityName | string | 否 | 否 | 图标对应的应用ability名。 | 123| details | Record<string, number \| string \| Uint8Array> | 否 | 是 | 是一个字典类型对象,key是string类型,value可以写入number(数值类型)、string(字符串类型)、Uint8Array(二进制字节数组)类型数据。非必填字段,默认值为空字典对象。| 124 125 126**示例:** 127 128```ts 129let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 130let appItemDetails : Record<string, number | string | Uint8Array> = { 131 'appItemKey1': 123, 132 'appItemKey2': 'appItemValue', 133 'appItemKey3': u8Array, 134} 135let appItem : uniformDataStruct.OpenHarmonyAppItem = { 136 uniformDataType:'openharmony.app-item', 137 appId : 'MyAppId', 138 appName : 'MyAppName', 139 appIconId : 'MyAppIconId', 140 appLabelId : 'MyAppLabelId', 141 bundleName : 'MyBundleName', 142 abilityName : 'MyAbilityName', 143 details : appItemDetails, 144} 145console.info('appItem.uniformDataType: ' + appItem.uniformDataType); 146``` 147 148## ContentForm<sup>14+</sup> 149 150内容卡片类型数据。 151 152**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 153 154| 名称 | 类型 | 只读 | 可选 | 说明 | 155|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------| 156| uniformDataType | 'general.content-form'| 是 | 否 | 统一数据类型标识为内容卡片类型数据,固定为“general.content-form”。 157| title | string | 否 | 否 | 内容卡片的标题。| 158| thumbData | Uint8Array | 否 | 是 | 内容卡片对应的图片数据。| 159| description| string | 否 | 是 | 内容卡片中的描述信息。| 160| appIcon | Uint8Array | 否 | 是 | 内容卡片中的应用图标数据。| 161| appName | string | 否 | 是 | 内容卡片中应用的应用名。| 162| linkUri | string | 否 | 是 | 内容卡片对应的跳转超链接。| 163 164 165**示例:** 166 167```ts 168let thumbDataU8Array = new Uint8Array([1, 2, 3, 4, 5]); 169let appIconU8Array = new Uint8Array([6, 7, 8, 9, 10]); 170let contentForm : uniformDataStruct.ContentForm = { 171 uniformDataType : 'general.content-form', 172 title : 'MyTitle', 173 thumbData : thumbDataU8Array, 174 description : 'MyDescription', 175 appName : 'MyAppName', 176 linkUri : 'MyLinkUri', 177 appIcon : appIconU8Array 178} 179console.info('contentForm.uniformDataType: ' + contentForm.uniformDataType); 180``` 181 182## Form<sup>15+</sup> 183 184系统定义的卡片类型数据。 185 186**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 187 188| 名称 | 类型 | 只读 | 可选 | 说明 | 189|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------| 190| uniformDataType | 'openharmony.form'| 是 | 否 | 统一数据类型标识为卡片类型数据,固定为“openharmony.form”,数据类型描述信息见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。 191| formId | number | 否 | 否 | 卡片id。| 192| formName | string | 否 | 否 | 卡片名。| 193| bundleName | string | 否 | 否 | 卡片所属的bundle名。| 194| abilityName| string | 否 | 否 | 卡片对应的ability名。| 195| module | string | 否 | 否 | 卡片所属的module名。| 196| details | Record<string, number \| string \| Uint8Array> | 否 | 是 | 是一个字典类型对象,key是string类型,value可以写入number(数值类型)、string(字符串类型)、Uint8Array(二进制字节数组)类型数据。非必填字段,默认值为空字典对象。| 197 198 199**示例:** 200 201```ts 202let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 203let formDetails : Record<string, number | string | Uint8Array> = { 204 'formKey1': 123, 205 'formKey2': 'formValue', 206 'formKey3': u8Array, 207} 208let form : uniformDataStruct.Form = { 209 uniformDataType : 'openharmony.form', 210 formId : 1, 211 formName : 'formName', 212 bundleName : 'com.xx.app', 213 abilityName : 'abilityName', 214 module : 'module', 215 details : formDetails 216} 217console.info('form.uniformDataType: ' + form.uniformDataType); 218``` 219 220## FileUri<sup>15+</sup> 221 222文件地址类型数据。 223 224**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 225 226| 名称 | 类型 | 只读 | 可选 | 说明 | 227|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------| 228| uniformDataType | 'general.file-uri'| 是 | 否 | 统一数据类型标识为文件地址类型数据,固定为“general.file-uri”,数据类型描述信息见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。 229| oriUri | string | 否 | 否 | 文件地址。| 230| fileType | string | 否 | 否 | 文件类型。| 231| details | Record<string, number \| string \| Uint8Array> | 否 | 是 | 是一个字典类型对象,key是string类型,value可以写入number(数值类型)、string(字符串类型)、Uint8Array(二进制字节数组)类型数据。非必填字段,默认值为空字典对象。| 232 233 234**示例:** 235 236```ts 237let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 238let fileUriDetails : Record<string, number | string | Uint8Array> = { 239 'fileUriKey1': 123, 240 'fileUriKey2': 'fileUriValue', 241 'fileUriKey3': u8Array, 242} 243let fileUri : uniformDataStruct.FileUri = { 244 uniformDataType : 'general.file-uri', 245 oriUri : 'www.xx.com', 246 fileType : 'general.image', 247 details : fileUriDetails 248} 249console.info('fileUri.uniformDataType: ' + fileUri.uniformDataType); 250``` 251 252## PixelMap<sup>15+</sup> 253 254系统定义的像素图类型数据。 255 256**系统能力**:SystemCapability.DistributedDataManager.UDMF.Core 257 258| 名称 | 类型 | 只读 | 可选 | 说明 | 259|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------| 260| uniformDataType | 'openharmony.pixel-map'| 是 | 否 | 统一数据类型标识为像素图类型数据,固定为“openharmony.pixel-map”,数据类型描述信息见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。 261| pixelMap | image.PixelMap | 否 | 否 | 像素图二进制数据。| 262| details | Record<string, number \| string \| Uint8Array> | 否 | 是 | 是一个字典类型对象,key是string类型,value可以写入number(数值类型)、string(字符串类型)、Uint8Array(二进制字节数组)类型数据。非必填字段,默认值为空字典对象。| 263 264 265**示例:** 266 267```ts 268import image from '@ohos.multimedia.image'; 269 270let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); 271let arrayBuffer = new ArrayBuffer(4*200*200); 272let opt : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 200, width: 200 }, alphaType: 3 }; 273let pixelMapDetails : Record<string, number | string | Uint8Array> = { 274 'pixelMapKey1': 123, 275 'pixelMapKey2': 'pixelMapValue', 276 'pixelMapKey3': u8Array, 277} 278let pixelMap : uniformDataStruct.PixelMap = { 279 uniformDataType : 'openharmony.pixel-map', 280 pixelMap : image.createPixelMapSync(arrayBuffer, opt), 281 details : pixelMapDetails 282} 283console.info('pixelMap.uniformDataType: ' + pixelMap.uniformDataType); 284```