4040 :scrollLeft =" reactiveState.scrollLeft"
4141 >
4242 <view id =" table-body" class =" wd-table__content" :style =" realWidthStyle" >
43+ <wd-table-col
44+ v-if =" index !== false"
45+ :prop =" indexColumn.prop"
46+ :label =" indexColumn.label"
47+ :width =" indexColumn.width"
48+ :sortable =" indexColumn.sortable"
49+ :fixed =" indexColumn.fixed"
50+ :align =" indexColumn.align"
51+ >
52+ <template #value =" { index } " >
53+ <text >{{ index + 1 }}</text >
54+ </template >
55+ </wd-table-col >
4356 <slot ></slot >
4457 </view >
4558 </scroll-view >
@@ -58,10 +71,14 @@ export default {
5871 </script >
5972
6073<script lang="ts" setup>
61- import { type CSSProperties , computed , provide , watch , reactive } from ' vue'
62- import { addUnit , debounce , deepClone , isDef , objToStyle } from ' ../common/util'
63- import type { SortDirection , TableColumn } from ' ../wd-table-col/types'
74+ import { type CSSProperties , computed , provide , watch , reactive , ref } from ' vue'
75+ import { addUnit , debounce , deepClone , isDef , isObj , objToStyle , uuid } from ' ../common/util'
76+ import type { SortDirection , TableColumn , TableColumnProps } from ' ../wd-table-col/types'
6477import { tableProps } from ' ./types'
78+ import WdTableCol from ' ../wd-table-col/wd-table-col.vue'
79+ import { useTranslate } from ' ../composables/useTranslate'
80+
81+ const { translate } = useTranslate (' tableCol' )
6582
6683const props = defineProps (tableProps )
6784const emit = defineEmits ([' click' , ' sort-method' , ' row-click' ])
@@ -79,6 +96,17 @@ const reactiveState = reactive({
7996 setColumns
8097})
8198
99+ const indexUUID = uuid ()
100+ const indexColumn = ref <TableColumnProps >({
101+ prop: indexUUID ,
102+ label: translate (' indexLabel' ),
103+ width: ' 100rpx' ,
104+ sortable: false ,
105+ fixed: false ,
106+ align: ' left' ,
107+ ... (isObj (props .index ) ? props .index : {})
108+ })
109+
82110const scroll = debounce (handleScroll , 100 , { leading: false }) // 滚动事件
83111
84112provide (' wdTable' , reactiveState )
@@ -191,7 +219,11 @@ function isLastFixed(column: TableColumn) {
191219 * @param column 列
192220 */
193221function setColumns(column : TableColumn ) {
194- reactiveState .columns = deepClone ([... reactiveState .columns , column ])
222+ if (column .prop === indexUUID ) {
223+ reactiveState .columns = deepClone ([column , ... reactiveState .columns ])
224+ } else {
225+ reactiveState .columns = deepClone ([... reactiveState .columns , column ])
226+ }
195227}
196228
197229/**
0 commit comments