gi-component 0.0.2 → 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,49 +1,49 @@
1
- <template>
2
- <el-table-column v-bind="columnProps">
3
- <!-- 处理render函数 -->
4
- <template v-if="column.render" v-slot="scope">
5
- <component :is="column.render(scope)" />
6
- </template>
7
-
8
- <!-- 处理插槽内容 -->
9
- <template v-else-if="column.slotName" #default="scope">
10
- <slot :name="column.slotName" v-bind="scope" />
11
- </template>
12
-
13
- <!-- 递归渲染子列 -->
14
- <template v-if="column.children && column.children.length > 0">
15
- <TableColumn
16
- v-for="child in column.children"
17
- :key="child.prop || child.label"
18
- :column="child"
19
- >
20
- <!-- 将所有插槽传递给子组件 -->
21
- <template
22
- v-for="(_, slotName) in $slots"
23
- :key="slotName"
24
- #[slotName]="scope"
25
- >
26
- <slot :name="slotName" v-bind="scope" />
27
- </template>
28
- </TableColumn>
29
- </template>
30
- </el-table-column>
31
- </template>
32
-
33
- <script lang="ts" setup>
34
- import type { TableColumnItem } from './type';
35
- import { computed } from 'vue';
36
- import TableColumn from './TableColumn.vue';
37
-
38
- const props = defineProps<{
39
- column: TableColumnItem;
40
- }>();
41
-
42
- // 计算el-table-column需要的属性
43
- const columnProps = computed(() => {
44
- const { slotName, render, children, ...restProps } = props.column;
45
- return restProps;
46
- });
47
- </script>
48
-
49
- <style scoped></style>
1
+ <template>
2
+ <el-table-column v-bind="columnProps">
3
+ <!-- 处理render函数 -->
4
+ <template v-if="column.render" v-slot="scope">
5
+ <component :is="column.render(scope)" />
6
+ </template>
7
+
8
+ <!-- 处理插槽内容 -->
9
+ <template v-else-if="column.slotName" #default="scope">
10
+ <slot :name="column.slotName" v-bind="scope" />
11
+ </template>
12
+
13
+ <!-- 递归渲染子列 -->
14
+ <template v-if="column.children && column.children.length > 0">
15
+ <TableColumn
16
+ v-for="child in column.children"
17
+ :key="child.prop || child.label"
18
+ :column="child"
19
+ >
20
+ <!-- 将所有插槽传递给子组件 -->
21
+ <template
22
+ v-for="(_, slotName) in $slots"
23
+ :key="slotName"
24
+ #[slotName]="scope"
25
+ >
26
+ <slot :name="slotName" v-bind="scope" />
27
+ </template>
28
+ </TableColumn>
29
+ </template>
30
+ </el-table-column>
31
+ </template>
32
+
33
+ <script lang="ts" setup>
34
+ import type { TableColumnItem } from './type';
35
+ import { computed } from 'vue';
36
+ import TableColumn from './TableColumn.vue';
37
+
38
+ const props = defineProps<{
39
+ column: TableColumnItem;
40
+ }>();
41
+
42
+ // 计算el-table-column需要的属性
43
+ const columnProps = computed(() => {
44
+ const { slotName, render, children, ...restProps } = props.column;
45
+ return restProps;
46
+ });
47
+ </script>
48
+
49
+ <style scoped></style>
@@ -1,85 +1,89 @@
1
- <template>
2
- <div>
3
- <el-table v-bind="tableProps" :data="props.data as any[]">
4
- <TableColumn
5
- v-for="item in props.columns"
6
- :key="item.prop || item.label"
7
- :column="item"
8
- >
9
- <!-- 将所有插槽传递给子组件 -->
10
- <template
11
- v-for="(_, slotName) in $slots"
12
- :key="slotName"
13
- #[slotName]="scope"
14
- >
15
- <slot :name="slotName" v-bind="scope" />
16
- </template>
17
- </TableColumn>
18
- </el-table>
19
-
20
- <el-row justify="end" :class="b('table-pagination')">
21
- <el-pagination
22
- v-bind="paginationProps"
23
- v-model:current-page="paginationProps.currentPage"
24
- v-model:page-size="paginationProps.pageSize"
25
- @size-change="handleSizeChange"
26
- @current-change="handleCurrentChange"
27
- />
28
- </el-row>
29
- </div>
30
- </template>
31
-
32
- <script lang="ts" setup>
33
- import type { TableProps } from './type';
34
- import { computed, useAttrs } from 'vue';
35
- import { useBemClass } from '../../../hooks';
36
- import TableColumn from './TableColumn.vue';
37
-
38
- const props = withDefaults(defineProps<TableProps>(), {
39
- columns: () => [],
40
- pagination: () => ({})
41
- });
42
-
43
- const attrs = useAttrs();
44
- const { b } = useBemClass();
45
-
46
- const tableProps = computed(() => {
47
- return {
48
- ...attrs,
49
- ...props,
50
- columns: undefined,
51
- pagination: undefined
52
- };
53
- });
54
-
55
- const paginationProps = computed(() => {
56
- return {
57
- background: true,
58
- layout: 'prev, pager, next, sizes, total',
59
- pageSizes: [10, 20, 50, 100],
60
- ...props.pagination
61
- };
62
- });
63
-
64
- function handleSizeChange(size: number) {
65
- // @ts-ignore
66
- props.pagination.pageSize = size;
67
- }
68
-
69
- function handleCurrentChange(page: number) {
70
- // @ts-ignore
71
- props.pagination.currentPage = page;
72
- }
73
- </script>
74
-
75
- <style lang="scss" scoped>
76
- @use '../../../styles/var.scss' as a;
77
-
78
- :deep(.el-pagination__rightwrapper) {
79
- flex: auto;
80
- }
81
-
82
- .#{a.$prefix}-table-pagination {
83
- margin-top: 10px;
84
- }
85
- </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
+ }
@@ -0,0 +1,3 @@
1
+ export function useTable() {
2
+
3
+ }
@@ -1,14 +1,12 @@
1
1
  import type { Component } from 'vue';
2
2
  import { ElMessage } from 'element-plus';
3
3
  import { h, ref } from 'vue';
4
- import { Dialog } from '../index';
4
+ import { Dialog, type DialogOptions } from '../index';
5
5
 
6
- type CreateSelectDialogParams = {
7
- title: string;
6
+ interface CreateSelectDialogParams extends Omit<DialogOptions, 'content' | 'onOk' | 'onBeforeOk'> {
8
7
  component: Component;
9
8
  componentProps?: Record<string, any>;
10
9
  tip?: string;
11
- bodyClass?: string;
12
10
  };
13
11
 
14
12
  interface DefOption {
@@ -35,6 +33,8 @@ export const createSelectDialog = <T, Q extends DefOption = DefOption>(
35
33
  const DialogTableRef = ref<any>();
36
34
 
37
35
  Dialog.open({
36
+ bodyClass: 'gi-p0',
37
+ ...{ ...params, component: undefined, componentProps: undefined, tip: undefined },
38
38
  title: params.title || options.title,
39
39
  content: () =>
40
40
  h(params.component, {
@@ -43,8 +43,7 @@ export const createSelectDialog = <T, Q extends DefOption = DefOption>(
43
43
  queryParams,
44
44
  ...params.componentProps
45
45
  }),
46
- style: { maxWidth: '960px' },
47
- bodyClass: params.bodyClass,
46
+ style: { maxWidth: '1000px', ...params.style },
48
47
  onBeforeOk: async () => {
49
48
  if (!DialogTableRef.value.getSelectedData) {
50
49
  ElMessage.error('组件必须暴露getSelectedData方法');