Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(operation): 支持自定义EditItemDialog.Form的props和fields #147

Conversation

ly525
Copy link
Contributor

@ly525 ly525 commented May 3, 2021

使用场景:

  1. 编辑Table Item,希望对里面的某个字段禁用,不支持编辑,比如Id 等数据库自动生成的信息
  2. 支持自定义EditItemDialog.Form的相关Props,比如 label-width,防止label因为宽度不够导致换行
{
  ctx: "view",
  type: "table",
  operations: {
    "editItemDialog": {
      "type": "button",
      "label": "编辑",
      "props": {
        "icon": "el-icon-edit",
      },
      formProps: {
        "label-width": "120px"
      },
      fields: {
        uuid: false
      },
    },
  }
}

@wuzebin wuzebin merged commit bd1ddbe into vipshop:master May 12, 2021
ly525 added a commit to ly525/ams that referenced this pull request Jun 6, 2021
`this.$block.emitEvent(this.operation.event || this.operationKey, this.operation);`
变更为
`this.$block.emitEvent(this.operation.event || this.operationKey, { operation: this.operation });`

原因:
在某个场景下,比如:
```js
operations: {
  addItemDialog: {
    type: 'button',
    label: '编辑'
  }
}
```

如果按照 `this.$block.emitEvent(this.operation.event || this.operationKey, this.operation);` 这种写法,:
实际为:
`ams.callAction('addItemDialog',  this.operation //params)`
会导致:
```js
ams.callAction('addItemDialog',  this.operation //params)

// 即调用item.js 的
export async function addItemDialog(params) {
    await commonHandlerItem.call(this, { type: 'add', insertType: 'dialog', ...params });
}

```

这样会导致 ...params 即 this.operation.type 会覆盖 type: 'add',这样会导致 type为button,addItemDialog 的时候,按钮按照 `label: type === 'add' ? '添加' : '修改',`的逻辑,总是显示为:`修改`,而非`添加`

因此将 operation 作为一个对象进行传递,然后从中再获取具体的 fields、formProps、dialogProps 等配置,修正覆盖风险
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants