gi-component 0.0.6 → 0.0.8
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/dist/gi.css +1 -1
- package/dist/index.d.ts +22 -10
- package/dist/index.es.js +42 -41
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +10 -3
- package/packages/components/button/index.ts +4 -4
- package/packages/components/button/src/button.vue +32 -32
- package/packages/components/button/src/type.ts +2 -2
- package/packages/components/card/index.ts +4 -4
- package/packages/components/card/src/card.vue +21 -21
- package/packages/components/card/src/type.ts +9 -9
- package/packages/components/dialog/index.ts +5 -5
- package/packages/components/dialog/src/dialog.ts +33 -33
- package/packages/components/dialog/src/dialog.vue +34 -32
- package/packages/components/dialog/src/type.ts +13 -13
- package/packages/components/edit-table/index.ts +4 -4
- package/packages/components/edit-table/src/edit-table.vue +49 -49
- package/packages/components/edit-table/src/type.ts +42 -62
- package/packages/components/form/index.ts +4 -4
- package/packages/components/form/src/form.vue +98 -98
- package/packages/components/form/src/type.ts +74 -88
- package/packages/components/grid/index.ts +6 -6
- package/packages/components/grid/src/context.ts +17 -17
- package/packages/components/grid/src/grid-item.vue +40 -40
- package/packages/components/grid/src/grid.vue +38 -38
- package/packages/components/grid/src/hook/use-index.ts +24 -24
- package/packages/components/grid/src/hook/use-responsive-state.ts +26 -26
- package/packages/components/grid/src/hook/use-responsive-value.ts +24 -24
- package/packages/components/grid/src/interface.ts +32 -32
- package/packages/components/grid/src/utils/global-config.ts +3 -3
- package/packages/components/grid/src/utils/index.ts +25 -25
- package/packages/components/grid/src/utils/is.ts +2 -2
- package/packages/components/grid/src/utils/responsive-observe.ts +53 -53
- package/packages/components/input-group/index.ts +4 -4
- package/packages/components/input-group/src/input-group.vue +2 -2
- package/packages/components/input-search/index.ts +4 -4
- package/packages/components/input-search/src/input-search.vue +15 -15
- package/packages/components/input-search/src/type.ts +4 -4
- package/packages/components/page-layout/index.ts +4 -4
- package/packages/components/page-layout/src/page-layout.vue +25 -25
- package/packages/components/page-layout/src/split-button.vue +22 -22
- package/packages/components/page-layout/src/type.ts +9 -9
- package/packages/components/table/index.ts +4 -4
- package/packages/components/table/src/TableColumn.vue +10 -10
- package/packages/components/table/src/table.vue +14 -14
- package/packages/components/table/src/type.ts +8 -16
- package/packages/components/tabs/index.ts +4 -4
- package/packages/components/tabs/src/tabs.vue +26 -36
- package/packages/components/tabs/src/type.ts +9 -9
- package/packages/hooks/index.ts +2 -2
- package/packages/hooks/useBemClass.ts +7 -7
- package/packages/hooks/useTable.ts +6 -7
- package/packages/index.ts +44 -44
- package/packages/styles/index.scss +6 -0
- package/packages/types/tool.ts +14 -0
- package/packages/utils/createSelectDialog.ts +28 -27
- package/packages/utils/index.ts +1 -1
|
@@ -22,55 +22,56 @@
|
|
|
22
22
|
</template>
|
|
23
23
|
|
|
24
24
|
<script lang="ts" setup>
|
|
25
|
-
import type { FormInstance } from 'element-plus'
|
|
26
|
-
import type { EditTableColumnItem, EditTableColumnItemType } from './type'
|
|
27
|
-
import type { EditTableProps } from './type.ts'
|
|
28
|
-
import * as El from 'element-plus'
|
|
29
|
-
import { computed,
|
|
30
|
-
import { useBemClass } from '../../../hooks'
|
|
25
|
+
import type { FormInstance } from 'element-plus'
|
|
26
|
+
import type { EditTableColumnItem, EditTableColumnItemType } from './type'
|
|
27
|
+
import type { EditTableProps } from './type.ts'
|
|
28
|
+
import * as El from 'element-plus'
|
|
29
|
+
import { computed, ref, useAttrs } from 'vue'
|
|
30
|
+
import { useBemClass } from '../../../hooks'
|
|
31
31
|
import InputSearch from '../../input-search'
|
|
32
32
|
|
|
33
33
|
const props = withDefaults(defineProps<EditTableProps>(), {
|
|
34
34
|
rowKey: 'id',
|
|
35
35
|
data: () => [],
|
|
36
36
|
columns: () => []
|
|
37
|
-
})
|
|
37
|
+
})
|
|
38
38
|
|
|
39
|
-
const attrs = useAttrs()
|
|
40
|
-
const { b } = useBemClass()
|
|
39
|
+
const attrs = useAttrs()
|
|
40
|
+
const { b } = useBemClass()
|
|
41
41
|
|
|
42
|
-
const COMP_MAP: Record<
|
|
43
|
-
input: El.ElInput,
|
|
44
|
-
textarea: El.ElInput,
|
|
42
|
+
const COMP_MAP: Record<EditTableColumnItemType, any> = {
|
|
43
|
+
'input': El.ElInput,
|
|
44
|
+
'textarea': El.ElInput,
|
|
45
45
|
'input-number': El.ElInputNumber,
|
|
46
46
|
'input-tag': El.ElInputTag,
|
|
47
|
-
select: El.ElSelect,
|
|
47
|
+
'select': El.ElSelect,
|
|
48
48
|
'select-v2': El.ElSelectV2,
|
|
49
49
|
'tree-select': El.ElTreeSelect,
|
|
50
|
-
cascader: El.ElCascader,
|
|
51
|
-
slider: El.ElSlider,
|
|
52
|
-
switch: El.ElSwitch,
|
|
53
|
-
rate: El.ElRate,
|
|
50
|
+
'cascader': El.ElCascader,
|
|
51
|
+
'slider': El.ElSlider,
|
|
52
|
+
'switch': El.ElSwitch,
|
|
53
|
+
'rate': El.ElRate,
|
|
54
54
|
'checkbox-group': El.ElCheckboxGroup,
|
|
55
|
-
checkbox: El.ElCheckbox,
|
|
55
|
+
'checkbox': El.ElCheckbox,
|
|
56
56
|
'radio-group': El.ElRadioGroup,
|
|
57
|
-
radio: El.ElRadio,
|
|
57
|
+
'radio': El.ElRadio,
|
|
58
58
|
'date-picker': El.ElDatePicker,
|
|
59
59
|
'time-picker': El.ElTimePicker,
|
|
60
60
|
'time-select': El.ElTimeSelect,
|
|
61
61
|
'color-picker': El.ElColorPicker,
|
|
62
|
-
transfer: El.ElTransfer,
|
|
63
|
-
autocomplete: El.ElAutocomplete,
|
|
64
|
-
upload: El.ElUpload,
|
|
65
|
-
'input-search': InputSearch
|
|
66
|
-
|
|
62
|
+
'transfer': El.ElTransfer,
|
|
63
|
+
'autocomplete': El.ElAutocomplete,
|
|
64
|
+
'upload': El.ElUpload,
|
|
65
|
+
'input-search': InputSearch,
|
|
66
|
+
'slot': undefined
|
|
67
|
+
}
|
|
67
68
|
|
|
68
|
-
const formRef = ref<FormInstance | null>()
|
|
69
|
+
const formRef = ref<FormInstance | null>()
|
|
69
70
|
|
|
70
71
|
/** 表单数据 */
|
|
71
|
-
const form = computed(() => ({ tableData: props.data }))
|
|
72
|
+
const form = computed(() => ({ tableData: props.data }))
|
|
72
73
|
|
|
73
|
-
const clearable = false
|
|
74
|
+
const clearable = false
|
|
74
75
|
/** 组件静态配置 */
|
|
75
76
|
const STATIC_PROPS = new Map([
|
|
76
77
|
['input', { clearable, maxlength: 20 }],
|
|
@@ -105,44 +106,43 @@ const STATIC_PROPS = new Map([
|
|
|
105
106
|
['autocomplete', {}],
|
|
106
107
|
['upload', {}],
|
|
107
108
|
['title', {}]
|
|
108
|
-
])
|
|
109
|
+
])
|
|
109
110
|
|
|
110
111
|
/** 获取占位文本 */
|
|
111
112
|
const getPlaceholder = (item: EditTableColumnItem) => {
|
|
112
|
-
if (!item.type) return undefined
|
|
113
|
+
if (!item.type) return undefined
|
|
113
114
|
if (['input', 'input-number', 'input-tag'].includes(item.type)) {
|
|
114
|
-
return `请输入${item.label}
|
|
115
|
+
return `请输入${item.label}`
|
|
115
116
|
}
|
|
116
117
|
if (['textarea'].includes(item.type)) {
|
|
117
|
-
return `请填写${item.label}
|
|
118
|
+
return `请填写${item.label}`
|
|
118
119
|
}
|
|
119
120
|
if (
|
|
120
121
|
['select', 'select-v2', 'tree-select', 'cascader', 'time-select', 'input-search'].includes(
|
|
121
122
|
item.type
|
|
122
123
|
)
|
|
123
124
|
) {
|
|
124
|
-
return `请选择${item.label}
|
|
125
|
+
return `请选择${item.label}`
|
|
125
126
|
}
|
|
126
127
|
if (['date-picker'].includes(item.type)) {
|
|
127
|
-
return
|
|
128
|
+
return `请选择日期`
|
|
128
129
|
}
|
|
129
130
|
if (['time-picker'].includes(item.type)) {
|
|
130
|
-
return
|
|
131
|
+
return `请选择时间`
|
|
131
132
|
}
|
|
132
|
-
return undefined
|
|
133
|
-
}
|
|
133
|
+
return undefined
|
|
134
|
+
}
|
|
134
135
|
|
|
135
136
|
// 组件的默认props配置
|
|
136
137
|
function getComponentBindProps(item: EditTableColumnItem) {
|
|
137
138
|
// 获取默认配置
|
|
138
|
-
const defaultProps: any = STATIC_PROPS.get(item.type || '') || {}
|
|
139
|
-
defaultProps.placeholder = getPlaceholder(item)
|
|
139
|
+
const defaultProps: any = STATIC_PROPS.get(item.type || '') || {}
|
|
140
|
+
defaultProps.placeholder = getPlaceholder(item)
|
|
140
141
|
if (item.type === 'date-picker') {
|
|
141
|
-
defaultProps.valueFormat =
|
|
142
|
-
item?.componentProps?.type === 'datetime' ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD';
|
|
142
|
+
defaultProps.valueFormat = item?.componentProps?.type === 'datetime' ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD'
|
|
143
143
|
}
|
|
144
144
|
// 合并默认配置和自定义配置
|
|
145
|
-
return { ...defaultProps, ...item
|
|
145
|
+
return { ...defaultProps, ...(item?.componentProps || {}) }
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
/** 表单项校验规则 */
|
|
@@ -151,24 +151,24 @@ function getFormItemRules(item: EditTableColumnItem) {
|
|
|
151
151
|
return [
|
|
152
152
|
{ required: true, message: `${item.label}为必填项` },
|
|
153
153
|
...(Array.isArray(item.rules) ? item.rules : [])
|
|
154
|
-
]
|
|
154
|
+
]
|
|
155
155
|
}
|
|
156
|
-
return item.rules
|
|
156
|
+
return item.rules
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
/** 表头标题样式 */
|
|
160
160
|
function getLabelClassName(item: EditTableColumnItem) {
|
|
161
|
-
if (item.required) return 'column-required'
|
|
162
|
-
return ''
|
|
161
|
+
if (item.required) return 'column-required'
|
|
162
|
+
return ''
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
/** 判断是否禁用 */
|
|
166
166
|
const isDisabled = (p: any) => {
|
|
167
|
-
if (typeof props?.cellDisabled === 'function') return props.cellDisabled(p)
|
|
168
|
-
return false
|
|
169
|
-
}
|
|
167
|
+
if (typeof props?.cellDisabled === 'function') return props.cellDisabled(p)
|
|
168
|
+
return false
|
|
169
|
+
}
|
|
170
170
|
|
|
171
|
-
defineExpose({ formRef })
|
|
171
|
+
defineExpose({ formRef })
|
|
172
172
|
</script>
|
|
173
173
|
|
|
174
174
|
<style lang="scss" scoped>
|
|
@@ -1,71 +1,51 @@
|
|
|
1
|
-
import type * as El from 'element-plus'
|
|
1
|
+
import type * as El from 'element-plus'
|
|
2
|
+
import type { MergeMultiple } from '../../../types/tool'
|
|
2
3
|
import type { InputSearchInstance } from '../../input-search'
|
|
3
4
|
|
|
4
|
-
export type EditTableColumnItemType
|
|
5
|
-
| 'input'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
5
|
+
export type EditTableColumnItemType
|
|
6
|
+
= | 'input'
|
|
7
|
+
| 'textarea'
|
|
8
|
+
| 'input-number'
|
|
9
|
+
| 'input-tag'
|
|
10
|
+
| 'select'
|
|
11
|
+
| 'select-v2'
|
|
12
|
+
| 'tree-select'
|
|
13
|
+
| 'cascader'
|
|
14
|
+
| 'slider'
|
|
15
|
+
| 'switch'
|
|
16
|
+
| 'rate'
|
|
17
|
+
| 'checkbox-group'
|
|
18
|
+
| 'checkbox'
|
|
19
|
+
| 'radio-group'
|
|
20
|
+
| 'radio'
|
|
21
|
+
| 'date-picker'
|
|
22
|
+
| 'time-picker'
|
|
23
|
+
| 'time-select'
|
|
24
|
+
| 'color-picker'
|
|
25
|
+
| 'transfer'
|
|
26
|
+
| 'autocomplete'
|
|
27
|
+
| 'upload'
|
|
28
|
+
| 'slot'
|
|
29
|
+
| 'input-search'
|
|
29
30
|
|
|
30
31
|
export interface EditTableColumnItem {
|
|
31
|
-
type?: EditTableColumnItemType
|
|
32
|
-
label: string
|
|
33
|
-
prop: string
|
|
34
|
-
width?: number | string
|
|
35
|
-
required?: boolean
|
|
36
|
-
rules?: El.FormItemRule[]
|
|
37
|
-
componentProps?:
|
|
38
|
-
columnProps?: El.TableColumnInstance['$props']
|
|
39
|
-
formItemProps?: El.FormItemProps
|
|
40
|
-
slotName?: string
|
|
32
|
+
type?: EditTableColumnItemType
|
|
33
|
+
label: string
|
|
34
|
+
prop: string
|
|
35
|
+
width?: number | string
|
|
36
|
+
required?: boolean
|
|
37
|
+
rules?: El.FormItemRule[] // 表单校验规则
|
|
38
|
+
componentProps?: EditTableColumnItemProps
|
|
39
|
+
columnProps?: El.TableColumnInstance['$props']
|
|
40
|
+
formItemProps?: El.FormItemProps
|
|
41
|
+
slotName?: string
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
export type
|
|
44
|
-
El.InputNumberProps &
|
|
45
|
-
El.InputTagProps &
|
|
46
|
-
El.SelectProps &
|
|
47
|
-
El.SelectV2Props &
|
|
48
|
-
El.TreeInstance['$props'] &
|
|
49
|
-
El.CascaderProps &
|
|
50
|
-
El.SliderProps &
|
|
51
|
-
El.SwitchProps &
|
|
52
|
-
El.RateProps &
|
|
53
|
-
El.CheckboxGroupProps &
|
|
54
|
-
El.CheckboxProps &
|
|
55
|
-
El.RadioGroupProps &
|
|
56
|
-
El.RadioProps &
|
|
57
|
-
El.DatePickerProps &
|
|
58
|
-
El.TimePickerDefaultProps &
|
|
59
|
-
El.TimeSelectProps &
|
|
60
|
-
El.ColorPickerProps &
|
|
61
|
-
El.TransferProps &
|
|
62
|
-
El.AutocompleteProps &
|
|
63
|
-
El.UploadProps &
|
|
64
|
-
InputSearchInstance['$props']
|
|
44
|
+
export type EditTableColumnItemProps = 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']]>
|
|
65
45
|
|
|
66
46
|
export interface EditTableProps {
|
|
67
|
-
rowKey?: string
|
|
68
|
-
data?: any[]
|
|
69
|
-
columns?: EditTableColumnItem[]
|
|
70
|
-
cellDisabled?: any
|
|
47
|
+
rowKey?: string
|
|
48
|
+
data?: any[]
|
|
49
|
+
columns?: EditTableColumnItem[]
|
|
50
|
+
cellDisabled?: any
|
|
71
51
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Form from './src/form.vue'
|
|
1
|
+
import Form from './src/form.vue'
|
|
2
2
|
|
|
3
|
-
export type FormInstance = InstanceType<typeof Form
|
|
4
|
-
export * from './src/type'
|
|
5
|
-
export default Form
|
|
3
|
+
export type FormInstance = InstanceType<typeof Form>
|
|
4
|
+
export * from './src/type'
|
|
5
|
+
export default Form
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
|
|
12
12
|
<template v-else>
|
|
13
13
|
<GridItem v-if="!isHide(item)" :key="item.field + index" v-bind="item.gridItemProps || props.gridItemProps"
|
|
14
|
-
:span="item.span
|
|
15
|
-
item.gridItemProps?.span
|
|
16
|
-
props?.gridItemProps?.span
|
|
14
|
+
:span="item.span
|
|
15
|
+
|| item.gridItemProps?.span
|
|
16
|
+
|| props?.gridItemProps?.span
|
|
17
17
|
">
|
|
18
18
|
<el-form-item :key="item.field + index" :prop="item.field" :label="item.label"
|
|
19
19
|
:rules="getFormItemRules(item)" v-bind="item.formItemProps">
|
|
@@ -45,9 +45,11 @@
|
|
|
45
45
|
<!-- 额外信息 -->
|
|
46
46
|
<div v-if="item.extra" :class="b('form-item__extra')">
|
|
47
47
|
<template v-if="typeof item.extra === 'string'">
|
|
48
|
-
<el-text type="info" size="small">
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
<el-text type="info" size="small">
|
|
49
|
+
{{
|
|
50
|
+
item.extra
|
|
51
|
+
}}
|
|
52
|
+
</el-text>
|
|
51
53
|
</template>
|
|
52
54
|
<template v-else-if="item.extra">
|
|
53
55
|
<component :is="item.extra"></component>
|
|
@@ -77,24 +79,23 @@
|
|
|
77
79
|
</template>
|
|
78
80
|
|
|
79
81
|
<script lang="tsx" setup>
|
|
80
|
-
import type {
|
|
81
|
-
import {
|
|
82
|
-
import
|
|
83
|
-
import
|
|
82
|
+
import type { FormInstance } from 'element-plus'
|
|
83
|
+
import type { FormColumnItem, FormColumnType, FormProps } from './type'
|
|
84
|
+
import { ArrowDown, ArrowUp } from '@element-plus/icons-vue'
|
|
85
|
+
import * as El from 'element-plus'
|
|
84
86
|
import {
|
|
85
87
|
computed,
|
|
88
|
+
getCurrentInstance,
|
|
89
|
+
onMounted,
|
|
86
90
|
ref,
|
|
87
91
|
toRaw,
|
|
88
|
-
watch,
|
|
89
92
|
useAttrs,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
} from '
|
|
93
|
-
import
|
|
94
|
-
import
|
|
95
|
-
import
|
|
96
|
-
import InputSearch from '../../input-search';
|
|
97
|
-
import type { FormProps } from './type';
|
|
93
|
+
watch
|
|
94
|
+
} from 'vue'
|
|
95
|
+
import { useBemClass } from '../../../hooks'
|
|
96
|
+
import GiCard from '../../card'
|
|
97
|
+
import { Grid, GridItem } from '../../grid'
|
|
98
|
+
import InputSearch from '../../input-search'
|
|
98
99
|
|
|
99
100
|
const props = withDefaults(defineProps<FormProps>(), {
|
|
100
101
|
columns: () => [],
|
|
@@ -106,23 +107,23 @@ const props = withDefaults(defineProps<FormProps>(), {
|
|
|
106
107
|
hideFoldBtn: false,
|
|
107
108
|
defaultCollapsed: undefined,
|
|
108
109
|
fc: () => ({})
|
|
109
|
-
})
|
|
110
|
+
})
|
|
110
111
|
|
|
111
112
|
const emit = defineEmits<{
|
|
112
|
-
(e: 'update:modelValue', value: any): void
|
|
113
|
-
(e: 'search'): void
|
|
114
|
-
(e: 'reset'): void
|
|
115
|
-
}>()
|
|
116
|
-
|
|
117
|
-
const attrs = useAttrs()
|
|
118
|
-
const { b } = useBemClass()
|
|
119
|
-
const collapsed = ref(props?.defaultCollapsed ?? props.search)
|
|
120
|
-
const instance = getCurrentInstance()
|
|
121
|
-
|
|
122
|
-
const globalConfig = instance?.appContext.config.globalProperties.$config
|
|
123
|
-
const clearable = globalConfig?.clearable ?? false
|
|
113
|
+
(e: 'update:modelValue', value: any): void
|
|
114
|
+
(e: 'search'): void
|
|
115
|
+
(e: 'reset'): void
|
|
116
|
+
}>()
|
|
117
|
+
|
|
118
|
+
const attrs = useAttrs()
|
|
119
|
+
const { b } = useBemClass()
|
|
120
|
+
const collapsed = ref(props?.defaultCollapsed ?? props.search)
|
|
121
|
+
const instance = getCurrentInstance()
|
|
122
|
+
|
|
123
|
+
const globalConfig = instance?.appContext.config.globalProperties.$config
|
|
124
|
+
const clearable = globalConfig?.clearable ?? false
|
|
124
125
|
// 字典数据存储
|
|
125
|
-
const dictData = ref<Record<string, any[]>>({})
|
|
126
|
+
const dictData = ref<Record<string, any[]>>({})
|
|
126
127
|
|
|
127
128
|
/** 组件静态配置 */
|
|
128
129
|
const STATIC_PROPS = new Map([
|
|
@@ -152,60 +153,59 @@ const STATIC_PROPS = new Map([
|
|
|
152
153
|
['autocomplete', {}],
|
|
153
154
|
['upload', {}],
|
|
154
155
|
['title', {}]
|
|
155
|
-
])
|
|
156
|
+
])
|
|
156
157
|
|
|
157
158
|
// 获取字典数据
|
|
158
159
|
const loadDictData = async () => {
|
|
159
|
-
const dictCodes: string[] = []
|
|
160
|
+
const dictCodes: string[] = []
|
|
160
161
|
// 收集所有需要的字典编码
|
|
161
|
-
props.columns?.forEach(item => {
|
|
162
|
+
props.columns?.forEach((item) => {
|
|
162
163
|
if (item.dictCode) {
|
|
163
|
-
dictCodes.push(item.dictCode)
|
|
164
|
+
dictCodes.push(item.dictCode)
|
|
164
165
|
}
|
|
165
|
-
})
|
|
166
|
-
if (!dictCodes.length) return
|
|
166
|
+
})
|
|
167
|
+
if (!dictCodes.length) return
|
|
167
168
|
if (!globalConfig?.dictRequest) {
|
|
168
|
-
return El.ElMessage.error('请配置全局字典请求方法dictRequest')
|
|
169
|
+
return El.ElMessage.error('请配置全局字典请求方法dictRequest')
|
|
169
170
|
}
|
|
170
171
|
try {
|
|
171
172
|
// 使用Promise.all并行处理所有字典请求
|
|
172
173
|
const dictResponses = await Promise.all(
|
|
173
|
-
dictCodes.map(code =>
|
|
174
|
+
dictCodes.map((code) =>
|
|
174
175
|
globalConfig
|
|
175
176
|
.dictRequest(code)
|
|
176
177
|
.then((response: any) => ({ code, response }))
|
|
177
178
|
)
|
|
178
|
-
)
|
|
179
|
+
)
|
|
179
180
|
// 处理所有响应结果
|
|
180
181
|
dictResponses.forEach(({ code, response }) => {
|
|
181
|
-
dictData.value[code] = response
|
|
182
|
-
})
|
|
182
|
+
dictData.value[code] = response
|
|
183
|
+
})
|
|
183
184
|
} catch (error) {
|
|
184
|
-
console.error('获取字典数据失败:', error)
|
|
185
|
-
El.ElMessage.error('获取字典数据失败')
|
|
185
|
+
console.error('获取字典数据失败:', error)
|
|
186
|
+
El.ElMessage.error('获取字典数据失败')
|
|
186
187
|
}
|
|
187
|
-
}
|
|
188
|
+
}
|
|
188
189
|
|
|
189
190
|
// 组件挂载时获取字典数据
|
|
190
191
|
onMounted(() => {
|
|
191
|
-
loadDictData()
|
|
192
|
-
})
|
|
192
|
+
loadDictData()
|
|
193
|
+
})
|
|
193
194
|
|
|
194
195
|
// 组件的默认props配置
|
|
195
196
|
function getComponentBindProps(item: FormColumnItem) {
|
|
196
197
|
// 获取默认配置
|
|
197
|
-
const defaultProps: any = STATIC_PROPS.get(item.type) || {}
|
|
198
|
-
defaultProps.placeholder = getPlaceholder(item)
|
|
198
|
+
const defaultProps: any = STATIC_PROPS.get(item.type) || {}
|
|
199
|
+
defaultProps.placeholder = getPlaceholder(item)
|
|
199
200
|
if (item.type === 'date-picker') {
|
|
200
|
-
defaultProps.valueFormat =
|
|
201
|
-
item?.props?.type === 'datetime' ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD';
|
|
201
|
+
defaultProps.valueFormat = item?.props?.type === 'datetime' ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD'
|
|
202
202
|
}
|
|
203
203
|
// 如果配置了dictCode且存在对应的字典数据,设置options
|
|
204
204
|
if (item.dictCode && dictData.value[item.dictCode]) {
|
|
205
|
-
defaultProps.options = dictData.value[item.dictCode]
|
|
205
|
+
defaultProps.options = dictData.value[item.dictCode]
|
|
206
206
|
}
|
|
207
207
|
// 合并默认配置和自定义配置
|
|
208
|
-
return { ...defaultProps, ...item
|
|
208
|
+
return { ...defaultProps, ...(item?.props || {}) }
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
const formProps = computed(() => {
|
|
@@ -219,54 +219,54 @@ const formProps = computed(() => {
|
|
|
219
219
|
searchText: undefined,
|
|
220
220
|
hideFoldBtn: undefined,
|
|
221
221
|
defaultCollapsed: undefined
|
|
222
|
-
}
|
|
223
|
-
})
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
224
|
|
|
225
225
|
const getClass = computed(() => {
|
|
226
|
-
const arr: string[] = [b('form')]
|
|
226
|
+
const arr: string[] = [b('form')]
|
|
227
227
|
if (props.search) {
|
|
228
|
-
arr.push(b('form--search'))
|
|
228
|
+
arr.push(b('form--search'))
|
|
229
229
|
}
|
|
230
|
-
return arr.join(' ')
|
|
231
|
-
})
|
|
230
|
+
return arr.join(' ')
|
|
231
|
+
})
|
|
232
232
|
|
|
233
233
|
const CompMap: Record<Exclude<FormColumnType, 'slot'>, any> = {
|
|
234
|
-
input: El.ElInput,
|
|
235
|
-
textarea: El.ElInput,
|
|
234
|
+
'input': El.ElInput,
|
|
235
|
+
'textarea': El.ElInput,
|
|
236
236
|
'input-number': El.ElInputNumber,
|
|
237
237
|
'input-tag': El.ElInputTag,
|
|
238
238
|
'input-search': InputSearch,
|
|
239
|
-
select: El.ElSelect,
|
|
239
|
+
'select': El.ElSelect,
|
|
240
240
|
'select-v2': El.ElSelectV2,
|
|
241
241
|
'tree-select': El.ElTreeSelect,
|
|
242
|
-
cascader: El.ElCascader,
|
|
243
|
-
slider: El.ElSlider,
|
|
244
|
-
switch: El.ElSwitch,
|
|
245
|
-
rate: El.ElRate,
|
|
242
|
+
'cascader': El.ElCascader,
|
|
243
|
+
'slider': El.ElSlider,
|
|
244
|
+
'switch': El.ElSwitch,
|
|
245
|
+
'rate': El.ElRate,
|
|
246
246
|
'checkbox-group': El.ElCheckboxGroup,
|
|
247
|
-
checkbox: El.ElCheckbox,
|
|
247
|
+
'checkbox': El.ElCheckbox,
|
|
248
248
|
'radio-group': El.ElRadioGroup,
|
|
249
|
-
radio: El.ElRadio,
|
|
249
|
+
'radio': El.ElRadio,
|
|
250
250
|
'date-picker': El.ElDatePicker,
|
|
251
251
|
'time-picker': El.ElTimePicker,
|
|
252
252
|
'time-select': El.ElTimeSelect,
|
|
253
253
|
'color-picker': El.ElColorPicker,
|
|
254
|
-
transfer: El.ElTransfer,
|
|
255
|
-
autocomplete: El.ElAutocomplete,
|
|
256
|
-
upload: El.ElUpload,
|
|
257
|
-
title: El.ElAlert
|
|
258
|
-
}
|
|
254
|
+
'transfer': El.ElTransfer,
|
|
255
|
+
'autocomplete': El.ElAutocomplete,
|
|
256
|
+
'upload': El.ElUpload,
|
|
257
|
+
'title': El.ElAlert
|
|
258
|
+
}
|
|
259
259
|
|
|
260
|
-
const formRef = ref<FormInstance>()
|
|
260
|
+
const formRef = ref<FormInstance>()
|
|
261
261
|
|
|
262
262
|
/** 获取占位文本 */
|
|
263
263
|
const getPlaceholder = (item: FormColumnItem) => {
|
|
264
|
-
if (!item.type) return undefined
|
|
264
|
+
if (!item.type) return undefined
|
|
265
265
|
if (['input', 'input-number', 'input-tag'].includes(item.type)) {
|
|
266
|
-
return `请输入${item.label}
|
|
266
|
+
return `请输入${item.label}`
|
|
267
267
|
}
|
|
268
268
|
if (['textarea'].includes(item.type)) {
|
|
269
|
-
return `请填写${item.label}
|
|
269
|
+
return `请填写${item.label}`
|
|
270
270
|
}
|
|
271
271
|
if (
|
|
272
272
|
[
|
|
@@ -278,16 +278,16 @@ const getPlaceholder = (item: FormColumnItem) => {
|
|
|
278
278
|
'input-search'
|
|
279
279
|
].includes(item.type)
|
|
280
280
|
) {
|
|
281
|
-
return `请选择${item.label}
|
|
281
|
+
return `请选择${item.label}`
|
|
282
282
|
}
|
|
283
283
|
if (['date-picker'].includes(item.type)) {
|
|
284
|
-
return
|
|
284
|
+
return `请选择日期`
|
|
285
285
|
}
|
|
286
286
|
if (['time-picker'].includes(item.type)) {
|
|
287
|
-
return
|
|
287
|
+
return `请选择时间`
|
|
288
288
|
}
|
|
289
|
-
return undefined
|
|
290
|
-
}
|
|
289
|
+
return undefined
|
|
290
|
+
}
|
|
291
291
|
|
|
292
292
|
/** 表单项校验规则 */
|
|
293
293
|
function getFormItemRules(item: FormColumnItem) {
|
|
@@ -295,7 +295,7 @@ function getFormItemRules(item: FormColumnItem) {
|
|
|
295
295
|
return [
|
|
296
296
|
{ required: true, message: `${item.label}为必填项` },
|
|
297
297
|
...(Array.isArray(item.rules) ? item.rules : [])
|
|
298
|
-
]
|
|
298
|
+
]
|
|
299
299
|
}
|
|
300
300
|
if (props.fc?.[item.field]?.required) {
|
|
301
301
|
return [
|
|
@@ -304,26 +304,26 @@ function getFormItemRules(item: FormColumnItem) {
|
|
|
304
304
|
message: `${item.label}为必填项`
|
|
305
305
|
},
|
|
306
306
|
...(Array.isArray(item.rules) ? item.rules : [])
|
|
307
|
-
]
|
|
307
|
+
]
|
|
308
308
|
}
|
|
309
|
-
return item.rules
|
|
309
|
+
return item.rules
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
/** 隐藏表单项 */
|
|
313
313
|
function isHide(item: FormColumnItem) {
|
|
314
|
-
if (typeof item.hide === 'boolean') return item.hide
|
|
314
|
+
if (typeof item.hide === 'boolean') return item.hide
|
|
315
315
|
if (typeof item.hide === 'function') {
|
|
316
|
-
return item.hide(props.modelValue)
|
|
316
|
+
return item.hide(props.modelValue)
|
|
317
317
|
}
|
|
318
|
-
if (props.fc?.[item.field]?.hidden) return true
|
|
319
|
-
if (item.hide === undefined) return false
|
|
318
|
+
if (props.fc?.[item.field]?.hidden) return true
|
|
319
|
+
if (item.hide === undefined) return false
|
|
320
320
|
}
|
|
321
321
|
|
|
322
322
|
/** 禁用表单项 */
|
|
323
323
|
function isDisabled(item: FormColumnItem) {
|
|
324
|
-
if (item?.props?.disabled !== undefined) return item?.props?.disabled
|
|
325
|
-
if (props.fc?.[item.field]?.disabled === true) return true
|
|
326
|
-
return false
|
|
324
|
+
if (item?.props?.disabled !== undefined) return item?.props?.disabled
|
|
325
|
+
if (props.fc?.[item.field]?.disabled === true) return true
|
|
326
|
+
return false
|
|
327
327
|
}
|
|
328
328
|
|
|
329
329
|
/** 表单数据更新 */
|
|
@@ -331,19 +331,19 @@ function updateModelValue(value: any, item: FormColumnItem) {
|
|
|
331
331
|
emit(
|
|
332
332
|
'update:modelValue',
|
|
333
333
|
Object.assign(props.modelValue, { [item.field]: value })
|
|
334
|
-
)
|
|
334
|
+
)
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
watch(
|
|
338
338
|
() => props.modelValue,
|
|
339
339
|
() => {
|
|
340
340
|
// eslint-disable-next-line no-console
|
|
341
|
-
console.log('form', toRaw(props.modelValue))
|
|
341
|
+
console.log('form', toRaw(props.modelValue))
|
|
342
342
|
},
|
|
343
343
|
{ deep: true }
|
|
344
|
-
)
|
|
344
|
+
)
|
|
345
345
|
|
|
346
|
-
defineExpose({ formRef })
|
|
346
|
+
defineExpose({ formRef })
|
|
347
347
|
</script>
|
|
348
348
|
|
|
349
349
|
<style lang="scss" scoped>
|