Skip to content

Commit c795c00

Browse files
author
xuqingkai
committed
fix: 🐛 修复Table组件异步填充数据源无效的问题
Closes: #445
1 parent 723c51b commit c795c00

File tree

3 files changed

+13
-72
lines changed

3 files changed

+13
-72
lines changed

src/uni_modules/wot-design-uni/components/wd-table-col/wd-table-col.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default {
2727
}
2828
</script>
2929
<script lang="ts" setup>
30-
import { type CSSProperties, computed, ref } from 'vue'
30+
import { type CSSProperties, computed, ref, watch } from 'vue'
3131
import { addUnit, isDef, objToStyle, isOdd, isFunction } from '../common/util'
3232
import { tableColumnProps, type SortDirection } from './types'
3333
import { useParent } from '../composables/useParent'
@@ -42,7 +42,7 @@ const sortDirection = ref<SortDirection>(0) // 排序方向
4242
// 是否开启斑马纹
4343
const stripe = computed(() => {
4444
if (isDef(table)) {
45-
return table.stripe
45+
return table.props.stripe
4646
} else {
4747
return false
4848
}
@@ -53,7 +53,7 @@ const stripe = computed(() => {
5353
*/
5454
const border = computed(() => {
5555
if (isDef(table)) {
56-
return table.border
56+
return table.props.border
5757
} else {
5858
return false
5959
}
@@ -64,7 +64,7 @@ const border = computed(() => {
6464
*/
6565
const ellipsis = computed(() => {
6666
if (isDef(table)) {
67-
return table.ellipsis
67+
return table.props.ellipsis
6868
} else {
6969
return false
7070
}
@@ -100,7 +100,7 @@ const columnStyle = computed(() => {
100100
*/
101101
const cellStyle = computed(() => {
102102
let style: CSSProperties = {}
103-
const rowHeight: string | number = isDef(table) ? table.rowHeight : '80rpx' // 自定义行高
103+
const rowHeight: string | number = isDef(table) ? table.props.rowHeight : '80rpx' // 自定义行高
104104
if (isDef(rowHeight)) {
105105
style['height'] = addUnit(rowHeight)
106106
}
@@ -115,7 +115,8 @@ const column = computed(() => {
115115
if (!isDef(table)) {
116116
return []
117117
}
118-
const column: any[] = table.data.map((item) => {
118+
119+
const column: any[] = table.props.data.map((item) => {
119120
return item[props.prop]
120121
})
121122
return column
@@ -137,7 +138,7 @@ function getScope(index: number) {
137138
if (!isDef(table)) {
138139
return {}
139140
}
140-
return table.data[index] || {}
141+
return table.props.data[index] || {}
141142
}
142143
143144
defineExpose({ sortDirection: sortDirection })

src/uni_modules/wot-design-uni/components/wd-table/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @Author: weisheng
33
* @Date: 2024-03-15 11:36:12
4-
* @LastEditTime: 2024-06-06 19:11:32
4+
* @LastEditTime: 2024-07-18 19:02:32
55
* @LastEditors: weisheng
66
* @Description:
77
* @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\wd-table\types.ts
@@ -53,7 +53,8 @@ export const tableProps = {
5353

5454
export type TableProps = ExtractPropTypes<typeof tableProps>
5555

56-
export type TableProvide = Omit<TableProps, 'index' | 'customStyle' | 'customClass'> & {
56+
export type TableProvide = {
57+
props: Omit<TableProps, 'index' | 'customStyle' | 'customClass'>
5758
scrollLeft: number
5859
rowClick: (index: number) => void
5960
getIsLastFixed: (column: { fixed: boolean; prop: string }) => boolean

src/uni_modules/wot-design-uni/components/wd-table/wd-table.vue

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default {
7171
</script>
7272

7373
<script lang="ts" setup>
74-
import { type CSSProperties, computed, watch, reactive, ref } from 'vue'
74+
import { type CSSProperties, computed, reactive, ref } from 'vue'
7575
import { addUnit, debounce, isDef, isObj, objToStyle, uuid } from '../common/util'
7676
import type { SortDirection, TableColumn, TableColumnInstance, TableColumnProps } from '../wd-table-col/types'
7777
import { TABLE_KEY, tableProps, type TableProvide } from './types'
@@ -85,13 +85,7 @@ const props = defineProps(tableProps)
8585
const emit = defineEmits(['sort-method', 'row-click'])
8686
8787
const reactiveState = reactive<TableProvide>({
88-
data: props.data,
89-
stripe: props.stripe,
90-
border: props.border,
91-
height: props.height,
92-
rowHeight: props.rowHeight,
93-
showHeader: props.showHeader,
94-
ellipsis: props.ellipsis,
88+
props,
9589
scrollLeft: 0,
9690
rowClick,
9791
getIsLastFixed,
@@ -115,61 +109,6 @@ const indexColumn = ref<TableColumnProps>({
115109
116110
const scroll = debounce(handleScroll, 100, { leading: false }) // 滚动事件
117111
118-
watch(
119-
() => props.data,
120-
(newValue) => {
121-
reactiveState.data = newValue
122-
},
123-
{ deep: true }
124-
)
125-
126-
watch(
127-
() => props.stripe,
128-
(newValue) => {
129-
reactiveState.stripe = newValue
130-
},
131-
{ deep: true }
132-
)
133-
134-
watch(
135-
() => props.border,
136-
(newValue) => {
137-
reactiveState.border = newValue
138-
},
139-
{ deep: true }
140-
)
141-
142-
watch(
143-
() => props.height,
144-
(newValue) => {
145-
reactiveState.height = newValue
146-
},
147-
{ deep: true }
148-
)
149-
150-
watch(
151-
() => props.rowHeight,
152-
(newValue) => {
153-
reactiveState.rowHeight = newValue
154-
},
155-
{ deep: true }
156-
)
157-
watch(
158-
() => props.showHeader,
159-
(newValue) => {
160-
reactiveState.showHeader = newValue
161-
},
162-
{ deep: true }
163-
)
164-
165-
watch(
166-
() => props.ellipsis,
167-
(newValue) => {
168-
reactiveState.ellipsis = newValue
169-
},
170-
{ deep: true }
171-
)
172-
173112
/**
174113
* 容器样式
175114
*/

0 commit comments

Comments
 (0)