gi-component 0.0.7 → 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 +4 -50
- package/dist/index.es.js +39 -39
- 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 +47 -47
- package/packages/components/edit-table/src/type.ts +42 -63
- package/packages/components/form/index.ts +4 -4
- package/packages/components/form/src/form.vue +98 -97
- package/packages/components/form/src/type.ts +67 -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 +7 -7
- package/packages/components/tabs/index.ts +4 -4
- package/packages/components/tabs/src/tabs.vue +20 -20
- 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 +4 -4
- package/packages/utils/createSelectDialog.ts +28 -27
- package/packages/utils/index.ts +1 -1
|
@@ -22,56 +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
42
|
const COMP_MAP: Record<EditTableColumnItemType, any> = {
|
|
43
|
-
input: El.ElInput,
|
|
44
|
-
textarea: El.ElInput,
|
|
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,
|
|
62
|
+
'transfer': El.ElTransfer,
|
|
63
|
+
'autocomplete': El.ElAutocomplete,
|
|
64
|
+
'upload': El.ElUpload,
|
|
65
65
|
'input-search': InputSearch,
|
|
66
|
-
slot: undefined
|
|
67
|
-
}
|
|
66
|
+
'slot': undefined
|
|
67
|
+
}
|
|
68
68
|
|
|
69
|
-
const formRef = ref<FormInstance | null>()
|
|
69
|
+
const formRef = ref<FormInstance | null>()
|
|
70
70
|
|
|
71
71
|
/** 表单数据 */
|
|
72
|
-
const form = computed(() => ({ tableData: props.data }))
|
|
72
|
+
const form = computed(() => ({ tableData: props.data }))
|
|
73
73
|
|
|
74
|
-
const clearable = false
|
|
74
|
+
const clearable = false
|
|
75
75
|
/** 组件静态配置 */
|
|
76
76
|
const STATIC_PROPS = new Map([
|
|
77
77
|
['input', { clearable, maxlength: 20 }],
|
|
@@ -106,43 +106,43 @@ const STATIC_PROPS = new Map([
|
|
|
106
106
|
['autocomplete', {}],
|
|
107
107
|
['upload', {}],
|
|
108
108
|
['title', {}]
|
|
109
|
-
])
|
|
109
|
+
])
|
|
110
110
|
|
|
111
111
|
/** 获取占位文本 */
|
|
112
112
|
const getPlaceholder = (item: EditTableColumnItem) => {
|
|
113
|
-
if (!item.type) return undefined
|
|
113
|
+
if (!item.type) return undefined
|
|
114
114
|
if (['input', 'input-number', 'input-tag'].includes(item.type)) {
|
|
115
|
-
return `请输入${item.label}
|
|
115
|
+
return `请输入${item.label}`
|
|
116
116
|
}
|
|
117
117
|
if (['textarea'].includes(item.type)) {
|
|
118
|
-
return `请填写${item.label}
|
|
118
|
+
return `请填写${item.label}`
|
|
119
119
|
}
|
|
120
120
|
if (
|
|
121
121
|
['select', 'select-v2', 'tree-select', 'cascader', 'time-select', 'input-search'].includes(
|
|
122
122
|
item.type
|
|
123
123
|
)
|
|
124
124
|
) {
|
|
125
|
-
return `请选择${item.label}
|
|
125
|
+
return `请选择${item.label}`
|
|
126
126
|
}
|
|
127
127
|
if (['date-picker'].includes(item.type)) {
|
|
128
|
-
return
|
|
128
|
+
return `请选择日期`
|
|
129
129
|
}
|
|
130
130
|
if (['time-picker'].includes(item.type)) {
|
|
131
|
-
return
|
|
131
|
+
return `请选择时间`
|
|
132
132
|
}
|
|
133
|
-
return undefined
|
|
134
|
-
}
|
|
133
|
+
return undefined
|
|
134
|
+
}
|
|
135
135
|
|
|
136
136
|
// 组件的默认props配置
|
|
137
137
|
function getComponentBindProps(item: EditTableColumnItem) {
|
|
138
138
|
// 获取默认配置
|
|
139
|
-
const defaultProps: any = STATIC_PROPS.get(item.type || '') || {}
|
|
140
|
-
defaultProps.placeholder = getPlaceholder(item)
|
|
139
|
+
const defaultProps: any = STATIC_PROPS.get(item.type || '') || {}
|
|
140
|
+
defaultProps.placeholder = getPlaceholder(item)
|
|
141
141
|
if (item.type === 'date-picker') {
|
|
142
|
-
defaultProps.valueFormat = 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?.componentProps || {}) }
|
|
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,72 +1,51 @@
|
|
|
1
|
-
import type * as El from 'element-plus'
|
|
2
|
-
import type { InputSearchInstance } from '../../input-search'
|
|
1
|
+
import type * as El from 'element-plus'
|
|
3
2
|
import type { MergeMultiple } from '../../../types/tool'
|
|
3
|
+
import type { InputSearchInstance } from '../../input-search'
|
|
4
4
|
|
|
5
|
-
export type EditTableColumnItemType
|
|
6
|
-
| 'input'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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'
|
|
30
30
|
|
|
31
31
|
export interface EditTableColumnItem {
|
|
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
|
|
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
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export type EditTableColumnItemProps = MergeMultiple<[El.InputProps,
|
|
45
|
-
El.InputNumberProps,
|
|
46
|
-
El.InputTagProps,
|
|
47
|
-
El.SelectProps,
|
|
48
|
-
El.SelectV2Props,
|
|
49
|
-
El.TreeInstance['$props'],
|
|
50
|
-
El.CascaderProps,
|
|
51
|
-
El.SliderProps,
|
|
52
|
-
El.SwitchProps,
|
|
53
|
-
El.RateProps,
|
|
54
|
-
El.CheckboxGroupProps,
|
|
55
|
-
El.CheckboxProps,
|
|
56
|
-
El.RadioGroupProps,
|
|
57
|
-
El.RadioProps,
|
|
58
|
-
El.DatePickerProps,
|
|
59
|
-
El.TimePickerDefaultProps,
|
|
60
|
-
El.TimeSelectProps,
|
|
61
|
-
El.ColorPickerProps,
|
|
62
|
-
El.TransferProps,
|
|
63
|
-
El.AutocompleteProps,
|
|
64
|
-
El.UploadProps,
|
|
65
|
-
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']]>
|
|
66
45
|
|
|
67
46
|
export interface EditTableProps {
|
|
68
|
-
rowKey?: string
|
|
69
|
-
data?: any[]
|
|
70
|
-
columns?: EditTableColumnItem[]
|
|
71
|
-
cellDisabled?: any
|
|
47
|
+
rowKey?: string
|
|
48
|
+
data?: any[]
|
|
49
|
+
columns?: EditTableColumnItem[]
|
|
50
|
+
cellDisabled?: any
|
|
72
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,59 +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 = 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'
|
|
201
202
|
}
|
|
202
203
|
// 如果配置了dictCode且存在对应的字典数据,设置options
|
|
203
204
|
if (item.dictCode && dictData.value[item.dictCode]) {
|
|
204
|
-
defaultProps.options = dictData.value[item.dictCode]
|
|
205
|
+
defaultProps.options = dictData.value[item.dictCode]
|
|
205
206
|
}
|
|
206
207
|
// 合并默认配置和自定义配置
|
|
207
|
-
return { ...defaultProps, ...(item?.props || {}) }
|
|
208
|
+
return { ...defaultProps, ...(item?.props || {}) }
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
const formProps = computed(() => {
|
|
@@ -218,54 +219,54 @@ const formProps = computed(() => {
|
|
|
218
219
|
searchText: undefined,
|
|
219
220
|
hideFoldBtn: undefined,
|
|
220
221
|
defaultCollapsed: undefined
|
|
221
|
-
}
|
|
222
|
-
})
|
|
222
|
+
}
|
|
223
|
+
})
|
|
223
224
|
|
|
224
225
|
const getClass = computed(() => {
|
|
225
|
-
const arr: string[] = [b('form')]
|
|
226
|
+
const arr: string[] = [b('form')]
|
|
226
227
|
if (props.search) {
|
|
227
|
-
arr.push(b('form--search'))
|
|
228
|
+
arr.push(b('form--search'))
|
|
228
229
|
}
|
|
229
|
-
return arr.join(' ')
|
|
230
|
-
})
|
|
230
|
+
return arr.join(' ')
|
|
231
|
+
})
|
|
231
232
|
|
|
232
233
|
const CompMap: Record<Exclude<FormColumnType, 'slot'>, any> = {
|
|
233
|
-
input: El.ElInput,
|
|
234
|
-
textarea: El.ElInput,
|
|
234
|
+
'input': El.ElInput,
|
|
235
|
+
'textarea': El.ElInput,
|
|
235
236
|
'input-number': El.ElInputNumber,
|
|
236
237
|
'input-tag': El.ElInputTag,
|
|
237
238
|
'input-search': InputSearch,
|
|
238
|
-
select: El.ElSelect,
|
|
239
|
+
'select': El.ElSelect,
|
|
239
240
|
'select-v2': El.ElSelectV2,
|
|
240
241
|
'tree-select': El.ElTreeSelect,
|
|
241
|
-
cascader: El.ElCascader,
|
|
242
|
-
slider: El.ElSlider,
|
|
243
|
-
switch: El.ElSwitch,
|
|
244
|
-
rate: El.ElRate,
|
|
242
|
+
'cascader': El.ElCascader,
|
|
243
|
+
'slider': El.ElSlider,
|
|
244
|
+
'switch': El.ElSwitch,
|
|
245
|
+
'rate': El.ElRate,
|
|
245
246
|
'checkbox-group': El.ElCheckboxGroup,
|
|
246
|
-
checkbox: El.ElCheckbox,
|
|
247
|
+
'checkbox': El.ElCheckbox,
|
|
247
248
|
'radio-group': El.ElRadioGroup,
|
|
248
|
-
radio: El.ElRadio,
|
|
249
|
+
'radio': El.ElRadio,
|
|
249
250
|
'date-picker': El.ElDatePicker,
|
|
250
251
|
'time-picker': El.ElTimePicker,
|
|
251
252
|
'time-select': El.ElTimeSelect,
|
|
252
253
|
'color-picker': El.ElColorPicker,
|
|
253
|
-
transfer: El.ElTransfer,
|
|
254
|
-
autocomplete: El.ElAutocomplete,
|
|
255
|
-
upload: El.ElUpload,
|
|
256
|
-
title: El.ElAlert
|
|
257
|
-
}
|
|
254
|
+
'transfer': El.ElTransfer,
|
|
255
|
+
'autocomplete': El.ElAutocomplete,
|
|
256
|
+
'upload': El.ElUpload,
|
|
257
|
+
'title': El.ElAlert
|
|
258
|
+
}
|
|
258
259
|
|
|
259
|
-
const formRef = ref<FormInstance>()
|
|
260
|
+
const formRef = ref<FormInstance>()
|
|
260
261
|
|
|
261
262
|
/** 获取占位文本 */
|
|
262
263
|
const getPlaceholder = (item: FormColumnItem) => {
|
|
263
|
-
if (!item.type) return undefined
|
|
264
|
+
if (!item.type) return undefined
|
|
264
265
|
if (['input', 'input-number', 'input-tag'].includes(item.type)) {
|
|
265
|
-
return `请输入${item.label}
|
|
266
|
+
return `请输入${item.label}`
|
|
266
267
|
}
|
|
267
268
|
if (['textarea'].includes(item.type)) {
|
|
268
|
-
return `请填写${item.label}
|
|
269
|
+
return `请填写${item.label}`
|
|
269
270
|
}
|
|
270
271
|
if (
|
|
271
272
|
[
|
|
@@ -277,16 +278,16 @@ const getPlaceholder = (item: FormColumnItem) => {
|
|
|
277
278
|
'input-search'
|
|
278
279
|
].includes(item.type)
|
|
279
280
|
) {
|
|
280
|
-
return `请选择${item.label}
|
|
281
|
+
return `请选择${item.label}`
|
|
281
282
|
}
|
|
282
283
|
if (['date-picker'].includes(item.type)) {
|
|
283
|
-
return
|
|
284
|
+
return `请选择日期`
|
|
284
285
|
}
|
|
285
286
|
if (['time-picker'].includes(item.type)) {
|
|
286
|
-
return
|
|
287
|
+
return `请选择时间`
|
|
287
288
|
}
|
|
288
|
-
return undefined
|
|
289
|
-
}
|
|
289
|
+
return undefined
|
|
290
|
+
}
|
|
290
291
|
|
|
291
292
|
/** 表单项校验规则 */
|
|
292
293
|
function getFormItemRules(item: FormColumnItem) {
|
|
@@ -294,7 +295,7 @@ function getFormItemRules(item: FormColumnItem) {
|
|
|
294
295
|
return [
|
|
295
296
|
{ required: true, message: `${item.label}为必填项` },
|
|
296
297
|
...(Array.isArray(item.rules) ? item.rules : [])
|
|
297
|
-
]
|
|
298
|
+
]
|
|
298
299
|
}
|
|
299
300
|
if (props.fc?.[item.field]?.required) {
|
|
300
301
|
return [
|
|
@@ -303,26 +304,26 @@ function getFormItemRules(item: FormColumnItem) {
|
|
|
303
304
|
message: `${item.label}为必填项`
|
|
304
305
|
},
|
|
305
306
|
...(Array.isArray(item.rules) ? item.rules : [])
|
|
306
|
-
]
|
|
307
|
+
]
|
|
307
308
|
}
|
|
308
|
-
return item.rules
|
|
309
|
+
return item.rules
|
|
309
310
|
}
|
|
310
311
|
|
|
311
312
|
/** 隐藏表单项 */
|
|
312
313
|
function isHide(item: FormColumnItem) {
|
|
313
|
-
if (typeof item.hide === 'boolean') return item.hide
|
|
314
|
+
if (typeof item.hide === 'boolean') return item.hide
|
|
314
315
|
if (typeof item.hide === 'function') {
|
|
315
|
-
return item.hide(props.modelValue)
|
|
316
|
+
return item.hide(props.modelValue)
|
|
316
317
|
}
|
|
317
|
-
if (props.fc?.[item.field]?.hidden) return true
|
|
318
|
-
if (item.hide === undefined) return false
|
|
318
|
+
if (props.fc?.[item.field]?.hidden) return true
|
|
319
|
+
if (item.hide === undefined) return false
|
|
319
320
|
}
|
|
320
321
|
|
|
321
322
|
/** 禁用表单项 */
|
|
322
323
|
function isDisabled(item: FormColumnItem) {
|
|
323
|
-
if (item?.props?.disabled !== undefined) return item?.props?.disabled
|
|
324
|
-
if (props.fc?.[item.field]?.disabled === true) return true
|
|
325
|
-
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
|
|
326
327
|
}
|
|
327
328
|
|
|
328
329
|
/** 表单数据更新 */
|
|
@@ -330,19 +331,19 @@ function updateModelValue(value: any, item: FormColumnItem) {
|
|
|
330
331
|
emit(
|
|
331
332
|
'update:modelValue',
|
|
332
333
|
Object.assign(props.modelValue, { [item.field]: value })
|
|
333
|
-
)
|
|
334
|
+
)
|
|
334
335
|
}
|
|
335
336
|
|
|
336
337
|
watch(
|
|
337
338
|
() => props.modelValue,
|
|
338
339
|
() => {
|
|
339
340
|
// eslint-disable-next-line no-console
|
|
340
|
-
console.log('form', toRaw(props.modelValue))
|
|
341
|
+
console.log('form', toRaw(props.modelValue))
|
|
341
342
|
},
|
|
342
343
|
{ deep: true }
|
|
343
|
-
)
|
|
344
|
+
)
|
|
344
345
|
|
|
345
|
-
defineExpose({ formRef })
|
|
346
|
+
defineExpose({ formRef })
|
|
346
347
|
</script>
|
|
347
348
|
|
|
348
349
|
<style lang="scss" scoped>
|