Skip to content

Commit

Permalink
fix(comp:table): the indent not work and selected records not cached (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
danranVm committed Mar 6, 2023
1 parent e044390 commit a3d5bb7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 31 deletions.
Expand Up @@ -63,9 +63,9 @@ exports[`Table > basic work > render work 1`] = `
</td>
</tr>
<tr class=\\"ix-table-row\\">
<td class=\\"ix-table-cell\\">
<!----><a>expandable</a>
</td>
<td class=\\"ix-table-cell\\"><button class=\\"ix-table-expandable-trigger\\" type=\\"button\\">
<!---->
</button><a>expandable</a></td>
<td class=\\"ix-table-cell\\">
<!----><label class=\\"ix-checkbox\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-disabled=\\"false\\"><span class=\\"ix-checkbox-input\\"><input type=\\"checkbox\\" class=\\"ix-checkbox-input-inner\\" aria-hidden=\\"true\\"><span class=\\"ix-checkbox-input-box\\"><div aria-hidden=\\"true\\" class=\\"ix-wave\\"></div></span></span>
<!---->
Expand All @@ -92,9 +92,9 @@ exports[`Table > basic work > render work 1`] = `
</td>
</tr>
<tr class=\\"ix-table-row\\">
<td class=\\"ix-table-cell\\">
<!----><a>expandable</a>
</td>
<td class=\\"ix-table-cell\\"><button class=\\"ix-table-expandable-trigger\\" type=\\"button\\">
<!---->
</button><a>expandable</a></td>
<td class=\\"ix-table-cell\\">
<!----><label class=\\"ix-checkbox\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-disabled=\\"false\\"><span class=\\"ix-checkbox-input\\"><input type=\\"checkbox\\" class=\\"ix-checkbox-input-inner\\" aria-hidden=\\"true\\"><span class=\\"ix-checkbox-input-box\\"><div aria-hidden=\\"true\\" class=\\"ix-wave\\"></div></span></span>
<!---->
Expand Down Expand Up @@ -148,9 +148,9 @@ exports[`Table > basic work > render work 1`] = `
</td>
</tr>
<tr class=\\"ix-table-row\\">
<td class=\\"ix-table-cell\\">
<!----><a>expandable</a>
</td>
<td class=\\"ix-table-cell\\"><button class=\\"ix-table-expandable-trigger\\" type=\\"button\\">
<!---->
</button><a>expandable</a></td>
<td class=\\"ix-table-cell\\">
<!----><label class=\\"ix-checkbox\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-disabled=\\"false\\"><span class=\\"ix-checkbox-input\\"><input type=\\"checkbox\\" class=\\"ix-checkbox-input-inner\\" aria-hidden=\\"true\\"><span class=\\"ix-checkbox-input-box\\"><div aria-hidden=\\"true\\" class=\\"ix-wave\\"></div></span></span>
<!---->
Expand All @@ -177,9 +177,9 @@ exports[`Table > basic work > render work 1`] = `
</td>
</tr>
<tr class=\\"ix-table-row\\">
<td class=\\"ix-table-cell\\">
<!----><a>expandable</a>
</td>
<td class=\\"ix-table-cell\\"><button class=\\"ix-table-expandable-trigger\\" type=\\"button\\">
<!---->
</button><a>expandable</a></td>
<td class=\\"ix-table-cell\\">
<!----><label class=\\"ix-checkbox\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-disabled=\\"false\\"><span class=\\"ix-checkbox-input\\"><input type=\\"checkbox\\" class=\\"ix-checkbox-input-inner\\" aria-hidden=\\"true\\"><span class=\\"ix-checkbox-input-box\\"><div aria-hidden=\\"true\\" class=\\"ix-wave\\"></div></span></span>
<!---->
Expand Down Expand Up @@ -233,9 +233,9 @@ exports[`Table > basic work > render work 1`] = `
</td>
</tr>
<tr class=\\"ix-table-row\\">
<td class=\\"ix-table-cell\\">
<!----><a>expandable</a>
</td>
<td class=\\"ix-table-cell\\"><button class=\\"ix-table-expandable-trigger\\" type=\\"button\\">
<!---->
</button><a>expandable</a></td>
<td class=\\"ix-table-cell\\">
<!----><label class=\\"ix-checkbox\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-disabled=\\"false\\"><span class=\\"ix-checkbox-input\\"><input type=\\"checkbox\\" class=\\"ix-checkbox-input-inner\\" aria-hidden=\\"true\\"><span class=\\"ix-checkbox-input-box\\"><div aria-hidden=\\"true\\" class=\\"ix-wave\\"></div></span></span>
<!---->
Expand All @@ -262,9 +262,9 @@ exports[`Table > basic work > render work 1`] = `
</td>
</tr>
<tr class=\\"ix-table-row\\">
<td class=\\"ix-table-cell\\">
<!----><a>expandable</a>
</td>
<td class=\\"ix-table-cell\\"><button class=\\"ix-table-expandable-trigger\\" type=\\"button\\">
<!---->
</button><a>expandable</a></td>
<td class=\\"ix-table-cell\\">
<!----><label class=\\"ix-checkbox\\" role=\\"checkbox\\" aria-checked=\\"false\\" aria-disabled=\\"false\\"><span class=\\"ix-checkbox-input\\"><input type=\\"checkbox\\" class=\\"ix-checkbox-input-inner\\" aria-hidden=\\"true\\"><span class=\\"ix-checkbox-input-box\\"><div aria-hidden=\\"true\\" class=\\"ix-wave\\"></div></span></span>
<!---->
Expand Down
7 changes: 7 additions & 0 deletions packages/components/table/demo/Server.vue
Expand Up @@ -55,6 +55,13 @@ interface RandomUser {
}
const columns: TableColumn<RandomUser>[] = [
{
type: 'selectable',
align: 'center',
multiple: true,
showIndex: false,
onChange: console.log,
},
{
key: 'Name',
title: 'Name',
Expand Down
2 changes: 1 addition & 1 deletion packages/components/table/demo/TreeTable.vue
Expand Up @@ -34,7 +34,7 @@ const columns: TableColumn<Data>[] = [
{
type: 'expandable',
width: 160,
indent: 10,
indent: 16,
title: 'Event Name',
dataKey: 'eventName',
customCell: 'name',
Expand Down
2 changes: 1 addition & 1 deletion packages/components/table/docs/Api.zh.md
Expand Up @@ -85,7 +85,7 @@ export type TableColumn<T = any, V = any> =
| `type` | 列类型 | `'expandable'` | - | - | 必填 |
| `disabled` | 设置是否允许行展开 | `(record:T) => boolean` | - | - | - |
| `icon` | 展开按钮图标 | `string \| VNode \| ((data: { expanded: boolean; record: T }) => string \| VNodeChild)` | `'right'` | ✅ | - |
| `indent` | 展示树形数据时,每层缩进的宽度 | `number` | `12` | - | - |
| `indent` | 展示树形数据时,每层缩进的宽度 | `number` | - | - | - |
| `trigger` | 不通过图标,触发行展开的方式 | `'click' \| 'doubleClick'` | - | - | - |
| `onChange` | 展开状态发生变化时触发 | `(expendedRowKeys: (string \| number)[], expendedRecords: T[]) => void` | - | - | - |
| `onExpand` | 点击展开图标,或通过 `trigger` 触发 | `(expanded: boolean, record: T) => void` | - | - | - |
Expand Down
15 changes: 14 additions & 1 deletion packages/components/table/src/composables/useSelectable.ts
Expand Up @@ -90,15 +90,28 @@ export function useSelectable(

// 当前页是否部分被选中
const currentPageSomeSelected = computed(() => !currentPageAllSelected.value && countCurrentPageSelected.value > 0)
// 缓存已经被选中的数据,考虑到后端分页的清空,dataMap 中没有全部的数据
const cacheSelectedMap = new Map<VKey, MergedData>()

const emitChange = (tempRowKeys: VKey[]) => {
setSelectedRowKeys(tempRowKeys)
const dataMap = mergedMap.value
const { onChange } = selectable.value || {}
if (onChange) {
const selectedRecords: unknown[] = []
// 清理掉缓存中被取消选中的数据
cacheSelectedMap.forEach((_, key) => {
if (!tempRowKeys.includes(key)) {
cacheSelectedMap.delete(key)
}
})
tempRowKeys.forEach(key => {
const currData = dataMap.get(key)
let currData = dataMap.get(key)
if (currData) {
cacheSelectedMap.set(key, currData)
} else {
currData = cacheSelectedMap.get(key)
}
currData && selectedRecords.push(currData.record)
})
callEmit(onChange, tempRowKeys, selectedRecords)
Expand Down
20 changes: 10 additions & 10 deletions packages/components/table/src/main/body/BodyCell.tsx
Expand Up @@ -178,21 +178,21 @@ function renderExpandableChildren(
expandable: ComputedRef<TableColumnMergedExpandable | undefined>,
prefixCls: string,
) {
if (props.disabled) {
return undefined
}

const { icon, customIcon, indent } = expandable.value!
const { record, expanded, level = 0 } = props
const style = indent ? `margin-left: ${convertCssPixel(level * indent)}` : undefined

let iconNode: VNodeChild | null
const iconRender = (isString(customIcon) ? slots[customIcon] : customIcon) ?? icon
if (isFunction(iconRender)) {
iconNode = iconRender({ expanded: !!expanded, record })
} else {
iconNode = isString(iconRender) ? <IxIcon name={iconRender} rotate={expanded ? 90 : 0} /> : iconRender
let iconNode: VNodeChild

if (!props.disabled) {
const iconRender = (isString(customIcon) ? slots[customIcon] : customIcon) ?? icon
if (isFunction(iconRender)) {
iconNode = iconRender({ expanded: !!expanded, record })
} else {
iconNode = isString(iconRender) ? <IxIcon name={iconRender} rotate={expanded ? 90 : 0} /> : iconRender
}
}

return (
<button class={`${prefixCls}-expandable-trigger`} style={style} type="button" onClick={props.handleExpend}>
{iconNode}
Expand Down

0 comments on commit a3d5bb7

Please sign in to comment.