# 函数 TriggerAction
根据上一章节 组件 actionRef
, 我们仍需要一个函数对其进行调用, 该函数我们定义为: triggerAction
, 函数签名如下:
export interface ICacheValue {
registryName: keyof typeof registries;
componentName: string;
props: IAnyObject;
key: string;
source: IAnyObject;
}
export function triggerAction(
searchCondition: Partial<ICacheValue> | string,
actionName: string,
): any;
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 例子
点击 外部刷新 table
按钮可以通过通信的方式刷新 Table
import React from 'react';
import parser from '@/utils/parser/react-component-parser';
export default () =>
parser.parse([
{
$$$: 'component',
registryName: 'antd',
componentName: 'Button',
props: {
type: 'primary',
onClick: {
$$$: 'function',
registryName: 'ams',
functionName: 'triggerAction',
args: ['ProTable-faf7f175', 'reload'],
},
},
children: ['外部刷新 table'],
},
{
$$$: 'component',
registryName: 'ams',
componentName: 'ProTable',
props: {
key: 'ProTable-faf7f175',
headerTitle: '测试表格',
query: '/api/rule',
forms: [
{
title: '规则名称',
dataIndex: 'name',
rules: [
{
required: true,
message: '规则名称为必填项',
},
],
},
{
title: '描述',
dataIndex: 'desc',
valueType: 'textarea',
},
{
title: '服务调用次数',
dataIndex: 'callNo',
sorter: true,
},
{
title: '状态',
dataIndex: 'status',
valueEnum: {
0: { text: '关闭', status: 'Default' },
1: { text: '运行中', status: 'Processing' },
2: { text: '已上线', status: 'Success' },
3: { text: '异常', status: 'Error' },
},
},
{
title: '上次调度时间',
dataIndex: 'updatedAt',
sorter: true,
valueType: 'dateTime',
},
],
toolBar: [
{
$$$: 'component',
registryName: 'antd',
componentName: 'Button',
props: {
onClick: {
$$$: 'function',
registryName: 'window',
functionName: 'alert',
args: ['测试'],
},
},
},
],
},
},
]);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84