draw-table-vue 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,116 +0,0 @@
1
- <script setup lang="ts">
2
- import { ref } from 'vue';
3
- import { CanvasTable } from '../src/table';
4
- import type { ColumnConfig, TableRow, TableOptions } from '../src/table/types';
5
-
6
- const columns = ref<ColumnConfig[]>([
7
- { key: 'expand', title: '', type: 'expand', width: 40, align: 'center', fixed: 'left' },
8
- { key: 'selection', title: '', type: 'selection', width: 40, align: 'center', fixed: 'left' },
9
- {
10
- title: 'Group 1',
11
- fixed: 'left',
12
- children: [
13
- { key: 'id', title: 'ID', type: 'text', width: 60, align: 'center', fixed: 'left' },
14
- {
15
- key: 'name',
16
- title: 'Name',
17
- type: 'text',
18
- width: 150,
19
- fixed: 'left',
20
- renderHeader: (col, h) => h('div', { style: { color: 'red' } }, col.title),
21
- renderEdit: (data, h) => h('div', { style: { padding: '20px' } }, [
22
- h('h3', 'Edit Name'),
23
- h('input', {
24
- value: data.name,
25
- style: { width: '100%', padding: '8px', marginTop: '10px' },
26
- onInput: (e: any) => data.name = e.target.value
27
- })
28
- ])
29
- },
30
- ]
31
- },
32
- { key: 'avatar', title: 'Avatar', type: 'image', width: 80, align: 'center' },
33
- { key: 'age', title: 'Age', type: 'text', width: 80, align: 'center', summary: [
34
- (data) => {
35
- const total = data.reduce((acc, r) => acc + (Number(r.age) || 0), 0);
36
- return { label: '平均值', value: Math.round(total / data.length) };
37
- },
38
- (data) => {
39
- const maxAge = data.reduce((acc, r) => Math.max(acc, Number(r.age) || 0), 0);
40
- return { label: '最大值', value: maxAge };
41
- }
42
- ]},
43
- { key: 'status', title: 'Active', type: 'switch', width: 100, align: 'center', summary: [
44
- (data) => {
45
- const activeCount = data.filter(r => r.status).length;
46
- return { label: '平均值', value: `${activeCount} active` };
47
- }
48
- ]},
49
- { key: 'tags', title: 'Tags', type: 'tags', width: 200 },
50
- { key: 'color', title: 'Color', type: 'color-picker', width: 100, align: 'center' },
51
- { key: 'address', title: 'Address', type: 'text', width: 300 },
52
- { key: 'email', title: 'Email', type: 'text', width: 200 },
53
- ]);
54
-
55
- const generateData = (count: number): TableRow[] => {
56
- return Array.from({ length: count }, (_, i) => ({
57
- id: i + 1,
58
- name: `User ${i + 1}`,
59
- avatar: `https://api.dicebear.com/7.x/avataaars/svg?seed=${i}`,
60
- age: 20 + (i % 30),
61
- status: i % 2 === 0,
62
- tags: ['Vue', 'TS', 'Canvas'].slice(0, (i % 3) + 1),
63
- color: i % 2 === 0 ? '#409eff' : '#67c23a',
64
- address: `Street ${i + 1}, City ${i % 10}`,
65
- email: `user${i+1}@example.com`
66
- }));
67
- };
68
-
69
- const data = ref(generateData(1000));
70
-
71
- const options: Partial<TableOptions> = {
72
- border: true,
73
- stripe: true,
74
- multiSelect: true,
75
- renderExpand: (row, h) => h('div', { style: { padding: '20px', background: '#fafafa' } }, [
76
- h('h4', {}, `Details for ${row.name}`),
77
- h('p', {}, `This is an expanded row for user ${row.id}. You can put any component here.`),
78
- h('div', { style: { display: 'flex', gap: '10px' } }, [
79
- h('button', { onClick: () => alert('Action 1') }, 'Action 1'),
80
- h('button', { onClick: () => alert('Action 2') }, 'Action 2')
81
- ])
82
- ]),
83
- spanMethod: ({ rowIndex, columnIndex }) => {
84
- // Note: adjusted columnIndex based on new column order
85
- if (rowIndex === 2 && columnIndex === 7) {
86
- return { rowspan: 2, colspan: 2 };
87
- }
88
- if ((rowIndex === 2 || rowIndex === 3) && (columnIndex === 7 || columnIndex === 8)) {
89
- if (rowIndex === 2 && columnIndex === 7) return { rowspan: 2, colspan: 2 };
90
- return { rowspan: 0, colspan: 0 };
91
- }
92
- return undefined;
93
- }
94
- };
95
- </script>
96
-
97
- <template>
98
- <div class="example-container">
99
- <h2>Basic Usage</h2>
100
- <div class="table-wrapper">
101
- <CanvasTable :columns="columns" v-model:data="data" :options="options" />
102
- </div>
103
- </div>
104
- </template>
105
-
106
- <style scoped>
107
- .example-container {
108
- height: 100%;
109
- display: flex;
110
- flex-direction: column;
111
- }
112
- .table-wrapper {
113
- flex: 1;
114
- min-height: 0;
115
- }
116
- </style>