@dt-frames/ui 1.0.10 → 1.0.13
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/es/components/curd/src/components/dialog.d.ts +28 -18
- package/es/components/curd/src/components/props.d.ts +4 -4
- package/es/components/curd/src/types/curd.type.d.ts +3 -2
- package/es/components/forms/src/components/formIcon.d.ts +11 -6
- package/es/components/forms/src/components/formInputUseDialog.d.ts +903 -0
- package/es/components/forms/src/types/form.type.d.ts +3 -1
- package/es/components/index.d.ts +1 -1
- package/es/components/modal/src/components/modal.d.ts +2 -2
- package/es/components/modal/src/components/modalFooter.d.ts +9 -4
- package/es/components/modal/src/index.d.ts +10 -5
- package/es/components/modal/src/props.d.ts +2 -1
- package/es/components/modal/src/types/modal.type.d.ts +5 -2
- package/es/components/source/src/hooks/useFetch.d.ts +2 -2
- package/es/components/source/src/hooks/useSource.d.ts +4 -4
- package/es/components/table/src/components/TableHeader.d.ts +2 -2
- package/es/components/table/src/components/editable/CellComponent.d.ts +14 -0
- package/es/components/table/src/components/editable/EditTableCell.d.ts +88 -0
- package/es/components/table/src/components/editable/componentMap.d.ts +4 -0
- package/es/components/table/src/components/editable/index.d.ts +9 -0
- package/es/components/table/src/hooks/useCustomRow.d.ts +19 -0
- package/es/components/table/src/hooks/useTable.d.ts +2 -2
- package/es/components/table/src/index.d.ts +27 -4
- package/es/components/table/src/props.d.ts +5 -1
- package/es/components/table/src/types/table.type.d.ts +18 -2
- package/es/components/upload/index.d.ts +1 -2
- package/es/components/upload/src/helper.d.ts +1 -0
- package/es/components/upload/src/index.d.ts +40 -13
- package/es/components/upload/src/props.d.ts +4 -1
- package/es/components/upload/src/upload.d.ts +45 -10
- package/es/index.js +589 -212
- package/es/style/components/forms/index.less +23 -0
- package/es/style/components/table/index.less +6 -0
- package/es/style/components/upload/index.less +3 -11
- package/es/style/theme/header/index.less +1 -1
- package/package.json +1 -1
- package/src/components/curd/src/components/dialog.vue +7 -5
- package/src/components/curd/src/components/props.ts +4 -4
- package/src/components/curd/src/hooks/useCurd.tsx +1 -1
- package/src/components/curd/src/types/curd.type.ts +3 -2
- package/src/components/forms/index.less +23 -0
- package/src/components/forms/src/componentMap.ts +2 -0
- package/src/components/forms/src/components/formInputUseDialog.vue +43 -0
- package/src/components/forms/src/components/formItem.vue +10 -10
- package/src/components/forms/src/types/form.type.ts +6 -0
- package/src/components/index.ts +1 -2
- package/src/components/modal/src/components/modalFooter.vue +10 -2
- package/src/components/modal/src/hooks/useModal.ts +12 -4
- package/src/components/modal/src/index.vue +19 -8
- package/src/components/modal/src/props.ts +3 -2
- package/src/components/modal/src/types/modal.type.ts +5 -2
- package/src/components/source/src/hooks/useFetch.ts +6 -4
- package/src/components/source/src/hooks/useSource.ts +5 -4
- package/src/components/table/index.less +6 -0
- package/src/components/table/src/components/TableHeader.vue +2 -2
- package/src/components/table/src/components/editable/CellComponent.ts +57 -0
- package/src/components/table/src/components/editable/EditTableCell.vue +181 -0
- package/src/components/table/src/components/editable/componentMap.ts +18 -0
- package/src/components/table/src/components/editable/index.ts +58 -0
- package/src/components/table/src/hooks/useColumns.ts +15 -8
- package/src/components/table/src/hooks/useCustomRow.ts +86 -0
- package/src/components/table/src/hooks/useRowSelection.ts +1 -1
- package/src/components/table/src/hooks/useTable.ts +1 -1
- package/src/components/table/src/hooks/useTableHeader.ts +1 -1
- package/src/components/table/src/index.vue +20 -3
- package/src/components/table/src/props.ts +4 -1
- package/src/components/table/src/types/table.type.ts +30 -3
- package/src/components/upload/index.less +3 -11
- package/src/components/upload/index.ts +0 -2
- package/src/components/upload/src/helper.ts +29 -1
- package/src/components/upload/src/props.ts +4 -1
- package/src/components/upload/src/upload.vue +88 -63
- package/src/theme/header/index.less +1 -1
- package/src/components/upload/src/index.vue +0 -38
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Recordable } from "@dt-frames/core"
|
|
2
|
+
import { Popover } from "ant-design-vue"
|
|
3
|
+
import { DefineComponent, FunctionalComponent, h, Ref } from "vue"
|
|
4
|
+
import { ComponentType } from "../../types/table.type"
|
|
5
|
+
import { componentMap } from "./componentMap"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
type ComponentProps = {
|
|
9
|
+
component: ComponentType
|
|
10
|
+
rule: boolean
|
|
11
|
+
popoverVisible: boolean
|
|
12
|
+
ruleMessage: string
|
|
13
|
+
getPopupContainer?: any
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type EditRecordRow<T = Recordable> = Partial<
|
|
17
|
+
{
|
|
18
|
+
onEdit: (editable: boolean, submit?: boolean) => Promise<boolean>;
|
|
19
|
+
onValid: () => Promise<boolean>;
|
|
20
|
+
editable: boolean;
|
|
21
|
+
onCancel: Function;
|
|
22
|
+
onSubmit: Function;
|
|
23
|
+
submitCbs: Function[];
|
|
24
|
+
cancelCbs: Function[];
|
|
25
|
+
validCbs: Function[];
|
|
26
|
+
editValueRefs: Recordable<Ref>;
|
|
27
|
+
} & T
|
|
28
|
+
>
|
|
29
|
+
|
|
30
|
+
export const CellComponent: FunctionalComponent = ({
|
|
31
|
+
component = 'Input',
|
|
32
|
+
rule = true,
|
|
33
|
+
ruleMessage,
|
|
34
|
+
popoverVisible,
|
|
35
|
+
getPopupContainer
|
|
36
|
+
}: ComponentProps,
|
|
37
|
+
{ attrs }
|
|
38
|
+
) => {
|
|
39
|
+
const Comp = componentMap.get(component) as DefineComponent
|
|
40
|
+
|
|
41
|
+
const DefaultComp = h(Comp, attrs)
|
|
42
|
+
|
|
43
|
+
if (!rule) return DefaultComp
|
|
44
|
+
|
|
45
|
+
return h(
|
|
46
|
+
Popover,
|
|
47
|
+
{
|
|
48
|
+
overlayClassName: 'edit-cell-rule-popover',
|
|
49
|
+
visible: !!popoverVisible,
|
|
50
|
+
...(getPopupContainer ? { getPopupContainer } : {}),
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
default: () => DefaultComp,
|
|
54
|
+
content: () => ruleMessage,
|
|
55
|
+
},
|
|
56
|
+
)
|
|
57
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="editable-cell">
|
|
3
|
+
<CellComponent
|
|
4
|
+
ref="elRef"
|
|
5
|
+
v-bind="getComponentProps"
|
|
6
|
+
:component = "column?.editComponent"
|
|
7
|
+
:popoverVisible = "getRuleVisible"
|
|
8
|
+
:rule = "editRule"
|
|
9
|
+
:ruleMessage = "ruleMessage"
|
|
10
|
+
:class = "getWrapperClass"
|
|
11
|
+
:onChange = "handleChange"
|
|
12
|
+
:onOptionsChange = "handleOptionsChange"
|
|
13
|
+
>
|
|
14
|
+
</CellComponent>
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script lang="tsx">
|
|
19
|
+
import { DtEvent, isBoolean, isNumber, isString, Recordable } from "@dt-frames/core"
|
|
20
|
+
import { isFunction } from "@vueuse/core"
|
|
21
|
+
import { omit } from 'lodash-es'
|
|
22
|
+
import { Spin } from "ant-design-vue"
|
|
23
|
+
import { defineComponent, PropType, ref, unref, computed, toRaw } from "vue"
|
|
24
|
+
import { BasicColumn, ComponentType, LableValOptions } from "../../types/table.type"
|
|
25
|
+
import { CellComponent, EditRecordRow } from "./CellComponent"
|
|
26
|
+
import { getTableInstance } from "../../hooks/useTableInstance"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export default defineComponent({
|
|
30
|
+
name: 'EditableCell',
|
|
31
|
+
components: {
|
|
32
|
+
Spin,
|
|
33
|
+
CellComponent
|
|
34
|
+
},
|
|
35
|
+
props: {
|
|
36
|
+
value: {
|
|
37
|
+
type: [String, Number, Boolean, Object] as PropType<string | number | boolean | Recordable>,
|
|
38
|
+
default: ''
|
|
39
|
+
},
|
|
40
|
+
record: {
|
|
41
|
+
type: Object as PropType<EditRecordRow>,
|
|
42
|
+
},
|
|
43
|
+
column: {
|
|
44
|
+
type: Object as PropType<BasicColumn>,
|
|
45
|
+
default: ():BasicColumn => ({}),
|
|
46
|
+
},
|
|
47
|
+
index: Number
|
|
48
|
+
},
|
|
49
|
+
setup(props) {
|
|
50
|
+
const table = getTableInstance()
|
|
51
|
+
const elRef = ref()
|
|
52
|
+
|
|
53
|
+
const { editRule, align = 'left' } = props.column
|
|
54
|
+
|
|
55
|
+
const ruleMessage = ref('')
|
|
56
|
+
const ruleVisible = ref(false)
|
|
57
|
+
|
|
58
|
+
const optionsRef = ref<LableValOptions>([])
|
|
59
|
+
const currentValueRef = ref<any>(props.value)
|
|
60
|
+
|
|
61
|
+
const getComponent = computed(() => props.column?.editComponent || 'Input')
|
|
62
|
+
|
|
63
|
+
// 提示信息是否可见
|
|
64
|
+
const getRuleVisible = computed(() => {
|
|
65
|
+
return unref( ruleMessage ) && unref( ruleVisible )
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const getWrapperClass = computed(() => {
|
|
69
|
+
return `edit-cell-align-${align}`
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const getIsCheckComp = computed(() => {
|
|
73
|
+
const component = unref(getComponent);
|
|
74
|
+
return ['Checkbox', 'Switch'].includes(component);
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const createPlaceholderMessage = ( component: ComponentType ) => {
|
|
78
|
+
if( component.includes('Input') ) {
|
|
79
|
+
return '请输入'
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return '请选择'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 设置表格属性
|
|
86
|
+
const getComponentProps = computed(() => {
|
|
87
|
+
const isCheckValue = unref(getIsCheckComp)
|
|
88
|
+
const valueField = isCheckValue ? 'checked' : 'value'
|
|
89
|
+
|
|
90
|
+
const val = unref(currentValueRef)
|
|
91
|
+
const value = isCheckValue ? (isNumber(val) && isBoolean(val) ? val : !!val) : val
|
|
92
|
+
|
|
93
|
+
let compProps = props.column?.editComponentProps ?? {}
|
|
94
|
+
|
|
95
|
+
const { record, column, index } = props
|
|
96
|
+
if (isFunction(compProps)) {
|
|
97
|
+
compProps = compProps({ text: val, record, column, index }) ?? {}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
size: 'small',
|
|
102
|
+
getPopupContainer: () => document.body,
|
|
103
|
+
placeholder: createPlaceholderMessage(unref(getComponent)),
|
|
104
|
+
...omit(compProps, 'onChange'),
|
|
105
|
+
[valueField]: value
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
async function handleChange( e: any ) {
|
|
111
|
+
const component = unref(getComponent)
|
|
112
|
+
|
|
113
|
+
if( !e ) {
|
|
114
|
+
currentValueRef.value = e
|
|
115
|
+
} else if (component === 'Checkbox') {
|
|
116
|
+
currentValueRef.value = (e as DtEvent).target.checked
|
|
117
|
+
} else if (component === 'Switch') {
|
|
118
|
+
currentValueRef.value = e
|
|
119
|
+
} else if (e?.target && Reflect.has(e.target, 'value')) {
|
|
120
|
+
currentValueRef.value = (e as DtEvent).target.value
|
|
121
|
+
} else if (isString(e) || isBoolean(e) || isNumber(e)) {
|
|
122
|
+
currentValueRef.value = e
|
|
123
|
+
}
|
|
124
|
+
const onChange = unref(getComponentProps)?.onChange
|
|
125
|
+
if (onChange && isFunction(onChange)) onChange(...arguments)
|
|
126
|
+
|
|
127
|
+
table.emit?.('edit-change', {
|
|
128
|
+
column: props.column,
|
|
129
|
+
value: unref(currentValueRef),
|
|
130
|
+
record: toRaw(props.record),
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
handleSubmitRule()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
async function handleSubmitRule() {
|
|
138
|
+
const { column, record } = props
|
|
139
|
+
const { editRule } = column
|
|
140
|
+
const currentValue = unref(currentValueRef)
|
|
141
|
+
|
|
142
|
+
if ( editRule ) {
|
|
143
|
+
if( isBoolean(editRule) && !currentValue && !isNumber(currentValue) ) {
|
|
144
|
+
ruleVisible.value = true
|
|
145
|
+
const component = unref(getComponent)
|
|
146
|
+
ruleMessage.value = createPlaceholderMessage(component)
|
|
147
|
+
return false
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if( isFunction(editRule) ) {
|
|
151
|
+
const res = await editRule(currentValue, record as Recordable)
|
|
152
|
+
|
|
153
|
+
if (!!res) {
|
|
154
|
+
ruleMessage.value = res;
|
|
155
|
+
ruleVisible.value = true;
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
ruleMessage.value = ''
|
|
162
|
+
return true
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function handleOptionsChange(options: LableValOptions) {
|
|
166
|
+
optionsRef.value = options
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
props,
|
|
171
|
+
getComponentProps,
|
|
172
|
+
getRuleVisible,
|
|
173
|
+
editRule,
|
|
174
|
+
ruleMessage,
|
|
175
|
+
getWrapperClass,
|
|
176
|
+
handleChange,
|
|
177
|
+
handleOptionsChange
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
</script>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Input, Select, Checkbox, DatePicker, InputNumber, Switch, TimePicker, TreeSelect } from 'ant-design-vue'
|
|
2
|
+
import { Component } from 'vue'
|
|
3
|
+
import { ComponentType } from '../../types/table.type'
|
|
4
|
+
|
|
5
|
+
const componentMap = new Map<ComponentType, Component>()
|
|
6
|
+
|
|
7
|
+
componentMap.set('Input', Input)
|
|
8
|
+
componentMap.set('InputNumber', InputNumber)
|
|
9
|
+
componentMap.set('Select', Select)
|
|
10
|
+
componentMap.set('TreeSelect', TreeSelect)
|
|
11
|
+
componentMap.set('Switch', Switch)
|
|
12
|
+
componentMap.set('Checkbox', Checkbox)
|
|
13
|
+
componentMap.set('DatePicker', DatePicker)
|
|
14
|
+
componentMap.set('TimePicker', TimePicker)
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
componentMap
|
|
18
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { isArray } from '@dt-frames/core'
|
|
2
|
+
import { h } from 'vue'
|
|
3
|
+
import { BasicColumn } from "../../types/table.type"
|
|
4
|
+
import EditableCell from './EditTableCell.vue'
|
|
5
|
+
|
|
6
|
+
function renderEditCell(column: BasicColumn) {
|
|
7
|
+
return ({text: value, record, index}) => {
|
|
8
|
+
// 触发校验
|
|
9
|
+
record.onValid = async () => {
|
|
10
|
+
if ( isArray( record?.validCbs ) ) {
|
|
11
|
+
const validFns = (record?.validCbs || []).map((fn) => fn())
|
|
12
|
+
const res = await Promise.all( validFns )
|
|
13
|
+
return res.every((item) => !!item)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// 触发修改
|
|
20
|
+
record.onEdit = async (edit: boolean, submit = false) => {
|
|
21
|
+
if (!submit) {
|
|
22
|
+
record.editable = edit;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 提交
|
|
26
|
+
if (!edit && submit) {
|
|
27
|
+
if ( !(await record.onValid()) ) return false
|
|
28
|
+
|
|
29
|
+
const res = await record.onSubmitEdit?.()
|
|
30
|
+
|
|
31
|
+
if (res) {
|
|
32
|
+
record.editable = false
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 取消
|
|
40
|
+
if (!edit && !submit) {
|
|
41
|
+
record.onCancelEdit?.()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return true
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return h(EditableCell, {
|
|
48
|
+
value,
|
|
49
|
+
record,
|
|
50
|
+
column,
|
|
51
|
+
index,
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
renderEditCell
|
|
58
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { PaginationProps } from 'ant-design-vue/lib/pagination'
|
|
2
|
-
import { computed, ComputedRef, Ref, ref, unref, toRaw, watch, h } from "vue"
|
|
3
|
-
import { cloneDeep, isEqual } from 'lodash-es'
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
2
|
+
import { computed, ComputedRef, Ref, ref, unref, toRaw, watch, h } from "vue"
|
|
3
|
+
import { cloneDeep, isEqual, omit } from 'lodash-es'
|
|
4
|
+
import { renderEditCell } from '../components/editable'
|
|
5
|
+
import { BasicColumn, BasicTableProps } from "../types/table.type"
|
|
6
|
+
import { SetColumnsParams } from '../types/tableHeader.type'
|
|
7
|
+
import { isArray, isBoolean, isFunction, isObject, isString, Recordable, useAppStore, getDictValueByCode } from '@dt-frames/core'
|
|
7
8
|
import TableAction from '../components/TableActions.vue'
|
|
8
9
|
|
|
9
10
|
// 索引列及操作列标识
|
|
@@ -157,12 +158,11 @@ function handleActionColumn(propsRef: ComputedRef<BasicTableProps>, columns: Bas
|
|
|
157
158
|
customRender: ({ record, index}) => {
|
|
158
159
|
return h(
|
|
159
160
|
TableAction as any,
|
|
160
|
-
{
|
|
161
|
+
omit({
|
|
161
162
|
...columnObj,
|
|
162
163
|
record,
|
|
163
|
-
align: null,
|
|
164
164
|
index
|
|
165
|
-
}
|
|
165
|
+
}, 'align')
|
|
166
166
|
)
|
|
167
167
|
}
|
|
168
168
|
})
|
|
@@ -211,6 +211,13 @@ export function useColumns(
|
|
|
211
211
|
|
|
212
212
|
return columns
|
|
213
213
|
.filter( column => isIfShow(column) )
|
|
214
|
+
.map(column => {
|
|
215
|
+
if( column.edit ) {
|
|
216
|
+
column.customRender = renderEditCell(column)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return column
|
|
220
|
+
})
|
|
214
221
|
|
|
215
222
|
})
|
|
216
223
|
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { DtEvent, Recordable } from "@dt-frames/core"
|
|
2
|
+
import { ComputedRef, unref } from "vue"
|
|
3
|
+
import { BasicTableProps } from "../types/table.type"
|
|
4
|
+
|
|
5
|
+
interface Options {
|
|
6
|
+
setSelectedRowKeys: (keys: string[]) => void
|
|
7
|
+
getSelectRowKeys: () => string[]
|
|
8
|
+
clearSelectedRowKeys: () => void
|
|
9
|
+
emit: any
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useCustomRow(
|
|
13
|
+
propsRef: ComputedRef<BasicTableProps>,
|
|
14
|
+
{ setSelectedRowKeys, getSelectRowKeys, clearSelectedRowKeys, emit }: Options
|
|
15
|
+
) {
|
|
16
|
+
const customRow = (record: Recordable, index: number) => {
|
|
17
|
+
return {
|
|
18
|
+
onClick: (e) => {
|
|
19
|
+
e?.stopPropagation()
|
|
20
|
+
|
|
21
|
+
function handleClick() {
|
|
22
|
+
const { rowSelection, rowKey, clickToRowSelect } = unref(propsRef)
|
|
23
|
+
if (!rowSelection || !clickToRowSelect) return
|
|
24
|
+
|
|
25
|
+
const keys = getSelectRowKeys()
|
|
26
|
+
const key = record[rowKey]
|
|
27
|
+
if (!key) return
|
|
28
|
+
|
|
29
|
+
const isCheckbox = rowSelection.type === 'checkbox'
|
|
30
|
+
if (isCheckbox) {
|
|
31
|
+
const tr: HTMLElement = (e as MouseEvent)
|
|
32
|
+
.composedPath?.()
|
|
33
|
+
.find((dom: HTMLElement) => dom.tagName === 'TR') as HTMLElement;
|
|
34
|
+
if (!tr) return
|
|
35
|
+
|
|
36
|
+
const checkBox = tr.querySelector('input[type=checkbox]')
|
|
37
|
+
|
|
38
|
+
if (!checkBox || checkBox.hasAttribute('disabled')) return
|
|
39
|
+
|
|
40
|
+
if (!keys.includes(key)) {
|
|
41
|
+
setSelectedRowKeys([...keys, key])
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const keyIndex = keys.findIndex((item) => item === key)
|
|
46
|
+
keys.splice(keyIndex, 1)
|
|
47
|
+
setSelectedRowKeys(keys)
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const isRadio = rowSelection.type === 'radio'
|
|
52
|
+
|
|
53
|
+
if (isRadio) {
|
|
54
|
+
if (!keys.includes(key)) {
|
|
55
|
+
if (keys.length) {
|
|
56
|
+
clearSelectedRowKeys()
|
|
57
|
+
}
|
|
58
|
+
setSelectedRowKeys([key])
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
clearSelectedRowKeys()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
handleClick()
|
|
66
|
+
emit('row-click', record, index, e)
|
|
67
|
+
},
|
|
68
|
+
onDblclick: (event: Event) => {
|
|
69
|
+
emit('row-dbClick', record, index, event);
|
|
70
|
+
},
|
|
71
|
+
onContextmenu: (event: Event) => {
|
|
72
|
+
emit('row-contextmenu', record, index, event);
|
|
73
|
+
},
|
|
74
|
+
onMouseenter: (event: Event) => {
|
|
75
|
+
emit('row-mouseenter', record, index, event);
|
|
76
|
+
},
|
|
77
|
+
onMouseleave: (event: Event) => {
|
|
78
|
+
emit('row-mouseleave', record, index, event);
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
customRow,
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -6,7 +6,7 @@ import { useHeaderCode } from './useHeaderCode'
|
|
|
6
6
|
|
|
7
7
|
type Props = Partial<DynamicProps<BasicTableProps>>
|
|
8
8
|
|
|
9
|
-
export function useTable(tableProps?: Props) {
|
|
9
|
+
export function useTable(tableProps?: Props): [registerTable: (...args: any) => void, methods: TableActionType] {
|
|
10
10
|
const tableRef = ref<Nullable<TableActionType>>(null)
|
|
11
11
|
const loadedRef = ref<Nullable<boolean>>(false)
|
|
12
12
|
|
|
@@ -12,7 +12,7 @@ export function useTableHeader(
|
|
|
12
12
|
const { tableSetting, toolbar } = unref(propsRef)
|
|
13
13
|
|
|
14
14
|
const { getSlot } = useSlots()
|
|
15
|
-
const hideTitle = !slots.toolbar && !slots.headerTop && !tableSetting
|
|
15
|
+
const hideTitle = !toolbar && !slots.toolbar && !slots.headerTop && !tableSetting
|
|
16
16
|
|
|
17
17
|
return {
|
|
18
18
|
title: hideTitle
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
import { useColumns } from "./hooks/useColumns"
|
|
38
38
|
import { useTableHeader } from "./hooks/useTableHeader"
|
|
39
39
|
import { useTableScroll } from "./hooks/useTableScroll"
|
|
40
|
+
import { useCustomRow } from "./hooks/useCustomRow"
|
|
40
41
|
|
|
41
42
|
|
|
42
43
|
export default defineComponent({
|
|
@@ -49,7 +50,14 @@
|
|
|
49
50
|
emits: [
|
|
50
51
|
'register',
|
|
51
52
|
'columns-change',
|
|
52
|
-
'selection-change'
|
|
53
|
+
'selection-change',
|
|
54
|
+
'row-click',
|
|
55
|
+
'row-dbClick',
|
|
56
|
+
'row-contextmenu',
|
|
57
|
+
'row-mouseenter',
|
|
58
|
+
'row-mouseleave',
|
|
59
|
+
'expanded-rows-change',
|
|
60
|
+
'edit-change'
|
|
53
61
|
],
|
|
54
62
|
setup(props, { emit, attrs, slots }) {
|
|
55
63
|
// table实例
|
|
@@ -91,7 +99,7 @@
|
|
|
91
99
|
getRowSelection,
|
|
92
100
|
getSelectRows,
|
|
93
101
|
getSelectRowKeys,
|
|
94
|
-
|
|
102
|
+
setSelectedRowKeys
|
|
95
103
|
} = useRowSelection(getProps, emit)
|
|
96
104
|
|
|
97
105
|
// 关于滚动条的设置
|
|
@@ -116,6 +124,7 @@
|
|
|
116
124
|
getCacheColumns,
|
|
117
125
|
getSelectRows,
|
|
118
126
|
getSelectRowKeys,
|
|
127
|
+
emit,
|
|
119
128
|
getSize: () => {
|
|
120
129
|
return unref(getBind).size as SizeType;
|
|
121
130
|
}
|
|
@@ -140,6 +149,13 @@
|
|
|
140
149
|
emit
|
|
141
150
|
)
|
|
142
151
|
|
|
152
|
+
// 表格的单击 双击事件
|
|
153
|
+
const { customRow } = useCustomRow(getProps, {
|
|
154
|
+
setSelectedRowKeys,
|
|
155
|
+
getSelectRowKeys,
|
|
156
|
+
clearSelectedRowKeys,
|
|
157
|
+
emit
|
|
158
|
+
})
|
|
143
159
|
|
|
144
160
|
const getBind = computed(() => {
|
|
145
161
|
return {
|
|
@@ -153,7 +169,8 @@
|
|
|
153
169
|
rowSelection: unref(getRowSelectionRef),
|
|
154
170
|
rowKey: unref(getProps).rowKey,
|
|
155
171
|
columns: unref(getViewColumns),
|
|
156
|
-
tableLayout: 'fixed'
|
|
172
|
+
tableLayout: 'fixed',
|
|
173
|
+
customRow,
|
|
157
174
|
}
|
|
158
175
|
})
|
|
159
176
|
|
|
@@ -12,7 +12,10 @@ export const TableProps = {
|
|
|
12
12
|
clickRowSelect: { type: Boolean, default: false },
|
|
13
13
|
|
|
14
14
|
// 表格设置
|
|
15
|
-
tableSetting: {type: Object as PropType<TableSetting>, default: () => ({})},
|
|
15
|
+
tableSetting: {type: Object as PropType<TableSetting | boolean>, default: () => ({})},
|
|
16
|
+
|
|
17
|
+
// 点击行是否可以选中整行数据
|
|
18
|
+
clickToRowSelect: { type: Boolean, default: false },
|
|
16
19
|
|
|
17
20
|
// 是否显示斑马条纹
|
|
18
21
|
striped: { type: Boolean, default: true },
|
|
@@ -88,6 +88,22 @@ export type ActionType = {
|
|
|
88
88
|
btns?: BtnsType[]
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
export type ComponentType =
|
|
92
|
+
| 'Input'
|
|
93
|
+
| 'InputNumber'
|
|
94
|
+
| 'Select'
|
|
95
|
+
| 'TreeSelect'
|
|
96
|
+
| 'Checkbox'
|
|
97
|
+
| 'Switch'
|
|
98
|
+
| 'DatePicker'
|
|
99
|
+
| 'TimePicker'
|
|
100
|
+
|
|
101
|
+
export type LableValOptions = {
|
|
102
|
+
label: string;
|
|
103
|
+
value: any;
|
|
104
|
+
[key: string]: string | number | boolean
|
|
105
|
+
}[]
|
|
106
|
+
|
|
91
107
|
|
|
92
108
|
export interface BasicColumn extends ColumnProps {
|
|
93
109
|
// 子元素
|
|
@@ -107,7 +123,17 @@ export interface BasicColumn extends ColumnProps {
|
|
|
107
123
|
|
|
108
124
|
edit?: boolean
|
|
109
125
|
editRow?: boolean
|
|
110
|
-
|
|
126
|
+
editable?: boolean
|
|
127
|
+
editComponent?: ComponentType
|
|
128
|
+
editComponentProps?:
|
|
129
|
+
| ((opt: {
|
|
130
|
+
text: string | number | boolean | Recordable;
|
|
131
|
+
record: Recordable;
|
|
132
|
+
column: BasicColumn;
|
|
133
|
+
index: number;
|
|
134
|
+
}) => Recordable)
|
|
135
|
+
| Recordable
|
|
136
|
+
editRule?: boolean | ((text: string, record: Recordable) => Promise<string>)
|
|
111
137
|
|
|
112
138
|
// 是否显示序号列
|
|
113
139
|
showIndexColumn?: boolean
|
|
@@ -128,6 +154,7 @@ export type TableActionType = {
|
|
|
128
154
|
getRowSelection: () => TableRowSelection<Recordable>
|
|
129
155
|
getCacheColumns: () => BasicColumn[]
|
|
130
156
|
setCacheColumnsByField?: (dataIndex: string | undefined, value: BasicColumn) => void
|
|
131
|
-
getSelectRows: ( ) =>
|
|
132
|
-
getSelectRowKeys: ( ) =>
|
|
157
|
+
getSelectRows: ( ) => Recordable[]
|
|
158
|
+
getSelectRowKeys: ( ) => string[]
|
|
159
|
+
emit?: any
|
|
133
160
|
}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
.dt-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
display: flex;
|
|
5
|
-
flex-direction: column;
|
|
6
|
-
|
|
7
|
-
.ant-table-wrapper{
|
|
8
|
-
flex: 1;
|
|
9
|
-
.ant-table-body{
|
|
10
|
-
border-bottom: 1px solid #e7e7e7;
|
|
11
|
-
}
|
|
1
|
+
.dt-file {
|
|
2
|
+
td.orange{
|
|
3
|
+
color: orange;
|
|
12
4
|
}
|
|
13
5
|
}
|
|
14
6
|
|
|
@@ -26,7 +26,35 @@ export function useHelpers(
|
|
|
26
26
|
.join(',')
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
+
const getHelpText = computed(() => {
|
|
30
|
+
const helpText = unref(helpTextRef)
|
|
31
|
+
if (helpText) {
|
|
32
|
+
return helpText
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const helpTexts: string[] = []
|
|
36
|
+
|
|
37
|
+
const accept = unref(acceptRef)
|
|
38
|
+
if (accept.length > 0) {
|
|
39
|
+
helpTexts.push(`支持${ accept.join(',') }格式`)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const maxSize = unref(maxSizeRef)
|
|
43
|
+
if (maxSize) {
|
|
44
|
+
helpTexts.push(`不超过${ maxSize }M`)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const maxNumber = unref(maxNumberRef)
|
|
48
|
+
if (maxNumber && maxNumber !== Infinity) {
|
|
49
|
+
helpTexts.push(`最多可选择${ maxNumber }个文件`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return helpTexts.join(',') || '请上传pptx、doc、jpg、jpeg、png、bmp、gif、xls、xlsx、txt、rar、zip、7z、tar、gz格式文件'
|
|
53
|
+
|
|
54
|
+
})
|
|
55
|
+
|
|
29
56
|
return {
|
|
30
|
-
getStringAccept
|
|
57
|
+
getStringAccept,
|
|
58
|
+
getHelpText
|
|
31
59
|
}
|
|
32
60
|
}
|
|
@@ -34,7 +34,6 @@ export const basicUploadProps = {
|
|
|
34
34
|
// 文件最大多少MB
|
|
35
35
|
maxSize: {
|
|
36
36
|
type: Number as PropType<number>,
|
|
37
|
-
default: 2,
|
|
38
37
|
},
|
|
39
38
|
// 最大数量的文件,Infinity不限制
|
|
40
39
|
maxNumber: {
|
|
@@ -44,5 +43,9 @@ export const basicUploadProps = {
|
|
|
44
43
|
defaultFiles: {
|
|
45
44
|
type: Array as PropType<FileType[]>,
|
|
46
45
|
default: []
|
|
46
|
+
},
|
|
47
|
+
showView: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
default: false
|
|
47
50
|
}
|
|
48
51
|
}
|