@dt-frames/ui 1.0.2 → 1.0.5
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/README.md +1 -15
- package/es/assets/imgs/header/avatar.png +0 -0
- package/es/assets/style/reset.less +0 -3
- package/es/components/curd/src/components/dialog.d.ts +21 -58
- package/es/components/curd/src/types/curd.type.d.ts +2 -1
- package/es/components/dialog/index.d.ts +2 -0
- package/es/components/dialog/src/hooks/useDialog.d.ts +3 -0
- package/es/components/forms/index.d.ts +2 -2
- package/es/components/forms/src/components/formIcon.d.ts +4 -47
- package/es/components/forms/src/index.d.ts +2 -6
- package/es/components/iframe/index.d.ts +2 -2
- package/es/components/index.d.ts +3 -2
- package/es/components/modal/src/components/close-icon.d.ts +0 -43
- package/es/components/modal/src/index.d.ts +0 -43
- package/es/components/source/src/types/table.type.d.ts +1 -1
- package/es/components/table/index.d.ts +1 -1
- package/es/components/table/src/components/setting/Column.d.ts +6 -5
- package/es/components/table/src/hooks/useColumns.d.ts +1 -1
- package/es/components/table/src/hooks/useDataSource.d.ts +1 -3
- package/es/components/table/src/hooks/useHeaderCode.d.ts +2 -0
- package/es/components/table/src/hooks/useRowSelection.d.ts +2 -3
- package/es/components/table/src/index.d.ts +15 -3
- package/es/components/table/src/props.d.ts +7 -1
- package/es/index.js +284 -271
- package/es/style/assets/style/reset.less +0 -3
- package/es/style/components/forms/{src/index.less → index.less} +2 -0
- package/es/style/components/icons/index.less +1 -0
- package/es/style/components/iframe/index.less +3 -0
- package/es/style/components/modal/{src/index.less → index.less} +0 -0
- package/es/style/components/table/{src/index.less → index.less} +12 -1
- package/es/style/theme/header/index.less +8 -4
- package/es/style/theme/sider/index.less +25 -25
- package/es/style/theme/theme.less +2 -1
- package/es/theme/header/components/logo.d.ts +43 -0
- package/es/theme/header/components/notify.d.ts +0 -1
- package/package.json +50 -40
- package/src/assets/data/icons/actions.ts +427 -0
- package/src/assets/data/icons/code.ts +10 -0
- package/src/assets/data/icons/commuticate.ts +190 -0
- package/src/assets/data/icons/currency.ts +46 -0
- package/src/assets/data/icons/devices.ts +128 -0
- package/src/assets/data/icons/edit.ts +165 -0
- package/src/assets/data/icons/file.ts +104 -0
- package/src/assets/data/icons/math.ts +53 -0
- package/src/assets/data/icons/message.ts +75 -0
- package/src/assets/data/icons/navigate.ts +181 -0
- package/src/assets/data/icons/other.ts +333 -0
- package/src/assets/data/icons.ts +58 -0
- 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 +3 -0
- package/src/assets/locales/zh_CN.json +3 -0
- package/src/assets/style/index.less +10 -0
- package/src/assets/style/reset.less +17 -0
- package/src/components/container/index.less +85 -0
- package/src/components/container/index.ts +8 -0
- package/src/components/container/src/bar.ts +107 -0
- package/src/components/container/src/lazy-container.vue +9 -0
- package/src/components/container/src/scroll-bar.vue +117 -0
- package/src/components/container/src/scroll-container.vue +61 -0
- package/src/components/curd/index.ts +5 -0
- package/src/components/curd/src/components/dialog.vue +71 -0
- package/src/components/curd/src/components/props.ts +32 -0
- package/src/components/curd/src/hooks/useCurd.tsx +87 -0
- package/src/components/curd/src/types/curd.type.ts +31 -0
- package/src/components/dialog/index.ts +5 -0
- package/src/components/dialog/src/hooks/useDialog.ts +85 -0
- package/src/components/excel/index.ts +6 -0
- package/src/components/excel/src/export2Excel.ts +44 -0
- package/src/components/forms/index.less +84 -0
- package/src/components/forms/index.ts +11 -0
- package/src/components/forms/src/componentMap.ts +44 -0
- package/src/components/forms/src/components/formButton.vue +150 -0
- package/src/components/forms/src/components/formIcon.vue +50 -0
- package/src/components/forms/src/components/formItem.vue +407 -0
- package/src/components/forms/src/components/radioButton.vue +58 -0
- package/src/components/forms/src/const/form.const.ts +7 -0
- package/src/components/forms/src/hooks/helper.ts +70 -0
- package/src/components/forms/src/hooks/useForm.ts +130 -0
- package/src/components/forms/src/hooks/useFormActions.ts +63 -0
- package/src/components/forms/src/hooks/useFormEvents.ts +247 -0
- package/src/components/forms/src/hooks/useFormValue.ts +49 -0
- package/src/components/forms/src/hooks/useFormValues.ts +131 -0
- package/src/components/forms/src/hooks/useLabelWidth.ts +57 -0
- package/src/components/forms/src/index.vue +306 -0
- package/src/components/forms/src/prop.ts +80 -0
- package/src/components/forms/src/types/form.type.ts +269 -0
- package/{es/style/components/icons/src → src/components/icons}/index.less +1 -0
- package/src/components/icons/index.ts +7 -0
- package/src/components/icons/src/pick-icon.vue +117 -0
- package/src/components/icons/src/svg-icon.vue +117 -0
- package/src/components/iframe/index.less +3 -0
- package/src/components/iframe/index.ts +5 -0
- package/src/components/iframe/src/index.less +3 -0
- package/src/components/iframe/src/index.vue +38 -0
- package/src/components/index.ts +48 -0
- package/src/components/modal/index.less +60 -0
- package/src/components/modal/index.ts +8 -0
- package/src/components/modal/src/components/close-icon.vue +47 -0
- package/src/components/modal/src/components/modal-wrap.vue +118 -0
- package/src/components/modal/src/components/modal.tsx +30 -0
- package/src/components/modal/src/components/modalFooter.vue +38 -0
- package/src/components/modal/src/hooks/useDrag.ts +107 -0
- package/src/components/modal/src/hooks/useFullScreen.ts +27 -0
- package/src/components/modal/src/hooks/useModal.ts +176 -0
- package/src/components/modal/src/index.vue +173 -0
- package/src/components/modal/src/props.ts +43 -0
- package/src/components/modal/src/types/modal.type.ts +27 -0
- package/src/components/router/base-router.vue +11 -0
- package/src/components/router/index.ts +3 -0
- package/src/components/source/index.ts +1 -0
- package/src/components/source/src/hooks/useFetch.ts +69 -0
- package/src/components/source/src/hooks/usePage.ts +3 -0
- package/src/components/source/src/hooks/useSource.ts +179 -0
- package/src/components/source/src/index.ts +5 -0
- package/src/components/source/src/types/source.type.ts +68 -0
- package/src/components/source/src/types/table.type.ts +8 -0
- package/src/components/table/index.less +173 -0
- package/src/components/table/index.ts +7 -0
- package/src/components/table/src/components/TableActions.vue +108 -0
- package/src/components/table/src/components/TableHeader.vue +77 -0
- package/src/components/table/src/components/TableRender.vue +76 -0
- package/src/components/table/src/components/setting/Column.vue +354 -0
- package/src/components/table/src/components/setting/Download.vue +55 -0
- package/src/components/table/src/components/setting/Fullscreen.vue +43 -0
- package/src/components/table/src/components/setting/Size.vue +42 -0
- package/src/components/table/src/components/setting/index.vue +64 -0
- package/src/components/table/src/const.ts +13 -0
- package/src/components/table/src/hooks/useColumns.ts +319 -0
- package/{es/assets/app-antd-dark-theme-style.e3b0c442.css → src/components/table/src/hooks/useCustomRow.ts} +0 -0
- package/src/components/table/src/hooks/useDataSource.ts +99 -0
- package/src/components/table/src/hooks/useHeaderCode.ts +82 -0
- package/src/components/table/src/hooks/useLoading.ts +29 -0
- package/src/components/table/src/hooks/usePagination.ts +76 -0
- package/src/components/table/src/hooks/useRowSelection.ts +145 -0
- package/src/components/table/src/hooks/useRows.ts +30 -0
- package/src/components/table/src/hooks/useTable.ts +89 -0
- package/src/components/table/src/hooks/useTableHeader.ts +48 -0
- package/src/components/table/src/hooks/useTableInstance.ts +29 -0
- package/src/components/table/src/hooks/useTableScroll.ts +229 -0
- package/src/components/table/src/index.vue +197 -0
- package/src/components/table/src/props.ts +157 -0
- package/src/components/table/src/types/table.type.ts +133 -0
- package/src/components/table/src/types/tableHeader.type.ts +27 -0
- package/{es/assets/app-theme-style.e3b0c442.css → src/components/type.ts} +0 -0
- package/src/directives/icon.ts +36 -0
- package/src/directives/index.ts +26 -0
- package/src/directives/permission.ts +20 -0
- package/src/global.d.ts +8 -0
- package/src/index.ts +4 -0
- package/src/theme/content/index.vue +37 -0
- package/src/theme/feature/back-top.vue +11 -0
- package/src/theme/feature/index.vue +7 -0
- package/src/theme/footer/index.less +16 -0
- package/src/theme/footer/index.vue +24 -0
- package/src/theme/header/components/bread-crumb.vue +26 -0
- package/src/theme/header/components/fullscreen.vue +12 -0
- package/src/theme/header/components/handler.ts +81 -0
- package/src/theme/header/components/index.ts +21 -0
- package/src/theme/header/components/lang-picker.vue +36 -0
- package/src/theme/header/components/logo.vue +35 -0
- package/src/theme/header/components/menu-search.vue +62 -0
- package/src/theme/header/components/notify.vue +22 -0
- package/src/theme/header/components/setting-theme.vue +123 -0
- package/src/theme/header/components/theme-drawer/enum.ts +12 -0
- package/src/theme/header/components/theme-drawer/feature.vue +75 -0
- package/src/theme/header/components/theme-drawer/index.ts +7 -0
- package/src/theme/header/components/theme-drawer/menu-type.vue +40 -0
- package/src/theme/header/components/theme-drawer/select-item.vue +46 -0
- package/src/theme/header/components/theme-drawer/switch-item.vue +39 -0
- package/src/theme/header/components/theme-drawer/theme-color.vue +26 -0
- package/src/theme/header/components/trigger.vue +14 -0
- package/src/theme/header/components/user-info.vue +60 -0
- package/src/theme/header/const/index.ts +40 -0
- package/src/theme/header/helper/menu-tree.ts +64 -0
- package/src/theme/header/index.less +442 -0
- package/{es/theme/theme.d.ts → src/theme/header/index.ts} +0 -0
- package/src/theme/header/index.vue +96 -0
- package/src/theme/header/multiple-header.vue +67 -0
- package/src/theme/header/set-theme.less +68 -0
- package/src/theme/index.ts +3 -0
- package/src/theme/sider/components/basic-menu/basic-menu-item.vue +14 -0
- package/src/theme/sider/components/basic-menu/basic-menu.vue +122 -0
- package/src/theme/sider/components/basic-menu/basic-sub-menu-item.vue +46 -0
- package/src/theme/sider/components/basic-menu/menu-item-content.vue +13 -0
- package/src/theme/sider/components/drag-bar.vue +26 -0
- package/src/theme/sider/components/layout-menu.vue +132 -0
- package/src/theme/sider/components/props.ts +97 -0
- package/src/theme/sider/components/sider-trigger.vue +24 -0
- package/src/theme/sider/helper/sider.ts +52 -0
- package/src/theme/sider/helper/split-menu.ts +146 -0
- package/src/theme/sider/hooks/useDragLine.ts +86 -0
- package/src/theme/sider/hooks/useOpenKeys.ts +57 -0
- package/src/theme/sider/index.less +203 -0
- package/src/theme/sider/index.vue +88 -0
- package/src/theme/tabs/components/TabContent.vue +36 -0
- package/src/theme/tabs/components/TabRedo.vue +18 -0
- package/src/theme/tabs/hooks/useMultifyTabs.ts +96 -0
- package/src/theme/tabs/hooks/useTabDropdown.ts +89 -0
- package/src/theme/tabs/index.less +165 -0
- package/src/theme/tabs/index.vue +98 -0
- package/src/theme/tabs/types/tabs.type.ts +8 -0
- package/src/theme/theme.less +67 -0
- package/src/theme/theme.vue +90 -0
- package/src/theme/transition.less +99 -0
- package/es/assets/data/icon.d.ts +0 -4
- package/es/assets/data/icon.ts +0 -69
- package/es/assets/data/icon11.ts +0 -69
- package/es/assets/style/var.less +0 -42
- package/es/components/icons/pick-icon.d.ts +0 -529
- package/es/components/icons/svg-icon.d.ts +0 -44
- package/es/components/table/src/hooks/useFormat.d.ts +0 -2
- package/es/components/table/src/hooks/useVirtualScroll.d.ts +0 -5
- package/es/components/table/src/utils/format.d.ts +0 -1
- package/es/index.css +0 -1
- package/es/style/assets/style/var.less +0 -42
- package/es/theme/content/index.d.ts +0 -29
- package/es/theme/header/components/menu-search.d.ts +0 -528
- package/es/theme/header/components/setting-theme.d.ts +0 -2550
- package/es/theme/header/components/user-info.d.ts +0 -452
- package/es/theme/header/index.d.ts +0 -4369
- package/es/theme/header/multiple-header.d.ts +0 -2001
- package/es/theme/styles/hooks/changeTheme.d.ts +0 -1
- package/es/theme/styles/hooks/generate.d.ts +0 -13
- package/es/theme/styles/index.d.ts +0 -2
- package/es/theme/tabs/components/TabRedo.d.ts +0 -49
- package/es/theme/tabs/index.d.ts +0 -1399
- package/es/theme/theme/initTheme.d.ts +0 -3
- package/es/theme/theme/util.d.ts +0 -5
- package/es/themes/generate.ts +0 -74
- package/es/themes/index.ts +0 -10
- package/es/themes/modifyVars.ts +0 -33
- package/es/themes/themePlugiin.ts +0 -74
|
@@ -0,0 +1,407 @@
|
|
|
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 } 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.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
|
|
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
|
|
65
|
+
|
|
66
|
+
if (isFunction(cProps)) {
|
|
67
|
+
cProps = cProps( { schema, formModel, formActionType } ) ?? {}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (schema.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
|
|
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
|
|
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
|
|
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
|
|
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
|
+
const 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
|
|
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 } = props.schema
|
|
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
|
+
const getContent = () => {
|
|
392
|
+
return colSlot
|
|
393
|
+
? getSlot(slots, colSlot, values)
|
|
394
|
+
: renderCol
|
|
395
|
+
? renderCol( values )
|
|
396
|
+
: renderItem()
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return unref(getShow) && (
|
|
400
|
+
<Col { ..._colProps }>
|
|
401
|
+
{ getContent() }
|
|
402
|
+
</Col>
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
})
|
|
407
|
+
</script>
|
|
@@ -0,0 +1,58 @@
|
|
|
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>
|
|
@@ -0,0 +1,70 @@
|
|
|
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']
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
}
|