gi-component 0.0.25 → 0.0.27

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,84 +1,84 @@
1
- import type * as El from 'element-plus'
2
- import type { FormProps as ElFormProps } from 'element-plus'
3
- import type { VNode } from 'vue'
4
- import type { MergeMultiple } from '../../../types/tool'
5
- import type { GridItemProps, GridProps } from '../../grid/src/interface'
6
- import type { InputSearchInstance } from '../../input-search'
7
-
8
- export type FormColumnType
9
- = | 'input'
10
- | 'textarea'
11
- | 'input-number'
12
- | 'input-tag'
13
- | 'input-search'
14
- | 'select'
15
- | 'select-v2'
16
- | 'tree-select'
17
- | 'cascader'
18
- | 'slider'
19
- | 'switch'
20
- | 'rate'
21
- | 'checkbox-group'
22
- | 'checkbox'
23
- | 'radio-group'
24
- | 'radio'
25
- | 'date-picker'
26
- | 'time-picker'
27
- | 'time-select'
28
- | 'color-picker'
29
- | 'transfer'
30
- | 'autocomplete'
31
- | 'upload'
32
- | 'title'
33
- | 'slot'
34
-
35
- /**
36
- * 表单列属性类型,根据组件类型使用对应的属性类型
37
- */
38
- export type FormColumnProps = MergeMultiple<[El.InputProps, El.InputNumberProps, El.InputTagProps, El.SelectProps, El.SelectV2Props, El.TreeInstance['$props'], El.CascaderProps, El.SliderProps, El.SwitchProps, El.RateProps, El.CheckboxGroupProps, El.CheckboxProps, El.RadioGroupProps, El.RadioProps, El.DatePickerProps, El.TimePickerDefaultProps, El.TimeSelectProps, El.ColorPickerProps, El.TransferProps, El.AutocompleteProps, El.UploadProps, InputSearchInstance['$props']]>
39
-
40
- export type FormColumnItemHide<F> = boolean | ((form: F) => boolean)
41
-
42
- /**
43
- * 表单列插槽类型,根据组件类型使用对应的插槽类型
44
- */
45
- export type FormColumnSlots = Partial<
46
- El.InputInstance['$slots']
47
- | El.InputNumberInstance['$slots']
48
- | El.InputTagInstance['$slots']
49
- | El.AutocompleteInstance['$slots']
50
- | El.CascaderInstance['$slots']
51
- | El.DatePickerInstance['$slots']
52
- >
53
-
54
- export interface FormColumnItem<F = any> {
55
- type: FormColumnType
56
- label?: string
57
- labelRender?: () => VNode
58
- field: string
59
- fieldName?: string
60
- span?: number | GridItemProps['span']
61
- props?: FormColumnProps
62
- formItemProps?: El.FormItemProps
63
- gridItemProps?: any
64
- required?: boolean
65
- rules?: El.FormItemRule[]
66
- hide?: FormColumnItemHide<F> // 是否隐藏
67
- tip?: string
68
- dictCode?: string // 字典编码
69
- slotName?: string
70
- slots?: FormColumnSlots
71
- extra?: string | (() => VNode) // 右侧额外内容
72
- }
73
-
74
- export interface FormProps extends Partial<ElFormProps> {
75
- modelValue: any
76
- columns?: FormColumnItem[]
77
- fc?: Record<string, { disabled?: boolean, hidden?: boolean, required?: boolean }> // 表单控制
78
- gridProps?: GridProps // grid默认配置
79
- gridItemProps?: GridItemProps // grid-item默认配置
80
- search?: boolean
81
- searchText?: string
82
- hideFoldBtn?: boolean
83
- defaultCollapsed?: boolean | undefined
84
- }
1
+ import type * as El from 'element-plus'
2
+ import type { FormProps as ElFormProps } from 'element-plus'
3
+ import type { VNode } from 'vue'
4
+ import type { MergeMultiple } from '../../../types/tool'
5
+ import type { GridItemProps, GridProps } from '../../grid/src/interface'
6
+ import type { InputSearchInstance } from '../../input-search'
7
+
8
+ export type FormColumnType
9
+ = | 'input'
10
+ | 'textarea'
11
+ | 'input-number'
12
+ | 'input-tag'
13
+ | 'input-search'
14
+ | 'select'
15
+ | 'select-v2'
16
+ | 'tree-select'
17
+ | 'cascader'
18
+ | 'slider'
19
+ | 'switch'
20
+ | 'rate'
21
+ | 'checkbox-group'
22
+ | 'checkbox'
23
+ | 'radio-group'
24
+ | 'radio'
25
+ | 'date-picker'
26
+ | 'time-picker'
27
+ | 'time-select'
28
+ | 'color-picker'
29
+ | 'transfer'
30
+ | 'autocomplete'
31
+ | 'upload'
32
+ | 'title'
33
+ | 'slot'
34
+
35
+ /**
36
+ * 表单列属性类型,根据组件类型使用对应的属性类型
37
+ */
38
+ export type FormColumnProps = MergeMultiple<[El.InputProps, El.InputNumberProps, El.InputTagProps, El.SelectProps, El.SelectV2Props, El.TreeInstance['$props'], El.CascaderProps, El.SliderProps, El.SwitchProps, El.RateProps, El.CheckboxGroupProps, El.CheckboxProps, El.RadioGroupProps, El.RadioProps, El.DatePickerProps, El.TimePickerDefaultProps, El.TimeSelectProps, El.ColorPickerProps, El.TransferProps, El.AutocompleteProps, El.UploadProps, InputSearchInstance['$props']]>
39
+
40
+ export type FormColumnItemHide<F> = boolean | ((form: F) => boolean)
41
+
42
+ /**
43
+ * 表单列插槽类型,根据组件类型使用对应的插槽类型
44
+ */
45
+ export type FormColumnSlots = Partial<
46
+ El.InputInstance['$slots']
47
+ | El.InputNumberInstance['$slots']
48
+ | El.InputTagInstance['$slots']
49
+ | El.AutocompleteInstance['$slots']
50
+ | El.CascaderInstance['$slots']
51
+ | El.DatePickerInstance['$slots']
52
+ >
53
+
54
+ export interface FormColumnItem<F = any> {
55
+ type: FormColumnType
56
+ label?: string
57
+ labelRender?: () => VNode
58
+ field: string
59
+ fieldName?: string
60
+ span?: number | GridItemProps['span']
61
+ props?: FormColumnProps
62
+ formItemProps?: El.FormItemProps
63
+ gridItemProps?: any
64
+ required?: boolean
65
+ rules?: El.FormItemRule[]
66
+ hide?: FormColumnItemHide<F> // 是否隐藏
67
+ tip?: string
68
+ dictCode?: string // 字典编码
69
+ slotName?: string
70
+ slots?: FormColumnSlots
71
+ extra?: string | (() => VNode) // 右侧额外内容
72
+ }
73
+
74
+ export interface FormProps extends Partial<ElFormProps> {
75
+ modelValue: any
76
+ columns?: FormColumnItem[]
77
+ fc?: Record<string, { disabled?: boolean, hidden?: boolean, required?: boolean }> // 表单控制
78
+ gridProps?: GridProps // grid默认配置
79
+ gridItemProps?: GridItemProps // grid-item默认配置
80
+ search?: boolean
81
+ searchText?: string
82
+ hideFoldBtn?: boolean
83
+ defaultCollapsed?: boolean | undefined
84
+ }
@@ -16,21 +16,28 @@
16
16
  </div>
