提交 2ae61809 编写于 作者: S sienna1128 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/docs into master

Signed-off-by: Nsienna1128 <lixiaoyan45@huawei.com>
...@@ -89,7 +89,7 @@ Register four synchronous APIs (`getSync`, `setSync`, `removeSync`, and`clearSyn ...@@ -89,7 +89,7 @@ Register four synchronous APIs (`getSync`, `setSync`, `removeSync`, and`clearSyn
/*********************************************** /***********************************************
* Module export and register * Module export and register
***********************************************/ ***********************************************/
static napi_value StorgeExport(napi_env env, napi_value exports) static napi_value StorageExport(napi_env env, napi_value exports)
{ {
napi_property_descriptor desc[] = { napi_property_descriptor desc[] = {
DECLARE_NAPI_FUNCTION("get", JSStorageGet), DECLARE_NAPI_FUNCTION("get", JSStorageGet),
...@@ -110,7 +110,7 @@ static napi_value StorgeExport(napi_env env, napi_value exports) ...@@ -110,7 +110,7 @@ static napi_value StorgeExport(napi_env env, napi_value exports)
static napi_module storage_module = {.nm_version = 1, static napi_module storage_module = {.nm_version = 1,
.nm_flags = 0, .nm_flags = 0,
.nm_filename = nullptr, .nm_filename = nullptr,
.nm_register_func = StorgeExport, .nm_register_func = StorageExport,
.nm_modname = "storage", .nm_modname = "storage",
.nm_priv = ((void*)0), .nm_priv = ((void*)0),
.reserved = {0}}; .reserved = {0}};
......
# Buffer
> **NOTE**
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
A **Buffer** object represents a byte sequence of a fixed length. It is used to store binary data.
You can use the APIs provided by the **Buffer** module to process images and a large amount of binary data, receive and upload files, and use network protocols.
## Modules to Import
```ts
import buffer from '@ohos.buffer';
```
## Buffer
### alloc
alloc(size: number, fill?: string | Buffer | number, encoding?: BufferEncoding): Buffer
Allocates and initializes a **Buffer** instance of the specified size.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| size | number | Yes| Size of the **Buffer** instance to allocate, in bytes.|
| fill | string&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;number | No| Pre-filled value. The default value is **0**.|
| encoding | BufferEncoding | No| Encoding format (valid only when **fill** is a string). The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | Initialized **Buffer** instance.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.alloc(5);
let buf2 = buffer.alloc(5, 'a');
let buf3 = buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
```
### allocUninitializedFromPool
allocUninitializedFromPool(size: number): Buffer
Allocates a **Buffer** instance of the specified size from the buffer pool, without initializing it.
To initialize the **Buffer** instance, call the **fill()** function.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| size | number | Yes| Size of the **Buffer** instance to allocate, in bytes.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | Uninitialized **Buffer** instance.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(10);
buf.fill(0);
```
### allocUninitialized
allocUninitialized(size: number): Buffer
Allocates a **Buffer** instance of the specified size, without initializing it. This API does not allocate memory from the buffer pool.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| size | number | Yes|Size of the **Buffer** instance to allocate, in bytes.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | Uninitialized **Buffer** instance.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitialized(10);
buf.fill(0);
```
### byteLength
byteLength(string: string | Buffer | TypeArray | DataView | ArrayBuffer | SharedArrayBuffer, encoding?: BufferEncoding): number
Obtains the number of bytes of a string based on the encoding format.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| string | string&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;TypeArray&nbsp;\|&nbsp;DataView&nbsp;\|&nbsp;ArrayBuffer&nbsp;\|&nbsp;SharedArrayBuffer | Yes| Target string.|
| encoding | BufferEncoding | No| Encoding format. The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes of the string.|
**Example**
```ts
import buffer from '@ohos.buffer';
let str = '\u00bd + \u00bc = \u00be';
console.log('${str}: ${str.length} characters, ${buffer.byteLength(str, 'utf-8')} bytes');
// Print: ½ + ¼ = ¾: 9 characters, 12 bytes
```
### compare
compare(buf1: Buffer | Uint8Array, buf2: Buffer | Uint8Array): number
Compares two **Buffer** instances.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| buf1 | Buffer&nbsp;\|&nbsp;Uint8Array | Yes| **Buffer** instance to compare.|
| buf2 | Buffer&nbsp;\|&nbsp;Uint8Array | Yes| **Buffer** instance to compare.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Returns **0** if **buf1** is the same as **buf2**.<br>Returns **1** if **buf1** comes after **buf2** when sorted.<br>Returns **-1** if **buf1** comes before **buf2** when sorted.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.from('1234');
let buf2 = buffer.from('0123');
console.log(buf1.compare(buf2));
// Print 1
```
### concat
concat(list: Buffer[] | Uint8Array[], totalLength?: number): Buffer
Concatenates an array of **Buffer** instances into a new instance of the specified length.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| list | Buffer[]&nbsp;\|&nbsp;Uint8Array[] | Yes| Array of instances to concatenate.|
| totalLength | number | No| Total length of the new **Buffer** instance, in bytes.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance created.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.from("1234");
let buf2 = buffer.from("abcd");
let buf = buffer.concat([buf1, buf2]);
console.log(buf); // <Buffer 31 32 33 34 61 62 63 64>
```
### from
from(array: number[]): Buffer
Creates a **Buffer** instance with the specified array.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| array | number[] | Yes| Array to create a **Buffer** instance.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance created.|
**Example**
```ts
import buffer from '@ohos.buffer';
let arrayList = new ArrayList();
let buf = buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
console.log(buf);
// Print: <Buffer 62 75 66 66 65 72>
```
### from
from(arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, length?: number): Buffer
Creates a **Buffer** instance that shares memory with the specified array of **Buffer** instances.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| arrayBuffer | ArrayBuffer&nbsp;\|&nbsp;SharedArrayBuffer | Yes| Array of **Buffer** instances, whose memory is to be shared.|
| byteOffset | number | No| Byte offset. The default value is **0**.|
| length | number | No| Length of the **Buffer** instance to create, in bytes. The default value is the length of **arrayBuffer** minus **byteOffset**.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance with shared memory.|
**Example**
```ts
import buffer from '@ohos.buffer';
let ab = new ArrayBuffer(10);
let buf = buffer.from(ab, 0, 2);
```
### from
from(data: Buffer | Uint8Array): Buffer
Creates a **Buffer** instance with the copy of another instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| data | Buffer&nbsp;\|&nbsp;Uint8Array | Yes| Instance to copy.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance created.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.from('buffer');
let buf2 = buffer.from(buf1);
```
### from
from(object: Object, offsetOrEncoding: number | string, length: number): Buffer
Creates a **Buffer** instance based on the specified object.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| object | Object | Yes| Object that supports **Symbol.toPrimitive** or **valueOf()**.|
| offsetOrEncoding | number&nbsp;\|&nbsp;string | No| Byte offset or encoding format.|
| length | number | No| Length of the **Buffer** instance to create.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance created.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from(new String('this is a test'));
```
### from
from(string: string, encoding?: BufferEncoding): Buffer
Creates a **Buffer** instance based on a string in the given encoding format.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| string | string | Yes| String.|
| encoding | BufferEncoding | No| Encoding format of the string. The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance created.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.from('this is a test');
let buf2 = buffer.from('7468697320697320612074c3a97374', 'hex');
console.log (buf1.toString()); // Print: this is a test
console.log(buf2.toString());
```
### isBuffer
isBuffer(obj: Object): boolean
Checks whether the specified object is a **Buffer** instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| obj | Object | Yes| Object to check.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the object is a **Buffer** instance; returns **false** otherwise.|
**Example**
```ts
import buffer from '@ohos.buffer';
buffer.isBuffer(buffer.alloc(10)); // true
buffer.isBuffer(buffer.from('foo')); // true
buffer.isBuffer('a string'); // false
buffer.isBuffer([]); // false
buffer.isBuffer(new Uint8Array(1024)); // false
```
### isEncoding
isEncoding(encoding: string): boolean
Checks whether the encoding format is supported.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| encoding | string | Yes| Encoding format.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the encoding format is supported; returns **false** otherwise.|
**Example**
```ts
import buffer from '@ohos.buffer';
console.log (Buffer.isEncoding ('utf-8')); // Print: true
console.log (Buffer.isEncoding ('hex')); // Print: true
console.log (Buffer.isEncoding ('utf/8')); // Print: false
console.log (Buffer.isEncoding ('')); // Print: false
```
### compare
compare(target: Buffer | Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): -1 | 0 | 1
Compares this **Buffer** instance with another instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| target | Buffer&nbsp;\|&nbsp;Uint8Array | Yes| Target **Buffer** instance to compare.|
| targetStart | number | No| Offset to the start of the data to compare in the target **Buffer** instance. The default value is **0**.|
| targetEnd | number | No| Offset to the end of the data to compare in the target **Buffer** instance (not inclusive). The default value is length of the target **Buffer** instance.|
| sourceStart | number | No| Offset to the start of the data to compare in this **Buffer** instance. The default value is **0**.|
| sourceEnd | number | No| Offset to the end of the data to compare in this **Buffer** instance (not inclusive). The default value is the length of this **Buffer** instance.|
| Type| Description|
| -------- | -------- |
| number | Returns **0** if the two **Buffer** instances are the same.<br>Returns **1** if the target instance comes before this instance when sorted.<br>Returns **-1** if the target instance comes after this instance when sorted.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]);
let buf2 = buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]);
console.log (buf1.compare (buf2, 5, 9, 0, 4); // Print: 0
console.log (buf1.compare (buf2, 0, 6, 4); // Print: -1
console.log (buf1.compare (buf2, 5, 6, 5)); // Print: 1
```
### copy
copy(target: Buffer| Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number
Copies data at the specified position in this **Buffer** instance to the specified position in another **Buffer** instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| target | Buffer&nbsp;\|&nbsp;Uint8Array | Yes| Instance to which data is copied.|
| targetStart | number | No| Offset to the start position in the target instance where data is copied. The default value is **0**.|
| sourceStart | number | No| Offset to the start position in this **Buffer** instance where data is copied. The default value is **0**.|
| sourceEnd | number | No| Offset to the end position in this **Buffer** instance (not inclusive). The default value is the length of this **Buffer** instance.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Total length of the data copied, in bytes.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.allocUninitializedFromPool(26);
let buf2 = buffer.allocUninitializedFromPool(26).fill('!');
for (let i = 0; i < 26; i++) {
buf1[i] = i + 97;
}
buf1.copy(buf2, 8, 16, 20);
console.log(buf2.toString('ascii', 0, 25));
// Print: !!!!!!! qrst!!!!!!!!!!!!!
```
### entries
entries(): IterableIterator&lt;[number,&nbsp;number]&gt;
Creates and returns an iterator that contains key-value pairs of this **Buffer** instance.
**System capability**: SystemCapability.Utils.Lang
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from('buffer');
for (let pair of buf.entries()) {
console.log(pair);
}
```
### equals
equals(otherBuffer: Buffer | Uint8Array): boolean
Checks whether this **Buffer** instance is the same as another **Buffer** instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| otherBuffer | Buffer&nbsp;\|&nbsp;Uint8Array | Yes| **Buffer** instance to compare.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the two instances are the same; returns **false** otherwise.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.from('ABC');
let buf2 = buffer.from('414243', 'hex');
let buf3 = buffer.from('ABCD');
console.log (buf1.equals (buf2)); // Print: true
console.log (buf1.equals (buf3)); // Print: false
```
### fill
fill(value: string | Buffer | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): Buffer
Fills this **Buffer** instance at the specified position. By default, data is filled cyclically.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | string&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;Uint8Array&nbsp;\|&nbsp;number | Yes| Value to fill.|
| offset | number | No| Offset to the start position in this **Buffer** instance where data is filled. The default value is **0**.|
| end | number | No| Offset to the end position in this **Buffer** instance (not inclusive). The default value is the length of this **Buffer** instance.|
| encoding | BufferEncoding | No| Encoding format (valid only when **value** is a string). The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance filled with the specified value.|
**Example**
```ts
import buffer from '@ohos.buffer';
let b = buffer.allocUninitializedFromPool(50).fill('h');
console.log(b.toString());
```
### includes
includes(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): boolean
Checks whether this **Buffer** instance contains the specified value.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;Uint8Array | Yes| Value to match.|
| byteOffset | number | No| Number of bytes to skip before checking data. If the offset is a negative number, data is searched from the end of the **Buffer** instance. The default value is **0**.|
| encoding | BufferEncoding | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the instance contains the specified value; returns **false** otherwise.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from('this is a buffer');
console.log (buf.includes ('this')); // Print: true
console.log (buf.includes ('be')); // Print: false
```
### indexOf
indexOf(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number
Obtains the index of the first occurrence of the specified value in this **Buffer** instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;Uint8Array | Yes| Value to match.|
| byteOffset | number | No| Number of bytes to skip before checking data. If the offset is a negative number, data is searched from the end of the **Buffer** instance. The default value is **0**.|
| encoding | BufferEncoding | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Index obtained. <br>If **-1** is returned, the **Buffer** instance does not contain the specified value.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from('this is a buffer');
console.log (buf.indexOf('this')); // Print: 0
console.log(buf.indexOf('is')); // Print: 2
```
### keys
keys(): IterableIterator&lt;number&gt;
Creates and returns an iterator that contains the keys of this **Buffer** instance.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;number&gt; | Iterator.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from('buffer');
for (const key of buf.keys()) {
console.log(key);
}
```
### lastIndexOf
lastIndexOf(value: string | number | Buffer | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number
Obtains the index of the last occurrence of the specified value in this **Buffer** instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;Buffer&nbsp;\|&nbsp;Uint8Array | Yes| Value to match.|
| byteOffset | number | No| Number of bytes to skip before checking data. If the offset is a negative number, data is searched from the end of the **Buffer** instance. The default value is **0**.|
| encoding | BufferEncoding | No| Encoding format used if **value** is a string. The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Index obtained.<br>If **-1** is returned, the **Buffer** instance does not contain the specified value.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from('this buffer is a buffer');
console.log(buf.lastIndexOf('this')); // Print: 0
console.log(buf.lastIndexOf('buffer')); // Print:17
```
### readBigInt64BE
readBigInt64BE(offset: number): number
Reads a signed, big-endian 64-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | A signed, big-endian 64-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70,
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]);
console.log(buf.readBigInt64BE(0));
```
### readBigInt64LE
readBigInt64LE(offset: number): number
Reads a signed, little-endian 64-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | A signed, little-endian 64-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70,
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]);
console.log(buf.readBigInt64LE(0));
```
### readBigUInt64BE
readBigUInt64BE(offset: number): number
Reads an unsigned, big-endian 64-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | An unsigned, big-endian 64-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70,
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]);
console.log(buf.readBigUInt64BE(0));
```
### readBigUInt64LE
readBigUInt64LE(offset: number): number
Reads an unsigned, little-endian 64-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | An unsigned, little-endian 64-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70,
0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78]);
console.log(buf.readBigUInt64LE(0));
```
### readDoubleBE
readDoubleBE(offset: number): number
Reads a 64-bit, big-endian double-precision floating-point number from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | A 64-bit, big-endian double-precision floating-point number.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readDoubleBE(0));
```
### readDoubleLE
readDoubleLE(offset: number): number
Reads a 64-bit, little-endian double-precision floating-point number from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | A 64-bit, little-endian double-precision floating-point number.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readDoubleLE(0));
```
### readFloatBE
readFloatBE(offset: number): number
Reads a 32-bit, big-endian floating-point number from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | A 32-bit, big-endian floating-point number.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readFloatBE(0));
```
### readFloatLE
readFloatLE(offset: number): number
Reads a 32-bit, little-endian floating-point number from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | A 32-bit, little-endian floating-point number.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
console.log(buf.readFloatLE(0));
```
### readInt8
readInt8(offset: number): number
Reads a signed 8-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | A signed 8-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([-1, 5]);
console.log (buf.readInt8(0)); // Print: -1
console.log (buf.readInt8(1); // Print: 5
```
### readInt16BE
readInt16BE(offset: number): number
Reads a signed, big-endian 16-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | A signed, big-endian 16-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = Buffer.from([0, 5]);
console.log (buf.readInt16BE(0)); // Print: 5
```
### readInt16LE
readInt16LE(offset: number): number
Reads a signed, little-endian 16-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | A signed, little-endian 16-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = Buffer.from([0, 5]);
console.log (buf.readInt16BE(0)); // Print: 1280
```
### readInt32BE
readInt32BE(offset: number): number
Reads a signed, big-endian 32-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | A signed, big-endian 32-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0, 0, 0, 5]);
console.log(buf.readInt32BE(0)); // Print: 5
```
### readInt32LE
readInt32LE(offset: number): number
Reads a signed, little-endian 32-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | Yes| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | A signed, little-endian 32-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0, 0, 0, 5]);
console.log (buf.readInt32LE(0)); // Print: 83886080
```
### readIntBE
readIntBE(offset: number, byteLength: number): number
Reads the specified number of bytes from this **Buffer** instance at the specified offset, and interprets the result as a big-endian, two's complement signed value that supports up to 48 bits of precision.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | No| Number of bytes to skip before reading data. The default value is **0**.|
| byteLength | number | No| Number of bytes to read.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Data read.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = Buffer.from("ab");
let num = buf.readIntBE(0, 1);
console.log(num); // 97
```
### readIntLE
readIntLE(offset: number, byteLength: number): number
Reads the specified number of bytes from this **Buffer** instance at the specified offset and interprets the result as a little-endian, two's complement signed value that supports up to 48 bits of precision.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | No| Number of bytes to skip before reading data. The default value is **0**.|
| byteLength | number | No| Number of bytes to read.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Data read.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
console.log(buf.readIntLE(0, 6).toString(16));
```
### readUInt8
readUInt8(offset: number): number
Reads an unsigned 8-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | No| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | An unsigned 8-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([1, -2]);
console.log(buf.readUInt8(0));
console.log(buf.readUInt8(1));
```
### readUInt16BE
readUInt16BE(offset: number): number
Reads an unsigned, big-endian 16-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | No| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | An unsigned, big-endian 16-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56]);
console.log(buf.readUInt16BE(0).toString(16));
console.log(buf.readUInt16BE(1).toString(16));
```
### readUInt16LE
readUInt16LE(offset: number): number
Reads an unsigned, little-endian 16-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | No| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | An unsigned, little-endian 16-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56]);
console.log(buf.readUInt16LE(0).toString(16));
console.log(buf.readUInt16LE(1).toString(16));
```
### readUInt32BE
readUInt32BE(offset: number): number
Reads an unsigned, big-endian 32-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | No| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | An unsigned, big-endian 32-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56, 0x78]);
console.log(buf.readUInt32BE(0).toString(16));
```
### readUInt32LE
readUInt32LE(offset: number): number
Reads an unsigned, little-endian 32-bit integer from this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | No| Number of bytes to skip before reading data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | An unsigned, little-endian 32-bit integer.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56, 0x78]);
console.log(buf.readUInt32LE(0).toString(16));
```
### readUIntBE
readUIntBE(offset: number, byteLength: number): number
Reads the specified number of bytes from this **Buffer** instance at the specified offset, and interprets the result as an unsigned, big-endian integer that supports up to 48 bits of precision.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | No| Number of bytes to skip before reading data. The default value is **0**.|
| byteLength | number | No| Number of bytes to read.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Data read.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
console.log(buf.readUIntBE(0, 6).toString(16));
```
### readUIntLE
readUIntLE(offset: number, byteLength: number): number
Reads the specified number of bytes from this **Buffer** instance at the specified offset, and interprets the result as an unsigned, little-endian integer that supports up to 48 bits of precision.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| offset | number | No| Number of bytes to skip before reading data. The default value is **0**.|
| byteLength | number | No| Number of bytes to read.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Data read.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
console.log(buf.readUIntLE(0, 6).toString(16));
```
### subarray
subarray(start?: number, end?: number): Buffer
Truncates this **Buffer** instance from the specified position to create a new **Buffer** instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| start | number | No| Offset to the start position in this **Buffer** instance where data is truncated. The default value is **0**.|
| end | number | No| Offset to the end position in this **Buffer** instance (not inclusive). The default value is the length of this **Buffer** instance.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance created.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.allocUninitializedFromPool(26);
for (let i = 0; i < 26; i++) {
buf1[i] = i + 97;
}
const buf2 = buf1.subarray(0, 3);
console.log(buf2.toString('ascii', 0, buf2.length));
// Print: abc
```
### swap16
swap16(): Buffer
Interprets this **Buffer** instance as an array of unsigned 16-bit integers and swaps the byte order in place.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance swapped.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
console.log(buf1); // Print: <Buffer 01 02 03 04 05 06 07 08>
buf1.swap16();
console.log(buf1); // Print: <Buffer 02 01 04 03 06 05 08 07>
```
### swap32
swap32(): Buffer
Interprets this **Buffer** instance as an array of unsigned 32-bit integers and swaps the byte order in place.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance swapped.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
console.log(buf1); // Print: <Buffer 01 02 03 04 05 06 07 08>
buf1.swap32();
console.log(buf1); // Print: <Buffer 04 03 02 01 08 07 06 05>
```
### swap64
swap64(): Buffer
Interprets this **Buffer** instance as an array of unsigned 64-bit integers and swaps the byte order in place.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | **Buffer** instance swapped.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
console.log(buf1); // Print: <Buffer 01 02 03 04 05 06 07 08>
buf1.swap64();
console.log(buf1); // Print: <Buffer 08 07 06 05 04 03 02 01>
```
### toJSON
toJSON(): Object
Converts this **Buffer** instance into a JSON object.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| Object | JSON object.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);
let buf2 = buffer.from(buf1.toJSON())
let json = JSON.stringify(buf2);
console.log(json);
// Print: {"type":"Buffer","data":[1,2,3,4,5]}
```
### toString
toString(encoding?: string, start?: number, end?: number): string
Converts the data at the specified position in this **Buffer** instance into a string in the specified encoding format.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| encoding | string | No| Encoding format of the string. The default value is **utf-8**.|
| start | number | No| Offset to the start position of the data to convert. The default value is **0**.|
| end | number | No| Offset to the end position of the data to convert. The default value is the length of this **Buffer** instance.|
**Return value**
| Type| Description|
| -------- | -------- |
| string | String obtained.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.allocUninitializedFromPool(26);
for (let i = 0; i < 26; i++) {
buf1[i] = i + 97;
}
console.log(buf1.toString('utf-8'));
// Print: abcdefghijklmnopqrstuvwxyz
```
### values
values(): IterableIterator&lt;number&gt;
Creates and returns an iterator that contains the values of this **Buffer** instance.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| IterableIterator&lt;number&gt; | Iterator created.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf1 = buffer.from('buffer');
for (const value of buf.values()) {
console.log(value);
}
```
### write
write(str: string, offset?: number, length?: number, encoding?: string): number
Writes a string of the specified length to this **Buffer** instance at the specified position in the given encoding format.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| str | string | Yes| String to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
| length | number | No| Maximum number of bytes to write. The default value is the length of the **Buffer** instance minus the offset.|
| encoding | BufferEncoding | No| Encoding format of the string. The default value is **utf-8**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.alloc(256);
let len = buf.write('\u00bd + \u00bc = \u00be', 0);
console.log(`${len} bytes: ${buf.toString('utf-8', 0, len)}`);
// Print: 12 bytes: ½ + ¼ = ¾
let buffer = Buffer.alloc(10);
let length = buffer.write('abcd', 8);
```
### writeBigInt64BE
writeBigInt64BE(value: number, offset?: number): number
Writes a signed, big-endian 64-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(8);
buf.writeBigInt64BE(0x0102030405060708n, 0);
```
### writeBigInt64LE
writeBigInt64LE(value : number, offset? : number): number
Writes a signed, little-endian 64-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(8);
buf.writeBigInt64LE(0x0102030405060708n, 0);
```
### writeBigUInt64BE
writeBigUInt64BE(value : number, offset? : number): number
Writes an unsigned, big-endian 64-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(8);
buf.writeBigUInt64BE(0xdecafafecacefaden, 0);
```
### writeBigUInt64LE
writeBigUInt64LE(value : number, offset? : number): number
Writes an unsigned, little-endian 64-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(8);
buf.writeBigUInt64LE(0xdecafafecacefaden, 0);
```
### writeDoubleBE
writeDoubleBE(value : number, offset? : number): number
Writes a 64-bit, big-endian double-precision floating-point number to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(8);
buf.writeDoubleBE(123.456, 0);
```
### writeDoubleLE
writeDoubleLE(value : number, offset? : number): number
Writes a 64-bit, little-endian double-precision floating-point number to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(8);
buf.writeDoubleLE(123.456, 0);
```
### writeFloatBE
writeFloatBE(value : number, offset? : number): number
Writes a 32-bit, big-endian floating-point number to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(8);
buf.writeFloatBE(0xcafebabe, 0);
```
### writeFloatLE
writeFloatLE(value : number, offset? : number): number
Writes a 32-bit, little-endian floating-point number to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(8);
buf.writeFloatLE(0xcafebabe, 0);
```
### writeInt8
writeInt8(value : number, offset? : number): number
Writes a signed 8-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(2);
buf.writeInt8(2, 0);
buf.writeInt8(-2, 1);
```
### writeInt16BE
writeInt16BE(value : number, offset? : number): number
Writes a signed, big-endian 16-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(2);
buf.writeInt16BE(0x0102, 0);
```
### writeInt16LE
writeInt16LE(value : number, offset : number): number
Writes a signed, little-endian 16-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(2);
buf.writeInt16LE(0x0304, 0);
```
### writeInt32BE
writeInt32BE(value : number, offset : number): number
Writes a signed, big-endian 32-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(4);
buf.writeInt32BE(0x01020304, 0);
```
### writeInt32LE
writeInt32LE(value : number, offset : number): number
Writes a signed, little-endian 32-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(4);
buf.writeInt32LE(0x05060708, 0);
```
### writeIntBE
writeIntBE(value : number, offset : number, byteLength : number): number
Writes a big-endian signed value of the specified length to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
| byteLength | number | No| Number of bytes to write.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(6);
buf.writeIntBE(0x1234567890ab, 0, 6);
```
### writeIntLE
writeIntLE(value : number, offset : number, byteLength : number): number
Writes a little-endian signed value of the specified length to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
| byteLength | number | No| Number of bytes to write.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(6);
buf.writeIntLE(0x1234567890ab, 0, 6);
```
### writeUInt8
writeUInt8(value : number, offset : number): number
Writes an unsigned 8-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(4);
buf.writeUInt8(0x3, 0);
buf.writeUInt8(0x4, 1);
buf.writeUInt8(0x23, 2);
buf.writeUInt8(0x42, 3);
```
### writeUInt16BE
writeUInt16BE(value : number, offset : number): number
Writes an unsigned, big-endian 16-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(4);
buf.writeUInt16BE(0xdead, 0);
buf.writeUInt16BE(0xbeef, 2);
```
### writeUInt16LE
writeUInt16LE(value : number, offset : number): number
Writes an unsigned, little-endian 16-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(4);
buf.writeUInt16LE(0xdead, 0);
buf.writeUInt16LE(0xbeef, 2);
```
### writeUInt32BE
writeUInt32BE(value : number, offset : number): number
Writes an unsigned, big-endian 32-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(4);
buf.writeUInt32BE(0xfeedface, 0);
```
### writeUInt32LE
writeUInt32LE(value : number, offset : number): number
Writes an unsigned, little-endian 32-bit integer to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Number to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(4);
buf.writeUInt32LE(0xfeedface, 0);
```
### writeUIntBE
writeUIntBE(value : number, offset : number, byteLength : number): number
Writes a big-endian unsigned value of the specified length to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
| byteLength | number | No| Number of bytes to write.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(6);
buf.writeUIntBE(0x1234567890ab, 0, 6);
```
### writeUIntLE
writeUIntLE(value : number, offset : number, byteLength : number): number
Writes a little-endian unsigned value of the specified length to this **Buffer** instance at the specified offset.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | number | Yes| Data to write.|
| offset | number | No| Number of bytes to skip before writing data. The default value is **0**.|
| byteLength | number | No| Number of bytes to write.|
**Return value**
| Type| Description|
| -------- | -------- |
| number | Number of bytes written.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.allocUninitializedFromPool(6);
buf.writeUIntLE(0x1234567890ab, 0, 6);
```
### transcode
transcode(source : Buffer | Uint8Array, fromEnc : string, toEnc : string): Buffer
Transcodes the given **Buffer** or **Uint8Array** instance from one encoding format to another.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| source | Buffer&nbsp;\|&nbsp;Uint8Array | Yes| Instance to encode.|
| fromEnc | string | Yes| Current encoding format.|
| toEnc | string | Yes| Target encoding format.|
**Return value**
| Type| Description|
| -------- | -------- |
| Buffer | New **Buffer** instance in the target encoding format.|
**Example**
```ts
import buffer from '@ohos.buffer';
let buf = buffer.alloc(50);
let newBuf = buf.transcode(buffer.from(''), 'utf8', 'ascii');
console.log(newBuf.toString('ascii'));
```
## Blob
### Attributes
**System capability**: SystemCapability.Utils.Lang
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| size | number | Yes| No| Total size of the **Blob** instance, in bytes.|
| type | string | Yes| No| Type of the data in the **Blob** instance.|
### constructor
constructor(sources: string[] | ArrayBuffer[] | TypedArray[] | DataView[] | Blob[] , options: Object)
A constructor used to create a **Blob** instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| sources | string[]&nbsp;\|&nbsp;ArrayBuffer[]&nbsp;\|&nbsp;TypedArray[]&nbsp;\|&nbsp;DataView[]&nbsp;\|&nbsp;Blob[] | Yes| Data sources of the **Blob** instance.|
| options | Object | No| options:<br>- **endings**: 'transparent' or 'native'.<br>- **type**: type of the data in **Blob**.|
**Example**
```ts
import buffer from '@ohos.buffer';
let blob1 = new buffer.Blob(['a', 'b', 'c']);
let blob1 = new buffer.Blob(['a', 'b', 'c'], {endings:'native', type: 'MIME'});
```
### encode
arrayBuffer(): Promise&lt;ArrayBuffer&gt;
Puts the **Blob** data into an **ArrayBuffer** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;ArrayBuffer&gt; | Promise used to return the **ArrayBuffer** containing the **Blob** data.|
**Example**
```ts
let blob = new buffer.Blob(['a', 'b', 'c']);
let pro = blob.arrayBuffer();
pro.then(val => {
console.log(val)
});
```
### slice
slice(start?: number, end?: number, type?: string): Blob
Creates a **Blob** instance by copying specified data from this **Blob** instance.
**System capability**: SystemCapability.Utils.Lang
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| start | number | No| Offset to the start position of the data to copy.|
| end | number | No| Offset to the end position of the data to copy.|
| type | string | No| Type of the data in the new **Blob** instance.|
**Return value**
| Type| Description|
| -------- | -------- |
| Blob | New **Blob** instance created.|
**Example**
```ts
let blob = new buffer.Blob(['a', 'b', 'c']);
let blob2 = blob.slice(0, 2);
let blob3 = blob.slice(0, 2, "MIME");
```
### text
text(): Promise&lt;string&gt;
Returns text in UTF-8 format.
**System capability**: SystemCapability.Utils.Lang
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;string&gt; | Promise used to return the text encoded in UTF-8.|
**Example**
```ts
let blob = new buffer.Blob(['a', 'b', 'c']);
let pro = blob.text();
pro.then(val => {
console.log(val)
});
```
...@@ -61,7 +61,7 @@ export default class MyAbilityStage extends AbilityStage { ...@@ -61,7 +61,7 @@ export default class MyAbilityStage extends AbilityStage {
console.log("Failed to create KVManager: " + JSON.stringify(err)); console.log("Failed to create KVManager: " + JSON.stringify(err));
return; return;
} }
console.log("Created KVManager"); console.log("Created KVManager successfully");
kvManager = manager; kvManager = manager;
}); });
} }
...@@ -89,7 +89,7 @@ export default class MyAbilityStage extends AbilityStage { ...@@ -89,7 +89,7 @@ export default class MyAbilityStage extends AbilityStage {
console.log("Failed to create KVManager: " + JSON.stringify(err)); console.log("Failed to create KVManager: " + JSON.stringify(err));
return; return;
} }
console.log("Created KVManager"); console.log("Created KVManager successfully");
kvManager = manager; kvManager = manager;
}); });
} }
...@@ -139,7 +139,7 @@ export default class MyAbilityStage extends AbilityStage { ...@@ -139,7 +139,7 @@ export default class MyAbilityStage extends AbilityStage {
console.log("Failed to create KVManager: " + JSON.stringify(err)); console.log("Failed to create KVManager: " + JSON.stringify(err));
return; return;
} }
console.log("Created KVManager"); console.log("Created KVManager successfully");
kvManager = manager; kvManager = manager;
}); });
} }
...@@ -167,7 +167,7 @@ export default class MyAbilityStage extends AbilityStage { ...@@ -167,7 +167,7 @@ export default class MyAbilityStage extends AbilityStage {
console.log("Failed to create KVManager: " + JSON.stringify(err)); console.log("Failed to create KVManager: " + JSON.stringify(err));
return; return;
} }
console.log("Created KVManager"); console.log("Created KVManager successfully");
kvManager = manager; kvManager = manager;
}); });
} }
...@@ -304,7 +304,7 @@ try { ...@@ -304,7 +304,7 @@ try {
} }
``` ```
### closeKVStore<sup>8+</sup> ### ### closeKVStore<sup>8+</sup>
closeKVStore(appId: string, storeId: string, kvStore: KVStore, callback: AsyncCallback&lt;void&gt;): void closeKVStore(appId: string, storeId: string, kvStore: KVStore, callback: AsyncCallback&lt;void&gt;): void
...@@ -350,7 +350,7 @@ const options = { ...@@ -350,7 +350,7 @@ const options = {
``` ```
### closeKVStore<sup>8+</sup> ### ### closeKVStore<sup>8+</sup>
closeKVStore(appId: string, storeId: string, kvStore: KVStore): Promise&lt;void&gt; closeKVStore(appId: string, storeId: string, kvStore: KVStore): Promise&lt;void&gt;
...@@ -404,7 +404,7 @@ const options = { ...@@ -404,7 +404,7 @@ const options = {
``` ```
### deleteKVStore<sup>8+</sup> ### ### deleteKVStore<sup>8+</sup>
deleteKVStore(appId: string, storeId: string, callback: AsyncCallback&lt;void&gt;): void deleteKVStore(appId: string, storeId: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -447,7 +447,7 @@ try { ...@@ -447,7 +447,7 @@ try {
} }
``` ```
### deleteKVStore<sup>8+</sup> ### ### deleteKVStore<sup>8+</sup>
deleteKVStore(appId: string, storeId: string): Promise&lt;void&gt; deleteKVStore(appId: string, storeId: string): Promise&lt;void&gt;
...@@ -501,7 +501,7 @@ try { ...@@ -501,7 +501,7 @@ try {
``` ```
### getAllKVStoreId<sup>8+</sup> ### ### getAllKVStoreId<sup>8+</sup>
getAllKVStoreId(appId: string, callback: AsyncCallback&lt;string[]&gt;): void getAllKVStoreId(appId: string, callback: AsyncCallback&lt;string[]&gt;): void
...@@ -531,7 +531,7 @@ try { ...@@ -531,7 +531,7 @@ try {
``` ```
### getAllKVStoreId<sup>8+</sup> ### ### getAllKVStoreId<sup>8+</sup>
getAllKVStoreId(appId: string): Promise&lt;string[]&gt; getAllKVStoreId(appId: string): Promise&lt;string[]&gt;
...@@ -570,7 +570,7 @@ try { ...@@ -570,7 +570,7 @@ try {
``` ```
### on('distributedDataServiceDie')<sup>8+</sup> ### ### on('distributedDataServiceDie')<sup>8+</sup>
on(event: 'distributedDataServiceDie', deathCallback: Callback&lt;void&gt;): void on(event: 'distributedDataServiceDie', deathCallback: Callback&lt;void&gt;): void
...@@ -582,8 +582,8 @@ Subscribes to service status changes. ...@@ -582,8 +582,8 @@ Subscribes to service status changes.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event | string | Yes | Event to subscribe to. The value is **distributedDataServiceDie**, which indicates service status changes.| | event | string | Yes | Event to subscribe to. The value is **distributedDataServiceDie**, which indicates a service status change event.|
| deathCallback | Callback&lt;void&gt; | Yes | Callback invoked to return service status changes.| | deathCallback | Callback&lt;void&gt; | Yes | Callback invoked to return a service status change event.|
**Example** **Example**
...@@ -602,11 +602,11 @@ try { ...@@ -602,11 +602,11 @@ try {
``` ```
### off('distributedDataServiceDie')<sup>8+</sup> ### ### off('distributedDataServiceDie')<sup>8+</sup>
off(event: 'distributedDataServiceDie', deathCallback?: Callback&lt;void&gt;): void off(event: 'distributedDataServiceDie', deathCallback?: Callback&lt;void&gt;): void
Unsubscribes from the service status changes. Unsubscribes from service status changes.
**System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore **System capability**: SystemCapability.DistributedDataManager.KVStore.DistributedKVStore
...@@ -614,8 +614,8 @@ Unsubscribes from the service status changes. ...@@ -614,8 +614,8 @@ Unsubscribes from the service status changes.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event | string | Yes | Event to unsubscribe from. The value is **distributedDataServiceDie**, which indicates service status changes.| | event | string | Yes | Event to unsubscribe from. The value is **distributedDataServiceDie**, which indicates a service status change event.|
| deathCallback | Callback&lt;void&gt; | No | Callback used to return service status changes.| | deathCallback | Callback&lt;void&gt; | No | Callback used to return a service status change event.|
**Example** **Example**
...@@ -706,7 +706,7 @@ Defines the schema of a KV store. You can create a **Schema** object and place i ...@@ -706,7 +706,7 @@ Defines the schema of a KV store. You can create a **Schema** object and place i
| mode<sup>8+</sup> | number | Schema mode. | | mode<sup>8+</sup> | number | Schema mode. |
| skip<sup>8+</sup> | number | Size of a skip of the schema. | | skip<sup>8+</sup> | number | Size of a skip of the schema. |
### constructor<sup>8+</sup> ### ### constructor<sup>8+</sup>
constructor() constructor()
...@@ -726,7 +726,7 @@ Represents a **Schema** instance, which provides the methods for defining the va ...@@ -726,7 +726,7 @@ Represents a **Schema** instance, which provides the methods for defining the va
| default<sup>8+</sup> | string | Default value of a **FieldNode**.| | default<sup>8+</sup> | string | Default value of a **FieldNode**.|
| type<sup>8+</sup> | number | Value of the data type corresponding to the specified node.| | type<sup>8+</sup> | number | Value of the data type corresponding to the specified node.|
### constructor<sup>8+</sup> ### ### constructor<sup>8+</sup>
constructor(name: string) constructor(name: string)
...@@ -740,7 +740,7 @@ A constructor used to create a **FieldNode** instance with a string field. ...@@ -740,7 +740,7 @@ A constructor used to create a **FieldNode** instance with a string field.
| ------ | -------- | ---- | --------------- | | ------ | -------- | ---- | --------------- |
| name | string | Yes | Value of **FieldNode**.| | name | string | Yes | Value of **FieldNode**.|
### appendChild<sup>8+</sup> ### ### appendChild<sup>8+</sup>
appendChild(child: FieldNode): boolean appendChild(child: FieldNode): boolean
...@@ -790,7 +790,7 @@ Provides methods to obtain the KV store result sets, and query and move the data ...@@ -790,7 +790,7 @@ Provides methods to obtain the KV store result sets, and query and move the data
Before calling any method in **KvStoreResultSet**, you must use [getKVStore](#getkvstore) to obtain a **KVStore** object. Before calling any method in **KvStoreResultSet**, you must use [getKVStore](#getkvstore) to obtain a **KVStore** object.
### getCount<sup>8+</sup> ### ### getCount<sup>8+</sup>
getCount(): number getCount(): number
...@@ -823,7 +823,7 @@ try { ...@@ -823,7 +823,7 @@ try {
} }
``` ```
### getPosition<sup>8+</sup> ### ### getPosition<sup>8+</sup>
getPosition(): number getPosition(): number
...@@ -857,7 +857,7 @@ try { ...@@ -857,7 +857,7 @@ try {
``` ```
### moveToFirst<sup>8+</sup> ### ### moveToFirst<sup>8+</sup>
moveToFirst(): boolean moveToFirst(): boolean
...@@ -891,7 +891,7 @@ try { ...@@ -891,7 +891,7 @@ try {
``` ```
### moveToLast<sup>8+</sup> ### ### moveToLast<sup>8+</sup>
moveToLast(): boolean moveToLast(): boolean
...@@ -925,7 +925,7 @@ try { ...@@ -925,7 +925,7 @@ try {
``` ```
### moveToNext<sup>8+</sup> ### ### moveToNext<sup>8+</sup>
moveToNext(): boolean moveToNext(): boolean
...@@ -959,7 +959,7 @@ try { ...@@ -959,7 +959,7 @@ try {
``` ```
### moveToPrevious<sup>8+</sup> ### ### moveToPrevious<sup>8+</sup>
moveToPrevious(): boolean moveToPrevious(): boolean
...@@ -993,7 +993,7 @@ try { ...@@ -993,7 +993,7 @@ try {
``` ```
### move<sup>8+</sup> ### ### move<sup>8+</sup>
move(offset: number): boolean move(offset: number): boolean
...@@ -1033,7 +1033,7 @@ try { ...@@ -1033,7 +1033,7 @@ try {
``` ```
### moveToPosition<sup>8+</sup> ### ### moveToPosition<sup>8+</sup>
moveToPosition(position: number): boolean moveToPosition(position: number): boolean
...@@ -1073,7 +1073,7 @@ try { ...@@ -1073,7 +1073,7 @@ try {
``` ```
### isFirst<sup>8+</sup> ### ### isFirst<sup>8+</sup>
isFirst(): boolean isFirst(): boolean
...@@ -1107,7 +1107,7 @@ try { ...@@ -1107,7 +1107,7 @@ try {
``` ```
### isLast<sup>8+</sup> ### ### isLast<sup>8+</sup>
isLast(): boolean isLast(): boolean
...@@ -1140,7 +1140,7 @@ try { ...@@ -1140,7 +1140,7 @@ try {
} }
``` ```
### isBeforeFirst<sup>8+</sup> ### ### isBeforeFirst<sup>8+</sup>
isBeforeFirst(): boolean isBeforeFirst(): boolean
...@@ -1174,7 +1174,7 @@ try { ...@@ -1174,7 +1174,7 @@ try {
``` ```
### isAfterLast<sup>8+</sup> ### ### isAfterLast<sup>8+</sup>
isAfterLast(): boolean isAfterLast(): boolean
...@@ -1208,7 +1208,7 @@ try { ...@@ -1208,7 +1208,7 @@ try {
``` ```
### getEntry<sup>8+</sup> ### ### getEntry<sup>8+</sup>
getEntry(): Entry getEntry(): Entry
...@@ -1248,7 +1248,7 @@ Provides methods to create a **Query** object, which defines different data quer ...@@ -1248,7 +1248,7 @@ Provides methods to create a **Query** object, which defines different data quer
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
### constructor<sup>8+</sup> ### ### constructor<sup>8+</sup>
constructor() constructor()
...@@ -1257,7 +1257,7 @@ A constructor used to create a **Schema** instance. ...@@ -1257,7 +1257,7 @@ A constructor used to create a **Schema** instance.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
### reset<sup>8+</sup> ### ### reset<sup>8+</sup>
reset(): Query reset(): Query
...@@ -1288,7 +1288,7 @@ try { ...@@ -1288,7 +1288,7 @@ try {
``` ```
### equalTo<sup>8+</sup> ### ### equalTo<sup>8+</sup>
equalTo(field: string, value: number|string|boolean): Query equalTo(field: string, value: number|string|boolean): Query
...@@ -1323,7 +1323,7 @@ try { ...@@ -1323,7 +1323,7 @@ try {
``` ```
### notEqualTo<sup>8+</sup> ### ### notEqualTo<sup>8+</sup>
notEqualTo(field: string, value: number|string|boolean): Query notEqualTo(field: string, value: number|string|boolean): Query
...@@ -1358,7 +1358,7 @@ try { ...@@ -1358,7 +1358,7 @@ try {
``` ```
### greaterThan<sup>8+</sup> ### ### greaterThan<sup>8+</sup>
greaterThan(field: string, value: number|string|boolean): Query greaterThan(field: string, value: number|string|boolean): Query
...@@ -1393,7 +1393,7 @@ try { ...@@ -1393,7 +1393,7 @@ try {
``` ```
### lessThan<sup>8+</sup> ### ### lessThan<sup>8+</sup>
lessThan(field: string, value: number|string): Query lessThan(field: string, value: number|string): Query
...@@ -1428,7 +1428,7 @@ try { ...@@ -1428,7 +1428,7 @@ try {
``` ```
### greaterThanOrEqualTo<sup>8+</sup> ### ### greaterThanOrEqualTo<sup>8+</sup>
greaterThanOrEqualTo(field: string, value: number|string): Query greaterThanOrEqualTo(field: string, value: number|string): Query
...@@ -1463,7 +1463,7 @@ try { ...@@ -1463,7 +1463,7 @@ try {
``` ```
### lessThanOrEqualTo<sup>8+</sup> ### ### lessThanOrEqualTo<sup>8+</sup>
lessThanOrEqualTo(field: string, value: number|string): Query lessThanOrEqualTo(field: string, value: number|string): Query
...@@ -1498,7 +1498,7 @@ try { ...@@ -1498,7 +1498,7 @@ try {
``` ```
### isNull<sup>8+</sup> ### ### isNull<sup>8+</sup>
isNull(field: string): Query isNull(field: string): Query
...@@ -1532,7 +1532,7 @@ try { ...@@ -1532,7 +1532,7 @@ try {
``` ```
### inNumber<sup>8+</sup> ### ### inNumber<sup>8+</sup>
inNumber(field: string, valueList: number[]): Query inNumber(field: string, valueList: number[]): Query
...@@ -1568,7 +1568,7 @@ try { ...@@ -1568,7 +1568,7 @@ try {
``` ```
### inString<sup>8+</sup> ### ### inString<sup>8+</sup>
inString(field: string, valueList: string[]): Query inString(field: string, valueList: string[]): Query
...@@ -1603,7 +1603,7 @@ try { ...@@ -1603,7 +1603,7 @@ try {
``` ```
### notInNumber<sup>8+</sup> ### ### notInNumber<sup>8+</sup>
notInNumber(field: string, valueList: number[]): Query notInNumber(field: string, valueList: number[]): Query
...@@ -1638,7 +1638,7 @@ try { ...@@ -1638,7 +1638,7 @@ try {
``` ```
### notInString<sup>8+</sup> ### ### notInString<sup>8+</sup>
notInString(field: string, valueList: string[]): Query notInString(field: string, valueList: string[]): Query
...@@ -1673,7 +1673,7 @@ try { ...@@ -1673,7 +1673,7 @@ try {
``` ```
### like<sup>8+</sup> ### ### like<sup>8+</sup>
like(field: string, value: string): Query like(field: string, value: string): Query
...@@ -1708,7 +1708,7 @@ try { ...@@ -1708,7 +1708,7 @@ try {
``` ```
### unlike<sup>8+</sup> ### ### unlike<sup>8+</sup>
unlike(field: string, value: string): Query unlike(field: string, value: string): Query
...@@ -1743,7 +1743,7 @@ try { ...@@ -1743,7 +1743,7 @@ try {
``` ```
### and<sup>8+</sup> ### ### and<sup>8+</sup>
and(): Query and(): Query
...@@ -1773,7 +1773,7 @@ try { ...@@ -1773,7 +1773,7 @@ try {
``` ```
### or<sup>8+</sup> ### ### or<sup>8+</sup>
or(): Query or(): Query
...@@ -1803,7 +1803,7 @@ try { ...@@ -1803,7 +1803,7 @@ try {
``` ```
### orderByAsc<sup>8+</sup> ### ### orderByAsc<sup>8+</sup>
orderByAsc(field: string): Query orderByAsc(field: string): Query
...@@ -1838,7 +1838,7 @@ try { ...@@ -1838,7 +1838,7 @@ try {
``` ```
### orderByDesc<sup>8+</sup> ### ### orderByDesc<sup>8+</sup>
orderByDesc(field: string): Query orderByDesc(field: string): Query
...@@ -1873,7 +1873,7 @@ try { ...@@ -1873,7 +1873,7 @@ try {
``` ```
### limit<sup>8+</sup> ### ### limit<sup>8+</sup>
limit(total: number, offset: number): Query limit(total: number, offset: number): Query
...@@ -1911,7 +1911,7 @@ try { ...@@ -1911,7 +1911,7 @@ try {
``` ```
### isNotNull<sup>8+</sup> ### ### isNotNull<sup>8+</sup>
isNotNull(field: string): Query isNotNull(field: string): Query
...@@ -1945,7 +1945,7 @@ try { ...@@ -1945,7 +1945,7 @@ try {
``` ```
### beginGroup<sup>8+</sup> ### ### beginGroup<sup>8+</sup>
beginGroup(): Query beginGroup(): Query
...@@ -1975,7 +1975,7 @@ try { ...@@ -1975,7 +1975,7 @@ try {
``` ```
### endGroup<sup>8+</sup> ### ### endGroup<sup>8+</sup>
endGroup(): Query endGroup(): Query
...@@ -2005,7 +2005,7 @@ try { ...@@ -2005,7 +2005,7 @@ try {
``` ```
### prefixKey<sup>8+</sup> ### ### prefixKey<sup>8+</sup>
prefixKey(prefix: string): Query prefixKey(prefix: string): Query
...@@ -2040,7 +2040,7 @@ try { ...@@ -2040,7 +2040,7 @@ try {
``` ```
### setSuggestIndex<sup>8+</sup> ### ### setSuggestIndex<sup>8+</sup>
setSuggestIndex(index: string): Query setSuggestIndex(index: string): Query
...@@ -2075,7 +2075,7 @@ try { ...@@ -2075,7 +2075,7 @@ try {
``` ```
### deviceId<sup>8+</sup> ### ### deviceId<sup>8+</sup>
deviceId(deviceId:string):Query deviceId(deviceId:string):Query
...@@ -2109,7 +2109,7 @@ try { ...@@ -2109,7 +2109,7 @@ try {
``` ```
### getSqlLike<sup>8+</sup> ### ### getSqlLike<sup>8+</sup>
getSqlLike():string getSqlLike():string
...@@ -2303,7 +2303,9 @@ try { ...@@ -2303,7 +2303,9 @@ try {
delete(predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;void&gt;) delete(predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;void&gt;)
Deletes KV pairs that meet the specified predicates. This API uses an asynchronous callback to return the result. Deletes KV pairs that meet the specified conditions. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2337,7 +2339,9 @@ try { ...@@ -2337,7 +2339,9 @@ try {
delete(predicates: dataSharePredicates.DataSharePredicates): Promise&lt;void&gt; delete(predicates: dataSharePredicates.DataSharePredicates): Promise&lt;void&gt;
Deletes KV pairs that meet the specified predicates. This API uses a promise to return the result. Deletes KV pairs that meet the specified conditions. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2352,7 +2356,7 @@ Deletes KV pairs that meet the specified predicates. This API uses a promise to ...@@ -2352,7 +2356,7 @@ Deletes KV pairs that meet the specified predicates. This API uses a promise to
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -2379,11 +2383,224 @@ try { ...@@ -2379,11 +2383,224 @@ try {
``` ```
### backup<sup>9+</sup>
backup(file:string, callback: AsyncCallback&lt;void&gt;):void
Backs up an RDB store. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| file | string | Yes | Name of the database. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants).|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is the error object. |
**Example**
```js
let kvStore;
let file = "BK001";
try {
kvStore.backup(file, (err, data) => {
if (err) {
console.info("backup err : " + err);
} else {
console.info("backup data : " + data);
}
});
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### backup<sup>9+</sup>
backup(file:string): Promise&lt;void&gt;
Backs up an RDB store. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | -------- | ---- | ------------------------------------------------------------ |
| file | string | Yes | Name of the database. This parameter cannot be empty and its length cannot exceed [MAX_KEY_LENGTH](#constants).|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let kvStore;
let file = "BK001";
try {
kvStore.backup(file).then((data) => {
console.info("backup data : " + data);
}).catch((err) => {
console.info("backup err : " + err);
});
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### restore<sup>9+</sup>
restore(file:string, callback: AsyncCallback&lt;void&gt;):void
Restores an RDB store from a database file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| file | string | Yes | Name of the database file. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants).|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example**
```js
let kvStore;
let file = "BK001";
try {
kvStore.restore(file, (err, data) => {
if (err) {
console.info("restore err : " + err);
} else {
console.info("restore data : " + data);
}
});
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### restore<sup>9+</sup>
restore(file:string): Promise&lt;void&gt;
Restores an RDB store from a database file. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | -------- | ---- | ------------------------------------------------------------ |
| file | string | Yes | Name of the database file. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants).|
**Return value**
| Type | Description |
| ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let kvStore;
let file = "BK001";
try {
kvStore.restore(file).then((data) => {
console.info("restore data : " + data);
}).catch((err) => {
console.info("restore err : " + err);
});
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### deleteBackup<sup>9+</sup>
deleteBackup(files:Array&lt;string&gt;, callback: AsyncCallback&lt;Array&lt;[string, number]&gt;&gt;):void
Deletes a backup file. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------------- | ---- | ------------------------------------------------------------ |
| files | Array&lt;string&gt; | Yes | Name of the backup file to delete. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants). |
| callback | AsyncCallback&lt;Array&lt;[string, number]&gt;&gt; | Yes | Callback invoked to return the name of the backup file deleted and the operation result. |
**Example**
```js
let kvStore;
let files = ["BK001", "BK002"];
try {
kvStore.deleteBackup(files, (err, data) => {
if (err) {
console.info("deleteBackup err : " + err);
} else {
console.info("deleteBackup data : " + data);
}
});
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### deleteBackup<sup>9+</sup>
deleteBackup(files:Array&lt;string&gt;): Promise&lt;Array&lt;[string, number]&gt;&gt;
Deletes a backup file. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters**
| Name| Type| Mandatory| Description |
| ------ | -------- | ---- | ------------------------------------------------------------ |
| files | Array&lt;string&gt; | Yes | Name of the backup file to delete. The value cannot be empty or exceed [MAX_KEY_LENGTH](#constants).|
**Return value**
| Type | Description |
| -------------------------------------------- | ----------------------------------------------- |
| Promise&lt;Array&lt;[string, number]&gt;&gt; | Promise used to return the name of the backup file deleted and the operation result.|
**Example**
```js
let kvStore;
let files = ["BK001", "BK002"];
try {
kvStore.deleteBackup(files).then((data) => {
console.info("deleteBackup data : " + data);
}).catch((err) => {
console.info("deleteBackup err : " + err);
})
} catch (e) {
console.log("An unexpected error occurred. Error : " + e);
}
```
### on('dataChange') ### on('dataChange')
on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
Subscribes to data change notifications of the specified type. Subscribes to data changes of the specified type.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2391,9 +2608,9 @@ Subscribes to data change notifications of the specified type. ...@@ -2391,9 +2608,9 @@ Subscribes to data change notifications of the specified type.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates data changes. | | event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates a data change event. |
| type |[SubscribeType](#subscribetype) | Yes |Type of data changes. | | type |[SubscribeType](#subscribetype) | Yes |Type of data change. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback used to return the data changes.| | listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback used to return a data change event.|
**Example** **Example**
...@@ -2409,7 +2626,7 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun ...@@ -2409,7 +2626,7 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Subscribes to data synchronization complete events. Subscribes to synchronization complete events.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2417,8 +2634,8 @@ Subscribes to data synchronization complete events. ...@@ -2417,8 +2634,8 @@ Subscribes to data synchronization complete events.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates completion of a data synchronization. | | event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates a synchronization complete event. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback used to return the data synchronization result. | | syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback used to return a synchronization complete event. |
**Example** **Example**
...@@ -2433,7 +2650,7 @@ kvStore.on('syncComplete', function (data) { ...@@ -2433,7 +2650,7 @@ kvStore.on('syncComplete', function (data) {
off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
Unsubscribes from data change notifications. Unsubscribes from data changes.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2441,26 +2658,35 @@ Unsubscribes from data change notifications. ...@@ -2441,26 +2658,35 @@ Unsubscribes from data change notifications.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates data changes. | | event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates a data change event. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return the data changes.| | listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return a data change event.|
**Example** **Example**
```js ```js
let kvStore; let kvStore;
kvStore.on('dataChange', function (data) { class KvstoreModel {
console.log("callback call data: " + data); call(data) {
}); console.log("dataChange: " + data);
kvStore.off('dataChange', function (data) { }
console.log("callback call data: " + data); subscribeDataChange() {
}); if (kvStore != null) {
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
}
}
unsubscribeDataChange() {
if (kvStore != null) {
kvStore.off('dataChange', this.call);
}
}
}
``` ```
### off('syncComplete')<sup>9+</sup> ### off('syncComplete')<sup>9+</sup>
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Unsubscribes from data change events. This API uses a synchronous callback to return the result. Unsubscribes from data changes. This API returns the result synchronously.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2468,21 +2694,27 @@ Unsubscribes from data change events. This API uses a synchronous callback to re ...@@ -2468,21 +2694,27 @@ Unsubscribes from data change events. This API uses a synchronous callback to re
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates completion of a data synchronization. | | event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. | | syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return a synchronization complete event. |
**Example** **Example**
```js ```js
let kvStore; let kvStore;
try { class KvstoreModel {
const func = function (data) { call(data) {
console.log('syncComplete ' + data) console.log("syncComplete: " + data);
}; }
kvStore.on('syncComplete', func); subscribeSyncComplete() {
kvStore.off('syncComplete', func); if (kvStore != null) {
}catch(e) { kvStore.on('syncComplete', this.call);
console.log('syncComplete e ' + e); }
}
unsubscribeSyncComplete() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
}
}
} }
``` ```
...@@ -2594,6 +2826,8 @@ putBatch(value: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;void&gt;): ...@@ -2594,6 +2826,8 @@ putBatch(value: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;void&gt;):
Writes data to this KV store. This API uses an asynchronous callback to return the result. Writes data to this KV store. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters** **Parameters**
...@@ -2631,7 +2865,9 @@ try { ...@@ -2631,7 +2865,9 @@ try {
putBatch(value: Array&lt;ValuesBucket&gt;): Promise&lt;void&gt; putBatch(value: Array&lt;ValuesBucket&gt;): Promise&lt;void&gt;
Writes data of the **valuesbucket** type to this KV store. This API uses a promise to return the result. Write data to this KV store. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -2645,7 +2881,7 @@ Writes data of the **valuesbucket** type to this KV store. This API uses a promi ...@@ -2645,7 +2881,7 @@ Writes data of the **valuesbucket** type to this KV store. This API uses a promi
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
| Promise&lt;void&gt; |Promise used to return the result.| | Promise&lt;void&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -2719,7 +2955,7 @@ try { ...@@ -2719,7 +2955,7 @@ try {
``` ```
### deleteBatch<sup>8+</sup> ### ### deleteBatch<sup>8+</sup>
deleteBatch(keys: string[]): Promise&lt;void&gt; deleteBatch(keys: string[]): Promise&lt;void&gt;
...@@ -2775,7 +3011,7 @@ try { ...@@ -2775,7 +3011,7 @@ try {
``` ```
### startTransaction<sup>8+</sup> ### ### startTransaction<sup>8+</sup>
startTransaction(callback: AsyncCallback&lt;void&gt;): void startTransaction(callback: AsyncCallback&lt;void&gt;): void
...@@ -2827,7 +3063,7 @@ try { ...@@ -2827,7 +3063,7 @@ try {
``` ```
### startTransaction<sup>8+</sup> ### ### startTransaction<sup>8+</sup>
startTransaction(): Promise&lt;void&gt; startTransaction(): Promise&lt;void&gt;
...@@ -2862,7 +3098,7 @@ try { ...@@ -2862,7 +3098,7 @@ try {
``` ```
### commit<sup>8+</sup> ### ### commit<sup>8+</sup>
commit(callback: AsyncCallback&lt;void&gt;): void commit(callback: AsyncCallback&lt;void&gt;): void
...@@ -2894,7 +3130,7 @@ try { ...@@ -2894,7 +3130,7 @@ try {
``` ```
### commit<sup>8+</sup> ### ### commit<sup>8+</sup>
commit(): Promise&lt;void&gt; commit(): Promise&lt;void&gt;
...@@ -2924,7 +3160,7 @@ try { ...@@ -2924,7 +3160,7 @@ try {
``` ```
### rollback<sup>8+</sup> ### ### rollback<sup>8+</sup>
rollback(callback: AsyncCallback&lt;void&gt;): void rollback(callback: AsyncCallback&lt;void&gt;): void
...@@ -2956,7 +3192,7 @@ try { ...@@ -2956,7 +3192,7 @@ try {
``` ```
### rollback<sup>8+</sup> ### ### rollback<sup>8+</sup>
rollback(): Promise&lt;void&gt; rollback(): Promise&lt;void&gt;
...@@ -2986,7 +3222,7 @@ try { ...@@ -2986,7 +3222,7 @@ try {
``` ```
### enableSync<sup>8+</sup> ### ### enableSync<sup>8+</sup>
enableSync(enabled: boolean, callback: AsyncCallback&lt;void&gt;): void enableSync(enabled: boolean, callback: AsyncCallback&lt;void&gt;): void
...@@ -3019,7 +3255,7 @@ try { ...@@ -3019,7 +3255,7 @@ try {
``` ```
### enableSync<sup>8+</sup> ### ### enableSync<sup>8+</sup>
enableSync(enabled: boolean): Promise&lt;void&gt; enableSync(enabled: boolean): Promise&lt;void&gt;
...@@ -3055,7 +3291,7 @@ try { ...@@ -3055,7 +3291,7 @@ try {
``` ```
### setSyncRange<sup>8+</sup> ### ### setSyncRange<sup>8+</sup>
setSyncRange(localLabels: string[], remoteSupportLabels: string[], callback: AsyncCallback&lt;void&gt;): void setSyncRange(localLabels: string[], remoteSupportLabels: string[], callback: AsyncCallback&lt;void&gt;): void
...@@ -3087,7 +3323,7 @@ try { ...@@ -3087,7 +3323,7 @@ try {
``` ```
### setSyncRange<sup>8+</sup> ### ### setSyncRange<sup>8+</sup>
setSyncRange(localLabels: string[], remoteSupportLabels: string[]): Promise&lt;void&gt; setSyncRange(localLabels: string[], remoteSupportLabels: string[]): Promise&lt;void&gt;
...@@ -3279,7 +3515,7 @@ try { ...@@ -3279,7 +3515,7 @@ try {
} }
``` ```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup>
getEntries(keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void getEntries(keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
...@@ -3325,7 +3561,7 @@ try { ...@@ -3325,7 +3561,7 @@ try {
``` ```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup>
getEntries(keyPrefix: string): Promise&lt;Entry[]&gt; getEntries(keyPrefix: string): Promise&lt;Entry[]&gt;
...@@ -3383,7 +3619,7 @@ try { ...@@ -3383,7 +3619,7 @@ try {
``` ```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup>
getEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void getEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
...@@ -3434,7 +3670,7 @@ try { ...@@ -3434,7 +3670,7 @@ try {
``` ```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup>
getEntries(query: Query): Promise&lt;Entry[]&gt; getEntries(query: Query): Promise&lt;Entry[]&gt;
...@@ -3492,7 +3728,7 @@ try { ...@@ -3492,7 +3728,7 @@ try {
``` ```
### getResultSet<sup>8+</sup><a name="singlekvstore_getresultset"></a> ### ### getResultSet<sup>8+</sup><a name="singlekvstore_getresultset"></a>
getResultSet(keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
...@@ -3541,7 +3777,7 @@ try { ...@@ -3541,7 +3777,7 @@ try {
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup>
getResultSet(keyPrefix: string): Promise&lt;KvStoreResultSet&gt; getResultSet(keyPrefix: string): Promise&lt;KvStoreResultSet&gt;
...@@ -3601,7 +3837,7 @@ try { ...@@ -3601,7 +3837,7 @@ try {
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup>
getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
...@@ -3649,7 +3885,7 @@ try { ...@@ -3649,7 +3885,7 @@ try {
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup>
getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt; getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt;
...@@ -3705,12 +3941,14 @@ try { ...@@ -3705,12 +3941,14 @@ try {
} }
``` ```
### getResultSet<sup>9+</sup> ### ### getResultSet<sup>9+</sup>
getResultSet(predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
Obtains a **KvStoreResultSet** object that matches the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result. Obtains a **KvStoreResultSet** object that matches the specified **DataSharePredicates** object. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters** **Parameters**
...@@ -3740,12 +3978,14 @@ try { ...@@ -3740,12 +3978,14 @@ try {
console.log('An unexpected error occurred. Error:' + e); console.log('An unexpected error occurred. Error:' + e);
} }
``` ```
### getResultSet<sup>9+</sup> ### ### getResultSet<sup>9+</sup>
getResultSet(predicates: dataSharePredicates.DataSharePredicates): Promise&lt;KvStoreResultSet&gt; getResultSet(predicates: dataSharePredicates.DataSharePredicates): Promise&lt;KvStoreResultSet&gt;
Obtains a **KvStoreResultSet** object that matches the specified **DataSharePredicates** object. This API uses a promise to return the result. Obtains a **KvStoreResultSet** object that matches the specified **DataSharePredicates** object. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
**Parameters** **Parameters**
...@@ -3758,7 +3998,7 @@ Obtains a **KvStoreResultSet** object that matches the specified **DataSharePred ...@@ -3758,7 +3998,7 @@ Obtains a **KvStoreResultSet** object that matches the specified **DataSharePred
| Type | Description | | Type | Description |
| ------ | ------- | | ------ | ------- |
|Promise&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; |Promise used to return the **KvStoreResultSet** object obtained.| |Promise&lt;[KvStoreResultSet](#kvstoreresultset8)&gt; |Promise that returns no value.|
**Example** **Example**
...@@ -3780,7 +4020,7 @@ try { ...@@ -3780,7 +4020,7 @@ try {
console.log('An unexpected error occurred. Error:' + e); console.log('An unexpected error occurred. Error:' + e);
} }
``` ```
### closeResultSet<sup>8+</sup> ### ### closeResultSet<sup>8+</sup>
closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void
...@@ -3814,7 +4054,7 @@ try { ...@@ -3814,7 +4054,7 @@ try {
``` ```
### closeResultSet<sup>8+</sup> ### ### closeResultSet<sup>8+</sup>
closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt; closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt;
...@@ -3851,7 +4091,7 @@ try { ...@@ -3851,7 +4091,7 @@ try {
``` ```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup>
getResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void getResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void
...@@ -3897,7 +4137,7 @@ try { ...@@ -3897,7 +4137,7 @@ try {
``` ```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup>
getResultSize(query: Query): Promise&lt;number&gt; getResultSize(query: Query): Promise&lt;number&gt;
...@@ -3952,7 +4192,7 @@ try { ...@@ -3952,7 +4192,7 @@ try {
``` ```
### removeDeviceData<sup>8+</sup> ### ### removeDeviceData<sup>8+</sup>
removeDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void removeDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -3994,7 +4234,7 @@ try { ...@@ -3994,7 +4234,7 @@ try {
``` ```
### removeDeviceData<sup>8+</sup> ### ### removeDeviceData<sup>8+</sup>
removeDeviceData(deviceId: string): Promise&lt;void&gt; removeDeviceData(deviceId: string): Promise&lt;void&gt;
...@@ -4043,11 +4283,11 @@ try { ...@@ -4043,11 +4283,11 @@ try {
``` ```
### on('syncComplete')<sup>8+</sup> ### ### on('syncComplete')<sup>8+</sup>
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Subscribes to the data synchronization complete events. Subscribes to synchronization complete events.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -4055,8 +4295,8 @@ Subscribes to the data synchronization complete events. ...@@ -4055,8 +4295,8 @@ Subscribes to the data synchronization complete events.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates completion of a data synchronization. | | event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates a synchronization complete event. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback called to return the synchronization result. | | syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | Yes |Callback invoked to return a synchronization complete event. |
**Example** **Example**
...@@ -4079,11 +4319,11 @@ try { ...@@ -4079,11 +4319,11 @@ try {
``` ```
### off('syncComplete')<sup>8+</sup> ### ### off('syncComplete')<sup>8+</sup>
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Unsubscribes from the data synchronization complete events. Unsubscribes from synchronization complete events.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -4091,25 +4331,31 @@ Unsubscribes from the data synchronization complete events. ...@@ -4091,25 +4331,31 @@ Unsubscribes from the data synchronization complete events.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates completion of a data synchronization. | | event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event. |
| syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. | | syncCallback |Callback&lt;Array&lt;[string, number]&gt;&gt; | No |Callback used to return a synchronization complete event. |
**Example** **Example**
```js ```js
let kvStore; let kvStore;
try { class KvstoreModel {
const func = function (data) { call(data) {
console.log('syncComplete ' + data) console.log("syncComplete: " + data);
}; }
kvStore.on('syncComplete', func); subscribeSyncComplete() {
kvStore.off('syncComplete', func); if (kvStore != null) {
}catch(e) { kvStore.on('syncComplete', this.call);
console.log('syncComplete e ' + e); }
}
unsubscribeSyncComplete() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
}
}
} }
``` ```
### on('dataChange')<sup>9+</sup> ### ### on('dataChange')<sup>9+</sup>
on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
...@@ -4121,9 +4367,9 @@ Subscribes to data changes of the specified type. This API returns the result sy ...@@ -4121,9 +4367,9 @@ Subscribes to data changes of the specified type. This API returns the result sy
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates data changes. | | event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates a data change event. |
| type |[SubscribeType](#subscribetype) | Yes |Subscription type. | | type |[SubscribeType](#subscribetype) | Yes |Type of data change. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback used to return the result.| | listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback invoked to return a data change event.|
**Example** **Example**
...@@ -4135,11 +4381,11 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun ...@@ -4135,11 +4381,11 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun
``` ```
### off('dataChange')<sup>9+</sup> ### ### off('dataChange')<sup>9+</sup>
off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
Unsubscribes from the data change events. This API returns the result synchronously. Unsubscribes from data changes. This API returns the result synchronously.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -4147,19 +4393,28 @@ Unsubscribes from the data change events. This API returns the result synchronou ...@@ -4147,19 +4393,28 @@ Unsubscribes from the data change events. This API returns the result synchronou
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates data changes. | | event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates a data change event. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return the result.| | listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return a data change event.|
**Example** **Example**
```js ```js
let kvStore; let kvStore;
kvStore.on('dataChange', function (data) { class KvstoreModel {
console.log("callback call data: " + data); call(data) {
}); console.log("dataChange: " + data);
kvStore.off('dataChange', function (data) { }
console.log("callback call data: " + data); subscribeDataChange() {
}); if (kvStore != null) {
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
}
}
unsubscribeDataChange() {
if (kvStore != null) {
kvStore.off('dataChange', this.call);
}
}
}
``` ```
### sync<sup>7+</sup> ### sync<sup>7+</sup>
...@@ -4229,7 +4484,7 @@ try { ...@@ -4229,7 +4484,7 @@ try {
} }
``` ```
### setSyncParam<sup>8+</sup> ### ### setSyncParam<sup>8+</sup>
setSyncParam(defaultAllowedDelayMs: number, callback: AsyncCallback&lt;void&gt;): void setSyncParam(defaultAllowedDelayMs: number, callback: AsyncCallback&lt;void&gt;): void
...@@ -4259,7 +4514,7 @@ try { ...@@ -4259,7 +4514,7 @@ try {
``` ```
### setSyncParam<sup>8+</sup> ### ### setSyncParam<sup>8+</sup>
setSyncParam(defaultAllowedDelayMs: number): Promise&lt;void&gt; setSyncParam(defaultAllowedDelayMs: number): Promise&lt;void&gt;
...@@ -4297,7 +4552,7 @@ try { ...@@ -4297,7 +4552,7 @@ try {
``` ```
### getSecurityLevel<sup>8+</sup> ### ### getSecurityLevel<sup>8+</sup>
getSecurityLevel(callback: AsyncCallback&lt;SecurityLevel&gt;): void getSecurityLevel(callback: AsyncCallback&lt;SecurityLevel&gt;): void
...@@ -4325,7 +4580,7 @@ try { ...@@ -4325,7 +4580,7 @@ try {
``` ```
### getSecurityLevel<sup>8+</sup> ### ### getSecurityLevel<sup>8+</sup>
getSecurityLevel(): Promise&lt;SecurityLevel&gt; getSecurityLevel(): Promise&lt;SecurityLevel&gt;
...@@ -4365,7 +4620,7 @@ For example, a device KV store can be used to implement image sharing between de ...@@ -4365,7 +4620,7 @@ For example, a device KV store can be used to implement image sharing between de
Before calling any method in **DeviceKVStore**, you must use [getKVStore](#getkvstore) to obtain a **DeviceKVStore** object. Before calling any method in **DeviceKVStore**, you must use [getKVStore](#getkvstore) to obtain a **DeviceKVStore** object.
### get<sup>8+</sup> ### ### get<sup>8+</sup>
get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): void get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): void
...@@ -4400,7 +4655,7 @@ try{ ...@@ -4400,7 +4655,7 @@ try{
``` ```
### get<sup>8+</sup> ### ### get<sup>8+</sup>
get(deviceId: string, key: string): Promise&lt;boolean|string|number|Uint8Array&gt; get(deviceId: string, key: string): Promise&lt;boolean|string|number|Uint8Array&gt;
...@@ -4444,7 +4699,7 @@ try { ...@@ -4444,7 +4699,7 @@ try {
``` ```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup>
getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void getEntries(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;Entry[]&gt;): void
...@@ -4492,7 +4747,7 @@ try { ...@@ -4492,7 +4747,7 @@ try {
``` ```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup>
getEntries(deviceId: string, keyPrefix: string): Promise&lt;Entry[]&gt; getEntries(deviceId: string, keyPrefix: string): Promise&lt;Entry[]&gt;
...@@ -4551,7 +4806,7 @@ try { ...@@ -4551,7 +4806,7 @@ try {
``` ```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup>
getEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void getEntries(query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
...@@ -4603,7 +4858,7 @@ try { ...@@ -4603,7 +4858,7 @@ try {
``` ```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup>
getEntries(query: Query): Promise&lt;Entry[]&gt; getEntries(query: Query): Promise&lt;Entry[]&gt;
...@@ -4661,7 +4916,7 @@ try { ...@@ -4661,7 +4916,7 @@ try {
``` ```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup>
getEntries(deviceId: string, query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void getEntries(deviceId: string, query: Query, callback: AsyncCallback&lt;Entry[]&gt;): void
...@@ -4714,7 +4969,7 @@ try { ...@@ -4714,7 +4969,7 @@ try {
``` ```
### getEntries<sup>8+</sup> ### ### getEntries<sup>8+</sup>
getEntries(deviceId: string, query: Query): Promise&lt;Entry[]&gt; getEntries(deviceId: string, query: Query): Promise&lt;Entry[]&gt;
...@@ -4774,7 +5029,7 @@ try { ...@@ -4774,7 +5029,7 @@ try {
``` ```
### getResultSet<sup>8+</sup><a name="devicekvstore_getresultset"></a> ### ### getResultSet<sup>8+</sup><a name="devicekvstore_getresultset"></a>
getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(deviceId: string, keyPrefix: string, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
...@@ -4809,7 +5064,7 @@ try { ...@@ -4809,7 +5064,7 @@ try {
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup>
getResultSet(deviceId: string, keyPrefix: string): Promise&lt;KvStoreResultSet&gt; getResultSet(deviceId: string, keyPrefix: string): Promise&lt;KvStoreResultSet&gt;
...@@ -4853,7 +5108,7 @@ try { ...@@ -4853,7 +5108,7 @@ try {
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup>
getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
...@@ -4905,7 +5160,7 @@ try { ...@@ -4905,7 +5160,7 @@ try {
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup>
getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt; getResultSet(query: Query): Promise&lt;KvStoreResultSet&gt;
...@@ -4969,7 +5224,7 @@ try { ...@@ -4969,7 +5224,7 @@ try {
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup>
getResultSet(deviceId: string, query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void getResultSet(deviceId: string, query: Query, callback: AsyncCallback&lt;KvStoreResultSet&gt;): void
...@@ -5021,7 +5276,7 @@ try { ...@@ -5021,7 +5276,7 @@ try {
``` ```
### getResultSet<sup>8+</sup> ### ### getResultSet<sup>8+</sup>
getResultSet(deviceId: string, query: Query): Promise&lt;KvStoreResultSet&gt; getResultSet(deviceId: string, query: Query): Promise&lt;KvStoreResultSet&gt;
...@@ -5087,7 +5342,7 @@ try { ...@@ -5087,7 +5342,7 @@ try {
``` ```
### closeResultSet<sup>8+</sup> ### ### closeResultSet<sup>8+</sup>
closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void closeResultSet(resultSet: KvStoreResultSet, callback: AsyncCallback&lt;void&gt;): void
...@@ -5122,7 +5377,7 @@ try { ...@@ -5122,7 +5377,7 @@ try {
``` ```
### closeResultSet<sup>8+</sup> ### ### closeResultSet<sup>8+</sup>
closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt; closeResultSet(resultSet: KvStoreResultSet): Promise&lt;void&gt;
...@@ -5160,7 +5415,7 @@ try { ...@@ -5160,7 +5415,7 @@ try {
``` ```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup>
getResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void getResultSize(query: Query, callback: AsyncCallback&lt;number&gt;): void
...@@ -5207,7 +5462,7 @@ try { ...@@ -5207,7 +5462,7 @@ try {
``` ```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup>
getResultSize(query: Query): Promise&lt;number&gt; getResultSize(query: Query): Promise&lt;number&gt;
...@@ -5263,7 +5518,7 @@ try { ...@@ -5263,7 +5518,7 @@ try {
``` ```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup>
getResultSize(deviceId: string, query: Query, callback: AsyncCallback&lt;number&gt;): void; getResultSize(deviceId: string, query: Query, callback: AsyncCallback&lt;number&gt;): void;
...@@ -5310,7 +5565,7 @@ try { ...@@ -5310,7 +5565,7 @@ try {
``` ```
### getResultSize<sup>8+</sup> ### ### getResultSize<sup>8+</sup>
getResultSize(deviceId: string, query: Query): Promise&lt;number&gt; getResultSize(deviceId: string, query: Query): Promise&lt;number&gt;
...@@ -5366,7 +5621,7 @@ try { ...@@ -5366,7 +5621,7 @@ try {
``` ```
### removeDeviceData<sup>8+</sup> ### ### removeDeviceData<sup>8+</sup>
removeDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void removeDeviceData(deviceId: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -5408,7 +5663,7 @@ try { ...@@ -5408,7 +5663,7 @@ try {
``` ```
### removeDeviceData<sup>8+</sup> ### ### removeDeviceData<sup>8+</sup>
removeDeviceData(deviceId: string): Promise&lt;void&gt; removeDeviceData(deviceId: string): Promise&lt;void&gt;
...@@ -5457,7 +5712,7 @@ try { ...@@ -5457,7 +5712,7 @@ try {
``` ```
### sync<sup>8+</sup> ### ### sync<sup>8+</sup>
sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void sync(deviceIds: string[], mode: SyncMode, delayMs?: number): void
...@@ -5496,7 +5751,7 @@ try { ...@@ -5496,7 +5751,7 @@ try {
} }
``` ```
### sync<sup>9+</sup> ### ### sync<sup>9+</sup>
sync(deviceIds: string[], query: Query, mode: SyncMode, delayMs?: number): void sync(deviceIds: string[], query: Query, mode: SyncMode, delayMs?: number): void
...@@ -5538,11 +5793,11 @@ try { ...@@ -5538,11 +5793,11 @@ try {
} }
``` ```
### on('syncComplete')<sup>8+</sup> ### ### on('syncComplete')<sup>8+</sup>
on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void on(event: 'syncComplete', syncCallback: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Subscribes to the data synchronization complete events. Subscribes to synchronization complete events.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -5550,8 +5805,8 @@ Subscribes to the data synchronization complete events. ...@@ -5550,8 +5805,8 @@ Subscribes to the data synchronization complete events.
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates the data synchronization complete event.| | event |string | Yes |Event to subscribe to. The value is **syncComplete**, which indicates a synchronization complete event.|
| syncCallback |Callback<Array&lt;[string, number]&gt;> | Yes |Callback used to return the synchronization result. | | syncCallback |Callback<Array&lt;[string, number]&gt;> | Yes |Callback invoked to return a synchronization complete event. |
**Example** **Example**
...@@ -5574,11 +5829,11 @@ try { ...@@ -5574,11 +5829,11 @@ try {
``` ```
### off('syncComplete')<sup>8+</sup> ### ### off('syncComplete')<sup>8+</sup>
off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&gt;&gt;): void
Unsubscribes from the synchronization complete events. This API returns the result synchronously. Unsubscribes from synchronization complete events. This API returns the result synchronously.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -5586,25 +5841,31 @@ Unsubscribes from the synchronization complete events. This API returns the resu ...@@ -5586,25 +5841,31 @@ Unsubscribes from the synchronization complete events. This API returns the resu
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates the data synchronization complete event.| | event |string | Yes |Event to unsubscribe from. The value is **syncComplete**, which indicates a synchronization complete event.|
| syncCallback |Callback<Array&lt;[string, number]&gt;&gt; | No |Callback used to return the synchronization result. | | syncCallback |Callback<Array&lt;[string, number]&gt;&gt; | No |Callback used to return a synchronization complete event. |
**Example** **Example**
```js ```js
let kvStore; let kvStore;
try { class KvstoreModel {
const func = function (data) { call(data) {
console.log('syncComplete ' + data) console.log("syncComplete: " + data);
}; }
kvStore.on('syncComplete', func); subscribeSyncComplete() {
kvStore.off('syncComplete', func); if (kvStore != null) {
}catch(e) { kvStore.on('syncComplete', this.call);
console.log('syncComplete e ' + e); }
}
unsubscribeSyncComplete() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
}
}
} }
``` ```
### on('dataChange')<sup>9+</sup> ### ### on('dataChange')<sup>9+</sup>
on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void on(event: 'dataChange', type: SubscribeType, listener: Callback&lt;ChangeNotification&gt;): void
...@@ -5616,9 +5877,9 @@ Subscribes to data changes of the specified type. This API returns the result sy ...@@ -5616,9 +5877,9 @@ Subscribes to data changes of the specified type. This API returns the result sy
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates data changes. | | event |string | Yes |Event to subscribe to. The value is **dataChange**, which indicates a data change event. |
| type |[SubscribeType](#subscribetype) | Yes |Subscription type. | | type |[SubscribeType](#subscribetype) | Yes |Type of data change. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback used to return the result.| | listener |Callback&lt;[ChangeNotification](#changenotification)&gt; | Yes |Callback invoked to return a data change event.|
**Example** **Example**
...@@ -5630,11 +5891,11 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun ...@@ -5630,11 +5891,11 @@ kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_LOCAL, fun
``` ```
### off('dataChange')<sup>9+</sup> ### ### off('dataChange')<sup>9+</sup>
off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
Unsubscribes from the data change events. This API returns the result synchronously. Unsubscribes from data changes. This API returns the result synchronously.
**System capability**: SystemCapability.DistributedDataManager.KVStore.Core **System capability**: SystemCapability.DistributedDataManager.KVStore.Core
...@@ -5642,19 +5903,28 @@ Unsubscribes from the data change events. This API returns the result synchronou ...@@ -5642,19 +5903,28 @@ Unsubscribes from the data change events. This API returns the result synchronou
| Name | Type| Mandatory | Description | | Name | Type| Mandatory | Description |
| ----- | ------ | ---- | ----------------------- | | ----- | ------ | ---- | ----------------------- |
| event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates data changes. | | event |string | Yes |Event to unsubscribe from. The value is **dataChange**, which indicates a data change event. |
| listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return the result.| | listener |Callback&lt;[ChangeNotification](#changenotification)&gt; |No |Callback used to return a data change event.|
**Example** **Example**
```js ```js
let kvStore; let kvStore;
kvStore.on('dataChange', function (data) { class KvstoreModel {
console.log("callback call data: " + data); call(data) {
}); console.log("dataChange: " + data);
kvStore.off('dataChange', function (data) { }
console.log("callback call data: " + data); subscribeDataChange() {
}); if (kvStore != null) {
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
}
}
unsubscribeDataChange() {
if (kvStore != null) {
kvStore.off('dataChange', this.call);
}
}
}
``` ```
## SyncMode ## SyncMode
...@@ -5668,4 +5938,3 @@ Enumerates the synchronization modes. ...@@ -5668,4 +5938,3 @@ Enumerates the synchronization modes.
| PULL_ONLY |0 |Pull data from the peer end to the local end only.| | PULL_ONLY |0 |Pull data from the peer end to the local end only.|
| PUSH_ONLY |1 |Push data from the local end to the peer end only.| | PUSH_ONLY |1 |Push data from the local end to the peer end only.|
| PUSH_PULL |2 |Push data from the local end to the peer end and then pull data from the peer end to the local end.| | PUSH_PULL |2 |Push data from the local end to the peer end and then pull data from the peer end to the local end.|
# Motion Recognition # Motion
## Overview ## Overview
...@@ -8,7 +8,7 @@ The motion recognition module provides motion recognition and control capabiliti ...@@ -8,7 +8,7 @@ The motion recognition module provides motion recognition and control capabiliti
The motion recognition driver is developed based on the hardware driver foundation (HDF). It shields hardware differences and provides APIs for the Multimodal Sensor Data Platform (MSDP) to implement capabilities such as enabling or disabling motion recognition, and subscribing to or unsubscribing from motion recognition data. The motion recognition driver is developed based on the hardware driver foundation (HDF). It shields hardware differences and provides APIs for the Multimodal Sensor Data Platform (MSDP) to implement capabilities such as enabling or disabling motion recognition, and subscribing to or unsubscribing from motion recognition data.
The figure below shows the motion recognition driver architecture. The framework layer provides MSDP services, and interacts with the Motion Hardware Device Interface (HDI) Server through the Motion HDI Client. The Motion HDI Server calls the Motion HDI Impl APIs to provide motion recognition capabilities for upper-layer services. The figure below shows the motion recognition driver architecture. The framework layer provides MSDP services, and interacts with the Motion Stub through the Motion Proxy in the User Hardware Driver Foundation (UHDF). The Motion Stub calls the Motion HDI Impl APIs to provide motion recognition capabilities for upper-layer services.
**Figure 1** Motion recognition driver architecture **Figure 1** Motion recognition driver architecture
...@@ -22,7 +22,7 @@ The figure below illustrates how a motion recognition driver works. ...@@ -22,7 +22,7 @@ The figure below illustrates how a motion recognition driver works.
![](figures/motion_recognition_driver_work.png) ![](figures/motion_recognition_driver_work.png)
1. MSDP: The MSDP service obtains a Motion HDI service instance from the Motion Proxy at the IDL and calls the Motion HDI API. 1. MSDP: The MSDP service obtains a Motion HDI service instance from the Motion Proxy and calls the Motion HDI API.
2. IDL: The IService Manager allocates a Motion HDI instance requested by the MSDP service, and the Motion Proxy forwards the instance to the MSDP service. After the MSDP service calls the HDI API provided by the Motion Proxy, Motion Stub is called through Inter-Process Communication (IPC) to invoke the Motion Service API. The code is automatically generated by a tool and does not need to be developed by the component vendor. 2. IDL: The IService Manager allocates a Motion HDI instance requested by the MSDP service, and the Motion Proxy forwards the instance to the MSDP service. After the MSDP service calls the HDI API provided by the Motion Proxy, Motion Stub is called through Inter-Process Communication (IPC) to invoke the Motion Service API. The code is automatically generated by a tool and does not need to be developed by the component vendor.
3. HDI Service: HDI Service consists of Motion Interface Driver, Motion Service, and Motion Impl. Motion Interface Driver provides the motion recognition driver code. A **HdfDriverEntry** structure is defined to implement the **Init**, **Bind**, and **Release** functions. The **HDF_INIT** macro is used to load the driver in the functions. Motion Service provides the motion recognition service interface class. The specific implementation is described in Motion Impl. The code of HDI Service must be developed by the component vendor. 3. HDI Service: HDI Service consists of Motion Interface Driver, Motion Service, and Motion Impl. Motion Interface Driver provides the motion recognition driver code. A **HdfDriverEntry** structure is defined to implement the **Init**, **Bind**, and **Release** functions. The **HDF_INIT** macro is used to load the driver in the functions. Motion Service provides the motion recognition service interface class. The specific implementation is described in Motion Impl. The code of HDI Service must be developed by the component vendor.
......
...@@ -55,15 +55,15 @@ ...@@ -55,15 +55,15 @@
| ----------- | ----------------------- | ------------------------------------------- | | ----------- | ----------------------- | ------------------------------------------- |
| Preferences | flush(): Promise\<void> | 将Preferences实例通过异步线程回写入文件中。 | | Preferences | flush(): Promise\<void> | 将Preferences实例通过异步线程回写入文件中。 |
### 订阅数据变 ### 订阅数据变
订阅数据变更者类,订阅的Key的值发生变更后,在执行flush方法后,会触发callback回调。 订阅数据变更,订阅的Key的值发生变更后,在执行flush方法后,会触发callback回调。
**表5** 首选项变化订阅接口 **表5** 首选项变化订阅接口
| 类名 | 接口名 | 描述 | | 类名 | 接口名 | 描述 |
| ----------- | ------------------------------------------------------------ | -------------- | | ----------- | ------------------------------------------------------------ | -------------- |
| Preferences | on(type: 'change', callback: Callback<{ key : string }>): void | 订阅数据变。 | | Preferences | on(type: 'change', callback: Callback<{ key : string }>): void | 订阅数据变。 |
| Preferences | off(type: 'change', callback: Callback<{ key : string }>): void | 注销订阅。 | | Preferences | off(type: 'change', callback: Callback<{ key : string }>): void | 注销订阅。 |
### 删除数据文件 ### 删除数据文件
...@@ -88,8 +88,30 @@ ...@@ -88,8 +88,30 @@
2. 获取Preferences实例。 2. 获取Preferences实例。
读取指定文件,将数据加载到Preferences实例,用于数据操作。 读取指定文件,将数据加载到Preferences实例,用于数据操作。
FA模型示例:
```js ```js
let promise = data_preferences.getPreferences(this.context, 'mystore'); // 获取context
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
let promise = data_preferences.getPreferences(context, 'mystore');
```
Stage模型示例:
```ts
// 获取context
import Ability from '@ohos.application.Ability'
var context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
let promise = data_preferences.getPreferences(context, 'mystore');
``` ```
3. 存入数据。 3. 存入数据。
...@@ -134,9 +156,9 @@ ...@@ -134,9 +156,9 @@
preferences.flush(); preferences.flush();
``` ```
6. 订阅数据变 6. 订阅数据变
应用订阅数据变需要指定observer作为回调方法。订阅的Key的值发生变更后,当执行flush方法时,observer被触发回调。 应用订阅数据变需要指定observer作为回调方法。订阅的Key的值发生变更后,当执行flush方法时,observer被触发回调。
```js ```js
var observer = function (key) { var observer = function (key) {
......
...@@ -12,7 +12,7 @@ HiTraceMeter为开发者提供系统性能打点接口。开发者通过在自 ...@@ -12,7 +12,7 @@ HiTraceMeter为开发者提供系统性能打点接口。开发者通过在自
| 接口名 | 返回值 | 描述 | | 接口名 | 返回值 | 描述 |
| ---------------------------------------------------------------------------- | --------- | ------------ | | ---------------------------------------------------------------------------- | --------- | ------------ |
| hiTraceMeter.startTrace(name: string, taskId: number, expectedTime?: number) | void | 标记一个预跟踪耗时任务的开始。如果有多个相同name的任务需要跟踪或者对同一个任务要跟踪多次,并且任务同时被执行,则每次调用startTrace的taskId不相同。如果具有相同name的任务是串行执行的,则taskId可以相同。 | | hiTraceMeter.startTrace(name: string, taskId: number) | void | 标记一个预跟踪耗时任务的开始。如果有多个相同name的任务需要跟踪或者对同一个任务要跟踪多次,并且任务同时被执行,则每次调用startTrace的taskId不相同。如果具有相同name的任务是串行执行的,则taskId可以相同。 |
| hiTraceMeter.finishTrace(name: string, taskId: number) | void | name和taskId必须与流程开始的hiTraceMeter.startTrace对应参数值保持一致。 | | hiTraceMeter.finishTrace(name: string, taskId: number) | void | name和taskId必须与流程开始的hiTraceMeter.startTrace对应参数值保持一致。 |
| hiTraceMeter.traceByValue(name: string, value: number) | void | 用来标记一个预跟踪的数值变量,该变量的数值会不断变化。| | hiTraceMeter.traceByValue(name: string, value: number) | void | 用来标记一个预跟踪的数值变量,该变量的数值会不断变化。|
...@@ -32,10 +32,6 @@ HiTraceMeter为开发者提供系统性能打点接口。开发者通过在自 ...@@ -32,10 +32,6 @@ HiTraceMeter为开发者提供系统性能打点接口。开发者通过在自
onInit() { onInit() {
this.title = this.$t('strings.world'); this.title = this.$t('strings.world');
// 从startTrace到finishTrace流程的耗时期望为5ms
hiTraceMeter.startTrace("business", 1);
hiTraceMeter.startTrace("business", 1, 5);
// 跟踪并行执行的同名任务 // 跟踪并行执行的同名任务
hiTraceMeter.startTrace("business", 1); hiTraceMeter.startTrace("business", 1);
// 业务流程 // 业务流程
......
# 数据管理开发常见问题 # 数据管理开发常见问题
## 如何将PixelMap的数据存储到数据库中。 ## 如何将PixelMap的数据存储到数据库中。
适用于:OpenHarmony SDK 3.2.3.5版本 适用于:OpenHarmony SDK 3.2.3.5版本
PixelMap应该被转换成相应的ArrayBuffer再放进数据库。 PixelMap应该被转换成相应的ArrayBuffer再放进数据库。
参考文档:[readPixelsToBuffer](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-image.md#readpixelstobuffer7-1) 参考文档:[readPixelsToBuffer](../reference/apis/js-apis-image.md#readpixelstobuffer7-1)
## 如何获取rdb关系型数据库文件 ## 如何获取rdb关系型数据库文件
...@@ -18,7 +16,6 @@ PixelMap应该被转换成相应的ArrayBuffer再放进数据库。 ...@@ -18,7 +16,6 @@ PixelMap应该被转换成相应的ArrayBuffer再放进数据库。
示例: 示例:
```shell
```
hdc_std file recv /data/app/el2/100/database/com.xxxx.xxxx/entry/db/test.db ./test.db hdc_std file recv /data/app/el2/100/database/com.xxxx.xxxx/entry/db/test.db ./test.db
``` ```
...@@ -52,7 +52,7 @@ await cameraManager.getCameras((err, cameras) => { ...@@ -52,7 +52,7 @@ await cameraManager.getCameras((err, cameras) => {
cameraArray = cameras cameraArray = cameras
}) })
for(let cameraIndex = 0; cameraIndex < cameraArray.length; cameraIndex) { for(let cameraIndex = 0; cameraIndex < cameraArray.length; cameraIndex++) {
console.log('cameraId : ' + cameraArray[cameraIndex].cameraId) //获取相机ID console.log('cameraId : ' + cameraArray[cameraIndex].cameraId) //获取相机ID
console.log('cameraPosition : ' + cameraArray[cameraIndex].cameraPosition) //获取相机位置 console.log('cameraPosition : ' + cameraArray[cameraIndex].cameraPosition) //获取相机位置
console.log('cameraType : ' + cameraArray[cameraIndex].cameraType) //获取相机类型 console.log('cameraType : ' + cameraArray[cameraIndex].cameraType) //获取相机类型
......
...@@ -90,7 +90,7 @@ export default storage; ...@@ -90,7 +90,7 @@ export default storage;
/*********************************************** /***********************************************
* Module export and register * Module export and register
***********************************************/ ***********************************************/
static napi_value StorgeExport(napi_env env, napi_value exports) static napi_value StorageExport(napi_env env, napi_value exports)
{ {
napi_property_descriptor desc[] = { napi_property_descriptor desc[] = {
DECLARE_NAPI_FUNCTION("get", JSStorageGet), DECLARE_NAPI_FUNCTION("get", JSStorageGet),
...@@ -111,7 +111,7 @@ static napi_value StorgeExport(napi_env env, napi_value exports) ...@@ -111,7 +111,7 @@ static napi_value StorgeExport(napi_env env, napi_value exports)
static napi_module storage_module = {.nm_version = 1, static napi_module storage_module = {.nm_version = 1,
.nm_flags = 0, .nm_flags = 0,
.nm_filename = nullptr, .nm_filename = nullptr,
.nm_register_func = StorgeExport, .nm_register_func = StorageExport,
.nm_modname = "storage", .nm_modname = "storage",
.nm_priv = ((void*)0), .nm_priv = ((void*)0),
.reserved = {0}}; .reserved = {0}};
......
...@@ -3953,7 +3953,7 @@ var audioStreamInfo = { ...@@ -3953,7 +3953,7 @@ var audioStreamInfo = {
var audioRendererInfo = { var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH, content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 0 rendererFlags: 0
} }
...@@ -3973,7 +3973,7 @@ audioRenderer.getBufferSize().then((data)=> { ...@@ -3973,7 +3973,7 @@ audioRenderer.getBufferSize().then((data)=> {
console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`); console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
bufferSize = data; bufferSize = data;
}).catch((err) => { }).catch((err) => {
console.error.(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`); console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
}); });
console.info(`Buffer size: ${bufferSize}`); console.info(`Buffer size: ${bufferSize}`);
var context = featureAbility.getContext(); var context = featureAbility.getContext();
......
...@@ -174,6 +174,7 @@ CommonEvent模块支持的事件类型。名称指的是系统公共事件宏; ...@@ -174,6 +174,7 @@ CommonEvent模块支持的事件类型。名称指的是系统公共事件宏;
| COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | ohos.permission.RECEIVER_SPLIT_SCREEN | 表示分屏的公共事件的动作。 | | COMMON_EVENT_SPLIT_SCREEN<sup>8+<sup> | usual.event.SPLIT_SCREEN | ohos.permission.RECEIVER_SPLIT_SCREEN | 表示分屏的公共事件的动作。 |
| COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | 表示通知通道更新的动作。 | | COMMON_EVENT_SLOT_CHANGE<sup>9+<sup> | usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | 表示通知通道更新的动作。 |
| COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | 无 | 表示spn显示信息已更新的公共事件的动作。 | | COMMON_EVENT_SPN_INFO_CHANGED <sup>9+<sup> | usual.event.SPN_INFO_CHANGED | 无 | 表示spn显示信息已更新的公共事件的动作。 |
| COMMON_EVENT_QUICK_FIX_APPLY_RESULT <sup>9+<sup> | usual.event.QUICK_FIX_APPLY_RESULT | 无 | 指示快速修复应用的动作。 |
## CommonEvent.publish ## CommonEvent.publish
......
...@@ -38,15 +38,21 @@ getPreferences(context: Context, name: string, callback: AsyncCallback&lt;Prefer ...@@ -38,15 +38,21 @@ getPreferences(context: Context, name: string, callback: AsyncCallback&lt;Prefer
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| context | [Context](js-apis-ability-context.md) | 是 | 应用上下文。 | | context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-Context.md)<br>Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 |
| name | string | 是 | Preferences实例的名称。 | | name | string | 是 | Preferences实例的名称。 |
| callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | 是 | 回调函数。当获取Preferences实例成功,err为undefined,返回Preferences实例;否则err为错误码。 | | callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | 是 | 回调函数。当获取Preferences实例成功,err为undefined,返回Preferences实例;否则err为错误码。 |
**示例:** **示例:**
FA模型示例:
```js ```js
// 获取context
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
var preferences = null; var preferences = null;
data_preferences.getPreferences(this.context, 'mystore', function (err, object) { data_preferences.getPreferences(context, 'mystore', function (err, object) {
if (err) { if (err) {
console.info("Failed to get preferences. Cause: " + err); console.info("Failed to get preferences. Cause: " + err);
return; return;
...@@ -56,6 +62,28 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, object) ...@@ -56,6 +62,28 @@ data_preferences.getPreferences(this.context, 'mystore', function (err, object)
}) })
``` ```
Stage模型示例:
```ts
// 获取context
import Ability from '@ohos.application.Ability'
var context;
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
var preferences = null;
data_preferences.getPreferences(context, 'mystore', function (err, object) {
if (err) {
console.info("Failed to get preferences. Cause: " + err);
return;
}
preferences = object;
console.info("Succeeded in getting preferences.");
})
```
## data_preferences.getPreferences ## data_preferences.getPreferences
...@@ -69,7 +97,7 @@ getPreferences(context: Context, name: string): Promise&lt;Preferences&gt; ...@@ -69,7 +97,7 @@ getPreferences(context: Context, name: string): Promise&lt;Preferences&gt;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------- | ---- | ----------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | [Context](js-apis-ability-context.md) | 是 | 应用上下文。 | | context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-Context.md)<br>Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 |
| name | string | 是 | Preferences实例的名称。 | | name | string | 是 | Preferences实例的名称。 |
**返回值:** **返回值:**
...@@ -80,9 +108,15 @@ getPreferences(context: Context, name: string): Promise&lt;Preferences&gt; ...@@ -80,9 +108,15 @@ getPreferences(context: Context, name: string): Promise&lt;Preferences&gt;
**示例:** **示例:**
FA模型示例:
```js ```js
// 获取context
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
var preferences = null; var preferences = null;
let promise = data_preferences.getPreferences(this.context, 'mystore') let promise = data_preferences.getPreferences(context, 'mystore')
promise.then((object) => { promise.then((object) => {
preferences = object; preferences = object;
console.info("Succeeded in getting preferences."); console.info("Succeeded in getting preferences.");
...@@ -91,6 +125,27 @@ promise.then((object) => { ...@@ -91,6 +125,27 @@ promise.then((object) => {
}) })
``` ```
Stage模型示例:
```ts
// 获取context
import Ability from '@ohos.application.Ability'
var context;
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
var preferences = null;
let promise = data_preferences.getPreferences(context, 'mystore')
promise.then((object) => {
preferences = object;
console.info("Succeeded in getting preferences.");
}).catch((err) => {
console.info("Failed to get preferences. Cause: " + err);
})
```
## data_preferences.deletePreferences ## data_preferences.deletePreferences
...@@ -108,14 +163,20 @@ deletePreferences(context: Context, name: string, callback: AsyncCallback&lt;voi ...@@ -108,14 +163,20 @@ deletePreferences(context: Context, name: string, callback: AsyncCallback&lt;voi
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- | | -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
| context | [Context](js-apis-ability-context.md) | 是 | 应用上下文。 | | context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-Context.md)<br>Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 |
| name | string | 是 | Preferences实例的名称。 | | name | string | 是 | Preferences实例的名称。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当移除成功,err为undefined,否则为错误码。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当移除成功,err为undefined,否则为错误码。 |
**示例:** **示例:**
FA模型示例:
```js ```js
data_preferences.deletePreferences(this.context, 'mystore', function (err) { // 获取context
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
data_preferences.deletePreferences(context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to delete preferences. Cause: " + err); console.info("Failed to delete preferences. Cause: " + err);
return return
...@@ -124,6 +185,26 @@ data_preferences.deletePreferences(this.context, 'mystore', function (err) { ...@@ -124,6 +185,26 @@ data_preferences.deletePreferences(this.context, 'mystore', function (err) {
}) })
``` ```
Stage模型示例:
```ts
// 获取context
import Ability from '@ohos.application.Ability'
var context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
data_preferences.deletePreferences(context, 'mystore', function (err) {
if (err) {
console.info("Failed to delete preferences. Cause: " + err);
return
}
console.info("Succeeded in deleting preferences." );
})
```
## data_preferences.deletePreferences ## data_preferences.deletePreferences
...@@ -141,7 +222,7 @@ deletePreferences(context: Context, name: string): Promise&lt;void&gt; ...@@ -141,7 +222,7 @@ deletePreferences(context: Context, name: string): Promise&lt;void&gt;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------- | ---- | ----------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | [Context](js-apis-ability-context.md) | 是 | 应用上下文。 | | context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-Context.md)<br>Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 |
| name | string | 是 | Preferences实例的名称。 | | name | string | 是 | Preferences实例的名称。 |
**返回值:** **返回值:**
...@@ -152,8 +233,14 @@ deletePreferences(context: Context, name: string): Promise&lt;void&gt; ...@@ -152,8 +233,14 @@ deletePreferences(context: Context, name: string): Promise&lt;void&gt;
**示例:** **示例:**
FA模型示例:
```js ```js
let promise = data_preferences.deletePreferences(this.context, 'mystore') // 获取context
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
let promise = data_preferences.deletePreferences(context, 'mystore')
promise.then(() => { promise.then(() => {
console.info("Succeeded in deleting preferences."); console.info("Succeeded in deleting preferences.");
}).catch((err) => { }).catch((err) => {
...@@ -161,6 +248,25 @@ promise.then(() => { ...@@ -161,6 +248,25 @@ promise.then(() => {
}) })
``` ```
Stage模型示例:
```ts
// 获取context
import Ability from '@ohos.application.Ability'
var context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
let promise = data_preferences.deletePreferences(context, 'mystore')
promise.then(() => {
console.info("Succeeded in deleting preferences.");
}).catch((err) => {
console.info("Failed to delete preferences. Cause: " + err);
})
```
## data_preferences.removePreferencesFromCache ## data_preferences.removePreferencesFromCache
...@@ -176,14 +282,20 @@ removePreferencesFromCache(context: Context, name: string, callback: AsyncCallba ...@@ -176,14 +282,20 @@ removePreferencesFromCache(context: Context, name: string, callback: AsyncCallba
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- | | -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
| context | [Context](js-apis-ability-context.md) | 是 | 应用上下文。 | | context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-Context.md)<br>Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 |
| name | string | 是 | Preferences实例的名称。 | | name | string | 是 | Preferences实例的名称。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当移除成功,err为undefined,否则为错误码。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当移除成功,err为undefined,否则为错误码。 |
**示例:** **示例:**
FA模型示例:
```js ```js
data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err) { // 获取context
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
data_preferences.removePreferencesFromCache(context, 'mystore', function (err) {
if (err) { if (err) {
console.info("Failed to remove preferences. Cause: " + err); console.info("Failed to remove preferences. Cause: " + err);
return; return;
...@@ -192,6 +304,26 @@ data_preferences.removePreferencesFromCache(this.context, 'mystore', function (e ...@@ -192,6 +304,26 @@ data_preferences.removePreferencesFromCache(this.context, 'mystore', function (e
}) })
``` ```
Stage模型示例:
```ts
// 获取context
import Ability from '@ohos.application.Ability'
var context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
data_preferences.removePreferencesFromCache(context, 'mystore', function (err) {
if (err) {
console.info("Failed to remove preferences. Cause: " + err);
return;
}
console.info("Succeeded in removing preferences.");
})
```
## data_preferences.removePreferencesFromCache ## data_preferences.removePreferencesFromCache
...@@ -207,7 +339,7 @@ removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt; ...@@ -207,7 +339,7 @@ removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt;
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------- | ---- | ----------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | [Context](js-apis-ability-context.md) | 是 | 应用上下文。 | | context | Context | 是 | 应用上下文。<br>FA模型的应用Context定义见[Context](js-apis-Context.md)<br>Stage模型的应用Context定义见[Context](js-apis-ability-context.md)。 |
| name | string | 是 | Preferences实例的名称。 | | name | string | 是 | Preferences实例的名称。 |
**返回值:** **返回值:**
...@@ -218,8 +350,14 @@ removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt; ...@@ -218,8 +350,14 @@ removePreferencesFromCache(context: Context, name: string): Promise&lt;void&gt;
**示例:** **示例:**
FA模型示例:
```js ```js
let promise = data_preferences.removePreferencesFromCache(this.context, 'mystore') // 获取context
import featureAbility from '@ohos.ability.featureAbility'
var context = featureAbility.getContext()
let promise = data_preferences.removePreferencesFromCache(context, 'mystore')
promise.then(() => { promise.then(() => {
console.info("Succeeded in removing preferences."); console.info("Succeeded in removing preferences.");
}).catch((err) => { }).catch((err) => {
...@@ -227,6 +365,25 @@ promise.then(() => { ...@@ -227,6 +365,25 @@ promise.then(() => {
}) })
``` ```
Stage模型示例:
```ts
// 获取context
import Ability from '@ohos.application.Ability'
var context
class MainAbility extends Ability{
onWindowStageCreate(windowStage){
context = this.context
}
}
let promise = data_preferences.removePreferencesFromCache(context, 'mystore')
promise.then(() => {
console.info("Succeeded in removing preferences.");
}).catch((err) => {
console.info("Failed to remove preferences. Cause: " + err);
})
```
## Preferences ## Preferences
......
...@@ -32,7 +32,7 @@ import hiAppEvent from '@ohos.hiAppEvent'; ...@@ -32,7 +32,7 @@ import hiAppEvent from '@ohos.hiAppEvent';
事件参数为object类型,key为事件的参数名称,value为事件的参数值,其规格定义如下: 事件参数为object类型,key为事件的参数名称,value为事件的参数值,其规格定义如下:
- 参数名为string类型,字符串非空且长度在16个字符以内,有效的字符是0-9、a-z、下划线,不能以下划线开头或结尾 - 参数名为string类型,字符串非空且长度在16个字符以内,有效的字符是0-9、a-z、下划线,不能以下划线开头或结尾
- 参数值支持string、number、boolean、Array类型; - 参数值支持string、number、boolean、Array类型;
- 参数值为string类型时,其长度需在8*1024个字符以内,超出会做截断处理; - 参数值为string类型时,其长度需在8*1024个字符以内,超出会做截断处理;
- 参数值为Array类型时,Array中的元素类型只能全为string、number、boolean中的一种,且元素个数需在100以内,超出会做丢弃处理; - 参数值为Array类型时,Array中的元素类型只能全为string、number、boolean中的一种,且元素个数需在100以内,超出会做丢弃处理;
...@@ -304,11 +304,8 @@ hiAppEvent.addWatcher({ ...@@ -304,11 +304,8 @@ hiAppEvent.addWatcher({
console.error("holder is null"); console.error("holder is null");
return; return;
} }
while (true) { let eventPkg = null;
let eventPkg = holder.takeNext(); while ((eventPkg = holder.takeNext()) != null) {
if (eventPkg == null) {
return;
}
console.info("eventPkg.packageId=" + eventPkg.packageId); console.info("eventPkg.packageId=" + eventPkg.packageId);
console.info("eventPkg.row=" + eventPkg.row); console.info("eventPkg.row=" + eventPkg.row);
console.info("eventPkg.size=" + eventPkg.size); console.info("eventPkg.size=" + eventPkg.size);
...@@ -324,16 +321,15 @@ let holder = hiAppEvent.addWatcher({ ...@@ -324,16 +321,15 @@ let holder = hiAppEvent.addWatcher({
name: "watcher2", name: "watcher2",
}); });
if (holder != null) { if (holder != null) {
let eventPkg = holder.takeNext(); let eventPkg = null;
if (eventPkg == null) { while ((eventPkg = holder.takeNext()) != null) {
return;
}
console.info("eventPkg.packageId=" + eventPkg.packageId); console.info("eventPkg.packageId=" + eventPkg.packageId);
console.info("eventPkg.row=" + eventPkg.row); console.info("eventPkg.row=" + eventPkg.row);
console.info("eventPkg.size=" + eventPkg.size); console.info("eventPkg.size=" + eventPkg.size);
for (const eventInfo of eventPkg.data) { for (const eventInfo of eventPkg.data) {
console.info("eventPkg.data=" + eventInfo); console.info("eventPkg.data=" + eventInfo);
} }
}
} }
``` ```
...@@ -417,6 +413,9 @@ setSize(size: number): void ...@@ -417,6 +413,9 @@ setSize(size: number): void
**示例:** **示例:**
```js ```js
let holder = hiAppEvent.addWatcher({
name: "watcher",
});
holder.setSize(1000); holder.setSize(1000);
``` ```
...@@ -429,6 +428,9 @@ takeNext(): [AppEventPackage](#appeventpackage9) ...@@ -429,6 +428,9 @@ takeNext(): [AppEventPackage](#appeventpackage9)
**示例:** **示例:**
```js ```js
let holder = hiAppEvent.addWatcher({
name: "watcher",
});
let eventPkg = holder.takeNext(); let eventPkg = holder.takeNext();
``` ```
......
...@@ -71,7 +71,7 @@ import hiTraceChain from '@ohos.hiTraceChain'; ...@@ -71,7 +71,7 @@ import hiTraceChain from '@ohos.hiTraceChain';
## hiTraceChain.begin ## hiTraceChain.begin
begin(name: string, flags: number = HiTraceFlag.DEFAULT): HiTraceId begin(name: string, flags?: number): HiTraceId
开始跟踪,同步接口。 开始跟踪,同步接口。
...@@ -82,7 +82,7 @@ begin(name: string, flags: number = HiTraceFlag.DEFAULT): HiTraceId ...@@ -82,7 +82,7 @@ begin(name: string, flags: number = HiTraceFlag.DEFAULT): HiTraceId
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| name | string | 是 | 跟踪业务名。 | | name | string | 是 | 跟踪业务名。 |
| flags | number | | 跟踪标志组合,具体可参考[HiTraceFlag](#hitraceflag)。 | | flags | number | | 跟踪标志组合,具体可参考[HiTraceFlag](#hitraceflag)。 |
**返回值:** **返回值:**
...@@ -113,7 +113,7 @@ end(id: HiTraceId): void ...@@ -113,7 +113,7 @@ end(id: HiTraceId): void
**示例:** **示例:**
```js ```js
let asyncTraceId = hiTraceChain.begin("business"); let asyncTraceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.DEFAULT);
// 若干业务逻辑完成后,结束跟踪。 // 若干业务逻辑完成后,结束跟踪。
hiTraceChain.end(asyncTraceId); hiTraceChain.end(asyncTraceId);
``` ```
...@@ -135,7 +135,7 @@ getId(): HiTraceId ...@@ -135,7 +135,7 @@ getId(): HiTraceId
**示例:** **示例:**
```js ```js
let traceId = hiTraceChain.begin("business"); let traceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.DEFAULT);
// 若干业务逻辑完成后,获取当前HiTraceId。 // 若干业务逻辑完成后,获取当前HiTraceId。
let curTraceId = hiTraceChain.getId(); let curTraceId = hiTraceChain.getId();
``` ```
...@@ -158,7 +158,7 @@ setId(id: HiTraceId): void ...@@ -158,7 +158,7 @@ setId(id: HiTraceId): void
```js ```js
let asyncTraceId; let asyncTraceId;
let traceId = hiTraceChain.begin("business"); let traceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.DEFAULT);
// 若干业务逻辑完成后,设置当前HiTraceId。 // 若干业务逻辑完成后,设置当前HiTraceId。
hiTraceChain.setId(asyncTraceId); hiTraceChain.setId(asyncTraceId);
``` ```
...@@ -174,7 +174,7 @@ clearId(): void ...@@ -174,7 +174,7 @@ clearId(): void
**示例:** **示例:**
```js ```js
let traceId = hiTraceChain.begin("business"); let traceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.DEFAULT);
// 若干业务逻辑完成后,清除当前HiTraceId。 // 若干业务逻辑完成后,清除当前HiTraceId。
hiTraceChain.clearId(); hiTraceChain.clearId();
``` ```
...@@ -196,7 +196,7 @@ createSpan(): HiTraceId ...@@ -196,7 +196,7 @@ createSpan(): HiTraceId
**示例:** **示例:**
```js ```js
let traceId = hiTraceChain.begin("business"); let traceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.DEFAULT);
// 若干业务逻辑完成后,创建跟踪分支。 // 若干业务逻辑完成后,创建跟踪分支。
let spanTraceId = hiTraceChain.createSpan(); let spanTraceId = hiTraceChain.createSpan();
``` ```
...@@ -249,7 +249,7 @@ isValid(id: HiTraceId): boolean ...@@ -249,7 +249,7 @@ isValid(id: HiTraceId): boolean
**示例:** **示例:**
```js ```js
let traceId = hiTraceChain.begin("business"); let traceId = hiTraceChain.begin("business", hiTraceChain.HiTraceFlag.DEFAULT);
let traceIdIsvalid = hiTraceChain.isValid(traceId); let traceIdIsvalid = hiTraceChain.isValid(traceId);
``` ```
......
...@@ -591,7 +591,7 @@ audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 ...@@ -591,7 +591,7 @@ audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调
on(type: 'timeUpdate', callback: Callback\<number>): void on(type: 'timeUpdate', callback: Callback\<number>): void
开始订阅音频播放[seek()](#seek)时间更新事件。 开始订阅音频播放时间更新事件。
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **系统能力:** SystemCapability.Multimedia.Media.AudioPlayer
...@@ -599,20 +599,20 @@ on(type: 'timeUpdate', callback: Callback\<number>): void ...@@ -599,20 +599,20 @@ on(type: 'timeUpdate', callback: Callback\<number>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------- | ---- | ------------------------------------------------------------ | | -------- | ----------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 播放事件回调类型,支持的事件包括:'timeUpdate'。<br>- 'timeUpdate':[seek()](#audioplayer_seek)调用完成,触发该事件。 | | type | string | 是 | 播放事件回调类型,支持的事件包括:'timeUpdate'。<br>- 'timeUpdate':音频播放时间戳更新,开始播放后自动触发该事件。 |
| callback | Callback\<number> | 是 | 播放事件回调方法。回调方法入参为成功seek的时间。 | | callback | Callback\<number> | 是 | 播放事件回调方法。回调方法入参为更新后的时间戳。 |
**示例:** **示例:**
```js ```js
audioPlayer.on('timeUpdate', (seekDoneTime) => { //设置'timeUpdate'事件回调 audioPlayer.on('timeUpdate', (newTime) => { //设置'timeUpdate'事件回调
if (seekDoneTime == null) { if (newTime == null) {
console.info('audio seek fail'); console.info('audio timeUpadate fail');
return; return;
} }
console.log('audio seek success. seekDoneTime: ' + seekDoneTime); console.log('audio timeUpadate success. seekDoneTime: ' + newTime);
}); });
audioPlayer.seek(30000); //seek到30000ms的位置 audioPlayer.play(); //开始播放后,自动触发时间戳更新事件
``` ```
### on('error') ### on('error')
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
> >
> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口仅可在Stage模型下使用。 > - 本模块接口仅可在Stage模型下使用。
> - 延迟任务调度约束见[延迟任务调度概述](../../task-management/work-scheduler-overview.md)。
## 导入模块 ## 导入模块
......
# Slider # Slider
> **说明:**
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
滑动条组件,用来快速调节设置值,如音量、亮度等。 滑动条组件,用来快速调节设置值,如音量、亮度等。
> **说明:**
## 权限列表 >
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 子组件 ## 子组件
...@@ -19,38 +14,40 @@ ...@@ -19,38 +14,40 @@
## 接口 ## 接口
Slider(options:{value?: number, min?: number, max?: number, step?: number, style?: SliderStyle, direction?: Axis, reverse?: boolean}) Slider(options?: {value?: number, min?: number, max?: number, step?: number, style?: SliderStyle, direction?: Axis, reverse?: boolean})
**参数:**
- 参数 | 参数名 | 参数类型 | 必填 | 参数描述 |
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- | -------- | | value | number | 否 | 当前进度值。<br/>默认值:0 |
| value | number | 否 | 0 | 当前进度值。 | | min | number | 否 | 设置最小值。<br/>默认值:0 |
| min | number | 否 | 0 | 设置最小值。 | | max | number | 否 | 设置最大值。<br/>默认值:100 |
| max | number | 否 | 100 | 设置最大值。 | | step | number | 否 | 设置Slider滑动跳动值,当设置相应的step时,Slider为间歇滑动。<br/>默认值:1 |
| step | number | 否 | 1 | 设置Slider滑动跳动值,当设置相应的step时,Slider为间歇滑动。 | | style | SliderStyle | 否 | 设置Slider的滑块样式。<br/>默认值:SliderStyle.OutSet |
| style | SliderStyle | 否 | SliderStyle.OutSet | 设置Slider的滑块样式。 | | direction<sup>8+</sup> | [Axis](ts-appendix-enums.md#axis) | 否 | 设置滑动条滑动方向为水平或竖直方向。<br/>默认值:Axis.Horizontal |
| direction<sup>8+</sup> | [Axis](ts-appendix-enums.md#axis) | 否 | Axis.Horizontal | 设置滑动条滑动方向为水平或竖直方向。 | | reverse<sup>8+</sup> | boolean | 否 | 设置滑动条取值范围是否反向。<br/>默认值:false |
| reverse<sup>8+</sup> | boolean | 否 | false | 设置滑动条取值范围是否反向。 |
- SliderStyle枚举说明 ## SliderStyle枚举说明
| 名称 | 描述 |
| -------- | -------- | | 名称 | 描述 |
| OutSet | 滑块在滑轨上。 | | -------- | -------- |
| InSet | 滑块在滑轨内。 | | OutSet | 滑块在滑轨上。 |
| InSet | 滑块在滑轨内。 |
## 属性 ## 属性
不支持触摸热区设置。 不支持触摸热区设置。
| 名称 | 参数类型 | 默认值 | 描述 | | 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- |
| blockColor | [ResourceColor](../../ui/ts-types.md#resourcecolor8) | - | 设置滑块的颜色。 | | blockColor | [ResourceColor](../../ui/ts-types.md#resourcecolor8) | 设置滑块的颜色。 |
| trackColor | [ResourceColor](../../ui/ts-types.md#resourcecolor8) | - | 设置滑轨的背景颜色。 | | trackColor | [ResourceColor](../../ui/ts-types.md#resourcecolor8) | 设置滑轨的背景颜色。 |
| selectedColor | [ResourceColor](../../ui/ts-types.md#resourcecolor8) | - | 设置滑轨的已滑动颜色。 | | selectedColor | [ResourceColor](../../ui/ts-types.md#resourcecolor8) | 设置滑轨的已滑动颜色。 |
| showSteps | boolean | false | 设置当前是否显示步长刻度值。 | | showSteps | boolean | 设置当前是否显示步长刻度值。<br/>默认值:false |
| showTips | boolean | false | 设置滑动时是否显示气泡提示百分比。 | | showTips | boolean | 设置滑动时是否显示气泡提示百分比。<br/>默认值:false |
| trackThickness | [Length](../../ui/ts-types.md#length) | - | 设置滑轨的粗细。 | | trackThickness | [Length](../../ui/ts-types.md#length) | 设置滑轨的粗细。 |
## 事件 ## 事件
...@@ -61,13 +58,14 @@ Slider(options:{value?: number, min?: number, max?: number, step?: number, style ...@@ -61,13 +58,14 @@ Slider(options:{value?: number, min?: number, max?: number, step?: number, style
| -------- | -------- | | -------- | -------- |
| onChange(callback:&nbsp;(value:&nbsp;number,&nbsp;mode:&nbsp;SliderChangeMode)&nbsp;=&gt;&nbsp;void) | Slider滑动时触发事件回调。<br/>value:当前进度值。<br/>mode:拖动状态。 | | onChange(callback:&nbsp;(value:&nbsp;number,&nbsp;mode:&nbsp;SliderChangeMode)&nbsp;=&gt;&nbsp;void) | Slider滑动时触发事件回调。<br/>value:当前进度值。<br/>mode:拖动状态。 |
- SliderChangeMode枚举说明 ## SliderChangeMode枚举说明
| 名称 | 值 | 描述 |
| -------- | -------- | -------- | | 名称 | 值 | 描述 |
| Begin | 0 | 用户开始拖动滑块。 | | -------- | -------- | -------- |
| Moving | 1 | 用户拖动滑块中。 | | Begin | 0 | 用户开始拖动滑块。 |
| End | 2 | 用户结束拖动滑块。 | | Moving | 1 | 用户拖动滑块中。 |
| Click | 3 | 用户点击滑动条使滑块位置移动。 | | End | 2 | 用户结束拖动滑块。 |
| Click | 3 | 用户点击滑动条使滑块位置移动。 |
## 示例 ## 示例
......
...@@ -3,14 +3,10 @@ ...@@ -3,14 +3,10 @@
作为Text组件的子组件,用于显示行内文本的组件。 作为Text组件的子组件,用于显示行内文本的组件。
> **说明:** > **说明:**
>
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 子组件 ## 子组件
...@@ -18,23 +14,24 @@ ...@@ -18,23 +14,24 @@
## 接口 ## 接口
Span(content: ResourceStr) Span(content: string | Resource)
- 参数 **参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | -------- | -------- | -------- | | 参数名 | 参数类型 | 必填 | 参数描述 |
| content | [ResourceStr](../../ui/ts-types.md#resourcestr8) | 是 | - | 文本内容。 | | -------- | -------- | -------- | -------- |
| content | string \| [Resource](../../ui/ts-types.md#resource) | 是 | 文本内容。 |
## 属性 ## 属性
通用属性方法仅支持通用文本样式,不支持触摸热区设置。 通用属性方法仅支持通用文本样式,不支持触摸热区设置。
| 名称 | 参数类型 | 默认值 | 描述 | | 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- |
| decoration | {<br/>type:&nbsp;[TextDecorationType](ts-appendix-enums.md#textdecorationtype),<br/>color?:&nbsp;[ResourceColor](../../ui/ts-types.md#resourcecolor8)<br/>} | {<br/>type:&nbsp;TextDecorationType.None<br/>color:Color.Black<br/>} | 设置文本装饰线样式及其颜色。 | | decoration | {<br/>type:&nbsp;[TextDecorationType](ts-appendix-enums.md#textdecorationtype),<br/>color?:&nbsp;[ResourceColor](../../ui/ts-types.md#resourcecolor8)<br/>} | 设置文本装饰线样式及其颜色。<br/>默认值:{<br/>type:&nbsp;TextDecorationType.None<br/>color:Color.Black<br/>} |
| letterSpacing | [Length](../../ui/ts-types.md#length) | - | 设置文本字符间距。 | | letterSpacing | number \| string | 设置文本字符间距。 |
| textCase | [TextCase](ts-appendix-enums.md#textcase) | Normal | 设置文本大小写。 | | textCase | [TextCase](ts-appendix-enums.md#textcase) | 设置文本大小写。<br/>默认值:TextCase.Normal |
## 事件 ## 事件
...@@ -42,6 +39,7 @@ Span(content: ResourceStr) ...@@ -42,6 +39,7 @@ Span(content: ResourceStr)
通用事件仅支持点击事件。 通用事件仅支持点击事件。
> **说明:** > **说明:**
>
> 由于Span组件无尺寸信息,因此点击事件返回的ClickEvent对象的target属性无效。 > 由于Span组件无尺寸信息,因此点击事件返回的ClickEvent对象的target属性无效。
......
...@@ -3,14 +3,10 @@ ...@@ -3,14 +3,10 @@
显示一段文本的组件。 显示一段文本的组件。
> **说明:** > **说明:**
>
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 子组件 ## 子组件
可以包含[Span](ts-basic-components-span.md)子组件。 可以包含[Span](ts-basic-components-span.md)子组件。
...@@ -18,33 +14,34 @@ ...@@ -18,33 +14,34 @@
## 接口 ## 接口
Text(content?: ResourceStr) Text(content?: string | Resource)
- 参数 **参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | -------- | -------- | -------- |
| content | [ResourceStr](../../ui/ts-types.md#resourcestr8) | 否 | '' | 文本内容。包含子组件Span时不生效,显示Span内容,并且此时text组件的样式不生效。 |
| 参数名 | 参数类型 | 必填 | 参数描述 |
| -------- | -------- | -------- | -------- |
| content | string \| [Resource](../../ui/ts-types.md#resource) | 否 | 文本内容。包含子组件Span时不生效,显示Span内容,并且此时text组件的样式不生效。<br/>默认值:' ' |
## 属性 ## 属性
Text组件除以下属性外同时包含[文本样式设置](ts-universal-attributes-text-style.md)的属性。 除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
| 名称 | 参数类型 | 默认值 | 描述 | | 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- |
| textAlign | [TextAlign](ts-appendix-enums.md#textalign) | TextAlign.Start | 设置多行文本的文本对齐方式。 | | textAlign | [TextAlign](ts-appendix-enums.md#textalign) | 设置多行文本的文本对齐方式。<br/>默认值:TextAlign.Start |
| textOverflow | {overflow:&nbsp;[TextOverflow](ts-appendix-enums.md#textoverflow)} | {overflow:&nbsp;TextOverflow.Clip} | 设置文本超长时的显示方式。<br/>**说明:**<br/>文本截断是按字截断。例如,英文以单词为最小单位进行截断,若需要以字母为单位进行截断,可在字母间添加零宽空格:\u200B。<br />需配合`maxLines`使用,单独设置不生效。 | | textOverflow | {overflow:&nbsp;[TextOverflow](ts-appendix-enums.md#textoverflow)} | 设置文本超长时的显示方式。<br/>默认值:{overflow:&nbsp;TextOverflow.Clip}<br/>**说明:**<br/>文本截断是按字截断。例如,英文以单词为最小单位进行截断,若需要以字母为单位进行截断,可在字母间添加零宽空格:\u200B。<br />需配合`maxLines`使用,单独设置不生效。 |
| maxLines | number | Infinity | 设置文本的最大行数。<br />**说明:**<br />默认情况下,文本是自动折行的,如果指定此参数,则文本最多不会超过指定的行。如果有多余的文本,可以通过 `textOverflow`来指定截断方式。 | | maxLines | number | 设置文本的最大行数。<br />默认值:Infinity<br/>**说明:**<br />默认情况下,文本是自动折行的,如果指定此参数,则文本最多不会超过指定的行。如果有多余的文本,可以通过 `textOverflow`来指定截断方式。 |
| lineHeight | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;[Resource](../../ui/ts-types.md) | - | 设置文本的文本行高,设置值不大于0时,不限制文本行高,自适应字体大小,Length为number类型时单位为fp。 | | lineHeight | string&nbsp;\|&nbsp;number&nbsp;\|&nbsp;[Resource](../../ui/ts-types.md) | 设置文本的文本行高,设置值不大于0时,不限制文本行高,自适应字体大小,Length为number类型时单位为fp。 |
| decoration | {<br/>type:&nbsp;TextDecorationType,<br/>color?:&nbsp;[ResourceColor](../../ui/ts-types.md)<br/>} | {<br/>type:&nbsp;TextDecorationType.None,<br/>color:Color.Black<br/>} | 设置文本装饰线样式及其颜色。 | | decoration | {<br/>type:&nbsp;TextDecorationType,<br/>color?:&nbsp;[ResourceColor](../../ui/ts-types.md)<br/>} | 设置文本装饰线样式及其颜色。<br />默认值:{<br/>type:&nbsp;TextDecorationType.None,<br/>color:Color.Black<br/>} |
| baselineOffset | number \| string | - | 设置文本基线的偏移量。 | | baselineOffset | number&nbsp;\|&nbsp;string | 设置文本基线的偏移量。 |
| letterSpacing | [Length](../../ui/ts-types.md) | - | 设置文本字符间距。 | | letterSpacing | number&nbsp;\|&nbsp;string | 设置文本字符间距。 |
| minFontSize | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](../../ui/ts-types.md) | - | 设置文本最小显示字号。 | | minFontSize | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](../../ui/ts-types.md) | 设置文本最小显示字号。 |
| maxFontSize | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](../../ui/ts-types.md) | - | 设置文本最大显示字号。 | | maxFontSize | number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](../../ui/ts-types.md) | 设置文本最大显示字号。 |
| textCase | [TextCase](ts-appendix-enums.md#textcase) | TextCase.Normal | 设置文本大小写。 | | textCase | [TextCase](ts-appendix-enums.md#textcase) | 设置文本大小写。<br />默认值:TextCase.Normal |
| copyOption<sup>9+</sup> | [CopyOptions](ts-appendix-enums.md#copyoptions9) | CopyOptions.None | 组件支持设置文本是否可复制粘贴。 | | copyOption<sup>9+</sup> | [CopyOptions](ts-appendix-enums.md#copyoptions9) | 组件支持设置文本是否可复制粘贴。<br />默认值:CopyOptions.None |
> **说明:** > **说明:**
>
> 不支持Text内同时存在文本内容和Span子组件。如果同时存在,只显示Span内的内容。 > 不支持Text内同时存在文本内容和Span子组件。如果同时存在,只显示Span内的内容。
......
...@@ -3,14 +3,10 @@ ...@@ -3,14 +3,10 @@
可以输入多行文本并支持响应部分输入事件的组件。 可以输入多行文本并支持响应部分输入事件的组件。
> **说明:** > **说明:**
>
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 子组件 ## 子组件
...@@ -20,36 +16,38 @@ ...@@ -20,36 +16,38 @@
TextArea(value?:{placeholder?: ResourceStr, text?: ResourceStr, controller?: TextAreaController}) TextArea(value?:{placeholder?: ResourceStr, text?: ResourceStr, controller?: TextAreaController})
- 参数 **参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| ----------------------- | ---------------------------------------- | ---- | ---- | -------------- |
| placeholder | [ResourceStr](../../ui/ts-types.md) | 否 | - | 无输入时的提示文本。 |
| text | [ResourceStr](../../ui/ts-types.md) | 否 | - | 设置输入框当前的文本内容。 |
| controller<sup>8+</sup> | [TextAreaController](#textareacontroller8) | 否 | - | 设置TextArea控制器。 |
| 参数名 | 参数类型 | 必填 | 参数描述 |
| ----------------------- | ---------------------------------------- | ---- | -------------- |
| placeholder | [ResourceStr](../../ui/ts-types.md) | 否 | 无输入时的提示文本。 |
| text | [ResourceStr](../../ui/ts-types.md) | 否 | 设置输入框当前的文本内容。 |
| controller<sup>8+</sup> | [TextAreaController](#textareacontroller8) | 否 | 设置TextArea控制器。 |
## 属性
除支持通用属性外,还支持以下属性: ## 属性
| 名称 | 参数类型 | 默认值 | 描述 | 除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
| ------------------------ | ---------------------------------------- | ----- | ---------------------------------------- |
| placeholderColor | Color | - | 设置placeholder文本颜色。 |
| placeholderFont | {<br/>size?:&nbsp;number,<br/>weight?:number&nbsp;\|&nbsp;[FontWeight](ts-universal-attributes-text-style.md),<br/>family?:&nbsp;string,<br/>style?:&nbsp;[FontStyle](ts-universal-attributes-text-style.md)<br/>} | - | 设置placeholder文本样式:<br/>-&nbsp;size:&nbsp;设置文本尺寸,Length为number类型时,使用fp单位。<br/>-&nbsp;weight:&nbsp;设置文本的字体粗细,number类型取值[100,&nbsp;900],取值间隔为100,默认为400,取值越大,字体越粗。<br/>-&nbsp;family:&nbsp;设置文本的字体列表。使用多个字体,使用','进行分割,优先级按顺序生效,例如:'Arial,&nbsp;sans-serif'。<br/>-&nbsp;style:&nbsp;设置文本的字体样式。 |
| textAlign | [TextAlign](ts-appendix-enums.md#textalign) | Start | 设置文本水平对齐式。 |
| caretColor | Color | - | 设置输入框光标颜色。 |
| inputFilter<sup>8+</sup> | {<br/>value:&nbsp;[ResourceStr](../../ui/ts-types.md)<sup>8+</sup>,<br/>error?:&nbsp;(value:&nbsp;string)<br/>} | - | 通过正则表达式设置输入过滤器。满足表达式的输入允许显示,不满足的输入被忽略。仅支持单个字符匹配,不支持字符串匹配。例如:^(?=.\*\d)(?=.\*[a-z])(?=.\*[A-Z]).{8,10}$,不支持过滤8到10位的强密码。<br/>-&nbsp;value:设置正则表达式。<br/>-&nbsp;error:正则匹配失败时,返回被忽略的内容。 |
| copyOption<sup>9+</sup> | [CopyOptions](ts-basic-components-text.md) | CopyOptions.CrossDevice | 设置文本是否可复制。 |
| 名称 | 参数类型 | 描述 |
| ------------------------ | ---------------------------------------- | ---------------------------------------- |
| placeholderColor | [ResourceColor](../../ui/ts-types.md#resourcecolor8) | 设置placeholder文本颜色。 |
| placeholderFont | [Font](../../ui/ts-types.md#font) | 设置placeholder文本样式。 |
| textAlign | [TextAlign](ts-appendix-enums.md#textalign) | 设置文本水平对齐式。<br/>默认值:TextAlign.Start |
| caretColor | [ResourceColor](../../ui/ts-types.md#resourcecolor8) | 设置输入框光标颜色。 |
| inputFilter<sup>8+</sup> | {<br/>value:&nbsp;[ResourceStr](../../ui/ts-types.md)<sup>8+</sup>,<br/>error?:&nbsp;(value:&nbsp;string) => void<br/>} | 通过正则表达式设置输入过滤器。满足表达式的输入允许显示,不满足的输入被忽略。仅支持单个字符匹配,不支持字符串匹配。例如:^(?=.\*\d)(?=.\*[a-z])(?=.\*[A-Z]).{8,10}$,不支持过滤8到10位的强密码。<br/>-&nbsp;value:设置正则表达式。<br/>-&nbsp;error:正则匹配失败时,返回被忽略的内容。 |
| copyOption<sup>9+</sup> | [CopyOptions](ts-appendix-enums.md#copyoptions9) | 设置文本是否可复制。 |
## 事件 ## 事件
除支持[通用事件](ts-universal-events-click.md)外,还支持以下事件:
| 名称 | 功能描述 | | 名称 | 功能描述 |
| ---------------------------------------- | ---------------------------------------- | | ------------------------------------------------------------ | ------------------------------------------------------------ |
| onChange(callback:&nbsp;(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 输入发生变化时,触发回调。 | | onChange(callback:&nbsp;(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 输入发生变化时,触发回调。 |
| onCopy<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板复制按钮,触发回调。<br/>value:复制的文本内容。 | | onCopy<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板复制按钮,触发回调。<br/>- value:复制的文本内容。 |
| onCut<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板剪切按钮,触发回调。<br/>value:剪切的文本内容。 | | onCut<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板剪切按钮,触发回调。<br/>- value:剪切的文本内容。 |
| onPaste<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板粘贴按钮,触发回调。<br/>value:粘贴的文本内容。 | | onPaste<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板粘贴按钮,触发回调。<br/>- value:粘贴的文本内容。 |
## TextAreaController<sup>8+</sup> ## TextAreaController<sup>8+</sup>
...@@ -59,7 +57,6 @@ TextArea组件的控制器,通过它操作TextArea组件。 ...@@ -59,7 +57,6 @@ TextArea组件的控制器,通过它操作TextArea组件。
``` ```
controller: TextAreaController = new TextAreaController() controller: TextAreaController = new TextAreaController()
``` ```
### caretPosition<sup>8+</sup> ### caretPosition<sup>8+</sup>
...@@ -68,10 +65,11 @@ caretPosition(value: number): void ...@@ -68,10 +65,11 @@ caretPosition(value: number): void
设置输入光标的位置。 设置输入光标的位置。
- 参数 **参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| ----- | ------ | ---- | ---- | ------------------- | | 参数名 | 参数类型 | 必填 | 参数描述 |
| value | number | 是 | - | 从字符串开始到光标所在位置的字符长度。 | | ------ | -------- | ---- | -------------------------------------- |
| value | number | 是 | 从字符串开始到光标所在位置的字符长度。 |
## 示例 ## 示例
......
...@@ -3,14 +3,10 @@ ...@@ -3,14 +3,10 @@
可以输入单行文本并支持响应输入事件的组件。 可以输入单行文本并支持响应输入事件的组件。
> **说明:** > **说明:**
>
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 子组件 ## 子组件
...@@ -20,53 +16,58 @@ ...@@ -20,53 +16,58 @@
TextInput(value?:{placeholder?: ResourceStr, text?: ResourceStr, controller?: TextInputController}) TextInput(value?:{placeholder?: ResourceStr, text?: ResourceStr, controller?: TextInputController})
- 参数 **参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| ----------------------- | ---------------------------------------- | ---- | ---- | --------------- | | 参数名 | 参数类型 | 必填 | 参数描述 |
| placeholder | [ResourceStr](../../ui/ts-types.md) | 否 | - | 无输入时的提示文本。 | | ----------------------- | ---------------------------------------- | ---- | --------------- |
| text | [ResourceStr](../../ui/ts-types.md) | 否 | - | 设置输入框当前的文本内容。 | | placeholder | [ResourceStr](../../ui/ts-types.md) | 否 | 无输入时的提示文本。 |
| controller<sup>8+</sup> | [TextInputController](#textinputcontroller8) | 否 | - | 设置TextInput控制器。 | | text | [ResourceStr](../../ui/ts-types.md) | 否 | 设置输入框当前的文本内容。 |
| controller<sup>8+</sup> | [TextInputController](#textinputcontroller8) | 否 | 设置TextInput控制器。 |
## 属性 ## 属性
除支持通用属性外,还支持以下属性: 除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
| 名称 | 参数类型 | 默认值 | 描述 | | 名称 | 参数类型 | 描述 |
| ------------------------ | ---------------------------------------- | ----------------- | ---------------------------------------- | | ------------------------ | ---------------------------------------- | ---------------------------------------- |
| type | InputType | InputType.Normal | 设置输入框类型。 | | type | InputType | 设置输入框类型。<br/>默认值:InputType.Normal |
| placeholderColor | [ResourceColor](../../ui/ts-types.md) | - | 设置placeholder颜色。| | placeholderColor | [ResourceColor](../../ui/ts-types.md) | 设置placeholder颜色。|
| placeholderFont | {<br/>size?:&nbsp;Length,<br/>weight?:&nbsp;number\|[FontWeight](ts-universal-attributes-text-style.md),<br/>family?:&nbsp;string,<br/>style?:&nbsp;[FontStyle](ts-universal-attributes-text-style.md)<br/>} | - | 设置placeholder文本样式:<br/>-&nbsp;size:&nbsp;设置文本尺寸,Length为number类型时,使用fp单位。<br/>-&nbsp;weight:&nbsp;设置文本的字体粗细,number类型取值[100,&nbsp;900],取值间隔为100,默认为400,取值越大,字体越粗。<br/>-&nbsp;family:&nbsp;设置文本的字体列表。使用多个字体,使用','进行分割,优先级按顺序生效。例如:'Arial,&nbsp;sans-serif'。<br/>-&nbsp;style:&nbsp;设置文本的字体样式。 | | placeholderFont | [Font](../../ui/ts-types.md#font) | 设置placeholder文本样式。 |
| enterKeyType | EnterKeyType | EnterKeyType.Done | 设置输入法回车键类型。 | | enterKeyType | EnterKeyType | 设置输入法回车键类型。<br/>默认值:EnterKeyType.Done |
| caretColor | [ResourceColor](../../ui/ts-types.md) | - | 设置输入框光标颜色。 | | caretColor | [ResourceColor](../../ui/ts-types.md) | 设置输入框光标颜色。 |
| maxLength | number | - | 设置文本的最大输入字符数。 | | maxLength | number | 设置文本的最大输入字符数。 |
| inputFilter<sup>8+</sup> | {<br/>value:&nbsp;[ResourceStr](../../ui/ts-types.md)<sup>8+</sup>,<br/>error?:&nbsp;(value:&nbsp;string)&nbsp;=&gt;&nbsp;void<br/>} | - | 正则表达式,满足表达式的输入允许显示,不满足正则表达式的输入被忽略。仅支持单个字符匹配,不支持字符串匹配。例如:^(?=.\*\d)(?=.\*[a-z])(?=.\*[A-Z]).{8,10}$,8到10位的强密码不支持过滤。<br/>-&nbsp;value:设置正则表达式。<br/>-&nbsp;error:正则匹配失败时,返回被忽略的内容。 | | inputFilter<sup>8+</sup> | {<br/>value:&nbsp;[ResourceStr](../../ui/ts-types.md)<sup>8+</sup>,<br/>error?:&nbsp;(value:&nbsp;string)&nbsp;=&gt;&nbsp;void<br/>} | 正则表达式,满足表达式的输入允许显示,不满足正则表达式的输入被忽略。仅支持单个字符匹配,不支持字符串匹配。例如:^(?=.\*\d)(?=.\*[a-z])(?=.\*[A-Z]).{8,10}$,8到10位的强密码不支持过滤。<br/>-&nbsp;value:设置正则表达式。<br/>-&nbsp;error:正则匹配失败时,返回被忽略的内容。 |
| copyOption<sup>9+</sup> | [CopyOptions](ts-basic-components-text.md) | CopyOptions.CrossDevice | 设置文本是否可复制。 | | copyOption<sup>9+</sup> | [CopyOptions](ts-appendix-enums.md#copyoptions9) | 设置文本是否可复制。 |
| showPasswordIcon<sup>9+</sup> | boolean | true | 密码输入模式时,密码框末尾的图标是否显示。 | | showPasswordIcon<sup>9+</sup> | boolean | 密码输入模式时,密码框末尾的图标是否显示。<br/>默认值:true |
| style<sup>9+</sup> | TextInputStyle | Default | TextInput风格。 | | style<sup>9+</sup> | TextInputStyle | TextInput风格。<br/>默认值:Default |
- EnterKeyType枚举说明 ## EnterKeyType枚举说明
| 名称 | 描述 |
| ------------------- | --------- | | 名称 | 描述 |
| Go | 显示Go文本。 | | ------------------- | --------- |
| Search | 显示为搜索样式。 | | Go | 显示Go文本。 |
| Send | 显示为发送样式。 | | Search | 显示为搜索样式。 |
| Next | 显示为下一个样式。 | | Send | 显示为发送样式。 |
| Done | 标准样式。 | | Next | 显示为下一个样式。 |
| Done | 标准样式。 |
- InputType枚举说明
| 名称 | 描述 | ## InputType枚举说明
| ------------------ | ------------- |
| Normal | 基本输入模式。 | | 名称 | 描述 |
| Password | 密码输入模式。 | | ------------------ | ------------- |
| Email | e-mail地址输入模式。 | | Normal | 基本输入模式。 |
| Number | 纯数字输入模式。 | | Password | 密码输入模式。 |
| Email | e-mail地址输入模式。 |
- TextInputStyle枚举说明 | Number | 纯数字输入模式。 |
| 名称 | 描述 | | PhoneNumber<sup>9+</sup> | 电话号码输入模式。<br/>支持输入数字、+ 、-、*、#,长度不限。 |
| ------------------ | ------------- |
| Default | 默认风格,光标宽1.5vp,光标高度和字体大小高度相关,字体越大光标越高。 | ## TextInputStyle枚举说明
| Inline | 内联输入风格。文字选中时底板与输入框同高。 |
| 名称 | 描述 |
| ------------------ | ------------- |
| Default | 默认风格,光标宽1.5vp,光标高度和字体大小高度相关,字体越大光标越高。 |
| Inline | 内联输入风格。文字选中时底板与输入框同高。 |
## 事件 ## 事件
...@@ -80,24 +81,25 @@ TextInput(value?:{placeholder?: ResourceStr, text?: ResourceStr, controller?: Te ...@@ -80,24 +81,25 @@ TextInput(value?:{placeholder?: ResourceStr, text?: ResourceStr, controller?: Te
| onCut<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板剪切按钮,触发回调。<br/>value:剪切的文本内容。 | | onCut<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板剪切按钮,触发回调。<br/>value:剪切的文本内容。 |
| onPaste<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板粘贴按钮,触发回调。<br/>value:粘贴的文本内容。 | | onPaste<sup>8+</sup>(callback:(value:&nbsp;string)&nbsp;=&gt;&nbsp;void) | 长按输入框内部区域弹出剪贴板后,点击剪切板粘贴按钮,触发回调。<br/>value:粘贴的文本内容。 |
### TextInputController<sup>8+</sup> ## TextInputController<sup>8+</sup>
TextInput组件的控制器。 TextInput组件的控制器。
#### 导入对象 ### 导入对象
``` ```
controller: TextInputController = new TextInputController() controller: TextInputController = new TextInputController()
``` ```
#### caretPosition ### caretPosition
caretPosition(value:&nbsp;number): void caretPosition(value:&nbsp;number): void
设置输入光标的位置。 设置输入光标的位置。
- 参数
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | **参数:**
| ----- | ------ | ---- | ---- | ---------------------------------------- |
| value | number | 是 | - | 从字符串开始到光标所在位置的字符长度。 | | 参数名 | 参数类型 | 必填 | 参数描述 |
| ------ | -------- | ---- | -------------------------------------- |
| value | number | 是 | 从字符串开始到光标所在位置的字符长度。 |
## 示例 ## 示例
......
...@@ -3,14 +3,10 @@ ...@@ -3,14 +3,10 @@
滚动选择文本的组件。 滚动选择文本的组件。
> **说明:** > **说明:**
>
> 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 子组件 ## 子组件
...@@ -18,27 +14,28 @@ ...@@ -18,27 +14,28 @@
## 接口 ## 接口
TextPicker(options: {range: string[]|Resource, selected?: number, value?: string}) TextPicker(options?: {range: string[]|Resource, selected?: number, value?: string})
根据range指定的选择范围创建文本选择器。 根据range指定的选择范围创建文本选择器。
- 参数 **参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | -------- | -------- | -------- |
| range | string[]&nbsp;\|&nbsp;[Resource](../../ui/ts-types.md#resource类型) | 是 | - | 选择器的数据选择范围。 |
| selected | number | 否 | 0 | 选中项在数组中的index值。 |
| value | string | 否 | 第一个元素值 | 选中项的值,优先级低于selected。 |
| 参数名 | 参数类型 | 必填 | 参数描述 |
| -------- | -------- | -------- | -------- |
| range | string[]&nbsp;\|&nbsp;[Resource](../../ui/ts-types.md#resource类型) | 是 | 选择器的数据选择范围。 |
| selected | number | 否 | 选中项在数组中的index值。<br/>默认值:0 |
| value | string | 否 | 选中项的值,优先级低于selected。<br/>默认值:第一个元素值 |
## 属性 ## 属性
| 名称 | 参数类型 | 默认值 | 描述 | | 名称 | 参数类型 | 描述 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- |
| defaultPickerItemHeight | number \| string | - | 默认Picker内容项元素高度。 | | defaultPickerItemHeight | number \| string | 默认Picker内容项元素高度。 |
## 事件 ## 事件
除支持[通用事件](ts-universal-events-click.md)外,还支持以下事件:
| 名称 | 描述 | | 名称 | 描述 |
| -------- | -------- | | -------- | -------- |
| onChange(callback:&nbsp;(value:&nbsp;string,&nbsp;index:&nbsp;number)&nbsp;=&gt;&nbsp;void) | 滑动选中TextPicker文本内容后,触发该回调。<br/>-&nbsp;value:&nbsp;当前选中项的文本。<br/>-&nbsp;index:&nbsp;当前选中项的索引值。 | | onChange(callback:&nbsp;(value:&nbsp;string,&nbsp;index:&nbsp;number)&nbsp;=&gt;&nbsp;void) | 滑动选中TextPicker文本内容后,触发该回调。<br/>-&nbsp;value:&nbsp;当前选中项的文本。<br/>-&nbsp;index:&nbsp;当前选中项的索引值。 |
......
...@@ -3,14 +3,10 @@ ...@@ -3,14 +3,10 @@
滚动选择时间的组件。 滚动选择时间的组件。
> **说明:** > **说明:**
>
> 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 子组件 ## 子组件
...@@ -18,21 +14,22 @@ ...@@ -18,21 +14,22 @@
## 接口 ## 接口
TimePicker(options?: TimePickerOptions) TimePicker(options?: {selected?: Date})
默认以00:00至23:59的时间区间创建滑动选择器。 默认以00:00至23:59的时间区间创建滑动选择器。
- options参数 **参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | ---- | ---- | ------ | --------- | | 参数名 | 参数类型 | 必填 | 参数描述 |
| selected | Date | 否 | 当前系统时间 | 设置选中项的时间。 | | -------- | -------- | -------- | -------- |
| selected | Date | 否 | 设置选中项的时间。<br/>默认值:当前系统时间 |
## 属性 ## 属性
| 名称 | 参数类型 | 默认值 | 描述 | | 名称 | 参数类型 | 描述 |
| --------------- | ------- | ----- | --------------------- | | -------- | -------- | -------- |
| useMilitaryTime | boolean | false | 展示时间是否为24小时制,不支持动态修改。 | | useMilitaryTime | boolean | 展示时间是否为24小时制,不支持动态修改。<br/>默认值:false |
## 事件 ## 事件
......
...@@ -3,32 +3,29 @@ ...@@ -3,32 +3,29 @@
用于触发长按手势事件,触发长按手势的最少手指数为1,最短时间为500毫秒。 用于触发长按手势事件,触发长按手势的最少手指数为1,最短时间为500毫秒。
> **说明:** > **说明:**
>
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 接口 ## 接口
LongPressGesture(options?: { fingers?: number, repeat?: boolean, duration?: number }) LongPressGesture(value?: { fingers?: number, repeat?: boolean, duration?: number })
**参数:**
- 参数 | 参数名称 | 参数类型 | 必填 | 参数描述 |
| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 | | -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- | -------- | | fingers | number | 否 | 触发长按的最少手指数,最小为1指,&nbsp;最大取值为10指。<br/>默认值:1 |
| fingers | number | 否 | 1 | 触发长按的最少手指数,最小为1指,&nbsp;最大取值为10指。 | | repeat | boolean | 否 | 是否连续触发事件回调。<br/>默认值:false |
| repeat | boolean | 否 | false | 是否连续触发事件回调。 | | duration | number | 否 | 触发长按的最短时间,单位为毫秒(ms)。<br/>默认值:500 |
| duration | number | 否 | 500 | 触发长按的最短时间,单位为毫秒(ms)。 |
## 事件 ## 事件
| 名称 | 功能描述 | | 名称 | 功能描述 |
| -------- | -------- | | -------- | -------- |
| onAction((event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | LongPress手势识别成功回调。 | | onAction(event:(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | LongPress手势识别成功回调。 |
| onActionEnd((event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | LongPress手势识别成功,手指抬起后触发回调。 | | onActionEnd(event:(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | LongPress手势识别成功,手指抬起后触发回调。 |
| onActionCancel(event:&nbsp;()&nbsp;=&gt;&nbsp;void) | LongPress手势识别成功,接收到触摸取消事件触发回调。 | | onActionCancel(event:&nbsp;()&nbsp;=&gt;&nbsp;void) | LongPress手势识别成功,接收到触摸取消事件触发回调。 |
......
...@@ -3,63 +3,67 @@ ...@@ -3,63 +3,67 @@
用于触发拖动手势事件,滑动的最小距离为5vp时拖动手势识别成功。 用于触发拖动手势事件,滑动的最小距离为5vp时拖动手势识别成功。
> **说明:** > **说明:**
>
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表 ## 接口
PanGesture(value?: { fingers?: number; direction?: PanDirection; distance?: number } | [PanGestureOptions](#pangestureoptions))
## 接口 **参数:**
PanGesture(options?: { fingers?: number, direction?: PanDirection, distance?: number } | [PanGestureOptions](#pangestureoptions)) | 参数名称 | 参数类型 | 必填 | 参数描述 |
| -------- | -------- | -------- | -------- |
| fingers | number | 否 | 触发拖动的最少手指数,最小为1指,&nbsp;最大取值为10指。<br/>默认值:1 |
| direction | PanDirection | 否 | 触发拖动的手势方向,此枚举值支持逻辑与(&amp;)和逻辑或(\|)运算。<br/>默认值:PanDirection.All |
| distance | number | 否 | 最小拖动识别距离,单位为vp。<br/>默认值:5.0<br/>**说明:**<br/>> tab滑动与该拖动手势事件同时存在时,可将distance值设为1,使拖动更灵敏,避免造成事件错乱。 |
- 参数 ## PanDirection枚举说明
| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | -------- | -------- | -------- |
| fingers | number | 否 | 1 | 触发拖动的最少手指数,最小为1指,&nbsp;最大取值为10指。 |
| direction | PanDirection | 否 | PanDirection.All | 触发拖动的手势方向,此枚举值支持逻辑与(&amp;)和逻辑或(\|)运算。 |
| distance | number | 否 | 5.0 | 最小拖动识别距离,单位为vp。<br/>**说明:**<br/>> tab滑动与该拖动手势事件同时存在时,可将distance值设为1,使拖动更灵敏,避免造成事件错乱。 |
- PanDirection枚举说明 | 名称 | 描述 |
| 名称 | 描述 | | -------- | -------- |
| -------- | -------- | | All | 所有方向。 |
| All | 所有方向。 | | Horizontal | 水平方向。 |
| Horizontal | 水平方向。 | | Vertical | 竖直方向。 |
| Vertical | 竖直方向。 | | Left | 向左拖动。 |
| Left | 向左拖动。 | | Right | 向右拖动。 |
| Right | 向右拖动。 | | Up | 向上拖动。 |
| Up | 向上拖动。 | | Down | 向下拖动。 |
| Down | 向下拖动。 | | None | 任何方向都不可触发拖动手势事件。 |
| None | 任何方向都不可触发拖动手势事件。 |
### PanGestureOptions ## PanGestureOptions
通过PanGestureOptions对象接口可以动态修改滑动手势识别器的属性,从而避免通过状态变量修改属性(状态变量修改会导致UI刷新)。 通过PanGestureOptions对象接口可以动态修改滑动手势识别器的属性,从而避免通过状态变量修改属性(状态变量修改会导致UI刷新)。
PanGestureOptions(options?: { fingers?: number, direction?: PanDirection, distance?: number }) PanGestureOptions(value?: { fingers?: number; direction?: PanDirection; distance?: number })
- 参数 **参数:**
同PanGesture参数说明。
- 接口 | 参数名称 | 参数类型 | 必填 | 参数描述 |
| 名称 | 功能描述 | | --------- | ------------ | ---- | ------------------------------------------------------------ |
| -------- | -------- | | fingers | number | 否 | 触发滑动的最少手指数,最小为1指,&nbsp;最大取值为10指。<br/>默认值:1 |
| setDirection(value:&nbsp;PanDirection) | 设置direction属性。 | | direction | PanDirection | 否 | 设置滑动方向,此枚举值支持逻辑与(&amp;)和逻辑或(\|)运算。<br/>默认值:All |
| setDistance(value:&nbsp;number) | 设置distance属性。 | | distance | number | 否 | 最小滑动识别距离,单位为vp。<br/>默认值:5.0<br/>**说明:**<br/>> tab滑动与该拖动手势事件同时存在时,可将distance值设为1,使拖动更灵敏,避免造成事件错乱。 |
| setFingers(value:&nbsp;number) | 设置fingers属性。 |
**接口**
| 名称 | 功能描述 |
| -------- | -------- |
| setDirection(value:&nbsp;PanDirection) | 设置direction属性。 |
| setDistance(value:&nbsp;number) | 设置distance属性。 |
| setFingers(value:&nbsp;number) | 设置fingers属性。 |
## 事件 ## 事件
| 名称 | 功能描述 | | 名称 | 功能描述 |
| -------- | -------- | | -------- | -------- |
| onActionStart(callback:&nbsp;(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pan手势识别成功回调。 | | onActionStart(event:&nbsp;(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pan手势识别成功回调。 |
| onActionUpdate(callback:&nbsp;(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pan手势移动过程中回调。 | | onActionUpdate(event:&nbsp;(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pan手势移动过程中回调。 |
| onActionEnd(callback:&nbsp;(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pan手势识别成功,手指抬起后触发回调。 | | onActionEnd(event:&nbsp;(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pan手势识别成功,手指抬起后触发回调。 |
| onActionCancel(callback:&nbsp;()&nbsp;=&gt;&nbsp;void) | Pan手势识别成功,接收到触摸取消事件触发回调。 | | onActionCancel(event:&nbsp;()&nbsp;=&gt;&nbsp;void) | Pan手势识别成功,接收到触摸取消事件触发回调。 |
## 示例 ## 示例
......
...@@ -3,32 +3,29 @@ ...@@ -3,32 +3,29 @@
用于触发捏合手势,触发捏合手势的最少手指为2指,最大为5指,最小识别距离为3vp。 用于触发捏合手势,触发捏合手势的最少手指为2指,最大为5指,最小识别距离为3vp。
> **说明:** > **说明:**
>
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 接口 ## 接口
PinchGesture(options?: { fingers?: number, distance?: number }) PinchGesture(value?: { fingers?: number, distance?: number })
**参数:**
- 参数 | 参数名称 | 参数类型 | 必填 | 参数描述 |
| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 | | -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- | -------- | | fingers | number | 否 | 触发捏合的最少手指数,&nbsp;最小为2指,最大为5指。<br/>默认值:2 |
| fingers | number | 否 | 2 | 触发捏合的最少手指数,&nbsp;最小为2指,最大为5指。 | | distance | number | 否 | 最小识别距离,单位为vp。<br/>默认值:3.0 |
| distance | number | 否 | 3.0 | 最小识别距离,单位为vp。 |
## 事件 ## 事件
| 名称 | 功能描述 | | 名称 | 功能描述 |
| -------- | -------- | | -------- | -------- |
| onActionStart((event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pinch手势识别成功回调。 | | onActionStart(event:(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pinch手势识别成功回调。 |
| onActionUpdate((event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pinch手势移动过程中回调。 | | onActionUpdate(event:(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pinch手势移动过程中回调。 |
| onActionEnd((event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pinch手势识别成功,手指抬起后触发回调。 | | onActionEnd(event:(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Pinch手势识别成功,手指抬起后触发回调。 |
| onActionCancel(event:&nbsp;()&nbsp;=&gt;&nbsp;void) | Pinch手势识别成功,接收到触摸取消事件触发回调。 | | onActionCancel(event:&nbsp;()&nbsp;=&gt;&nbsp;void) | Pinch手势识别成功,接收到触摸取消事件触发回调。 |
......
...@@ -3,32 +3,29 @@ ...@@ -3,32 +3,29 @@
用于触发旋转手势事件,触发旋转手势的最少手指为2指,最大为5指,最小改变度数为1度。 用于触发旋转手势事件,触发旋转手势的最少手指为2指,最大为5指,最小改变度数为1度。
> **说明:** > **说明:**
>
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 接口 ## 接口
RotationGesture(options?: { fingers?: number, angle?: number }) RotationGesture(value?: { fingers?: number, angle?: number })
**参数:**
- 参数 | 参数名称 | 参数类型 | 必填 | 参数描述 |
| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 | | -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- | -------- | | fingers | number | 否 | 触发旋转的最少手指数,&nbsp;最小为2指,最大为5指。<br/>默认值:2 |
| fingers | number | 否 | 2 | 触发旋转的最少手指数,&nbsp;最小为2指,最大为5指。 | | angle | number | 否 | 触发旋转手势的最小改变度数,单位为deg。<br/>默认值:1.0 |
| angle | number | 否 | 1.0 | 触发旋转手势的最小改变度数,单位为deg。 |
## 事件 ## 事件
| 名称 | 功能描述 | | 名称 | 功能描述 |
| -------- | -------- | | -------- | -------- |
| onActionStart((event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Rotation手势识别成功回调。 | | onActionStart(event:(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Rotation手势识别成功回调。 |
| onActionUpdate((event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Rotation手势移动过程中回调。 | | onActionUpdate(event:(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Rotation手势移动过程中回调。 |
| onActionEnd((event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Rotation手势识别成功,手指抬起后触发回调。 | | onActionEnd(event:(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Rotation手势识别成功,手指抬起后触发回调。 |
| onActionCancel(event:&nbsp;()&nbsp;=&gt;&nbsp;void) | Rotation手势识别成功,接收到触摸取消事件触发回调。 | | onActionCancel(event:&nbsp;()&nbsp;=&gt;&nbsp;void) | Rotation手势识别成功,接收到触摸取消事件触发回调。 |
......
...@@ -3,40 +3,37 @@ ...@@ -3,40 +3,37 @@
用于触发滑动事件,滑动最小速度为100vp/s时识别成功。 用于触发滑动事件,滑动最小速度为100vp/s时识别成功。
> **说明:** > **说明:**
>
> 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从API Version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 接口 ## 接口
SwipeGesture(value?: { fingers?: number; direction?: SwipeDirection; speed?: number }) SwipeGesture(value?: { fingers?: number; direction?: SwipeDirection; speed?: number })
- 参数 **参数:**
| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | -------- | -------- | -------- |
| fingers | number | 否 | 1 | 触发滑动的最少手指数,默认为1,最小为1指,最大为10指。 |
| direction | SwipeDirection | 否 | SwipeDirection.All | 触发滑动手势的滑动方向。 |
| speed | number | 否 | 100 | 识别滑动的最小速度(默认为100vp/秒)。 |
- SwipeDirection枚举说明 | 参数名称 | 参数类型 | 必填 | 参数描述 |
| 名称 | 描述 | | -------- | -------- | -------- | -------- |
| -------- | -------- | | fingers | number | 否 | 触发滑动的最少手指数,默认为1,最小为1指,最大为10指。<br/>默认值:1 |
| All | 所有方向。 | | direction | SwipeDirection | 否 | 触发滑动手势的滑动方向。<br/>默认值:SwipeDirection.All |
| Horizontal | 水平方向。 | | speed | number | 否 | 识别滑动的最小速度(默认为100VP/秒)。<br/>默认值:100 |
| Vertical | 竖直方向。 |
| None | 任何方向均不可触发。 | ## SwipeDirection枚举说明
| 名称 | 描述 |
| -------- | -------- |
| All | 所有方向。 |
| Horizontal | 水平方向。 |
| Vertical | 竖直方向。 |
| None | 任何方向均不可触发。 |
## 事件 ## 事件
| 名称 | 功能描述 | | 名称 | 功能描述 |
| -------- | -------- | | -------- | -------- |
| onAction(callback:(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | 滑动手势识别成功回调。 | | onAction(event:(event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | 滑动手势识别成功回调。 |
![zh-cn_image_0000001231374559](figures/zh-cn_image_0000001231374661.png) ![zh-cn_image_0000001231374559](figures/zh-cn_image_0000001231374661.png)
## 示例 ## 示例
......
...@@ -3,30 +3,27 @@ ...@@ -3,30 +3,27 @@
支持单次点击、多次点击识别。 支持单次点击、多次点击识别。
> **说明:** > **说明:**
>
> 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 接口 ## 接口
TapGesture(options?: { count?: number, fingers?: number }) TapGesture(value?: { count?: number, fingers?: number })
**参数:**
- 参数 | 参数名称 | 参数类型 | 必填 | 参数描述 |
| 参数名称 | 参数类型 | 必填 | 默认值 | 参数描述 | | -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- | -------- | | count | number | 否 | 识别的连续点击次数。如果设置小于1,会被转化为默认值。<br/>默认值:1<br/>>&nbsp;&nbsp;**说明:**<br/>>&nbsp;如配置多击,上一次抬起和下一次按下的超时时间为300毫秒(ms)。 |
| count | number | 否 | 1 | 识别的连续点击次数。如果设置小于1,会被转化为默认值。<br/>>&nbsp;&nbsp;**说明:**<br/>>&nbsp;如配置多击,上一次抬起和下一次按下的超时时间为300毫秒(ms)。 | | fingers | number | 否 | 触发点击的最少手指数,最小为1指,&nbsp;最大为10指。<br/>默认值:1<br/>>&nbsp;&nbsp;**说明:**<br/>>&nbsp;1.&nbsp;当配置多指时,第一根手指按下后300毫秒(ms)内未有足够的手指数按下,手势识别失败。<br/>>&nbsp;2.&nbsp;实际点击手指数超过配置值,手势识别失败。 |
| fingers | number | 否 | 1 | 触发点击的最少手指数,最小为1指,&nbsp;最大为10指。<br/>>&nbsp;&nbsp;**说明:**<br/>>&nbsp;1.&nbsp;当配置多指时,第一根手指按下后300毫秒(ms)内未有足够的手指数按下,手势识别失败。<br/>>&nbsp;2.&nbsp;实际点击手指数超过配置值,手势识别失败。 |
## 事件 ## 事件
| 名称 | 功能描述 | | 名称 | 功能描述 |
| -------- | -------- | | -------- | -------- |
| onAction((event?:&nbsp;[GestureEvent](ts-gesture-settings.md))&nbsp;=&gt;&nbsp;void) | Tap手势识别成功回调。 | | onAction(event: (event?: GestureEvent) => void) | Tap手势识别成功回调。 |
## 示例 ## 示例
......
...@@ -3,12 +3,9 @@ ...@@ -3,12 +3,9 @@
可以与容器组件联动用于按逻辑结构快速定位容器显示区域的组件。 可以与容器组件联动用于按逻辑结构快速定位容器显示区域的组件。
> **说明:** > **说明:**
>
> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 权限列表
## 子组件 ## 子组件
...@@ -19,15 +16,17 @@ ...@@ -19,15 +16,17 @@
AlphabetIndexer(value: {arrayValue: Array&lt;string&gt;, selected: number}) AlphabetIndexer(value: {arrayValue: Array&lt;string&gt;, selected: number})
- 参数 **参数:**
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | -------- | -------- | -------- |
| arrayValue | Array&lt;string&gt; | 是 | - | 字母索引字符串数组。 |
| selected | number | 是 | - | 初始选中项索引值。 |
| 参数名 | 参数类型 | 必填 | 参数描述 |
| -------- | -------- | -------- | -------- |
| arrayValue | Array&lt;string&gt; | 是 | 字母索引字符串数组。 |
| selected | number | 是 | 初始选中项索引值。 |
## 属性 ## 属性
除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
| 名称 | 参数类型 | 描述 | | 名称 | 参数类型 | 描述 |
| ----------------------- | --------------- | ----------------------------------------------------------- | | ----------------------- | --------------- | ----------------------------------------------------------- |
| color | [ResourceColor](../../ui/ts-types.md#resourcecolor8) | 设置文字颜色。 | | color | [ResourceColor](../../ui/ts-types.md#resourcecolor8) | 设置文字颜色。 |
...@@ -39,20 +38,22 @@ AlphabetIndexer(value: {arrayValue: Array&lt;string&gt;, selected: number}) ...@@ -39,20 +38,22 @@ AlphabetIndexer(value: {arrayValue: Array&lt;string&gt;, selected: number})
| selectedFont | [Font](../../ui/ts-types.md#font) | 设置选中项文字样式。 | | selectedFont | [Font](../../ui/ts-types.md#font) | 设置选中项文字样式。 |
| popupFont | [Font](../../ui/ts-types.md#font) | 设置提示弹窗字体样式。 | | popupFont | [Font](../../ui/ts-types.md#font) | 设置提示弹窗字体样式。 |
| font | [Font](../../ui/ts-types.md#font) | 设置字母索引条默认字体样式。 | | font | [Font](../../ui/ts-types.md#font) | 设置字母索引条默认字体样式。 |
| itemSize | string \| number | 设置字母索引条字母区域大小,字母区域为正方形,即正方形边长。 | | itemSize | string&nbsp;\|&nbsp;number | 设置字母索引条字母区域大小,字母区域为正方形,即正方形边长。 |
| alignStyle | IndexerAlign | 设置字母索引条弹框的对齐样式,支持弹窗显示在索引条右侧和左侧。<br/>默认值:IndexerAlign.Right | | alignStyle | IndexerAlign | 设置字母索引条弹框的对齐样式,支持弹窗显示在索引条右侧和左侧。<br/>默认值:IndexerAlign.Right |
| selected | number | 设置选中项索引值。 | | selected | number | 设置选中项索引值。 |
| popupPosition | [Position](../../ui/ts-types.md#position8) | 设置弹出窗口相对于索引器条上边框中点的位置。 | | popupPosition | [Position](../../ui/ts-types.md#position8) | 设置弹出窗口相对于索引器条上边框中点的位置。 |
- IndexerAlign枚举说明 ## IndexerAlign枚举说明
| 名称 | 描述 |
| -------- | -------- |
| Left | 弹框显示在索引条右侧。 |
| Right | 弹框显示在索引条左侧。 |
| 名称 | 描述 |
| -------- | -------- |
| Left | 弹框显示在索引条右侧。 |
| Right | 弹框显示在索引条左侧。 |
## 事件 ## 事件
仅支持以下事件:
| 名称 | 功能描述 | | 名称 | 功能描述 |
| -------- | -------- | | -------- | -------- |
| onSelected(callback:&nbsp;(index:&nbsp;number)&nbsp;=&gt;&nbsp;void)<sup>(deprecated)</sup> | 索引条选中回调,返回值为当前选中索引。 | | onSelected(callback:&nbsp;(index:&nbsp;number)&nbsp;=&gt;&nbsp;void)<sup>(deprecated)</sup> | 索引条选中回调,返回值为当前选中索引。 |
......
...@@ -14,13 +14,13 @@ ...@@ -14,13 +14,13 @@
## 接口 ## 接口
Column(value?:{space?: string&nbsp;|&nbsp;number }) Column(value?:{space?: string&nbsp;|&nbsp;number})
**参数:** **参数**
| 参数名 | 参数类型 | 必填 | 参数描述 | | 参数名 | 参数类型 | 必填 | 参数描述 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| space | string&nbsp;\|&nbsp;number | 否 | 纵向布局元素间距。 | | space | string&nbsp;\|&nbsp;number | 否 | 纵向布局元素间距。<br/>默认值:0 |
## 属性 ## 属性
...@@ -31,8 +31,6 @@ Column(value?:{space?: string&nbsp;|&nbsp;number }) ...@@ -31,8 +31,6 @@ Column(value?:{space?: string&nbsp;|&nbsp;number })
| alignItems | [HorizontalAlign](ts-appendix-enums.md#horizontalalign) | 设置子组件在水平方向上的对齐格式。<br/>默认值:HorizontalAlign.Center | | alignItems | [HorizontalAlign](ts-appendix-enums.md#horizontalalign) | 设置子组件在水平方向上的对齐格式。<br/>默认值:HorizontalAlign.Center |
| justifyContent<sup>8+</sup> | [FlexAlign](ts-container-flex.md) | 设置子组件在垂直方向上的对齐格式。<br/>默认值:FlexAlign.Start | | justifyContent<sup>8+</sup> | [FlexAlign](ts-container-flex.md) | 设置子组件在垂直方向上的对齐格式。<br/>默认值:FlexAlign.Start |
## 示例 ## 示例
```ts ```ts
......
...@@ -37,7 +37,7 @@ List(value?: {initialIndex?: number, space?: number | string, scroller?: Scrolle ...@@ -37,7 +37,7 @@ List(value?: {initialIndex?: number, space?: number | string, scroller?: Scrolle
| cachedCount | number | 1 | 设置预加载的ListItem的数量。 | | cachedCount | number | 1 | 设置预加载的ListItem的数量。 |
| editMode | boolean | false | 声明当前List组件是否处于可编辑模式。 | | editMode | boolean | false | 声明当前List组件是否处于可编辑模式。 |
| edgeEffect | [EdgeEffect](ts-appendix-enums.md#edgeeffect) | EdgeEffect.Spring | 滑动效果,目前支持的滑动效果参见EdgeEffect的枚举说明。 | | edgeEffect | [EdgeEffect](ts-appendix-enums.md#edgeeffect) | EdgeEffect.Spring | 滑动效果,目前支持的滑动效果参见EdgeEffect的枚举说明。 |
| chainAnimation | boolean | false | 用于设置当前list是否启用链式联动动效,开启后列表滑动以及顶部和底部拖拽时会有链式联动的效果。链式联动效果:list内的list-item间隔一定距离,在基本的滑动交互行为下,主动对象驱动从动对象进行联动,驱动效果遵循弹簧物理动效。<br/>-&nbsp;false:不启用链式联动。<br/>-&nbsp;true:启用链式联动。 | | chainAnimation | boolean | false | 用于设置当前list是否启用链式联动动效,开启后列表滑动以及顶部和底部拖拽时会有链式联动的效果。链式联动效果:List内的ListItem或ListItemGroup间隔一定距离,在基本的滑动交互行为下,主动对象驱动从动对象进行联动,驱动效果遵循弹簧物理动效。其中ListItemGroup以一个整体参与链式联动动效,ListItemGroup内的ListITem不参与链式联动动效。<br/>-&nbsp;false:不启用链式联动。<br/>-&nbsp;true:启用链式联动。 |
| multiSelectable<sup>8+</sup> | boolean | false | 是否开启鼠标框选。<br/>-&nbsp;false:关闭框选。<br/>-&nbsp;true:开启框选。 | | multiSelectable<sup>8+</sup> | boolean | false | 是否开启鼠标框选。<br/>-&nbsp;false:关闭框选。<br/>-&nbsp;true:开启框选。 |
| lanes<sup>9+</sup> | number \|<br>{<br/>minLength: Length,<br/>maxLength: Length<br/>} | 1 | 以列模式为例(listDirection为Axis.Vertical):<br/>lanes用于决定List组件在交叉轴方向按几列布局,规则如下:<br/>- lanes为指定的数量时,根据指定的数量与List组件的交叉轴宽度来决定每列的宽度;<br/>- lane设置了{minLength,maxLength}时,根据List组件的宽度自适应决定lanes数量(即列数),保证缩放过程中lane的宽度符合{minLength,maxLength}的限制。其中,minLength条件会被优先满足,即优先保证符合ListItem的宽度符合最小宽度限制。例如在列模式下,设置了{minLength: 40vp,maxLength: 60vp},则当List组件宽度为70vp时,ListItem为一列,并且根据alignListItem属性做靠左、居中或者靠右布局;当List组件宽度变化至80vp时,符合两倍的minLength,则ListItem自适应为两列。 | | lanes<sup>9+</sup> | number \|<br>{<br/>minLength: Length,<br/>maxLength: Length<br/>} | 1 | 以列模式为例(listDirection为Axis.Vertical):<br/>lanes用于决定List组件在交叉轴方向按几列布局,规则如下:<br/>- lanes为指定的数量时,根据指定的数量与List组件的交叉轴宽度来决定每列的宽度;<br/>- lane设置了{minLength,maxLength}时,根据List组件的宽度自适应决定lanes数量(即列数),保证缩放过程中lane的宽度符合{minLength,maxLength}的限制。其中,minLength条件会被优先满足,即优先保证符合ListItem的宽度符合最小宽度限制。例如在列模式下,设置了{minLength: 40vp,maxLength: 60vp},则当List组件宽度为70vp时,ListItem为一列,并且根据alignListItem属性做靠左、居中或者靠右布局;当List组件宽度变化至80vp时,符合两倍的minLength,则ListItem自适应为两列。 |
| alignListItem<sup>9+</sup> | [ListItemAlign](#listitemalign9枚举说明) | ListItemAlign.Center | List交叉轴方向宽度大于ListItem交叉轴宽度 * lanes时,ListItem在List交叉轴方向的布局方式,默认为居中。 | | alignListItem<sup>9+</sup> | [ListItemAlign](#listitemalign9枚举说明) | ListItemAlign.Center | List交叉轴方向宽度大于ListItem交叉轴宽度 * lanes时,ListItem在List交叉轴方向的布局方式,默认为居中。 |
...@@ -67,9 +67,9 @@ List(value?: {initialIndex?: number, space?: number | string, scroller?: Scrolle ...@@ -67,9 +67,9 @@ List(value?: {initialIndex?: number, space?: number | string, scroller?: Scrolle
| 名称 | 功能描述 | | 名称 | 功能描述 |
| -------- | -------- | | -------- | -------- |
| onItemDelete(event: (index: number) => boolean) | 列表项删除时触发。 | | onItemDelete(event: (index: number) => boolean) | 当List组件在编辑模式时,点击ListItem右边出现的删除按钮时触发。 |
| onScroll(event: (scrollOffset: number, scrollState: ScrollState) => void) | 列表滑动时触发,返回值scrollOffset为滑动偏移量,[scrollState](#scrollstate枚举说明)为当前滑动状态。 | | onScroll(event: (scrollOffset: number, scrollState: ScrollState) => void) | 列表滑动时触发,返回值scrollOffset为滑动偏移量,[scrollState](#scrollstate枚举说明)为当前滑动状态。 |
| onScrollIndex(event: (start: number, end: number) => void) | 列表滑动时触发,返回值分别为滑动起始位置索引值与滑动结束位置索引值。 | | onScrollIndex(event: (start: number, end: number) => void) | 列表滑动时触发,返回值分别为滑动起始位置索引值与滑动结束位置索引值。计算索引值时,ListItemGroup作为一个整体占一个索引值,不计算ListItemGroup内部ListItem的索引值。 |
| onReachStart(event: () => void) | 列表到达起始位置时触发。 | | onReachStart(event: () => void) | 列表到达起始位置时触发。 |
| onReachEnd(event: () => void) | 列表到底末尾位置时触发。 | | onReachEnd(event: () => void) | 列表到底末尾位置时触发。 |
| onScrollStop(event: () => void) | 列表滑动停止时触发。 | | onScrollStop(event: () => void) | 列表滑动停止时触发。 |
......
...@@ -4,8 +4,11 @@ ...@@ -4,8 +4,11 @@
> **说明:** > **说明:**
> >
> 该组件从API Version 9开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 > - 该组件从API Version 9开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 使用说明
当ListItemGroup的父组件List的listDirection属性为Axis.Vertical时,不允许设置ListItemGroup组件的height属性。ListItemGroup的高度为header高度、footer高度和所有ListItem布局后总高度之和。当父组件List的listDirection属性为Axis.Horizontal时,不允许设置ListItemGroup组件的width属性。ListItemGroup的宽度为header宽度、footer宽度和所有ListItem布局后总宽度之和。
当前ListItemGroup内部的ListItem不支持编辑、框选、拖拽功能,即ListItemGroup内部的ListItem组件editable、selectable属性不生效。
## 子组件 ## 子组件
...@@ -22,7 +25,7 @@ ListItemGroup(options?: {header?: CustomBuilder, footer?: CustomBuilder, space?: ...@@ -22,7 +25,7 @@ ListItemGroup(options?: {header?: CustomBuilder, footer?: CustomBuilder, space?:
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| header | [CustomBuilder](../../ui/ts-types.md#custombuilder8) | 否 | 设置ListItemGroup头部组件。 | | header | [CustomBuilder](../../ui/ts-types.md#custombuilder8) | 否 | 设置ListItemGroup头部组件。 |
| footer | [CustomBuilder](../../ui/ts-types.md#custombuilder8) | 否 | 设置ListItemGroup尾部组件。 | | footer | [CustomBuilder](../../ui/ts-types.md#custombuilder8) | 否 | 设置ListItemGroup尾部组件。 |
| space | number&nbsp;\|&nbsp;string | 否 | 列表项间距。 | | space | number&nbsp;\|&nbsp;string | 否 | 列表项间距。只作用于ListItem与ListItem之间,不作用于header与ListItem、footer与ListItem之间。 |
## 属性 ## 属性
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## 场景介绍 ## 场景介绍
应用要执行对实时性要求不高的任务的时候,比如设备空闲时候做一次数据学习等场景,可以使用延迟调度任务,该机制在满足应用设定条件的时候,会根据系统当前状态,如内存、功耗、温度等统一决策调度时间。 应用要执行对实时性要求不高的任务的时候,比如设备空闲时候做一次数据学习等场景,可以使用延迟调度任务,该机制在满足应用设定条件的时候,会根据系统当前状态,如内存、功耗、温度等统一决策调度时间。延迟任务调度约束见[延迟任务调度概述](./work-scheduler-overview.md)
## 接口说明 ## 接口说明
...@@ -36,28 +36,28 @@ isLastWorkTimeOut(workId: number): Promise\<boolean>;| 获取上次任务是否 ...@@ -36,28 +36,28 @@ isLastWorkTimeOut(workId: number): Promise\<boolean>;| 获取上次任务是否
> **说明:** WorkInfo设置参数约束见[延迟任务调度概述](./work-scheduler-overview.md) > **说明:** WorkInfo设置参数约束见[延迟任务调度概述](./work-scheduler-overview.md)
接口名|描述|类型 参数名| 类型 |描述
---------------------------------------------------------|-----------------------------------------|--------------------------------------------------------- ---------------------------------------------------------|-----------------------------------------|---------------------------------------------------------
workId | 延迟任务Id(必填)|number workId| number | 延迟任务Id(必填)
bundleName | 延迟任务包名(必填)|string bundleName| string | 延迟任务包名(必填)
abilityName | 延迟任务回调通知的组件名(必填)|string abilityName| string | 延迟任务回调通知的组件名(必填)
networkType | 网络类型 | NetworkType networkType | [NetworkType](../reference/apis/js-apis-workScheduler.md#networktype) | 网络类型
isCharging | 是否充电 | boolean isCharging| boolean | 是否充电
chargerType | 充电类型 | ChargingType chargerType| [ChargingType](../reference/apis/js-apis-workScheduler.md#chargingtype) | 充电类型
batteryLevel | 电量| number batteryLevel| number | 电量
batteryStatus| 电池状态| BatteryStatus batteryStatus| [BatteryStatus](../reference/apis/js-apis-workScheduler.md#batterystatus) | 电池状态
storageRequest|存储状态| StorageRequest storageRequest| [StorageRequest](../reference/apis/js-apis-workScheduler.md#storagerequest) |存储状态
isRepeat|是否循环任务| boolean isRepeat| boolean |是否循环任务
repeatCycleTime |循环间隔| number repeatCycleTime| number |循环间隔
repeatCount |循环次数| number repeatCount | number|循环次数
parameters |携带参数信息| {[key: string]: any} parameters | {[key: string]: any} |携带参数信息
**表3** 延迟任务回调接口 **表3** 延迟任务回调接口
接口名 | 接口描述 接口名 | 接口描述
---------------------------------------------------------|----------------------------------------- ---------------------------------------------------------|-----------------------------------------
onWorkStart(work: WorkInfo): void; | 延迟调度任务开始回调 onWorkStart(work: WorkInfo): void | 延迟调度任务开始回调
onWorkStop(work: WorkInfo): void; | 延迟调度任务结束回调 onWorkStop(work: WorkInfo): void | 延迟调度任务结束回调
### 开发步骤 ### 开发步骤
......
...@@ -117,8 +117,8 @@ group("wifi") { ...@@ -117,8 +117,8 @@ group("wifi") {
``` ```
{ {
subsystem": "communication", "subsystem": "communication",
components": [ "components": [
{ "component": "wifi_lite", "features":[] } { "component": "wifi_lite", "features":[] }
] ]
}, },
......
...@@ -23,6 +23,7 @@ applications/sample/hello ...@@ -23,6 +23,7 @@ applications/sample/hello
请在源码目录中通过以下步骤创建“Hello World”应用程序: 请在源码目录中通过以下步骤创建“Hello World”应用程序:
1. 新建目录及源码。 1. 新建目录及源码。
新建**applications/sample/hello/src/helloworld.c**目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改OHOS为World)。当前应用程序可支持标准C及C++的代码开发。 新建**applications/sample/hello/src/helloworld.c**目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改OHOS为World)。当前应用程序可支持标准C及C++的代码开发。
...@@ -40,6 +41,7 @@ applications/sample/hello ...@@ -40,6 +41,7 @@ applications/sample/hello
``` ```
2. 新建编译组织文件。 2. 新建编译组织文件。
新建**applications/sample/hello/BUILD.gn**文件,内容如下所示: 新建**applications/sample/hello/BUILD.gn**文件,内容如下所示:
...@@ -55,6 +57,7 @@ applications/sample/hello ...@@ -55,6 +57,7 @@ applications/sample/hello
``` ```
3. 添加新组件。 3. 添加新组件。
修改文件**build/lite/components/communication.json**,添加组件hello_world_app的配置,如下所示为communication.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): 修改文件**build/lite/components/communication.json**,添加组件hello_world_app的配置,如下所示为communication.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
...@@ -117,6 +120,7 @@ applications/sample/hello ...@@ -117,6 +120,7 @@ applications/sample/hello
``` ```
4. 修改单板配置文件。 4. 修改单板配置文件。
修改文件**vendor/hisilicon/hispark_taurus/config.json**,新增hello_world_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): 修改文件**vendor/hisilicon/hispark_taurus/config.json**,新增hello_world_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
1. 确定目录结构。 1. 确定目录结构。
开发者编写业务时,务必先在./applications/sample/wifi-iot/app路径下新建一个目录(或一套目录结构),用于存放业务源码文件。 开发者编写业务时,务必先在./applications/sample/wifi-iot/app路径下新建一个目录(或一套目录结构),用于存放业务源码文件。
例如:在app下新增业务my_first_app,其中hello_world.c为业务代码,BUILD.gn为编译脚本,具体规划目录结构如下: 例如:在app下新增业务my_first_app,其中hello_world.c为业务代码,BUILD.gn为编译脚本,具体规划目录结构如下:
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
``` ```
2. 编写业务代码。 2. 编写业务代码。
新建./applications/sample/wifi-iot/app/my_first_app下的hello_world.c文件,在hello_world.c中新建业务入口函数HelloWorld,并实现业务逻辑。并在代码最下方,使用OpenHarmony启动恢复模块接口SYS_RUN()启动业务。(SYS_RUN定义在ohos_init.h文件中) 新建./applications/sample/wifi-iot/app/my_first_app下的hello_world.c文件,在hello_world.c中新建业务入口函数HelloWorld,并实现业务逻辑。并在代码最下方,使用OpenHarmony启动恢复模块接口SYS_RUN()启动业务。(SYS_RUN定义在ohos_init.h文件中)
``` ```
...@@ -37,6 +39,7 @@ ...@@ -37,6 +39,7 @@
``` ```
3. 编写用于将业务构建成静态库的BUILD.gn文件。 3. 编写用于将业务构建成静态库的BUILD.gn文件。
新建./applications/sample/wifi-iot/app/my_first_app下的BUILD.gn文件,并完成如下配置。 新建./applications/sample/wifi-iot/app/my_first_app下的BUILD.gn文件,并完成如下配置。
如步骤1所述,BUILD.gn文件由三部分内容(目标、源文件、头文件路径)构成,需由开发者完成填写。 如步骤1所述,BUILD.gn文件由三部分内容(目标、源文件、头文件路径)构成,需由开发者完成填写。
...@@ -58,6 +61,7 @@ ...@@ -58,6 +61,7 @@
- include_dirs中指定source所需要依赖的.h文件路径。 - include_dirs中指定source所需要依赖的.h文件路径。
4. 添加新组件。 4. 添加新组件。
修改文件**build/lite/components/communication.json**,添加组件hello_world_app的配置,如下所示为communication.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): 修改文件**build/lite/components/communication.json**,添加组件hello_world_app的配置,如下所示为communication.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
...@@ -120,6 +124,7 @@ ...@@ -120,6 +124,7 @@
``` ```
5. 修改单板配置文件。 5. 修改单板配置文件。
修改文件**vendor/hisilicon/hispark_pegasus/config.json**,新增hello_world_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): 修改文件**vendor/hisilicon/hispark_pegasus/config.json**,新增hello_world_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
......
...@@ -19,9 +19,9 @@ applications/sample/hello ...@@ -19,9 +19,9 @@ applications/sample/hello
├── bundle.json ├── bundle.json
build build
└── subsystem_config.json └── subsystem_config.json
productdefine/common vendor/hisilicon
└── products └── Hi3516DV300
└── Hi3516DV300.json └── config.json
``` ```
...@@ -31,6 +31,7 @@ productdefine/common ...@@ -31,6 +31,7 @@ productdefine/common
1. 创建目录,编写业务代码。 1. 创建目录,编写业务代码。
新建applications/sample/hello/src/helloworld.c目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改World为OHOS)。其中helloworld.h包含字符串打印函数HelloPrint的声明。当前应用程序可支持标准C及C++的代码开发。 新建applications/sample/hello/src/helloworld.c目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改World为OHOS)。其中helloworld.h包含字符串打印函数HelloPrint的声明。当前应用程序可支持标准C及C++的代码开发。
...@@ -75,6 +76,7 @@ productdefine/common ...@@ -75,6 +76,7 @@ productdefine/common
``` ```
2. 新建编译组织文件。 2. 新建编译组织文件。
1. 新建applications/sample/hello/BUILD.gn文件,内容如下所示: 1. 新建applications/sample/hello/BUILD.gn文件,内容如下所示:
``` ```
...@@ -136,8 +138,8 @@ productdefine/common ...@@ -136,8 +138,8 @@ productdefine/common
bundle.json文件包含两个部分,第一部分描述该部件所属子系统的信息,第二部分component则定义该部件构建相关配置。添加的时候需要指明该部件包含的模块sub_component,假如有提供给其它部件的接口,需要在inner_kits中说明,假如有测试用例,需要在test中说明,inner_kits与test没有也可以不添加。 bundle.json文件包含两个部分,第一部分描述该部件所属子系统的信息,第二部分component则定义该部件构建相关配置。添加的时候需要指明该部件包含的模块sub_component,假如有提供给其它部件的接口,需要在inner_kits中说明,假如有测试用例,需要在test中说明,inner_kits与test没有也可以不添加。
3. 修改子系统配置文件。 3. 修改子系统配置文件。
在build/subsystem_config.json中添加新建的子系统的配置。
在build/subsystem_config.json中添加新建的子系统的配置。
``` ```
"sample": { "sample": {
...@@ -147,8 +149,8 @@ productdefine/common ...@@ -147,8 +149,8 @@ productdefine/common
``` ```
4. 修改产品配置文件。 4. 修改产品配置文件。
在productdefine\common\products\Hi3516DV300.json中添加对应的hello部件,直接添加到原有部件后即可。
在vendor/hisilicon/Hi3516DV300/config.json中添加对应的hello部件,直接添加到原有部件后即可。
``` ```
"usb:usb_manager_native":{}, "usb:usb_manager_native":{},
......
...@@ -19,9 +19,9 @@ applications/sample/hello ...@@ -19,9 +19,9 @@ applications/sample/hello
├── bundle.json ├── bundle.json
build build
└── subsystem_config.json └── subsystem_config.json
productdefine/common vendor/hihope
└── products └── rk3568
└── rk3568.json └── config.json
``` ```
...@@ -30,6 +30,7 @@ productdefine/common ...@@ -30,6 +30,7 @@ productdefine/common
请在源码目录中通过以下步骤创建“Hello World”应用程序: 请在源码目录中通过以下步骤创建“Hello World”应用程序:
1. 创建目录,编写业务代码。 1. 创建目录,编写业务代码。
新建applications/sample/hello/src/helloworld.c目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改World为OHOS)。其中helloworld.h包含字符串打印函数HelloPrint的声明。当前应用程序可支持标准C及C++的代码开发。 新建applications/sample/hello/src/helloworld.c目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改World为OHOS)。其中helloworld.h包含字符串打印函数HelloPrint的声明。当前应用程序可支持标准C及C++的代码开发。
...@@ -74,6 +75,7 @@ productdefine/common ...@@ -74,6 +75,7 @@ productdefine/common
``` ```
2. 新建编译组织文件。 2. 新建编译组织文件。
1. 新建applications/sample/hello/BUILD.gn文件,内容如下所示: 1. 新建applications/sample/hello/BUILD.gn文件,内容如下所示:
``` ```
...@@ -135,6 +137,7 @@ productdefine/common ...@@ -135,6 +137,7 @@ productdefine/common
bundle.json文件包含两个部分,第一部分描述该部件所属子系统的信息,第二部分component则定义该部件构建相关配置。添加的时候需要指明该部件包含的模块sub_component,假如有提供给其它部件的接口,需要在inner_kits中说明,假如有测试用例,需要在test中说明,inner_kits与test没有也可以不添加。 bundle.json文件包含两个部分,第一部分描述该部件所属子系统的信息,第二部分component则定义该部件构建相关配置。添加的时候需要指明该部件包含的模块sub_component,假如有提供给其它部件的接口,需要在inner_kits中说明,假如有测试用例,需要在test中说明,inner_kits与test没有也可以不添加。
3. 修改子系统配置文件。 3. 修改子系统配置文件。
在build/subsystem_config.json中添加新建的子系统的配置。 在build/subsystem_config.json中添加新建的子系统的配置。
...@@ -146,7 +149,8 @@ productdefine/common ...@@ -146,7 +149,8 @@ productdefine/common
``` ```
4. 修改产品配置文件。 4. 修改产品配置文件。
在productdefine\common\products\rk3568.json中添加对应的hello部件,直接添加到原有部件后即可。
在vendor/hihope/rk3568/config.json中添加对应的hello部件,直接添加到原有部件后即可。
``` ```
"usb:usb_manager_native":{}, "usb:usb_manager_native":{},
......
...@@ -23,6 +23,7 @@ applications/sample/hello ...@@ -23,6 +23,7 @@ applications/sample/hello
请在源码目录中通过以下步骤创建“Hello World”应用程序: 请在源码目录中通过以下步骤创建“Hello World”应用程序:
1. 新建目录及源码。 1. 新建目录及源码。
新建**applications/sample/hello/src/helloworld.c**目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改OHOS为World)。当前应用程序可支持标准C及C++的代码开发。 新建**applications/sample/hello/src/helloworld.c**目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改OHOS为World)。当前应用程序可支持标准C及C++的代码开发。
...@@ -40,6 +41,7 @@ applications/sample/hello ...@@ -40,6 +41,7 @@ applications/sample/hello
``` ```
2. 新建编译组织文件。 2. 新建编译组织文件。
新建**applications/sample/hello/BUILD.gn**文件,内容如下所示: 新建**applications/sample/hello/BUILD.gn**文件,内容如下所示:
...@@ -55,6 +57,7 @@ applications/sample/hello ...@@ -55,6 +57,7 @@ applications/sample/hello
``` ```
3. 添加新组件。 3. 添加新组件。
修改文件**build/lite/components/communication.json**,添加组件hello_world_app的配置,如下所示为communication.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): 修改文件**build/lite/components/communication.json**,添加组件hello_world_app的配置,如下所示为communication.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
...@@ -117,6 +120,7 @@ applications/sample/hello ...@@ -117,6 +120,7 @@ applications/sample/hello
``` ```
4. 修改单板配置文件。 4. 修改单板配置文件。
修改文件**vendor/hisilicon/hispark_taurus/config.json**,新增hello_world_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): 修改文件**vendor/hisilicon/hispark_taurus/config.json**,新增hello_world_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
1. 确定目录结构。 1. 确定目录结构。
开发者编写业务时,务必先在./applications/sample/wifi-iot/app路径下新建一个目录(或一套目录结构),用于存放业务源码文件。 开发者编写业务时,务必先在./applications/sample/wifi-iot/app路径下新建一个目录(或一套目录结构),用于存放业务源码文件。
例如:在app下新增业务my_first_app,其中hello_world.c为业务代码,BUILD.gn为编译脚本,具体规划目录结构如下: 例如:在app下新增业务my_first_app,其中hello_world.c为业务代码,BUILD.gn为编译脚本,具体规划目录结构如下:
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
``` ```
2. 编写业务代码。 2. 编写业务代码。
新建./applications/sample/wifi-iot/app/my_first_app下的hello_world.c文件,在hello_world.c中新建业务入口函数HelloWorld,并实现业务逻辑。并在代码最下方,使用OpenHarmony启动恢复模块接口SYS_RUN()启动业务。(SYS_RUN定义在ohos_init.h文件中) 新建./applications/sample/wifi-iot/app/my_first_app下的hello_world.c文件,在hello_world.c中新建业务入口函数HelloWorld,并实现业务逻辑。并在代码最下方,使用OpenHarmony启动恢复模块接口SYS_RUN()启动业务。(SYS_RUN定义在ohos_init.h文件中)
``` ```
...@@ -37,6 +39,7 @@ ...@@ -37,6 +39,7 @@
``` ```
3. 编写用于将业务构建成静态库的BUILD.gn文件。 3. 编写用于将业务构建成静态库的BUILD.gn文件。
新建./applications/sample/wifi-iot/app/my_first_app下的BUILD.gn文件,并完成如下配置。 新建./applications/sample/wifi-iot/app/my_first_app下的BUILD.gn文件,并完成如下配置。
如步骤1所述,BUILD.gn文件由三部分内容(目标、源文件、头文件路径)构成,需由开发者完成填写。 如步骤1所述,BUILD.gn文件由三部分内容(目标、源文件、头文件路径)构成,需由开发者完成填写。
...@@ -58,6 +61,7 @@ ...@@ -58,6 +61,7 @@
- include_dirs中指定source所需要依赖的.h文件路径。 - include_dirs中指定source所需要依赖的.h文件路径。
4. 添加新组件。 4. 添加新组件。
修改文件**build/lite/components/communication.json**,添加组件hello_world_app的配置,如下所示为communication.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): 修改文件**build/lite/components/communication.json**,添加组件hello_world_app的配置,如下所示为communication.json文件片段,"\#\#start\#\#"和"\#\#end\#\#"之间为新增配置("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
...@@ -120,6 +124,7 @@ ...@@ -120,6 +124,7 @@
``` ```
5. 修改单板配置文件。 5. 修改单板配置文件。
修改文件**vendor/hisilicon/hispark_pegasus/config.json**,新增hello_world_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行): 修改文件**vendor/hisilicon/hispark_pegasus/config.json**,新增hello_world_app组件的条目,如下所示代码片段为applications子系统配置,"\#\#start\#\#"和"\#\#end\#\#"之间为新增条目("\#\#start\#\#"和"\#\#end\#\#"仅用来标识位置,添加完配置后删除这两行):
......
...@@ -18,9 +18,9 @@ applications/sample/hello ...@@ -18,9 +18,9 @@ applications/sample/hello
│ └── bundle.json │ └── bundle.json
build build
└── subsystem_config.json └── subsystem_config.json
productdefine/common vendor/hihope
└── products └── rk3568
└── rk3568.json └── config.json
``` ```
...@@ -29,6 +29,7 @@ productdefine/common ...@@ -29,6 +29,7 @@ productdefine/common
请在源码目录中通过以下步骤创建“Hello World”应用程序: 请在源码目录中通过以下步骤创建“Hello World”应用程序:
1. 创建目录,编写业务代码。 1. 创建目录,编写业务代码。
新建applications/sample/hello/src/helloworld.c目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改World为OH)。其中helloworld.h包含字符串打印函数HelloPrint的声明。当前应用程序可支持标准C及C++的代码开发。 新建applications/sample/hello/src/helloworld.c目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改World为OH)。其中helloworld.h包含字符串打印函数HelloPrint的声明。当前应用程序可支持标准C及C++的代码开发。
...@@ -73,6 +74,7 @@ productdefine/common ...@@ -73,6 +74,7 @@ productdefine/common
``` ```
2. 新建编译组织文件。 2. 新建编译组织文件。
1. 新建applications/sample/hello/BUILD.gn文件,内容如下所示: 1. 新建applications/sample/hello/BUILD.gn文件,内容如下所示:
``` ```
...@@ -134,6 +136,7 @@ productdefine/common ...@@ -134,6 +136,7 @@ productdefine/common
bundle.json文件包含两个部分,第一部分描述该部件所属子系统的信息,第二部分component则定义该部件构建相关配置。添加的时候需要指明该部件包含的模块sub_component,假如有提供给其它部件的接口,需要在inner_kits中说明,假如有测试用例,需要在test中说明,inner_kits与test没有也可以不添加。 bundle.json文件包含两个部分,第一部分描述该部件所属子系统的信息,第二部分component则定义该部件构建相关配置。添加的时候需要指明该部件包含的模块sub_component,假如有提供给其它部件的接口,需要在inner_kits中说明,假如有测试用例,需要在test中说明,inner_kits与test没有也可以不添加。
3. 修改子系统配置文件。 3. 修改子系统配置文件。
在build/subsystem_config.json中添加新建的子系统的配置。 在build/subsystem_config.json中添加新建的子系统的配置。
...@@ -145,7 +148,8 @@ productdefine/common ...@@ -145,7 +148,8 @@ productdefine/common
``` ```
4. 修改产品配置文件。 4. 修改产品配置文件。
在productdefine/common/products/rk3568.json中添加对应的hello部件,直接添加到原有部件后即可。
在vendor/hihope/rk3568/config.json中添加对应的hello部件,直接添加到原有部件后即可。
``` ```
"usb:usb_manager_native":{}, "usb:usb_manager_native":{},
......
...@@ -19,9 +19,9 @@ applications/sample/hello ...@@ -19,9 +19,9 @@ applications/sample/hello
├── bundle.json ├── bundle.json
build build
└── subsystem_config.json └── subsystem_config.json
productdefine/common vendor/hisilicon
└── products └── Hi3516DV300
└── Hi3516DV300.json └── config.json
``` ```
...@@ -31,6 +31,7 @@ productdefine/common ...@@ -31,6 +31,7 @@ productdefine/common
1. 创建目录,编写业务代码。 1. 创建目录,编写业务代码。
新建applications/sample/hello/src/helloworld.c目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改World为OH)。其中helloworld.h包含字符串打印函数HelloPrint的声明。当前应用程序可支持标准C及C++的代码开发。 新建applications/sample/hello/src/helloworld.c目录及文件,代码如下所示,用户可以自定义修改打印内容(例如:修改World为OH)。其中helloworld.h包含字符串打印函数HelloPrint的声明。当前应用程序可支持标准C及C++的代码开发。
...@@ -75,6 +76,7 @@ productdefine/common ...@@ -75,6 +76,7 @@ productdefine/common
``` ```
2. 新建编译组织文件。 2. 新建编译组织文件。
1. 新建applications/sample/hello/BUILD.gn文件,内容如下所示: 1. 新建applications/sample/hello/BUILD.gn文件,内容如下所示:
``` ```
...@@ -136,6 +138,7 @@ productdefine/common ...@@ -136,6 +138,7 @@ productdefine/common
bundle.json文件包含两个部分,第一部分描述该部件所属子系统的信息,第二部分component则定义该部件构建相关配置。添加的时候需要指明该部件包含的模块sub_component,假如有提供给其它部件的接口,需要在inner_kits中说明,假如有测试用例,需要在test中说明,inner_kits与test没有也可以不添加。 bundle.json文件包含两个部分,第一部分描述该部件所属子系统的信息,第二部分component则定义该部件构建相关配置。添加的时候需要指明该部件包含的模块sub_component,假如有提供给其它部件的接口,需要在inner_kits中说明,假如有测试用例,需要在test中说明,inner_kits与test没有也可以不添加。
3. 修改子系统配置文件。 3. 修改子系统配置文件。
在build/subsystem_config.json中添加新建的子系统的配置。 在build/subsystem_config.json中添加新建的子系统的配置。
...@@ -147,7 +150,8 @@ productdefine/common ...@@ -147,7 +150,8 @@ productdefine/common
``` ```
4. 修改产品配置文件。 4. 修改产品配置文件。
在productdefine/common/products/Hi3516DV300.json中添加对应的hello部件,直接添加到原有部件后即可。
在vendor/hisilicon/Hi3516DV300/config.json中添加对应的hello部件,直接添加到原有部件后即可。
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册