@dt-frames/ui 1.0.2 → 1.0.3
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/style/reset.less +0 -3
- package/es/index.css +1 -1
- package/es/index.js +1 -0
- package/es/style/assets/style/reset.less +0 -3
- package/es/style/theme/sider/index.less +25 -25
- package/es/theme/content/index.d.ts +27 -29
- package/es/theme/header/components/menu-search.d.ts +528 -528
- package/es/theme/header/components/setting-theme.d.ts +2580 -2550
- package/es/theme/header/index.d.ts +4369 -4369
- package/es/theme/tabs/components/TabRedo.d.ts +7 -49
- package/es/theme/tabs/index.d.ts +2478 -1399
- package/es/theme/theme/initTheme.d.ts +3 -3
- package/es/theme/theme.d.ts +22 -0
- 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/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 +65 -0
- package/src/components/curd/src/components/props.ts +32 -0
- package/src/components/curd/src/hooks/useCurd.tsx +72 -0
- package/src/components/curd/src/types/curd.type.ts +29 -0
- package/src/components/excel/index.ts +6 -0
- package/src/components/excel/src/export2Excel.ts +44 -0
- package/src/components/forms/index.ts +12 -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.less +82 -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/src/components/icons/index.ts +7 -0
- package/src/components/icons/src/index.less +96 -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.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 +46 -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 +177 -0
- package/src/components/modal/src/index.less +60 -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 +70 -0
- package/src/components/source/src/hooks/usePage.ts +3 -0
- package/src/components/source/src/hooks/useSource.ts +178 -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.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 +355 -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/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/useLoading.ts +29 -0
- package/src/components/table/src/hooks/usePagination.ts +76 -0
- package/src/components/table/src/hooks/useRowSelection.ts +146 -0
- package/src/components/table/src/hooks/useRows.ts +30 -0
- package/src/components/table/src/hooks/useTable.ts +77 -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 +227 -0
- package/src/components/table/src/index.less +162 -0
- package/src/components/table/src/index.vue +198 -0
- package/src/components/table/src/props.ts +152 -0
- package/src/components/table/src/types/table.type.ts +133 -0
- package/src/components/table/src/types/tableHeader.type.ts +27 -0
- package/src/components/type.ts +0 -0
- package/src/directives/icon.ts +36 -0
- package/src/directives/index.ts +27 -0
- package/src/directives/permission.ts +21 -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 +14 -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 +33 -0
- package/src/theme/header/components/menu-search.vue +62 -0
- package/src/theme/header/components/notify.vue +23 -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 +43 -0
- package/src/theme/header/const/index.ts +40 -0
- package/src/theme/header/helper/menu-tree.ts +67 -0
- package/src/theme/header/index.less +438 -0
- package/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 +147 -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 +37 -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 +66 -0
- package/src/theme/theme.vue +89 -0
- package/src/theme/transition.less +99 -0
- 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,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
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { dateFormat, 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
|
+
|
|
7
|
+
/** =================================
|
|
8
|
+
* 定义表单的事件
|
|
9
|
+
* =================================*/
|
|
10
|
+
type FormEventsType = {
|
|
11
|
+
emit: (event: string, ...args: any[]) => void
|
|
12
|
+
getProps: ComputedRef<FormProps>;
|
|
13
|
+
getSchema: ComputedRef<FormSchema[]>
|
|
14
|
+
formModel: Recordable,
|
|
15
|
+
defaultValue: Ref<Recordable>,
|
|
16
|
+
formElRef: Ref<FormActionType>,
|
|
17
|
+
schemaRef: Ref<FormSchema[]>,
|
|
18
|
+
handleFormValues: Function;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function useFormEvents({
|
|
22
|
+
emit,
|
|
23
|
+
getSchema,
|
|
24
|
+
formModel,
|
|
25
|
+
defaultValue,
|
|
26
|
+
formElRef,
|
|
27
|
+
schemaRef,
|
|
28
|
+
handleFormValues
|
|
29
|
+
}: FormEventsType) {
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 获取form表单的值
|
|
33
|
+
*/
|
|
34
|
+
function getFormValues() {
|
|
35
|
+
const formEl = unref(formElRef);
|
|
36
|
+
if (!formEl) return {};
|
|
37
|
+
|
|
38
|
+
return handleFormValues(toRaw(unref(formModel)))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 更新表单的值
|
|
43
|
+
*/
|
|
44
|
+
function updateSchema(data: Partial<FormSchema> | Partial<FormSchema>[]): Promise<void> {
|
|
45
|
+
let updateItems: Partial<FormSchema>[] = []
|
|
46
|
+
|
|
47
|
+
updateItems = isObject(data)
|
|
48
|
+
? [ data as FormSchema ]
|
|
49
|
+
: [...data]
|
|
50
|
+
|
|
51
|
+
if( updateItems.every( it => it.component !== 'Divider' && !it.name ) ) {
|
|
52
|
+
console.error( '所有的元素都必须设置name属性' )
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let schema: FormSchema[] = []
|
|
57
|
+
updateItems.forEach( it => {
|
|
58
|
+
unref(getSchema).forEach( val => {
|
|
59
|
+
if( val.name === it.name ) {
|
|
60
|
+
const newSchema = deepMerge(val, it)
|
|
61
|
+
schema.push(newSchema as FormSchema)
|
|
62
|
+
} else {
|
|
63
|
+
schema.push(val)
|
|
64
|
+
}
|
|
65
|
+
} )
|
|
66
|
+
} )
|
|
67
|
+
|
|
68
|
+
schemaRef.value = uniqBy(schema, 'name')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 重新设置schema
|
|
74
|
+
*/
|
|
75
|
+
function resetSchema(data: Partial<FormSchema> | Partial<FormSchema>[]): Promise<void> {
|
|
76
|
+
let updateItems: Partial<FormSchema>[] = []
|
|
77
|
+
|
|
78
|
+
updateItems = isObject(data)
|
|
79
|
+
? [ data as FormSchema ]
|
|
80
|
+
: [...data]
|
|
81
|
+
|
|
82
|
+
if( updateItems.every( it => it.component !== 'Divider' && !it.name ) ) {
|
|
83
|
+
console.error( '所有的元素都必须设置name属性' )
|
|
84
|
+
return
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
schemaRef.value = updateItems as FormSchema[]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 清除验证条件
|
|
92
|
+
*/
|
|
93
|
+
async function clearValidate(name?: string | string[]) {
|
|
94
|
+
await unref(formElRef)?.clearValidate(name);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 重置form表单
|
|
99
|
+
*/
|
|
100
|
+
function resetForms() {
|
|
101
|
+
if ( !unref(formElRef) ) return
|
|
102
|
+
|
|
103
|
+
Object.keys( formModel ).forEach( key => {
|
|
104
|
+
const schema = unref(getSchema).find((item) => item.name === key)
|
|
105
|
+
const isInput =
|
|
106
|
+
schema?.component &&
|
|
107
|
+
['Input', 'InputPassword', 'InputSearch', 'InputTextArea'].includes(schema.component)
|
|
108
|
+
|
|
109
|
+
formModel[key] = isInput ? defaultValue.value[key] || '' : defaultValue.value[key]
|
|
110
|
+
|
|
111
|
+
} )
|
|
112
|
+
|
|
113
|
+
nextTick(() => clearValidate())
|
|
114
|
+
|
|
115
|
+
emit('reset', toRaw(formModel))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 根据属性名删除表单
|
|
120
|
+
*/
|
|
121
|
+
function removeFormByName(names: string | string[]) {
|
|
122
|
+
if( !names ) return
|
|
123
|
+
|
|
124
|
+
const schemaList: FormSchema[] = cloneDeep(unref(getSchema))
|
|
125
|
+
const nameList: string[] = isString(names) ? [names] : names
|
|
126
|
+
|
|
127
|
+
for (const name of nameList) {
|
|
128
|
+
_removeSchemaByName(name, schemaList);
|
|
129
|
+
}
|
|
130
|
+
schemaRef.value = schemaList
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function _removeSchemaByName(name: string, schemaList: FormSchema[]) {
|
|
134
|
+
const index = schemaList.findIndex((schema) => schema.name === name);
|
|
135
|
+
if (index !== -1) {
|
|
136
|
+
delete formModel[name];
|
|
137
|
+
schemaList.splice(index, 1);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 设置属性的值
|
|
144
|
+
*/
|
|
145
|
+
function setFormValues(values: Recordable | null): Promise<void> {
|
|
146
|
+
|
|
147
|
+
if( !values || !Object.keys( values ).length ) {
|
|
148
|
+
for(let it in formModel) formModel[it] = Array.isArray(formModel[it]) ? [] : null
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const names = unref(getSchema).map((item) => item.name).filter(Boolean)
|
|
153
|
+
|
|
154
|
+
const validKeys: string[] = []
|
|
155
|
+
|
|
156
|
+
Object.keys(values).forEach( key => {
|
|
157
|
+
const schema = unref(getSchema).find((item) => item.name === key)
|
|
158
|
+
let value = values[key]
|
|
159
|
+
|
|
160
|
+
const hasKey = Reflect.has(values, key)
|
|
161
|
+
|
|
162
|
+
value = handleInputNumberValue(schema?.component, value)
|
|
163
|
+
|
|
164
|
+
if (hasKey && names.includes(key)) {
|
|
165
|
+
if( itemIsDateType(key) ) {
|
|
166
|
+
if (Array.isArray(value)) {
|
|
167
|
+
const arr: any[] = [];
|
|
168
|
+
for (const ele of value) {
|
|
169
|
+
arr.push(ele ? dateFormat(ele) : null);
|
|
170
|
+
}
|
|
171
|
+
formModel[key] = arr;
|
|
172
|
+
} else {
|
|
173
|
+
const { props } = schema || {}
|
|
174
|
+
|
|
175
|
+
let _props = props as any
|
|
176
|
+
|
|
177
|
+
if (typeof props === 'function') {
|
|
178
|
+
_props = props({ formModel });
|
|
179
|
+
}
|
|
180
|
+
formModel[key] = value ? (_props?.valueFormat ? value : dateFormat(value)) : null
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
formModel[key] = value
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
validKeys.push(key)
|
|
187
|
+
}
|
|
188
|
+
} )
|
|
189
|
+
|
|
190
|
+
return validateFields(validKeys).catch((_) => {})
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* 动态添加一个表单
|
|
195
|
+
*/
|
|
196
|
+
function appendFormItems(schema: FormSchema, prefixName?: string, first = false) {
|
|
197
|
+
const schemaList: FormSchema[] = cloneDeep(unref(getSchema))
|
|
198
|
+
|
|
199
|
+
const index = schemaList.findIndex((schema) => schema.name === prefixName)
|
|
200
|
+
|
|
201
|
+
if (!prefixName || index === -1 || first) {
|
|
202
|
+
first ? schemaList.unshift(schema) : schemaList.push(schema);
|
|
203
|
+
schemaRef.value = schemaList;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (index !== -1) {
|
|
208
|
+
schemaList.splice(index + 1, 0, schema);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
schemaRef.value = schemaList;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 检验有效的属性值
|
|
216
|
+
*/
|
|
217
|
+
async function validate(nameList: (string | number)[]) {
|
|
218
|
+
return await unref(formElRef)?.validate(nameList);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 返回有效的区域
|
|
223
|
+
*/
|
|
224
|
+
async function validateFields(nameList: (string | number)[]) {
|
|
225
|
+
return unref(formElRef)?.validateFields(nameList);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function itemIsDateType(key: string) {
|
|
229
|
+
return unref(getSchema).some((item) => {
|
|
230
|
+
return item.name === key ? ['DatePicker', 'MonthPicker', 'WeekPicker', 'TimePicker', 'RangePicker'].includes(item.component) : false;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
return {
|
|
236
|
+
updateSchema,
|
|
237
|
+
resetSchema,
|
|
238
|
+
clearValidate,
|
|
239
|
+
resetForms,
|
|
240
|
+
removeFormByName,
|
|
241
|
+
setFormValues,
|
|
242
|
+
appendFormItems,
|
|
243
|
+
getFormValues,
|
|
244
|
+
validate,
|
|
245
|
+
validateFields
|
|
246
|
+
}
|
|
247
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}
|