@aspire-ui/element-component-pro 1.0.1 → 1.0.3
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/README.md +141 -7
- package/dist/ProForm/ApiSelect.vue.d.ts +67 -0
- package/dist/ProForm/ProForm.vue.d.ts +5 -1
- package/dist/ProForm/ProFormItem.vue.d.ts +4 -0
- package/dist/ProForm/TreeSelect.vue.d.ts +64 -0
- package/dist/ProTable/ProTable.vue.d.ts +421 -0
- package/dist/ProTable/TableAction.vue.d.ts +43 -0
- package/dist/ProTable/index.d.ts +8 -0
- package/dist/ProTable/types/index.d.ts +252 -0
- package/dist/ProTable/useProTable.d.ts +14 -0
- package/dist/element-component-pro.es.js +959 -302
- package/dist/element-component-pro.es.js.map +1 -1
- package/dist/element-component-pro.umd.js +2 -2
- package/dist/element-component-pro.umd.js.map +1 -1
- package/dist/index.d.ts +1369 -25
- package/dist/style.css +1 -1
- package/dist/types/index.d.ts +13 -51
- package/dist/useComponentSetting.d.ts +12 -0
- package/package.json +7 -5
- package/src/ProForm/ApiSelect.vue +85 -0
- package/src/ProForm/ProForm.vue +13 -3
- package/src/ProForm/ProFormItem.vue +53 -1
- package/src/ProForm/TreeSelect.vue +272 -0
- package/src/ProForm/useForm.ts +0 -1
- package/src/ProTable/ProTable.vue +773 -0
- package/src/ProTable/TableAction.vue +193 -0
- package/src/ProTable/index.ts +20 -0
- package/src/ProTable/types/index.ts +236 -0
- package/src/ProTable/useProTable.ts +79 -0
- package/src/index.ts +13 -10
- package/src/types/index.ts +26 -46
- package/src/useComponentSetting.ts +35 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="ecp-table-action">
|
|
3
|
+
<!-- 主操作按钮组 -->
|
|
4
|
+
<span
|
|
5
|
+
v-for="(action, index) in visibleActions"
|
|
6
|
+
:key="`action-${index}`"
|
|
7
|
+
class="ecp-table-action__item"
|
|
8
|
+
>
|
|
9
|
+
<!-- 气泡确认 -->
|
|
10
|
+
<el-popconfirm
|
|
11
|
+
v-if="action.popConfirm"
|
|
12
|
+
:title="action.popConfirm.title"
|
|
13
|
+
:confirm-button-text="action.popConfirm.okText || '确定'"
|
|
14
|
+
:cancel-button-text="action.popConfirm.cancelText || '取消'"
|
|
15
|
+
@confirm="(e) => handlePopConfirm(action, 'confirm', e)"
|
|
16
|
+
@cancel="(e) => handlePopConfirm(action, 'cancel', e)"
|
|
17
|
+
>
|
|
18
|
+
<span slot="reference">
|
|
19
|
+
<component
|
|
20
|
+
:is="action.tooltip ? 'el-tooltip' : 'span'"
|
|
21
|
+
v-bind="action.tooltip ? normalizeTooltip(action.tooltip) : {}"
|
|
22
|
+
>
|
|
23
|
+
<el-button
|
|
24
|
+
:type="getButtonType(action)"
|
|
25
|
+
size="small"
|
|
26
|
+
:disabled="action.disabled"
|
|
27
|
+
v-bind="action.props"
|
|
28
|
+
@click="(e) => handleClick(action, e)"
|
|
29
|
+
>
|
|
30
|
+
<i v-if="action.icon" :class="['ecp-table-action__icon', action.icon]" />
|
|
31
|
+
<span>{{ action.label }}</span>
|
|
32
|
+
</el-button>
|
|
33
|
+
</component>
|
|
34
|
+
</span>
|
|
35
|
+
</el-popconfirm>
|
|
36
|
+
|
|
37
|
+
<!-- 普通按钮 -->
|
|
38
|
+
<component
|
|
39
|
+
v-else
|
|
40
|
+
:is="action.tooltip ? 'el-tooltip' : 'span'"
|
|
41
|
+
v-bind="action.tooltip ? normalizeTooltip(action.tooltip) : {}"
|
|
42
|
+
>
|
|
43
|
+
<el-button
|
|
44
|
+
:type="getButtonType(action)"
|
|
45
|
+
size="small"
|
|
46
|
+
:disabled="action.disabled"
|
|
47
|
+
v-bind="action.props"
|
|
48
|
+
@click="(e) => handleClick(action, e)"
|
|
49
|
+
>
|
|
50
|
+
<i v-if="action.icon" :class="['ecp-table-action__icon', action.icon]" />
|
|
51
|
+
<span>{{ action.label }}</span>
|
|
52
|
+
</el-button>
|
|
53
|
+
</component>
|
|
54
|
+
|
|
55
|
+
<el-divider v-if="action.divider" direction="vertical" />
|
|
56
|
+
</span>
|
|
57
|
+
|
|
58
|
+
<!-- 下拉更多操作 -->
|
|
59
|
+
<el-dropdown v-if="visibleDropDownActions.length" trigger="click" @command="handleDropdownCommand">
|
|
60
|
+
<span class="ecp-table-action__more">
|
|
61
|
+
<el-button type="text" size="small">
|
|
62
|
+
更多<i class="el-icon-arrow-down el-icon--right" />
|
|
63
|
+
</el-button>
|
|
64
|
+
</span>
|
|
65
|
+
<el-dropdown-menu slot="dropdown">
|
|
66
|
+
<el-dropdown-item
|
|
67
|
+
v-for="(action, index) in visibleDropDownActions"
|
|
68
|
+
:key="`dropdown-${index}`"
|
|
69
|
+
:command="index"
|
|
70
|
+
:disabled="action.disabled"
|
|
71
|
+
:divided="!!action.divider"
|
|
72
|
+
>
|
|
73
|
+
<span class="ecp-table-action__dropdown-item">
|
|
74
|
+
<i v-if="action.icon" :class="['ecp-table-action__icon', action.icon]" />
|
|
75
|
+
<span>{{ action.label }}</span>
|
|
76
|
+
</span>
|
|
77
|
+
</el-dropdown-item>
|
|
78
|
+
</el-dropdown-menu>
|
|
79
|
+
</el-dropdown>
|
|
80
|
+
</div>
|
|
81
|
+
</template>
|
|
82
|
+
|
|
83
|
+
<script setup lang="ts">
|
|
84
|
+
import { computed } from 'vue'
|
|
85
|
+
import { MessageBox } from 'element-ui'
|
|
86
|
+
import type { TableActionItem } from './types'
|
|
87
|
+
|
|
88
|
+
const props = withDefaults(
|
|
89
|
+
defineProps<{
|
|
90
|
+
actions?: TableActionItem[]
|
|
91
|
+
dropDownActions?: TableActionItem[]
|
|
92
|
+
/** 是否阻止按钮 click 冒泡,参考 VbenAdmin stopButtonPropagation */
|
|
93
|
+
stopButtonPropagation?: boolean
|
|
94
|
+
}>(),
|
|
95
|
+
{
|
|
96
|
+
actions: () => [],
|
|
97
|
+
dropDownActions: () => [],
|
|
98
|
+
stopButtonPropagation: false,
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
const normalizeTooltip = (tooltip?: TableActionItem['tooltip']) => {
|
|
103
|
+
if (!tooltip) return {}
|
|
104
|
+
if (typeof tooltip === 'string') {
|
|
105
|
+
return { content: tooltip }
|
|
106
|
+
}
|
|
107
|
+
return tooltip as Record<string, unknown>
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const getButtonType = (action: TableActionItem) => {
|
|
111
|
+
if (action.type) return action.type
|
|
112
|
+
if (action.color === 'error') return 'danger'
|
|
113
|
+
if (action.color === 'success') return 'success'
|
|
114
|
+
if (action.color === 'warning') return 'warning'
|
|
115
|
+
return 'text'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const filterVisible = (list: TableActionItem[]) =>
|
|
119
|
+
list.filter((item) => {
|
|
120
|
+
const { ifShow } = item
|
|
121
|
+
if (typeof ifShow === 'boolean') return ifShow
|
|
122
|
+
if (typeof ifShow === 'function') return ifShow(item)
|
|
123
|
+
return true
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
const visibleActions = computed(() => filterVisible(props.actions || []))
|
|
127
|
+
const visibleDropDownActions = computed(() => filterVisible(props.dropDownActions || []))
|
|
128
|
+
|
|
129
|
+
const handleClick = (action: TableActionItem, e: MouseEvent) => {
|
|
130
|
+
if (props.stopButtonPropagation) {
|
|
131
|
+
e.stopPropagation()
|
|
132
|
+
}
|
|
133
|
+
action.onClick?.(e)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const handlePopConfirm = (action: TableActionItem, type: 'confirm' | 'cancel', e: MouseEvent) => {
|
|
137
|
+
if (props.stopButtonPropagation) {
|
|
138
|
+
e.stopPropagation()
|
|
139
|
+
}
|
|
140
|
+
if (!action.popConfirm) return
|
|
141
|
+
if (type === 'confirm') {
|
|
142
|
+
action.popConfirm.confirm?.()
|
|
143
|
+
} else {
|
|
144
|
+
action.popConfirm.cancel?.()
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const handleDropdownCommand = (index: number | string) => {
|
|
149
|
+
const idx = Number(index)
|
|
150
|
+
const action = visibleDropDownActions.value[idx]
|
|
151
|
+
if (!action || action.disabled) return
|
|
152
|
+
if (action.popConfirm) {
|
|
153
|
+
const title = action.popConfirm.title
|
|
154
|
+
const okText = action.popConfirm.okText || '确定'
|
|
155
|
+
const cancelText = action.popConfirm.cancelText || '取消'
|
|
156
|
+
MessageBox.confirm(title, '提示', {
|
|
157
|
+
confirmButtonText: okText,
|
|
158
|
+
cancelButtonText: cancelText,
|
|
159
|
+
type: 'warning',
|
|
160
|
+
})
|
|
161
|
+
.then(() => action.popConfirm?.confirm?.())
|
|
162
|
+
.catch(() => action.popConfirm?.cancel?.())
|
|
163
|
+
return
|
|
164
|
+
}
|
|
165
|
+
action.onClick?.({} as MouseEvent)
|
|
166
|
+
}
|
|
167
|
+
</script>
|
|
168
|
+
|
|
169
|
+
<style scoped>
|
|
170
|
+
.ecp-table-action {
|
|
171
|
+
display: inline-flex;
|
|
172
|
+
align-items: center;
|
|
173
|
+
gap: 4px;
|
|
174
|
+
}
|
|
175
|
+
.ecp-table-action__item {
|
|
176
|
+
display: inline-flex;
|
|
177
|
+
align-items: center;
|
|
178
|
+
gap: 4px;
|
|
179
|
+
}
|
|
180
|
+
.ecp-table-action__icon {
|
|
181
|
+
margin-right: 4px;
|
|
182
|
+
}
|
|
183
|
+
.ecp-table-action__more {
|
|
184
|
+
display: inline-flex;
|
|
185
|
+
align-items: center;
|
|
186
|
+
}
|
|
187
|
+
.ecp-table-action__dropdown-item {
|
|
188
|
+
display: inline-flex;
|
|
189
|
+
align-items: center;
|
|
190
|
+
gap: 4px;
|
|
191
|
+
}
|
|
192
|
+
</style>
|
|
193
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import ProTable from './ProTable.vue'
|
|
2
|
+
import TableAction from './TableAction.vue'
|
|
3
|
+
import { useProTable } from './useProTable'
|
|
4
|
+
|
|
5
|
+
export { ProTable, useProTable, TableAction }
|
|
6
|
+
export type { UseProTableReturn, UseProTablePropsReactive } from './useProTable'
|
|
7
|
+
export type {
|
|
8
|
+
ProColumn,
|
|
9
|
+
ProTableProps,
|
|
10
|
+
TableActionType,
|
|
11
|
+
FetchSetting,
|
|
12
|
+
FetchParams,
|
|
13
|
+
ProTableToolBarConfig,
|
|
14
|
+
SpanMethodParams,
|
|
15
|
+
SpanMethodResult,
|
|
16
|
+
TreeProps,
|
|
17
|
+
TableActionItem,
|
|
18
|
+
TableActionProps,
|
|
19
|
+
} from './types'
|
|
20
|
+
export default ProTable
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import type { VNode } from 'vue'
|
|
2
|
+
|
|
3
|
+
/** ProTable 列配置 */
|
|
4
|
+
export interface ProColumn {
|
|
5
|
+
/** 列唯一标识 */
|
|
6
|
+
key?: string
|
|
7
|
+
/** 列标题 */
|
|
8
|
+
title: string
|
|
9
|
+
/** 数据字段名 */
|
|
10
|
+
dataIndex: string
|
|
11
|
+
/** 列宽度:number 为比例(如 1、2、3 表示 1:2:3),string 为 px */
|
|
12
|
+
width?: number | string
|
|
13
|
+
/** 最小宽度(参考 VbenAdmin,比例列和固定列均生效) */
|
|
14
|
+
minWidth?: number | string
|
|
15
|
+
/** 最大宽度(参考 VbenAdmin,用于限制列宽上限) */
|
|
16
|
+
maxWidth?: number | string
|
|
17
|
+
/** 固定列 */
|
|
18
|
+
fixed?: 'left' | 'right'
|
|
19
|
+
/** 是否可排序 */
|
|
20
|
+
sortable?: boolean
|
|
21
|
+
/** 对齐方式 */
|
|
22
|
+
align?: 'left' | 'center' | 'right'
|
|
23
|
+
/** 是否可调整宽度 */
|
|
24
|
+
resizable?: boolean
|
|
25
|
+
/** 内容超出时是否省略并显示 tooltip,默认继承表格 ellipsis */
|
|
26
|
+
ellipsis?: boolean
|
|
27
|
+
/** 是否隐藏 */
|
|
28
|
+
hideInTable?: boolean
|
|
29
|
+
/** 默认隐藏,可在列设置中显示(参考 VbenAdmin defaultHidden) */
|
|
30
|
+
defaultHidden?: boolean
|
|
31
|
+
/** 列头右侧帮助文本(参考 VbenAdmin helpMessage) */
|
|
32
|
+
helpMessage?: string | string[]
|
|
33
|
+
/** 值类型 */
|
|
34
|
+
valueType?: 'text' | 'date' | 'dateTime' | 'option' | 'select' | 'index'
|
|
35
|
+
/** 枚举值映射 */
|
|
36
|
+
valueEnum?: Record<string | number, { text: string; status?: string }>
|
|
37
|
+
/** 自定义渲染 */
|
|
38
|
+
customRender?: (params: { text: unknown; record: Record<string, unknown>; index: number }) => VNode | string
|
|
39
|
+
/** Element UI formatter */
|
|
40
|
+
formatter?: (row: Record<string, unknown>, column: unknown, cellValue: unknown) => string
|
|
41
|
+
/** 根据业务控制列是否显示 */
|
|
42
|
+
ifShow?: boolean | ((params: { column: ProColumn }) => boolean)
|
|
43
|
+
/** 表单项配置(用于搜索) */
|
|
44
|
+
fieldProps?: Record<string, unknown>
|
|
45
|
+
/** 表单项占位符 */
|
|
46
|
+
placeholder?: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 接口请求配置 */
|
|
50
|
+
export interface FetchSetting {
|
|
51
|
+
pageField?: string
|
|
52
|
+
sizeField?: string
|
|
53
|
+
listField?: string
|
|
54
|
+
totalField?: string
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** reload 请求参数(参考 VbenAdmin FetchParams) */
|
|
58
|
+
export interface FetchParams {
|
|
59
|
+
page?: number
|
|
60
|
+
pageSize?: number
|
|
61
|
+
searchInfo?: Record<string, unknown>
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 合并单元格回调参数 */
|
|
65
|
+
export interface SpanMethodParams {
|
|
66
|
+
row: Record<string, unknown>
|
|
67
|
+
column: Record<string, unknown>
|
|
68
|
+
rowIndex: number
|
|
69
|
+
columnIndex: number
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 合并单元格返回值 */
|
|
73
|
+
export type SpanMethodResult = [number, number] | { rowspan: number; colspan: number }
|
|
74
|
+
|
|
75
|
+
/** 树形表格配置 */
|
|
76
|
+
export interface TreeProps {
|
|
77
|
+
/** 是否有子节点字段名 */
|
|
78
|
+
hasChildren?: string
|
|
79
|
+
/** 子节点字段名 */
|
|
80
|
+
children?: string
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** ProTable Props */
|
|
84
|
+
export interface ProTableProps {
|
|
85
|
+
columns?: ProColumn[]
|
|
86
|
+
dataSource?: Record<string, unknown>[]
|
|
87
|
+
api?: (params: Record<string, unknown>) => Promise<unknown>
|
|
88
|
+
rowKey?: string
|
|
89
|
+
title?: string
|
|
90
|
+
titleHelpMessage?: string | string[]
|
|
91
|
+
bordered?: boolean
|
|
92
|
+
striped?: boolean
|
|
93
|
+
size?: 'medium' | 'small' | 'large'
|
|
94
|
+
loading?: boolean
|
|
95
|
+
maxHeight?: number | string
|
|
96
|
+
height?: number | string
|
|
97
|
+
ellipsis?: boolean
|
|
98
|
+
showIndexColumn?: boolean
|
|
99
|
+
indexColumnProps?: Partial<ProColumn>
|
|
100
|
+
actionColumn?: Partial<ProColumn>
|
|
101
|
+
/** 选择列配置(参考 VbenAdmin,通过自定义列实现,不使用 type="selection") */
|
|
102
|
+
rowSelection?: {
|
|
103
|
+
type?: 'checkbox' | 'radio'
|
|
104
|
+
width?: number
|
|
105
|
+
fixed?: 'left' | 'right'
|
|
106
|
+
/** 多选时禁用某行的勾选,(record) => { disabled?: boolean } */
|
|
107
|
+
getCheckboxProps?: (record: Record<string, unknown>) => { disabled?: boolean }
|
|
108
|
+
/** 单选时禁用某行的选择,(record) => { disabled?: boolean } */
|
|
109
|
+
getRadioProps?: (record: Record<string, unknown>) => { disabled?: boolean }
|
|
110
|
+
}
|
|
111
|
+
/** 切换页码时是否清空勾选,默认 false 即支持跨分页选择 */
|
|
112
|
+
clearSelectOnPageChange?: boolean
|
|
113
|
+
pagination?: false | Record<string, unknown>
|
|
114
|
+
fetchSetting?: FetchSetting
|
|
115
|
+
beforeFetch?: (params: Record<string, unknown>) => Record<string, unknown>
|
|
116
|
+
afterFetch?: (data: unknown) => unknown
|
|
117
|
+
immediate?: boolean
|
|
118
|
+
searchInfo?: Record<string, unknown>
|
|
119
|
+
/** 合并行或列的方法 */
|
|
120
|
+
spanMethod?: (params: SpanMethodParams) => SpanMethodResult
|
|
121
|
+
/** 树形表格配置 */
|
|
122
|
+
treeProps?: TreeProps
|
|
123
|
+
/** 是否默认展开所有行(树形表格) */
|
|
124
|
+
defaultExpandAll?: boolean
|
|
125
|
+
/** 展开的行(树形表格),需配合 rowKey 使用 */
|
|
126
|
+
expandRowKeys?: (string | number)[]
|
|
127
|
+
/** 是否懒加载子节点(树形表格) */
|
|
128
|
+
lazy?: boolean
|
|
129
|
+
/** 懒加载子节点的方法(树形表格) */
|
|
130
|
+
load?: (row: Record<string, unknown>, treeNode: { level: number; expanded: boolean; loaded: boolean }, resolve: (data: Record<string, unknown>[]) => void) => void
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** 行选择配置(与 ProTableProps.rowSelection 一致,供 getRowSelection 返回) */
|
|
134
|
+
export type TableRowSelection = ProTableProps['rowSelection']
|
|
135
|
+
|
|
136
|
+
/** TableAction 气泡确认配置(参考 VbenAdmin PopConfirm) */
|
|
137
|
+
export interface TableActionPopConfirm {
|
|
138
|
+
title: string
|
|
139
|
+
okText?: string
|
|
140
|
+
cancelText?: string
|
|
141
|
+
confirm: () => void | Promise<void>
|
|
142
|
+
cancel?: () => void | Promise<void>
|
|
143
|
+
icon?: string
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** TableAction 单个操作项(参考 VbenAdmin ActionItem) */
|
|
147
|
+
export interface TableActionItem {
|
|
148
|
+
/** 按钮文本 */
|
|
149
|
+
label: string
|
|
150
|
+
/** 是否禁用 */
|
|
151
|
+
disabled?: boolean
|
|
152
|
+
/** 按钮颜色(内部会映射到 Element UI 按钮类型) */
|
|
153
|
+
color?: 'success' | 'error' | 'warning'
|
|
154
|
+
/** 按钮类型,直接透传给 Element UI Button 的 type */
|
|
155
|
+
type?: string
|
|
156
|
+
/** 额外的按钮 props,直接透传给 Element UI Button */
|
|
157
|
+
props?: Record<string, unknown>
|
|
158
|
+
/** 图标 class(例如 element-ui 图标或自定义 iconfont) */
|
|
159
|
+
icon?: string
|
|
160
|
+
/** 气泡确认配置 */
|
|
161
|
+
popConfirm?: TableActionPopConfirm
|
|
162
|
+
/** 是否显示分隔线(垂直 Divider) */
|
|
163
|
+
divider?: boolean
|
|
164
|
+
/** 权限标识,具体含义由业务自行约定 */
|
|
165
|
+
auth?: string | string[]
|
|
166
|
+
/** 是否显示当前操作项,可为布尔值或函数 */
|
|
167
|
+
ifShow?: boolean | ((action: TableActionItem) => boolean)
|
|
168
|
+
/** 点击回调 */
|
|
169
|
+
onClick?: (e: MouseEvent) => void
|
|
170
|
+
/** Tooltip 配置:字符串或 Element UI Tooltip 的 props */
|
|
171
|
+
tooltip?: string | Record<string, unknown>
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** TableAction 组件 Props(参考 VbenAdmin TableAction) */
|
|
175
|
+
export interface TableActionProps {
|
|
176
|
+
actions?: TableActionItem[]
|
|
177
|
+
dropDownActions?: TableActionItem[]
|
|
178
|
+
/** 是否阻止按钮 click 冒泡 */
|
|
179
|
+
stopButtonPropagation?: boolean
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** ProTable 操作类型(参考 Vben Admin TableActionType) */
|
|
183
|
+
export interface TableActionType {
|
|
184
|
+
setProps: (props: Partial<ProTableProps>) => void
|
|
185
|
+
reload: (opt?: FetchParams) => Promise<void>
|
|
186
|
+
/** 重新计算表格高度/布局(参考 VbenAdmin redoHeight) */
|
|
187
|
+
redoHeight: () => void
|
|
188
|
+
setLoading: (loading: boolean) => void
|
|
189
|
+
getDataSource: () => Record<string, unknown>[]
|
|
190
|
+
/** 获取接口原始返回数据(参考 VbenAdmin getRawDataSource) */
|
|
191
|
+
getRawDataSource: () => Record<string, unknown>
|
|
192
|
+
setTableData: (data: Record<string, unknown>[]) => void
|
|
193
|
+
getColumns: () => ProColumn[]
|
|
194
|
+
/** 设置列配置,支持列数组或列 key 列表(参考 VbenAdmin setColumns) */
|
|
195
|
+
setColumns: (columns: ProColumn[] | string[]) => void
|
|
196
|
+
setPagination: (info: Partial<{ page: number; pageSize: number; total: number }>) => void
|
|
197
|
+
getSelectRowKeys: () => (string | number)[]
|
|
198
|
+
getSelectRows: () => Record<string, unknown>[]
|
|
199
|
+
clearSelectedRowKeys: () => void
|
|
200
|
+
/** 设置选中行(参考 VbenAdmin setSelectedRowKeys) */
|
|
201
|
+
setSelectedRowKeys: (keys: (string | number)[]) => void
|
|
202
|
+
/** 按 key 取消选中(参考 VbenAdmin deleteSelectRowByKey) */
|
|
203
|
+
deleteSelectRowByKey: (key: string | number) => void
|
|
204
|
+
/** 按行索引和字段名更新单格数据(参考 VbenAdmin updateTableData) */
|
|
205
|
+
updateTableData: (index: number, key: string, value: unknown) => void
|
|
206
|
+
/** 根据 rowKey 更新指定行(参考 VbenAdmin updateTableDataRecord) */
|
|
207
|
+
updateTableDataRecord: (rowKey: string | number, record: Record<string, unknown>) => Record<string, unknown> | void
|
|
208
|
+
/** 根据 rowKey 删除指定行(参考 VbenAdmin deleteTableDataRecord) */
|
|
209
|
+
deleteTableDataRecord: (rowKey: string | number | (string | number)[]) => void
|
|
210
|
+
/** 插入行(参考 VbenAdmin insertTableDataRecord) */
|
|
211
|
+
insertTableDataRecord: (record: Record<string, unknown>, index?: number) => Record<string, unknown> | void
|
|
212
|
+
/** 获取分页信息(参考 VbenAdmin getPaginationRef) */
|
|
213
|
+
getPaginationRef: () => { page: number; pageSize: number; total: number } | false
|
|
214
|
+
/** 是否显示分页 */
|
|
215
|
+
getShowPagination: () => boolean
|
|
216
|
+
/** 设置是否显示分页(参考 VbenAdmin,返回 Promise) */
|
|
217
|
+
setShowPagination: (show: boolean) => void | Promise<void>
|
|
218
|
+
/** 获取当前行选择配置(参考 VbenAdmin getRowSelection) */
|
|
219
|
+
getRowSelection: () => TableRowSelection
|
|
220
|
+
/** 展开树形表格所有行 */
|
|
221
|
+
expandAll?: () => void
|
|
222
|
+
/** 折叠树形表格所有行 */
|
|
223
|
+
collapseAll?: () => void
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** ProTable 工具栏配置 */
|
|
227
|
+
export interface ProTableToolBarConfig {
|
|
228
|
+
/** 是否显示刷新按钮 */
|
|
229
|
+
reload?: boolean
|
|
230
|
+
/** 是否显示密度切换 */
|
|
231
|
+
density?: boolean
|
|
232
|
+
/** 是否显示列设置 */
|
|
233
|
+
columnSetting?: boolean
|
|
234
|
+
/** 是否显示全屏 */
|
|
235
|
+
fullScreen?: boolean
|
|
236
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ref, watch, unref, type Ref } from 'vue'
|
|
2
|
+
import type { ProTableProps, TableActionType } from './types'
|
|
3
|
+
|
|
4
|
+
export type UseProTableReturn = [
|
|
5
|
+
(instance: TableActionType) => void,
|
|
6
|
+
TableActionType
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
/** 支持 ref/computed 的 props */
|
|
10
|
+
export type UseProTablePropsReactive = ProTableProps | Ref<ProTableProps | undefined>
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 用于 ProTable 的 useProTable,支持通过 ref 调用表格方法
|
|
14
|
+
* @param props ProTable 的 props 配置,传入后会通过 setProps 同步到表格(支持 ref/computed 响应式更新)
|
|
15
|
+
*/
|
|
16
|
+
export function useProTable(props?: UseProTablePropsReactive): UseProTableReturn {
|
|
17
|
+
const tableActionRef = ref<TableActionType | null>(null)
|
|
18
|
+
|
|
19
|
+
const getTableProps = (): ProTableProps | undefined =>
|
|
20
|
+
(props ? unref(props as Ref<ProTableProps | undefined>) : undefined) as ProTableProps | undefined
|
|
21
|
+
|
|
22
|
+
const getTableAction = (): TableActionType => {
|
|
23
|
+
const action = unref(tableActionRef)
|
|
24
|
+
if (!action) {
|
|
25
|
+
throw new Error('ProTable instance has not been registered')
|
|
26
|
+
}
|
|
27
|
+
return action
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const register = (instance: TableActionType) => {
|
|
31
|
+
tableActionRef.value = instance
|
|
32
|
+
const tableProps = getTableProps()
|
|
33
|
+
if (tableProps && Object.keys(tableProps).length > 0) {
|
|
34
|
+
instance.setProps(tableProps)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (props) {
|
|
39
|
+
watch(
|
|
40
|
+
() => getTableProps(),
|
|
41
|
+
(tableProps) => {
|
|
42
|
+
if (tableProps && tableActionRef.value) {
|
|
43
|
+
tableActionRef.value.setProps(tableProps)
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{ deep: true }
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const tableActions: UseProTableReturn[1] = {
|
|
51
|
+
setProps: (p) => getTableAction().setProps(p),
|
|
52
|
+
reload: (opt) => getTableAction().reload(opt),
|
|
53
|
+
redoHeight: () => getTableAction().redoHeight(),
|
|
54
|
+
setLoading: (v) => getTableAction().setLoading(v),
|
|
55
|
+
getDataSource: () => getTableAction().getDataSource(),
|
|
56
|
+
getRawDataSource: () => getTableAction().getRawDataSource(),
|
|
57
|
+
setTableData: (data) => getTableAction().setTableData(data),
|
|
58
|
+
getColumns: () => getTableAction().getColumns(),
|
|
59
|
+
setColumns: (cols) => getTableAction().setColumns(cols),
|
|
60
|
+
setPagination: (info) => getTableAction().setPagination(info),
|
|
61
|
+
getSelectRowKeys: () => getTableAction().getSelectRowKeys(),
|
|
62
|
+
getSelectRows: () => getTableAction().getSelectRows(),
|
|
63
|
+
clearSelectedRowKeys: () => getTableAction().clearSelectedRowKeys(),
|
|
64
|
+
setSelectedRowKeys: (keys) => getTableAction().setSelectedRowKeys(keys),
|
|
65
|
+
deleteSelectRowByKey: (key) => getTableAction().deleteSelectRowByKey(key),
|
|
66
|
+
updateTableData: (index, key, value) => getTableAction().updateTableData(index, key, value),
|
|
67
|
+
updateTableDataRecord: (rowKey, record) => getTableAction().updateTableDataRecord(rowKey, record),
|
|
68
|
+
deleteTableDataRecord: (rowKey) => getTableAction().deleteTableDataRecord(rowKey),
|
|
69
|
+
insertTableDataRecord: (record, index) => getTableAction().insertTableDataRecord(record, index),
|
|
70
|
+
getPaginationRef: () => getTableAction().getPaginationRef(),
|
|
71
|
+
getShowPagination: () => getTableAction().getShowPagination(),
|
|
72
|
+
setShowPagination: (show) => getTableAction().setShowPagination(show),
|
|
73
|
+
getRowSelection: () => getTableAction().getRowSelection(),
|
|
74
|
+
expandAll: () => getTableAction().expandAll?.(),
|
|
75
|
+
collapseAll: () => getTableAction().collapseAll?.(),
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return [register, tableActions]
|
|
79
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import type { VueConstructor } from 'vue'
|
|
2
|
-
|
|
2
|
+
import ProTable, { TableAction } from './ProTable'
|
|
3
3
|
import ProForm, { ProFormItem, FormActions } from './ProForm'
|
|
4
|
-
// import ProCard from './ProCard'
|
|
5
|
-
// import ProDescriptions from './ProDescriptions'
|
|
6
4
|
import { useForm } from './ProForm/useForm'
|
|
5
|
+
import { useProTable } from './ProTable/useProTable'
|
|
6
|
+
import { useComponentSetting } from './useComponentSetting'
|
|
7
7
|
|
|
8
8
|
export { ProForm, ProFormItem, FormActions, useForm }
|
|
9
|
+
export { ProTable, useProTable, TableAction }
|
|
10
|
+
export { useComponentSetting }
|
|
11
|
+
export type { UseComponentSettingReturn } from './useComponentSetting'
|
|
12
|
+
export type { UseProTableReturn, UseProTablePropsReactive } from './ProTable/useProTable'
|
|
13
|
+
export * from './ProTable/types'
|
|
9
14
|
export * from './types'
|
|
10
15
|
|
|
11
16
|
const components = [
|
|
12
|
-
|
|
17
|
+
{ name: 'ProTable', component: ProTable },
|
|
18
|
+
{ name: 'TableAction', component: TableAction },
|
|
13
19
|
{ name: 'ProForm', component: ProForm },
|
|
14
20
|
{ name: 'ProFormItem', component: ProFormItem },
|
|
15
|
-
{ name: 'FormActions', component: FormActions }
|
|
16
|
-
// { name: 'ProCard', component: ProCard },
|
|
17
|
-
// { name: 'ProDescriptions', component: ProDescriptions },
|
|
21
|
+
{ name: 'FormActions', component: FormActions },
|
|
18
22
|
]
|
|
19
23
|
|
|
20
24
|
export function install(Vue: VueConstructor) {
|
|
@@ -25,8 +29,7 @@ export function install(Vue: VueConstructor) {
|
|
|
25
29
|
|
|
26
30
|
export default {
|
|
27
31
|
install,
|
|
28
|
-
|
|
32
|
+
ProTable,
|
|
29
33
|
ProForm,
|
|
30
|
-
|
|
31
|
-
// ProDescriptions,
|
|
34
|
+
TableAction,
|
|
32
35
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,49 +1,5 @@
|
|
|
1
1
|
import type { VNode } from 'vue'
|
|
2
2
|
|
|
3
|
-
/** ProTable 列配置 */
|
|
4
|
-
export interface ProColumn {
|
|
5
|
-
/** 列标题 */
|
|
6
|
-
title: string
|
|
7
|
-
/** 数据字段名 */
|
|
8
|
-
dataIndex: string
|
|
9
|
-
/** 列宽度 */
|
|
10
|
-
width?: number | string
|
|
11
|
-
/** 最小宽度 */
|
|
12
|
-
minWidth?: number | string
|
|
13
|
-
/** 固定列 */
|
|
14
|
-
fixed?: 'left' | 'right'
|
|
15
|
-
/** 是否可排序 */
|
|
16
|
-
sortable?: boolean
|
|
17
|
-
/** 对齐方式 */
|
|
18
|
-
align?: 'left' | 'center' | 'right'
|
|
19
|
-
/** 是否可调整宽度 */
|
|
20
|
-
resizable?: boolean
|
|
21
|
-
/** 是否隐藏 */
|
|
22
|
-
hideInTable?: boolean
|
|
23
|
-
/** 值类型 */
|
|
24
|
-
valueType?: 'text' | 'date' | 'dateTime' | 'option' | 'select' | 'index'
|
|
25
|
-
/** 枚举值映射 */
|
|
26
|
-
valueEnum?: Record<string | number, { text: string; status?: string }>
|
|
27
|
-
/** 自定义渲染 */
|
|
28
|
-
customRender?: (params: { text: unknown; record: Record<string, unknown>; index: number }) => VNode | string
|
|
29
|
-
/** 表单项配置(用于搜索) */
|
|
30
|
-
fieldProps?: Record<string, unknown>
|
|
31
|
-
/** 表单项占位符 */
|
|
32
|
-
placeholder?: string
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** ProTable 工具栏配置 */
|
|
36
|
-
export interface ProTableToolBarConfig {
|
|
37
|
-
/** 是否显示刷新按钮 */
|
|
38
|
-
reload?: boolean
|
|
39
|
-
/** 是否显示密度切换 */
|
|
40
|
-
density?: boolean
|
|
41
|
-
/** 是否显示列设置 */
|
|
42
|
-
columnSetting?: boolean
|
|
43
|
-
/** 是否显示全屏 */
|
|
44
|
-
fullScreen?: boolean
|
|
45
|
-
}
|
|
46
|
-
|
|
47
3
|
/** 栅格配置 */
|
|
48
4
|
export interface ColEx {
|
|
49
5
|
span?: number
|
|
@@ -122,16 +78,40 @@ export interface ProFormProps {
|
|
|
122
78
|
fieldMapToTime?: FieldMapToTime[]
|
|
123
79
|
/** 透传给 el-form 的事件监听器 */
|
|
124
80
|
formListeners?: FormListeners
|
|
81
|
+
/** 自定义组件映射(组件名 -> 组件定义),供 schema.component 使用 */
|
|
82
|
+
components?: Record<string, unknown>
|
|
125
83
|
}
|
|
126
84
|
|
|
85
|
+
/** ProForm 内置表单项组件类型 */
|
|
86
|
+
export type ProFormBuiltInComponent =
|
|
87
|
+
| 'input'
|
|
88
|
+
| 'select'
|
|
89
|
+
| 'api-select'
|
|
90
|
+
| 'tree-select'
|
|
91
|
+
| 'date-picker'
|
|
92
|
+
| 'date-range'
|
|
93
|
+
| 'input-number'
|
|
94
|
+
| 'switch'
|
|
95
|
+
| 'cascader'
|
|
96
|
+
| 'checkbox'
|
|
97
|
+
| 'radio'
|
|
98
|
+
|
|
99
|
+
/** 自定义组件:组件名(string)或 Vue 组件选项/构造函数(object | Function) */
|
|
100
|
+
export type ProFormCustomComponent = string | object | ((...args: unknown[]) => unknown)
|
|
101
|
+
|
|
127
102
|
/** ProForm 表单项配置 */
|
|
128
103
|
export interface ProFormSchema {
|
|
129
104
|
/** 字段名 */
|
|
130
105
|
field: string
|
|
131
106
|
/** 标签 */
|
|
132
107
|
label: string
|
|
133
|
-
/**
|
|
134
|
-
|
|
108
|
+
/**
|
|
109
|
+
* 组件类型:
|
|
110
|
+
* - 内置:'input' | 'select' | 'date-picker' | 'date-range' | 'input-number' | 'switch' | 'cascader' | 'checkbox' | 'radio'
|
|
111
|
+
* - 自定义组件名:任意字符串,对应全局或 ProForm 传入的 components 中注册的组件
|
|
112
|
+
* - 内联组件:直接传入 Vue 组件选项对象或构造函数
|
|
113
|
+
*/
|
|
114
|
+
component?: ProFormBuiltInComponent | ProFormCustomComponent
|
|
135
115
|
/** 组件属性,支持函数 */
|
|
136
116
|
componentProps?: Record<string, unknown> | ((params: RenderCallbackParams & { formActionType?: FormActionType }) => Record<string, unknown>)
|
|
137
117
|
/** 占位符 */
|