Skip to content

Commit 0f3ea69

Browse files
committed
Restructuring the project (ongoing).
1 parent 2da5b04 commit 0f3ea69

File tree

8 files changed

+75
-60
lines changed

8 files changed

+75
-60
lines changed

docs/TableDemo.vue

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<script setup lang="ts">
2-
import type { Ref } from 'vue';
3-
import { onMounted, ref, toRaw } from 'vue';
4-
import { IwEvents, IwProps } from '../src';
5-
import { IwUtils } from '../src/utils';
2+
import type { Ref } from 'vue'
3+
import { onMounted, ref, toRaw } from 'vue'
4+
import { IwEvents, IwProps } from '../src'
5+
import { IwUtils } from '../src/utils'
66
77
const selectedRecordPks: Ref<any[]> = ref([])
88
@@ -123,12 +123,12 @@ const events: IwProps.TableEventProps = {
123123
}
124124
if (sorts) {
125125
sorts.conds.forEach((sort) => {
126-
data = data.sort((a, b) => {
126+
data.sort((a, b) => {
127127
if (sort.orderDesc) {
128-
return a[sort.columnName] - b[sort.columnName]
128+
return typeof a[sort.columnName] === 'number' ? b[sort.columnName] - a[sort.columnName] : b[sort.columnName].localeCompare(a[sort.columnName])
129129
}
130130
else {
131-
return b[sort.columnName] - a[sort.columnName]
131+
return typeof a[sort.columnName] === 'number' ? a[sort.columnName] - b[sort.columnName] : a[sort.columnName].localeCompare(b[sort.columnName])
132132
}
133133
})
134134
})
@@ -140,7 +140,15 @@ const events: IwProps.TableEventProps = {
140140
}
141141
if (byGroupValue && group && group.item) {
142142
// 只获取当前分组的数据
143-
data = data.filter(d => d[group.item!.columnName] === byGroupValue)
143+
data = data.filter((d) => {
144+
// eslint-disable-next-line ts/no-use-before-define
145+
if (columns.find(col => col.name === group.item!.columnName)?.multiValue) {
146+
return d[group.item!.columnName].includes(byGroupValue)
147+
}
148+
else {
149+
return d[group.item!.columnName] === byGroupValue
150+
}
151+
})
144152
}
145153
if (group && group.item && !byGroupValue) {
146154
let dataGroup: { [key: string]: any[] } = IwUtils.groupBy(data, (d) => { return d[group.item!.columnName] })
@@ -433,7 +441,7 @@ const events: IwProps.TableEventProps = {
433441
},
434442
435443
loadCellDictItems: async (columnName: string, filterValue?: any, slice?: IwProps.DataQuerySliceReq): Promise<IwProps.DictItemsResp> => {
436-
if (columnName === 'name') {
444+
if (columnName === 'creator') {
437445
let nameDict: IwProps.DictItemProps[] = JSON.parse(JSON.stringify(NAME_DICT))
438446
if (filterValue) {
439447
nameDict = nameDict.filter((dict) => { return dict.title.includes(filterValue) || dict.value.includes(filterValue) })
@@ -496,7 +504,7 @@ const events: IwProps.TableEventProps = {
496504
}
497505
498506
const columns: IwProps.SimpleTableColumnProps[] = [
499-
{ name: 'no', title: 'ID', dataKind: IwProps.DataKind.NUMBER, sortable: true, width: 80, styles: { cursor: 'pointer' } },
507+
{ name: 'no', title: 'ID', dataKind: IwProps.DataKind.NUMBER, sortable: true, width: 80, styles: { cursor: 'pointer' }, filterable: true },
500508
{ name: 'pno', title: '父ID', dataKind: IwProps.DataKind.NUMBER, hide: true },
501509
{ name: 'name', title: '名称', sortable: true, width: 300, render: (record: { [key: string]: any }, layoutKind: IwProps.LayoutKind) => {
502510
if (layoutKind === IwProps.LayoutKind.LIST) {
@@ -505,36 +513,36 @@ const columns: IwProps.SimpleTableColumnProps[] = [
505513
else {
506514
return record.name
507515
}
508-
} },
509-
{ name: 'creator', title: '创建人', useDict: true, dictEditable: true, sortable: true, groupable: true },
510-
{ name: 'stats', title: '状态', useDict: true, dictEditable: true, multiValue: true, sortable: true, groupable: true },
511-
{ name: 'planStartTime', title: '计划开始时间', dataKind: IwProps.DataKind.DATETIME, sortable: true },
512-
{ name: 'planEndTime', title: '计划结束时间', dataKind: IwProps.DataKind.DATETIME, sortable: true },
516+
}, aggable: true, filterable: true },
517+
{ name: 'creator', title: '创建人', useDict: true, dictEditable: true, sortable: true, aggable: true, groupable: true, filterable: true },
518+
{ name: 'stats', title: '状态', useDict: true, dictEditable: true, multiValue: true, aggable: true, groupable: true, filterable: true },
519+
{ name: 'planStartTime', title: '计划开始时间', dataKind: IwProps.DataKind.DATETIME, aggable: true, sortable: true, filterable: true },
520+
{ name: 'planEndTime', title: '计划结束时间', dataKind: IwProps.DataKind.DATETIME, sortable: true, filterable: true },
513521
{ name: 'actualStartTime', title: '实际开始时间', dataKind: IwProps.DataKind.DATETIME, sortable: true },
514522
{ name: 'actualEndTime', title: '实际结束时间', dataKind: IwProps.DataKind.DATETIME, sortable: true },
515523
]
516524
517525
const layouts: IwProps.SimpleLayoutProps[] = [
518-
// {
519-
// id: 'hi1',
520-
// title: 'gantt demo',
521-
// layoutKind: IwProps.LayoutKind.GANTT,
522-
// columns: [{
523-
// name: 'name',
524-
// }, {
525-
// name: 'creator',
526-
// }, {
527-
// name: 'no',
528-
// }, {
529-
// name: 'planStartTime',
530-
// }, {
531-
// name: 'planEndTime',
532-
// }, {
533-
// name: 'actualStartTime',
534-
// }, {
535-
// name: 'actualEndTime',
536-
// }],
537-
// },
526+
{
527+
id: 'hi1',
528+
title: 'gantt demo',
529+
layoutKind: IwProps.LayoutKind.GANTT,
530+
columns: [{
531+
name: 'name',
532+
}, {
533+
name: 'creator',
534+
}, {
535+
name: 'no',
536+
}, {
537+
name: 'planStartTime',
538+
}, {
539+
name: 'planEndTime',
540+
}, {
541+
name: 'actualStartTime',
542+
}, {
543+
name: 'actualEndTime',
544+
}],
545+
},
538546
{
539547
id: 'hi2',
540548
title: 'list demo',
@@ -614,7 +622,10 @@ const _tableProps: IwProps.SimpleTableProps = {
614622
width: 100,
615623
},
616624
agg: {
617-
items: [],
625+
items: [
626+
{ columnName: 'name', aggKind: IwProps.AggregateKind.MIN },
627+
{ columnName: 'stats', aggKind: IwProps.AggregateKind.MIN },
628+
],
618629
},
619630
gantt: {
620631
timelineWidth: 500,

src/components/eventbus.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ export async function loadData(moreForGroupedValue?: any, returnOnlyAgg?: boolea
4444

4545
const resp = await events.loadData(
4646
tableConf.quickSearch?.searchContent,
47-
layout.filter,
48-
layout.sort,
49-
layout.group,
50-
layout.agg,
51-
layout.subDataShowKind === SubDataShowKind.ONLY_PARENT_DATA,
47+
rawLayout.filter,
48+
rawLayout.sort,
49+
rawLayout.group,
50+
rawLayout.agg,
51+
rawLayout.subDataShowKind === SubDataShowKind.ONLY_PARENT_DATA,
5252
moreForGroupedValue,
53-
moreForGroupedValue && layout.group && layout.group.slices && layout.group.slices[moreForGroupedValue as string]
53+
moreForGroupedValue && rawLayout.group && rawLayout.group.slices && rawLayout.group.slices[moreForGroupedValue as string]
5454
? {
55-
offsetNumber: layout.group.slices[moreForGroupedValue as string].offsetNumber,
56-
fetchNumber: layout.group.slices[moreForGroupedValue as string].fetchNumber,
55+
offsetNumber: rawLayout.group.slices[moreForGroupedValue as string].offsetNumber,
56+
fetchNumber: rawLayout.group.slices[moreForGroupedValue as string].fetchNumber,
5757
}
5858
: {
59-
offsetNumber: layout.slice.offsetNumber,
60-
fetchNumber: layout.slice.fetchNumber,
59+
offsetNumber: rawLayout.slice.offsetNumber,
60+
fetchNumber: rawLayout.slice.fetchNumber,
6161
},
6262
showColumns,
6363
returnOnlyAgg,
@@ -273,7 +273,6 @@ export async function setQuickSearchContent(quickSearchContent: string): Promise
273273
tableConf.quickSearch.searchContent = quickSearchContent
274274
}
275275
else {
276-
// TODO reactive
277276
tableConf.quickSearch = {
278277
placeholder: '',
279278
searchContent: quickSearchContent,

src/components/function/LayoutSetting.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ async function resetLayout() {
3131
slice: generateDataSliceProps(),
3232
subDataShowKind: SubDataShowKind.FOLD_SUB_DATA,
3333
}
34-
props.layoutConf.filter ?? (layout.filter = { groups: [] })
35-
props.layoutConf.group ?? (layout.group = {})
36-
props.layoutConf.sort ?? (layout.sort = { conds: [] })
37-
props.layoutConf.agg ?? (layout.agg = { items: [] })
34+
props.layoutConf.filter && (layout.filter = { groups: [] })
35+
props.layoutConf.group && (layout.group = {})
36+
props.layoutConf.sort && (layout.sort = { conds: [] })
37+
props.layoutConf.agg && (layout.agg = { items: [] })
3838
await eb.modifyLayout(layout)
3939
confirmResetLayoutCompRef.value?.close()
4040
}

src/components/function/Pagination.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async function setSlice(newPage?: number, newFetchNumber?: number) {
8383
fetchNumbers: props.slice.fetchNumbers,
8484
}
8585
}
86-
const groupSlices = toRaw(props.groupProps?.slices)
86+
const groupSlices = toRaw(props.groupProps?.slices) ?? {}
8787
groupSlices![props.groupValue!] = newSlice
8888
const changedLayoutReq: LayoutModifyProps = {
8989
group: {

src/components/function/RowSortSetting.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function addSortCond(columnName: string, orderDesc: boolean) {
8080
<div
8181
v-for="column in props.sort.conds"
8282
:key="`${props.layoutId}-${column.columnName}`"
83-
class="iw-row-sort__item p-1 flex w-full justify-between cursor-pointer"
83+
class="iw-row-sort__item p-1 flex w-full justify-between cursor-move"
8484
>
8585
<div>
8686
<i :class="`${iconSvg.GRABBER} cursor-pointer mr-0.5`" />

src/components/layout/gantt/GanttTimelineRows.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function getTimelineBarTitle(row: { [key: string]: any }, plan: boolean) {
146146
return `${plan ? t('gantt.planTimeTitle') : t('gantt.actualTimeTitle')}: ${startTime ?? ''} / ${endTime ?? ''} ${t('gantt.totalWeekDays', { days: weekdays })}`
147147
}
148148
else {
149-
return `${plan ? t('gantt.planTimeTitle') : t('gantt.actualTimeTitle')}: ${startTime ?? ''} / ${t('gantt.endTime')}: ${endTime ?? ''}`
149+
return `${plan ? t('gantt.planTimeTitle') : t('gantt.actualTimeTitle')}: ${startTime ?? ''} / ${endTime ?? ''}`
150150
}
151151
}
152152

src/components/layout/list/ListColumnAgg.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ function showAggsContextMenu(event: MouseEvent, colIdx: number) {
3737
3838
async function changeColumnAggs(aggKind: AggregateKind, columnName: string) {
3939
const agg = toRaw(props.agg)
40-
agg.items.forEach((item) => {
41-
if (item.columnName === columnName) {
42-
item.aggKind = aggKind
43-
}
44-
})
40+
const idx = agg.items.findIndex(item => item.columnName === columnName)
41+
if (idx === -1) {
42+
agg.items.push({ columnName, aggKind })
43+
}
44+
else {
45+
agg.items[idx].aggKind = aggKind
46+
}
4547
await eb.modifyLayout({
4648
agg,
4749
})

src/props/kernelProps.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ function generateCommonColumnProps(tableSimple: SimpleCommonColumnProps, layoutS
7878
width: layoutSimple?.width ?? tableSimple.width ?? 100,
7979
hide: layoutSimple?.hide ?? tableSimple.hide ?? false,
8080
styles: layoutSimple?.styles ?? tableSimple.styles ?? {},
81+
categoryTitle: layoutSimple?.categoryTitle ?? tableSimple.categoryTitle,
82+
render: layoutSimple?.render ?? tableSimple.render,
83+
8184
filterable: layoutSimple?.filterable ?? tableSimple.filterable ?? false,
8285
groupable: layoutSimple?.groupable ?? tableSimple.groupable ?? false,
8386
sortable: layoutSimple?.sortable ?? tableSimple.sortable ?? false,
@@ -166,7 +169,7 @@ export interface TableColumnProps extends CommonColumnProps {
166169
export type SimpleTableColumnProps = ChangeOptionalExcept<TableColumnProps, 'name'>
167170
function generateTableColumnProps(simple: SimpleTableColumnProps): TableColumnProps {
168171
return {
169-
title: simple.name,
172+
title: simple.title ?? simple.name,
170173
icon: getDefaultIconByDataKind(simple.dataKind ?? DataKind.TEXT),
171174
dataKind: simple.dataKind ?? DataKind.TEXT,
172175
useDict: simple.useDict ?? false,

0 commit comments

Comments
 (0)