17
17
  </template>
18
18
 
19
- <script lang="ts" setup>
20
- import type { TableProps } from './type'
19
+ <script lang="ts" setup generic="T extends DefaultRow">
20
+ import type { DefaultRow, TableProps, TableSlotScope } from './type'
21
21
  import { ElPagination, ElRow, ElTable } from 'element-plus'
22
22
  import { computed, useAttrs, useTemplateRef } from 'vue'
23
23
  import { useBemClass } from '../../../hooks'
24
24
  import TableColumn from './TableColumn.vue'
25
25
 
26
- const props = withDefaults(defineProps<TableProps>(), {
26
+ const props = withDefaults(defineProps<TableProps<T>>(), {
27
27
  fit: true,
28
28
  showHeader: true,
29
29
  selectOnIndeterminate: true,
30
+ data: () => [],
30
31
  columns: () => [],
31
32
  pagination: () => ({})
32
33
  })
33
34
 
35
+ defineSlots<{
36
+ append: () => void
37
+ empty: () => void
38
+ [propsName: string]: (props: TableSlotScope<T>) => void
39
+ }>()
40
+
34
41
  const attrs = useAttrs()
35
42
  const { b } = useBemClass()
36
43
  const tableRef = useTemplateRef('tableRef')
@@ -1,14 +1,24 @@
1
1
  import type { TableProps as ElTableProps, PaginationProps, TableColumnInstance } from 'element-plus'
2
2
  import type { ExtractPropTypes, VNode } from 'vue'
3
3
 
4
- type DefaultRow = Record<PropertyKey, any>
5
- export interface TableColumnItem<T extends DefaultRow = DefaultRow> extends Omit<TableColumnInstance['$props'], never> {
4
+ export type DefaultRow = Record<PropertyKey, any>
5
+
6
+ export interface TableColumnItem<T extends DefaultRow = any> extends Omit<TableColumnInstance['$props'], never> {
6
7
  slotName?: string
7
8
  children?: TableColumnItem[]
8
- render?: (scope: { $index: number, cellIndex: number, column: TableColumnItem<T>, row: T }) => VNode | VNode[] | string
9
+ render?: (scope: TableSlotScope<T>) => VNode | VNode[] | string
10
+ }
11
+
12
+ export type TableSlotScope<T extends DefaultRow = any> = {
13
+ $index: number
14
+ cellIndex: number
15
+ column: TableColumnInstance['$props']
16
+ row: T
17
+ expanded: boolean
9
18
  }
10
19
 
11
- export interface TableProps extends ExtractPropTypes<ElTableProps<Record<string | number | symbol, any>>> {
20
+ export interface TableProps<T extends DefaultRow = any> extends ExtractPropTypes<ElTableProps<Record<string | number | symbol, any>>> {
21
+ data?: T[]
12
22
  columns?: TableColumnItem[]
13
23
  pagination?: Partial<PaginationProps> | boolean
14
24
  }
@@ -2,8 +2,10 @@
2
2
  @use './el.scss';
3
3
 
4
4
  body {
5
+ // 主要作用于页面
5
6
  --padding: 14px;
6
7
  --margin: 14px;
8
+ // 主要作用于内置组件(不建议使用)
7
9
  --padding-x: 14px;
8
10
  --padding-x-small: 10px;
9
11
  --padding-y: 12px;
@@ -144,4 +146,8 @@ body {
144
146
 
145
147
  .gi-flex-column {
146
148
  flex-direction: column;
149
+ }
150
+
151
+ .gi-tool {
152
+ gap: 8px;
147
153
  }
@@ -1,48 +1,55 @@
1
1
  import type { Component } from 'vue'
2
2
  import type { DialogOptions } from '../index'
3
3
  import { ElMessage } from 'element-plus'
4
- import { h, ref } from 'vue'
4
+ import { h, ref } from 'vue'
5
5
  import { Dialog } from '../index'
6
6
 
7
+ // 创建选择弹窗的参数
7
8
  interface CreateSelectDialogParams extends Omit<DialogOptions, 'content' | 'onOk' | 'onBeforeOk'> {
8
- component: Component
9
- componentProps?: Record<string, any>
10
- tip?: string
9
+ component: Component // 内容组件
10
+ componentProps?: Record<string, any> // 内容组件属性
11
+ tip?: string // 提示信息
11
12
  };
12
13
 
13
- interface DefOption {
14
- queryParams: Record<string, any>
14
+ // 默认选项
15
+ interface DefaultOption {
16
+ queryParams?: Record<string, any>
17
+ componentProps?: Record<string, any>
15
18
  }
16
19
 
17
- type DialogOption<T, Q extends DefOption = DefOption> = {
18
- title?: string
19
- multiple?: boolean
20
- queryParams?: Q['queryParams']
21
- onOk?: (data: T) => void
22
- onBeforeOk?: (data: T) => Promise<boolean>
20
+ // 打开选择弹窗的选项
21
+ type DialogOption<T, Q extends DefaultOption = DefaultOption> = {
22
+ title?: string // 标题
23
+ multiple?: boolean // 是否多选
24
+ queryParams?: (Q extends { queryParams: infer P } ? P : DefaultOption['queryParams']) // 查询参数
25
+ componentProps?: (Q extends { componentProps: infer P } ? P : DefaultOption['componentProps']) // 组件属性
26
+ onOk?: (data: T) => void // 确定回调
27
+ onBeforeOk?: (data: T) => Promise<boolean> // 确定前的回调
23
28
  }
24
29
 
25
30
  /**
26
31
  * 创建选择弹窗
27
32
  * @description component组件必须暴露一个getSelectedData方法
28
33
  */
29
- export const createSelectDialog = <T, Q extends DefOption = DefOption>(
34
+ export const createSelectDialog = <T, Q extends DefaultOption = DefaultOption>(
30
35
  params: CreateSelectDialogParams
31
36
  ) => {
32
37
  return function (options: DialogOption<T, Q>) {
33
- const { multiple = false, onOk, onBeforeOk, queryParams } = options
38
+ const { multiple = false, onOk, onBeforeOk, queryParams, componentProps } = options
34
39
  const DialogTableRef = ref<any>()
40
+ const { component, componentProps: componentPropsFromParams, tip, ...restParams } = params
35
41
 
36
42
  Dialog.open({
37
43
  bodyClass: 'gi-p0',
38
- ...{ ...params, component: undefined, componentProps: undefined, tip: undefined },
44
+ ...restParams,
39
45
  title: params.title || options.title,
40
46
  content: () =>
41
47
  h(params.component, {
42
48
  ref: (e: any) => (DialogTableRef.value = e),
43
49
  multiple,
44
50
  queryParams,
45
- ...params.componentProps
51
+ ...params.componentProps,
52
+ ...componentProps
46
53
  }),
47
54
  style: { maxWidth: '1000px', ...params.style },
48
55
  onBeforeOk: async () => {