@dt-frames/ui 1.0.10 → 1.0.11
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 +1 -0
- package/es/components/forms/src/components/formIcon.d.ts +1 -1
- package/es/components/modal/src/types/modal.type.d.ts +1 -1
- 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/index.d.ts +7 -3
- package/es/components/table/src/props.d.ts +1 -1
- package/es/components/table/src/types/table.type.d.ts +16 -0
- package/es/components/upload/src/index.d.ts +7 -3
- package/es/components/upload/src/upload.d.ts +7 -3
- package/es/index.js +318 -73
- package/es/style/components/table/index.less +6 -0
- package/es/style/theme/header/index.less +1 -1
- package/package.json +1 -1
- package/src/components/curd/src/components/dialog.vue +4 -2
- package/src/components/modal/src/hooks/useModal.ts +5 -3
- package/src/components/modal/src/index.vue +1 -1
- package/src/components/modal/src/types/modal.type.ts +1 -1
- package/src/components/source/src/hooks/useFetch.ts +6 -4
- package/src/components/source/src/hooks/useSource.ts +4 -3
- 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/useTableHeader.ts +2 -2
- package/src/components/table/src/index.vue +6 -1
- package/src/components/table/src/props.ts +1 -1
- package/src/components/table/src/types/table.type.ts +28 -1
- package/src/theme/header/index.less +1 -1
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
}
|
|
27
27
|
} )
|
|
28
28
|
|
|
29
|
-
const [registerDialog] = useModal({
|
|
29
|
+
const [registerDialog, { closeModal }] = useModal({
|
|
30
30
|
...omit(toRaw(props), [
|
|
31
31
|
'actions',
|
|
32
32
|
'curd',
|
|
@@ -63,9 +63,11 @@
|
|
|
63
63
|
getFormValues()
|
|
64
64
|
)
|
|
65
65
|
|
|
66
|
-
obj.id
|
|
66
|
+
let pro = obj.id
|
|
67
67
|
? props.curd.onUpdate( obj )
|
|
68
68
|
: props.curd.onAdd( obj )
|
|
69
|
+
|
|
70
|
+
pro.then( rsp => closeModal() )
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
</script>
|
|
@@ -155,10 +155,11 @@ export function useModal(props?: Partial<ModalProps>,callbackFn?: Function): Use
|
|
|
155
155
|
getVisible: computed(() => visibleData[~~unref(uidRef)]),
|
|
156
156
|
|
|
157
157
|
// 关闭弹框进行回调
|
|
158
|
-
closeModal: (rsp
|
|
159
|
-
cbTransfer[unref(uidRef)](rsp)
|
|
160
|
-
getInstance()?.setModalProps({ visible: false })
|
|
158
|
+
closeModal: (rsp?: Recordable) => {
|
|
159
|
+
if(cbTransfer[unref(uidRef)]) cbTransfer[unref(uidRef)](rsp)
|
|
160
|
+
getInstance()?.setModalProps({ visible: false })
|
|
161
161
|
},
|
|
162
|
+
|
|
162
163
|
openModal: <T = any>(visable = true, data?: T, openOnSet = true) => {
|
|
163
164
|
getInstance()?.setModalProps({
|
|
164
165
|
visible: visable
|
|
@@ -178,6 +179,7 @@ export function useModal(props?: Partial<ModalProps>,callbackFn?: Function): Use
|
|
|
178
179
|
dataTransfer[id] = toRaw(data);
|
|
179
180
|
}
|
|
180
181
|
},
|
|
182
|
+
|
|
181
183
|
setModalProps: (props: Partial<ModalProps>) => {
|
|
182
184
|
getInstance()?.setModalProps(props);
|
|
183
185
|
},
|
|
@@ -15,7 +15,7 @@ export interface ReturnMethods extends ModalMethods{
|
|
|
15
15
|
|
|
16
16
|
export interface ReturnInnerMethods extends ModalMethods {
|
|
17
17
|
openModal: <T = any>(props?: boolean, data?: T, openOnSet?: boolean) => void
|
|
18
|
-
closeModal: (rsp
|
|
18
|
+
closeModal: (rsp?: Recordable) => void
|
|
19
19
|
changeLoading: (loading: boolean) => void
|
|
20
20
|
getVisible?: ComputedRef<boolean>
|
|
21
21
|
redoModalHeight: () => void
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { http, isString, JsonResult, Recordable, ApiType } from "@dt-frames/core";
|
|
1
|
+
import { http, isString, JsonResult, Recordable, ApiType, isObject } from "@dt-frames/core";
|
|
2
2
|
|
|
3
3
|
export function useFetch(api: string | ApiType, baseUrl: string = '') {
|
|
4
4
|
/**
|
|
5
5
|
* 发送请求
|
|
6
6
|
* handleParams 记录返回的值
|
|
7
7
|
*/
|
|
8
|
-
function fetch(params:
|
|
9
|
-
let type, header = { }, model = {}
|
|
8
|
+
function fetch(params: any) {
|
|
9
|
+
let type, header = { }, model = {}
|
|
10
10
|
if(isString( api )) {
|
|
11
11
|
api = baseUrl + api
|
|
12
12
|
} else {
|
|
@@ -19,7 +19,9 @@ export function useFetch(api: string | ApiType, baseUrl: string = '') {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
return new Promise(( resolve, reject ) => {
|
|
22
|
-
|
|
22
|
+
let param = isObject(params) ? Object.assign({}, model, params) : params
|
|
23
|
+
|
|
24
|
+
http[type || 'post']( api, param, {
|
|
23
25
|
...header,
|
|
24
26
|
...{ onlyData: false }
|
|
25
27
|
}).then(
|
|
@@ -134,7 +134,7 @@ export function useSource(opt: SourceType) {
|
|
|
134
134
|
function onAdd(model: Recordable) {
|
|
135
135
|
const { fetch } = useFetch(add, baseUrl)
|
|
136
136
|
|
|
137
|
-
fetch(model).then( (rsp: any) => {
|
|
137
|
+
return fetch(model).then( (rsp: any) => {
|
|
138
138
|
message.success('新增成功')
|
|
139
139
|
search()
|
|
140
140
|
} )
|
|
@@ -151,7 +151,7 @@ export function useSource(opt: SourceType) {
|
|
|
151
151
|
// 修改
|
|
152
152
|
function onUpdate(model: Recordable) {
|
|
153
153
|
const { fetch } = useFetch(update, baseUrl)
|
|
154
|
-
fetch(model).then( (rsp: any) => {
|
|
154
|
+
return fetch(model).then( (rsp: any) => {
|
|
155
155
|
message.success('更新数据成功')
|
|
156
156
|
search()
|
|
157
157
|
} )
|
|
@@ -162,7 +162,8 @@ export function useSource(opt: SourceType) {
|
|
|
162
162
|
function onDeletes(ids: any) {
|
|
163
163
|
const { fetch } = useFetch(deletes, baseUrl)
|
|
164
164
|
|
|
165
|
-
fetch(ids).then( (rsp: any) => {
|
|
165
|
+
fetch(toRaw(ids)).then( (rsp: any) => {
|
|
166
|
+
message.success(`${ ids.length > 1 ? '批量' : '' } 删除成功!`)
|
|
166
167
|
search()
|
|
167
168
|
} )
|
|
168
169
|
}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<slot name="toolbar"></slot>
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
|
-
<div class="dt-table-header-actions__right">
|
|
12
|
+
<div class="dt-table-header-actions__right" v-if="tableTools">
|
|
13
13
|
<TableSettinCom
|
|
14
14
|
:setting="tableTools"
|
|
15
15
|
@columns-change="handleColumnChange"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
props: {
|
|
44
44
|
tableTools: {
|
|
45
|
-
type: Object as PropType<TableSetting>
|
|
45
|
+
type: Object as PropType<TableSetting | boolean>
|
|
46
46
|
},
|
|
47
47
|
toolbar: {
|
|
48
48
|
type: Array as PropType<BtnsType[]>,
|
|
@@ -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
|
|
|
@@ -9,10 +9,10 @@ export function useTableHeader(
|
|
|
9
9
|
handlers: { onColumnsChange: (data: ColumnChangeParam[]) => void }
|
|
10
10
|
) {
|
|
11
11
|
const getHeaderProps = computed((): Recordable => {
|
|
12
|
-
const { tableSetting, toolbar } = unref(propsRef)
|
|
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.length && !slots.toolbar && !slots.headerTop && !tableSetting
|
|
16
16
|
|
|
17
17
|
return {
|
|
18
18
|
title: hideTitle
|
|
@@ -49,7 +49,11 @@
|
|
|
49
49
|
emits: [
|
|
50
50
|
'register',
|
|
51
51
|
'columns-change',
|
|
52
|
-
'selection-change'
|
|
52
|
+
'selection-change',
|
|
53
|
+
'row-click',
|
|
54
|
+
'row-dbClick',
|
|
55
|
+
'expanded-rows-change',
|
|
56
|
+
'edit-change'
|
|
53
57
|
],
|
|
54
58
|
setup(props, { emit, attrs, slots }) {
|
|
55
59
|
// table实例
|
|
@@ -116,6 +120,7 @@
|
|
|
116
120
|
getCacheColumns,
|
|
117
121
|
getSelectRows,
|
|
118
122
|
getSelectRowKeys,
|
|
123
|
+
emit,
|
|
119
124
|
getSize: () => {
|
|
120
125
|
return unref(getBind).size as SizeType;
|
|
121
126
|
}
|
|
@@ -12,7 +12,7 @@ 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
16
|
|
|
17
17
|
// 是否显示斑马条纹
|
|
18
18
|
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
|
|
@@ -130,4 +156,5 @@ export type TableActionType = {
|
|
|
130
156
|
setCacheColumnsByField?: (dataIndex: string | undefined, value: BasicColumn) => void
|
|
131
157
|
getSelectRows: ( ) => void
|
|
132
158
|
getSelectRowKeys: ( ) => void
|
|
159
|
+
emit?: any
|
|
133
160
|
}
|