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(selection): add selection feature #WIK-16060 #12

Merged
merged 10 commits into from
Jul 24, 2024
Merged

Conversation

cmm-va
Copy link
Contributor

@cmm-va cmm-va commented Jul 19, 2024

No description provided.

effect(
() => {
this.aiTable.selection.set(this.aiTableGridSelectionService.selection());
console.log('跟新啦', this.aiTable.selection());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console

) {
effect(
() => {
this.aiTable.selection.set(this.aiTableGridSelectionService.selection());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aiTableGridSelectionService 中的 selection 和 aiTable.selection 中应该是同一个 signal ,这样就不需要维护两套 signal 数据

const data = this.gridData().records.map((item) => {
return { ...item, checked: checked };
});
this.gridData().records = data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gridData 中的数据应该是只从 buildGridData 中而来,外部不应该有修改它属性的逻辑。

如果是要修改 checked ,当 toggleAllCheckbox 事件触发时 :

  1. 应该优先修改 aiTable.selection 中的数据(这里是否需要通过 Actions.xxx 待定,当前在 AITableGridSelectionService 中修改也没问题)
  2. 同时在 buildGridData 中的数据源中加上 aiTable.selection ,并增加根据 aiTable.selection 计算出 checked 的逻辑
  3. 当 selection 数据发生变化时,gridData 会自动计算出正确的 checked


selectCell(recordId: string, fieldId: string) {
this.toggleAllCheckbox(false);
this.isSelectedAll = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 isSelectedAll 最好也是通过 aiTable.selection 计算得到

import { ThyTag } from 'ngx-tethys/tag';
import { ThyPopoverModule } from 'ngx-tethys/popover';
import { ThyPopover, ThyPopoverModule } from 'ngx-tethys/popover';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没用的引用删除一下

@@ -10,3 +10,13 @@ export class SelectOptionPipe implements PipeTransform {
return options.find((item) => item.id === id);
}
}

@Pipe({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没用到的删除

@@ -29,6 +34,116 @@ export class AITableGridEventService {
.subscribe((event) => {
this.dblClick(event as MouseEvent);
});

fromEvent<MouseEvent>(element, 'click')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

选中单元格的交互应该是 mousedown

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的逻辑有些奇怪,gridComponent 中已经针对行和列以及单元格的点击事件做处理了,这里又监听了 click 并且再区分点击的是什么,如果用操作 dom 的方式设置高亮在 gridComponent 中就可以实现

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个可以在 gridComponent 中实现,我觉得 这个高亮方案 不一定行 我心里觉得 ngClass 更好, 我就拆开写了,不行就删除了 ,不会影响我的 gridComponent 文件, gridComponent 文件 的点击事件 都很分散

this.updateAllClass(cell.element, 'add', (event.target as HTMLInputElement).checked);
}

this.lastClickCellElement = event.target as HTMLElement;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不能直接赋值吧,会出现点击到的不是 cell 的情况

private aiTableGridFieldService: AITableGridFieldService
) {}

ngOnInit(): void {
this.initAITable();
this.initService();
this.buildFieldMenus();
this.aiTableGridEventService.mousedownEvent$.subscribe((event) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. dom 中的事件监听使用 ngZone.runOutsideAngular 包一下,可以减少变化监测的次数
  2. 取消订阅

@@ -129,6 +143,14 @@ export class AITableGrid implements OnInit {
Actions.addRecord(this.aiTable, getDefaultRecord(this.aiFields()), [this.aiRecords().length]);
}

selectRow(recordId: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

行和列统一使用 record 和 field ,其他地方也一并改下吧

&.highlight {
background: variables.$secondary-item-active;
}
&.isSelected {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

css 中不使用驼峰

@@ -9,6 +9,9 @@

.grid-header {
border-top: 1px solid variables.$gray-200;
.grid-column-field {
justify-content: left;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

样式不对,左右应该都是有间距的,内容也是靠左显示

fromEvent<MouseEvent>(element, 'click')
.pipe(this.takeUntilDestroyed)
.subscribe((event) => {
this.mousedownEvent$.next(event as MouseEvent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

click 中的不应该是 mousedownEvent

}

updateSelect(event: MouseEvent) {
const cell = this.cellType(event.target as HTMLElement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 cellType 名字不太合适,里面有 field 相关的代码,感觉可以移除了, 把里面逻辑直接写在这个函数里

@huanhuanwa huanhuanwa merged commit 0392723 into develop Jul 24, 2024
1 check passed
@huanhuanwa huanhuanwa deleted the #WIK-16060 branch July 24, 2024 07:36
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