@dt-frames/ui 1.0.11 → 1.0.15
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 +34 -25
- package/es/components/curd/src/components/props.d.ts +6 -5
- package/es/components/curd/src/hooks/useCurd.d.ts +1 -0
- package/es/components/curd/src/types/curd.type.d.ts +4 -3
- package/es/components/forms/src/components/formButton.d.ts +1 -2
- package/es/components/forms/src/components/formIcon.d.ts +16 -11
- package/es/components/forms/src/components/formInputUseDialog.d.ts +903 -0
- package/es/components/forms/src/hooks/useFormActions.d.ts +2 -2
- package/es/components/forms/src/index.d.ts +2 -2
- package/es/components/forms/src/types/form.type.d.ts +6 -18
- package/es/components/index.d.ts +2 -2
- package/es/components/modal/src/components/modal.d.ts +2 -2
- package/es/components/modal/src/components/modalFooter.d.ts +10 -5
- package/es/components/modal/src/index.d.ts +16 -11
- package/es/components/modal/src/props.d.ts +2 -1
- package/es/components/modal/src/types/modal.type.d.ts +4 -1
- package/es/components/source/src/hooks/useFetch.d.ts +1 -1
- package/es/components/table/src/hooks/useCustomRow.d.ts +19 -0
- package/es/components/table/src/hooks/useTable.d.ts +2 -2
- package/es/components/table/src/index.d.ts +24 -5
- package/es/components/table/src/props.d.ts +5 -2
- package/es/components/table/src/types/table.type.d.ts +2 -2
- package/es/components/tree/src/props.d.ts +8 -1
- package/es/components/upload/index.d.ts +1 -2
- package/es/components/upload/src/helper.d.ts +1 -0
- package/es/components/upload/src/index.d.ts +34 -11
- package/es/components/upload/src/props.d.ts +4 -1
- package/es/components/upload/src/upload.d.ts +42 -11
- package/es/index.js +356 -200
- package/es/style/components/forms/index.less +23 -0
- package/es/style/components/icons/index.less +1 -1
- package/es/style/components/upload/index.less +3 -11
- package/package.json +1 -10
- package/vite.config.js +10 -0
- 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 -31
- package/src/components/excel/index.ts +0 -6
- package/src/components/excel/src/export2Excel.ts +0 -44
- package/src/components/forms/index.less +0 -84
- package/src/components/forms/index.ts +0 -11
- package/src/components/forms/src/componentMap.ts +0 -44
- 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/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 -269
- 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 -54
- 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 -38
- 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 -194
- package/src/components/modal/src/index.vue +0 -173
- package/src/components/modal/src/props.ts +0 -43
- package/src/components/modal/src/types/modal.type.ts +0 -27
- 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 -0
- 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 -200
- package/src/components/table/src/props.ts +0 -157
- 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 -43
- package/src/components/upload/index.ts +0 -7
- package/src/components/upload/src/helper.ts +0 -32
- package/src/components/upload/src/index.vue +0 -38
- package/src/components/upload/src/props.ts +0 -48
- package/src/components/upload/src/upload.vue +0 -166
- 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,63 +0,0 @@
|
|
|
1
|
-
/** ==================================
|
|
2
|
-
* 处理查询条件中的按钮收缩
|
|
3
|
-
* ==================================*/
|
|
4
|
-
|
|
5
|
-
import { isBoolean, Recordable, useAppStore } from "@dt-frames/core"
|
|
6
|
-
import { ComputedRef, Ref, toRaw, unref } from "vue"
|
|
7
|
-
import { RESET_BTN_NAME, SEARCH_BTN_NAME } from "../const/form.const"
|
|
8
|
-
import { ButtonProps, FormProps, FormSchema } from "../types/form.type"
|
|
9
|
-
|
|
10
|
-
type FormOpt = {
|
|
11
|
-
updateSchema: (data: Partial<FormSchema> | Partial<FormSchema>[]) => Promise<void>
|
|
12
|
-
getProps: ComputedRef<FormProps>
|
|
13
|
-
getSchema: ComputedRef<FormSchema[]>,
|
|
14
|
-
defaultValue: Ref<Recordable>,
|
|
15
|
-
getFormValues: () => Recordable,
|
|
16
|
-
setFormValues: (values: Recordable) => Promise<void>,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function useFormActions(opt: FormOpt) {
|
|
20
|
-
const { getProps, getSchema, defaultValue, updateSchema, getFormValues, setFormValues } = opt
|
|
21
|
-
const { appConf } = useAppStore()
|
|
22
|
-
|
|
23
|
-
// 切换查询条件的展开 折叠
|
|
24
|
-
function handleAdvanced(isAdvanced: boolean) {
|
|
25
|
-
const { schemas, minShowColumn = appConf.ui.form?.minShowColumn || 2 } = unref(getProps)
|
|
26
|
-
|
|
27
|
-
let schema = schemas.reduce( ( t: FormSchema[], it: FormSchema, index ) => {
|
|
28
|
-
if( index > minShowColumn - 1)
|
|
29
|
-
it.isAdvanced = isAdvanced
|
|
30
|
-
t.push( it )
|
|
31
|
-
|
|
32
|
-
return t
|
|
33
|
-
}, [] )
|
|
34
|
-
|
|
35
|
-
updateSchema( schema )
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function handleMethod(params: boolean | ButtonProps) {
|
|
39
|
-
const { onSearch, onReset } = unref(getProps)
|
|
40
|
-
|
|
41
|
-
if( isBoolean( params ) ) {
|
|
42
|
-
|
|
43
|
-
// 如果为boolean 则视为查询条件的切换按钮
|
|
44
|
-
handleAdvanced(params as boolean)
|
|
45
|
-
|
|
46
|
-
} else if(params.name === SEARCH_BTN_NAME) {
|
|
47
|
-
|
|
48
|
-
// 查询
|
|
49
|
-
onSearch(getFormValues())
|
|
50
|
-
|
|
51
|
-
} else if(params.name === RESET_BTN_NAME) {
|
|
52
|
-
|
|
53
|
-
// 重置
|
|
54
|
-
setFormValues(toRaw(defaultValue.value))
|
|
55
|
-
onReset(getFormValues())
|
|
56
|
-
|
|
57
|
-
} else {
|
|
58
|
-
(params as ButtonProps).onClick()
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return [ handleMethod ]
|
|
63
|
-
}
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { deepMerge, isObject, isString, Recordable } from "@dt-frames/core"
|
|
2
|
-
import { ComputedRef, nextTick, Ref, toRaw, unref } from "vue"
|
|
3
|
-
import { uniqBy, cloneDeep } from 'lodash-es'
|
|
4
|
-
import { FormActionType, FormProps, FormSchema } from "../types/form.type"
|
|
5
|
-
import { handleInputNumberValue } from "./helper"
|
|
6
|
-
import dayjs from 'dayjs'
|
|
7
|
-
|
|
8
|
-
/** =================================
|
|
9
|
-
* 定义表单的事件
|
|
10
|
-
* =================================*/
|
|
11
|
-
type FormEventsType = {
|
|
12
|
-
emit: (event: string, ...args: any[]) => void
|
|
13
|
-
getProps: ComputedRef<FormProps>;
|
|
14
|
-
getSchema: ComputedRef<FormSchema[]>
|
|
15
|
-
formModel: Recordable,
|
|
16
|
-
defaultValue: Ref<Recordable>,
|
|
17
|
-
formElRef: Ref<FormActionType>,
|
|
18
|
-
schemaRef: Ref<FormSchema[]>,
|
|
19
|
-
handleFormValues: Function;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function useFormEvents({
|
|
23
|
-
emit,
|
|
24
|
-
getSchema,
|
|
25
|
-
formModel,
|
|
26
|
-
defaultValue,
|
|
27
|
-
formElRef,
|
|
28
|
-
schemaRef,
|
|
29
|
-
handleFormValues
|
|
30
|
-
}: FormEventsType) {
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 获取form表单的值
|
|
34
|
-
*/
|
|
35
|
-
function getFormValues() {
|
|
36
|
-
const formEl = unref(formElRef);
|
|
37
|
-
if (!formEl) return {};
|
|
38
|
-
|
|
39
|
-
return handleFormValues(toRaw(unref(formModel)))
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 更新表单的值
|
|
44
|
-
*/
|
|
45
|
-
function updateSchema(data: Partial<FormSchema> | Partial<FormSchema>[]): Promise<void> {
|
|
46
|
-
let updateItems: Partial<FormSchema>[] = []
|
|
47
|
-
|
|
48
|
-
updateItems = isObject(data)
|
|
49
|
-
? [ data as FormSchema ]
|
|
50
|
-
: [...data]
|
|
51
|
-
|
|
52
|
-
if( updateItems.every( it => it.component !== 'Divider' && !it.name ) ) {
|
|
53
|
-
console.error( '所有的元素都必须设置name属性' )
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let schema: FormSchema[] = []
|
|
58
|
-
updateItems.forEach( it => {
|
|
59
|
-
unref(getSchema).forEach( val => {
|
|
60
|
-
if( val.name === it.name ) {
|
|
61
|
-
const newSchema = deepMerge(val, it)
|
|
62
|
-
schema.push(newSchema as FormSchema)
|
|
63
|
-
} else {
|
|
64
|
-
schema.push(val)
|
|
65
|
-
}
|
|
66
|
-
} )
|
|
67
|
-
} )
|
|
68
|
-
|
|
69
|
-
schemaRef.value = uniqBy(schema, 'name')
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 重新设置schema
|
|
75
|
-
*/
|
|
76
|
-
function resetSchema(data: Partial<FormSchema> | Partial<FormSchema>[]): Promise<void> {
|
|
77
|
-
let updateItems: Partial<FormSchema>[] = []
|
|
78
|
-
|
|
79
|
-
updateItems = isObject(data)
|
|
80
|
-
? [ data as FormSchema ]
|
|
81
|
-
: [...data]
|
|
82
|
-
|
|
83
|
-
if( updateItems.every( it => it.component !== 'Divider' && !it.name ) ) {
|
|
84
|
-
console.error( '所有的元素都必须设置name属性' )
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
schemaRef.value = updateItems as FormSchema[]
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 清除验证条件
|
|
93
|
-
*/
|
|
94
|
-
async function clearValidate(name?: string | string[]) {
|
|
95
|
-
await unref(formElRef)?.clearValidate(name);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* 重置form表单
|
|
100
|
-
*/
|
|
101
|
-
function resetForms() {
|
|
102
|
-
if ( !unref(formElRef) ) return
|
|
103
|
-
|
|
104
|
-
Object.keys( formModel ).forEach( key => {
|
|
105
|
-
const schema = unref(getSchema).find((item) => item.name === key)
|
|
106
|
-
const isInput =
|
|
107
|
-
schema?.component &&
|
|
108
|
-
['Input', 'InputPassword', 'InputSearch', 'InputTextArea'].includes(schema.component)
|
|
109
|
-
|
|
110
|
-
formModel[key] = isInput ? defaultValue.value[key] || '' : defaultValue.value[key]
|
|
111
|
-
|
|
112
|
-
} )
|
|
113
|
-
|
|
114
|
-
nextTick(() => clearValidate())
|
|
115
|
-
|
|
116
|
-
emit('reset', toRaw(formModel))
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* 根据属性名删除表单
|
|
121
|
-
*/
|
|
122
|
-
function removeFormByName(names: string | string[]) {
|
|
123
|
-
if( !names ) return
|
|
124
|
-
|
|
125
|
-
const schemaList: FormSchema[] = cloneDeep(unref(getSchema))
|
|
126
|
-
const nameList: string[] = isString(names) ? [names] : names
|
|
127
|
-
|
|
128
|
-
for (const name of nameList) {
|
|
129
|
-
_removeSchemaByName(name, schemaList);
|
|
130
|
-
}
|
|
131
|
-
schemaRef.value = schemaList
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function _removeSchemaByName(name: string, schemaList: FormSchema[]) {
|
|
135
|
-
const index = schemaList.findIndex((schema) => schema.name === name);
|
|
136
|
-
if (index !== -1) {
|
|
137
|
-
delete formModel[name];
|
|
138
|
-
schemaList.splice(index, 1);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* 设置属性的值
|
|
145
|
-
*/
|
|
146
|
-
function setFormValues(values: Recordable | null): Promise<void> {
|
|
147
|
-
|
|
148
|
-
if( !values || !Object.keys( values ).length ) {
|
|
149
|
-
for(let it in formModel) formModel[it] = Array.isArray(formModel[it]) ? [] : null
|
|
150
|
-
return
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const names = unref(getSchema).map((item) => item.name).filter(Boolean)
|
|
154
|
-
|
|
155
|
-
const validKeys: string[] = []
|
|
156
|
-
|
|
157
|
-
Object.keys(values).forEach( key => {
|
|
158
|
-
const schema = unref(getSchema).find((item) => item.name === key)
|
|
159
|
-
let value = values[key]
|
|
160
|
-
|
|
161
|
-
const hasKey = Reflect.has(values, key)
|
|
162
|
-
|
|
163
|
-
value = handleInputNumberValue(schema?.component, value)
|
|
164
|
-
|
|
165
|
-
if (hasKey && names.includes(key)) {
|
|
166
|
-
if( itemIsDateType(key) ) {
|
|
167
|
-
if (Array.isArray(value)) {
|
|
168
|
-
const arr: any[] = [];
|
|
169
|
-
for (const ele of value) {
|
|
170
|
-
arr.push(ele ? dayjs(ele) : null);
|
|
171
|
-
}
|
|
172
|
-
formModel[key] = arr;
|
|
173
|
-
} else {
|
|
174
|
-
const { props } = schema || {}
|
|
175
|
-
|
|
176
|
-
let _props = props as any
|
|
177
|
-
|
|
178
|
-
if (typeof props === 'function') {
|
|
179
|
-
_props = props({ formModel });
|
|
180
|
-
}
|
|
181
|
-
formModel[key] = value ? (_props?.valueFormat ? value : dayjs(value)) : null
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
formModel[key] = value
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
validKeys.push(key)
|
|
188
|
-
}
|
|
189
|
-
} )
|
|
190
|
-
|
|
191
|
-
return validateFields(validKeys).catch((_) => {})
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* 动态添加一个表单
|
|
196
|
-
*/
|
|
197
|
-
function appendFormItems(schema: FormSchema, prefixName?: string, first = false) {
|
|
198
|
-
const schemaList: FormSchema[] = cloneDeep(unref(getSchema))
|
|
199
|
-
|
|
200
|
-
const index = schemaList.findIndex((schema) => schema.name === prefixName)
|
|
201
|
-
|
|
202
|
-
if (!prefixName || index === -1 || first) {
|
|
203
|
-
first ? schemaList.unshift(schema) : schemaList.push(schema);
|
|
204
|
-
schemaRef.value = schemaList;
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (index !== -1) {
|
|
209
|
-
schemaList.splice(index + 1, 0, schema);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
schemaRef.value = schemaList;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* 检验有效的属性值
|
|
217
|
-
*/
|
|
218
|
-
async function validate(nameList: (string | number)[]) {
|
|
219
|
-
return await unref(formElRef)?.validate(nameList);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* 返回有效的区域
|
|
224
|
-
*/
|
|
225
|
-
async function validateFields(nameList: (string | number)[]) {
|
|
226
|
-
return unref(formElRef)?.validateFields(nameList);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function itemIsDateType(key: string) {
|
|
230
|
-
return unref(getSchema).some((item) => {
|
|
231
|
-
return item.name === key ? ['DatePicker', 'MonthPicker', 'WeekPicker', 'TimePicker', 'RangePicker'].includes(item.component) : false;
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
updateSchema,
|
|
238
|
-
resetSchema,
|
|
239
|
-
clearValidate,
|
|
240
|
-
resetForms,
|
|
241
|
-
removeFormByName,
|
|
242
|
-
setFormValues,
|
|
243
|
-
appendFormItems,
|
|
244
|
-
getFormValues,
|
|
245
|
-
validate,
|
|
246
|
-
validateFields
|
|
247
|
-
}
|
|
248
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { Recordable } from "@dt-frames/core";
|
|
2
|
-
import { getCurrentInstance, Ref, reactive, readonly, watchEffect, computed, nextTick, toRaw, unref } from "vue";
|
|
3
|
-
import { isEqual } from 'lodash-es'
|
|
4
|
-
|
|
5
|
-
export function useFormValue<T extends Recordable>(
|
|
6
|
-
props: T,
|
|
7
|
-
key: keyof T = 'value',
|
|
8
|
-
changeEvent = 'change',
|
|
9
|
-
emitData?: Ref<any[]>
|
|
10
|
-
) {
|
|
11
|
-
const instance = getCurrentInstance()
|
|
12
|
-
const emit = instance?.emit
|
|
13
|
-
|
|
14
|
-
const innerState = reactive({
|
|
15
|
-
value: props[key]
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
const defaultState = readonly(innerState)
|
|
19
|
-
|
|
20
|
-
const setState = ( val: any ) => {
|
|
21
|
-
innerState.value = val
|
|
22
|
-
|
|
23
|
-
nextTick(() => {
|
|
24
|
-
emit?.(changeEvent, val, ...(toRaw(unref(emitData)) || []))
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
watchEffect(() => {
|
|
29
|
-
innerState.value = props[key]
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const state: any = computed({
|
|
33
|
-
get() {
|
|
34
|
-
return innerState.value
|
|
35
|
-
},
|
|
36
|
-
set(value) {
|
|
37
|
-
if( isEqual(value, defaultState.value) ) return
|
|
38
|
-
|
|
39
|
-
innerState.value = value as T[keyof T]
|
|
40
|
-
|
|
41
|
-
nextTick(() => {
|
|
42
|
-
emit?.(changeEvent, value, ...(toRaw(unref(emitData)) || []))
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
return [state, setState, defaultState]
|
|
49
|
-
}
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/** =========================================================
|
|
2
|
-
* 处理表单的值
|
|
3
|
-
* ==========================================================*/
|
|
4
|
-
import { dateFormat, isFunction, isObject, isString, Recordable } from "@dt-frames/core";
|
|
5
|
-
import { isArray } from "@vue/shared";
|
|
6
|
-
import { set } from "lodash-es";
|
|
7
|
-
import dayjs from "dayjs";
|
|
8
|
-
import { ComputedRef, Ref, unref } from "vue";
|
|
9
|
-
import { FormProps, FormSchema } from "../types/form.type";
|
|
10
|
-
import { datePickerType } from "./helper";
|
|
11
|
-
|
|
12
|
-
type FormValueOptions = {
|
|
13
|
-
getProps: ComputedRef<FormProps>
|
|
14
|
-
defaultValue: Ref<any>
|
|
15
|
-
getSchema: ComputedRef<FormSchema[]>
|
|
16
|
-
formModel: Recordable
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function useFormValues({
|
|
20
|
-
defaultValue,
|
|
21
|
-
getSchema,
|
|
22
|
-
formModel,
|
|
23
|
-
getProps
|
|
24
|
-
}: FormValueOptions) {
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 可以动态获取formModel的值
|
|
28
|
-
*/
|
|
29
|
-
function handleFormValues(values: Recordable) {
|
|
30
|
-
if( !isObject(values) ) return { }
|
|
31
|
-
|
|
32
|
-
const res: Recordable = {}
|
|
33
|
-
|
|
34
|
-
for(let [key, value] of Object.entries(values)) {
|
|
35
|
-
if( !key || (Array.isArray(value) && value.length === 0) || isFunction(value) ) {
|
|
36
|
-
continue
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* TODO 这里需要对时间进行处理
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if ( isString(value) ) {
|
|
45
|
-
value = value.trim();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
set(res, key, value)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return res
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 设置默认值
|
|
57
|
-
* 设置初始化的formModel值
|
|
58
|
-
*/
|
|
59
|
-
function initDefault() {
|
|
60
|
-
const schema = unref( getSchema ).filter(it => it.component )
|
|
61
|
-
const obj: Recordable = {}
|
|
62
|
-
|
|
63
|
-
schema.forEach( item => {
|
|
64
|
-
|
|
65
|
-
const { props = {}, name, component } = item
|
|
66
|
-
|
|
67
|
-
let { defaultValue, mode, format, treeCheckable } = isFunction( props ) ? props() : props
|
|
68
|
-
const names: string[] = isString(name) ? [ name ] : name
|
|
69
|
-
|
|
70
|
-
if( defaultValue !== null && defaultValue !== undefined ) {
|
|
71
|
-
|
|
72
|
-
// 处理时间
|
|
73
|
-
if( datePickerType.includes(component) ) {
|
|
74
|
-
const modeType = {
|
|
75
|
-
time: 'YYYY-MM-DD HH:mm:ss',
|
|
76
|
-
date: 'YYYY-MM-DD',
|
|
77
|
-
month: 'YYYY-MM',
|
|
78
|
-
year: 'YYYY'
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const _format = format || ( modeType[mode] ) || modeType.date
|
|
82
|
-
|
|
83
|
-
if ( !isArray(defaultValue) ) {
|
|
84
|
-
// 单个时间
|
|
85
|
-
obj[names[0]] = dayjs(defaultValue, _format)
|
|
86
|
-
formModel[names[0]] = dayjs(defaultValue, _format)
|
|
87
|
-
} else {
|
|
88
|
-
|
|
89
|
-
// 范围时间
|
|
90
|
-
let rangeTimes = defaultValue.reduce(( t, it ) => {
|
|
91
|
-
t.push( dayjs(it, _format) )
|
|
92
|
-
return t
|
|
93
|
-
}, [])
|
|
94
|
-
|
|
95
|
-
obj[names[0]] = rangeTimes
|
|
96
|
-
formModel[names[0]] = rangeTimes
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
// 如果names是数组 则代表有多个默认值 如 InputGroup
|
|
100
|
-
if( names.length > 1 ) {
|
|
101
|
-
names.forEach( ( key, index ) => {
|
|
102
|
-
obj[ key ] = defaultValue[ index ]
|
|
103
|
-
formModel[ key ] = defaultValue[ index ]
|
|
104
|
-
} )
|
|
105
|
-
} else {
|
|
106
|
-
obj[names[0]] = defaultValue
|
|
107
|
-
formModel[names[0]] = defaultValue
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
} else {
|
|
111
|
-
names.forEach( ( key, index ) => {
|
|
112
|
-
let defaultV = null
|
|
113
|
-
// 如果为树结构且为多选 或者复选框为多选状态
|
|
114
|
-
if( (component === 'TreeSelect' && (mode === 'multiple' || treeCheckable)) ||
|
|
115
|
-
(component === 'Select' && mode === 'multiple') ) {
|
|
116
|
-
defaultV = []
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
formModel[ key ] = obj[ key ] = defaultV
|
|
120
|
-
} )
|
|
121
|
-
}
|
|
122
|
-
} )
|
|
123
|
-
|
|
124
|
-
defaultValue.value = obj
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
handleFormValues,
|
|
129
|
-
initDefault
|
|
130
|
-
}
|
|
131
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/** =========================================================
|
|
2
|
-
* 处理表单的label宽度问题
|
|
3
|
-
* ==========================================================*/
|
|
4
|
-
|
|
5
|
-
import { isString, isNumber, useAppStore } from "@dt-frames/core";
|
|
6
|
-
import { computed, Ref, unref } from "vue";
|
|
7
|
-
import { FormProps, FormSchema } from "../types/form.type";
|
|
8
|
-
|
|
9
|
-
// 计算label的宽度
|
|
10
|
-
export function useLabelWidth(schemaItemRef: Ref<FormSchema>, propsRef: Ref<FormProps>) {
|
|
11
|
-
return computed(() => {
|
|
12
|
-
// 当前元素上关于label的设置
|
|
13
|
-
const { labelWidth, labelCol = { }, wrapperCol = { } } = unref( schemaItemRef )
|
|
14
|
-
// 获取全局配置
|
|
15
|
-
const { appConf } = useAppStore()
|
|
16
|
-
|
|
17
|
-
// 整个form关于label的设置
|
|
18
|
-
const {
|
|
19
|
-
labelWidth: gLabelWidth,
|
|
20
|
-
labelCol: glabelCol,
|
|
21
|
-
wrapperCol: gwrapperCol,
|
|
22
|
-
layout = appConf.ui.form.layout
|
|
23
|
-
} = unref( propsRef )
|
|
24
|
-
|
|
25
|
-
// 如果宽度设置为0
|
|
26
|
-
if( (isString(labelWidth) || isNumber(labelWidth)) && Number(labelWidth.toString()) === 0 ) {
|
|
27
|
-
return {
|
|
28
|
-
labelCol: {
|
|
29
|
-
...labelCol,
|
|
30
|
-
...{ style: { textAlign: 'left' } }
|
|
31
|
-
},
|
|
32
|
-
wrapperCol
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let width = labelWidth || gLabelWidth
|
|
37
|
-
const labelcol = { ...glabelCol, ...labelCol }
|
|
38
|
-
const wrapcol = { ...gwrapperCol, ...wrapperCol }
|
|
39
|
-
|
|
40
|
-
if (width) {
|
|
41
|
-
width = isNumber(width) ? `${width}px` : width
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
labelCol: {
|
|
46
|
-
style: { width },
|
|
47
|
-
...labelcol
|
|
48
|
-
},
|
|
49
|
-
wrapperCol: {
|
|
50
|
-
style: { width: layout === 'vertical' ? '100%' : `calc(100% - ${width})` },
|
|
51
|
-
...wrapcol
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|