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: apply icon and width #WIK-16166 #17

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions packages/grid/src/core/constants/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,38 @@ export const BasicFields = [
{
type: AITableFieldType.Text,
name: '文本',
icon: 'font'
icon: 'font',
width: 300
},
{
type: AITableFieldType.SingleSelect,
name: '单选',
icon: 'check-circle'
icon: 'check-circle',
width: 200
},
{
type: AITableFieldType.Number,
name: '数字',
icon: 'hashtag'
icon: 'hashtag',
width: 200
},
{
type: AITableFieldType.DateTime,
name: '日期',
icon: 'calendar'
icon: 'calendar',
width: 200
},
{
type: AITableFieldType.Rating,
name: '评分',
icon: 'star-circle'
icon: 'star-circle',
width: 200
},
{
type: AITableFieldType.Link,
name: '链接',
icon: 'link-insert'
icon: 'link-insert',
width: 300
}
];

Expand Down
4 changes: 3 additions & 1 deletion packages/grid/src/core/types/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export interface AITableField {
id: string;
name: string;
type: AITableFieldType;
width?: string;
icon?: string;
width?: number;
hidden?: boolean;
frozen?: boolean;
statType?: AITableStatType;
Expand Down Expand Up @@ -90,4 +91,5 @@ export interface AITableFieldInfo {
type: AITableFieldType;
name: string;
icon: string;
width: number;
}
15 changes: 10 additions & 5 deletions packages/grid/src/grid.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
</div>
@for (field of gridData().fields; track field.id) {
<div
class="grid-cell grid-column-field"
class="grid-cell grid-field"
#fieldAction
[attr.fieldId]="field.id"
[ngClass]="{ highlight: aiTable.selection().selectedFields.has(field.id) }"
[ngStyle]="{ width: field.width + 'px' }"
>
{{ field.name }}
<a thyAction thyActiveClass="active" thyIcon="more-vertical" [thyDropdown]="fieldMenu" href="javascript:;">
<span>
<thy-icon [thyIconName]="field.icon!" class="mr-2 text-muted"></thy-icon>
<span>{{ field.name }}</span>
</span>
<a class="grid-field-action" thyAction thyActiveClass="active" thyIcon="more-vertical" [thyDropdown]="fieldMenu" href="javascript:;">
<thy-dropdown-menu #fieldMenu>
<field-menu [origin]="fieldAction" [field]="field" [aiTable]="aiTable" [fieldMenus]="fieldMenus"></field-menu>
</thy-dropdown-menu>
Expand Down Expand Up @@ -44,6 +48,7 @@
[attr.type]="[field.type]"
[attr.fieldId]="[field.id]"
[attr.recordId]="[record.id]"
[ngStyle]="{ width: field.width + 'px' }"
#cell
>
@switch (field.type) {
Expand All @@ -60,7 +65,7 @@
}
@case (AITableFieldType.Link) {
<a
class="d-block pl-4 pr-4"
class="d-block"
thyStopPropagation
thyFlexibleText
[thyTooltipContent]="record.value[field.id]?.text"
Expand All @@ -70,7 +75,7 @@
>
}
@default {
{{ record.value[field.id] }}
<span class="text-truncate"> {{ record.value[field.id] }}</span>
}
}
<div class="autofill-container"></div>
Expand Down
1 change: 1 addition & 0 deletions packages/grid/src/services/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class AITableGridEventService {
height: height + 2 + 'px',
placement: 'top',
offset: -(height + 4),
minWidth: width,
initialState: {
field: field,
record: record,
Expand Down
2 changes: 1 addition & 1 deletion packages/grid/src/services/selection.servive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class AITableGridSelectionService {
updateSelect(event: MouseEvent) {
const target = event.target as HTMLElement;
const cellDom = target.closest('.grid-cell');
const colDom = target.closest('.grid-column-field');
const colDom = target.closest('.grid-field');
if (cellDom) {
const fieldId = cellDom.getAttribute('fieldId');
const recordId = cellDom.getAttribute('recordId');
Expand Down
16 changes: 14 additions & 2 deletions packages/grid/src/styles/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
.grid-cell {
min-height: 44px;
max-height: 148px;
overflow: auto;
display: flex;
align-items: center;
width: 300px;
border-left: 1px solid variables.$gray-200;
padding-left: 12px;
padding: 0 12px;
position: relative;
cursor: pointer;
justify-content: space-between;
.autofill-container {
position: absolute;
width: 4px;
Expand All @@ -67,6 +67,18 @@
}
}
}

.grid-field {
.grid-field-action {
visibility: hidden;
}
&:hover {
.grid-field-action {
visibility: visible;
}
}
}

.grid-column-blank {
flex: 1;
min-width: 180px;
Expand Down
10 changes: 8 additions & 2 deletions packages/grid/src/utils/build.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { AITableFields, AITableRecords } from '../core';
import { AITableFields, AITableRecords, FieldsMap } from '../core';
import { AITableGridData, AITableSelection } from '../types';

export const buildGridData = (recordValue: AITableRecords, fieldsValue: AITableFields, selection: AITableSelection): AITableGridData => {
return {
type: 'grid',
fields: fieldsValue,
fields: fieldsValue.map(item=>{
return {
...item,
icon: item.icon || FieldsMap[item.type].icon,
Copy link
Contributor

Choose a reason for hiding this comment

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

如果 item.icon 和 item.width 可能不存在,那么就需要加上 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

不用加吧,不存在就使用FieldsMap[item.type] 中的了

width: item.width || FieldsMap[item.type].width
}
}),
records: recordValue.map((item) => {
return { ...item, checked: selection.selectedRecords.has(item.id) };
})
Expand Down