|
@@ -1,30 +1,31 @@
|
|
|
<template>
|
|
<template>
|
|
|
<div class="app-table">
|
|
<div class="app-table">
|
|
|
- <table class="app-table__body">
|
|
|
|
|
|
|
+ <table class="app-table__body" cellspacing="0" cellpadding="0">
|
|
|
<thead>
|
|
<thead>
|
|
|
- <Draggable :list="columns" tag="tr" item-key="key">
|
|
|
|
|
|
|
+ <Draggable class="app-table__row" :list="columns" tag="tr" item-key="key">
|
|
|
<template #header v-if="$slots.expand">
|
|
<template #header v-if="$slots.expand">
|
|
|
- <th></th>
|
|
|
|
|
|
|
+ <th class="app-table__cell expand"></th>
|
|
|
</template>
|
|
</template>
|
|
|
<template #item="{ element }">
|
|
<template #item="{ element }">
|
|
|
- <th>{{ element.label }}</th>
|
|
|
|
|
|
|
+ <th class="app-table__cell">{{ element.label }}</th>
|
|
|
</template>
|
|
</template>
|
|
|
</Draggable>
|
|
</Draggable>
|
|
|
</thead>
|
|
</thead>
|
|
|
<tbody>
|
|
<tbody>
|
|
|
<template v-for="(row, i) in dataSource" :key="i">
|
|
<template v-for="(row, i) in dataSource" :key="i">
|
|
|
<tr class="app-table__row" @click="rowClick(i)">
|
|
<tr class="app-table__row" @click="rowClick(i)">
|
|
|
- <td v-if="$slots.expand">
|
|
|
|
|
|
|
+ <td class="app-table__cell expand" v-if="$slots.expand">
|
|
|
<Icon name="arrow-down" v-if="selectedIndex === i" />
|
|
<Icon name="arrow-down" v-if="selectedIndex === i" />
|
|
|
<Icon name="arrow" v-else />
|
|
<Icon name="arrow" v-else />
|
|
|
</td>
|
|
</td>
|
|
|
- <td :class="column.className" v-for="(column, n) in columns" :key="i + n.toString()">
|
|
|
|
|
|
|
+ <td class="app-table__cell" :class="column.className" v-for="(column, n) in columns"
|
|
|
|
|
+ :key="i + n.toString()">
|
|
|
<slot :name="column.key" :value="row[column.key]" :row="row">{{ row[column.key] }}</slot>
|
|
<slot :name="column.key" :value="row[column.key]" :row="row">{{ row[column.key] }}</slot>
|
|
|
</td>
|
|
</td>
|
|
|
</tr>
|
|
</tr>
|
|
|
<!-- expand -->
|
|
<!-- expand -->
|
|
|
<tr class="app-table__row expand" v-show="selectedIndex === i" v-if="$slots.expand">
|
|
<tr class="app-table__row expand" v-show="selectedIndex === i" v-if="$slots.expand">
|
|
|
- <td :colspan="columns.length + 1">
|
|
|
|
|
|
|
+ <td class="app-table__cell" :colspan="columns.length + 1">
|
|
|
<slot name="expand" :row="row"></slot>
|
|
<slot name="expand" :row="row"></slot>
|
|
|
</td>
|
|
</td>
|
|
|
</tr>
|
|
</tr>
|
|
@@ -40,7 +41,9 @@ import { Icon } from 'vant'
|
|
|
import { TableColumn } from './interface'
|
|
import { TableColumn } from './interface'
|
|
|
import Draggable from 'vuedraggable'
|
|
import Draggable from 'vuedraggable'
|
|
|
|
|
|
|
|
-defineProps({
|
|
|
|
|
|
|
+const emit = defineEmits(['rowClick'])
|
|
|
|
|
+
|
|
|
|
|
+const props = defineProps({
|
|
|
// 数据列表
|
|
// 数据列表
|
|
|
dataSource: {
|
|
dataSource: {
|
|
|
type: Array,
|
|
type: Array,
|
|
@@ -60,6 +63,7 @@ const rowClick = (index: number) => {
|
|
|
} else {
|
|
} else {
|
|
|
selectedIndex.value = index;
|
|
selectedIndex.value = index;
|
|
|
}
|
|
}
|
|
|
|
|
+ emit('rowClick', index, props.dataSource[index]);
|
|
|
}
|
|
}
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|