gi-component 0.0.26 → 0.0.28
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/package.json +60 -60
- package/packages/components/edit-table/src/edit-table.vue +36 -30
- package/packages/components/form/src/form.vue +423 -426
- package/packages/components/form/src/type.ts +84 -84
- package/packages/hooks/index.ts +0 -1
- package/packages/index.ts +5 -5
- package/packages/styles/index.scss +6 -0
- package/packages/utils/createSelectDialog.ts +23 -16
- package/packages/hooks/useTable.ts +0 -100
|
@@ -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
|
+
}
|
package/packages/hooks/index.ts
CHANGED
package/packages/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { App } from 'vue'
|
|
1
|
+
import type { App, Component } from 'vue'
|
|
2
2
|
|
|
3
3
|
import Button from './components/button'
|
|
4
4
|
import Card from './components/card'
|
|
5
|
-
import
|
|
5
|
+
import DialogComponent from './components/dialog'
|
|
6
6
|
import Dot from './components/dot'
|
|
7
7
|
import Drawer from './components/drawer'
|
|
8
8
|
import EditTable from './components/edit-table'
|
|
@@ -38,11 +38,11 @@ const components = {
|
|
|
38
38
|
GridItem,
|
|
39
39
|
Form,
|
|
40
40
|
PageLayout,
|
|
41
|
-
Dialog,
|
|
41
|
+
Dialog: DialogComponent,
|
|
42
42
|
EditTable,
|
|
43
43
|
Table,
|
|
44
44
|
TreeTransfer
|
|
45
|
-
}
|
|
45
|
+
} as unknown as Record<string, Component>
|
|
46
46
|
|
|
47
47
|
// 导出Gi前缀的组件并添加明确类型注解
|
|
48
48
|
export const GiButton: typeof Button = Button
|
|
@@ -56,7 +56,7 @@ export const GiGrid: typeof Grid = Grid
|
|
|
56
56
|
export const GiGridItem: typeof GridItem = GridItem
|
|
57
57
|
export const GiForm: typeof Form = Form
|
|
58
58
|
export const GiPageLayout: typeof PageLayout = PageLayout
|
|
59
|
-
export const GiDialog: typeof
|
|
59
|
+
export const GiDialog: typeof DialogComponent = DialogComponent
|
|
60
60
|
export const GiEditTable: typeof EditTable = EditTable
|
|
61
61
|
export const GiTable: typeof Table = Table
|
|
62
62
|
export const GiTreeTransfer: typeof TreeTransfer = TreeTransfer
|
|
@@ -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
|
-
|
|
14
|
-
|
|
14
|
+
// 默认选项
|
|
15
|
+
interface DefaultOption {
|
|
16
|
+
queryParams?: Record<string, any>
|
|
17
|
+
componentProps?: Record<string, any>
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
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
|
-
...
|
|
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 () => {
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import type { Ref } from 'vue'
|
|
2
|
-
import { reactive, ref } from 'vue'
|
|
3
|
-
|
|
4
|
-
interface Options<T, U> {
|
|
5
|
-
onSuccess?: () => void
|
|
6
|
-
onError?: (error: Error) => void
|
|
7
|
-
immediate?: boolean
|
|
8
|
-
rowKey?: keyof T
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface ApiResult<T> {
|
|
12
|
-
code: number
|
|
13
|
-
data: T
|
|
14
|
-
message: string
|
|
15
|
-
success: boolean
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface PageResult<T> {
|
|
19
|
-
list: T[]
|
|
20
|
-
total: number
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface UseTablePaginationParams { page: number, size: number }
|
|
24
|
-
|
|
25
|
-
export interface UseTableApi<T> {
|
|
26
|
-
(params: UseTablePaginationParams): Promise<ApiResult<PageResult<T[]>>> | Promise<ApiResult<T[]>>
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function useTable<T extends U, U = T>(api: UseTableApi<T>, options: Options<T, U>) {
|
|
30
|
-
const { onSuccess, onError, immediate = true, rowKey = 'id' } = options || {}
|
|
31
|
-
|
|
32
|
-
// const instance = getCurrentInstance();
|
|
33
|
-
// const globalConfig = instance?.appContext.config.globalProperties?.$config || {};
|
|
34
|
-
|
|
35
|
-
const loading = ref(false)
|
|
36
|
-
const tableData: Ref<U[]> = ref([])
|
|
37
|
-
|
|
38
|
-
const pagination = reactive({
|
|
39
|
-
currentPage: 1,
|
|
40
|
-
pageSize: 20,
|
|
41
|
-
total: 0,
|
|
42
|
-
onCurrentChange: (size: number) => {
|
|
43
|
-
pagination.currentPage = size
|
|
44
|
-
getTableData()
|
|
45
|
-
},
|
|
46
|
-
onSizeChange: (size: number) => {
|
|
47
|
-
pagination.pageSize = size
|
|
48
|
-
getTableData()
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
function setTotal(total: number) {
|
|
53
|
-
pagination.total = total
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async function getTableData() {
|
|
57
|
-
try {
|
|
58
|
-
loading.value = true
|
|
59
|
-
const res = await api({ page: pagination.currentPage, size: pagination.pageSize })
|
|
60
|
-
// 处理返回的数据结构可能是分页或数组的情况
|
|
61
|
-
const data = !Array.isArray(res.data) ? res.data.list : res.data
|
|
62
|
-
tableData.value = data as T[]
|
|
63
|
-
// 设置总数据量
|
|
64
|
-
const total = !Array.isArray(res.data) ? res.data.total : data.length
|
|
65
|
-
setTotal(total)
|
|
66
|
-
onSuccess?.()
|
|
67
|
-
} catch (error) {
|
|
68
|
-
onError?.(error as Error)
|
|
69
|
-
} finally {
|
|
70
|
-
loading.value = false
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// 是否立即触发请求
|
|
75
|
-
immediate && getTableData()
|
|
76
|
-
|
|
77
|
-
function search() {
|
|
78
|
-
pagination.currentPage = 1
|
|
79
|
-
getTableData()
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function refresh() {
|
|
83
|
-
getTableData()
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
/** 表格数据 */
|
|
88
|
-
tableData,
|
|
89
|
-
/** 获取表格数据 */
|
|
90
|
-
getTableData,
|
|
91
|
-
/** 分页数据 */
|
|
92
|
-
pagination,
|
|
93
|
-
/** 加载状态 */
|
|
94
|
-
loading,
|
|
95
|
-
/** 搜索 */
|
|
96
|
-
search,
|
|
97
|
-
/** 刷新 */
|
|
98
|
-
refresh
|
|
99
|
-
}
|
|
100
|
-
}
|