gi-component 0.0.3 → 0.0.4

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,89 +1,89 @@
1
- <template>
2
- <div :class="b('table')">
3
- <el-table v-bind="tableProps" ref="tableRef" :data="props.data as any[]">
4
- <TableColumn v-for="item in props.columns" :key="item.prop || item.label" :column="item">
5
- <!-- 将所有插槽传递给子组件 -->
6
- <template v-for="(_, slotName) in $slots" :key="slotName" #[slotName]="scope">
7
- <slot :name="slotName" v-bind="scope" />
8
- </template>
9
- </TableColumn>
10
- </el-table>
11
-
12
- <el-row justify="end" :class="b('table-pagination')">
13
- <el-pagination v-bind="paginationProps" v-model:current-page="paginationProps.currentPage"
14
- v-model:page-size="paginationProps.pageSize" @size-change="handleSizeChange"
15
- @current-change="handleCurrentChange" />
16
- </el-row>
17
- </div>
18
- </template>
19
-
20
- <script lang="ts" setup>
21
- import type { TableProps } from './type';
22
- import { computed, useAttrs, useTemplateRef } from 'vue';
23
- import { useBemClass } from '../../../hooks';
24
- import TableColumn from './TableColumn.vue';
25
-
26
- const props = withDefaults(defineProps<TableProps>(), {
27
- columns: () => [],
28
- pagination: () => ({})
29
- });
30
-
31
- const attrs = useAttrs();
32
- const { b } = useBemClass();
33
- const tableRef = useTemplateRef('tableRef');
34
-
35
- const tableProps = computed(() => {
36
- return {
37
- ...attrs,
38
- ...props,
39
- columns: undefined,
40
- pagination: undefined
41
- };
42
- });
43
-
44
- const paginationProps = computed(() => {
45
- return {
46
- background: true,
47
- layout: 'prev, pager, next, sizes, total',
48
- pageSizes: [10, 20, 50, 100],
49
- ...props.pagination
50
- };
51
- });
52
-
53
- function handleSizeChange(size: number) {
54
- // @ts-ignore
55
- props.pagination.pageSize = size;
56
- }
57
-
58
- function handleCurrentChange(page: number) {
59
- // @ts-ignore
60
- props.pagination.currentPage = page;
61
- }
62
-
63
- defineExpose({
64
- tableRef
65
- })
66
- </script>
67
-
68
- <style lang="scss" scoped>
69
- @use '../../../styles/var.scss' as a;
70
-
71
- :deep(.el-pagination__rightwrapper) {
72
- flex: auto;
73
- }
74
-
75
- .#{a.$prefix}-table {
76
- height: 100%;
77
- overflow: hidden;
78
- display: flex;
79
- flex-direction: column;
80
-
81
- :deep(.el-table) {
82
- flex: 1;
83
- }
84
- }
85
-
86
- .#{a.$prefix}-table-pagination {
87
- margin-top: 10px;
88
- }
89
- </style>
1
+ <template>
2
+ <div :class="b('table')">
3
+ <el-table v-bind="tableProps" ref="tableRef" :data="props.data as any[]">
4
+ <TableColumn v-for="item in props.columns" :key="item.prop || item.label" :column="item">
5
+ <!-- 将所有插槽传递给子组件 -->
6
+ <template v-for="(_, slotName) in $slots" :key="slotName" #[slotName]="scope">
7
+ <slot :name="slotName" v-bind="scope" />
8
+ </template>
9
+ </TableColumn>
10
+ </el-table>
11
+
12
+ <el-row justify="end" :class="b('table-pagination')">
13
+ <el-pagination v-bind="paginationProps" v-model:current-page="paginationProps.currentPage"
14
+ v-model:page-size="paginationProps.pageSize" @size-change="handleSizeChange"
15
+ @current-change="handleCurrentChange" />
16
+ </el-row>
17
+ </div>
18
+ </template>
19
+
20
+ <script lang="ts" setup>
21
+ import type { TableProps } from './type';
22
+ import { computed, useAttrs, useTemplateRef } from 'vue';
23
+ import { useBemClass } from '../../../hooks';
24
+ import TableColumn from './TableColumn.vue';
25
+
26
+ const props = withDefaults(defineProps<TableProps>(), {
27
+ columns: () => [],
28
+ pagination: () => ({})
29
+ });
30
+
31
+ const attrs = useAttrs();
32
+ const { b } = useBemClass();
33
+ const tableRef = useTemplateRef('tableRef');
34
+
35
+ const tableProps = computed(() => {
36
+ return {
37
+ ...attrs,
38
+ ...props,
39
+ columns: undefined,
40
+ pagination: undefined
41
+ };
42
+ });
43
+
44
+ const paginationProps = computed(() => {
45
+ return {
46
+ background: true,
47
+ layout: 'prev, pager, next, sizes, total',
48
+ pageSizes: [10, 20, 50, 100],
49
+ ...props.pagination
50
+ };
51
+ });
52
+
53
+ function handleSizeChange(size: number) {
54
+ // @ts-ignore
55
+ props.pagination.pageSize = size;
56
+ }
57
+
58
+ function handleCurrentChange(page: number) {
59
+ // @ts-ignore
60
+ props.pagination.currentPage = page;
61
+ }
62
+
63
+ defineExpose({
64
+ tableRef
65
+ })
66
+ </script>
67
+
68
+ <style lang="scss" scoped>
69
+ @use '../../../styles/var.scss' as a;
70
+
71
+ :deep(.el-pagination__rightwrapper) {
72
+ flex: auto;
73
+ }
74
+
75
+ .#{a.$prefix}-table {
76
+ height: 100%;
77
+ overflow: hidden;
78
+ display: flex;
79
+ flex-direction: column;
80
+
81
+ :deep(.el-table) {
82
+ flex: 1;
83
+ }
84
+ }
85
+
86
+ .#{a.$prefix}-table-pagination {
87
+ margin-top: 10px;
88
+ }
89
+ </style>
@@ -1,22 +1,22 @@
1
- import type {
2
- TableProps as ElTableProps,
3
- PaginationProps,
4
- TableColumnCtx,
5
- TableColumnInstance
6
- } from 'element-plus';
7
- import type { ExtractPropTypes, VNode } from 'vue';
8
-
9
- export interface TableColumnItem
10
- extends Omit<TableColumnInstance['$props'], never> {
11
- slotName?: string;
12
- children?: TableColumnItem[];
13
- render?: (scope: TableColumnCtx<any>) => VNode | VNode[] | string;
14
- }
15
-
16
- export interface TableProps
17
- extends ExtractPropTypes<
18
- ElTableProps<Record<string | number | symbol, any>>
19
- > {
20
- columns?: TableColumnItem[];
21
- pagination?: Partial<PaginationProps>;
22
- }
1
+ import type {
2
+ TableProps as ElTableProps,
3
+ PaginationProps,
4
+ TableColumnCtx,
5
+ TableColumnInstance
6
+ } from 'element-plus';
7
+ import type { ExtractPropTypes, VNode } from 'vue';
8
+
9
+ export interface TableColumnItem
10
+ extends Omit<TableColumnInstance['$props'], never> {
11
+ slotName?: string;
12
+ children?: TableColumnItem[];
13
+ render?: (scope: TableColumnCtx<any>) => VNode | VNode[] | string;
14
+ }
15
+
16
+ export interface TableProps
17
+ extends ExtractPropTypes<
18
+ ElTableProps<Record<string | number | symbol, any>>
19
+ > {
20
+ columns?: TableColumnItem[];
21
+ pagination?: Partial<PaginationProps>;
22
+ }