Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
352614bd
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看板
提交
352614bd
编写于
9月 06, 2023
作者:
X
xuzhihao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Bugfix: ArkTs整改
Signed-off-by:
N
xuzhihao
<
xuzhihao16@huawei.com
>
上级
c448dcbc
变更
31
展开全部
显示空白变更内容
内联
并排
Showing
31 changed file
with
2052 addition
and
1345 deletion
+2052
-1345
zh-cn/application-dev/application-models/arkts-ui-widget-event-call.md
...tion-dev/application-models/arkts-ui-widget-event-call.md
+36
-15
zh-cn/application-dev/application-models/arkts-ui-widget-event-formextensionability.md
...tion-models/arkts-ui-widget-event-formextensionability.md
+4
-4
zh-cn/application-dev/application-models/arkts-ui-widget-event-router.md
...on-dev/application-models/arkts-ui-widget-event-router.md
+15
-12
zh-cn/application-dev/application-models/arkts-ui-widget-event-uiability.md
...dev/application-models/arkts-ui-widget-event-uiability.md
+57
-28
zh-cn/application-dev/application-models/arkts-ui-widget-image-update.md
...on-dev/application-models/arkts-ui-widget-image-update.md
+84
-81
zh-cn/application-dev/application-models/arkts-ui-widget-lifecycle.md
...ation-dev/application-models/arkts-ui-widget-lifecycle.md
+64
-66
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-proxy.md
...dev/application-models/arkts-ui-widget-update-by-proxy.md
+45
-37
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-status.md
...ev/application-models/arkts-ui-widget-update-by-status.md
+40
-34
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-time.md
...-dev/application-models/arkts-ui-widget-update-by-time.md
+4
-3
zh-cn/application-dev/application-models/common-event-publish.md
...pplication-dev/application-models/common-event-publish.md
+7
-5
zh-cn/application-dev/application-models/common-event-remove-sticky.md
...tion-dev/application-models/common-event-remove-sticky.md
+2
-1
zh-cn/application-dev/application-models/common-event-static-subscription.md
...ev/application-models/common-event-static-subscription.md
+3
-2
zh-cn/application-dev/application-models/common-event-subscription.md
...ation-dev/application-models/common-event-subscription.md
+5
-4
zh-cn/application-dev/application-models/common-event-unsubscription.md
...ion-dev/application-models/common-event-unsubscription.md
+2
-1
zh-cn/application-dev/reference/apis/js-apis-app-form-formBindingData.md
...on-dev/reference/apis/js-apis-app-form-formBindingData.md
+6
-5
zh-cn/application-dev/reference/apis/js-apis-app-form-formExtensionAbility.md
...v/reference/apis/js-apis-app-form-formExtensionAbility.md
+21
-23
zh-cn/application-dev/reference/apis/js-apis-app-form-formHost.md
...plication-dev/reference/apis/js-apis-app-form-formHost.md
+39
-39
zh-cn/application-dev/reference/apis/js-apis-app-form-formProvider.md
...ation-dev/reference/apis/js-apis-app-form-formProvider.md
+28
-43
zh-cn/application-dev/reference/apis/js-apis-application-formBindingData.md
...dev/reference/apis/js-apis-application-formBindingData.md
+2
-1
zh-cn/application-dev/reference/apis/js-apis-application-formHost.md
...cation-dev/reference/apis/js-apis-application-formHost.md
+3
-3
zh-cn/application-dev/reference/apis/js-apis-application-formProvider.md
...on-dev/reference/apis/js-apis-application-formProvider.md
+9
-19
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
+22
-2
zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md
...lication-dev/reference/apis/js-apis-commonEventManager.md
+26
-1
zh-cn/application-dev/reference/apis/js-apis-emitter.md
zh-cn/application-dev/reference/apis/js-apis-emitter.md
+21
-24
zh-cn/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md
...ce/apis/js-apis-inner-application-formExtensionContext.md
+4
-4
zh-cn/application-dev/reference/apis/js-apis-inner-notification-notificationFlags.md
...ence/apis/js-apis-inner-notification-notificationFlags.md
+2
-0
zh-cn/application-dev/reference/apis/js-apis-inner-notification-notificationSubscriber.md
...apis/js-apis-inner-notification-notificationSubscriber.md
+130
-116
zh-cn/application-dev/reference/apis/js-apis-notification.md
zh-cn/application-dev/reference/apis/js-apis-notification.md
+853
-571
zh-cn/application-dev/reference/apis/js-apis-notificationManager.md
...ication-dev/reference/apis/js-apis-notificationManager.md
+348
-73
zh-cn/application-dev/reference/apis/js-apis-notificationSubscribe.md
...ation-dev/reference/apis/js-apis-notificationSubscribe.md
+168
-122
zh-cn/application-dev/reference/apis/js-apis-system-notification.md
...ication-dev/reference/apis/js-apis-system-notification.md
+2
-6
未找到文件。
zh-cn/application-dev/application-models/arkts-ui-widget-event-call.md
浏览文件 @
352614bd
...
...
@@ -53,27 +53,48 @@
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
Base
from
'
@ohos.base
'
import
rpc
from
'
@ohos.rpc
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
AbilityConstant
from
'
@ohos.app.ability.AbilityConstant
'
;
function
FunACall
(
data
)
{
// 获取call事件中传递的所有参数
console
.
info
(
'
FunACall param:
'
+
JSON
.
stringify
(
data
.
readString
()));
return
null
;
}
function
FunBCall
(
data
)
{
console
.
info
(
'
FunBCall param:
'
+
JSON
.
stringify
(
data
.
readString
()));
return
null
;
class
MyParcelable
implements
rpc
.
Parcelable
{
num
:
number
;
str
:
string
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
}
marshalling
(
messageSequence
:
rpc
.
MessageSequence
):
boolean
{
messageSequence
.
writeInt
(
this
.
num
);
messageSequence
.
writeString
(
this
.
str
);
return
true
;
}
unmarshalling
(
messageSequence
:
rpc
.
MessageSequence
):
boolean
{
this
.
num
=
messageSequence
.
readInt
();
this
.
str
=
messageSequence
.
readString
();
return
true
;
}
}
export
default
class
CameraAbility
extends
UIAbility
{
// 如果UIAbility第一次启动,在收到call事件后会触发onCreate生命周期回调
onCreate
(
want
,
l
aunchParam
)
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
try
{
// 监听call事件所需的方法
this
.
callee
.
on
(
'
funA
'
,
FunACall
);
this
.
callee
.
on
(
'
funB
'
,
FunBCall
);
this
.
callee
.
on
(
'
funA
'
,
(
data
:
rpc
.
MessageSequence
)
=>
{
// 获取call事件中传递的所有参数
console
.
info
(
'
FunACall param:
'
+
JSON
.
stringify
(
data
.
readString
()));
return
new
MyParcelable
(
1
,
'
aaa
'
);
});
this
.
callee
.
on
(
'
funB
'
,
(
data
:
rpc
.
MessageSequence
)
=>
{
// 获取call事件中传递的所有参数
console
.
info
(
'
FunACall param:
'
+
JSON
.
stringify
(
data
.
readString
()));
return
new
MyParcelable
(
2
,
'
bbb
'
);
});
}
catch
(
err
)
{
console
.
error
(
`Failed to register callee on. Cause:
${
JSON
.
stringify
(
err
)}
`
);
console
.
error
(
`Failed to register callee on. Cause:
${
JSON
.
stringify
(
err
as
Base
.
BusinessError
)}
`
);
}
}
...
...
@@ -85,7 +106,7 @@
this
.
callee
.
off
(
'
funA
'
);
this
.
callee
.
off
(
'
funB
'
);
}
catch
(
err
)
{
console
.
error
(
`Failed to register callee off. Cause:
${
JSON
.
stringify
(
err
)}
`
);
console
.
error
(
`Failed to register callee off. Cause:
${
JSON
.
stringify
(
err
as
Base
.
BusinessError
)}
`
);
}
}
};
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-event-formextensionability.md
浏览文件 @
352614bd
...
...
@@ -52,10 +52,10 @@
let
formData
=
new
Map
<
Object
,
string
>
();
formData
.
set
(
'
title
'
,
'
Title Update.
'
);
// 和卡片布局中对应
formData
.
set
(
'
detail
'
,
'
Description update success.
'
);
// 和卡片布局中对应
let
formInfo
=
formBindingData
.
createFormBindingData
(
formData
)
formProvider
.
updateForm
(
formId
,
formInfo
).
then
((
data
)
=>
{
console
.
info
(
'
FormAbility updateForm success.
'
+
JSON
.
stringify
(
data
)
);
})
let
formInfo
:
formBindingData
.
FormBindingData
=
formBindingData
.
createFormBindingData
(
formData
);
formProvider
.
updateForm
(
formId
,
formInfo
).
then
(()
=>
{
console
.
info
(
'
FormAbility updateForm success.
'
);
})
;
}
...
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-event-router.md
浏览文件 @
352614bd
...
...
@@ -54,26 +54,29 @@
```
ts
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
window
from
'
@ohos.window
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
Base
from
'
@ohos.base
'
;
import
AbilityConstant
from
'
@ohos.app.ability.AbilityConstant
'
;
let
selectPage
=
""
;
let
currentWindowStage
=
null
;
let
selectPage
:
string
=
""
;
let
currentWindowStage
:
window
.
WindowStage
|
null
=
null
;
export
default
class
EntryAbility
extends
UIAbility
{
// 如果UIAbility第一次启动,在收到Router事件后会触发onCreate生命周期回调
onCreate
(
want
,
l
aunchParam
)
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
// 获取router事件中传递的targetPage参数
console
.
info
(
"
onCreate want:
"
+
JSON
.
stringify
(
want
));
if
(
want
.
parameters
.
params
!==
undefined
)
{
let
params
=
JSON
.
parse
(
want
.
parameters
.
params
);
if
(
want
.
parameters
?
.
params
!==
undefined
)
{
let
params
:
Record
<
string
,
string
>
=
JSON
.
parse
(
JSON
.
stringify
(
want
.
parameters
?.
params
)
);
console
.
info
(
"
onCreate router targetPage:
"
+
params
.
targetPage
);
selectPage
=
params
.
targetPage
;
}
}
// 如果UIAbility已在后台运行,在收到Router事件后会触发onNewWant生命周期回调
onNewWant
(
want
,
l
aunchParam
)
{
onNewWant
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
console
.
info
(
"
onNewWant want:
"
+
JSON
.
stringify
(
want
));
if
(
want
.
parameters
.
params
!==
undefined
)
{
let
params
=
JSON
.
parse
(
want
.
parameters
.
params
);
if
(
want
.
parameters
?
.
params
!==
undefined
)
{
let
params
:
Record
<
string
,
string
>
=
JSON
.
parse
(
JSON
.
stringify
(
want
.
parameters
?.
params
)
);
console
.
info
(
"
onNewWant router targetPage:
"
+
params
.
targetPage
);
selectPage
=
params
.
targetPage
;
}
...
...
@@ -83,7 +86,7 @@
}
onWindowStageCreate
(
windowStage
:
window
.
WindowStage
)
{
let
targetPage
;
let
targetPage
:
string
;
// 根据传递的targetPage不同,选择拉起不同的页面
switch
(
selectPage
)
{
case
'
funA
'
:
...
...
@@ -98,7 +101,7 @@
if
(
currentWindowStage
===
null
)
{
currentWindowStage
=
windowStage
;
}
windowStage
.
loadContent
(
targetPage
,
(
err
,
data
)
=>
{
windowStage
.
loadContent
(
targetPage
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
&&
err
.
code
)
{
console
.
info
(
'
Failed to load the content. Cause: %{public}s
'
,
JSON
.
stringify
(
err
));
return
;
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-event-uiability.md
浏览文件 @
352614bd
...
...
@@ -44,30 +44,33 @@
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
import
AbilityConstant
from
'
@ohos.app.ability.AbilityConstant
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
Base
from
'
@ohos.base
'
export
default
class
EntryAbility
extends
UIAbility
{
// 如果UIAbility第一次启动,在收到Router事件后会触发onCreate生命周期回调
onCreate
(
want
,
l
aunchParam
)
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
this
.
handleFormRouterEvent
(
want
);
}
// 如果UIAbility已在后台运行,在收到Router事件后会触发onNewWant生命周期回调
onNewWant
(
want
,
l
aunchParam
)
{
onNewWant
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
this
.
handleFormRouterEvent
(
want
);
}
handleFormRouterEvent
(
want
)
{
handleFormRouterEvent
(
want
:
Want
)
{
console
.
info
(
'
Want:
'
+
JSON
.
stringify
(
want
));
if
(
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
]
!==
undefined
)
{
let
curFormId
=
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
]
;
let
message
=
JSON
.
parse
(
want
.
parameters
.
params
).
detail
;
if
(
want
.
parameters
&&
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
]
!==
undefined
)
{
let
curFormId
=
JSON
.
stringify
(
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
])
;
let
message
:
string
=
JSON
.
parse
(
JSON
.
stringify
(
want
.
parameters
.
params
)
).
detail
;
console
.
info
(
`UpdateForm formId:
${
curFormId
}
, message:
${
message
}
`
);
let
formData
=
{
let
formData
:
Record
<
string
,
string
>
=
{
"
detail
"
:
message
+
'
: UIAbility.
'
,
// 和卡片布局中对应
};
let
formMsg
=
formBindingData
.
createFormBindingData
(
formData
)
formProvider
.
updateForm
(
curFormId
,
formMsg
).
then
((
data
)
=>
{
console
.
info
(
'
updateForm success.
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
updateForm failed:
'
+
JSON
.
stringify
(
error
));
})
}
...
...
@@ -83,17 +86,20 @@
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onAddForm
(
want
)
{
let
formId
=
want
.
parameters
[
"
ohos.extra.param.key.form_identity
"
];
let
dataObj1
=
{
onAddForm
(
want
:
Want
)
{
let
dataObj1
:
Record
<
string
,
string
>
|
undefined
;
if
(
want
.
parameters
&&
want
.
parameters
[
"
ohos.extra.param.key.form_identity
"
]
!=
undefined
)
{
let
formId
:
string
=
JSON
.
parse
(
JSON
.
stringify
(
want
.
parameters
[
"
ohos.extra.param.key.form_identity
"
]));
dataObj1
=
{
"
formId
"
:
formId
};
}
let
obj1
=
formBindingData
.
createFormBindingData
(
dataObj1
);
return
obj1
;
}
...
};
```
...
...
@@ -138,40 +144,63 @@
import
UIAbility
from
'
@ohos.app.ability.UIAbility
'
;
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
Base
from
'
@ohos.base
'
import
rpc
from
'
@ohos.rpc
'
;
import
AbilityConstant
from
'
@ohos.app.ability.AbilityConstant
'
;
const
MSG_SEND_METHOD
:
string
=
'
funA
'
;
class
MyParcelable
implements
rpc
.
Parcelable
{
num
:
number
;
str
:
string
;
constructor
(
num
:
number
,
str
:
string
)
{
this
.
num
=
num
;
this
.
str
=
str
;
}
marshalling
(
messageSequence
:
rpc
.
MessageSequence
):
boolean
{
messageSequence
.
writeInt
(
this
.
num
);
messageSequence
.
writeString
(
this
.
str
);
return
true
;
}
unmarshalling
(
messageSequence
:
rpc
.
MessageSequence
):
boolean
{
this
.
num
=
messageSequence
.
readInt
();
this
.
str
=
messageSequence
.
readString
();
return
true
;
}
}
// 在收到call事件后会触发callee监听的方法
function
FunACall
(
data
)
{
let
FunACall
=
(
data
:
rpc
.
MessageSequence
)
=>
{
// 获取call事件中传递的所有参数
let
params
=
JSON
.
parse
(
data
.
readString
())
let
params
:
Record
<
string
,
string
>
=
JSON
.
parse
(
data
.
readString
())
if
(
params
.
formId
!==
undefined
)
{
let
curFormId
=
params
.
formId
;
let
message
=
params
.
detail
;
let
curFormId
:
string
=
params
.
formId
;
let
message
:
string
=
params
.
detail
;
console
.
info
(
`UpdateForm formId:
${
curFormId
}
, message:
${
message
}
`
);
let
formData
=
{
let
formData
:
Record
<
string
,
string
>
=
{
"
detail
"
:
message
};
let
formMsg
=
formBindingData
.
createFormBindingData
(
formData
)
let
formMsg
:
formBindingData
.
FormBindingData
=
formBindingData
.
createFormBindingData
(
formData
);
formProvider
.
updateForm
(
curFormId
,
formMsg
).
then
((
data
)
=>
{
console
.
info
(
'
updateForm success.
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
updateForm failed:
'
+
JSON
.
stringify
(
error
));
})
}
return
n
ull
;
return
n
ew
MyParcelable
(
1
,
'
aaa
'
)
;
}
export
default
class
EntryAbility
extends
UIAbility
{
// 如果UIAbility第一次启动,call事件后会触发onCreate生命周期回调
onCreate
(
want
,
l
aunchParam
)
{
onCreate
(
want
:
Want
,
launchParam
:
AbilityConstant
.
L
aunchParam
)
{
console
.
info
(
'
Want:
'
+
JSON
.
stringify
(
want
));
try
{
// 监听call事件所需的方法
this
.
callee
.
on
(
MSG_SEND_METHOD
,
FunACall
);
}
catch
(
error
)
{
console
.
info
(
`
${
MSG_SEND_METHOD
}
register failed with error
${
JSON
.
stringify
(
error
)}
`
)
console
.
info
(
`
${
MSG_SEND_METHOD
}
register failed with error
${
JSON
.
stringify
(
error
as
Base
.
BusinessError
)}
`
)
}
}
...
}
```
\ No newline at end of file
zh-cn/application-dev/application-models/arkts-ui-widget-image-update.md
浏览文件 @
352614bd
...
...
@@ -14,27 +14,30 @@
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
request
from
'
@ohos.request
'
;
import
fs
from
'
@ohos.file.fs
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
Base
from
'
@ohos.base
'
;
import
fileFs
from
'
@ohos.file.fs
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
...
// 在添加卡片时,打开一个本地图片并将图片内容传递给卡片页面显示
onAddForm
(
w
ant
)
{
onAddForm
(
want
:
W
ant
)
{
// 假设在当前卡片应用的tmp目录下有一个本地图片:head.PNG
let
tempDir
=
this
.
context
.
getApplicationContext
().
tempDir
;
// 打开本地图片并获取其打开后的fd
let
file
;
let
file
:
fileFs
.
File
;
let
formData
=
new
Map
<
string
,
Object
>
();
formData
.
set
(
'
text
'
,
'
Image: Bear
'
);
formData
.
set
(
'
imgName
'
,
'
imgBear
'
);
formData
.
set
(
'
loaded
'
,
true
);
try
{
file
=
fs
.
openSync
(
tempDir
+
'
/
'
+
'
head.PNG
'
);
}
catch
(
e
)
{
console
.
error
(
`openSync failed:
${
JSON
.
stringify
(
e
)}
`
);
}
let
formData
=
{
'
text
'
:
'
Image: Bear
'
,
'
imgName
'
:
'
imgBear
'
,
'
formImages
'
:
{
let
imgBear
:
Record
<
string
,
number
>
=
{
'
imgBear
'
:
file
.
fd
},
'
loaded
'
:
true
}
formData
.
set
(
'
formImages
'
,
imgBear
);
}
catch
(
e
)
{
console
.
error
(
`openSync failed:
${
JSON
.
stringify
(
e
as
Base
.
BusinessError
)}
`
);
}
// 将fd封装在formData中并返回至卡片页面
return
formBindingData
.
createFormBindingData
(
formData
);
...
...
@@ -52,10 +55,12 @@
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
request
from
'
@ohos.request
'
;
import
fs
from
'
@ohos.file.fs
'
;
import
Base
from
'
@ohos.base
'
;
import
fileFs
from
'
@ohos.file.fs
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
// 在卡片页面触发message事件时,下载一个网络图片,并将网络图片内容传递给卡片页面显示
onFormEvent
(
formId
,
message
)
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
let
formInfo
=
formBindingData
.
createFormBindingData
({
'
text
'
:
'
刷新中...
'
})
...
...
@@ -69,42 +74,40 @@
request
.
downloadFile
(
this
.
context
,
{
url
:
netFile
,
filePath
:
tmpFile
,
enableMetered
:
true
,
enableRoaming
:
true
}).
then
((
task
)
=>
{
task
.
on
(
'
complete
'
,
function
callback
()
{
task
.
on
(
'
complete
'
,
()
=>
{
console
.
info
(
'
ArkTSCard download complete:
'
+
tmpFile
);
let
file
;
let
file
:
fileFs
.
File
;
let
formData
=
new
Map
<
string
,
Object
>
();
try
{
file
=
fs
.
openSync
(
tmpFile
);
formData
.
set
(
'
text
'
,
'
Image: Bear
'
+
fileName
);
formData
.
set
(
'
imgName
'
,
'
imgBear
'
+
fileName
);
formData
.
set
(
'
loaded
'
,
true
);
let
imgBear
:
Record
<
string
,
number
>
=
{
'
imgBear
'
:
file
.
fd
};
formData
.
set
(
'
formImages
'
,
imgBear
);
}
catch
(
e
)
{
console
.
error
(
`openSync failed:
${
JSON
.
stringify
(
e
)}
`
);
console
.
error
(
`openSync failed:
${
JSON
.
stringify
(
e
as
Base
.
BusinessError
)}
`
);
}
let
fileInfo
=
{};
fileInfo
[
fileName
]
=
file
.
fd
;
let
formData
=
{
'
text
'
:
'
Image:
'
+
fileName
,
'
imgName
'
:
fileName
,
'
formImages
'
:
fileInfo
,
'
loaded
'
:
true
};
let
formInfo
=
formBindingData
.
createFormBindingData
(
formData
)
formProvider
.
updateForm
(
formId
,
formInfo
).
then
((
data
)
=>
{
console
.
info
(
'
FormAbility updateForm success.
'
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
let
formInfo
=
formBindingData
.
createFormBindingData
(
formData
);
formProvider
.
updateForm
(
formId
,
formInfo
).
then
(()
=>
{
console
.
info
(
'
FormAbility updateForm success.
'
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
FormAbility updateForm failed:
'
+
JSON
.
stringify
(
error
));
});
})
})
task
.
on
(
'
fail
'
,
function
callBack
(
err
)
{
task
.
on
(
'
fail
'
,
(
err
:
number
)
=>
{
console
.
info
(
'
ArkTSCard download task failed. Cause:
'
+
err
);
let
formInfo
=
formBindingData
.
createFormBindingData
({
'
text
'
:
'
刷新失败
'
})
formProvider
.
updateForm
(
formId
,
formInfo
)
});
}).
catch
((
er
r
)
=>
{
}).
catch
((
err
:
Base
.
BusinessErro
r
)
=>
{
console
.
error
(
'
Failed to request the download. Cause:
'
+
JSON
.
stringify
(
err
));
});
}
...
};
```
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-lifecycle.md
浏览文件 @
352614bd
...
...
@@ -20,14 +20,16 @@
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
{
Configuration
}
from
'
@ohos.app.ability.Configuration
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
formInfo
from
'
@ohos.app.form.formInfo
'
;
import
Base
from
'
@ohos.base
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onAddForm
(
w
ant
)
{
onAddForm
(
want
:
W
ant
)
{
console
.
info
(
'
[EntryFormAbility] onAddForm
'
);
// 在入参want中可以取出卡片的唯一标识:formId
let
formId
:
string
=
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
];
// 使用方创建卡片时触发,提供方需要返回卡片数据绑定类
let
obj
=
{
let
obj
:
Record
<
string
,
string
>
=
{
'
title
'
:
'
titleOnAddForm
'
,
'
detail
'
:
'
detailOnAddForm
'
};
...
...
@@ -35,54 +37,50 @@
return
formData
;
}
onCastToNormalForm
(
formId
)
{
onCastToNormalForm
(
formId
:
string
)
{
// Called when the form provider is notified that a temporary form is successfully
// converted to a normal form.
// 使用方将临时卡片转换为常态卡片触发,提供方需要做相应的处理
console
.
info
(
`[EntryFormAbility] onCastToNormalForm, formId:
${
formId
}
`
);
}
onUpdateForm
(
formId
)
{
onUpdateForm
(
formId
:
string
)
{
// 若卡片支持定时更新/定点更新/卡片使用方主动请求更新功能,则提供方需要重写该方法以支持数据更新
console
.
info
(
'
[EntryFormAbility] onUpdateForm
'
);
let
obj
=
{
let
obj
:
Record
<
string
,
string
>
=
{
'
title
'
:
'
titleOnUpdateForm
'
,
'
detail
'
:
'
detailOnUpdateForm
'
};
let
formData
=
formBindingData
.
createFormBindingData
(
obj
);
formProvider
.
updateForm
(
formId
,
formData
).
catch
((
err
)
=>
{
if
(
err
)
{
// 异常分支打印
formProvider
.
updateForm
(
formId
,
formData
).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`[EntryFormAbility] Failed to updateForm. Code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
return
;
}
});
}
onChangeFormVisibility
(
newStatus
)
{
onChangeFormVisibility
(
newStatus
:
Record
<
string
,
number
>
)
{
// Called when the form provider receives form events from the system.
// 需要配置formVisibleNotify为true,且为系统应用才会回调
console
.
info
(
'
[EntryFormAbility] onChangeFormVisibility
'
);
}
onFormEvent
(
formId
,
message
)
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
// Called when a specified message event defined by the form provider is triggered.
// 若卡片支持触发事件,则需要重写该方法并实现对事件的触发
console
.
info
(
'
[EntryFormAbility] onFormEvent
'
);
}
onRemoveForm
(
formId
)
{
onRemoveForm
(
formId
:
string
)
{
// Called to notify the form provider that a specified form has been destroyed.
// 当对应的卡片删除时触发的回调,入参是被删除的卡片ID
console
.
info
(
'
[EntryFormAbility] onRemoveForm
'
);
}
onConfigurationUpdate
(
config
)
{
onConfigurationUpdate
(
config
:
Configuration
)
{
// 当系统配置信息置更新时触发的回调
console
.
info
(
'
[EntryFormAbility] configurationUpdate:
'
+
JSON
.
stringify
(
config
));
}
onAcquireFormState
(
w
ant
)
{
onAcquireFormState
(
want
:
W
ant
)
{
// Called to return a {@link FormState} object.
// 卡片提供方接收查询卡片状态通知接口,默认返回卡片初始状态。
return
formInfo
.
FormState
.
READY
;
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-proxy.md
浏览文件 @
352614bd
...
...
@@ -76,11 +76,13 @@
> key可以是uri也可以是简单字符串,subscriberId默认值为当前formId,实际取值都依赖于数据发布方的定义。
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
let
dataShareHelper
;
onAddForm
(
w
ant
)
{
let
formData
=
{};
let
proxies
=
[
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onAddForm
(
want
:
W
ant
)
{
let
formData
:
Record
<
string
,
Object
>
=
{};
let
proxies
:
formBindingData
.
ProxyData
[]
=
[
{
"
key
"
:
"
detail
"
,
"
subscriberId
"
:
"
11
"
...
...
@@ -90,6 +92,7 @@
formBinding
[
"
proxies
"
]
=
proxies
;
return
formBinding
;
}
}
```
-
在
[
卡片页面文件
](
arkts-ui-widget-creation.md
)
中,通过LocalStorage变量获取订阅到的数据,LocalStorage绑定了一个字符串,以key:value的键值对格式来刷新卡片订阅数据,其中key必须与卡片提供方订阅的key保持一致。示例中,通过'detail'获取订阅的数据,并在Text组件显示。
...
...
@@ -151,24 +154,28 @@
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
dataShare
from
'
@ohos.data.dataShare
'
let
dataShareHelper
;
onAddForm
(
want
)
{
let
template
=
{
predicates
:
{
"
list
"
:
"
select type from TBL00 limit 0,1
"
import
dataShare
from
'
@ohos.data.dataShare
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
let
dataShareHelper
:
dataShare
.
DataShareHelper
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onAddForm
(
want
:
Want
)
{
let
template
:
dataShare
.
Template
=
{
predicates
:
{
"
list
"
:
"
select type from TBL00 limit 0,1
"
},
scheduler
:
""
}
let
subscriberId
=
"
111
"
;
dataShare
.
createDataShareHelper
(
this
.
context
,
"
datashareproxy://com.example.myapplication
"
,
{
isProxy
:
true
}).
then
((
data
)
=>
{
let
subscriberId
:
string
=
"
111
"
;
dataShare
.
createDataShareHelper
(
this
.
context
,
"
datashareproxy://com.example.myapplication
"
,
{
isProxy
:
true
}).
then
((
data
:
dataShare
.
DataShareHelper
)
=>
{
dataShareHelper
=
data
;
dataShareHelper
.
addTemplate
(
"
datashareproxy://com.example.myapplication/test
"
,
subscriberId
,
template
);
})
let
formData
=
{};
let
proxies
=
[
let
formData
:
Record
<
string
,
Object
>
=
{};
let
proxies
:
formBindingData
.
ProxyData
[]
=
[
{
"
key
"
:
"
datashareproxy://com.example.myapplication/test
"
,
"
subscriberId
"
:
subscriberId
...
...
@@ -179,6 +186,7 @@
return
formBinding
;
}
}
```
-
在
[
卡片页面文件
](
arkts-ui-widget-creation.md
)
中,通过LocalStorage变量获取订阅到的数据,LocalStorage绑定了一个字符串,以key:value的键值对格式来刷新卡片订阅数据,其中key必须与卡片提供方订阅的key保持一致。示例中,通过'list'获取订阅的数据,并把第一个元素的值显示在Text组件上。
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-status.md
浏览文件 @
352614bd
...
...
@@ -96,56 +96,62 @@
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
dataPreferences
from
'
@ohos.data.preferences
'
;
import
Want
from
'
@ohos.app.ability.Want
'
;
import
Base
from
'
@ohos.base
'
;
export
default
class
EntryFormAbility
extends
FormExtensionAbility
{
onAddForm
(
want
)
{
let
formId
=
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
];
let
isTempCard
:
boolean
=
want
.
parameters
[
formInfo
.
FormParam
.
TEMPORARY_KEY
];
onAddForm
(
want
:
Want
)
{
let
formId
:
string
=
''
;
let
isTempCard
:
boolean
;
if
(
want
.
parameters
)
{
formId
=
JSON
.
stringify
(
want
.
parameters
[
formInfo
.
FormParam
.
IDENTITY_KEY
]);
isTempCard
=
want
.
parameters
[
formInfo
.
FormParam
.
TEMPORARY_KEY
]
as
boolean
;
if
(
isTempCard
===
false
)
{
// 如果为常态卡片,直接进行信息持久化
console
.
info
(
'
Not temp card, init db for:
'
+
formId
);
let
promise
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
)
=>
{
let
promise
:
Promise
<
dataPreferences
.
Preferences
>
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
:
dataPreferences
.
Preferences
)
=>
{
console
.
info
(
"
Succeeded to get preferences.
"
);
await
storeDB
.
put
(
'
A
'
+
formId
,
'
false
'
);
await
storeDB
.
put
(
'
B
'
+
formId
,
'
false
'
);
await
storeDB
.
flush
();
}).
catch
((
er
r
)
=>
{
}).
catch
((
err
:
Base
.
BusinessErro
r
)
=>
{
console
.
info
(
`Failed to get preferences.
${
JSON
.
stringify
(
err
)}
`
);
})
}
let
formData
=
{};
}
let
formData
:
Record
<
string
,
Object
|
string
>
=
{};
return
formBindingData
.
createFormBindingData
(
formData
);
}
onRemoveForm
(
formId
)
{
onRemoveForm
(
formId
:
string
)
{
console
.
info
(
'
onRemoveForm, formId:
'
+
formId
);
let
promise
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
)
=>
{
console
.
info
(
"
Succeeded to get preferences.
"
);
await
storeDB
.
delete
(
'
A
'
+
formId
);
await
storeDB
.
delete
(
'
B
'
+
formId
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
info
(
`Failed to get preferences.
${
JSON
.
stringify
(
err
)}
`
);
})
}
// 如果在添加时为临时卡片,则建议转为常态卡片时进行信息持久化
onCastToNormalForm
(
formId
)
{
onCastToNormalForm
(
formId
:
string
)
{
console
.
info
(
'
onCastToNormalForm, formId:
'
+
formId
);
let
promise
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
)
=>
{
let
promise
:
Promise
<
dataPreferences
.
Preferences
>
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
:
dataPreferences
.
Preferences
)
=>
{
console
.
info
(
"
Succeeded to get preferences.
"
);
await
storeDB
.
put
(
'
A
'
+
formId
,
'
false
'
);
await
storeDB
.
put
(
'
B
'
+
formId
,
'
false
'
);
await
storeDB
.
flush
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
info
(
`Failed to get preferences.
${
JSON
.
stringify
(
err
)}
`
);
})
}
onUpdateForm
(
formId
)
{
let
promise
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
)
=>
{
onUpdateForm
(
formId
:
string
)
{
let
promise
:
Promise
<
dataPreferences
.
Preferences
>
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
:
dataPreferences
.
Preferences
)
=>
{
console
.
info
(
"
Succeeded to get preferences.
"
);
let
stateA
=
await
storeDB
.
get
(
'
A
'
+
formId
,
'
false
'
);
let
stateB
=
await
storeDB
.
get
(
'
B
'
+
formId
,
'
false
'
);
...
...
@@ -160,18 +166,18 @@
await
formProvider
.
updateForm
(
formId
,
formInfo
);
}
console
.
info
(
`Update form success stateA:
${
stateA
}
stateB:
${
stateB
}
.`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
info
(
`Failed to get preferences.
${
JSON
.
stringify
(
err
)}
`
);
})
}
onFormEvent
(
formId
,
message
)
{
onFormEvent
(
formId
:
string
,
message
:
string
)
{
// 存放卡片状态
console
.
info
(
'
onFormEvent formId:
'
+
formId
+
'
msg:
'
+
message
);
let
promise
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
)
=>
{
let
promise
:
Promise
<
dataPreferences
.
Preferences
>
=
dataPreferences
.
getPreferences
(
this
.
context
,
'
myStore
'
);
promise
.
then
(
async
(
storeDB
:
dataPreferences
.
Preferences
)
=>
{
console
.
info
(
"
Succeeded to get preferences.
"
);
let
msg
=
JSON
.
parse
(
message
);
let
msg
:
Record
<
string
,
string
>
=
JSON
.
parse
(
message
);
if
(
msg
.
selectA
!=
undefined
)
{
console
.
info
(
'
onFormEvent selectA info:
'
+
msg
.
selectA
);
await
storeDB
.
put
(
'
A
'
+
formId
,
msg
.
selectA
);
...
...
@@ -181,7 +187,7 @@
await
storeDB
.
put
(
'
B
'
+
formId
,
msg
.
selectB
);
}
await
storeDB
.
flush
();
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
console
.
info
(
`Failed to get preferences.
${
JSON
.
stringify
(
err
)}
`
);
})
}
...
...
zh-cn/application-dev/application-models/arkts-ui-widget-update-by-time.md
浏览文件 @
352614bd
...
...
@@ -69,11 +69,12 @@
```
ts
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
Base
from
'
@ohos.base
'
;
let
formId
=
'
123456789
'
;
// 实际业务场景需要使用正确的formId
let
formId
:
string
=
'
123456789
'
;
// 实际业务场景需要使用正确的formId
try
{
// 设置过5分钟后更新卡片内容
formProvider
.
setFormNextRefreshTime
(
formId
,
5
,
(
err
,
data
)
=>
{
formProvider
.
setFormNextRefreshTime
(
formId
,
5
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to setFormNextRefreshTime. Code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
return
;
...
...
@@ -82,7 +83,7 @@
}
});
}
catch
(
err
)
{
console
.
error
(
`Failed to setFormNextRefreshTime. Code:
${
err
.
code
}
, message:
${
err
.
message
}
`
);
console
.
error
(
`Failed to setFormNextRefreshTime. Code:
${
(
err
as
Base
.
BusinessError
).
code
}
, message:
${(
err
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
zh-cn/application-dev/application-models/common-event-publish.md
浏览文件 @
352614bd
...
...
@@ -27,19 +27,20 @@
```
ts
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
2.
传入需要发布的事件名称和回调函数,发布事件。
```
ts
// 发布公共事件
commonEventManager
.
publish
(
"
usual.event.SCREEN_OFF
"
,
(
err
)
=>
{
commonEventManager
.
publish
(
"
usual.event.SCREEN_OFF
"
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`[CommonEvent] PublishCallBack err=
${
JSON
.
stringify
(
err
)}
`
);
}
else
{
console
.
info
(
`[CommonEvent] Publish success`
);
}
})
})
;
```
...
...
@@ -51,13 +52,14 @@
```
ts
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
2.
传入需要发布的事件名称和回调函数,发布事件。
```
ts
// 公共事件相关信息
let
options
=
{
let
options
:
commonEventManager
.
CommonEventPublishData
=
{
code
:
1
,
// 公共事件的初始代码
data
:
"
initial data
"
,
// 公共事件的初始数据
}
...
...
@@ -67,11 +69,11 @@
```
ts
// 发布公共事件
commonEventManager
.
publish
(
"
usual.event.SCREEN_OFF
"
,
options
,
(
err
)
=>
{
commonEventManager
.
publish
(
"
usual.event.SCREEN_OFF
"
,
options
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
'
[CommonEvent] PublishCallBack err=
'
+
JSON
.
stringify
(
err
));
}
else
{
console
.
info
(
'
[CommonEvent] Publish success
'
)
}
})
})
;
```
zh-cn/application-dev/application-models/common-event-remove-sticky.md
浏览文件 @
352614bd
...
...
@@ -22,6 +22,7 @@
```
ts
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
3.
调用
[
`removeStickyCommonEvent()`
](
../reference/apis/js-apis-commonEventManager.md#commoneventmanagerremovestickycommonevent10
)
方法移除对应的粘性公共事件。
...
...
@@ -31,7 +32,7 @@
> 移除的粘性公共事件,必须是本应用之前已发布的粘性公共事件,发布粘性公共事件参考[公共事件发布](common-event-publish.md)章节。
```
ts
commonEventManager
.
removeStickyCommonEvent
(
"
sticky_event
"
,
(
err
)
=>
{
// sticky_event粘性公共事件名
commonEventManager
.
removeStickyCommonEvent
(
"
sticky_event
"
,
(
err
:
Base
.
BusinessError
)
=>
{
// sticky_event粘性公共事件名
if
(
err
)
{
console
.
error
(
`Failed to remove sticky common event. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
...
...
zh-cn/application-dev/application-models/common-event-static-subscription.md
浏览文件 @
352614bd
...
...
@@ -21,10 +21,11 @@
开发者可以在
[
`onReceiveEvent()`
](
../reference/apis/js-apis-application-staticSubscriberExtensionAbility.md#staticsubscriberextensionabilityonreceiveevent
)
回调中实现业务逻辑。
```
ts
import
StaticSubscriberExtensionAbility
from
'
@ohos.application.StaticSubscriberExtensionAbility
'
import
StaticSubscriberExtensionAbility
from
'
@ohos.application.StaticSubscriberExtensionAbility
'
;
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
export
default
class
StaticSubscriber
extends
StaticSubscriberExtensionAbility
{
onReceiveEvent
(
event
)
{
onReceiveEvent
(
event
:
commonEventManager
.
CommonEventData
)
{
console
.
info
(
'
onReceiveEvent, event:
'
+
event
.
event
);
}
}
...
...
zh-cn/application-dev/application-models/common-event-subscription.md
浏览文件 @
352614bd
...
...
@@ -23,15 +23,16 @@
```
ts
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
2.
创建订阅者信息,详细的订阅者信息数据类型及包含的参数请见
[
CommonEventSubscribeInfo
](
../reference/apis/js-apis-commonEventManager.md#commoneventsubscribeinfo
)
文档介绍。
```
ts
// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
let
subscriber
=
null
;
let
subscriber
:
commonEventManager
.
CommonEventSubscriber
|
null
=
null
;
// 订阅者信息
let
subscribeInfo
=
{
let
subscribeInfo
:
commonEventManager
.
CommonEventSubscribeInfo
=
{
events
:
[
"
usual.event.SCREEN_OFF
"
],
// 订阅灭屏公共事件
}
```
...
...
@@ -40,7 +41,7 @@
```
ts
// 创建订阅者回调
commonEventManager
.
createSubscriber
(
subscribeInfo
,
(
err
,
data
)
=>
{
commonEventManager
.
createSubscriber
(
subscribeInfo
,
(
err
:
Base
.
BusinessError
,
data
:
commonEventManager
.
CommonEventSubscriber
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to create subscriber. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
...
...
@@ -56,7 +57,7 @@
```
ts
// 订阅公共事件回调
if
(
subscriber
!==
null
)
{
commonEventManager
.
subscribe
(
subscriber
,
(
err
,
d
ata
)
=>
{
commonEventManager
.
subscribe
(
subscriber
,
(
err
:
Base
.
BusinessError
,
data
:
commonEventManager
.
CommonEventD
ata
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to subscribe common event. Code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
return
;
...
...
zh-cn/application-dev/application-models/common-event-unsubscription.md
浏览文件 @
352614bd
...
...
@@ -19,6 +19,7 @@
```
ts
import
commonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
2.
根据
[
动态订阅公共事件
](
common-event-subscription.md
)
章节的步骤来订阅某个事件。
...
...
@@ -28,7 +29,7 @@
```
ts
// subscriber为订阅事件时创建的订阅者对象
if
(
subscriber
!==
null
)
{
commonEventManager
.
unsubscribe
(
subscriber
,
(
err
)
=>
{
commonEventManager
.
unsubscribe
(
subscriber
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`[CommonEvent] UnsubscribeCallBack err=
${
JSON
.
stringify
(
err
)}
`
);
}
else
{
...
...
zh-cn/application-dev/reference/apis/js-apis-app-form-formBindingData.md
浏览文件 @
352614bd
...
...
@@ -63,15 +63,16 @@ createFormBindingData(obj?: Object | string): FormBindingData
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
fs
from
'
@ohos.file.fs
'
;
import
Base
from
'
@ohos.base
'
;
try
{
let
fd
=
fs
.
openSync
(
'
/path/to/form.png
'
);
let
createFormBindingDataParam
=
new
Map
<
Object
,
string
|
object
>
()
let
formImagesParam
=
new
Map
<
Object
,
object
>
()
formImagesParam
.
set
(
'
image
'
,
fd
)
createFormBindingDataParam
.
set
(
"
name
"
,
'
21°
'
)
createFormBindingDataParam
.
set
(
'
formImages
'
,
formImagesParam
)
let
createFormBindingDataParam
=
new
Map
<
string
,
string
|
Object
>
();
let
formImagesParam
=
new
Map
<
string
,
Object
>
();
formImagesParam
.
set
(
'
image
'
,
fd
)
;
createFormBindingDataParam
.
set
(
"
name
"
,
'
21°
'
)
;
createFormBindingDataParam
.
set
(
'
formImages
'
,
formImagesParam
)
;
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
}
catch
(
error
)
{
...
...
zh-cn/application-dev/reference/apis/js-apis-app-form-formExtensionAbility.md
浏览文件 @
352614bd
...
...
@@ -51,7 +51,7 @@ import Want from '@ohos.app.ability.Want';
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onAddForm
(
want
:
Want
)
{
console
.
log
(
`FormExtensionAbility onAddForm, want:
${
want
.
abilityName
}
`
);
let
dataObj1
=
new
Map
<
Object
,
string
>
();
let
dataObj1
=
new
Map
<
string
,
string
>
();
dataObj1
.
set
(
'
temperature
'
,
'
11c
'
);
dataObj1
.
set
(
'
time
'
,
'
11:00
'
);
...
...
@@ -107,20 +107,19 @@ onUpdateForm(formId: string): void
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
Base
from
'
@ohos.base
'
;
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onUpdateForm
(
formId
:
string
)
{
console
.
log
(
`FormExtensionAbility onUpdateForm, formId:
${
formId
}
`
);
class
createFormBindingDataParam
{
temperature
:
string
time
:
string
}
let
obj2
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
}
as
createFormBindingDataParam
);
});
formProvider
.
updateForm
(
formId
,
obj2
).
then
((
data
)
=>
{
console
.
log
(
`FormExtensionAbility context updateForm, data:
${
data
}
`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`FormExtensionAbility context updateForm failed, data:
${
error
}
`
);
});
}
};
...
...
@@ -146,6 +145,7 @@ onChangeFormVisibility(newStatus: { [key: string]: number }): void
import
FormExtensionAbility
from
'
@ohos.app.form.FormExtensionAbility
'
;
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
import
formProvider
from
'
@ohos.app.form.formProvider
'
;
import
Base
from
'
@ohos.base
'
;
// 由于arkTs中无Object.keys,且无法使用for..in...
// 若报arkTs问题,请将此方法单独抽离至一个ts文件中并暴露,在需要用到的ets文件中引入使用
...
...
@@ -155,23 +155,21 @@ function getObjKeys(obj: Object): string[] {
}
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onChangeFormVisibility
(
newStatus
)
{
onChangeFormVisibility
(
newStatus
:
Record
<
string
,
number
>
)
{
console
.
log
(
`FormExtensionAbility onChangeFormVisibility, newStatus:
${
newStatus
}
`
);
class
createFormBindingDataParam
{
temperature
:
string
time
:
string
}
let
obj2
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
}
as
createFormBindingDataParam
);
});
for
(
let
key
in
newStatus
)
{
console
.
log
(
`FormExtensionAbility onChangeFormVisibility, key:
${
key
}
, value=
${
newStatus
[
key
]}
`
);
formProvider
.
updateForm
(
key
,
obj2
).
then
((
data
)
=>
{
console
.
log
(
`FormExtensionAbility context updateForm, data:
${
data
}
`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`Operation updateForm failed. Cause:
${
error
}
`
);
let
keys
:
string
[]
=
getObjKeys
(
newStatus
);
for
(
let
i
:
number
=
0
;
i
<
keys
.
length
;
i
++
)
{
console
.
log
(
`FormExtensionAbility onChangeFormVisibility, key:
${
keys
[
i
]}
, value=
${
newStatus
[
keys
[
i
]]}
`
);
formProvider
.
updateForm
(
keys
[
i
],
obj2
).
then
(()
=>
{
console
.
log
(
`FormExtensionAbility context updateForm`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`Operation updateForm failed. Cause:
${
JSON
.
stringify
(
error
)}
`
);
});
}
}
...
...
@@ -317,9 +315,9 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onShareForm
(
formId
:
string
)
{
console
.
log
(
`FormExtensionAbility onShareForm, formId:
${
formId
}
`
);
let
wantParams
=
{
let
wantParams
:
Record
<
string
,
Object
>
=
{
'
temperature
'
:
'
20
'
,
'
time
'
:
'
2022-8-8 09:59
'
,
s
'
time
'
:
'
2022-8-8 09:59
'
,
};
return
wantParams
;
}
...
...
@@ -355,8 +353,8 @@ import FormExtensionAbility from '@ohos.app.form.FormExtensionAbility';
export
default
class
MyFormExtensionAbility
extends
FormExtensionAbility
{
onAcquireFormData
(
formId
:
string
)
{
console
.
log
(
'
FormExtensionAbility onAcquireFormData, formId: ${formId}
'
);
let
wantParams
=
{
console
.
log
(
`FormExtensionAbility onAcquireFormData, formId:
${
formId
}
`
);
let
wantParams
:
Record
<
string
,
Object
>
=
{
'
temperature
'
:
'
20
'
,
'
time
'
:
'
2022-8-8 09:59
'
,
};
...
...
zh-cn/application-dev/reference/apis/js-apis-app-form-formHost.md
浏览文件 @
352614bd
...
...
@@ -61,7 +61,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -113,10 +113,10 @@ try {
formHost
.
deleteForm
(
formId
).
then
(()
=>
{
console
.
log
(
'
formHost deleteForm success
'
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
'
formHost deleteForm, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`formHost deleteForm, error:
${
JSON
.
stringify
(
error
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -165,7 +165,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -215,7 +215,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -270,7 +270,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -319,7 +319,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -373,7 +373,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -423,7 +423,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -477,7 +477,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -524,7 +524,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -576,7 +576,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -623,7 +623,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -675,7 +675,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -723,7 +723,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -776,7 +776,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -825,7 +825,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -879,7 +879,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -918,7 +918,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -956,7 +956,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1004,7 +1004,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1049,7 +1049,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1099,7 +1099,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1150,7 +1150,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1204,7 +1204,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1253,7 +1253,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1305,7 +1305,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1366,7 +1366,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1430,7 +1430,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1547,7 +1547,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1601,7 +1601,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1650,7 +1650,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1704,7 +1704,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
## shareForm
...
...
@@ -1753,7 +1753,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1808,7 +1808,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1856,7 +1856,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1907,7 +1907,7 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -1955,7 +1955,7 @@ try {
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
...
...
@@ -2005,6 +2005,6 @@ try {
console
.
error
(
`error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
`
);
}
```
zh-cn/application-dev/reference/apis/js-apis-app-form-formProvider.md
浏览文件 @
352614bd
...
...
@@ -56,7 +56,7 @@ try {
console
.
log
(
`formProvider setFormNextRefreshTime success`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -107,7 +107,7 @@ try {
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -148,15 +148,10 @@ import formBindingData from '@ohos.app.form.formBindingData';
let
formId
:
string
=
'
12400633174999288
'
;
try
{
class
createFormBindingDataParamType
{
temperature
:
string
time
:
string
}
let
createFormBindingDataParam
:
createFormBindingDataParamType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
let
obj
:
formBindingData
.
FormBindingData
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
formProvider
.
updateForm
(
formId
,
obj
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
...
...
@@ -165,7 +160,7 @@ try {
console
.
log
(
`formProvider updateForm success`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -210,23 +205,18 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
let
formId
:
string
=
'
12400633174999288
'
;
class
createFormBindingDataParamType
{
temperature
:
string
time
:
string
}
let
createFormBindingDataParam
:
createFormBindingDataParamType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
let
obj
:
formBindingData
.
FormBindingData
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
try
{
formProvider
.
updateForm
(
formId
,
obj
).
then
(()
=>
{
console
.
log
(
`formProvider updateForm success`
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`promise error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -267,7 +257,7 @@ try {
console
.
log
(
`formProvider getFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
## getFormsInfo
...
...
@@ -314,7 +304,7 @@ try {
console
.
log
(
`formProvider getFormsInfo, data:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -365,7 +355,7 @@ try {
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -414,24 +404,19 @@ let want: Want = {
}
};
try
{
class
createFormBindingDataParamType
{
temperature
:
string
time
:
string
}
let
createFormBindingDataParam
:
createFormBindingDataParamType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
let
obj
:
formBindingData
.
FormBindingData
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
formProvider
.
requestPublishForm
(
want
,
obj
,
(
error
:
Base
.
BusinessError
,
data
:
string
)
=>
{
if
(
error
)
{
console
.
error
(
`callback error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`callback error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
return
;
}
console
.
log
(
'
formProvider requestPublishForm, form ID is: ${JSON.stringify(data)}
'
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -486,7 +471,7 @@ try {
console
.
log
(
`formProvider requestPublishForm, form ID is:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -545,7 +530,7 @@ try {
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -604,13 +589,13 @@ try {
console
.
log
(
`formProvider requestPublishForm, form ID is:
${
JSON
.
stringify
(
data
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
}
}
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
...
...
@@ -663,13 +648,13 @@ try {
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
}
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
console
.
error
(
`promise error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
});
}
catch
(
error
)
{
console
.
error
(
`catch error, code:
${
error
.
code
}
, message:
${
error
.
message
}
)`
);
console
.
error
(
`catch error, code:
${
(
error
as
Base
.
BusinessError
).
code
}
, message:
${(
error
as
Base
.
BusinessError
)
.
message
}
)`
);
}
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-application-formBindingData.md
浏览文件 @
352614bd
...
...
@@ -50,6 +50,7 @@ createFormBindingData(obj?: Object | string): FormBindingData
```
ts
import
formBindingData
from
'
@ohos.application.formBindingData
'
;
import
fs
from
'
@ohos.file.fs
'
;
import
Base
from
'
@ohos.base
'
;
try
{
let
fd
=
fs
.
openSync
(
'
/path/to/form.png
'
);
...
...
@@ -61,6 +62,6 @@ try {
formBindingData
.
createFormBindingData
(
createFormBindingDataParam
);
}
catch
(
error
)
{
console
.
error
(
'
catch error, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`catch error, error:
${
JSON
.
stringify
(
error
as
Base
.
BusinessError
)}
`
);
}
```
zh-cn/application-dev/reference/apis/js-apis-application-formHost.md
浏览文件 @
352614bd
...
...
@@ -38,9 +38,9 @@ deleteForm(formId: string, callback: AsyncCallback<void>): void
import
formHost
from
'
@ohos.application.formHost
'
;
let
formId
:
string
=
'
12400633174999288
'
;
formHost
.
deleteForm
(
formId
,
(
error
,
data
)
=>
{
formHost
.
deleteForm
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost deleteForm, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`formHost deleteForm, error:
${
JSON
.
stringify
(
error
)}
`
);
}
});
```
...
...
@@ -336,7 +336,7 @@ import formHost from '@ohos.application.formHost';
let
formId
:
string
[]
=
[
'
12400633174999288
'
];
formHost
.
notifyVisibleForms
(
formId
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
'
formHost notifyVisibleForms, error: ${JSON.stringify(error)}
'
);
console
.
error
(
`formHost notifyVisibleForms, error:
${
JSON
.
stringify
(
error
)}
`
);
}
});
```
...
...
zh-cn/application-dev/reference/apis/js-apis-application-formProvider.md
浏览文件 @
352614bd
...
...
@@ -93,16 +93,11 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData,call
```
ts
import
formBindingData
from
'
@ohos.app.form.formBindingData
'
;
let
formId
=
'
12400633174999288
'
;
class
createBindingDataType
{
temperature
:
string
time
:
string
};
let
createBindingDataParam
:
createBindingDataType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createBindingDataParam
);
let
formId
:
string
=
'
12400633174999288
'
;
let
obj
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
formProvider
.
updateForm
(
formId
,
obj
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
.
code
)
{
console
.
error
(
`formProvider updateForm, error:
${
JSON
.
stringify
(
error
)}
`
);
...
...
@@ -137,15 +132,10 @@ updateForm(formId: string, formBindingData: formBindingData.FormBindingData): Pr
import
formBindingData
from
'
@ohos.application.formBindingData
'
;
let
formId
:
string
=
'
12400633174999288
'
;
class
createBindingDataType
{
temperature
:
string
time
:
string
};
let
createBindingDataParam
:
createBindingDataType
=
{
temperature
:
'
22c
'
,
time
:
'
22:00
'
};
let
obj
=
formBindingData
.
createFormBindingData
(
createBindingDataParam
);
let
obj
=
formBindingData
.
createFormBindingData
({
temperature
:
'
22c
'
,
time
:
'
22:00
'
});
formProvider
.
updateForm
(
formId
,
obj
).
then
(()
=>
{
console
.
log
(
'
formProvider updateForm success
'
);
}).
catch
((
error
:
Base
.
BusinessError
)
=>
{
...
...
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
浏览文件 @
352614bd
...
...
@@ -11,8 +11,6 @@
```
ts
import
CommonEvent
from
'
@ohos.commonEvent
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
## Support
...
...
@@ -42,6 +40,8 @@ publish(event: string, callback: AsyncCallback\<void>): void
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
//发布公共事件回调
function
publishCB
(
err
:
Base
.
BusinessError
)
{
if
(
err
.
code
)
{
...
...
@@ -78,6 +78,9 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
//公共事件相关信息
let
options
:
CommonEventManager
.
CommonEventPublishData
=
{
code
:
0
,
//公共事件的初始代码
...
...
@@ -122,6 +125,8 @@ publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): vo
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
// 发布公共事件回调
function
publishCB
(
err
:
Base
.
BusinessError
)
{
if
(
err
.
code
)
{
...
...
@@ -164,6 +169,9 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
// 公共事件相关信息
let
options
:
CommonEventManager
.
CommonEventPublishData
=
{
code
:
0
,
// 公共事件的初始代码
...
...
@@ -208,6 +216,9 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
...
...
@@ -254,6 +265,9 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
...
...
@@ -291,6 +305,9 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
...
...
@@ -344,6 +361,9 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>):
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
// 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
// 订阅者信息
...
...
zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md
浏览文件 @
352614bd
...
...
@@ -10,7 +10,6 @@
```
ts
import
CommonEventManager
from
'
@ohos.commonEventManager
'
;
import
Base
from
'
@ohos.base
'
;
```
## Support
...
...
@@ -48,6 +47,8 @@ publish(event: string, callback: AsyncCallback\<void>): void
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
//发布公共事件回调
function
publishCB
(
err
:
Base
.
BusinessError
)
{
if
(
err
)
{
...
...
@@ -95,6 +96,8 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
//公共事件相关信息
let
options
:
CommonEventManager
.
CommonEventPublishData
=
{
code
:
0
,
//公共事件的初始代码
...
...
@@ -151,6 +154,8 @@ publishAsUser(event: string, userId: number, callback: AsyncCallback\<void>): vo
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
//发布公共事件回调
function
publishCB
(
err
:
Base
.
BusinessError
)
{
if
(
err
)
{
...
...
@@ -205,6 +210,8 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca
```
ts
import
Base
from
'
@ohos.base
'
;
//公共事件相关信息
let
options
:
CommonEventManager
.
CommonEventPublishData
=
{
code
:
0
,
//公共事件的初始代码
...
...
@@ -249,6 +256,8 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
//用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
...
...
@@ -296,6 +305,8 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
//用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
...
...
@@ -335,6 +346,8 @@ createSubscriber的同步接口。
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscriber
;
//用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
...
...
@@ -379,6 +392,8 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
//订阅者信息
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
//用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
...
...
@@ -448,6 +463,8 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>):
**示例:**
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscriber
:
CommonEventManager
.
CommonEventSubscriber
;
//用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作
//订阅者信息
let
subscribeInfo
:
CommonEventManager
.
CommonEventSubscribeInfo
=
{
...
...
@@ -532,6 +549,8 @@ removeStickyCommonEvent(event: string, callback: AsyncCallback\<void>): void
```
ts
import
Base
from
'
@ohos.base
'
;
CommonEventManager
.
removeStickyCommonEvent
(
"
sticky_event
"
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
info
(
`Remove sticky event AsyncCallback failed, errCode:
${
err
.
code
}
, errMes:
${
err
.
message
}
`
);
...
...
@@ -579,6 +598,8 @@ removeStickyCommonEvent(event: string): Promise\<void>
```
ts
import
Base
from
'
@ohos.base
'
;
CommonEventManager
.
removeStickyCommonEvent
(
"
sticky_event
"
).
then
(()
=>
{
console
.
info
(
`Remove sticky event AsyncCallback success`
);
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
...
...
@@ -616,6 +637,8 @@ setStaticSubscriberState(enable: boolean, callback: AsyncCallback\<void>): void;
```
ts
import
Base
from
'
@ohos.base
'
;
CommonEventManager
.
setStaticSubscriberState
(
true
,
(
err
:
Base
.
BusinessError
)
=>
{
if
(
!
err
)
{
console
.
info
(
`Set static subscriber state callback failed, err is null.`
);
...
...
@@ -664,6 +687,8 @@ setStaticSubscriberState(enable: boolean): Promise\<void>;
```
ts
import
Base
from
'
@ohos.base
'
;
CommonEventManager
.
setStaticSubscriberState
(
false
).
then
(()
=>
{
console
.
info
(
`Set static subscriber state promise success`
);
}).
catch
((
err
:
Base
.
BusinessError
)
=>
{
...
...
zh-cn/application-dev/reference/apis/js-apis-emitter.md
浏览文件 @
352614bd
...
...
@@ -10,8 +10,8 @@
## 导入模块
```
javascript
import
emitter
from
'
@ohos.events.emitter
'
```
ts
import
emitter
from
'
@ohos.events.emitter
'
;
```
## 权限列表
...
...
@@ -35,16 +35,15 @@ on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)
**示例:**
```
javascript
let
innerEvent
=
{
```
ts
let
innerEvent
:
emitter
.
InnerEvent
=
{
eventId
:
1
};
// 收到eventId为1的事件后执行
该
回调函数
function
emitterCallback
()
{
// 收到eventId为1的事件后执行回调函数
emitter
.
on
(
innerEvent
,
()
=>
{
console
.
info
(
'
callback
'
);
}
emitter
.
on
(
innerEvent
,
emitterCallback
);
});
```
## emitter.once
...
...
@@ -64,16 +63,15 @@ once(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdat
**示例:**
```
javascript
let
innerEvent
=
{
```
ts
let
innerEvent
:
emitter
.
InnerEvent
=
{
eventId
:
1
};
// 收到eventId为1的事件后执行该回调函数
function
emitterCallback
()
{
emitter
.
once
(
innerEvent
,
()
=>
{
console
.
info
(
'
once callback
'
);
};
emitter
.
once
(
innerEvent
,
emitterCallback
);
});
```
## emitter.off
...
...
@@ -92,7 +90,7 @@ off(eventId: number): void
**示例:**
```
javascript
```
ts
// 取消eventID为1的所有事件回调处理函数
emitter
.
off
(
1
);
```
...
...
@@ -114,13 +112,12 @@ off(eventId: number, callback: Callback\<[EventData](#eventdata)\>): void
**示例:**
```
javascript
```
ts
// 取消eventID为1的事件回调处理函数 emitterCallback
// 如果该回调处理函数没有被订阅,则不做任何处理
function
emitterCallback
()
{
emitter
.
off
(
1
,
()
=>
{
console
.
info
(
'
callback
'
);
}
emitter
.
off
(
1
,
emitterCallback
);
});
```
## emitter.emit
...
...
@@ -140,15 +137,15 @@ emit(event: [InnerEvent](#innerevent), data?: [EventData](#eventdata)): void
**示例:**
```
javascript
let
eventData
=
{
```
ts
let
eventData
:
emitter
.
EventData
=
{
data
:
{
"
content
"
:
"
c
"
,
"
id
"
:
1
,
}
};
let
innerEvent
=
{
let
innerEvent
:
emitter
.
InnerEvent
=
{
eventId
:
1
,
priority
:
emitter
.
EventPriority
.
HIGH
};
...
...
zh-cn/application-dev/reference/apis/js-apis-inner-application-formExtensionContext.md
浏览文件 @
352614bd
...
...
@@ -66,7 +66,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
};
this
.
context
.
startAbility
(
want
,
(
error
:
Base
.
BusinessError
)
=>
{
if
(
error
)
{
console
.
error
(
'
FormExtensionContext startAbility, error:${JSON.stringify(error)}
'
);
console
.
error
(
`FormExtensionContext startAbility, error:
${
JSON
.
stringify
(
error
)}
`
);
}
else
{
console
.
log
(
'
FormExtensionContext startAbility success
'
);
}
...
...
@@ -212,7 +212,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
connection
=
this
.
context
.
connectServiceExtensionAbility
(
want
,
options
);
}
catch
(
paramError
)
{
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
console
.
error
(
`error.code:
${
(
paramError
as
Base
.
BusinessError
).
code
}
, error.message:
${(
paramError
as
Base
.
BusinessError
)
.
message
}
`
);
}
}
};
...
...
@@ -273,7 +273,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
}
catch
(
paramError
)
{
commRemote
=
null
;
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
console
.
error
(
`error.code:
${
(
paramError
as
Base
.
BusinessError
).
code
}
, error.message:
${(
paramError
as
Base
.
BusinessError
)
.
message
}
`
);
}
}
};
...
...
@@ -340,7 +340,7 @@ export default class MyFormExtensionAbility extends FormExtensionAbility {
}
catch
(
paramError
)
{
commRemote
=
null
;
// 处理入参错误异常
console
.
error
(
`error.code:
${
paramError
.
code
}
, error.message:
${
paramError
.
message
}
`
);
console
.
error
(
`error.code:
${
(
paramError
as
Base
.
BusinessError
).
code
}
, error.message:
${(
paramError
as
Base
.
BusinessError
)
.
message
}
`
);
}
}
};
...
...
zh-cn/application-dev/reference/apis/js-apis-inner-notification-notificationFlags.md
浏览文件 @
352614bd
...
...
@@ -8,6 +8,8 @@
**系统能力**
:以下各项对应的系统能力均为SystemCapability.Notification.Notification
## 属性
| 名称 | 类型 | 必填 | 说明 |
| ---------------- | ---------------------- | ---- | --------------------------------- |
| soundEnabled |
[
NotificationFlagStatus
](
#notificationflagstatus
)
| 否 | 是否启用声音提示。 |
...
...
zh-cn/application-dev/reference/apis/js-apis-inner-notification-notificationSubscriber.md
浏览文件 @
352614bd
...
...
@@ -32,8 +32,10 @@ onConsume?: (data: [SubscribeCallbackData](js-apis-notification.md#subscribecall
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
...
...
@@ -41,13 +43,13 @@ function subscribeCallback(err) {
}
};
function
onConsumeCallback
(
data
)
{
let
onConsumeCallback
=
(
data
:
notificationSubscribe
.
SubscribeCallbackData
)
=>
{
console
.
info
(
'
===> onConsume in test
'
);
let
req
=
data
.
request
;
console
.
info
(
'
===> onConsume callback req.id:
'
+
req
.
id
);
};
let
subscriber
=
{
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onConsume
:
onConsumeCallback
};
...
...
@@ -72,8 +74,10 @@ onCancel?:(data: [SubscribeCallbackData](js-apis-notification.md#subscribecallba
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
...
...
@@ -81,13 +85,13 @@ function subscribeCallback(err) {
}
};
function
onCancelCallback
(
data
)
{
function
onCancelCallback
(
data
:
notificationSubscribe
.
SubscribeCallbackData
)
{
console
.
info
(
'
===> onCancel in test
'
);
let
req
=
data
.
request
;
console
.
info
(
'
===> onCancel callback req.id:
'
+
req
.
id
);
}
let
subscriber
=
{
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onCancel
:
onCancelCallback
};
...
...
@@ -112,8 +116,10 @@ onUpdate?:(data: [NotificationSortingMap](js-apis-notification.md#notificationso
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
...
...
@@ -121,12 +127,10 @@ function subscribeCallback(err) {
}
};
function
onUpdateCallback
(
map
)
{
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onUpdate
:
(
map
)
=>
{
console
.
info
(
'
===> onUpdateCallback map:
'
+
JSON
.
stringify
(
map
));
}
let
subscriber
=
{
onUpdate
:
onUpdateCallback
}
};
notificationSubscribe
.
subscribe
(
subscriber
,
subscribeCallback
);
...
...
@@ -144,8 +148,10 @@ onConnect?:() => void
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
...
...
@@ -153,11 +159,11 @@ function subscribeCallback(err) {
}
};
function
onConnectCallback
()
{
let
onConnectCallback
=
()
=>
{
console
.
info
(
'
===> onConnect in test
'
);
}
let
subscriber
=
{
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onConnect
:
onConnectCallback
};
...
...
@@ -176,30 +182,32 @@ onDisconnect?:() => void
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeCallback
"
);
}
};
function
unsubscribeCallback
(
err
)
{
if
(
err
.
code
)
{
let
unsubscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`unsubscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
unsubscribeCallback
"
);
}
};
function
onConnectCallback
()
{
let
onConnectCallback
=
()
=>
{
console
.
info
(
'
===> onConnect in test
'
);
}
function
onDisconnectCallback
()
{
let
onDisconnectCallback
=
()
=>
{
console
.
info
(
'
===> onDisconnect in test
'
);
}
let
subscriber
=
{
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onConnect
:
onConnectCallback
,
onDisconnect
:
onDisconnectCallback
};
...
...
@@ -222,8 +230,10 @@ onDestroy?:() => void
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
...
...
@@ -231,11 +241,11 @@ function subscribeCallback(err) {
}
};
function
onDestroyCallback
()
{
let
onDestroyCallback
=
()
=>
{
console
.
info
(
'
===> onDestroy in test
'
);
}
let
subscriber
=
{
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onDestroy
:
onDestroyCallback
};
...
...
@@ -260,8 +270,10 @@ onDoNotDisturbDateChange?:(mode: notification.[DoNotDisturbDate](js-apis-notific
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
...
...
@@ -269,11 +281,11 @@ function subscribeCallback(err) {
}
};
function
onDoNotDisturbDateChangeCallback
(
mode
)
{
let
onDoNotDisturbDateChangeCallback
=
(
mode
:
NotificationManager
.
DoNotDisturbDate
)
=>
{
console
.
info
(
'
===> onDoNotDisturbDateChange:
'
+
mode
);
}
let
subscriber
=
{
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onDoNotDisturbDateChange
:
onDoNotDisturbDateChangeCallback
};
...
...
@@ -299,8 +311,10 @@ onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](j
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
...
...
@@ -308,13 +322,13 @@ function subscribeCallback(err) {
}
};
function
onEnabledNotificationChangedCallback
(
callbackData
)
{
let
onEnabledNotificationChangedCallback
=
(
callbackData
:
notificationSubscribe
.
EnabledNotificationCallbackData
)
=>
{
console
.
info
(
"
bundle:
"
,
callbackData
.
bundle
);
console
.
info
(
"
uid:
"
,
callbackData
.
uid
);
console
.
info
(
"
enable:
"
,
callbackData
.
enable
);
};
let
subscriber
=
{
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onEnabledNotificationChanged
:
onEnabledNotificationChangedCallback
};
...
...
@@ -339,8 +353,10 @@ notificationSubscribe.subscribe(subscriber, subscribeCallback);
**示例:**
```
javascript
function
subscribeCallback
(
err
)
{
```
ts
import
Base
from
'
@ohos.base
'
;
let
subscribeCallback
=
(
err
:
Base
.
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`subscribe failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
...
...
@@ -348,14 +364,12 @@ function subscribeCallback(err) {
}
};
function
onBadgeChangedCallback
(
data
)
{
let
subscriber
:
notificationSubscribe
.
NotificationSubscriber
=
{
onBadgeChanged
:
(
data
)
=>
{
console
.
info
(
"
bundle:
"
,
data
.
bundle
);
console
.
info
(
"
uid:
"
,
data
.
uid
);
console
.
info
(
"
badgeNumber:
"
,
data
.
badgeNumber
);
};
let
subscriber
=
{
onBadgeChanged
:
onBadgeChangedCallback
}
};
notificationSubscribe
.
subscribe
(
subscriber
,
subscribeCallback
);
...
...
zh-cn/application-dev/reference/apis/js-apis-notification.md
浏览文件 @
352614bd
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-notificationManager.md
浏览文件 @
352614bd
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-notificationSubscribe.md
浏览文件 @
352614bd
此差异已折叠。
点击以展开。
zh-cn/application-dev/reference/apis/js-apis-system-notification.md
浏览文件 @
352614bd
...
...
@@ -51,11 +51,7 @@ show(options?: ShowNotificationOptions): void
**示例:**
```
ts
class
NotificationClass
{
show
:
Function
}
let
notificationObj
:
NotificationClass
=
{
let
notificationObj
:
notification
=
{
show
()
{
notification
.
show
({
contentTitle
:
'
title info
'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录