@dt-frames/ui 1.0.13 → 1.0.17
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 +20 -21
- package/es/components/curd/src/components/props.d.ts +2 -1
- package/es/components/curd/src/hooks/useCurd.d.ts +1 -0
- package/es/components/curd/src/types/curd.type.d.ts +2 -2
- package/es/components/forms/src/components/formButton.d.ts +1 -2
- package/es/components/forms/src/components/formIcon.d.ts +15 -15
- package/es/components/forms/src/hooks/helper.d.ts +2 -0
- package/es/components/forms/src/hooks/useFormActions.d.ts +2 -2
- package/es/components/forms/src/index.d.ts +2 -3
- package/es/components/forms/src/types/form.type.d.ts +3 -17
- 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 +1 -1
- package/es/components/modal/src/index.d.ts +15 -15
- package/es/components/modal/src/props.d.ts +1 -1
- package/es/components/source/src/hooks/useFetch.d.ts +1 -1
- package/es/components/table/src/components/editable/EditTableCell.d.ts +3 -0
- package/es/components/table/src/components/editable/index.d.ts +1 -1
- package/es/components/table/src/index.d.ts +6 -3
- package/es/components/table/src/props.d.ts +1 -2
- package/es/components/table/src/types/table.type.d.ts +2 -0
- package/es/components/tree/src/props.d.ts +8 -1
- package/es/components/upload/src/upload.d.ts +6 -3
- package/es/index.js +196 -39
- package/es/style/components/icons/index.less +1 -1
- package/es/style/components/table/index.less +4 -0
- package/package.json +1 -10
- package/vite.config.js +10 -0
- package/es/components/upload/src/index.d.ts +0 -2811
- package/src/assets/data/icons/actions.ts +0 -427
- package/src/assets/data/icons/code.ts +0 -10
- package/src/assets/data/icons/commuticate.ts +0 -190
- package/src/assets/data/icons/currency.ts +0 -46
- package/src/assets/data/icons/devices.ts +0 -128
- package/src/assets/data/icons/edit.ts +0 -165
- package/src/assets/data/icons/file.ts +0 -104
- package/src/assets/data/icons/math.ts +0 -53
- package/src/assets/data/icons/message.ts +0 -75
- package/src/assets/data/icons/navigate.ts +0 -181
- package/src/assets/data/icons/other.ts +0 -333
- package/src/assets/data/icons.ts +0 -58
- package/src/assets/imgs/header/avatar.png +0 -0
- package/src/assets/imgs/logo/logo.png +0 -0
- package/src/assets/locales/en_US.json +0 -3
- package/src/assets/locales/zh_CN.json +0 -3
- package/src/assets/style/index.less +0 -10
- package/src/assets/style/reset.less +0 -17
- package/src/components/container/index.less +0 -85
- package/src/components/container/index.ts +0 -8
- package/src/components/container/src/bar.ts +0 -107
- package/src/components/container/src/lazy-container.vue +0 -9
- package/src/components/container/src/scroll-bar.vue +0 -117
- package/src/components/container/src/scroll-container.vue +0 -61
- package/src/components/curd/index.ts +0 -5
- package/src/components/curd/src/components/dialog.vue +0 -73
- package/src/components/curd/src/components/props.ts +0 -32
- package/src/components/curd/src/hooks/useCurd.tsx +0 -87
- package/src/components/curd/src/types/curd.type.ts +0 -32
- package/src/components/excel/index.ts +0 -6
- package/src/components/excel/src/export2Excel.ts +0 -44
- package/src/components/forms/index.less +0 -107
- package/src/components/forms/index.ts +0 -11
- package/src/components/forms/src/componentMap.ts +0 -46
- package/src/components/forms/src/components/formButton.vue +0 -150
- package/src/components/forms/src/components/formIcon.vue +0 -51
- package/src/components/forms/src/components/formInputUseDialog.vue +0 -43
- package/src/components/forms/src/components/formItem.vue +0 -420
- package/src/components/forms/src/components/radioButton.vue +0 -58
- package/src/components/forms/src/const/form.const.ts +0 -7
- package/src/components/forms/src/hooks/helper.ts +0 -70
- package/src/components/forms/src/hooks/useForm.ts +0 -130
- package/src/components/forms/src/hooks/useFormActions.ts +0 -63
- package/src/components/forms/src/hooks/useFormEvents.ts +0 -248
- package/src/components/forms/src/hooks/useFormValue.ts +0 -49
- package/src/components/forms/src/hooks/useFormValues.ts +0 -131
- package/src/components/forms/src/hooks/useLabelWidth.ts +0 -57
- package/src/components/forms/src/index.vue +0 -310
- package/src/components/forms/src/prop.ts +0 -80
- package/src/components/forms/src/types/form.type.ts +0 -275
- package/src/components/icons/index.less +0 -101
- package/src/components/icons/index.ts +0 -7
- package/src/components/icons/src/pick-icon.vue +0 -119
- package/src/components/icons/src/svg-icon.vue +0 -117
- package/src/components/iframe/index.less +0 -3
- package/src/components/iframe/index.ts +0 -5
- package/src/components/iframe/src/index.less +0 -3
- package/src/components/iframe/src/index.vue +0 -38
- package/src/components/index.ts +0 -53
- package/src/components/modal/index.less +0 -60
- package/src/components/modal/index.ts +0 -8
- package/src/components/modal/src/components/close-icon.vue +0 -46
- package/src/components/modal/src/components/modal-wrap.vue +0 -128
- package/src/components/modal/src/components/modal.tsx +0 -30
- package/src/components/modal/src/components/modalFooter.vue +0 -46
- package/src/components/modal/src/hooks/useDrag.ts +0 -107
- package/src/components/modal/src/hooks/useFullScreen.ts +0 -29
- package/src/components/modal/src/hooks/useModal.ts +0 -200
- package/src/components/modal/src/index.vue +0 -184
- package/src/components/modal/src/props.ts +0 -44
- package/src/components/modal/src/types/modal.type.ts +0 -30
- package/src/components/router/base-router.vue +0 -11
- package/src/components/router/index.ts +0 -3
- package/src/components/source/index.ts +0 -1
- package/src/components/source/src/hooks/useFetch.ts +0 -42
- package/src/components/source/src/hooks/usePage.ts +0 -3
- package/src/components/source/src/hooks/useSource.ts +0 -214
- package/src/components/source/src/index.ts +0 -5
- package/src/components/source/src/types/source.type.ts +0 -58
- package/src/components/source/src/types/table.type.ts +0 -8
- package/src/components/table/index.less +0 -179
- package/src/components/table/index.ts +0 -7
- package/src/components/table/src/components/TableActions.vue +0 -108
- package/src/components/table/src/components/TableHeader.vue +0 -78
- package/src/components/table/src/components/TableRender.vue +0 -76
- package/src/components/table/src/components/editable/CellComponent.ts +0 -57
- package/src/components/table/src/components/editable/EditTableCell.vue +0 -181
- package/src/components/table/src/components/editable/componentMap.ts +0 -18
- package/src/components/table/src/components/editable/index.ts +0 -58
- package/src/components/table/src/components/setting/Column.vue +0 -354
- package/src/components/table/src/components/setting/Download.vue +0 -55
- package/src/components/table/src/components/setting/Fullscreen.vue +0 -43
- package/src/components/table/src/components/setting/Size.vue +0 -42
- package/src/components/table/src/components/setting/index.vue +0 -64
- package/src/components/table/src/const.ts +0 -13
- package/src/components/table/src/hooks/useColumns.ts +0 -326
- package/src/components/table/src/hooks/useCustomRow.ts +0 -86
- package/src/components/table/src/hooks/useDataSource.ts +0 -97
- package/src/components/table/src/hooks/useHeaderCode.ts +0 -89
- package/src/components/table/src/hooks/useLoading.ts +0 -29
- package/src/components/table/src/hooks/usePagination.ts +0 -76
- package/src/components/table/src/hooks/useRowSelection.ts +0 -145
- package/src/components/table/src/hooks/useRows.ts +0 -30
- package/src/components/table/src/hooks/useTable.ts +0 -90
- package/src/components/table/src/hooks/useTableHeader.ts +0 -48
- package/src/components/table/src/hooks/useTableInstance.ts +0 -29
- package/src/components/table/src/hooks/useTableScroll.ts +0 -229
- package/src/components/table/src/index.vue +0 -212
- package/src/components/table/src/props.ts +0 -160
- package/src/components/table/src/types/table.type.ts +0 -160
- package/src/components/table/src/types/tableHeader.type.ts +0 -27
- package/src/components/tree/index.less +0 -41
- package/src/components/tree/index.ts +0 -5
- package/src/components/tree/src/components/TreeHeader.vue +0 -97
- package/src/components/tree/src/hooks/useTree.ts +0 -239
- package/src/components/tree/src/index.vue +0 -392
- package/src/components/tree/src/props.ts +0 -133
- package/src/components/tree/src/type/tree.ts +0 -105
- package/src/components/tree/src/utils/tree.ts +0 -73
- package/src/components/type.ts +0 -0
- package/src/components/upload/index.less +0 -35
- package/src/components/upload/index.ts +0 -5
- package/src/components/upload/src/helper.ts +0 -60
- package/src/components/upload/src/props.ts +0 -51
- package/src/components/upload/src/upload.vue +0 -191
- package/src/directives/icon.ts +0 -36
- package/src/directives/index.ts +0 -26
- package/src/directives/permission.ts +0 -20
- package/src/global.d.ts +0 -8
- package/src/index.ts +0 -4
- package/src/theme/content/index.vue +0 -37
- package/src/theme/feature/back-top.vue +0 -11
- package/src/theme/feature/index.vue +0 -7
- package/src/theme/footer/index.less +0 -16
- package/src/theme/footer/index.vue +0 -24
- package/src/theme/header/components/bread-crumb.vue +0 -26
- package/src/theme/header/components/fullscreen.vue +0 -12
- package/src/theme/header/components/handler.ts +0 -81
- package/src/theme/header/components/index.ts +0 -21
- package/src/theme/header/components/lang-picker.vue +0 -36
- package/src/theme/header/components/logo.vue +0 -35
- package/src/theme/header/components/menu-search.vue +0 -62
- package/src/theme/header/components/notify.vue +0 -22
- package/src/theme/header/components/setting-theme.vue +0 -123
- package/src/theme/header/components/theme-drawer/enum.ts +0 -12
- package/src/theme/header/components/theme-drawer/feature.vue +0 -75
- package/src/theme/header/components/theme-drawer/index.ts +0 -7
- package/src/theme/header/components/theme-drawer/menu-type.vue +0 -40
- package/src/theme/header/components/theme-drawer/select-item.vue +0 -46
- package/src/theme/header/components/theme-drawer/switch-item.vue +0 -39
- package/src/theme/header/components/theme-drawer/theme-color.vue +0 -26
- package/src/theme/header/components/trigger.vue +0 -14
- package/src/theme/header/components/user-info.vue +0 -60
- package/src/theme/header/const/index.ts +0 -40
- package/src/theme/header/helper/menu-tree.ts +0 -64
- package/src/theme/header/index.less +0 -442
- package/src/theme/header/index.ts +0 -0
- package/src/theme/header/index.vue +0 -96
- package/src/theme/header/multiple-header.vue +0 -67
- package/src/theme/header/set-theme.less +0 -68
- package/src/theme/index.ts +0 -3
- package/src/theme/sider/components/basic-menu/basic-menu-item.vue +0 -14
- package/src/theme/sider/components/basic-menu/basic-menu.vue +0 -122
- package/src/theme/sider/components/basic-menu/basic-sub-menu-item.vue +0 -46
- package/src/theme/sider/components/basic-menu/menu-item-content.vue +0 -13
- package/src/theme/sider/components/drag-bar.vue +0 -26
- package/src/theme/sider/components/layout-menu.vue +0 -132
- package/src/theme/sider/components/props.ts +0 -97
- package/src/theme/sider/components/sider-trigger.vue +0 -24
- package/src/theme/sider/helper/sider.ts +0 -52
- package/src/theme/sider/helper/split-menu.ts +0 -146
- package/src/theme/sider/hooks/useDragLine.ts +0 -86
- package/src/theme/sider/hooks/useOpenKeys.ts +0 -57
- package/src/theme/sider/index.less +0 -203
- package/src/theme/sider/index.vue +0 -88
- package/src/theme/tabs/components/TabContent.vue +0 -36
- package/src/theme/tabs/components/TabRedo.vue +0 -18
- package/src/theme/tabs/hooks/useMultifyTabs.ts +0 -96
- package/src/theme/tabs/hooks/useTabDropdown.ts +0 -89
- package/src/theme/tabs/index.less +0 -165
- package/src/theme/tabs/index.vue +0 -98
- package/src/theme/tabs/types/tabs.type.ts +0 -8
- package/src/theme/theme.less +0 -67
- package/src/theme/theme.vue +0 -90
- package/src/theme/transition.less +0 -99
|
@@ -1,420 +0,0 @@
|
|
|
1
|
-
<script lang="tsx">
|
|
2
|
-
import { defineComponent, PropType, Ref, toRefs, unref, computed } from "vue"
|
|
3
|
-
import { Col, Tooltip, Divider, Form, FormItem } from 'ant-design-vue'
|
|
4
|
-
import { upperFirst, cloneDeep } from 'lodash-es'
|
|
5
|
-
import { isFunction, isBoolean, isNull, Recordable, useSlots, useAppStore, isString, isArray, error } from "@dt-frames/core"
|
|
6
|
-
import type { ValidationRule } from 'ant-design-vue/lib/form/Form'
|
|
7
|
-
|
|
8
|
-
import { useLabelWidth } from "../hooks/useLabelWidth"
|
|
9
|
-
import { componentMap } from '../componentMap'
|
|
10
|
-
import { createPlaceholder, setComponentRuleType } from '../hooks/helper'
|
|
11
|
-
import { FormSchema, FormProps, FormCallBackParams, FormActionType } from '../types/form.type'
|
|
12
|
-
import { FormItemProps } from "../prop"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export default defineComponent({
|
|
16
|
-
name: 'FormItem',
|
|
17
|
-
inheritAttrs: false,
|
|
18
|
-
props: FormItemProps,
|
|
19
|
-
setup( props, { emit, slots } ) {
|
|
20
|
-
// 获取指定的slot
|
|
21
|
-
const { getSlot } = useSlots()
|
|
22
|
-
// 获取全局配置
|
|
23
|
-
const { appConf } = useAppStore()
|
|
24
|
-
|
|
25
|
-
const { schema, formProps } = toRefs(props) as {
|
|
26
|
-
schema: Ref<FormSchema>
|
|
27
|
-
formProps: Ref<FormProps>
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 计算每个条目的props
|
|
31
|
-
const getValues = computed(() => {
|
|
32
|
-
const { defaultValues, formModel, schema } = props;
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
name: (schema as FormSchema).name,
|
|
36
|
-
model: formModel,
|
|
37
|
-
values: {
|
|
38
|
-
...defaultValues,
|
|
39
|
-
...formModel
|
|
40
|
-
},
|
|
41
|
-
schema: schema
|
|
42
|
-
} as FormCallBackParams
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
// 是否显示当前条目
|
|
46
|
-
const getShow = computed(() => {
|
|
47
|
-
const { show = true, isAdvanced = true } = props.schema as FormSchema
|
|
48
|
-
|
|
49
|
-
// 是否处于收缩状态
|
|
50
|
-
if( !isAdvanced ) {
|
|
51
|
-
return false
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if( isFunction(show) ) {
|
|
55
|
-
return show(unref(getValues))
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return show
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
// 设置表单绑定的特殊属性,如前后缀、禁用启用、日期格式等
|
|
62
|
-
const getComponentProps = computed(() => {
|
|
63
|
-
const { schema, formModel, formActionType } = props
|
|
64
|
-
let { props: cProps = {} } = schema as FormSchema
|
|
65
|
-
|
|
66
|
-
if (isFunction(cProps)) {
|
|
67
|
-
cProps = cProps( { schema, formModel, formActionType } ) ?? {}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if ((schema as FormSchema).component === 'Divider') {
|
|
71
|
-
cProps = Object.assign({ type: 'horizontal' }, cProps, {
|
|
72
|
-
orientation: 'left',
|
|
73
|
-
plain: true,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return cProps as Recordable
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 动态渲染单个条目
|
|
83
|
-
* 支持的类型参照 ../types/form.type.ts 中 ComponentType
|
|
84
|
-
*/
|
|
85
|
-
function renderItem() {
|
|
86
|
-
const { component, props: cProps, slot, render, name, colon = appConf.ui.form.colon, suffix } = props.schema as FormSchema
|
|
87
|
-
|
|
88
|
-
// 计算label的属性
|
|
89
|
-
const { labelCol, wrapperCol } = unref( useLabelWidth( schema, formProps ) )
|
|
90
|
-
|
|
91
|
-
if( component === 'Divider' ) {
|
|
92
|
-
return (
|
|
93
|
-
<Col span={24}>
|
|
94
|
-
<Divider {...unref(cProps)}>{ renderLabel() }</Divider>
|
|
95
|
-
</Col>
|
|
96
|
-
)
|
|
97
|
-
} else {
|
|
98
|
-
const getContent = () => {
|
|
99
|
-
let value = unref(getValues)
|
|
100
|
-
|
|
101
|
-
let _con = slot
|
|
102
|
-
? getSlot(slots, slot, value)
|
|
103
|
-
: render
|
|
104
|
-
? render(value)
|
|
105
|
-
: renderFormItem()
|
|
106
|
-
|
|
107
|
-
return (component === 'InputGroup' || component === 'Icon')
|
|
108
|
-
? (
|
|
109
|
-
<FormItem rules = { handleRules() } class="M0">{ _con }</FormItem>
|
|
110
|
-
)
|
|
111
|
-
: _con
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const getSuffix = () => {
|
|
115
|
-
return isFunction( suffix ) ? suffix(unref(getValues)) : suffix
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return (
|
|
119
|
-
<Form.Item
|
|
120
|
-
name = { name }
|
|
121
|
-
colon = { colon }
|
|
122
|
-
class = {{ 'suffix-item': !!suffix }}
|
|
123
|
-
label = { renderLabel() }
|
|
124
|
-
rules = { handleRules() }
|
|
125
|
-
labelCol = { labelCol }
|
|
126
|
-
wrapperCol = { wrapperCol }
|
|
127
|
-
>
|
|
128
|
-
<div style="display:flex">
|
|
129
|
-
<div style="flex:1;">{ getContent() }</div>
|
|
130
|
-
{!!suffix && <span class="suffix">{getSuffix()}</span>}
|
|
131
|
-
</div>
|
|
132
|
-
</Form.Item>
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* 渲染Label标签元素
|
|
140
|
-
*/
|
|
141
|
-
function renderLabel() {
|
|
142
|
-
const { label, toolTip, subLabel, toolTipProps } = props.schema as FormSchema
|
|
143
|
-
|
|
144
|
-
const renderLabel
|
|
145
|
-
= subLabel
|
|
146
|
-
? ( <span> {label} <span class="text-secondary">({subLabel})</span></span> )
|
|
147
|
-
: ( label )
|
|
148
|
-
|
|
149
|
-
// 判断是否需要显示tooltips
|
|
150
|
-
const _toolTip = isFunction(toolTip) ? toolTip( unref(getValues) ) : toolTip
|
|
151
|
-
|
|
152
|
-
return _toolTip
|
|
153
|
-
? (
|
|
154
|
-
<span>
|
|
155
|
-
{ renderLabel }
|
|
156
|
-
<Tooltip v-bind={ toolTipProps }>{ _toolTip }</Tooltip>
|
|
157
|
-
</span>
|
|
158
|
-
)
|
|
159
|
-
: renderLabel
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* 渲染表单元素
|
|
164
|
-
*/
|
|
165
|
-
function renderFormItem() {
|
|
166
|
-
const { schema, formModel, formActionType } = props
|
|
167
|
-
const { component, name, changeEvent = 'change', valueField, renderComponent, props: sProps } = props.schema as FormSchema
|
|
168
|
-
|
|
169
|
-
const isCheck = component && ['Switch', 'Checkbox'].includes(component)
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* 监听表单事件,默认是change
|
|
173
|
-
*/
|
|
174
|
-
const eventKey = `on${upperFirst(changeEvent)}`
|
|
175
|
-
// 绑定事件
|
|
176
|
-
const _sProps = isFunction( sProps )
|
|
177
|
-
? sProps({ schema, formModel, formActionType })
|
|
178
|
-
: sProps
|
|
179
|
-
|
|
180
|
-
// 绑定onChange事件
|
|
181
|
-
const on: {
|
|
182
|
-
[key: string]: ( ...args: Array<any> ) => void
|
|
183
|
-
} = {
|
|
184
|
-
[ eventKey ]: ( ...args: Array<any> ) => {
|
|
185
|
-
const [e] = args
|
|
186
|
-
|
|
187
|
-
const target = e ? e.target : null
|
|
188
|
-
const value = target ? (isCheck ? target.checked : target.value) : e
|
|
189
|
-
|
|
190
|
-
if( isString( name ) ) {
|
|
191
|
-
props.setFormModel(name, value)
|
|
192
|
-
} else if( isArray( name ) ) {
|
|
193
|
-
name.forEach( key => {
|
|
194
|
-
props.setFormModel(key, value)
|
|
195
|
-
} )
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if( _sProps && _sProps[eventKey] ) _sProps[eventKey](...args, props)
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// 监听其它事件
|
|
203
|
-
for(let it in _sProps) {
|
|
204
|
-
if( it.startsWith('on') && it !== eventKey ) {
|
|
205
|
-
on[it] = ( ...args: Array<any> ) => {
|
|
206
|
-
_sProps[it]( ...args, props )
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* 设置表单绑定的属性
|
|
213
|
-
*/
|
|
214
|
-
const { size } = props.formProps as FormProps
|
|
215
|
-
|
|
216
|
-
// 设置表单禁用启用
|
|
217
|
-
const getDisable = computed(() => {
|
|
218
|
-
const { disabled: gDisabled } = props.formProps as FormProps
|
|
219
|
-
const { dynamicDisabled } = props.schema as FormSchema
|
|
220
|
-
const { disabled: itemDisabled = false } = unref( getComponentProps )
|
|
221
|
-
|
|
222
|
-
let disabled = !!gDisabled || itemDisabled
|
|
223
|
-
|
|
224
|
-
if (isBoolean(dynamicDisabled)) disabled = dynamicDisabled
|
|
225
|
-
if (isFunction(dynamicDisabled)) disabled = dynamicDisabled(unref(getValues))
|
|
226
|
-
|
|
227
|
-
return disabled
|
|
228
|
-
})
|
|
229
|
-
|
|
230
|
-
const { enterToSearch = appConf.ui.form.enterToSearch, onSearch, mode } = props.formProps as FormProps
|
|
231
|
-
|
|
232
|
-
const itemProps: Recordable = {
|
|
233
|
-
allowClear: appConf.ui.form.allowClear,
|
|
234
|
-
getPopupContainer: (trigger: Element) => trigger.parentNode,
|
|
235
|
-
size: size || appConf.ui.form.size,
|
|
236
|
-
...unref(getComponentProps),
|
|
237
|
-
disabled: unref(getDisable),
|
|
238
|
-
onPressEnter: (mode === 'search' && enterToSearch) ? onSearch : () => { }
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// 设置表单占位符,注意:RangePicker是一个数组
|
|
242
|
-
if( !itemProps.disabled && component !== 'RangePicker' ) {
|
|
243
|
-
itemProps.placeholder = unref(getComponentProps)?.placeholder || createPlaceholder( component )
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// 处理默认值
|
|
247
|
-
if( ['DatePicker', 'MonthPicker', 'RangePicker'].includes(component) ) {
|
|
248
|
-
itemProps.defaultValue = props.formModel[ name as string ]
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
itemProps.codeName = name
|
|
252
|
-
itemProps.formValues = unref(getValues)
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* 定义表单绑定的值v-bind:value
|
|
256
|
-
*/
|
|
257
|
-
const bindValue: Recordable = {
|
|
258
|
-
[valueField || (isCheck ? 'checked' : 'value')]: props.formModel[ name as string ]
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* 所有属性汇总,包括方法、属性及值的绑定
|
|
263
|
-
*/
|
|
264
|
-
let compAttr: Recordable = {
|
|
265
|
-
...itemProps,
|
|
266
|
-
...bindValue,
|
|
267
|
-
...on
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// 设置返回的DOM元素
|
|
271
|
-
const Comp = componentMap.get(component) as ReturnType<typeof defineComponent>
|
|
272
|
-
|
|
273
|
-
if( !renderComponent ) {
|
|
274
|
-
return <Comp {...compAttr} />
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// 定义一个组件插槽,用于处理后缀、前缀等问题,返回的是{ default: () => {} )这种数据格式
|
|
278
|
-
const compSlot = isFunction( renderComponent )
|
|
279
|
-
? { ...renderComponent( unref( getValues ) ) }
|
|
280
|
-
: {
|
|
281
|
-
default: () => renderComponent
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return <Comp {...compAttr}>{compSlot}</Comp>
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* 处理验证规则
|
|
289
|
-
*/
|
|
290
|
-
function handleRules(): ValidationRule[] {
|
|
291
|
-
const { rules: defaultRules = [], component, label, dynamicRules, required } = props.schema as FormSchema
|
|
292
|
-
|
|
293
|
-
// 1、如果为动态规则,则直接返回rules
|
|
294
|
-
if( isFunction( dynamicRules ) ) {
|
|
295
|
-
return dynamicRules( unref(getValues) ) as ValidationRule[]
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
// 2、如果没有静态规则,并且require为true
|
|
300
|
-
// 默认提示信息
|
|
301
|
-
const defaultMsg = createPlaceholder(component) + label
|
|
302
|
-
|
|
303
|
-
let rules = cloneDeep(defaultRules) as ValidationRule[]
|
|
304
|
-
// 是否必填
|
|
305
|
-
const getRequired = isFunction(required) ? required(unref(getValues)) : required
|
|
306
|
-
|
|
307
|
-
// 非空校验
|
|
308
|
-
function validator(rule: any, value: any) {
|
|
309
|
-
const msg = rule.message || defaultMsg
|
|
310
|
-
|
|
311
|
-
if(
|
|
312
|
-
// 空值
|
|
313
|
-
(value === undefined || isNull(value)) ||
|
|
314
|
-
// 数组
|
|
315
|
-
(Array.isArray(value) && value.length === 0) ||
|
|
316
|
-
// 空字符串
|
|
317
|
-
(typeof value === 'string' && value.trim() === '') ||
|
|
318
|
-
// 树组件未选择
|
|
319
|
-
(
|
|
320
|
-
typeof value === 'object' &&
|
|
321
|
-
Reflect.has(value, 'checked') &&
|
|
322
|
-
Reflect.has(value, 'halfChecked') &&
|
|
323
|
-
Array.isArray(value.checked) &&
|
|
324
|
-
Array.isArray(value.halfChecked) &&
|
|
325
|
-
value.checked.length === 0 &&
|
|
326
|
-
value.halfChecked.length === 0
|
|
327
|
-
)
|
|
328
|
-
) {
|
|
329
|
-
return Promise.reject(msg)
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
return Promise.resolve()
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
if( (!rules || !rules.length) && getRequired ) {
|
|
336
|
-
rules = [{ required: getRequired, validator }]
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// 3、如果有自定义的规则,则使用自定义的规则
|
|
340
|
-
const requiredIndex = rules.findIndex( rule => Reflect.has(rule, 'required') && !Reflect.has(rule, 'validator') )
|
|
341
|
-
|
|
342
|
-
if( requiredIndex !== -1 ) {
|
|
343
|
-
const rule = rules[requiredIndex]
|
|
344
|
-
|
|
345
|
-
if( !unref(getShow) ) {
|
|
346
|
-
rule.required = false
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (!Reflect.has(rule, 'type')) {
|
|
350
|
-
rule.type = component === 'InputNumber' ? 'number' : 'string';
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
rule.message = rule.message || defaultMsg
|
|
354
|
-
|
|
355
|
-
if (component.includes('Input') || component.includes('Textarea')) {
|
|
356
|
-
rule.whitespace = true
|
|
357
|
-
}
|
|
358
|
-
const valueFormat = unref(getComponentProps)?.valueFormat;
|
|
359
|
-
|
|
360
|
-
setComponentRuleType(rule, component, valueFormat)
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const maxIndex = rules.findIndex((val) => val.max)
|
|
364
|
-
|
|
365
|
-
if (maxIndex !== -1 && !rules[maxIndex].validator) {
|
|
366
|
-
rules[maxIndex].message = rules[maxIndex].message || `最大值为${ rules[maxIndex].max }`
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
return rules
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* 返回整个Col元素
|
|
375
|
-
* 1、如果有slot 则渲染slot元素
|
|
376
|
-
* 2、如果有renderCol自定义dom元素,则使用renderCol
|
|
377
|
-
* 3、否则通过属性去动态设置渲染条目
|
|
378
|
-
*/
|
|
379
|
-
return () => {
|
|
380
|
-
const { colSlot, renderCol, colProps, component, render } = props.schema as FormSchema
|
|
381
|
-
const { colProps: gColProps, mode } = props.formProps as FormProps
|
|
382
|
-
|
|
383
|
-
let _colProps = colProps
|
|
384
|
-
? colProps
|
|
385
|
-
: gColProps
|
|
386
|
-
? gColProps
|
|
387
|
-
: (mode === 'search' ? appConf.ui.form.searchColspan : appConf.ui.form.dialogColspan)
|
|
388
|
-
|
|
389
|
-
const values = unref(getValues)
|
|
390
|
-
|
|
391
|
-
if( !component ) {
|
|
392
|
-
if( !render ) {
|
|
393
|
-
error('请配置render函数')
|
|
394
|
-
return
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
return (
|
|
398
|
-
<Col span={24}>
|
|
399
|
-
{ render() }
|
|
400
|
-
</Col>
|
|
401
|
-
)
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
const getContent = () => {
|
|
405
|
-
return colSlot
|
|
406
|
-
? getSlot(slots, colSlot, values)
|
|
407
|
-
: renderCol
|
|
408
|
-
? renderCol( values )
|
|
409
|
-
: renderItem()
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
return unref(getShow) && (
|
|
413
|
-
<Col { ..._colProps }>
|
|
414
|
-
{ getContent() }
|
|
415
|
-
</Col>
|
|
416
|
-
)
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
})
|
|
420
|
-
</script>
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<template>
|
|
4
|
-
<RadioGroup v-bind="attrs" v-model:value="state" button-style="solid">
|
|
5
|
-
<template v-for="item in getOptions" :key="`${item.value}`">
|
|
6
|
-
<RadioButton :value="item.value" :disabled="item.disabled">
|
|
7
|
-
{{ item.label }}
|
|
8
|
-
</RadioButton>
|
|
9
|
-
</template>
|
|
10
|
-
</RadioGroup>
|
|
11
|
-
</template>
|
|
12
|
-
|
|
13
|
-
<script lang="ts">
|
|
14
|
-
import { computed, defineComponent, PropType } from "vue"
|
|
15
|
-
import { RadioGroup, RadioButton } from 'ant-design-vue'
|
|
16
|
-
import { isString } from "@dt-frames/core"
|
|
17
|
-
import { useFormValue } from "../hooks/useFormValue";
|
|
18
|
-
|
|
19
|
-
type OptionsItem = { label: string; value: string | number | boolean; disabled?: boolean }
|
|
20
|
-
type RadioItem = string | OptionsItem
|
|
21
|
-
|
|
22
|
-
export default defineComponent({
|
|
23
|
-
name: 'radio-button',
|
|
24
|
-
props: {
|
|
25
|
-
value: {
|
|
26
|
-
type: [String, Number, Boolean] as PropType<string | number | boolean>,
|
|
27
|
-
},
|
|
28
|
-
options: {
|
|
29
|
-
type: Array as PropType<RadioItem[]>,
|
|
30
|
-
default: () => [],
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
components: {
|
|
34
|
-
RadioGroup,
|
|
35
|
-
RadioButton
|
|
36
|
-
},
|
|
37
|
-
setup(props, { attrs }) {
|
|
38
|
-
const [state] = useFormValue(props)
|
|
39
|
-
|
|
40
|
-
const getOptions = computed((): OptionsItem[] => {
|
|
41
|
-
const { options } = props;
|
|
42
|
-
if (!options || options?.length === 0) return [];
|
|
43
|
-
|
|
44
|
-
const isStringArr = options.some((item) => isString(item));
|
|
45
|
-
if (!isStringArr) return options as OptionsItem[];
|
|
46
|
-
|
|
47
|
-
return options.map((item) => ({ label: item, value: item })) as OptionsItem[];
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
attrs,
|
|
53
|
-
getOptions,
|
|
54
|
-
state
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
})
|
|
58
|
-
</script>
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { ComponentType } from "../types/form.type";
|
|
2
|
-
import type { ValidationRule } from 'ant-design-vue/lib/form/Form'
|
|
3
|
-
import { isNumber } from "@dt-frames/core";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 生成占位符
|
|
7
|
-
* 根据组件名称不同 生成不同的占位符
|
|
8
|
-
*/
|
|
9
|
-
export function createPlaceholder(component: ComponentType) {
|
|
10
|
-
if( component.includes('Input') || component.includes('Complete') ) {
|
|
11
|
-
return '请输入'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if(
|
|
15
|
-
component.includes('Picker') ||
|
|
16
|
-
component.includes('Select') ||
|
|
17
|
-
component.includes('Cascader') ||
|
|
18
|
-
component.includes('Checkbox') ||
|
|
19
|
-
component.includes('Radio') ||
|
|
20
|
-
component.includes('Switch')
|
|
21
|
-
) {
|
|
22
|
-
return '请选择'
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if(component.includes('Icon')) {
|
|
26
|
-
return '请设置图标'
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return ''
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// 定义表单的type
|
|
34
|
-
export function setComponentRuleType(
|
|
35
|
-
rule: ValidationRule,
|
|
36
|
-
component: ComponentType,
|
|
37
|
-
valueFormat: string
|
|
38
|
-
) {
|
|
39
|
-
if (['DatePicker', 'MonthPicker', 'WeekPicker', 'TimePicker'].includes(component)) {
|
|
40
|
-
|
|
41
|
-
rule.type = valueFormat ? 'string' : 'object';
|
|
42
|
-
|
|
43
|
-
} else if (['RangePicker', 'Upload', 'CheckboxGroup', 'TimePicker'].includes(component)) {
|
|
44
|
-
|
|
45
|
-
rule.type = 'array';
|
|
46
|
-
|
|
47
|
-
} else if (['InputNumber'].includes(component)) {
|
|
48
|
-
|
|
49
|
-
rule.type = 'number';
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 获取Input的值
|
|
55
|
-
export function handleInputNumberValue(component?: ComponentType, val?: any) {
|
|
56
|
-
if (!component) return val;
|
|
57
|
-
if ([
|
|
58
|
-
'Input',
|
|
59
|
-
'InputPassword',
|
|
60
|
-
'InputSearch',
|
|
61
|
-
'InputTextArea'
|
|
62
|
-
].includes(component)) {
|
|
63
|
-
return val && isNumber(val) ? `${val}` : val;
|
|
64
|
-
}
|
|
65
|
-
return val;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// 时间类型
|
|
70
|
-
export const datePickerType: string[] = ['DatePicker', 'MonthPicker', 'WeekPicker', 'TimePicker', 'RangePicker']
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/** =========================================================
|
|
2
|
-
* 对form表单进行一次封装,方便后期调用
|
|
3
|
-
* ==========================================================*/
|
|
4
|
-
|
|
5
|
-
import { Recordable } from "@dt-frames/core";
|
|
6
|
-
import { ref, unref, onUnmounted, watch, nextTick } from "vue";
|
|
7
|
-
import { FormActionType, FormProps, FormSchema } from "../types/form.type";
|
|
8
|
-
|
|
9
|
-
type RegisterFn = (formInstance: FormActionType) => void;
|
|
10
|
-
type UseFormReturnType = [RegisterFn, FormActionType]
|
|
11
|
-
|
|
12
|
-
export function useForm(props: FormProps): UseFormReturnType {
|
|
13
|
-
const formRef = ref( null )
|
|
14
|
-
const loadedRef = ref( false )
|
|
15
|
-
|
|
16
|
-
function registerForm(instance: FormActionType) {
|
|
17
|
-
|
|
18
|
-
// 卸载之后,表单数据清空
|
|
19
|
-
onUnmounted(() => {
|
|
20
|
-
formRef.value = null
|
|
21
|
-
loadedRef.value = false
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
// 如果表单实例已经存在,停止注册表单
|
|
25
|
-
if( unref(loadedRef) && instance === unref(formRef) ) return
|
|
26
|
-
formRef.value = instance
|
|
27
|
-
loadedRef.value = true
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 深度监听props的变化,首次监听
|
|
31
|
-
* 动态更改表单实例
|
|
32
|
-
*/
|
|
33
|
-
watch(
|
|
34
|
-
() => props,
|
|
35
|
-
() => props && instance.setProps(props),
|
|
36
|
-
{
|
|
37
|
-
immediate: true,
|
|
38
|
-
deep: true
|
|
39
|
-
}
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* 定义表单的操作方法
|
|
46
|
-
*/
|
|
47
|
-
async function getForm() {
|
|
48
|
-
const form = unref( formRef )
|
|
49
|
-
|
|
50
|
-
if( !form ) console.error('表单未申明!');
|
|
51
|
-
|
|
52
|
-
await nextTick()
|
|
53
|
-
|
|
54
|
-
return form
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const methods: FormActionType = {
|
|
58
|
-
// 设置属性值
|
|
59
|
-
setProps: async (props: FormProps) => {
|
|
60
|
-
const form = await getForm()
|
|
61
|
-
form.setProps(props)
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
// 批量更新
|
|
65
|
-
updateSchema: async (data: Partial<FormSchema> | Partial<FormSchema>[]) => {
|
|
66
|
-
const form = await getForm()
|
|
67
|
-
form.updateSchema( data )
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
// 重置
|
|
71
|
-
resetSchema: async ( data: Partial<FormSchema> | Partial<FormSchema>[] ) => {
|
|
72
|
-
const form = await getForm()
|
|
73
|
-
form.resetSchema(data)
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
// 清除验证规则
|
|
77
|
-
clearValidate: async (name?: string | string[]) => {
|
|
78
|
-
const form = await getForm()
|
|
79
|
-
form.clearValidate(name)
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
// 表单重置
|
|
83
|
-
resetForms: async () => {
|
|
84
|
-
const form = await getForm()
|
|
85
|
-
form.resetForms()
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
// 根据属性名删除表单
|
|
89
|
-
removeFormByName: async (name?: string | string[]) => {
|
|
90
|
-
unref(formRef)?.removeFormByName( name )
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
// 设置表单的值
|
|
94
|
-
setFormValues: async ( values: Recordable ) => {
|
|
95
|
-
const form = await getForm()
|
|
96
|
-
form.setFormValues(values)
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
// 动态添加一个表单
|
|
100
|
-
appendFormItems: async (
|
|
101
|
-
schema: FormSchema,
|
|
102
|
-
prefixName: string | undefined,
|
|
103
|
-
first: boolean
|
|
104
|
-
) => {
|
|
105
|
-
const form = await getForm()
|
|
106
|
-
form.appendFormItems( schema, prefixName, first )
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
// 检验有效的属性值
|
|
110
|
-
validate: async ( nameList: (string | number)[] ) => {
|
|
111
|
-
const form = await getForm()
|
|
112
|
-
return form.validate(nameList)
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
// 返回有效的区域
|
|
116
|
-
validateFields: async (nameList: (string | number)[]) => {
|
|
117
|
-
const form = await getForm()
|
|
118
|
-
return form.validateFields(nameList)
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
// 获取属性值
|
|
122
|
-
getFormValues: () => {
|
|
123
|
-
return unref(formRef)?.getFormValues()
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return [ registerForm, methods ]
|
|
130
|
-
}
|