-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
2,804 additions
and
0 deletions.
There are no files selected for viewing
461 changes: 461 additions & 0 deletions
461
dbm-ui/frontend/src/components/editable-table/Column.vue
Large diffs are not rendered by default.
Oops, something went wrong.
410 changes: 410 additions & 0 deletions
410
dbm-ui/frontend/src/components/editable-table/Index.vue
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<template> | ||
<tr ref="rowRootRef"> | ||
<slot /> | ||
</tr> | ||
</template> | ||
<script lang="ts"> | ||
import _ from 'lodash'; | ||
import { inject, type InjectionKey, onBeforeMount, onMounted, provide } from 'vue'; | ||
import type { IContext as IColumnContext } from './Column.vue'; | ||
import { tableInjectKey } from './Index.vue'; | ||
export const injectKey: InjectionKey<{ | ||
registerColumn: (column: IColumnContext) => void; | ||
unregisterColumn: (columnKey: string) => void; | ||
getColumnIndex: () => number; | ||
}> = Symbol.for('bk-editable-table-row'); | ||
</script> | ||
<script setup lang="ts"> | ||
const tableContext = inject(tableInjectKey); | ||
const rowRootRef = ref<HTMLElement>(); | ||
const columnList: IColumnContext[] = []; | ||
const registerColumn = (column: IColumnContext) => { | ||
const index = _.indexOf(rowRootRef.value!.children, column.el); | ||
if (index > -1) { | ||
columnList.splice(index, 0, column); | ||
} else { | ||
columnList.push(column); | ||
} | ||
tableContext?.updateRow(); | ||
}; | ||
const unregisterColumn = (columnKey: string) => { | ||
_.remove(columnList, (item) => item.key === columnKey); | ||
tableContext?.updateRow(); | ||
}; | ||
const getColumnIndex = (() => { | ||
let columnIndex = 0; | ||
return () => { | ||
columnIndex = columnIndex + 1; | ||
return columnIndex; | ||
}; | ||
})(); | ||
provide(injectKey, { | ||
registerColumn, | ||
unregisterColumn, | ||
getColumnIndex, | ||
}); | ||
onMounted(() => { | ||
tableContext?.registerRow(columnList); | ||
}); | ||
onBeforeMount(() => { | ||
tableContext?.unregisterRow(columnList); | ||
}); | ||
</script> |
26 changes: 26 additions & 0 deletions
26
dbm-ui/frontend/src/components/editable-table/component/RenderColGroup.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<template> | ||
<colgroup> | ||
<col | ||
v-for="item in columnList" | ||
:key="item.key" | ||
:width="columnSizeMap[item.key].renderWidth ? columnSizeMap[item.key].renderWidth : ''" /> | ||
</colgroup> | ||
</template> | ||
<script setup lang="ts"> | ||
import type { IContext as IColumnContext } from '../Column.vue'; | ||
interface Props { | ||
columnList: IColumnContext[]; | ||
columnSizeMap: Record< | ||
string, | ||
{ | ||
width?: number; | ||
minWidth?: number; | ||
maxWidth?: number; | ||
renderWidth: number; | ||
} | ||
>; | ||
} | ||
defineProps<Props>(); | ||
</script> |
28 changes: 28 additions & 0 deletions
28
dbm-ui/frontend/src/components/editable-table/component/render-body/Index.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<template> | ||
<tbody> | ||
<tr> | ||
<RenderCell | ||
v-for="(columnItem, index) in columnList" | ||
:key="`#${index}}#${columnItem.props.field}`" | ||
:column="columnItem" /> | ||
</tr> | ||
</tbody> | ||
</template> | ||
<script setup lang="ts"> | ||
import type { IContext as IColumnContext } from '../../Column.vue'; | ||
import RenderCell from './render-cell'; | ||
interface Props { | ||
columnList: IColumnContext[]; | ||
} | ||
defineProps<Props>(); | ||
</script> | ||
<style lang="less"> | ||
.bk-editable-table-cell { | ||
display: flex; | ||
min-height: 40px; | ||
align-items: center; | ||
} | ||
</style> |
29 changes: 29 additions & 0 deletions
29
dbm-ui/frontend/src/components/editable-table/component/render-body/render-cell.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { defineComponent, h } from 'vue'; | ||
|
||
import type { IContext as IColumnContext } from '../../Column.vue'; | ||
|
||
export default defineComponent({ | ||
name: 'RenderColumnCell', | ||
props: { | ||
column: { | ||
type: Object as () => IColumnContext, | ||
required: true, | ||
}, | ||
}, | ||
setup(props) { | ||
return () => | ||
h( | ||
'td', | ||
{ | ||
class: 'bk-editable-table-body-column', | ||
}, | ||
h( | ||
'div', | ||
{ | ||
class: 'bk-editable-table-cell', | ||
}, | ||
props.column.slots.default(), | ||
), | ||
); | ||
}, | ||
}); |
74 changes: 74 additions & 0 deletions
74
dbm-ui/frontend/src/components/editable-table/component/render-header/Index.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<template> | ||
<thead class="bk-editable-table-header"> | ||
<tr> | ||
<RenderTh | ||
v-for="(columnItem, index) in columnList" | ||
:key="`#${index}}#${columnItem.key}`" | ||
:class="{ | ||
[`is-column-fixed-${columnItem.props.fixed}`]: columnItem.props.fixed, | ||
}" | ||
:column="columnItem" | ||
:style="{ | ||
width: | ||
columnSizeConfig[columnItem.key].renderWidth > 0 ? `${columnSizeConfig[columnItem.key].renderWidth}px` : '', | ||
}" /> | ||
</tr> | ||
</thead> | ||
</template> | ||
<script setup lang="ts"> | ||
import type { IContext as IColumnContext } from '../../Column.vue'; | ||
import RenderTh from './render-th'; | ||
interface Props { | ||
columnList: IColumnContext[]; | ||
columnSizeConfig: Record<string, Record<'renderWidth', number>>; | ||
} | ||
defineProps<Props>(); | ||
</script> | ||
<style lang="less"> | ||
.bk-editable-table-header { | ||
th.is-required { | ||
.bk-editable-table-label-cell { | ||
&::after { | ||
margin-left: 4px; | ||
line-height: 20px; | ||
color: #ea3636; | ||
content: '*'; | ||
} | ||
} | ||
} | ||
} | ||
.bk-editable-table-label-cell { | ||
display: flex; | ||
min-height: 40px; | ||
align-items: center; | ||
font-weight: normal; | ||
color: #313238; | ||
} | ||
.bk-editable-table-th-prepend { | ||
margin-right: 4px; | ||
} | ||
.bk-editable-table-th-text { | ||
display: flex; | ||
height: 20px; | ||
overflow: hidden; | ||
line-height: 20px; | ||
text-overflow: ellipsis; | ||
word-break: keep-all; | ||
white-space: nowrap; | ||
} | ||
.bk-editable-table-th-text-description { | ||
cursor: pointer; | ||
border-bottom: 1px dashed #979ba5; | ||
} | ||
.bk-editable-table-th-append { | ||
margin-left: 4px; | ||
} | ||
</style> |
81 changes: 81 additions & 0 deletions
81
dbm-ui/frontend/src/components/editable-table/component/render-header/render-th.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { defineComponent, h, resolveDirective, withDirectives } from 'vue'; | ||
|
||
import type { IContext as IColumnContext } from '../../Column.vue'; | ||
|
||
export default defineComponent({ | ||
name: 'RenderColumnHead', | ||
props: { | ||
column: { | ||
type: Object as () => IColumnContext, | ||
required: true, | ||
}, | ||
}, | ||
setup(props) { | ||
return () => { | ||
const childNode = [ | ||
withDirectives( | ||
h( | ||
'div', | ||
{ | ||
class: { | ||
'bk-editable-table-th-text': true, | ||
'bk-editable-table-th-text-description': Boolean(props.column.props.description), | ||
}, | ||
}, | ||
props.column.slots.head ? props.column.slots.head() : props.column.props.label || '', | ||
), | ||
[ | ||
[ | ||
resolveDirective('bk-tooltips'), | ||
{ | ||
content: props.column.props.description || '', | ||
disabled: !props.column.props.description, | ||
}, | ||
], | ||
], | ||
), | ||
]; | ||
|
||
if (!props.column.slots.head && props.column.slots.headPrepend) { | ||
childNode.unshift( | ||
h( | ||
'div', | ||
{ | ||
class: 'bk-editable-table-th-prepend', | ||
}, | ||
props.column.slots.headPrepend(), | ||
), | ||
); | ||
} | ||
|
||
if (!props.column.slots.head && props.column.slots.headAppend) { | ||
childNode.push( | ||
h( | ||
'div', | ||
{ | ||
class: 'bk-editable-table-th-append', | ||
}, | ||
props.column.slots.headAppend(), | ||
), | ||
); | ||
} | ||
return h( | ||
'th', | ||
{ | ||
class: { | ||
'bk-editable-table-header-column': true, | ||
'is-required': props.column.props.required, | ||
}, | ||
'data-name': props.column.key, | ||
}, | ||
h( | ||
'div', | ||
{ | ||
class: 'bk-editable-table-label-cell', | ||
}, | ||
childNode, | ||
), | ||
); | ||
}; | ||
}, | ||
}); |
Oops, something went wrong.