Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
5884c682
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5884c682
编写于
5月 17, 2023
作者:
O
openharmony_ci
提交者:
Gitee
5月 17, 2023
浏览文件
操作
浏览文件
下载
差异文件
!17989 分布式账号指定localID设置查询信息
Merge pull request !17989 from liushuling/ohos资料
上级
6af1e407
808c118a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
234 addition
and
35 deletion
+234
-35
zh-cn/application-dev/reference/apis/js-apis-distributed-account.md
...ication-dev/reference/apis/js-apis-distributed-account.md
+234
-35
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-distributed-account.md
浏览文件 @
5884c682
...
...
@@ -62,12 +62,14 @@ getOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): voi
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
try
{
accountAbility
.
getOsAccountDistributedInfo
((
err
,
data
)
=>
{
console
.
log
(
"
getOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
console
.
log
(
'
Query account info name:
'
+
data
.
name
);
console
.
log
(
'
Query account info id:
'
+
data
.
id
);
if
(
err
)
{
console
.
log
(
'
getOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
'
distributed information:
'
+
JSON
.
stringify
(
data
));
}
});
}
catch
(
e
)
{
console
.
log
(
"
getOsAccountDistributedInfo exception:
"
+
JSON
.
stringify
(
e
));
}
catch
(
e
rr
)
{
console
.
log
(
'
getOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
}
```
...
...
@@ -98,15 +100,96 @@ getOsAccountDistributedInfo(): Promise<DistributedInfo>
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
try
{
accountAbility
.
getOsAccountDistributedInfo
().
then
((
data
)
=>
{
console
.
log
(
'
Query account info name:
'
+
data
.
name
);
console
.
log
(
'
Query account info id:
'
+
data
.
id
);
console
.
log
(
'
distributed information:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
console
.
log
(
"
getOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
console
.
log
(
'
getOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
"
getOsAccountDistributedInfo exception:
"
+
JSON
.
stringify
(
e
));
}
catch
(
e
rr
)
{
console
.
log
(
'
getOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
}
```
### getOsAccountDistributedInfoByLocalId<sup>10+</sup>
getOsAccountDistributedInfoByLocalId(localId: number, callback: AsyncCallback
<
DistributedInfo
>
): void
获取指定系统账号的分布式信息。使用callback异步回调。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Account.OsAccount
**需要权限:**
ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| localId | number | 是 | 系统帐号ID。 |
| callback | AsyncCallback
<
[DistributedInfo](#distributedinfo)
>
| 是 | 回调参数。当获取分布式帐号信息成功,err为undefined,data为获取到的分布式帐号信息对象;否则为错误对象。 |
**错误码:**
| 错误码ID | 错误信息|
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300003 | Account not found. |
**示例:**
```
js
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
try
{
accountAbility
.
getOsAccountDistributedInfoByLocalId
(
100
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
log
(
'
getOsAccountDistributedInfoByLocalId exception:
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
'
distributed information:
'
+
JSON
.
stringify
(
data
));
}
});
}
catch
(
err
)
{
console
.
log
(
'
getOsAccountDistributedInfoByLocalId exception:
'
+
JSON
.
stringify
(
err
));
}
```
### getOsAccountDistributedInfoByLocalId<sup>10+</sup>
getOsAccountDistributedInfoByLocalId(localId: number): Promise
<
DistributedInfo
>
获取指定系统账号的分布式信息。使用Promise异步回调。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Account.OsAccount
**需要权限:**
ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS 或 ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
[DistributedInfo](#distributedinfo)
>
| Promise对象,返回分布式帐号信息对象。 |
**错误码:**
| 错误码ID | 错误信息|
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300003 | Account not found. |
**示例:**
```
js
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
try
{
accountAbility
.
getOsAccountDistributedInfoByLocalId
(
100
).
then
((
data
)
=>
{
console
.
log
(
'
distributed information:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
console
.
log
(
'
getOsAccountDistributedInfoByLocalId exception:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
err
)
{
console
.
log
(
'
getOsAccountDistributedInfoByLocalId exception:
'
+
JSON
.
stringify
(
err
));
}
```
### queryOsAccountDistributedInfo<sup>(deprecated)</sup>
queryOsAccountDistributedInfo(callback: AsyncCallback
<
DistributedInfo
>
): void
...
...
@@ -130,9 +213,11 @@ queryOsAccountDistributedInfo(callback: AsyncCallback<DistributedInfo>): v
```
js
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
accountAbility
.
queryOsAccountDistributedInfo
((
err
,
data
)
=>
{
console
.
log
(
"
queryOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
console
.
log
(
'
Query account info name:
'
+
data
.
name
);
console
.
log
(
'
Query account info id:
'
+
data
.
id
);
if
(
err
)
{
console
.
log
(
'
queryOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
'
distributed information:
'
+
JSON
.
stringify
(
data
));
}
});
```
...
...
@@ -160,10 +245,9 @@ queryOsAccountDistributedInfo(): Promise<DistributedInfo>
```
js
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
accountAbility
.
queryOsAccountDistributedInfo
().
then
((
data
)
=>
{
console
.
log
(
'
Query account info name:
'
+
data
.
name
);
console
.
log
(
'
Query account info id:
'
+
data
.
id
);
console
.
log
(
'
distributed information:
'
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
console
.
log
(
"
queryOsAccountDistributedInfoerr:
"
+
JSON
.
stringify
(
err
));
console
.
log
(
'
queryOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
});
```
...
...
@@ -198,10 +282,14 @@ setOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallbac
let
accountInfo
=
{
id
:
'
12345
'
,
name
:
'
ZhangSan
'
,
event
:
'
Ohos.account.event.LOGIN
'
};
try
{
accountAbility
.
setOsAccountDistributedInfo
(
accountInfo
,
(
err
)
=>
{
console
.
log
(
"
setOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
if
(
err
)
{
console
.
log
(
'
setOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
'
setOsAccountDistributedInfo successfully
'
);
}
});
}
catch
(
e
)
{
console
.
log
(
"
setOsAccountDistributedInfo exception:
"
+
JSON
.
stringify
(
e
));
}
catch
(
e
rr
)
{
console
.
log
(
'
setOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
}
```
...
...
@@ -241,14 +329,109 @@ setOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void>
let
accountInfo
=
{
id
:
'
12345
'
,
name
:
'
ZhangSan
'
,
event
:
'
Ohos.account.event.LOGIN
'
};
try
{
accountAbility
.
setOsAccountDistributedInfo
(
accountInfo
).
then
(()
=>
{
console
.
log
(
'
setOsAccountDistributedInfo Success
'
);
console
.
log
(
'
setOsAccountDistributedInfo successfully
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
'
setOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
err
)
{
console
.
log
(
'
setOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
}
```
### setOsAccountDistributedInfoByLocalId<sup>10+</sup>
setOsAccountDistributedInfoByLocalId(localId: number, distributedInfo: DistributedInfo, callback: AsyncCallback
<
void
>
): void
设置指定系统帐号的分布式信息。使用callback异步回调。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Account.OsAccount
**需要权限:**
ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| localId | number | 是 | 系统帐号ID。 |
| accountInfo |
[
DistributedInfo
](
#distributedinfo
)
| 是 | 分布式帐号信息。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数。当设置指定系统帐号的分布式信息成功时,err为undefined,否则为错误对象。 |
**错误码:**
| 错误码ID | 错误信息|
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid distributedInfo. |
| 12300003 | Account identified by localId or by distributedInfo not found. |
| 12300008 | Restricted OS account. |
**示例:**
```
js
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
let
accountInfo
=
{
id
:
'
12345
'
,
name
:
'
ZhangSan
'
,
event
:
'
Ohos.account.event.LOGIN
'
};
try
{
accountAbility
.
setOsAccountDistributedInfoByLocalId
(
100
,
accountInfo
,
(
err
)
=>
{
if
(
err
)
{
console
.
log
(
'
setOsAccountDistributedInfoByLocalId exception:
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
'
setOsAccountDistributedInfoByLocalId successfully
'
);
}
});
}
catch
(
err
)
{
console
.
log
(
'
setOsAccountDistributedInfoByLocalId exception:
'
+
JSON
.
stringify
(
err
));
}
```
### setOsAccountDistributedInfoByLocalId<sup>10+</sup>
setOsAccountDistributedInfoByLocalId(localId: number, distributedInfo: DistributedInfo): Promise
<
void
>
设置指定系统帐号的分布式信息。使用Promise异步回调。
**系统接口:**
此接口为系统接口。
**系统能力:**
SystemCapability.Account.OsAccount
**需要权限:**
ohos.permission.MANAGE_DISTRIBUTED_ACCOUNTS
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| localId | number | 是 | 系统帐号ID。 |
| distributedInfo |
[
DistributedInfo
](
#distributedinfo
)
| 是 | 分布式帐户信息。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| Promise对象,无返回结果的Promise对象。 |
**错误码:**
| 错误码ID | 错误信息|
| -------- | ------------------- |
| 12300001 | System service exception. |
| 12300002 | Invalid distributedInfo. |
| 12300003 | Account identified by localId or by distributedInfo not found. |
| 12300008 | Restricted OS account. |
**示例:**
```
js
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
let
accountInfo
=
{
id
:
'
12345
'
,
name
:
'
ZhangSan
'
,
event
:
'
Ohos.account.event.LOGIN
'
};
try
{
accountAbility
.
setOsAccountDistributedInfoByLocalId
(
100
,
accountInfo
).
then
(()
=>
{
console
.
log
(
'
setOsAccountDistributedInfoByLocalId successfully
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
"
setOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
console
.
log
(
'
setOsAccountDistributedInfoByLocalId exception:
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
e
)
{
console
.
log
(
"
setOsAccountDistributedInfo exception:
"
+
JSON
.
stringify
(
e
));
}
catch
(
e
rr
)
{
console
.
log
(
'
setOsAccountDistributedInfoByLocalId exception:
'
+
JSON
.
stringify
(
err
));
}
```
### updateOsAccountDistributedInfo<sup>(deprecated)</sup>
updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCallback
<
void
>
): void
...
...
@@ -275,7 +458,11 @@ updateOsAccountDistributedInfo(accountInfo: DistributedInfo, callback: AsyncCall
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
let
accountInfo
=
{
id
:
'
12345
'
,
name
:
'
ZhangSan
'
,
event
:
'
Ohos.account.event.LOGIN
'
};
accountAbility
.
updateOsAccountDistributedInfo
(
accountInfo
,
(
err
)
=>
{
console
.
log
(
"
queryOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
if
(
err
)
{
console
.
log
(
'
queryOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
'
queryOsAccountDistributedInfo successfully
'
);
}
});
```
...
...
@@ -308,22 +495,34 @@ updateOsAccountDistributedInfo(accountInfo: DistributedInfo): Promise<void>
const
accountAbility
=
account_distributedAccount
.
getDistributedAccountAbility
();
let
accountInfo
=
{
id
:
'
12345
'
,
name
:
'
ZhangSan
'
,
event
:
'
Ohos.account.event.LOGIN
'
};
accountAbility
.
updateOsAccountDistributedInfo
(
accountInfo
).
then
(()
=>
{
console
.
log
(
'
updateOsAccountDistributedInfo
Success
'
);
console
.
log
(
'
updateOsAccountDistributedInfo
successfully
'
);
}).
catch
((
err
)
=>
{
console
.
log
(
"
updateOsAccountDistributedInfo err:
"
+
JSON
.
stringify
(
err
));
console
.
log
(
'
updateOsAccountDistributedInfo exception:
'
+
JSON
.
stringify
(
err
));
});
```
## DistributedInfo
提供操作系统帐
户
的分布式信息。
提供操作系统帐
号
的分布式信息。
**系统能力:**
SystemCapability.Account.OsAccount
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| name | string | 是 | 分布式帐号名称,非空字符串。 |
| id | string | 是 | 分布式帐号UID,非空字符串。 |
| event | string | 是 | 分布式帐号登录状态,包括登录、登出、Token失效和注销,分别对应以下字符串:
<br/>
-
Ohos.account.event.LOGIN
<br/>
-
Ohos.account.event.LOGOUT
<br/>
-
Ohos.account.event.TOKEN_INVALID
<br/>
-
Ohos.account.event.LOGOFF |
| nickname
<sup>
9+
</sup>
| string | 否 | 分布式帐号的昵称,非空字符串。 |
| avatar
<sup>
9+
</sup>
| string | 否 | 分布式帐号的头像,非空字符串。 |
| scalableData
<sup>
8+
</sup>
| object | 否 | 分布式帐号扩展信息,根据业务所需,以k-v形式传递定制化信息。
<br/>
说明:该参数是预留的可选项,目前查询和更新的方法实现中未使用。 |
| 名称 | 类型 | 只读 | 必填 | 说明 |
| -------- | -------- | -------- |-------- | -------- |
| name | string | 否 |是 | 分布式帐号名称,非空字符串。 |
| id | string | 否 |是 | 分布式帐号UID,非空字符串。 |
| event | string | 否 |是 | 分布式帐号登录状态,包括登录、登出、Token失效和注销,分别对应以下字符串:
<br/>
-
Ohos.account.event.LOGIN
<br/>
-
Ohos.account.event.LOGOUT
<br/>
-
Ohos.account.event.TOKEN_INVALID
<br/>
-
Ohos.account.event.LOGOFF |
| nickname
<sup>
9+
</sup>
| string | 否 |否 | 分布式帐号的昵称,默认为空。 |
| avatar
<sup>
9+
</sup>
| string | 否 |否 | 分布式帐号的头像,默认为空。 |
| status
<sup>
10+
</sup>
|
[
DistributedAccountStatus
](
#distributedaccountstatus10
)
| 是 |否 | 分布式帐号的状态,枚举类型,默认为未登录状态。 |
| scalableData
<sup>
8+
</sup>
| object | 否 |否 | 分布式帐号扩展信息,根据业务所需,以k-v形式传递定制化信息,默认为空。|
## DistributedAccountStatus<sup>10+</sup>
表示分布式帐号状态枚举。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Account.OsAccount
| 名称 | 值 | 说明 |
| ---- | ------ | ----------- |
| NOT_LOGGED_IN | 0 | 未登录状态。 |
| LOGGED_IN | 1 | 已登录状态。 |
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录