title: 函数 TriggerAction

函数 TriggerAction

根据上一章节 组件 actionRef, 我们仍需要一个函数对其进行调用, 该函数我们定义为: triggerAction, 函数签名如下:

  1. export interface ICacheValue {
  2. registryName: keyof typeof registries;
  3. componentName: string;
  4. props: IAnyObject;
  5. key: string;
  6. source: IAnyObject;
  7. }
  8. export function triggerAction(
  9. searchCondition: Partial<ICacheValue> | string,
  10. actionName: string,
  11. ): any;

例子

点击 外部刷新 table 按钮可以通过通信的方式刷新 Table

  1. import React from 'react';
  2. import parser from '@/utils/parser/react-component-parser';
  3. export default () =>
  4. parser.parse([
  5. {
  6. $$$: 'component',
  7. registryName: 'antd',
  8. componentName: 'Button',
  9. props: {
  10. type: 'primary',
  11. onClick: {
  12. $$$: 'function',
  13. registryName: 'ams',
  14. functionName: 'triggerAction',
  15. args: ['ProTable-faf7f175', 'reload'],
  16. },
  17. },
  18. children: ['外部刷新 table'],
  19. },
  20. {
  21. $$$: 'component',
  22. registryName: 'ams',
  23. componentName: 'ProTable',
  24. props: {
  25. key: 'ProTable-faf7f175',
  26. headerTitle: '测试表格',
  27. query: '/api/rule',
  28. forms: [
  29. {
  30. title: '规则名称',
  31. dataIndex: 'name',
  32. rules: [
  33. {
  34. required: true,
  35. message: '规则名称为必填项',
  36. },
  37. ],
  38. },
  39. {
  40. title: '描述',
  41. dataIndex: 'desc',
  42. valueType: 'textarea',
  43. },
  44. {
  45. title: '服务调用次数',
  46. dataIndex: 'callNo',
  47. sorter: true,
  48. },
  49. {
  50. title: '状态',
  51. dataIndex: 'status',
  52. valueEnum: {
  53. 0: { text: '关闭', status: 'Default' },
  54. 1: { text: '运行中', status: 'Processing' },
  55. 2: { text: '已上线', status: 'Success' },
  56. 3: { text: '异常', status: 'Error' },
  57. },
  58. },
  59. {
  60. title: '上次调度时间',
  61. dataIndex: 'updatedAt',
  62. sorter: true,
  63. valueType: 'dateTime',
  64. },
  65. ],
  66. toolBar: [
  67. {
  68. $$$: 'component',
  69. registryName: 'antd',
  70. componentName: 'Button',
  71. props: {
  72. onClick: {
  73. $$$: 'function',
  74. registryName: 'window',
  75. functionName: 'alert',
  76. args: ['测试'],
  77. },
  78. },
  79. },
  80. ],
  81. },
  82. },
  83. ]);