baidu / amis

前端低代码框架,通过 JSON 配置就能生成各种页面。
https://baidu.github.io/amis/
Apache License 2.0
17.32k stars 2.51k forks source link

在编排动作里加入“刷新目标组件”的动作,但实际结上无法刷新目标组件 #7605

Open SmallSeaNO3 opened 1 year ago

SmallSeaNO3 commented 1 year ago

描述问题: 在编排动作里加入“刷新目标组件”的动作,但实际结上无法刷新目标组件

如何复现(请务必完整填写下面内容):

  1. 你是如何使用 amis 的? sdk

  2. amis 版本是什么? 3.2.0

  3. 粘贴有问题的完整 amis schema 代码:

    
    {
    title: '浏览器内核对 CSS 的支持情况',
    remark: '嘿,不保证数据准确性',
    type: 'page',
    body: [
    {
      type: 'service',
      data: {
        loopName: 'loopData',
        loopData: [1]
      },
      body: [
        {
          // 1、单独作为按钮放外面可以生效
          label: '刷新',
          type: 'action',
          actionType: 'reload',
          target: 'myService'
        },
        {
          type: 'button',
          label: '弹窗后刷新',
          level: 'primary',
          close: true,
          onEvent: {
            click: {
              actions: [
                {
                  actionType: 'loop',
                  args: {
                    loopName: '${loopName}'
                  },
                  children: [
                    {
                      actionType: 'toast',
                      args: {
                        msgType: 'warning',
                        msg: '我是全局警告消息,可以配置不同类型和弹出位置~',
                        position: 'top-right'
                      }
                    },
                    {
                      actionType: 'for'
                    },
                    {
                      // 2、【bug】在这里不生效
                      type: 'action',
                      actionType: 'reload',
                      target: 'myService'
                    }
                  ]
                }
              ]
            }
          }
        }
      ]
    },
    {
      type: 'crud',
      name: 'myService',
      draggable: true,
      syncLocation: false,
      api: 'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/sample',
      keepItemSelectionOnPageChange: true,
      autoGenerateFilter: true,
      bulkActions: [
        {
          type: 'button',
          label: '批量删除',
          actionType: 'ajax',
          api: 'delete:https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/sample/${ids|raw}',
          confirmText: '确定要批量删除?'
        },
        {
          type: 'button',
          label: '批量修改',
          actionType: 'dialog',
          dialog: {
            title: '批量编辑',
            name: 'sample-bulk-edit',
            body: {
              type: 'form',
              api: 'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/sample/bulkUpdate2',
              body: [
                {
                  type: 'hidden',
                  name: 'ids'
                },
                {
                  type: 'input-text',
                  name: 'engine',
                  label: 'Engine'
                }
              ]
            }
          }
        }
      ],
      quickSaveApi:
        'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/sample/bulkUpdate',
      quickSaveItemApi:
        'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/sample/$id',
      headerToolbar: [
        'bulkActions',
        {
          type: 'button',
          label: '重置测试数据',
          actionType: 'ajax',
          size: 'sm',
          api: 'https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/sample/reset'
        },
        'export-excel',
        {
          type: 'tpl',
          tpl: '一共有 ${count} 行数据。',
          className: 'v-middle'
        },
        {
          type: 'columns-toggler',
          align: 'right',
          draggable: true
        },
        {
          type: 'drag-toggler',
          align: 'right'
        }
      ],
      footerToolbar: ['statistics', 'switch-per-page', 'pagination'],
      columns: [
        {
          name: 'id',
          label: 'ID',
          width: 20,
          sortable: true,
          type: 'text',
          searchable: {
            type: 'input-text',
            name: 'id',
            label: '主键',
            placeholder: '输入id'
          }
        },
        {
          name: 'browser',
          label: 'Browser',
          searchable: {
            type: 'select',
            name: 'browser',
            label: '浏览器',
            placeholder: '选择浏览器',
            options: [
              {
                label: 'Internet Explorer ',
                value: 'ie'
              },
              {
                label: 'AOL browser',
                value: 'aol'
              },
              {
                label: 'Firefox',
                value: 'firefox'
              }
            ]
          }
        },
        {
          name: 'platform',
          label: '平台',
          popOver: {
            trigger: 'hover',
            body: {
              type: 'tpl',
              tpl: '就是为了演示有个叫 popOver 的功能'
            }
          },
          sortable: true,
          type: 'text'
        },
        {
          name: 'grade',
          label: 'CSS 等级',
          type: 'select',
          options: ['A', 'B', 'C', 'D', 'X']
        },
        {
          type: 'operation',
          label: '操作',
          width: 100,
          buttons: [
            {
              type: 'button',
              actionType: 'ajax',
              label: '删除',
              confirmText: '您确认要删除?',
              api: 'delete:https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/mock2/sample/$id'
            }
          ]
        }
      ]
    }
    ]
    }


4. 操作步骤
现状:点击“弹窗后刷新”,出现了弹窗,但是不会刷新目标组件。(点击“刷新”按钮可以看到正常刷新目标组件应该有的效果)
预期结果:先弹窗,然后组件刷新
github-actions[bot] commented 1 year ago

👍 Thanks for this! 🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

2betop commented 1 year ago

额外还有如下缺陷

  1. 循环目标为非对象数组场景
  2. 需要额外扩充一下属性
    • loopItemName 循环的时候使用字段名,默认用 _item,如果是嵌套 loop 必须设置,不然就取不到上级 loop 的值了
    • loopIndexName 循环时的 index 名,默认用 _index,如果是嵌套 loop 必须设置
    • firstIndex 起始 index
    • lastIndex 结束 index