diff --git a/packages/grid/src/components/cell-editors/select/select-editor.component.ts b/packages/grid/src/components/cell-editors/select/select-editor.component.ts index 18bfc22b..75f83e98 100644 --- a/packages/grid/src/components/cell-editors/select/select-editor.component.ts +++ b/packages/grid/src/components/cell-editors/select/select-editor.component.ts @@ -15,7 +15,7 @@ export interface AITableSingleSelectField extends AITableField - + `, standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, diff --git a/packages/grid/src/components/field-menu/field-menu.component.html b/packages/grid/src/components/field-menu/field-menu.component.html index eb11e089..fd155425 100644 --- a/packages/grid/src/components/field-menu/field-menu.component.html +++ b/packages/grid/src/components/field-menu/field-menu.component.html @@ -1,5 +1,5 @@ @for (menu of fieldMenus; track index; let index = $index) { - @if (menu.id === 'divider') { + @if (menu._id === 'divider') { } @else { diff --git a/packages/grid/src/components/field-property-editor/field-property-editor.component.ts b/packages/grid/src/components/field-property-editor/field-property-editor.component.ts index e2e91a3f..5fddf957 100644 --- a/packages/grid/src/components/field-property-editor/field-property-editor.component.ts +++ b/packages/grid/src/components/field-property-editor/field-property-editor.component.ts @@ -88,7 +88,7 @@ export class AITableFieldPropertyEditor { checkUniqueName = (fieldName: string) => { fieldName = fieldName?.trim(); - return of(!!this.aiTable.fields()?.find((field) => field.name === fieldName && this.aiField()?.id !== field.id)); + return of(!!this.aiTable.fields()?.find((field) => field.name === fieldName && this.aiField()?._id !== field._id)); }; selectFieldType(fieldType: AITableFieldType) { @@ -97,7 +97,7 @@ export class AITableFieldPropertyEditor { editFieldProperty() { if (this.isUpdate) { - const path = this.aiTable.fields().findIndex((item) => item.id === this.aiField().id); + const path = this.aiTable.fields().findIndex((item) => item._id === this.aiField()._id); Actions.setField(this.aiTable, this.aiField(), [path]); } else { Actions.addField(this.aiTable, this.aiField(), [this.aiTable.fields().length]); diff --git a/packages/grid/src/constants/field.ts b/packages/grid/src/constants/field.ts index 926c6503..bc6b86f0 100644 --- a/packages/grid/src/constants/field.ts +++ b/packages/grid/src/constants/field.ts @@ -4,11 +4,11 @@ import { ElementRef, signal, Signal, WritableSignal } from '@angular/core'; import { AITableFieldMenuItem } from '../types'; export const DividerMenuItem = { - id: 'divider' + _id: 'divider' }; export const EditFieldPropertyItem = { - id: 'editFieldProperty', + _id: 'editFieldProperty', name: '编辑列', icon: 'edit', exec: (aiTable: AITable, field: Signal, origin?: HTMLElement | ElementRef) => { @@ -19,7 +19,7 @@ export const EditFieldPropertyItem = { }; export const RemoveFieldItem = { - id: 'removeField', + _id: 'removeField', name: '删除列', icon: 'trash', exec: (aiTable: AITable, field: Signal) => { diff --git a/packages/grid/src/core/action/general.ts b/packages/grid/src/core/action/general.ts index e0329ab5..b4149464 100644 --- a/packages/grid/src/core/action/general.ts +++ b/packages/grid/src/core/action/general.ts @@ -7,7 +7,7 @@ const apply = (aiTable: AITable, records: AITableRecords, fields: AITableFields, case ActionName.UpdateFieldValue: { const [recordIndex, fieldIndex] = options.path; if (fieldIndex > -1 && recordIndex > -1) { - const fieldId = aiTable.fields()[fieldIndex].id; + const fieldId = aiTable.fields()[fieldIndex]._id; records[recordIndex].values[fieldId] = options.newFieldValue; } break; @@ -25,7 +25,7 @@ const apply = (aiTable: AITable, records: AITableRecords, fields: AITableFields, const newField = options.field; fields.splice(fieldIndex, 0, newField); const newRecord = { - [newField.id]: '' + [newField._id]: '' }; records.forEach((item) => { item.values = { @@ -59,7 +59,7 @@ const apply = (aiTable: AITable, records: AITableRecords, fields: AITableFields, case ActionName.RemoveField: { const [fieldIndex] = options.path; if (fieldIndex > -1) { - const fieldId = aiTable.fields()[fieldIndex].id; + const fieldId = aiTable.fields()[fieldIndex]._id; fields.splice(fieldIndex, 1); records.forEach((item) => { delete item.values[fieldId]; diff --git a/packages/grid/src/core/types/core.ts b/packages/grid/src/core/types/core.ts index 0c177b43..23f28593 100644 --- a/packages/grid/src/core/types/core.ts +++ b/packages/grid/src/core/types/core.ts @@ -38,13 +38,15 @@ export enum AITableStatType { } export interface AITableSelectOption { - id: string; - name: string; + _id: string; + text: string; color?: string; + bg_color?: string; + [key: string]: any; } export interface AITableField { - id: string; + _id: string; name: string; type: AITableFieldType; icon?: string; @@ -81,7 +83,7 @@ export type FieldValue = | any; export interface AITableRecord { - id: string; + _id: string; checked?: boolean; values: Record; } diff --git a/packages/grid/src/core/utils/field.ts b/packages/grid/src/core/utils/field.ts index bac45ca0..a88f28c4 100644 --- a/packages/grid/src/core/utils/field.ts +++ b/packages/grid/src/core/utils/field.ts @@ -13,5 +13,5 @@ export function createDefaultFieldName(aiTable: AITable, type: AITableFieldType } export function createDefaultField(aiTable: AITable, type: AITableFieldType = AITableFieldType.text) { - return { id: idCreator(), type, name: createDefaultFieldName(aiTable, type) }; + return { _id: idCreator(), type, name: createDefaultFieldName(aiTable, type) }; } diff --git a/packages/grid/src/core/utils/queries.ts b/packages/grid/src/core/utils/queries.ts index 52fd9578..dc22a133 100644 --- a/packages/grid/src/core/utils/queries.ts +++ b/packages/grid/src/core/utils/queries.ts @@ -34,7 +34,7 @@ export const AITableQueries = { if (!field) { throw new Error(`can not find field at path [${path}]`); } - return aiTable.records()[path[0]].values[field.id]; + return aiTable.records()[path[0]].values[field._id]; }, getField(aiTable: AITable, path: AIFieldPath): AITableField { diff --git a/packages/grid/src/core/utils/record.ts b/packages/grid/src/core/utils/record.ts index f64b680b..b8e8e9dd 100644 --- a/packages/grid/src/core/utils/record.ts +++ b/packages/grid/src/core/utils/record.ts @@ -4,11 +4,11 @@ import { idCreator } from './id-creator'; export function getDefaultRecord(fields: AITableFields) { const newRow: AITableRecord = { - id: idCreator(), + _id: idCreator(), values: {} }; fields.map((item) => { - newRow.values[item.id] = getDefaultFieldValue(item.type); + newRow.values[item._id] = getDefaultFieldValue(item.type); }); return newRow; } diff --git a/packages/grid/src/grid.component.html b/packages/grid/src/grid.component.html index e6b8e146..33ab7cce 100644 --- a/packages/grid/src/grid.component.html +++ b/packages/grid/src/grid.component.html @@ -2,12 +2,12 @@
- @for (field of gridData().fields; track field.id) { + @for (field of gridData().fields; track field._id) {
@@ -23,7 +23,7 @@ href="javascript:;" > - +
@@ -33,15 +33,15 @@
- @for (record of gridData().records; track record.id; let index = $index) { -
+ @for (record of gridData().records; track record._id; let index = $index) { +
{{ index + 1 }}
@@ -50,51 +50,51 @@ #cell class="grid-cell" [ngClass]="{ - highlight: aiTable.selection().selectedCells.has(record.id) || aiTable.selection().selectedFields.has(field.id), - selected: aiTable.selection().selectedCells.get(record.id)?.hasOwnProperty(field.id) + highlight: aiTable.selection().selectedCells.has(record._id) || aiTable.selection().selectedFields.has(field._id), + selected: aiTable.selection().selectedCells.get(record._id)?.hasOwnProperty(field._id) }" [attr.type]="[field.type]" - [attr.fieldId]="[field.id]" - [attr.recordId]="[record.id]" + [attr.fieldId]="[field._id]" + [attr.recordId]="[record._id]" [ngStyle]="{ width: field.width + 'px' }" > @switch (field.type) { @case (AITableFieldType.select) { - @if (!field.isMultiple && record.values[field.id] | selectOption: field['options']; as selectedOption) { - {{ selectedOption.name }} + @if (!field.isMultiple && record.values[field._id] | selectOption: field['options']; as selectedOption) { + {{ selectedOption.text }} } } @case (AITableFieldType.date) { - {{ record.values[field.id] | thyDatePickerFormat }} + {{ record.values[field._id] | thyDatePickerFormat }} } @case (AITableFieldType.rate) { - + } @case (AITableFieldType.link) { - {{ record.values[field.id]?.text }} + {{ record.values[field._id]?.text }} } @case (AITableFieldType.progress) { - {{ record.values[field.id] }}{{ record.values[field.id]?.config?.suffix || '%' }} + {{ record.values[field._id] }}{{ record.values[field._id]?.config?.suffix || '%' }} } @default { - {{ record.values[field.id] }} + {{ record.values[field._id] }} } }
diff --git a/packages/grid/src/pipes/grid.ts b/packages/grid/src/pipes/grid.ts index 25525bc0..49cb3bc2 100644 --- a/packages/grid/src/pipes/grid.ts +++ b/packages/grid/src/pipes/grid.ts @@ -6,7 +6,7 @@ import { AITableSelectOption } from '../core'; standalone: true }) export class SelectOptionPipe implements PipeTransform { - transform(id: string, options: AITableSelectOption[]) { - return options.find((item) => item.id === id); + transform(_id: string, options: AITableSelectOption[]) { + return options.find((item) => item._id === _id); } } diff --git a/packages/grid/src/services/selection.service.ts b/packages/grid/src/services/selection.service.ts index 25caba82..116d10f8 100644 --- a/packages/grid/src/services/selection.service.ts +++ b/packages/grid/src/services/selection.service.ts @@ -46,7 +46,7 @@ export class AITableGridSelectionService { this.clearSelection(); if (checked) { this.aiTable.records().forEach((item) => { - this.selectRecord(item.id); + this.selectRecord(item._id); }); } } diff --git a/packages/grid/src/styles/styles.scss b/packages/grid/src/styles/styles.scss index 7f9da975..c8f30243 100644 --- a/packages/grid/src/styles/styles.scss +++ b/packages/grid/src/styles/styles.scss @@ -135,14 +135,6 @@ align-items: center; } - .text-column { - width: 100%; - height: 100%; - display: flex; - align-items: center; - justify-content: center; - } - .cell-active { border: 1px solid variables.$primary; margin-left: 0.5px; diff --git a/packages/grid/src/types/field.ts b/packages/grid/src/types/field.ts index a35ca0c2..f67d376b 100644 --- a/packages/grid/src/types/field.ts +++ b/packages/grid/src/types/field.ts @@ -2,7 +2,7 @@ import { ElementRef, Signal } from '@angular/core'; import { AITable, AITableField } from '../core'; export interface AITableFieldMenuItem { - id: string; + _id: string; name?: string; icon?: string; exec?: (aiTable: AITable, field: Signal, origin?: HTMLElement | ElementRef) => void; diff --git a/packages/grid/src/utils/build.ts b/packages/grid/src/utils/build.ts index 88f345d5..c1c85dc1 100644 --- a/packages/grid/src/utils/build.ts +++ b/packages/grid/src/utils/build.ts @@ -12,7 +12,7 @@ export const buildGridData = (recordValue: AITableRecords, fieldsValue: AITableF } }), records: recordValue.map((item) => { - return { ...item, checked: selection.selectedRecords.has(item.id) }; + return { ...item, checked: selection.selectedRecords.has(item._id) }; }) }; }; diff --git a/packages/grid/src/utils/cell.ts b/packages/grid/src/utils/cell.ts index 79fb1924..7238381b 100644 --- a/packages/grid/src/utils/cell.ts +++ b/packages/grid/src/utils/cell.ts @@ -1,8 +1,8 @@ import { computed, Signal } from '@angular/core'; import { AITableField, AITableFields, AITableRecord, AITableRecords } from '../core'; -export function getRecordOrField(value: Signal, id: string): Signal { +export function getRecordOrField(value: Signal, _id: string): Signal { return computed(() => { - return value().find((item) => item.id === id)!; + return value().find((item) => item._id === _id)!; }); } diff --git a/src/app/component/common/content/content.component.ts b/src/app/component/common/content/content.component.ts index cd5bfa46..27e6fa2c 100644 --- a/src/app/component/common/content/content.component.ts +++ b/src/app/component/common/content/content.component.ts @@ -43,15 +43,15 @@ export class DemoTableContent { listOfOption = [ { value: 'short', - text: 'short' + name: 'short' }, { value: 'medium', - text: 'medium' + name: 'medium' }, { value: 'tall', - text: 'tall' + name: 'tall' } ]; @@ -61,7 +61,7 @@ export class DemoTableContent { EditFieldPropertyItem, DividerMenuItem, { - id: 'filterFields', + _id: 'filterFields', name: '按本列筛选', icon: 'filter-line', exec: (aiTable: AITable, field: Signal) => {}, @@ -138,7 +138,7 @@ export class DemoTableContent { removeRecord() { const recordIds = [...this.aiTable.selection().selectedRecords.keys()]; recordIds.forEach((item) => { - const path = this.aiTable.records().findIndex((record) => record.id === item); + const path = this.aiTable.records().findIndex((record) => record._id === item); Actions.removeRecord(this.aiTable, [path]); }); } @@ -146,7 +146,7 @@ export class DemoTableContent { moveField() { const newIndex = 2; const selectedFieldIds = [...this.aiTable.selection().selectedFields.keys()]; - const selectedRecords = this.aiTable.fields().filter((item) => selectedFieldIds.includes(item.id)); + const selectedRecords = this.aiTable.fields().filter((item) => selectedFieldIds.includes(item._id)); selectedRecords.forEach((item) => { const path = AITableQueries.findPath(this.aiTable, item) as AIFieldPath; Actions.moveField(this.aiTable, path, [newIndex]); @@ -155,7 +155,7 @@ export class DemoTableContent { moveRecord() { const selectedRecordIds = [...this.aiTable.selection().selectedRecords.keys()]; - const selectedRecords = this.aiTable.records().filter((item) => selectedRecordIds.includes(item.id)); + const selectedRecords = this.aiTable.records().filter((item) => selectedRecordIds.includes(item._id)); const selectedRecordsAfterNewPath: AITableRecord[] = []; let offset = 0; const newIndex = 2; diff --git a/src/app/component/table.component.html b/src/app/component/table.component.html index da3f296f..53ebcd98 100644 --- a/src/app/component/table.component.html +++ b/src/app/component/table.component.html @@ -4,9 +4,9 @@ tableService.provider ? '断开连接' : '连接协同' }}
- + @for (item of tableService.views(); track $index) { - + @if (item.isActive) { } diff --git a/src/app/component/table.component.ts b/src/app/component/table.component.ts index 27a0021b..f6ccfe61 100644 --- a/src/app/component/table.component.ts +++ b/src/app/component/table.component.ts @@ -10,8 +10,8 @@ import { ThyInputDirective } from 'ngx-tethys/input'; import { TableService } from '../service/table.service'; const initViews = [ - { id: 'view1', name: '表格视图1', isActive: true }, - { id: 'view2', name: '表格视图2' } + { _id: 'view1', name: '表格视图1', isActive: true }, + { _id: 'view2', name: '表格视图2' } ]; @Component({ @@ -37,7 +37,7 @@ export class DemoTable implements OnInit, OnDestroy { activeTabChange(data: any) { this.tableService.updateActiveView(data); - this.router.navigateByUrl(`/${this.tableService.activeView().id}`); + this.router.navigateByUrl(`/${this.tableService.activeView()._id}`); } handleShared() { diff --git a/src/app/service/table.service.ts b/src/app/service/table.service.ts index b17358f3..f410648d 100644 --- a/src/app/service/table.service.ts +++ b/src/app/service/table.service.ts @@ -37,10 +37,10 @@ export class TableService { this.views.update((value) => { const draftViews = createDraft(value); draftViews.forEach((item) => { - if (item.isActive && item.id !== activeViewId) { + if (item.isActive && item._id !== activeViewId) { item.isActive = false; } - if (!item.isActive && item.id === activeViewId) { + if (!item.isActive && item._id === activeViewId) { item.isActive = true; } }); @@ -53,11 +53,11 @@ export class TableService { } buildRenderRecords(records?: DemoAIRecord[]) { - this.records = signal(sortDataByView(records ?? this.records(), this.activeView().id) as DemoAIRecord[]); + this.records = signal(sortDataByView(records ?? this.records(), this.activeView()._id) as DemoAIRecord[]); } buildRenderFields(fields?: DemoAIField[]) { - this.fields = signal(sortDataByView(fields ?? this.fields(), this.activeView().id) as DemoAIField[]); + this.fields = signal(sortDataByView(fields ?? this.fields(), this.activeView()._id) as DemoAIField[]); } handleShared(room: string) { diff --git a/src/app/share/apply-to-table/array-event.ts b/src/app/share/apply-to-table/array-event.ts index 3a52945c..8d433d4c 100644 --- a/src/app/share/apply-to-table/array-event.ts +++ b/src/app/share/apply-to-table/array-event.ts @@ -42,7 +42,7 @@ export default function translateArrayEvent(aiTable: AITable, event: Y.YEvent> { const nonEditableArray = new Y.Array(); - nonEditableArray.insert(0, [record['id']]); + nonEditableArray.insert(0, [record['_id']]); const editableArray = new Y.Array(); const editableFields = []; diff --git a/src/app/share/utils/translate-to-table.ts b/src/app/share/utils/translate-to-table.ts index b9e8a96f..9e68541b 100644 --- a/src/app/share/utils/translate-to-table.ts +++ b/src/app/share/utils/translate-to-table.ts @@ -3,7 +3,7 @@ import { SharedType } from '../shared'; import { DemoAIField, DemoAIRecord } from '../../types'; export const translateRecord = (arrayRecord: any[], fields: AITableFields) => { - const fieldIds = fields.map((item) => item.id); + const fieldIds = fields.map((item) => item._id); const recordValue: Record = {}; fieldIds.forEach((item, index) => { recordValue[item] = arrayRecord[index] || ''; @@ -17,7 +17,7 @@ export const translateSharedTypeToTable = (sharedType: SharedType) => { const records: DemoAIRecord[] = data['records'].map((record: any) => { const [nonEditableArray, editableArray] = record; return { - id: nonEditableArray[0], + _id: nonEditableArray[0], positions: editableArray[editableArray.length - 1], values: translateRecord(editableArray.slice(0, editableArray.length - 1), fields) }; diff --git a/src/app/types/view.ts b/src/app/types/view.ts index 675a2be8..e73b2a85 100644 --- a/src/app/types/view.ts +++ b/src/app/types/view.ts @@ -8,7 +8,7 @@ export enum Direction { } export interface AITableView { - id: string; + _id: string; name: string; emoji_icon?: string; isActive?: boolean; diff --git a/src/app/utils/utils.ts b/src/app/utils/utils.ts index f14c7f6d..131f71f7 100644 --- a/src/app/utils/utils.ts +++ b/src/app/utils/utils.ts @@ -47,7 +47,7 @@ export function getDefaultValue() { } = { records: [ { - id: 'row-1', + _id: 'row-1', positions: { view1: 0, view2: 1 @@ -64,7 +64,7 @@ export function getDefaultValue() { } }, { - id: 'row-2', + _id: 'row-2', positions: { view1: 1, view2: 2 @@ -78,7 +78,7 @@ export function getDefaultValue() { } }, { - id: 'row-3', + _id: 'row-3', positions: { view1: 2, view2: 0 @@ -94,7 +94,7 @@ export function getDefaultValue() { ], fields: [ { - id: 'column-1', + _id: 'column-1', name: '文本', positions: { view1: 0, @@ -103,7 +103,7 @@ export function getDefaultValue() { type: AITableFieldType.text }, { - id: 'column-2', + _id: 'column-2', name: '单选', positions: { view1: 1, @@ -112,24 +112,24 @@ export function getDefaultValue() { type: AITableFieldType.select, options: [ { - id: '1', - name: '开始', + _id: '1', + text: '开始', color: '#5dcfff' }, { - id: '2', - name: '进行中', + _id: '2', + text: '进行中', color: '#ffcd5d' }, { - id: '3', - name: '已完成', + _id: '3', + text: '已完成', color: '#73d897' } ] }, { - id: 'column-3', + _id: 'column-3', name: '链接', positions: { view1: 2, @@ -138,7 +138,7 @@ export function getDefaultValue() { type: AITableFieldType.link }, { - id: 'column-4', + _id: 'column-4', name: '评分', positions: { view1: 3, @@ -147,7 +147,7 @@ export function getDefaultValue() { type: AITableFieldType.rate }, { - id: 'column-5', + _id: 'column-5', name: '进度', positions:{ view1: 4, @@ -162,7 +162,7 @@ export function getDefaultValue() { // initValue.fields = []; // for (let index = 0; index < 5; index++) { // initValue.fields.push({ - // id: `column-${index}`, + // _id: `column-${index}`, // name: "文本", // type: AITableFieldType.text, // }); @@ -171,10 +171,10 @@ export function getDefaultValue() { // for (let index = 0; index < 40 * 3 * 2*30; index++) { // const value: any = {}; // initValue.fields.forEach((column, columnIndex) => { - // value[`${column.id}`] = `text-${index}-${columnIndex}`; + // value[`${column._id}`] = `name-${index}-${columnIndex}`; // }); // initValue.records.push({ - // id: `row-${index + 1}`, + // _id: `row-${index + 1}`, // value: value, // }); // }