gi-component 0.0.27 → 0.0.29
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import DialogComponent from './src/dialog.vue'
|
|
2
2
|
|
|
3
|
-
export type DialogInstance = InstanceType<typeof
|
|
3
|
+
export type DialogInstance = InstanceType<typeof DialogComponent>
|
|
4
4
|
export * from './src/dialog'
|
|
5
5
|
export * from './src/type'
|
|
6
|
-
export default
|
|
6
|
+
export default DialogComponent
|
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
|
|
@@ -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
|
-
}
|