@ -9,8 +9,9 @@
: data = "pageData"
: data = "pageData"
: width = "width"
: width = "width"
: height = "resolvedHeight(height)"
: height = "resolvedHeight(height)"
: row - height = "rowHeight"
: row - height = "prop.rowHeight"
: header - height = "headerHeight"
: header - height = "rowHeight"
: estimated - row - height = "prop.estimatedRowHeight"
: border = "border"
: border = "border"
: row - key = "rowKey"
: row - key = "rowKey"
: class = "border ? 'has-border' : ''"
: class = "border ? 'has-border' : ''"
@ -36,12 +37,13 @@
< / div >
< / div >
< / template >
< / template >
< script lang = "ts" setup >
< script lang = "tsx " setup >
import { useStore } from "vuex" ;
import { useStore } from "vuex" ;
import { ref , computed , watch , h , onMounted , onUpdated , useSlots , renderSlot } from "vue" ;
import { ref , computed , watch , h , onMounted , onUpdated , useSlots , renderSlot } from "vue" ;
import { useI18n } from "vue3-i18n" ;
import { useI18n } from "vue3-i18n" ;
import { ElAutoResizer , ElTableV2 } from "element-plus" ;
import { ElAutoResizer , ElTableV2 } from "element-plus" ;
import * as lodash from "lodash-es" ;
import * as lodash from "lodash-es" ;
import TzDateTime from "../item/tzDateTime.vue" ;
const slots = useSlots ( ) ;
const slots = useSlots ( ) ;
@ -49,12 +51,39 @@ const { t } = useI18n();
const { state } = useStore ( ) ;
const { state } = useStore ( ) ;
const table = ref ( ) ;
const table = ref ( ) ;
/ / e l - t a b l e - v 2 u s e s f i x e d r o w h e i g h t s f o r v i r t u a l s c r o l l i n g b y d e f a u l t
type TimestampValue =
const ROW _HEIGHT = 50 ;
| undefined
const HEADER _HEIGHT = 50 ;
| boolean
| string
| {
valueFormat ? : string ;
valueTz ? : string ;
displayFormat ? : string ;
locale ? : string ;
type ? : "iso8601" | "unix" | "unixMillis" ;
} ;
interface TzDateTimeProps {
value : string | number ;
valueFormat ? : string ;
valueTz ? : string ;
displayFormat ? : string ;
locale ? : string ;
type ? : "iso8601" | "unix" | "unixMillis" ;
slot ? : boolean ;
}
interface TzDateTimeConfig {
valueFormat ? : string ;
valueTz ? : string ;
displayFormat ? : string ;
locale ? : string ;
type ? : "iso8601" | "unix" | "unixMillis" ;
}
interface TableColumn {
interface TableColumn {
code : string ;
key : string ;
dataKey ? : string ;
name ? : string ;
name ? : string ;
i18n ? : string ;
i18n ? : string ;
type ? : string ;
type ? : string ;
@ -64,7 +93,7 @@ interface TableColumn {
align ? : "left" | "center" | "right" ;
align ? : "left" | "center" | "right" ;
slot ? : boolean ;
slot ? : boolean ;
dict ? : string ;
dict ? : string ;
timestamp ? : boolean ;
timestamp ? : TimestampValue ;
filesize ? : boolean ;
filesize ? : boolean ;
[ others : string ] : any ;
[ others : string ] : any ;
@ -82,6 +111,9 @@ interface Props {
treeProps ? : any ;
treeProps ? : any ;
lazy ? : boolean ;
lazy ? : boolean ;
border ? : boolean ;
border ? : boolean ;
timestampFormat ? : string ;
rowHeight ? : number ;
estimatedRowHeight ? : number ;
}
}
const prop = withDefaults ( defineProps < Props > ( ) , {
const prop = withDefaults ( defineProps < Props > ( ) , {
@ -96,13 +128,13 @@ const prop = withDefaults(defineProps<Props>(), {
treeProps : undefined ,
treeProps : undefined ,
lazy : false ,
lazy : false ,
border : false ,
border : false ,
timestampFormat : "YYYY-MM-DD HH:mm:ss" ,
rowHeight : 30 ,
estimatedRowHeight : undefined ,
} ) ;
} ) ;
const emit = defineEmits ( [ "query" , "selection-change" , "row-click" , "cell-click" ] ) ;
const emit = defineEmits ( [ "query" , "selection-change" , "row-click" , "cell-click" ] ) ;
const rowHeight = ROW _HEIGHT ;
const headerHeight = HEADER _HEIGHT ;
const containerStyle = computed ( ( ) => {
const containerStyle = computed ( ( ) => {
const style : Record < string , string > = { } ;
const style : Record < string , string > = { } ;
if ( prop . height !== undefined ) {
if ( prop . height !== undefined ) {
@ -169,6 +201,26 @@ const formatFileSize = (value: any) => {
return g . toFixed ( 2 ) + "G" ;
return g . toFixed ( 2 ) + "G" ;
} ;
} ;
/ / H e l p e r t o r e s o l v e t i m e s t a m p c o l u m n c o n f i g t o T z D a t e T i m e p r o p s
const resolveTimestampProps = ( ts : TimestampValue ) : TzDateTimeConfig | null => {
if ( ! ts ) return null ;
if ( ts === true ) return { type : "unixMillis" , displayFormat : prop . timestampFormat } ;
if ( typeof ts === "string" ) {
/ / I f i t ' s ' u n i x ' , ' i s o 8 6 0 1 ' , o r ' u n i x M i l l i s ' t r e a t a s t y p e
if ( [ "unix" , "iso8601" , "unixMillis" ] . includes ( ts ) ) {
return { type : ts as TzDateTimeConfig [ "type" ] , displayFormat : prop . timestampFormat } ;
}
/ / O t h e r w i s e t r e a t a s v a l u e F o r m a t
return { valueFormat : ts , displayFormat : prop . timestampFormat } ;
}
/ / F o r o b j e c t c o n f i g , a p p l y d e f a u l t d i s p l a y F o r m a t i f n o t s p e c i f i e d
const config = ts as TzDateTimeConfig ;
if ( ! config . displayFormat ) {
config . displayFormat = prop . timestampFormat ;
}
return config ;
} ;
const formatterByDist = ( dictKey : string , value : any ) => {
const formatterByDist = ( dictKey : string , value : any ) => {
if ( ! dictKey ) {
if ( ! dictKey ) {
return getValue ( value ) ;
return getValue ( value ) ;
@ -184,7 +236,7 @@ const formatCellValue = (value: any, item: TableColumn, row: any) => {
if ( item . dict ) return formatterByDist ( item . dict , value ) ;
if ( item . dict ) return formatterByDist ( item . dict , value ) ;
if ( item . timestamp ) return formatStamp ( value ) ;
if ( item . timestamp ) return formatStamp ( value ) ;
if ( item . filesize ) return formatFileSize ( value ) ;
if ( item . filesize ) return formatFileSize ( value ) ;
if ( row . scheme ) return formatterByDist ( row . scheme + "_" + item . code , value ) ;
if ( row . scheme ) return formatterByDist ( row . scheme + "_" + ( item . dataKey || item . key ) , value ) ;
return getValue ( value ) ;
return getValue ( value ) ;
} ;
} ;
@ -198,7 +250,14 @@ const handleCurrentChange = (val: number) => {
emit ( "query" ) ;
emit ( "query" ) ;
} ;
} ;
const onScroll = ( { scrollTop } : { scrollTop : number ; scrollLeft ? : number ; horizontal ? : boolean ; vertical ? : boolean } ) => {
const onScroll = ( {
scrollTop ,
} : {
scrollTop : number ;
scrollLeft ? : number ;
horizontal ? : boolean ;
vertical ? : boolean ;
} ) => {
/ / C a n b e u s e d f o r l a z y l o a d i n g o r o t h e r s c r o l l - b a s e d f e a t u r e s
/ / C a n b e u s e d f o r l a z y l o a d i n g o r o t h e r s c r o l l - b a s e d f e a t u r e s
} ;
} ;
@ -214,9 +273,9 @@ const onCellClick = ({ row, column }: { row: any; column: any }) => {
const tableColumns = computed ( ( ) => {
const tableColumns = computed ( ( ) => {
return prop . columns . map ( ( item : TableColumn ) => {
return prop . columns . map ( ( item : TableColumn ) => {
const col : any = {
const col : any = {
key : item . code ,
key : item . key ,
title : item . name || ( item . i18n ? t ( item . i18n ) : item . code ) ,
title : item . name || ( item . i18n ? t ( item . i18n ) : item . key ) ,
dataKey : item . code ,
dataKey : item . dataKey || item . key ,
align : item . align || "center" ,
align : item . align || "center" ,
fixed : item . fixed ,
fixed : item . fixed ,
} ;
} ;
@ -234,25 +293,43 @@ const tableColumns = computed(() => {
col . minWidth = typeof item . minWidth === "number" ? item . minWidth : parseInt ( String ( item . minWidth ) ) || 120 ;
col . minWidth = typeof item . minWidth === "number" ? item . minWidth : parseInt ( String ( item . minWidth ) ) || 120 ;
}
}
/ / C e l l r e n d e r e r - e l - t a b l e - v 2 u s e s c e l l R e n d e r e r f u n c t i o n , c o n v e r t s p a r e n t s l o t s
/ / C e l l r e n d e r e r - e l - t a b l e - v 2 u s e s c e l l R e n d e r e r f u n c t i o n
col . cellRenderer = ( { cellData , rowData } : { cellData : any ; rowData : any } ) => {
col . cellRenderer = ( { cellData , rowData } : { cellData : any ; rowData : any } ) => {
const slotName = item . code ;
const slotName = item . key ;
/ / I f c o l u m n h a s s l o t = t r u e , r e n d e r t h e p a r e n t ' s s l o t c o n t e n t
/ / I f c o l u m n h a s s l o t = t r u e , r e n d e r t h e p a r e n t ' s s l o t c o n t e n t
if ( item . slot && slots [ slotName ] ) {
if ( item . slot && slots [ slotName ] ) {
return renderSlot ( slots , slotName , { row : rowData } ) ;
return renderSlot ( slots , slotName , { row : rowData } ) ;
}
}
const value = lodash . get ( rowData , item . code ) ;
const value = lodash . get ( rowData , item . dataKey || item . key ) ;
/ / H a n d l e t i m e s t a m p d i s p l a y u s i n g T z D a t e T i m e c o m p o n e n t
if ( item . timestamp ) {
const tzProps = resolveTimestampProps ( item . timestamp ) ;
if ( tzProps ) {
const { valueFormat , valueTz , displayFormat , locale , type } = tzProps ;
return (
< TzDateTime
value = { value }
valueFormat = { valueFormat }
valueTz = { valueTz }
displayFormat = { displayFormat }
locale = { locale }
type = { type }
/ >
) ;
}
}
/ / H a n d l e d i c t d i s p l a y
/ / H a n d l e d i c t d i s p l a y
if ( item . dict ) {
if ( item . dict ) {
return h ( "span" , { } , formatterByDist ( item . dict , value ) ) ;
return < span > { formatterByDist ( item . dict , value ) } < / span > ;
}
}
/ / H a n d l e f o r m a t t i n g
/ / H a n d l e f o r m a t t i n g
const formatted = formatCellValue ( value , item , rowData ) ;
const formatted = formatCellValue ( value , item , rowData ) ;
return h ( "span" , { } , formatted ) ;
return < span > { formatted } < / span > ;
} ;
} ;
return col ;
return col ;
@ -288,6 +365,9 @@ const tableColumns = computed(() => {
-- el - table - current - row - bg - color : v - bind ( "state.style.tableCurBg" ) ;
-- el - table - current - row - bg - color : v - bind ( "state.style.tableCurBg" ) ;
-- el - table - header - bg - color : v - bind ( "state.style.tableHeadBg" ) ;
-- el - table - header - bg - color : v - bind ( "state.style.tableHeadBg" ) ;
-- el - bg - color : v - bind ( "state.style.tableBg" ) ! important ;
-- el - bg - color : v - bind ( "state.style.tableBg" ) ! important ;
/ / B o r d e r - e l - t a b l e - v 2 u s e s - - e l - t a b l e - b o r d e r
-- el - table - border : 1 px solid var ( -- el - table - border - color ) ;
}
}
. my - table : deep ( . el - table - v2 _ _row ) {
. my - table : deep ( . el - table - v2 _ _row ) {
@ -298,8 +378,22 @@ const tableColumns = computed(() => {
background : v - bind ( "state.style.tableCurBg" ) ! important ;
background : v - bind ( "state.style.tableCurBg" ) ! important ;
}
}
. my - table : deep ( . el - table - v2 _ _cell ) {
. my - table : deep ( . el - table - v2 _ _header - cell ) {
padding : v - bind ( "state.size.tablePad" ) ;
padding : v - bind ( "state.size.tablePad" ) ;
border - right : var ( -- el - table - border ) ;
color : v - bind ( "state.style.tableColor" ) ;
}
. my - table : deep ( . el - table - v2 _ _row - cell ) {
padding : v - bind ( "state.size.tablePad" ) ;
border - right : var ( -- el - table - border ) ;
color : v - bind ( "state.style.tableColor" ) ;
}
/ / C h i l d r o w b a c k g r o u n d f o r t r e e d a t a
. my - table : deep ( . el - table - v2 _ _row [ data - level = "1" ] ) ,
. my - table : deep ( . el - table - v2 _ _row [ data - level = "3" ] ) {
background : v - bind ( "state.style.tableChildBg" ) ! important ;
}
}
. my - pagination {
. my - pagination {