gi-component 0.0.7 → 0.0.8
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.
- package/dist/gi.css +1 -1
- package/dist/index.d.ts +4 -50
- package/dist/index.es.js +39 -39
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +10 -3
- package/packages/components/button/index.ts +4 -4
- package/packages/components/button/src/button.vue +32 -32
- package/packages/components/button/src/type.ts +2 -2
- package/packages/components/card/index.ts +4 -4
- package/packages/components/card/src/card.vue +21 -21
- package/packages/components/card/src/type.ts +9 -9
- package/packages/components/dialog/index.ts +5 -5
- package/packages/components/dialog/src/dialog.ts +33 -33
- package/packages/components/dialog/src/dialog.vue +34 -32
- package/packages/components/dialog/src/type.ts +13 -13
- package/packages/components/edit-table/index.ts +4 -4
- package/packages/components/edit-table/src/edit-table.vue +47 -47
- package/packages/components/edit-table/src/type.ts +42 -63
- package/packages/components/form/index.ts +4 -4
- package/packages/components/form/src/form.vue +98 -97
- package/packages/components/form/src/type.ts +67 -88
- package/packages/components/grid/index.ts +6 -6
- package/packages/components/grid/src/context.ts +17 -17
- package/packages/components/grid/src/grid-item.vue +40 -40
- package/packages/components/grid/src/grid.vue +38 -38
- package/packages/components/grid/src/hook/use-index.ts +24 -24
- package/packages/components/grid/src/hook/use-responsive-state.ts +26 -26
- package/packages/components/grid/src/hook/use-responsive-value.ts +24 -24
- package/packages/components/grid/src/interface.ts +32 -32
- package/packages/components/grid/src/utils/global-config.ts +3 -3
- package/packages/components/grid/src/utils/index.ts +25 -25
- package/packages/components/grid/src/utils/is.ts +2 -2
- package/packages/components/grid/src/utils/responsive-observe.ts +53 -53
- package/packages/components/input-group/index.ts +4 -4
- package/packages/components/input-group/src/input-group.vue +2 -2
- package/packages/components/input-search/index.ts +4 -4
- package/packages/components/input-search/src/input-search.vue +15 -15
- package/packages/components/input-search/src/type.ts +4 -4
- package/packages/components/page-layout/index.ts +4 -4
- package/packages/components/page-layout/src/page-layout.vue +25 -25
- package/packages/components/page-layout/src/split-button.vue +22 -22
- package/packages/components/page-layout/src/type.ts +9 -9
- package/packages/components/table/index.ts +4 -4
- package/packages/components/table/src/TableColumn.vue +10 -10
- package/packages/components/table/src/table.vue +14 -14
- package/packages/components/table/src/type.ts +7 -7
- package/packages/components/tabs/index.ts +4 -4
- package/packages/components/tabs/src/tabs.vue +20 -20
- package/packages/components/tabs/src/type.ts +9 -9
- package/packages/hooks/index.ts +2 -2
- package/packages/hooks/useBemClass.ts +7 -7
- package/packages/hooks/useTable.ts +6 -7
- package/packages/index.ts +44 -44
- package/packages/styles/index.scss +6 -0
- package/packages/types/tool.ts +4 -4
- package/packages/utils/createSelectDialog.ts +28 -27
- package/packages/utils/index.ts +1 -1
|
@@ -1,105 +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 { GridItemProps, GridProps } from '../../grid/src/interface';
|
|
5
|
-
import type { InputSearchInstance } from '../../input-search';
|
|
1
|
+
import type * as El from 'element-plus'
|
|
2
|
+
import type { FormProps as ElFormProps } from 'element-plus'
|
|
3
|
+
import type { VNode } from 'vue'
|
|
6
4
|
import type { MergeMultiple } from '../../../types/tool'
|
|
5
|
+
import type { GridItemProps, GridProps } from '../../grid/src/interface'
|
|
6
|
+
import type { InputSearchInstance } from '../../input-search'
|
|
7
7
|
|
|
8
|
-
export type FormColumnType
|
|
9
|
-
| 'input'
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
34
|
|
|
35
35
|
/**
|
|
36
36
|
* 表单列属性类型,根据组件类型使用对应的属性类型
|
|
37
37
|
*/
|
|
38
|
-
export type FormColumnProps = MergeMultiple<[El.InputProps,
|
|
39
|
-
El.InputNumberProps,
|
|
40
|
-
El.InputTagProps,
|
|
41
|
-
El.SelectProps,
|
|
42
|
-
El.SelectV2Props,
|
|
43
|
-
El.TreeInstance['$props'],
|
|
44
|
-
El.CascaderProps,
|
|
45
|
-
El.SliderProps,
|
|
46
|
-
El.SwitchProps,
|
|
47
|
-
El.RateProps,
|
|
48
|
-
El.CheckboxGroupProps,
|
|
49
|
-
El.CheckboxProps,
|
|
50
|
-
El.RadioGroupProps,
|
|
51
|
-
El.RadioProps,
|
|
52
|
-
El.DatePickerProps,
|
|
53
|
-
El.TimePickerDefaultProps,
|
|
54
|
-
El.TimeSelectProps,
|
|
55
|
-
El.ColorPickerProps,
|
|
56
|
-
El.TransferProps,
|
|
57
|
-
El.AutocompleteProps,
|
|
58
|
-
El.UploadProps,
|
|
59
|
-
InputSearchInstance['$props']]>;
|
|
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']]>
|
|
60
39
|
|
|
61
|
-
export type FormColumnItemHide<F> = boolean | ((form: F) => boolean)
|
|
40
|
+
export type FormColumnItemHide<F> = boolean | ((form: F) => boolean)
|
|
62
41
|
|
|
63
42
|
/**
|
|
64
43
|
* 表单列插槽类型,根据组件类型使用对应的插槽类型
|
|
65
44
|
*/
|
|
66
45
|
export type FormColumnSlots = Partial<
|
|
67
|
-
El.InputInstance['$slots']
|
|
68
|
-
El.InputNumberInstance['$slots']
|
|
69
|
-
El.InputTagInstance['$slots']
|
|
70
|
-
El.AutocompleteInstance['$slots']
|
|
71
|
-
El.CascaderInstance['$slots']
|
|
72
|
-
El.DatePickerInstance['$slots']
|
|
73
|
-
|
|
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
|
+
>
|
|
74
53
|
|
|
75
54
|
export interface FormColumnItem<F = any> {
|
|
76
|
-
type: FormColumnType
|
|
77
|
-
label?: string
|
|
78
|
-
labelRender?: () => VNode
|
|
79
|
-
field: string
|
|
80
|
-
fieldName?: string
|
|
81
|
-
span?: number
|
|
82
|
-
props?: FormColumnProps
|
|
83
|
-
formItemProps?: El.FormItemProps
|
|
84
|
-
gridItemProps?: any
|
|
85
|
-
required?: boolean
|
|
86
|
-
rules?: El.FormItemRule[]
|
|
87
|
-
hide?: FormColumnItemHide<F
|
|
88
|
-
tip?: string
|
|
89
|
-
dictCode?: string
|
|
90
|
-
slotName?: string
|
|
91
|
-
slots?: FormColumnSlots
|
|
92
|
-
extra?: string | (() => VNode)
|
|
55
|
+
type: FormColumnType
|
|
56
|
+
label?: string
|
|
57
|
+
labelRender?: () => VNode
|
|
58
|
+
field: string
|
|
59
|
+
fieldName?: string
|
|
60
|
+
span?: number
|
|
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) // 右侧额外内容
|
|
93
72
|
}
|
|
94
73
|
|
|
95
74
|
export interface FormProps extends Partial<ElFormProps> {
|
|
96
|
-
modelValue: any
|
|
97
|
-
columns?: FormColumnItem[]
|
|
98
|
-
fc?: Record<string, { disabled?: boolean
|
|
99
|
-
gridProps?: GridProps
|
|
100
|
-
gridItemProps?: GridItemProps
|
|
101
|
-
search?: boolean
|
|
102
|
-
searchText?: string
|
|
103
|
-
hideFoldBtn?: boolean
|
|
104
|
-
defaultCollapsed?: boolean | undefined
|
|
105
|
-
}
|
|
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,8 +1,8 @@
|
|
|
1
|
-
import GridItem from './src/grid-item.vue'
|
|
2
|
-
import Grid from './src/grid.vue'
|
|
1
|
+
import GridItem from './src/grid-item.vue'
|
|
2
|
+
import Grid from './src/grid.vue'
|
|
3
3
|
|
|
4
|
-
export type GridInstance = InstanceType<typeof Grid
|
|
5
|
-
export type GridItemInstance = InstanceType<typeof GridItem
|
|
6
|
-
export * from './src/interface'
|
|
4
|
+
export type GridInstance = InstanceType<typeof Grid>
|
|
5
|
+
export type GridItemInstance = InstanceType<typeof GridItem>
|
|
6
|
+
export * from './src/interface'
|
|
7
7
|
|
|
8
|
-
export { Grid, GridItem }
|
|
8
|
+
export { Grid, GridItem }
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import type { InjectionKey } from 'vue'
|
|
2
|
-
import type { GridItemData } from './interface'
|
|
1
|
+
import type { InjectionKey } from 'vue'
|
|
2
|
+
import type { GridItemData } from './interface'
|
|
3
3
|
|
|
4
4
|
export type RowContextContext = Readonly<{
|
|
5
|
-
gutter?: [number, number]
|
|
6
|
-
div?: boolean
|
|
7
|
-
}
|
|
5
|
+
gutter?: [number, number]
|
|
6
|
+
div?: boolean
|
|
7
|
+
}>
|
|
8
8
|
|
|
9
9
|
export const RowContextInjectionKey: InjectionKey<RowContextContext> = Symbol(
|
|
10
10
|
'RowContextInjectionKey'
|
|
11
|
-
)
|
|
11
|
+
)
|
|
12
12
|
|
|
13
13
|
export type GridContext = Readonly<{
|
|
14
|
-
overflow: boolean
|
|
15
|
-
displayIndexList: number[]
|
|
16
|
-
cols: number
|
|
17
|
-
colGap: number
|
|
18
|
-
}
|
|
14
|
+
overflow: boolean
|
|
15
|
+
displayIndexList: number[]
|
|
16
|
+
cols: number
|
|
17
|
+
colGap: number
|
|
18
|
+
}>
|
|
19
19
|
|
|
20
20
|
export const GridContextInjectionKey: InjectionKey<GridContext> = Symbol(
|
|
21
21
|
'GridContextInjectionKey'
|
|
22
|
-
)
|
|
22
|
+
)
|
|
23
23
|
|
|
24
24
|
export type GridDataCollector = Readonly<{
|
|
25
|
-
collectItemData: (index: number, itemData: GridItemData) => void
|
|
26
|
-
removeItemData: (index: number) => void
|
|
27
|
-
}
|
|
25
|
+
collectItemData: (index: number, itemData: GridItemData) => void
|
|
26
|
+
removeItemData: (index: number) => void
|
|
27
|
+
}>
|
|
28
28
|
|
|
29
|
-
export const GridDataCollectorInjectionKey: InjectionKey<GridDataCollector>
|
|
30
|
-
Symbol('GridDataCollectorInjectionKey')
|
|
29
|
+
export const GridDataCollectorInjectionKey: InjectionKey<GridDataCollector>
|
|
30
|
+
= Symbol('GridDataCollectorInjectionKey')
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script lang="ts">
|
|
8
|
-
import type { PropType } from 'vue'
|
|
9
|
-
import type { ResponsiveValue } from './interface'
|
|
8
|
+
import type { PropType } from 'vue'
|
|
9
|
+
import type { ResponsiveValue } from './interface'
|
|
10
10
|
import {
|
|
11
11
|
computed,
|
|
12
12
|
defineComponent,
|
|
@@ -15,15 +15,15 @@ import {
|
|
|
15
15
|
ref,
|
|
16
16
|
toRefs,
|
|
17
17
|
watchEffect
|
|
18
|
-
} from 'vue'
|
|
18
|
+
} from 'vue'
|
|
19
19
|
import {
|
|
20
20
|
GridContextInjectionKey,
|
|
21
21
|
GridDataCollectorInjectionKey
|
|
22
|
-
} from './context'
|
|
23
|
-
import { useIndex } from './hook/use-index'
|
|
24
|
-
import { useResponsiveState } from './hook/use-responsive-state'
|
|
25
|
-
import { resolveItemData } from './utils'
|
|
26
|
-
import { getPrefixCls } from './utils/global-config'
|
|
22
|
+
} from './context'
|
|
23
|
+
import { useIndex } from './hook/use-index'
|
|
24
|
+
import { useResponsiveState } from './hook/use-responsive-state'
|
|
25
|
+
import { resolveItemData } from './utils'
|
|
26
|
+
import { getPrefixCls } from './utils/global-config'
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* @version 2.15.0
|
|
@@ -59,55 +59,55 @@ export default defineComponent({
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
setup(props) {
|
|
62
|
-
const prefixCls = getPrefixCls('grid-item')
|
|
63
|
-
const domRef = ref<HTMLDivElement>()
|
|
62
|
+
const prefixCls = getPrefixCls('grid-item')
|
|
63
|
+
const domRef = ref<HTMLDivElement>()
|
|
64
64
|
const { computedIndex } = useIndex({
|
|
65
65
|
itemRef: domRef,
|
|
66
66
|
selector: `.${prefixCls}`
|
|
67
|
-
})
|
|
67
|
+
})
|
|
68
68
|
const gridContext = inject(GridContextInjectionKey, {
|
|
69
69
|
overflow: false,
|
|
70
70
|
displayIndexList: [],
|
|
71
71
|
cols: 24,
|
|
72
72
|
colGap: 0
|
|
73
|
-
})
|
|
74
|
-
const gridDataCollector = inject(GridDataCollectorInjectionKey)
|
|
73
|
+
})
|
|
74
|
+
const gridDataCollector = inject(GridDataCollectorInjectionKey)
|
|
75
75
|
const visible = computed(() =>
|
|
76
76
|
gridContext?.displayIndexList?.includes(computedIndex.value)
|
|
77
|
-
)
|
|
78
|
-
const { span: propSpan, offset: propOffset } = toRefs(props)
|
|
79
|
-
const rSpan = useResponsiveState(propSpan, 1)
|
|
80
|
-
const rOffset = useResponsiveState(propOffset, 0)
|
|
77
|
+
)
|
|
78
|
+
const { span: propSpan, offset: propOffset } = toRefs(props)
|
|
79
|
+
const rSpan = useResponsiveState(propSpan, 1)
|
|
80
|
+
const rOffset = useResponsiveState(propOffset, 0)
|
|
81
81
|
const itemData = computed(() =>
|
|
82
82
|
resolveItemData(gridContext.cols, {
|
|
83
83
|
...props,
|
|
84
84
|
span: rSpan.value,
|
|
85
85
|
offset: rOffset.value
|
|
86
86
|
})
|
|
87
|
-
)
|
|
87
|
+
)
|
|
88
88
|
|
|
89
|
-
const classNames = computed(() => [prefixCls])
|
|
89
|
+
const classNames = computed(() => [prefixCls])
|
|
90
90
|
const offsetStyle = computed(() => {
|
|
91
|
-
const { offset, span } = itemData.value
|
|
92
|
-
const { colGap } = gridContext
|
|
91
|
+
const { offset, span } = itemData.value
|
|
92
|
+
const { colGap } = gridContext
|
|
93
93
|
if (offset > 0) {
|
|
94
|
-
const oneSpan = `(100% - ${colGap * (span - 1)}px) / ${span}
|
|
94
|
+
const oneSpan = `(100% - ${colGap * (span - 1)}px) / ${span}`
|
|
95
95
|
return {
|
|
96
96
|
'margin-left': `calc((${oneSpan} * ${offset}) + ${colGap * offset}px)`
|
|
97
|
-
}
|
|
97
|
+
}
|
|
98
98
|
}
|
|
99
|
-
return {}
|
|
100
|
-
})
|
|
99
|
+
return {}
|
|
100
|
+
})
|
|
101
101
|
const columnStart = computed(() => {
|
|
102
|
-
const { suffix, span } = itemData.value
|
|
103
|
-
const { cols } = gridContext
|
|
102
|
+
const { suffix, span } = itemData.value
|
|
103
|
+
const { cols } = gridContext
|
|
104
104
|
if (suffix) {
|
|
105
|
-
return `${cols - span + 1}
|
|
105
|
+
return `${cols - span + 1}`
|
|
106
106
|
}
|
|
107
|
-
return `span ${span}
|
|
108
|
-
})
|
|
107
|
+
return `span ${span}`
|
|
108
|
+
})
|
|
109
109
|
const style = computed(() => {
|
|
110
|
-
const { span } = itemData.value
|
|
110
|
+
const { span } = itemData.value
|
|
111
111
|
if (domRef.value) {
|
|
112
112
|
return [
|
|
113
113
|
{
|
|
@@ -115,29 +115,29 @@ export default defineComponent({
|
|
|
115
115
|
},
|
|
116
116
|
offsetStyle.value,
|
|
117
117
|
!visible.value || span === 0 ? { display: 'none' } : {}
|
|
118
|
-
]
|
|
118
|
+
]
|
|
119
119
|
}
|
|
120
|
-
return []
|
|
121
|
-
})
|
|
120
|
+
return []
|
|
121
|
+
})
|
|
122
122
|
|
|
123
123
|
watchEffect(() => {
|
|
124
124
|
if (computedIndex.value !== -1) {
|
|
125
|
-
gridDataCollector?.collectItemData(computedIndex.value, itemData.value)
|
|
125
|
+
gridDataCollector?.collectItemData(computedIndex.value, itemData.value)
|
|
126
126
|
}
|
|
127
|
-
})
|
|
127
|
+
})
|
|
128
128
|
|
|
129
129
|
onUnmounted(() => {
|
|
130
130
|
if (computedIndex.value !== -1) {
|
|
131
|
-
gridDataCollector?.removeItemData(computedIndex.value)
|
|
131
|
+
gridDataCollector?.removeItemData(computedIndex.value)
|
|
132
132
|
}
|
|
133
|
-
})
|
|
133
|
+
})
|
|
134
134
|
|
|
135
135
|
return {
|
|
136
136
|
classNames,
|
|
137
137
|
style,
|
|
138
138
|
domRef,
|
|
139
139
|
overflow: computed(() => gridContext.overflow)
|
|
140
|
-
}
|
|
140
|
+
}
|
|
141
141
|
}
|
|
142
|
-
})
|
|
142
|
+
})
|
|
143
143
|
</script>
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
</template>
|
|
6
6
|
|
|
7
7
|
<script lang="ts">
|
|
8
|
-
import type { PropType } from 'vue'
|
|
9
|
-
import type { GridItemData, ResponsiveValue } from './interface'
|
|
8
|
+
import type { PropType } from 'vue'
|
|
9
|
+
import type { GridItemData, ResponsiveValue } from './interface'
|
|
10
10
|
import {
|
|
11
11
|
computed,
|
|
12
12
|
defineComponent,
|
|
@@ -14,14 +14,14 @@ import {
|
|
|
14
14
|
reactive,
|
|
15
15
|
toRefs,
|
|
16
16
|
watchEffect
|
|
17
|
-
} from 'vue'
|
|
17
|
+
} from 'vue'
|
|
18
18
|
import {
|
|
19
19
|
GridContextInjectionKey,
|
|
20
20
|
GridDataCollectorInjectionKey
|
|
21
|
-
} from './context'
|
|
22
|
-
import { useResponsiveState } from './hook/use-responsive-state'
|
|
23
|
-
import { setItemVisible } from './utils'
|
|
24
|
-
import { getPrefixCls } from './utils/global-config'
|
|
21
|
+
} from './context'
|
|
22
|
+
import { useResponsiveState } from './hook/use-responsive-state'
|
|
23
|
+
import { setItemVisible } from './utils'
|
|
24
|
+
import { getPrefixCls } from './utils/global-config'
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* @version 2.15.0
|
|
@@ -79,69 +79,69 @@ export default defineComponent({
|
|
|
79
79
|
colGap: propColGap,
|
|
80
80
|
collapsedRows,
|
|
81
81
|
collapsed
|
|
82
|
-
} = toRefs(props)
|
|
83
|
-
const cols = useResponsiveState(propCols, 24)
|
|
84
|
-
const colGap = useResponsiveState(propColGap, 0)
|
|
85
|
-
const rowGap = useResponsiveState(propRowGap, 0)
|
|
86
|
-
const prefixCls = getPrefixCls('grid')
|
|
87
|
-
const classNames = computed(() => [prefixCls])
|
|
82
|
+
} = toRefs(props)
|
|
83
|
+
const cols = useResponsiveState(propCols, 24)
|
|
84
|
+
const colGap = useResponsiveState(propColGap, 0)
|
|
85
|
+
const rowGap = useResponsiveState(propRowGap, 0)
|
|
86
|
+
const prefixCls = getPrefixCls('grid')
|
|
87
|
+
const classNames = computed(() => [prefixCls])
|
|
88
88
|
const style = computed(() => [
|
|
89
89
|
{
|
|
90
|
-
gap: `${rowGap.value}px ${colGap.value}px`,
|
|
90
|
+
'gap': `${rowGap.value}px ${colGap.value}px`,
|
|
91
91
|
'grid-template-columns': `repeat(${cols.value}, minmax(0px, 1fr))`
|
|
92
92
|
}
|
|
93
|
-
])
|
|
94
|
-
const itemDataMap = reactive<Map<number, GridItemData>>(new Map())
|
|
93
|
+
])
|
|
94
|
+
const itemDataMap = reactive<Map<number, GridItemData>>(new Map())
|
|
95
95
|
const itemDataList = computed(() => {
|
|
96
|
-
const list: GridItemData[] = []
|
|
96
|
+
const list: GridItemData[] = []
|
|
97
97
|
for (const [index, itemData] of itemDataMap.entries()) {
|
|
98
|
-
list[index] = itemData
|
|
98
|
+
list[index] = itemData
|
|
99
99
|
}
|
|
100
|
-
return list
|
|
101
|
-
})
|
|
100
|
+
return list
|
|
101
|
+
})
|
|
102
102
|
const gridContext = reactive<{
|
|
103
|
-
overflow: boolean
|
|
104
|
-
displayIndexList: number[]
|
|
105
|
-
cols: number
|
|
106
|
-
colGap: number
|
|
103
|
+
overflow: boolean
|
|
104
|
+
displayIndexList: number[]
|
|
105
|
+
cols: number
|
|
106
|
+
colGap: number
|
|
107
107
|
}>({
|
|
108
108
|
overflow: false,
|
|
109
109
|
displayIndexList: [],
|
|
110
110
|
cols: cols.value,
|
|
111
111
|
colGap: colGap.value
|
|
112
|
-
})
|
|
112
|
+
})
|
|
113
113
|
|
|
114
114
|
watchEffect(() => {
|
|
115
|
-
gridContext.cols = cols.value
|
|
116
|
-
gridContext.colGap = colGap.value
|
|
117
|
-
})
|
|
115
|
+
gridContext.cols = cols.value
|
|
116
|
+
gridContext.colGap = colGap.value
|
|
117
|
+
})
|
|
118
118
|
watchEffect(() => {
|
|
119
119
|
const displayInfo = setItemVisible({
|
|
120
120
|
cols: cols.value,
|
|
121
121
|
collapsed: collapsed.value,
|
|
122
122
|
collapsedRows: collapsedRows.value,
|
|
123
123
|
itemDataList: itemDataList.value
|
|
124
|
-
})
|
|
125
|
-
gridContext.overflow = displayInfo.overflow
|
|
126
|
-
gridContext.displayIndexList = displayInfo.displayIndexList
|
|
127
|
-
})
|
|
124
|
+
})
|
|
125
|
+
gridContext.overflow = displayInfo.overflow
|
|
126
|
+
gridContext.displayIndexList = displayInfo.displayIndexList
|
|
127
|
+
})
|
|
128
128
|
|
|
129
|
-
provide(GridContextInjectionKey, gridContext)
|
|
129
|
+
provide(GridContextInjectionKey, gridContext)
|
|
130
130
|
provide(GridDataCollectorInjectionKey, {
|
|
131
131
|
collectItemData(index, itemData) {
|
|
132
|
-
itemDataMap.set(index, itemData)
|
|
132
|
+
itemDataMap.set(index, itemData)
|
|
133
133
|
},
|
|
134
134
|
removeItemData(index) {
|
|
135
|
-
itemDataMap.delete(index)
|
|
135
|
+
itemDataMap.delete(index)
|
|
136
136
|
}
|
|
137
|
-
})
|
|
137
|
+
})
|
|
138
138
|
|
|
139
139
|
return {
|
|
140
140
|
classNames,
|
|
141
141
|
style
|
|
142
|
-
}
|
|
142
|
+
}
|
|
143
143
|
}
|
|
144
|
-
})
|
|
144
|
+
})
|
|
145
145
|
</script>
|
|
146
146
|
|
|
147
147
|
<style lang="scss" scoped>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Ref } from 'vue'
|
|
2
|
-
import { computed, onMounted, onUpdated, ref, watch } from 'vue'
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
import { computed, onMounted, onUpdated, ref, watch } from 'vue'
|
|
3
3
|
|
|
4
4
|
function isUndefined(obj: any): obj is undefined {
|
|
5
|
-
return obj === undefined
|
|
5
|
+
return obj === undefined
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export function useIndex({
|
|
@@ -11,53 +11,53 @@ export function useIndex({
|
|
|
11
11
|
index,
|
|
12
12
|
parentClassName
|
|
13
13
|
}: {
|
|
14
|
-
itemRef: Ref<HTMLElement | undefined
|
|
15
|
-
selector: string
|
|
16
|
-
index?: Ref<number | undefined
|
|
17
|
-
parentClassName?: string
|
|
14
|
+
itemRef: Ref<HTMLElement | undefined>
|
|
15
|
+
selector: string
|
|
16
|
+
index?: Ref<number | undefined>
|
|
17
|
+
parentClassName?: string
|
|
18
18
|
}) {
|
|
19
|
-
const _index = ref(-1)
|
|
20
|
-
const computedIndex = computed(() => index?.value ?? _index.value)
|
|
19
|
+
const _index = ref(-1)
|
|
20
|
+
const computedIndex = computed(() => index?.value ?? _index.value)
|
|
21
21
|
|
|
22
|
-
const parent = ref<HTMLElement>()
|
|
22
|
+
const parent = ref<HTMLElement>()
|
|
23
23
|
|
|
24
24
|
const getParent = () => {
|
|
25
|
-
let parent = itemRef.value?.parentElement ?? undefined
|
|
25
|
+
let parent = itemRef.value?.parentElement ?? undefined
|
|
26
26
|
if (parentClassName) {
|
|
27
27
|
while (parent && !parent.className.includes(parentClassName)) {
|
|
28
|
-
parent = parent.parentElement ?? undefined
|
|
28
|
+
parent = parent.parentElement ?? undefined
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
return parent
|
|
32
|
-
}
|
|
31
|
+
return parent
|
|
32
|
+
}
|
|
33
33
|
|
|
34
34
|
const getIndex = () => {
|
|
35
35
|
if (isUndefined(index?.value) && parent.value && itemRef.value) {
|
|
36
36
|
const index = Array.from(parent.value.querySelectorAll(selector)).indexOf(
|
|
37
37
|
itemRef.value
|
|
38
|
-
)
|
|
38
|
+
)
|
|
39
39
|
if (index !== _index.value) {
|
|
40
|
-
_index.value = index
|
|
40
|
+
_index.value = index
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|
|
44
44
|
|
|
45
45
|
watch(itemRef, () => {
|
|
46
46
|
if (itemRef.value && !parent.value) {
|
|
47
|
-
parent.value = getParent()
|
|
47
|
+
parent.value = getParent()
|
|
48
48
|
}
|
|
49
|
-
})
|
|
49
|
+
})
|
|
50
50
|
|
|
51
51
|
onMounted(() => {
|
|
52
52
|
if (itemRef.value) {
|
|
53
|
-
parent.value = getParent()
|
|
53
|
+
parent.value = getParent()
|
|
54
54
|
}
|
|
55
|
-
getIndex()
|
|
56
|
-
})
|
|
55
|
+
getIndex()
|
|
56
|
+
})
|
|
57
57
|
|
|
58
|
-
onUpdated(() => getIndex())
|
|
58
|
+
onUpdated(() => getIndex())
|
|
59
59
|
|
|
60
60
|
return {
|
|
61
61
|
computedIndex
|
|
62
|
-
}
|
|
62
|
+
}
|
|
63
63
|
}
|