dynamicformdjx 0.3.4 → 0.3.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 +39 -10
- package/dist/index.css +1 -1
- package/dist/naiveUi/NaiDynamicForm.d.ts +6 -5
- package/dist/naiveUi/index.cjs +1 -1
- package/dist/naiveUi/index.mjs +337 -324
- package/dist/types/form.d.ts +1 -1
- package/dist/types/index.d.ts +7 -0
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -53,13 +53,16 @@ pnpm add dynamicformdjx
|
|
|
53
53
|
import {ref} from "vue";
|
|
54
54
|
import {NButton} from "naive-ui";
|
|
55
55
|
import {useDyForm, useReactiveForm} from "dynamicformdjx";
|
|
56
|
-
import {type naiDynamicFormRef, NaiDynamicForm, renderInput} from "dynamicformdjx/naiveUi";
|
|
56
|
+
import {type naiDynamicFormRef, NaiDynamicForm, renderInput, renderRadioGroup} from "dynamicformdjx/naiveUi";
|
|
57
|
+
import type {PresetType} from "dynamicformdjx/types/index";
|
|
57
58
|
|
|
58
59
|
type FormRow = {
|
|
59
60
|
username: string
|
|
60
61
|
password: string
|
|
62
|
+
preset: PresetType
|
|
61
63
|
}
|
|
62
64
|
const naiDynamicFormRef = ref<naiDynamicFormRef | null>(null)
|
|
65
|
+
const presetType = ref<PresetType>('fullRow')
|
|
63
66
|
const formItems = useReactiveForm<FormRow>([
|
|
64
67
|
{
|
|
65
68
|
key: "username",
|
|
@@ -69,6 +72,7 @@ pnpm add dynamicformdjx
|
|
|
69
72
|
placeholder: '请输入姓名',
|
|
70
73
|
required: true, // 是否必填 (简化rules规则)
|
|
71
74
|
render2: f => renderInput(f.value, {}, f),
|
|
75
|
+
span: 6
|
|
72
76
|
},
|
|
73
77
|
{
|
|
74
78
|
key: "password",
|
|
@@ -79,7 +83,22 @@ pnpm add dynamicformdjx
|
|
|
79
83
|
required: true,
|
|
80
84
|
placeholder: '请输入密码',
|
|
81
85
|
render2: f => renderInput(f.value, {showPasswordOn: 'click'}, f),
|
|
82
|
-
|
|
86
|
+
span: 6,
|
|
87
|
+
requiredHint:l=>`${l} is not empty`
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
key: "preset",
|
|
91
|
+
label: "表格预设",
|
|
92
|
+
value: ref<PresetType | null>(presetType.value),
|
|
93
|
+
render2: f => renderRadioGroup(f.value, [
|
|
94
|
+
{label: '整行', value: 'fullRow'},
|
|
95
|
+
{label: '表格', value: 'grid'},
|
|
96
|
+
], {name: 'preset'}, f),
|
|
97
|
+
onChange: (v) => {
|
|
98
|
+
console.log(v)
|
|
99
|
+
presetType.value = v
|
|
100
|
+
}
|
|
101
|
+
},
|
|
83
102
|
])
|
|
84
103
|
const useForm = useDyForm<FormRow>(formItems)
|
|
85
104
|
const getData = () => {
|
|
@@ -89,7 +108,7 @@ pnpm add dynamicformdjx
|
|
|
89
108
|
}
|
|
90
109
|
const resetData = () => {
|
|
91
110
|
// useForm.onReset() // 或
|
|
92
|
-
naiDynamicFormRef.value?.reset()
|
|
111
|
+
naiDynamicFormRef.value?.reset?.()
|
|
93
112
|
}
|
|
94
113
|
const setData = () => {
|
|
95
114
|
// 隐藏username
|
|
@@ -113,16 +132,26 @@ pnpm add dynamicformdjx
|
|
|
113
132
|
</script>
|
|
114
133
|
|
|
115
134
|
<template>
|
|
116
|
-
<NaiDynamicForm :items="formItems" ref="naiDynamicFormRef"
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
<
|
|
121
|
-
|
|
122
|
-
|
|
135
|
+
<NaiDynamicForm :items="formItems" ref="naiDynamicFormRef" :preset="presetType">
|
|
136
|
+
<template #header>
|
|
137
|
+
<h3>基本表单</h3>
|
|
138
|
+
</template>
|
|
139
|
+
<template #footer>
|
|
140
|
+
<div class="control">
|
|
141
|
+
<n-button @click="getData" type="success" size="small">get Data</n-button>
|
|
142
|
+
<n-button @click="setData" type="warning" size="small">set Data</n-button>
|
|
143
|
+
<n-button @click="validatorData" type="default" size="small">validate Data</n-button>
|
|
144
|
+
<n-button @click="resetData" type="error" size="small">reset Data</n-button>
|
|
145
|
+
</div>
|
|
146
|
+
</template>
|
|
147
|
+
</NaiDynamicForm>
|
|
123
148
|
</template>
|
|
124
149
|
|
|
125
150
|
<style scoped>
|
|
151
|
+
h3{
|
|
152
|
+
text-align: center;
|
|
153
|
+
margin:0 0 10px 0;
|
|
154
|
+
}
|
|
126
155
|
.control {
|
|
127
156
|
display: flex;
|
|
128
157
|
gap: 5px;
|
package/dist/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.dynamicForm{overflow:hidden}.dynamicForm.small .dyFormList{gap:6px}.dynamicForm.small .dyFormList .typeBtn{padding:.2em .6em;height:18px}.dynamicForm.small .dyFormList>.dItem .input .key{font-size:.7em}.dynamicForm.small .dyFormList>.dItem .input .vInput{padding:.15em .4em}.dynamicForm.small .dyFormList>.dItem .input .vInput .slot{white-space:nowrap}.dynamicForm.small .dyFormList>.dItem .input .vInput .slot>button{padding:.1em .4em;font-size:.8em}.dynamicForm.small .dyFormList>.dItem .btn .bt{padding:.3em .8em}.dynamicForm.large .dyFormList{gap:15px}.dynamicForm.large .dyFormList .dItem{column-gap:20px}.dynamicForm.large .dyFormList .dItem .input .key{font-size:1.2em}.dynamicForm.large .dyFormList .dItem .input .vInput{padding:.5em .4em}.dynamicForm.large .dyFormList .dItem .input .vInput input{font-size:1.2em}.dynamicForm.large .dyFormList .dItem .input .vInput .slot{white-space:nowrap}.dynamicForm.large .dyFormList .dItem .input .vInput .slot>button{padding:.15em .4em;font-size:1em}.dynamicForm.large .dyFormList .dItem .btn .bt{padding:.8em 1.2em}.dynamicForm .dyFormList{overflow:auto;display:grid;gap:10px;padding:0 5px 10px}.dynamicForm .dyFormList.noList{padding:0}.dynamicForm .dyFormList .dItem{width:100%;display:grid;grid-template-columns:1fr 100px;column-gap:0}.dynamicForm .dyFormList .dItem .input{display:flex;justify-content:flex-start;align-items:center;column-gap:15px}.dynamicForm .dyFormList .dItem .input .key{text-align:center;width:150px}.dynamicForm .dyFormList .dItem .input .key.nativeInput{border:1px solid #d2d6dd;padding:.5em .4em;border-radius:3px}.dynamicForm .dyFormList .dItem .input .key.nativeInput:focus{outline:none;box-shadow:0 0 5px #007bff4d}.dynamicForm .dyFormList .dItem .input .vInput{width:100%;border:1px solid #d2d6dd;padding:.2em .4em;border-radius:3px;display:flex;column-gap:5px}.dynamicForm .dyFormList .dItem .input .vInput>.value{border:none;width:100%}.dynamicForm .dyFormList .dItem .input .vInput>.value.nativeV{letter-spacing:3px}.dynamicForm .dyFormList .dItem .input .vInput>.value.nativeV:focus{outline:none}.dynamicForm .dyFormList .dItem .input .vInput .slot{white-space:nowrap}.dynamicForm .dyFormList .dItem .input .vInput .slot>button{font-weight:400;border-radius:3px;font-size:.8em}.dynamicForm .dyFormList .dItem .btn{display:flex;justify-content:flex-end;align-items:center;column-gap:8px}.dynamicForm .dyFormList .dItem .btn .n-button{font-size:25px;padding:10px 12px}.dynamicForm .dyFormList .dItem .btn .el-button+.el-button{margin-left:0}.dynamicForm .dyFormList .dItem .btn .bt{padding:.5em 1em}.dynamicForm .key .el-input__inner,.dynamicForm .isKey .el-input__inner{text-align:center}.dynamicForm .control{display:flex;justify-content:center;align-items:center;margin-top:5px;column-gap:10px}.dynamicForm .control.noList{margin-top:0}.dynamicForm .bt{color:#fff;border-radius:5px;border:1px solid transparent;padding:.3em .8em;font-size:.9em;font-weight:600;font-family:inherit;background-color:#1a1a1a;cursor:pointer;transition:.25s;opacity:.9}.dynamicForm .bt:hover{opacity:1}.dynamicForm .bt:disabled{opacity:.35;cursor:not-allowed}.dynamicForm .default{background:#fff;color:#000;border:1px solid #d2d6dd}.dynamicForm .info{background:#8a8e94}.dynamicForm .success{background:#63ba39}.dynamicForm .danger{background:#ea696a}.dynamicCascadeForm{overflow:hidden}.dynamicCascadeForm.small .dyFormList{gap:6px}.dynamicCascadeForm.small .dyFormList .typeBtn{padding:.2em .6em;height:18px}.dynamicCascadeForm.small .dyFormList>.dItem .input .key{font-size:.7em}.dynamicCascadeForm.small .dyFormList>.dItem .input .vInput{padding:.15em .4em}.dynamicCascadeForm.small .dyFormList>.dItem .input .vInput .slot{white-space:nowrap}.dynamicCascadeForm.small .dyFormList>.dItem .input .vInput .slot>button{padding:.1em .4em;font-size:.8em}.dynamicCascadeForm.small .dyFormList>.dItem .btn .bt{padding:.3em .8em}.dynamicCascadeForm.large .dyFormList{gap:15px}.dynamicCascadeForm.large .dyFormList .dItem{column-gap:20px}.dynamicCascadeForm.large .dyFormList .dItem .input .key{font-size:1.2em}.dynamicCascadeForm.large .dyFormList .dItem .input .vInput{padding:.5em .4em}.dynamicCascadeForm.large .dyFormList .dItem .input .vInput input{font-size:1.2em}.dynamicCascadeForm.large .dyFormList .dItem .input .vInput .slot{white-space:nowrap}.dynamicCascadeForm.large .dyFormList .dItem .input .vInput .slot>button{padding:.15em .4em;font-size:1em}.dynamicCascadeForm.large .dyFormList .dItem .btn .bt{padding:.8em 1.2em}.dynamicCascadeForm .dyFormList{overflow:auto;display:grid;gap:10px;padding:0 5px 10px}.dynamicCascadeForm .dyFormList.noList{padding:0}.dynamicCascadeForm .dyFormList .dItem{width:100%;display:grid;grid-template-columns:1fr 100px;column-gap:0}.dynamicCascadeForm .dyFormList .dItem .input{display:flex;justify-content:flex-start;align-items:center;column-gap:15px}.dynamicCascadeForm .dyFormList .dItem .input .key{text-align:center;width:150px}.dynamicCascadeForm .dyFormList .dItem .input .key.nativeInput{border:1px solid #d2d6dd;padding:.5em .4em;border-radius:3px}.dynamicCascadeForm .dyFormList .dItem .input .key.nativeInput:focus{outline:none;box-shadow:0 0 5px #007bff4d}.dynamicCascadeForm .dyFormList .dItem .input .vInput{width:100%;border:1px solid #d2d6dd;padding:.2em .4em;border-radius:3px;display:flex;column-gap:5px}.dynamicCascadeForm .dyFormList .dItem .input .vInput>.value{border:none;width:100%}.dynamicCascadeForm .dyFormList .dItem .input .vInput>.value.nativeV{letter-spacing:3px}.dynamicCascadeForm .dyFormList .dItem .input .vInput>.value.nativeV:focus{outline:none}.dynamicCascadeForm .dyFormList .dItem .input .vInput .slot{white-space:nowrap}.dynamicCascadeForm .dyFormList .dItem .input .vInput .slot>button{font-weight:400;border-radius:3px;font-size:.8em}.dynamicCascadeForm .dyFormList .dItem .btn{display:flex;justify-content:flex-end;align-items:center;column-gap:8px}.dynamicCascadeForm .dyFormList .dItem .btn .n-button{font-size:25px;padding:10px 12px}.dynamicCascadeForm .dyFormList .dItem .btn .el-button+.el-button{margin-left:0}.dynamicCascadeForm .dyFormList .dItem .btn .bt{padding:.5em 1em}.dynamicCascadeForm .key .el-input__inner,.dynamicCascadeForm .isKey .el-input__inner{text-align:center}.dynamicCascadeForm .control{display:flex;justify-content:center;align-items:center;margin-top:5px;column-gap:10px}.dynamicCascadeForm .control.noList{margin-top:0}.dynamicCascadeForm .bt{color:#fff;border-radius:5px;border:1px solid transparent;padding:.3em .8em;font-size:.9em;font-weight:600;font-family:inherit;background-color:#1a1a1a;cursor:pointer;transition:.25s;opacity:.9}.dynamicCascadeForm .bt:hover{opacity:1}.dynamicCascadeForm .bt:disabled{opacity:.35;cursor:not-allowed}.dynamicCascadeForm .default{background:#fff;color:#000;border:1px solid #d2d6dd}.dynamicCascadeForm .info{background:#8a8e94}.dynamicCascadeForm .success{background:#63ba39}.dynamicCascadeForm .danger{background:#ea696a}.dynamicCascadeForm .dyFormList .dItem{width:inherit}.dynamicCascadeForm .dyFormList .dItem .vInput .surSlot{white-space:nowrap}.dynamicCascadeForm .dyFormList .dItem .vInput .surSlot>button{padding:.1em .4em;font-size:.8em}.dynamicCascadeForm .dyFormList .dItem .input .value.isKey{text-align:center}.dynamicCascadeForm .dyFormList .dItem .input .value.isKey input{font-weight:700}.dynamicCascadeForm .dyFormList>.depth-1{display:grid;border:1px solid var(--c1);border-style:dashed;border-radius:5px}.dynamicCascadeForm .dyFormList>.depth-1>.dItem{padding:5px}.dynamicCascadeForm .dyFormList>.depth-1 .dItem+.dItem{margin-top:5px}.dynamicCascadeForm .dyFormList>.depth-1.no-pad>.dItem{padding:0}.dynamicCascadeForm .dyFormList .depth-1 .depth-2{border:1px solid var(--c2);border-style:dashed;padding:8px;border-radius:5px;margin-top:10px;row-gap:-3px}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .dItem .btn .n-button{transform:scale(.84)}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3{border:1px solid var(--c3);border-style:dashed;padding:7px;border-radius:5px;margin-top:9px;row-gap:-5px}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3 .dItem .btn .n-button{transform:scale(.76)}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3 .depth-4{border:1px solid var(--c4);border-style:dashed;padding:6px;border-radius:5px;margin-top:8px;row-gap:-7px}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3 .depth-4 .dItem .btn .n-button{transform:scale(.68)}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3 .depth-4 .depth-5{border:1px solid var(--c5);border-style:dashed;padding:5px;border-radius:5px;margin-top:7px;row-gap:-9px}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3 .depth-4 .depth-5 .dItem .btn .n-button{transform:scale(.6)}.dynamicCascadeForm .dyFormList .no-border{border:none!important}.dynamicCascadeForm .dyFormList .no-pad{padding:0!important}.naiDynamicForm .cls-required{margin-left:5px;color:red}@media(max-width:756px){.dynamicForm .dyFormList .dItem .input .key{width:50px}.dynamicForm .dyFormList .dItem .input .value{width:calc(100% - 60px)}}
|
|
1
|
+
.dynamicForm{overflow:hidden}.dynamicForm.small .dyFormList{gap:6px}.dynamicForm.small .dyFormList .typeBtn{padding:.2em .6em;height:18px}.dynamicForm.small .dyFormList>.dItem .input .key{font-size:.7em}.dynamicForm.small .dyFormList>.dItem .input .vInput{padding:.15em .4em}.dynamicForm.small .dyFormList>.dItem .input .vInput .slot{white-space:nowrap}.dynamicForm.small .dyFormList>.dItem .input .vInput .slot>button{padding:.1em .4em;font-size:.8em}.dynamicForm.small .dyFormList>.dItem .btn .bt{padding:.3em .8em}.dynamicForm.large .dyFormList{gap:15px}.dynamicForm.large .dyFormList .dItem{column-gap:20px}.dynamicForm.large .dyFormList .dItem .input .key{font-size:1.2em}.dynamicForm.large .dyFormList .dItem .input .vInput{padding:.5em .4em}.dynamicForm.large .dyFormList .dItem .input .vInput input{font-size:1.2em}.dynamicForm.large .dyFormList .dItem .input .vInput .slot{white-space:nowrap}.dynamicForm.large .dyFormList .dItem .input .vInput .slot>button{padding:.15em .4em;font-size:1em}.dynamicForm.large .dyFormList .dItem .btn .bt{padding:.8em 1.2em}.dynamicForm .dyFormList{overflow:auto;display:grid;gap:10px;padding:0 5px 10px}.dynamicForm .dyFormList.noList{padding:0}.dynamicForm .dyFormList .dItem{width:100%;display:grid;grid-template-columns:1fr 100px;column-gap:0}.dynamicForm .dyFormList .dItem .input{display:flex;justify-content:flex-start;align-items:center;column-gap:15px}.dynamicForm .dyFormList .dItem .input .key{text-align:center;width:150px}.dynamicForm .dyFormList .dItem .input .key.nativeInput{border:1px solid #d2d6dd;padding:.5em .4em;border-radius:3px}.dynamicForm .dyFormList .dItem .input .key.nativeInput:focus{outline:none;box-shadow:0 0 5px #007bff4d}.dynamicForm .dyFormList .dItem .input .vInput{width:100%;border:1px solid #d2d6dd;padding:.2em .4em;border-radius:3px;display:flex;column-gap:5px}.dynamicForm .dyFormList .dItem .input .vInput>.value{border:none;width:100%}.dynamicForm .dyFormList .dItem .input .vInput>.value.nativeV{letter-spacing:3px}.dynamicForm .dyFormList .dItem .input .vInput>.value.nativeV:focus{outline:none}.dynamicForm .dyFormList .dItem .input .vInput .slot{white-space:nowrap}.dynamicForm .dyFormList .dItem .input .vInput .slot>button{font-weight:400;border-radius:3px;font-size:.8em}.dynamicForm .dyFormList .dItem .btn{display:flex;justify-content:flex-end;align-items:center;column-gap:8px}.dynamicForm .dyFormList .dItem .btn .n-button{font-size:25px;padding:10px 12px}.dynamicForm .dyFormList .dItem .btn .el-button+.el-button{margin-left:0}.dynamicForm .dyFormList .dItem .btn .bt{padding:.5em 1em}.dynamicForm .key .el-input__inner,.dynamicForm .isKey .el-input__inner{text-align:center}.dynamicForm .control{display:flex;justify-content:center;align-items:center;margin-top:5px;column-gap:10px}.dynamicForm .control.noList{margin-top:0}.dynamicForm .bt{color:#fff;border-radius:5px;border:1px solid transparent;padding:.3em .8em;font-size:.9em;font-weight:600;font-family:inherit;background-color:#1a1a1a;cursor:pointer;transition:.25s;opacity:.9}.dynamicForm .bt:hover{opacity:1}.dynamicForm .bt:disabled{opacity:.35;cursor:not-allowed}.dynamicForm .default{background:#fff;color:#000;border:1px solid #d2d6dd}.dynamicForm .info{background:#8a8e94}.dynamicForm .success{background:#63ba39}.dynamicForm .danger{background:#ea696a}.dynamicCascadeForm{overflow:hidden}.dynamicCascadeForm.small .dyFormList{gap:6px}.dynamicCascadeForm.small .dyFormList .typeBtn{padding:.2em .6em;height:18px}.dynamicCascadeForm.small .dyFormList>.dItem .input .key{font-size:.7em}.dynamicCascadeForm.small .dyFormList>.dItem .input .vInput{padding:.15em .4em}.dynamicCascadeForm.small .dyFormList>.dItem .input .vInput .slot{white-space:nowrap}.dynamicCascadeForm.small .dyFormList>.dItem .input .vInput .slot>button{padding:.1em .4em;font-size:.8em}.dynamicCascadeForm.small .dyFormList>.dItem .btn .bt{padding:.3em .8em}.dynamicCascadeForm.large .dyFormList{gap:15px}.dynamicCascadeForm.large .dyFormList .dItem{column-gap:20px}.dynamicCascadeForm.large .dyFormList .dItem .input .key{font-size:1.2em}.dynamicCascadeForm.large .dyFormList .dItem .input .vInput{padding:.5em .4em}.dynamicCascadeForm.large .dyFormList .dItem .input .vInput input{font-size:1.2em}.dynamicCascadeForm.large .dyFormList .dItem .input .vInput .slot{white-space:nowrap}.dynamicCascadeForm.large .dyFormList .dItem .input .vInput .slot>button{padding:.15em .4em;font-size:1em}.dynamicCascadeForm.large .dyFormList .dItem .btn .bt{padding:.8em 1.2em}.dynamicCascadeForm .dyFormList{overflow:auto;display:grid;gap:10px;padding:0 5px 10px}.dynamicCascadeForm .dyFormList.noList{padding:0}.dynamicCascadeForm .dyFormList .dItem{width:100%;display:grid;grid-template-columns:1fr 100px;column-gap:0}.dynamicCascadeForm .dyFormList .dItem .input{display:flex;justify-content:flex-start;align-items:center;column-gap:15px}.dynamicCascadeForm .dyFormList .dItem .input .key{text-align:center;width:150px}.dynamicCascadeForm .dyFormList .dItem .input .key.nativeInput{border:1px solid #d2d6dd;padding:.5em .4em;border-radius:3px}.dynamicCascadeForm .dyFormList .dItem .input .key.nativeInput:focus{outline:none;box-shadow:0 0 5px #007bff4d}.dynamicCascadeForm .dyFormList .dItem .input .vInput{width:100%;border:1px solid #d2d6dd;padding:.2em .4em;border-radius:3px;display:flex;column-gap:5px}.dynamicCascadeForm .dyFormList .dItem .input .vInput>.value{border:none;width:100%}.dynamicCascadeForm .dyFormList .dItem .input .vInput>.value.nativeV{letter-spacing:3px}.dynamicCascadeForm .dyFormList .dItem .input .vInput>.value.nativeV:focus{outline:none}.dynamicCascadeForm .dyFormList .dItem .input .vInput .slot{white-space:nowrap}.dynamicCascadeForm .dyFormList .dItem .input .vInput .slot>button{font-weight:400;border-radius:3px;font-size:.8em}.dynamicCascadeForm .dyFormList .dItem .btn{display:flex;justify-content:flex-end;align-items:center;column-gap:8px}.dynamicCascadeForm .dyFormList .dItem .btn .n-button{font-size:25px;padding:10px 12px}.dynamicCascadeForm .dyFormList .dItem .btn .el-button+.el-button{margin-left:0}.dynamicCascadeForm .dyFormList .dItem .btn .bt{padding:.5em 1em}.dynamicCascadeForm .key .el-input__inner,.dynamicCascadeForm .isKey .el-input__inner{text-align:center}.dynamicCascadeForm .control{display:flex;justify-content:center;align-items:center;margin-top:5px;column-gap:10px}.dynamicCascadeForm .control.noList{margin-top:0}.dynamicCascadeForm .bt{color:#fff;border-radius:5px;border:1px solid transparent;padding:.3em .8em;font-size:.9em;font-weight:600;font-family:inherit;background-color:#1a1a1a;cursor:pointer;transition:.25s;opacity:.9}.dynamicCascadeForm .bt:hover{opacity:1}.dynamicCascadeForm .bt:disabled{opacity:.35;cursor:not-allowed}.dynamicCascadeForm .default{background:#fff;color:#000;border:1px solid #d2d6dd}.dynamicCascadeForm .info{background:#8a8e94}.dynamicCascadeForm .success{background:#63ba39}.dynamicCascadeForm .danger{background:#ea696a}.dynamicCascadeForm .dyFormList .dItem{width:inherit}.dynamicCascadeForm .dyFormList .dItem .vInput .surSlot{white-space:nowrap}.dynamicCascadeForm .dyFormList .dItem .vInput .surSlot>button{padding:.1em .4em;font-size:.8em}.dynamicCascadeForm .dyFormList .dItem .input .value.isKey{text-align:center}.dynamicCascadeForm .dyFormList .dItem .input .value.isKey input{font-weight:700}.dynamicCascadeForm .dyFormList>.depth-1{display:grid;border:1px solid var(--c1);border-style:dashed;border-radius:5px}.dynamicCascadeForm .dyFormList>.depth-1>.dItem{padding:5px}.dynamicCascadeForm .dyFormList>.depth-1 .dItem+.dItem{margin-top:5px}.dynamicCascadeForm .dyFormList>.depth-1.no-pad>.dItem{padding:0}.dynamicCascadeForm .dyFormList .depth-1 .depth-2{border:1px solid var(--c2);border-style:dashed;padding:8px;border-radius:5px;margin-top:10px;row-gap:-3px}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .dItem .btn .n-button{transform:scale(.84)}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3{border:1px solid var(--c3);border-style:dashed;padding:7px;border-radius:5px;margin-top:9px;row-gap:-5px}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3 .dItem .btn .n-button{transform:scale(.76)}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3 .depth-4{border:1px solid var(--c4);border-style:dashed;padding:6px;border-radius:5px;margin-top:8px;row-gap:-7px}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3 .depth-4 .dItem .btn .n-button{transform:scale(.68)}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3 .depth-4 .depth-5{border:1px solid var(--c5);border-style:dashed;padding:5px;border-radius:5px;margin-top:7px;row-gap:-9px}.dynamicCascadeForm .dyFormList .depth-1 .depth-2 .depth-3 .depth-4 .depth-5 .dItem .btn .n-button{transform:scale(.6)}.dynamicCascadeForm .dyFormList .no-border{border:none!important}.dynamicCascadeForm .dyFormList .no-pad{padding:0!important}.naiDynamicForm .cls-required{margin-left:5px;color:red}.naiDynamicForm .header{margin-bottom:5px}.naiDynamicForm .footer{margin-top:5px}@media(max-width:756px){.dynamicForm .dyFormList .dItem .input .key{width:50px}.dynamicForm .dyFormList .dItem .input .value{width:calc(100% - 60px)}}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { PropType } from 'vue';
|
|
1
|
+
import { PropType, SlotsType } from 'vue';
|
|
2
2
|
import { FormProps, GridProps } from 'naive-ui';
|
|
3
3
|
import { DyFormItem } from '../types/form';
|
|
4
4
|
import { FormRules } from 'naive-ui/es/form/src/interface';
|
|
5
|
+
import { DynamicFormSlots, PresetType } from '../types';
|
|
5
6
|
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
6
7
|
formConfig: {
|
|
7
8
|
type: PropType<FormProps>;
|
|
@@ -22,7 +23,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
22
23
|
type: PropType<FormRules>;
|
|
23
24
|
};
|
|
24
25
|
preset: {
|
|
25
|
-
type: PropType<
|
|
26
|
+
type: PropType<PresetType>;
|
|
26
27
|
default: string;
|
|
27
28
|
validator: (value: string) => boolean;
|
|
28
29
|
};
|
|
@@ -50,7 +51,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
50
51
|
type: PropType<FormRules>;
|
|
51
52
|
};
|
|
52
53
|
preset: {
|
|
53
|
-
type: PropType<
|
|
54
|
+
type: PropType<PresetType>;
|
|
54
55
|
default: string;
|
|
55
56
|
validator: (value: string) => boolean;
|
|
56
57
|
};
|
|
@@ -61,6 +62,6 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
61
62
|
}>> & Readonly<{}>, {
|
|
62
63
|
formConfig: FormProps;
|
|
63
64
|
gridConfig: GridProps;
|
|
64
|
-
preset:
|
|
65
|
-
},
|
|
65
|
+
preset: PresetType;
|
|
66
|
+
}, SlotsType<DynamicFormSlots>, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
66
67
|
export default _default;
|
package/dist/naiveUi/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),i=require("naive-ui"),b=require("../index-CA3F2Lxo.cjs"),O=e.defineComponent({name:"NaiDynamicInput",props:{size:{type:String},isController:{type:Boolean},dyCls:{type:String},randomFun:{type:Function,default:r=>`${Date.now()}_${r??0}`},btnConfigs:{type:Object},configs:{type:Object},dyListConfigs:{type:Object},modelValue:{type:Object,required:!0}},emits:{"update:modelValue":r=>!0,onReset:()=>!0,onMerge:(r,d)=>!0},setup(r,{emit:d,expose:c}){const n={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...r.btnConfigs},t={hideReset:!1,maxHeight:"300px",autoScroll:!0,allowFilter:!0,...r.configs},s={arraySplitSymbol:",",...r.dyListConfigs},v=r.size,y=e.ref(b.tranArr(r.modelValue,r.randomFun,s.arraySplitSymbol)),p=e.ref(null);return e.watch(y,u=>{if(!r.isController)return;const m=b.resetObj(u,s.arraySplitSymbol);d("update:modelValue",m),d("onMerge",m,e.toRaw(y.value))},{deep:!0}),c({onSet:u=>{y.value=b.tranArr(u??r.modelValue,r.randomFun,s.arraySplitSymbol)},getResult:(u="res")=>u==="ori"?e.toRaw(y.value):b.resetObj(y.value,s.arraySplitSymbol)}),()=>e.createVNode("div",{class:r.dyCls??`dynamicForm ${v}`},[e.createVNode("div",{class:`dyFormList ${y.value.length?"":"noList"}`,ref:p,style:{maxHeight:t.maxHeight}},[y.value.map((u,m,a)=>e.createVNode("div",{class:"dItem",key:u.rId},[e.createVNode("div",{class:"input"},[e.createVNode(i.NInput,{size:v,value:u.key,class:"key",onInput:l=>{u.key=l}},null),e.createTextVNode(":"),e.createVNode(i.NInput,{size:v,value:u.value,class:"value",onInput:l=>{t.allowFilter&&u.isNumber?u.value=b.formatNumberInput(l,u.isArray,s.arraySplitSymbol):u.value=l}},{prefix:()=>e.createVNode(e.Fragment,null,[e.createVNode(i.NButton,{type:u.isArray?"success":"default",size:"tiny",onClick:()=>{u.isArray=!u.isArray}},{default:()=>[e.createTextVNode("Array")]}),e.createTextVNode(" "),e.createVNode(i.NButton,{type:u.isNumber?"success":"default",size:"tiny",onClick:()=>{u.isNumber=!u.isNumber}},{default:()=>[e.createTextVNode("Number")]})])})]),e.createVNode("div",{class:"btn"},[e.createVNode(i.NButton,{type:"success",size:v,disabled:m!==a.length-1,onClick:()=>{y.value.push({rId:r.randomFun(),key:"",value:""}),t.autoScroll&&e.nextTick(()=>{const l=p.value;l?.scrollTo({top:l.scrollHeight,behavior:"smooth"})})}},{default:()=>[e.createTextVNode("+")]}),e.createVNode(i.NButton,{size:v,type:"error",onClick:()=>{y.value=y.value.filter(l=>l.rId!==u.rId)}},{default:()=>[e.createTextVNode("-")]})])]))]),e.createVNode("div",{class:`control ${y.value.length?"":"noList"}`},[!y.value.length&&e.createVNode(i.NButton,{size:v,type:"success",onClick:()=>{y.value.push({rId:r.randomFun(),key:"",value:""})}},{default:()=>[n.newTxt]}),!r.isController&&e.createVNode(e.Fragment,null,[!t.hideReset&&e.createVNode(i.NButton,{size:v,type:"default",onClick:()=>{y.value=b.tranArr(r.modelValue,r.randomFun,s.arraySplitSymbol),d("onReset")}},{default:()=>[n.resetTxt]}),e.createVNode(i.NButton,{size:v,type:"info",onClick:()=>{y.value.sort((m,a)=>+m.rId-+a.rId);const u=b.resetObj(y.value,s.arraySplitSymbol);d("update:modelValue",u),d("onMerge",u,e.toRaw(y.value)),y.value=b.tranArr(u,r.randomFun,s.arraySplitSymbol)}},{default:()=>[n.mergeTxt]})])])])}});function D(r){return typeof r=="function"||Object.prototype.toString.call(r)==="[object Object]"&&!e.isVNode(r)}const z=e.defineComponent({name:"NaiveUiDynamicCascadeInput",props:{modelValue:{type:Object,required:!0},isController:{type:Boolean},dyCls:{type:String},randomFun:{type:Function,default:r=>`${Date.now()}_${r??0}`},depth:{type:Number,default:3},btnConfigs:{type:Object},configs:{type:Object},dyListConfigs:{type:Object},newChildTxt:{type:Function,default:r=>`添加 '${r.key}' 子项`}},emits:{"update:modelValue":r=>!0,onReset:()=>!0,onMerge:(r,d)=>!0},setup(r,{emit:d,expose:c}){const n={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...r.btnConfigs},t={hideReset:!1,maxHeight:"600px",allowFilter:!0,showBorder:!0,showPad:!0,retractLen:0,borderColors:[],...r.configs},s={arraySplitSymbol:",",...r.dyListConfigs},v=a=>["string","number"].includes(a),y=a=>Object.keys(a).map((l,f)=>{let o=a[l];const g=Array.isArray(o),C=g?o.every(V=>typeof V=="number"):typeof o=="number",h=o===null;return v(typeof o)&&(o=a[l]),h&&(o=""),{rId:r.randomFun(f),key:l,value:Object.prototype.toString.call(o)==="[object Object]"?y(a[l]):g?o.join(s.arraySplitSymbol):o,isArray:g||void 0,isNumber:C||void 0}}),p=a=>a.reduce((l,f)=>{const o=f.value;return f.key.trim().length&&(l[f.key]=Array.isArray(o)?p(o):b.parseValue(f.value,f.isArray,f.isNumber,s.arraySplitSymbol)),l},{}),u=e.ref(y(r.modelValue)),m=(a,l=1,f)=>e.createVNode("div",{class:[`depth-${l}`,t.showBorder?"":"no-border",t.showPad?"":"no-pad"],style:{"--depth":l,["--c"+[l]]:b.saferRepairColor(t.borderColors,l)}},[a.map((o,g,C)=>{const h=Array.isArray(o.value),V=v(typeof o.value);return e.createVNode("div",{class:"dItem",key:o.rId,style:{marginLeft:l>1?`${l*t.retractLen}px`:"0"}},[e.createVNode("div",{class:"input"},[!h&&e.createVNode(e.Fragment,null,[e.createVNode(i.NInput,{value:o.key,class:"key",onInput:N=>o.key=N},null),e.createTextVNode(":")]),e.createVNode(i.NInput,{class:`value ${h?"isKey":""}`,value:V?o.value:o.key,onInput:N=>{if(h){o.key=N;return}t.allowFilter&&o.isNumber?o.value=b.formatNumberInput(N,o.isArray,s.arraySplitSymbol):o.value=N}},{prefix:Array.isArray(o.value)?void 0:()=>e.createVNode(e.Fragment,null,[e.createVNode(i.NButton,{type:o.isArray?"success":"default",size:"tiny",onClick:()=>{o.isArray=!o.isArray}},{default:()=>[e.createTextVNode("Array")]}),e.createTextVNode(" "),e.createVNode(i.NButton,{type:o.isNumber?"success":"default",size:"tiny",onClick:()=>{o.isNumber=!o.isNumber}},{default:()=>[e.createTextVNode("Number")]})]),suffix:()=>{let N;return l<r.depth?!h&&e.createVNode(i.NButton,{type:"success",size:"tiny",onClick:()=>{V&&(o.value=[],o.isArray=void 0),o.value.push({rId:r.randomFun(),key:"",value:""})}},D(N=r.newChildTxt(o))?N:{default:()=>[N]}):null}})]),e.createVNode("div",{class:"btn"},[e.createVNode(i.NButton,{type:"success",disabled:g!==C.length-1,onClick:()=>{a.push({rId:r.randomFun(),key:"",value:""})}},{default:()=>[e.createTextVNode("+")]}),e.createVNode(i.NButton,{type:"error",onClick:()=>{if(a.splice(g,1),a.length<1){if(f===void 0)return p([]);const N=u.value.findIndex(j=>j.rId===f?.rId);l<1?u.value.splice(N,1,{...f,value:""}):f.value=""}}},{default:()=>[e.createTextVNode("-")]})]),Array.isArray(o.value)&&m(o.value,l+1,o)])})]);return e.watch(u,a=>{if(!r.isController)return;const l=p(a);d("update:modelValue",l),d("onMerge",l,e.toRaw(u.value))},{deep:!0}),c({onSet:a=>{u.value=y(a??r.modelValue)},getResult:(a="res")=>a==="ori"?e.toRaw(u.value):p(u.value)}),()=>e.createVNode("div",{class:r.dyCls??"dynamicCascadeForm"},[e.createVNode("div",{class:"dyFormList",style:{maxHeight:t.maxHeight}},[m(u.value)]),e.createVNode("div",{class:"control"},[!u.value.length&&e.createVNode(i.NButton,{type:"success",onClick:()=>{u.value.push({rId:r.randomFun(),key:"",value:""})}},{default:()=>[n.newTxt]}),!r.isController&&e.createVNode(e.Fragment,null,[!t.hideReset&&e.createVNode(i.NButton,{type:"default",onClick:()=>{u.value=y(r.modelValue),d("onReset")}},{default:()=>[n.resetTxt]}),e.createVNode(i.NButton,{type:"info",onClick:()=>{const a=p(u.value);d("update:modelValue",a),d("onMerge",a,e.toRaw(u.value)),u.value=y(a)}},{default:()=>[n.mergeTxt]})])])])}}),G=e.defineComponent({name:"NaiDynamicForm",props:{formConfig:{type:Object,default:()=>({labelPlacement:"left",size:"medium"})},gridConfig:{type:Object,default:()=>({responsive:"screen",cols:"xs:1 s:2 m:3 l:3 xl:4 2xl:4",xGap:10})},rules:{type:Object},preset:{type:String,default:"fullRow",validator:r=>["fullRow","grid"].includes(r)?!0:(console.error("preset value must be `fullRow` or `grid`, the default value is `fullRow`"),!1)},items:{type:Array,require:!0}},setup(r,{emit:d,expose:c}){const n=e.ref(null),t=e.computed(()=>(r.items??[]).filter(m=>!m.hidden)),s=e.computed(()=>t.value?t.value.reduce((m,a)=>(m[a.key]=a.value.value,m),{}):{}),v=e.computed(()=>({...t.value?.reduce((a,l)=>{let f=l.rule;return l.required&&!l.rule&&(f={required:!0,message:`${l.label}不能为空`,trigger:["blur"]}),a[l.key]=f,a},{}),...r.rules})),y=e.computed(()=>[...t.value].sort((a,l)=>{const f=a.sort??1/0,o=l.sort??1/0;return Number(f)-Number(o)}));function p(m=null){t.value&&t.value.forEach(a=>{a.reset?a.reset(a):a.value.value=m})}function u(){return new Promise((m,a)=>{n.value?.validate(l=>{l?a(l):m(s.value)})})}if(c({reset:p,validator:u,getResult:(m="res")=>m==="ori"?t.value:s.value}),!r.items)throw new Error("prop items must be not null");return()=>e.createVNode("div",{class:"naiDynamicForm"},[e.createVNode(i.NForm,e.mergeProps({ref:n},r.formConfig,{model:s.value,rules:v.value}),{default(){const m=y.value;return r.preset==="grid"?e.h(i.NGrid,{...r.gridConfig},{default:()=>m?.map(a=>e.h(i.NFormItemGridItem,{label:a.label,path:a.path||a.key},{default:S(a)}))}):m?.map(a=>e.h(i.NFormItem,{label:a.label,path:a.path||a.key},{default:S(a)}))}})])}});function S(r){return function(){return r.render2?r.render2(r):null}}function k(r,d={},c){return e.h(i.NInput,{...c,value:r.value,onUpdateValue:n=>{r.value=n,c?.onChange?.(n,c)},...d})}function x(r,d,c={},n){return e.h(i.NSelect,{...n,value:r.value,options:d,onUpdateValue:t=>{r.value=t,n?.onChange?.(t,n,d)},...c})}function F(r,d,c={},n,t){const{value:s,labelField:v,valueField:y,...p}=n,u=v??"label",m=y??"value",a=p.options??d;return e.createVNode(i.NPopselect,{...p,value:r.value,onUpdateValue:l=>{r.value=l,n?.onChange?.(l,n,a)},options:a.map(l=>({...l,label:l[u],value:l[m]})),...c},{default:()=>t??e.createVNode(i.NButton,null,{default:()=>r.value||"请选择"})})}function I(r,d,c={},n){const{valueField:t="value",...s}=n;return e.h(i.NTreeSelect,{...s,value:r.value,options:d,onUpdateValue:v=>{r.value=v,n?.onChange?.(v,n,d)},keyField:t,...c})}function T(r,d,c={},n){return e.h(i.NRadioGroup,{...n,value:r.value,onUpdateValue:t=>{r.value=t,n?.onChange?.(t,n,d)},...c},{default:()=>(n?.options??d).map(s=>{const v=n,y=s[v?.labelField??"label"],p=s[v?.valueField??"value"];return e.h(i.NRadio,{...s,label:y,value:p},{default:()=>s.label})})})}function R(r,d,c={},n){return e.createVNode(i.NRadioGroup,{...n,value:r.value,onUpdateValue:t=>{r.value=t,n?.onChange?.(t,n,d)},...c},{default:()=>(n?.options??d).map(s=>{const v=n,y=s[v?.labelField??"label"],p=s[v?.valueField??"value"];return e.createVNode(i.NRadioButton,{...s,label:y,value:p},{default:()=>s.label})})})}function A(r,d,c={},n){return e.h(i.NCheckboxGroup,{...n,value:r.value,onUpdateValue:t=>{r.value=t,n?.onChange?.(t,n,d)},...c},{default:()=>e.h(i.NSpace,{itemStyle:"display: flex"},{default:()=>(n?.options??d).map(s=>{const v=n,y=s[v?.labelField??"label"],p=s[v?.valueField??"value"];return e.h(i.NCheckbox,{value:p,label:y})})})})}function P(r,d={},c){return e.h(i.NSwitch,{...c,value:r.value,onUpdateValue:n=>{r.value=n,c?.onChange?.(n,c)},...d})}function w(r,d={},c){return e.h(i.NDatePicker,{...c,value:r.value,onUpdateValue:n=>{r.value=n,c?.onChange?.(n,c)},...d})}function B(r,d={},c){return e.h(i.NTimePicker,{...c,value:r.value,onUpdateValue:n=>{r.value=n,c?.onChange?.(n,c)},...d})}function $(r,d=!0){const c={renderInput:t=>k(t.value,t.renderProps??{},t),renderSelect:t=>x(t.value,t.options??[],t.renderProps??{},t),renderPopSelect:t=>F(t.value,t.options??[],t.renderProps??{},t),renderTreeSelect:t=>I(t.value,t.options??[],t.renderProps??{},t),renderRadioGroup:t=>T(t.value,t.options??[],t.renderProps??{},t),renderRadioButtonGroup:t=>R(t.value,t.options??[],t.renderProps??{},t),renderCheckboxGroup:t=>A(t.value,t.options??[],t.renderProps??{},t),renderSwitch:t=>P(t.value,t.renderProps??{},t),renderDatePicker:t=>w(t.value,t.renderProps??{},t),renderTimePicker:t=>B(t.value,t.renderProps??{},t)};return r.map(t=>{const s=t;if(s.value=b.ensureRef(t.value),typeof t.render2=="function")s.render2=t.render2;else if(t.renderType){const v=c[t.renderType];v?s.render2=()=>v(s):console.warn(`[useDecorateForm] unknown renderType: ${t.renderType}`)}else s.render2=()=>c.renderInput(s);return d?e.shallowReactive(s):s})}exports.NaiDynamicCascadeInput=z;exports.NaiDynamicForm=G;exports.NaiDynamicInput=O;exports.renderCheckboxGroup=A;exports.renderDatePicker=w;exports.renderInput=k;exports.renderPopSelect=F;exports.renderRadioButtonGroup=R;exports.renderRadioGroup=T;exports.renderSelect=x;exports.renderSwitch=P;exports.renderTimePicker=B;exports.renderTreeSelect=I;exports.useDecorateForm=$;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),y=require("naive-ui"),b=require("../index-CA3F2Lxo.cjs"),O=e.defineComponent({name:"NaiDynamicInput",props:{size:{type:String},isController:{type:Boolean},dyCls:{type:String},randomFun:{type:Function,default:t=>`${Date.now()}_${t??0}`},btnConfigs:{type:Object},configs:{type:Object},dyListConfigs:{type:Object},modelValue:{type:Object,required:!0}},emits:{"update:modelValue":t=>!0,onReset:()=>!0,onMerge:(t,c)=>!0},setup(t,{emit:c,expose:i}){const u={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...t.btnConfigs},r={hideReset:!1,maxHeight:"300px",autoScroll:!0,allowFilter:!0,...t.configs},l={arraySplitSymbol:",",...t.dyListConfigs},v=t.size,s=e.ref(b.tranArr(t.modelValue,t.randomFun,l.arraySplitSymbol)),p=e.ref(null);return e.watch(s,n=>{if(!t.isController)return;const m=b.resetObj(n,l.arraySplitSymbol);c("update:modelValue",m),c("onMerge",m,e.toRaw(s.value))},{deep:!0}),i({onSet:n=>{s.value=b.tranArr(n??t.modelValue,t.randomFun,l.arraySplitSymbol)},getResult:(n="res")=>n==="ori"?e.toRaw(s.value):b.resetObj(s.value,l.arraySplitSymbol)}),()=>e.createVNode("div",{class:t.dyCls??`dynamicForm ${v}`},[e.createVNode("div",{class:`dyFormList ${s.value.length?"":"noList"}`,ref:p,style:{maxHeight:r.maxHeight}},[s.value.map((n,m,a)=>e.createVNode("div",{class:"dItem",key:n.rId},[e.createVNode("div",{class:"input"},[e.createVNode(y.NInput,{size:v,value:n.key,class:"key",onInput:o=>{n.key=o}},null),e.createTextVNode(":"),e.createVNode(y.NInput,{size:v,value:n.value,class:"value",onInput:o=>{r.allowFilter&&n.isNumber?n.value=b.formatNumberInput(o,n.isArray,l.arraySplitSymbol):n.value=o}},{prefix:()=>e.createVNode(e.Fragment,null,[e.createVNode(y.NButton,{type:n.isArray?"success":"default",size:"tiny",onClick:()=>{n.isArray=!n.isArray}},{default:()=>[e.createTextVNode("Array")]}),e.createTextVNode(" "),e.createVNode(y.NButton,{type:n.isNumber?"success":"default",size:"tiny",onClick:()=>{n.isNumber=!n.isNumber}},{default:()=>[e.createTextVNode("Number")]})])})]),e.createVNode("div",{class:"btn"},[e.createVNode(y.NButton,{type:"success",size:v,disabled:m!==a.length-1,onClick:()=>{s.value.push({rId:t.randomFun(),key:"",value:""}),r.autoScroll&&e.nextTick(()=>{const o=p.value;o?.scrollTo({top:o.scrollHeight,behavior:"smooth"})})}},{default:()=>[e.createTextVNode("+")]}),e.createVNode(y.NButton,{size:v,type:"error",onClick:()=>{s.value=s.value.filter(o=>o.rId!==n.rId)}},{default:()=>[e.createTextVNode("-")]})])]))]),e.createVNode("div",{class:`control ${s.value.length?"":"noList"}`},[!s.value.length&&e.createVNode(y.NButton,{size:v,type:"success",onClick:()=>{s.value.push({rId:t.randomFun(),key:"",value:""})}},{default:()=>[u.newTxt]}),!t.isController&&e.createVNode(e.Fragment,null,[!r.hideReset&&e.createVNode(y.NButton,{size:v,type:"default",onClick:()=>{s.value=b.tranArr(t.modelValue,t.randomFun,l.arraySplitSymbol),c("onReset")}},{default:()=>[u.resetTxt]}),e.createVNode(y.NButton,{size:v,type:"info",onClick:()=>{s.value.sort((m,a)=>+m.rId-+a.rId);const n=b.resetObj(s.value,l.arraySplitSymbol);c("update:modelValue",n),c("onMerge",n,e.toRaw(s.value)),s.value=b.tranArr(n,t.randomFun,l.arraySplitSymbol)}},{default:()=>[u.mergeTxt]})])])])}});function D(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!e.isVNode(t)}const z=e.defineComponent({name:"NaiveUiDynamicCascadeInput",props:{modelValue:{type:Object,required:!0},isController:{type:Boolean},dyCls:{type:String},randomFun:{type:Function,default:t=>`${Date.now()}_${t??0}`},depth:{type:Number,default:3},btnConfigs:{type:Object},configs:{type:Object},dyListConfigs:{type:Object},newChildTxt:{type:Function,default:t=>`添加 '${t.key}' 子项`}},emits:{"update:modelValue":t=>!0,onReset:()=>!0,onMerge:(t,c)=>!0},setup(t,{emit:c,expose:i}){const u={resetTxt:"重置",newTxt:"添加项",mergeTxt:"合并",...t.btnConfigs},r={hideReset:!1,maxHeight:"600px",allowFilter:!0,showBorder:!0,showPad:!0,retractLen:0,borderColors:[],...t.configs},l={arraySplitSymbol:",",...t.dyListConfigs},v=a=>["string","number"].includes(a),s=a=>Object.keys(a).map((o,f)=>{let d=a[o];const g=Array.isArray(d),V=g?d.every(C=>typeof C=="number"):typeof d=="number",h=d===null;return v(typeof d)&&(d=a[o]),h&&(d=""),{rId:t.randomFun(f),key:o,value:Object.prototype.toString.call(d)==="[object Object]"?s(a[o]):g?d.join(l.arraySplitSymbol):d,isArray:g||void 0,isNumber:V||void 0}}),p=a=>a.reduce((o,f)=>{const d=f.value;return f.key.trim().length&&(o[f.key]=Array.isArray(d)?p(d):b.parseValue(f.value,f.isArray,f.isNumber,l.arraySplitSymbol)),o},{}),n=e.ref(s(t.modelValue)),m=(a,o=1,f)=>e.createVNode("div",{class:[`depth-${o}`,r.showBorder?"":"no-border",r.showPad?"":"no-pad"],style:{"--depth":o,["--c"+[o]]:b.saferRepairColor(r.borderColors,o)}},[a.map((d,g,V)=>{const h=Array.isArray(d.value),C=v(typeof d.value);return e.createVNode("div",{class:"dItem",key:d.rId,style:{marginLeft:o>1?`${o*r.retractLen}px`:"0"}},[e.createVNode("div",{class:"input"},[!h&&e.createVNode(e.Fragment,null,[e.createVNode(y.NInput,{value:d.key,class:"key",onInput:N=>d.key=N},null),e.createTextVNode(":")]),e.createVNode(y.NInput,{class:`value ${h?"isKey":""}`,value:C?d.value:d.key,onInput:N=>{if(h){d.key=N;return}r.allowFilter&&d.isNumber?d.value=b.formatNumberInput(N,d.isArray,l.arraySplitSymbol):d.value=N}},{prefix:Array.isArray(d.value)?void 0:()=>e.createVNode(e.Fragment,null,[e.createVNode(y.NButton,{type:d.isArray?"success":"default",size:"tiny",onClick:()=>{d.isArray=!d.isArray}},{default:()=>[e.createTextVNode("Array")]}),e.createTextVNode(" "),e.createVNode(y.NButton,{type:d.isNumber?"success":"default",size:"tiny",onClick:()=>{d.isNumber=!d.isNumber}},{default:()=>[e.createTextVNode("Number")]})]),suffix:()=>{let N;return o<t.depth?!h&&e.createVNode(y.NButton,{type:"success",size:"tiny",onClick:()=>{C&&(d.value=[],d.isArray=void 0),d.value.push({rId:t.randomFun(),key:"",value:""})}},D(N=t.newChildTxt(d))?N:{default:()=>[N]}):null}})]),e.createVNode("div",{class:"btn"},[e.createVNode(y.NButton,{type:"success",disabled:g!==V.length-1,onClick:()=>{a.push({rId:t.randomFun(),key:"",value:""})}},{default:()=>[e.createTextVNode("+")]}),e.createVNode(y.NButton,{type:"error",onClick:()=>{if(a.splice(g,1),a.length<1){if(f===void 0)return p([]);const N=n.value.findIndex(B=>B.rId===f?.rId);o<1?n.value.splice(N,1,{...f,value:""}):f.value=""}}},{default:()=>[e.createTextVNode("-")]})]),Array.isArray(d.value)&&m(d.value,o+1,d)])})]);return e.watch(n,a=>{if(!t.isController)return;const o=p(a);c("update:modelValue",o),c("onMerge",o,e.toRaw(n.value))},{deep:!0}),i({onSet:a=>{n.value=s(a??t.modelValue)},getResult:(a="res")=>a==="ori"?e.toRaw(n.value):p(n.value)}),()=>e.createVNode("div",{class:t.dyCls??"dynamicCascadeForm"},[e.createVNode("div",{class:"dyFormList",style:{maxHeight:r.maxHeight}},[m(n.value)]),e.createVNode("div",{class:"control"},[!n.value.length&&e.createVNode(y.NButton,{type:"success",onClick:()=>{n.value.push({rId:t.randomFun(),key:"",value:""})}},{default:()=>[u.newTxt]}),!t.isController&&e.createVNode(e.Fragment,null,[!r.hideReset&&e.createVNode(y.NButton,{type:"default",onClick:()=>{n.value=s(t.modelValue),c("onReset")}},{default:()=>[u.resetTxt]}),e.createVNode(y.NButton,{type:"info",onClick:()=>{const a=p(n.value);c("update:modelValue",a),c("onMerge",a,e.toRaw(n.value)),n.value=s(a)}},{default:()=>[u.mergeTxt]})])])])}}),G=e.defineComponent({name:"NaiDynamicForm",props:{formConfig:{type:Object,default:()=>({labelPlacement:"left",size:"medium"})},gridConfig:{type:Object,default:()=>({responsive:"screen",cols:"xs:1 s:2 m:3 l:3 xl:4 2xl:4",xGap:10})},rules:{type:Object},preset:{type:String,default:"fullRow",validator:t=>["fullRow","grid"].includes(t)?!0:(console.error("preset value must be `fullRow` or `grid`, the default value is `fullRow`"),!1)},items:{type:Array,require:!0}},slots:Object,setup(t,{expose:c,slots:i}){const u=e.ref(null),r=e.computed(()=>(t.items??[]).filter(m=>!m.hidden)),l=e.computed(()=>r.value?r.value.reduce((m,a)=>(m[a.key]=a.value.value,m),{}):{}),v=e.computed(()=>({...r.value?.reduce((a,o)=>{let f=o.rule;return o.required&&!o.rule&&(f={required:!0,message:o.requiredHint?.(o.label)??`${o.label}不能为空`,trigger:["blur"]}),a[o.key]=f,a},{}),...t.rules})),s=e.computed(()=>[...r.value].sort((a,o)=>{const f=a.sort??1/0,d=o.sort??1/0;return Number(f)-Number(d)}));function p(m=null){r.value&&r.value.forEach(a=>{a.value.value=m})}function n(){return new Promise((m,a)=>{u.value?.validate(o=>{o?a(o):m(l.value)})})}if(c({reset:p,validator:n,getResult:(m="res")=>m==="ori"?r.value:l.value}),!t.items)throw new Error("prop items must be not null");return()=>e.createVNode("div",{class:"naiDynamicForm"},[i.header&&e.createVNode("div",{class:"header"},[i.header?.()]),e.createVNode(y.NForm,e.mergeProps({ref:u},t.formConfig,{model:l.value,rules:v.value}),{default(){const m=s.value;return t.preset==="grid"?e.h(y.NGrid,{...t.gridConfig},{default:()=>m?.map(a=>e.h(y.NFormItemGridItem,{label:a.label,path:a.path||a.key},{default:S(a)}))}):m?.map(a=>e.h(y.NFormItem,{label:a.label,path:a.path||a.key},{default:S(a)}))}}),i.footer&&e.h("div",{class:"footer"},i.footer?.())])}});function S(t){return function(){return t.render2?t.render2(t):null}}function k(t,c={},i){const{onChange:u,...r}=i;return e.h(y.NInput,{...r,value:t.value,onUpdateValue:l=>{t.value=l,i?.onChange?.(l,i)},...c})}function x(t,c,i={},u){const{onChange:r,...l}=u;return e.h(y.NSelect,{...l,value:t.value,options:c,onUpdateValue:v=>{t.value=v,u?.onChange?.(v,u,c)},...i})}function F(t,c,i={},u,r){const{value:l,labelField:v,valueField:s,onChange:p,...n}=u,m=v??"label",a=s??"value",o=n.options??c;return e.createVNode(y.NPopselect,{...n,value:t.value,onUpdateValue:f=>{t.value=f,u?.onChange?.(f,u,o)},options:o.map(f=>({...f,label:f[m],value:f[a]})),...i},{default:()=>r??e.createVNode(y.NButton,null,{default:()=>t.value||"请选择"})})}function R(t,c,i={},u){const{valueField:r="value",onChange:l,...v}=u;return e.h(y.NTreeSelect,{...v,value:t.value,options:c,onUpdateValue:s=>{t.value=s,u?.onChange?.(s,u,c)},keyField:r,...i})}function I(t,c,i={},u){const{onChange:r,...l}=u;return e.h(y.NRadioGroup,{...l,value:t.value,onUpdateValue:v=>{t.value=v,u?.onChange?.(v,u,c)},...i},{default:()=>(u?.options??c).map(s=>{const p=u,n=s[p?.labelField??"label"],m=s[p?.valueField??"value"];return e.h(y.NRadio,{...s,label:n,value:m},{default:()=>s.label})})})}function T(t,c,i={},u){const{onChange:r,...l}=u;return e.createVNode(y.NRadioGroup,{...l,value:t.value,onUpdateValue:v=>{t.value=v,u?.onChange?.(v,u,c)},...i},{default:()=>(u?.options??c).map(s=>{const p=u,n=s[p?.labelField??"label"],m=s[p?.valueField??"value"];return e.createVNode(y.NRadioButton,{...s,label:n,value:m},{default:()=>s.label})})})}function A(t,c,i={},u){const{onChange:r,...l}=u;return e.h(y.NCheckboxGroup,{...l,value:t.value,onUpdateValue:v=>{t.value=v,u?.onChange?.(v,u,c)},...i},{default:()=>e.h(y.NSpace,{itemStyle:"display: flex"},{default:()=>(u?.options??c).map(s=>{const p=u,n=s[p?.labelField??"label"],m=s[p?.valueField??"value"];return e.h(y.NCheckbox,{value:m,label:n})})})})}function P(t,c={},i){const{onChange:u,...r}=i;return e.h(y.NSwitch,{...r,value:t.value,onUpdateValue:l=>{t.value=l,i?.onChange?.(l,i)},...c})}function j(t,c={},i){const{onChange:u,...r}=i;return e.h(y.NDatePicker,{...r,value:t.value,onUpdateValue:l=>{t.value=l,i?.onChange?.(l,i)},...c})}function w(t,c={},i){const{onChange:u,...r}=i;return e.h(y.NTimePicker,{...r,value:t.value,onUpdateValue:l=>{t.value=l,i?.onChange?.(l,i)},...c})}function $(t,c=!0){const i={renderInput:r=>k(r.value,r.renderProps??{},r),renderSelect:r=>x(r.value,r.options??[],r.renderProps??{},r),renderPopSelect:r=>F(r.value,r.options??[],r.renderProps??{},r),renderTreeSelect:r=>R(r.value,r.options??[],r.renderProps??{},r),renderRadioGroup:r=>I(r.value,r.options??[],r.renderProps??{},r),renderRadioButtonGroup:r=>T(r.value,r.options??[],r.renderProps??{},r),renderCheckboxGroup:r=>A(r.value,r.options??[],r.renderProps??{},r),renderSwitch:r=>P(r.value,r.renderProps??{},r),renderDatePicker:r=>j(r.value,r.renderProps??{},r),renderTimePicker:r=>w(r.value,r.renderProps??{},r)};return t.map(r=>{const l=r;if(l.value=b.ensureRef(r.value),typeof r.render2=="function")l.render2=r.render2;else if(r.renderType){const v=i[r.renderType];v?l.render2=()=>v(l):console.warn(`[useDecorateForm] unknown renderType: ${r.renderType}`)}else l.render2=()=>i.renderInput(l);return c?e.shallowReactive(l):l})}exports.NaiDynamicCascadeInput=z;exports.NaiDynamicForm=G;exports.NaiDynamicInput=O;exports.renderCheckboxGroup=A;exports.renderDatePicker=j;exports.renderInput=k;exports.renderPopSelect=F;exports.renderRadioButtonGroup=T;exports.renderRadioGroup=I;exports.renderSelect=x;exports.renderSwitch=P;exports.renderTimePicker=w;exports.renderTreeSelect=R;exports.useDecorateForm=$;
|
package/dist/naiveUi/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineComponent as j, ref as A, watch as z, toRaw as S, createVNode as
|
|
2
|
-
import { NInput as N, NButton as p, NForm as U, NGrid as B, NFormItemGridItem as H, NFormItem as q, NSelect as _, NPopselect as E, NTreeSelect as K, NRadioGroup as
|
|
3
|
-
import { t as
|
|
1
|
+
import { defineComponent as j, ref as A, watch as z, toRaw as S, createVNode as s, createTextVNode as C, Fragment as F, nextTick as $, isVNode as L, computed as R, h as b, mergeProps as G, shallowReactive as M } from "vue";
|
|
2
|
+
import { NInput as N, NButton as p, NForm as U, NGrid as B, NFormItemGridItem as H, NFormItem as q, NSelect as _, NPopselect as E, NTreeSelect as K, NRadioGroup as O, NRadio as J, NRadioButton as Q, NCheckboxGroup as W, NSpace as X, NCheckbox as Y, NSwitch as Z, NDatePicker as ee, NTimePicker as le } from "naive-ui";
|
|
3
|
+
import { t as I, r as P, f as w, p as te, s as ne, e as re } from "../index-MF72-iEr.js";
|
|
4
4
|
const Ce = /* @__PURE__ */ j({
|
|
5
5
|
name: "NaiDynamicInput",
|
|
6
6
|
props: {
|
|
@@ -15,7 +15,7 @@ const Ce = /* @__PURE__ */ j({
|
|
|
15
15
|
},
|
|
16
16
|
randomFun: {
|
|
17
17
|
type: Function,
|
|
18
|
-
default: (
|
|
18
|
+
default: (e) => `${Date.now()}_${e ?? 0}`
|
|
19
19
|
},
|
|
20
20
|
btnConfigs: {
|
|
21
21
|
type: Object
|
|
@@ -32,151 +32,151 @@ const Ce = /* @__PURE__ */ j({
|
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
emits: {
|
|
35
|
-
"update:modelValue": (
|
|
35
|
+
"update:modelValue": (e) => !0,
|
|
36
36
|
onReset: () => !0,
|
|
37
|
-
onMerge: (
|
|
37
|
+
onMerge: (e, d) => !0
|
|
38
38
|
},
|
|
39
|
-
setup(
|
|
40
|
-
emit:
|
|
41
|
-
expose:
|
|
39
|
+
setup(e, {
|
|
40
|
+
emit: d,
|
|
41
|
+
expose: c
|
|
42
42
|
}) {
|
|
43
|
-
const
|
|
43
|
+
const u = {
|
|
44
44
|
resetTxt: "重置",
|
|
45
45
|
newTxt: "添加项",
|
|
46
46
|
mergeTxt: "合并",
|
|
47
|
-
...
|
|
48
|
-
},
|
|
47
|
+
...e.btnConfigs
|
|
48
|
+
}, l = {
|
|
49
49
|
hideReset: !1,
|
|
50
50
|
maxHeight: "300px",
|
|
51
51
|
autoScroll: !0,
|
|
52
52
|
allowFilter: !0,
|
|
53
|
-
...
|
|
54
|
-
},
|
|
53
|
+
...e.configs
|
|
54
|
+
}, r = {
|
|
55
55
|
arraySplitSymbol: ",",
|
|
56
|
-
...
|
|
57
|
-
},
|
|
58
|
-
return z(
|
|
59
|
-
if (!
|
|
60
|
-
const
|
|
61
|
-
|
|
56
|
+
...e.dyListConfigs
|
|
57
|
+
}, v = e.size, o = A(I(e.modelValue, e.randomFun, r.arraySplitSymbol)), f = A(null);
|
|
58
|
+
return z(o, (t) => {
|
|
59
|
+
if (!e.isController) return;
|
|
60
|
+
const y = P(t, r.arraySplitSymbol);
|
|
61
|
+
d("update:modelValue", y), d("onMerge", y, S(o.value));
|
|
62
62
|
}, {
|
|
63
63
|
deep: !0
|
|
64
|
-
}),
|
|
65
|
-
onSet: (
|
|
66
|
-
|
|
64
|
+
}), c({
|
|
65
|
+
onSet: (t) => {
|
|
66
|
+
o.value = I(t ?? e.modelValue, e.randomFun, r.arraySplitSymbol);
|
|
67
67
|
},
|
|
68
|
-
getResult: (
|
|
69
|
-
}), () =>
|
|
70
|
-
class:
|
|
71
|
-
}, [
|
|
72
|
-
class: `dyFormList ${
|
|
73
|
-
ref:
|
|
68
|
+
getResult: (t = "res") => t === "ori" ? S(o.value) : P(o.value, r.arraySplitSymbol)
|
|
69
|
+
}), () => s("div", {
|
|
70
|
+
class: e.dyCls ?? `dynamicForm ${v}`
|
|
71
|
+
}, [s("div", {
|
|
72
|
+
class: `dyFormList ${o.value.length ? "" : "noList"}`,
|
|
73
|
+
ref: f,
|
|
74
74
|
style: {
|
|
75
|
-
maxHeight:
|
|
75
|
+
maxHeight: l.maxHeight
|
|
76
76
|
}
|
|
77
|
-
}, [
|
|
77
|
+
}, [o.value.map((t, y, n) => s("div", {
|
|
78
78
|
class: "dItem",
|
|
79
|
-
key:
|
|
80
|
-
}, [
|
|
79
|
+
key: t.rId
|
|
80
|
+
}, [s("div", {
|
|
81
81
|
class: "input"
|
|
82
|
-
}, [
|
|
83
|
-
size:
|
|
84
|
-
value:
|
|
82
|
+
}, [s(N, {
|
|
83
|
+
size: v,
|
|
84
|
+
value: t.key,
|
|
85
85
|
class: "key",
|
|
86
|
-
onInput: (
|
|
87
|
-
|
|
86
|
+
onInput: (a) => {
|
|
87
|
+
t.key = a;
|
|
88
88
|
}
|
|
89
|
-
}, null), C(":"),
|
|
90
|
-
size:
|
|
91
|
-
value:
|
|
89
|
+
}, null), C(":"), s(N, {
|
|
90
|
+
size: v,
|
|
91
|
+
value: t.value,
|
|
92
92
|
class: "value",
|
|
93
|
-
onInput: (
|
|
94
|
-
|
|
93
|
+
onInput: (a) => {
|
|
94
|
+
l.allowFilter && t.isNumber ? t.value = w(a, t.isArray, r.arraySplitSymbol) : t.value = a;
|
|
95
95
|
}
|
|
96
96
|
}, {
|
|
97
|
-
prefix: () =>
|
|
98
|
-
type:
|
|
97
|
+
prefix: () => s(F, null, [s(p, {
|
|
98
|
+
type: t.isArray ? "success" : "default",
|
|
99
99
|
size: "tiny",
|
|
100
100
|
onClick: () => {
|
|
101
|
-
|
|
101
|
+
t.isArray = !t.isArray;
|
|
102
102
|
}
|
|
103
103
|
}, {
|
|
104
104
|
default: () => [C("Array")]
|
|
105
|
-
}), C(" "),
|
|
106
|
-
type:
|
|
105
|
+
}), C(" "), s(p, {
|
|
106
|
+
type: t.isNumber ? "success" : "default",
|
|
107
107
|
size: "tiny",
|
|
108
108
|
onClick: () => {
|
|
109
|
-
|
|
109
|
+
t.isNumber = !t.isNumber;
|
|
110
110
|
}
|
|
111
111
|
}, {
|
|
112
112
|
default: () => [C("Number")]
|
|
113
113
|
})])
|
|
114
|
-
})]),
|
|
114
|
+
})]), s("div", {
|
|
115
115
|
class: "btn"
|
|
116
|
-
}, [
|
|
116
|
+
}, [s(p, {
|
|
117
117
|
type: "success",
|
|
118
|
-
size:
|
|
119
|
-
disabled:
|
|
118
|
+
size: v,
|
|
119
|
+
disabled: y !== n.length - 1,
|
|
120
120
|
onClick: () => {
|
|
121
|
-
|
|
122
|
-
rId:
|
|
121
|
+
o.value.push({
|
|
122
|
+
rId: e.randomFun(),
|
|
123
123
|
key: "",
|
|
124
124
|
value: ""
|
|
125
|
-
}),
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
top:
|
|
125
|
+
}), l.autoScroll && $(() => {
|
|
126
|
+
const a = f.value;
|
|
127
|
+
a?.scrollTo({
|
|
128
|
+
top: a.scrollHeight,
|
|
129
129
|
behavior: "smooth"
|
|
130
130
|
});
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
}, {
|
|
134
134
|
default: () => [C("+")]
|
|
135
|
-
}),
|
|
136
|
-
size:
|
|
135
|
+
}), s(p, {
|
|
136
|
+
size: v,
|
|
137
137
|
type: "error",
|
|
138
138
|
onClick: () => {
|
|
139
|
-
|
|
139
|
+
o.value = o.value.filter((a) => a.rId !== t.rId);
|
|
140
140
|
}
|
|
141
141
|
}, {
|
|
142
142
|
default: () => [C("-")]
|
|
143
|
-
})])]))]),
|
|
144
|
-
class: `control ${
|
|
145
|
-
}, [!
|
|
146
|
-
size:
|
|
143
|
+
})])]))]), s("div", {
|
|
144
|
+
class: `control ${o.value.length ? "" : "noList"}`
|
|
145
|
+
}, [!o.value.length && s(p, {
|
|
146
|
+
size: v,
|
|
147
147
|
type: "success",
|
|
148
148
|
onClick: () => {
|
|
149
|
-
|
|
150
|
-
rId:
|
|
149
|
+
o.value.push({
|
|
150
|
+
rId: e.randomFun(),
|
|
151
151
|
key: "",
|
|
152
152
|
value: ""
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
155
|
}, {
|
|
156
|
-
default: () => [
|
|
157
|
-
}), !
|
|
158
|
-
size:
|
|
156
|
+
default: () => [u.newTxt]
|
|
157
|
+
}), !e.isController && s(F, null, [!l.hideReset && s(p, {
|
|
158
|
+
size: v,
|
|
159
159
|
type: "default",
|
|
160
160
|
onClick: () => {
|
|
161
|
-
|
|
161
|
+
o.value = I(e.modelValue, e.randomFun, r.arraySplitSymbol), d("onReset");
|
|
162
162
|
}
|
|
163
163
|
}, {
|
|
164
|
-
default: () => [
|
|
165
|
-
}),
|
|
166
|
-
size:
|
|
164
|
+
default: () => [u.resetTxt]
|
|
165
|
+
}), s(p, {
|
|
166
|
+
size: v,
|
|
167
167
|
type: "info",
|
|
168
168
|
onClick: () => {
|
|
169
|
-
|
|
170
|
-
const
|
|
171
|
-
|
|
169
|
+
o.value.sort((y, n) => +y.rId - +n.rId);
|
|
170
|
+
const t = P(o.value, r.arraySplitSymbol);
|
|
171
|
+
d("update:modelValue", t), d("onMerge", t, S(o.value)), o.value = I(t, e.randomFun, r.arraySplitSymbol);
|
|
172
172
|
}
|
|
173
173
|
}, {
|
|
174
|
-
default: () => [
|
|
174
|
+
default: () => [u.mergeTxt]
|
|
175
175
|
})])])]);
|
|
176
176
|
}
|
|
177
177
|
});
|
|
178
|
-
function ae(
|
|
179
|
-
return typeof
|
|
178
|
+
function ae(e) {
|
|
179
|
+
return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !L(e);
|
|
180
180
|
}
|
|
181
181
|
const he = /* @__PURE__ */ j({
|
|
182
182
|
name: "NaiveUiDynamicCascadeInput",
|
|
@@ -193,7 +193,7 @@ const he = /* @__PURE__ */ j({
|
|
|
193
193
|
},
|
|
194
194
|
randomFun: {
|
|
195
195
|
type: Function,
|
|
196
|
-
default: (
|
|
196
|
+
default: (e) => `${Date.now()}_${e ?? 0}`
|
|
197
197
|
},
|
|
198
198
|
// 子层深度 (超过则不再出现添加选项)
|
|
199
199
|
depth: {
|
|
@@ -211,24 +211,24 @@ const he = /* @__PURE__ */ j({
|
|
|
211
211
|
},
|
|
212
212
|
newChildTxt: {
|
|
213
213
|
type: Function,
|
|
214
|
-
default: (
|
|
214
|
+
default: (e) => `添加 '${e.key}' 子项`
|
|
215
215
|
}
|
|
216
216
|
},
|
|
217
217
|
emits: {
|
|
218
|
-
"update:modelValue": (
|
|
218
|
+
"update:modelValue": (e) => !0,
|
|
219
219
|
onReset: () => !0,
|
|
220
|
-
onMerge: (
|
|
220
|
+
onMerge: (e, d) => !0
|
|
221
221
|
},
|
|
222
|
-
setup(
|
|
223
|
-
emit:
|
|
224
|
-
expose:
|
|
222
|
+
setup(e, {
|
|
223
|
+
emit: d,
|
|
224
|
+
expose: c
|
|
225
225
|
}) {
|
|
226
|
-
const
|
|
226
|
+
const u = {
|
|
227
227
|
resetTxt: "重置",
|
|
228
228
|
newTxt: "添加项",
|
|
229
229
|
mergeTxt: "合并",
|
|
230
|
-
...
|
|
231
|
-
},
|
|
230
|
+
...e.btnConfigs
|
|
231
|
+
}, l = {
|
|
232
232
|
hideReset: !1,
|
|
233
233
|
maxHeight: "600px",
|
|
234
234
|
allowFilter: !0,
|
|
@@ -236,163 +236,163 @@ const he = /* @__PURE__ */ j({
|
|
|
236
236
|
showPad: !0,
|
|
237
237
|
retractLen: 0,
|
|
238
238
|
borderColors: [],
|
|
239
|
-
...
|
|
240
|
-
},
|
|
239
|
+
...e.configs
|
|
240
|
+
}, r = {
|
|
241
241
|
arraySplitSymbol: ",",
|
|
242
|
-
...
|
|
243
|
-
},
|
|
244
|
-
let
|
|
245
|
-
const h = Array.isArray(
|
|
246
|
-
return
|
|
247
|
-
rId:
|
|
248
|
-
key:
|
|
249
|
-
value: Object.prototype.toString.call(
|
|
242
|
+
...e.dyListConfigs
|
|
243
|
+
}, v = (n) => ["string", "number"].includes(n), o = (n) => Object.keys(n).map((a, m) => {
|
|
244
|
+
let i = n[a];
|
|
245
|
+
const h = Array.isArray(i), T = h ? i.every((x) => typeof x == "number") : typeof i == "number", k = i === null;
|
|
246
|
+
return v(typeof i) && (i = n[a]), k && (i = ""), {
|
|
247
|
+
rId: e.randomFun(m),
|
|
248
|
+
key: a,
|
|
249
|
+
value: Object.prototype.toString.call(i) === "[object Object]" ? o(n[a]) : h ? i.join(r.arraySplitSymbol) : i,
|
|
250
250
|
isArray: h || void 0,
|
|
251
251
|
isNumber: T || void 0
|
|
252
252
|
};
|
|
253
|
-
}),
|
|
254
|
-
const
|
|
255
|
-
return
|
|
256
|
-
}, {}),
|
|
257
|
-
class: [`depth-${
|
|
253
|
+
}), f = (n) => n.reduce((a, m) => {
|
|
254
|
+
const i = m.value;
|
|
255
|
+
return m.key.trim().length && (a[m.key] = Array.isArray(i) ? f(i) : te(m.value, m.isArray, m.isNumber, r.arraySplitSymbol)), a;
|
|
256
|
+
}, {}), t = A(o(e.modelValue)), y = (n, a = 1, m) => s("div", {
|
|
257
|
+
class: [`depth-${a}`, l.showBorder ? "" : "no-border", l.showPad ? "" : "no-pad"],
|
|
258
258
|
style: {
|
|
259
|
-
"--depth":
|
|
260
|
-
["--c" + [
|
|
259
|
+
"--depth": a,
|
|
260
|
+
["--c" + [a]]: ne(l.borderColors, a)
|
|
261
261
|
}
|
|
262
|
-
}, [
|
|
263
|
-
const k = Array.isArray(
|
|
264
|
-
return
|
|
262
|
+
}, [n.map((i, h, T) => {
|
|
263
|
+
const k = Array.isArray(i.value), x = v(typeof i.value);
|
|
264
|
+
return s("div", {
|
|
265
265
|
class: "dItem",
|
|
266
|
-
key:
|
|
266
|
+
key: i.rId,
|
|
267
267
|
style: {
|
|
268
|
-
marginLeft:
|
|
268
|
+
marginLeft: a > 1 ? `${a * l.retractLen}px` : "0"
|
|
269
269
|
}
|
|
270
|
-
}, [
|
|
270
|
+
}, [s("div", {
|
|
271
271
|
class: "input"
|
|
272
|
-
}, [!k &&
|
|
273
|
-
value:
|
|
272
|
+
}, [!k && s(F, null, [s(N, {
|
|
273
|
+
value: i.key,
|
|
274
274
|
class: "key",
|
|
275
|
-
onInput: (g) =>
|
|
276
|
-
}, null), C(":")]),
|
|
275
|
+
onInput: (g) => i.key = g
|
|
276
|
+
}, null), C(":")]), s(N, {
|
|
277
277
|
class: `value ${k ? "isKey" : ""}`,
|
|
278
|
-
value: x ?
|
|
278
|
+
value: x ? i.value : i.key,
|
|
279
279
|
onInput: (g) => {
|
|
280
280
|
if (k) {
|
|
281
|
-
|
|
281
|
+
i.key = g;
|
|
282
282
|
return;
|
|
283
283
|
}
|
|
284
|
-
|
|
284
|
+
l.allowFilter && i.isNumber ? i.value = w(g, i.isArray, r.arraySplitSymbol) : i.value = g;
|
|
285
285
|
}
|
|
286
286
|
}, {
|
|
287
|
-
prefix: Array.isArray(
|
|
288
|
-
type:
|
|
287
|
+
prefix: Array.isArray(i.value) ? void 0 : () => s(F, null, [s(p, {
|
|
288
|
+
type: i.isArray ? "success" : "default",
|
|
289
289
|
size: "tiny",
|
|
290
290
|
onClick: () => {
|
|
291
|
-
|
|
291
|
+
i.isArray = !i.isArray;
|
|
292
292
|
}
|
|
293
293
|
}, {
|
|
294
294
|
default: () => [C("Array")]
|
|
295
|
-
}), C(" "),
|
|
296
|
-
type:
|
|
295
|
+
}), C(" "), s(p, {
|
|
296
|
+
type: i.isNumber ? "success" : "default",
|
|
297
297
|
size: "tiny",
|
|
298
298
|
onClick: () => {
|
|
299
|
-
|
|
299
|
+
i.isNumber = !i.isNumber;
|
|
300
300
|
}
|
|
301
301
|
}, {
|
|
302
302
|
default: () => [C("Number")]
|
|
303
303
|
})]),
|
|
304
304
|
suffix: () => {
|
|
305
305
|
let g;
|
|
306
|
-
return
|
|
306
|
+
return a < e.depth ? !k && s(p, {
|
|
307
307
|
type: "success",
|
|
308
308
|
size: "tiny",
|
|
309
309
|
onClick: () => {
|
|
310
|
-
x && (
|
|
311
|
-
rId:
|
|
310
|
+
x && (i.value = [], i.isArray = void 0), i.value.push({
|
|
311
|
+
rId: e.randomFun(),
|
|
312
312
|
key: "",
|
|
313
313
|
value: ""
|
|
314
314
|
});
|
|
315
315
|
}
|
|
316
|
-
}, ae(g =
|
|
316
|
+
}, ae(g = e.newChildTxt(i)) ? g : {
|
|
317
317
|
default: () => [g]
|
|
318
318
|
}) : null;
|
|
319
319
|
}
|
|
320
|
-
})]),
|
|
320
|
+
})]), s("div", {
|
|
321
321
|
class: "btn"
|
|
322
|
-
}, [
|
|
322
|
+
}, [s(p, {
|
|
323
323
|
type: "success",
|
|
324
324
|
disabled: h !== T.length - 1,
|
|
325
325
|
onClick: () => {
|
|
326
|
-
|
|
327
|
-
rId:
|
|
326
|
+
n.push({
|
|
327
|
+
rId: e.randomFun(),
|
|
328
328
|
key: "",
|
|
329
329
|
value: ""
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
}, {
|
|
333
333
|
default: () => [C("+")]
|
|
334
|
-
}),
|
|
334
|
+
}), s(p, {
|
|
335
335
|
type: "error",
|
|
336
336
|
onClick: () => {
|
|
337
|
-
if (
|
|
338
|
-
if (
|
|
339
|
-
const g =
|
|
340
|
-
|
|
341
|
-
...
|
|
337
|
+
if (n.splice(h, 1), n.length < 1) {
|
|
338
|
+
if (m === void 0) return f([]);
|
|
339
|
+
const g = t.value.findIndex((D) => D.rId === m?.rId);
|
|
340
|
+
a < 1 ? t.value.splice(g, 1, {
|
|
341
|
+
...m,
|
|
342
342
|
value: ""
|
|
343
|
-
}) :
|
|
343
|
+
}) : m.value = "";
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
}, {
|
|
347
347
|
default: () => [C("-")]
|
|
348
|
-
})]), Array.isArray(
|
|
348
|
+
})]), Array.isArray(i.value) && y(i.value, a + 1, i)]);
|
|
349
349
|
})]);
|
|
350
|
-
return z(
|
|
351
|
-
if (!
|
|
352
|
-
const
|
|
353
|
-
|
|
350
|
+
return z(t, (n) => {
|
|
351
|
+
if (!e.isController) return;
|
|
352
|
+
const a = f(n);
|
|
353
|
+
d("update:modelValue", a), d("onMerge", a, S(t.value));
|
|
354
354
|
}, {
|
|
355
355
|
deep: !0
|
|
356
|
-
}),
|
|
357
|
-
onSet: (
|
|
358
|
-
|
|
356
|
+
}), c({
|
|
357
|
+
onSet: (n) => {
|
|
358
|
+
t.value = o(n ?? e.modelValue);
|
|
359
359
|
},
|
|
360
|
-
getResult: (
|
|
361
|
-
}), () =>
|
|
362
|
-
class:
|
|
363
|
-
}, [
|
|
360
|
+
getResult: (n = "res") => n === "ori" ? S(t.value) : f(t.value)
|
|
361
|
+
}), () => s("div", {
|
|
362
|
+
class: e.dyCls ?? "dynamicCascadeForm"
|
|
363
|
+
}, [s("div", {
|
|
364
364
|
class: "dyFormList",
|
|
365
365
|
style: {
|
|
366
|
-
maxHeight:
|
|
366
|
+
maxHeight: l.maxHeight
|
|
367
367
|
}
|
|
368
|
-
}, [
|
|
368
|
+
}, [y(t.value)]), s("div", {
|
|
369
369
|
class: "control"
|
|
370
|
-
}, [!
|
|
370
|
+
}, [!t.value.length && s(p, {
|
|
371
371
|
type: "success",
|
|
372
372
|
onClick: () => {
|
|
373
|
-
|
|
374
|
-
rId:
|
|
373
|
+
t.value.push({
|
|
374
|
+
rId: e.randomFun(),
|
|
375
375
|
key: "",
|
|
376
376
|
value: ""
|
|
377
377
|
});
|
|
378
378
|
}
|
|
379
379
|
}, {
|
|
380
|
-
default: () => [
|
|
381
|
-
}), !
|
|
380
|
+
default: () => [u.newTxt]
|
|
381
|
+
}), !e.isController && s(F, null, [!l.hideReset && s(p, {
|
|
382
382
|
type: "default",
|
|
383
383
|
onClick: () => {
|
|
384
|
-
|
|
384
|
+
t.value = o(e.modelValue), d("onReset");
|
|
385
385
|
}
|
|
386
386
|
}, {
|
|
387
|
-
default: () => [
|
|
388
|
-
}),
|
|
387
|
+
default: () => [u.resetTxt]
|
|
388
|
+
}), s(p, {
|
|
389
389
|
type: "info",
|
|
390
390
|
onClick: () => {
|
|
391
|
-
const
|
|
392
|
-
|
|
391
|
+
const n = f(t.value);
|
|
392
|
+
d("update:modelValue", n), d("onMerge", n, S(t.value)), t.value = o(n);
|
|
393
393
|
}
|
|
394
394
|
}, {
|
|
395
|
-
default: () => [
|
|
395
|
+
default: () => [u.mergeTxt]
|
|
396
396
|
})])])]);
|
|
397
397
|
}
|
|
398
398
|
}), ke = /* @__PURE__ */ j({
|
|
@@ -419,204 +419,214 @@ const he = /* @__PURE__ */ j({
|
|
|
419
419
|
preset: {
|
|
420
420
|
type: String,
|
|
421
421
|
default: "fullRow",
|
|
422
|
-
validator: (
|
|
422
|
+
validator: (e) => ["fullRow", "grid"].includes(e) ? !0 : (console.error("preset value must be `fullRow` or `grid`, the default value is `fullRow`"), !1)
|
|
423
423
|
},
|
|
424
424
|
items: {
|
|
425
425
|
type: Array,
|
|
426
426
|
require: !0
|
|
427
427
|
}
|
|
428
428
|
},
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
expose: d
|
|
429
|
+
slots: Object,
|
|
430
|
+
setup(e, {
|
|
431
|
+
expose: d,
|
|
432
|
+
slots: c
|
|
432
433
|
}) {
|
|
433
|
-
const
|
|
434
|
-
...
|
|
435
|
-
let
|
|
436
|
-
return
|
|
434
|
+
const u = A(null), l = R(() => (e.items ?? []).filter((y) => !y.hidden)), r = R(() => l.value ? l.value.reduce((y, n) => (y[n.key] = n.value.value, y), {}) : {}), v = R(() => ({
|
|
435
|
+
...l.value?.reduce((n, a) => {
|
|
436
|
+
let m = a.rule;
|
|
437
|
+
return a.required && !a.rule && (m = {
|
|
437
438
|
required: !0,
|
|
438
|
-
message: `${
|
|
439
|
+
message: a.requiredHint?.(a.label) ?? `${a.label}不能为空`,
|
|
439
440
|
trigger: ["blur"]
|
|
440
|
-
}),
|
|
441
|
+
}), n[a.key] = m, n;
|
|
441
442
|
}, {}),
|
|
442
|
-
...
|
|
443
|
-
})),
|
|
444
|
-
const
|
|
445
|
-
return Number(
|
|
443
|
+
...e.rules
|
|
444
|
+
})), o = R(() => [...l.value].sort((n, a) => {
|
|
445
|
+
const m = n.sort ?? 1 / 0, i = a.sort ?? 1 / 0;
|
|
446
|
+
return Number(m) - Number(i);
|
|
446
447
|
}));
|
|
447
|
-
function
|
|
448
|
-
|
|
449
|
-
|
|
448
|
+
function f(y = null) {
|
|
449
|
+
l.value && l.value.forEach((n) => {
|
|
450
|
+
n.value.value = y;
|
|
450
451
|
});
|
|
451
452
|
}
|
|
452
|
-
function
|
|
453
|
-
return new Promise((
|
|
454
|
-
|
|
455
|
-
|
|
453
|
+
function t() {
|
|
454
|
+
return new Promise((y, n) => {
|
|
455
|
+
u.value?.validate((a) => {
|
|
456
|
+
a ? n(a) : y(r.value);
|
|
456
457
|
});
|
|
457
458
|
});
|
|
458
459
|
}
|
|
459
460
|
if (d({
|
|
460
|
-
reset:
|
|
461
|
-
validator:
|
|
462
|
-
getResult: (
|
|
463
|
-
}), !
|
|
464
|
-
return () =>
|
|
461
|
+
reset: f,
|
|
462
|
+
validator: t,
|
|
463
|
+
getResult: (y = "res") => y === "ori" ? l.value : r.value
|
|
464
|
+
}), !e.items) throw new Error("prop items must be not null");
|
|
465
|
+
return () => s("div", {
|
|
465
466
|
class: "naiDynamicForm"
|
|
466
|
-
}, [
|
|
467
|
-
|
|
468
|
-
},
|
|
469
|
-
|
|
470
|
-
|
|
467
|
+
}, [c.header && s("div", {
|
|
468
|
+
class: "header"
|
|
469
|
+
}, [c.header?.()]), s(U, G({
|
|
470
|
+
ref: u
|
|
471
|
+
}, e.formConfig, {
|
|
472
|
+
model: r.value,
|
|
473
|
+
rules: v.value
|
|
471
474
|
}), {
|
|
472
475
|
default() {
|
|
473
|
-
const
|
|
474
|
-
return
|
|
475
|
-
...
|
|
476
|
+
const y = o.value;
|
|
477
|
+
return e.preset === "grid" ? b(B, {
|
|
478
|
+
...e.gridConfig
|
|
476
479
|
}, {
|
|
477
|
-
default: () =>
|
|
478
|
-
label:
|
|
479
|
-
path:
|
|
480
|
+
default: () => y?.map((n) => b(H, {
|
|
481
|
+
label: n.label,
|
|
482
|
+
path: n.path || n.key
|
|
480
483
|
}, {
|
|
481
|
-
default: V(
|
|
484
|
+
default: V(n)
|
|
482
485
|
}))
|
|
483
|
-
}) :
|
|
484
|
-
label:
|
|
485
|
-
path:
|
|
486
|
+
}) : y?.map((n) => b(q, {
|
|
487
|
+
label: n.label,
|
|
488
|
+
path: n.path || n.key
|
|
486
489
|
}, {
|
|
487
|
-
default: V(
|
|
490
|
+
default: V(n)
|
|
488
491
|
}));
|
|
489
492
|
}
|
|
490
|
-
})
|
|
493
|
+
}), c.footer && b("div", {
|
|
494
|
+
class: "footer"
|
|
495
|
+
}, c.footer?.())]);
|
|
491
496
|
}
|
|
492
497
|
});
|
|
493
|
-
function V(
|
|
498
|
+
function V(e) {
|
|
494
499
|
return function() {
|
|
495
|
-
return
|
|
500
|
+
return e.render2 ? e.render2(e) : null;
|
|
496
501
|
};
|
|
497
502
|
}
|
|
498
|
-
function ue(
|
|
503
|
+
function ue(e, d = {}, c) {
|
|
504
|
+
const { onChange: u, ...l } = c;
|
|
499
505
|
return b(N, {
|
|
500
|
-
...
|
|
501
|
-
value:
|
|
502
|
-
onUpdateValue: (
|
|
503
|
-
|
|
506
|
+
...l,
|
|
507
|
+
value: e.value,
|
|
508
|
+
onUpdateValue: (r) => {
|
|
509
|
+
e.value = r, c?.onChange?.(r, c);
|
|
504
510
|
},
|
|
505
|
-
...
|
|
511
|
+
...d
|
|
506
512
|
});
|
|
507
513
|
}
|
|
508
|
-
function oe(
|
|
514
|
+
function oe(e, d, c = {}, u) {
|
|
515
|
+
const { onChange: l, ...r } = u;
|
|
509
516
|
return b(_, {
|
|
510
|
-
...
|
|
511
|
-
value:
|
|
512
|
-
options:
|
|
513
|
-
onUpdateValue: (
|
|
514
|
-
|
|
517
|
+
...r,
|
|
518
|
+
value: e.value,
|
|
519
|
+
options: d,
|
|
520
|
+
onUpdateValue: (v) => {
|
|
521
|
+
e.value = v, u?.onChange?.(v, u, d);
|
|
515
522
|
},
|
|
516
|
-
...
|
|
523
|
+
...c
|
|
517
524
|
});
|
|
518
525
|
}
|
|
519
|
-
function se(
|
|
520
|
-
const { value:
|
|
521
|
-
return
|
|
526
|
+
function se(e, d, c = {}, u, l) {
|
|
527
|
+
const { value: r, labelField: v, valueField: o, onChange: f, ...t } = u, y = v ?? "label", n = o ?? "value", a = t.options ?? d;
|
|
528
|
+
return s(
|
|
522
529
|
E,
|
|
523
530
|
{
|
|
524
|
-
...
|
|
525
|
-
value:
|
|
526
|
-
onUpdateValue: (
|
|
527
|
-
|
|
531
|
+
...t,
|
|
532
|
+
value: e.value,
|
|
533
|
+
onUpdateValue: (m) => {
|
|
534
|
+
e.value = m, u?.onChange?.(m, u, a);
|
|
528
535
|
},
|
|
529
|
-
options:
|
|
530
|
-
...
|
|
536
|
+
options: a.map((m) => ({ ...m, label: m[y], value: m[n] })),
|
|
537
|
+
...c
|
|
531
538
|
},
|
|
532
539
|
{
|
|
533
|
-
default: () =>
|
|
534
|
-
default: () =>
|
|
540
|
+
default: () => l ?? s(p, null, {
|
|
541
|
+
default: () => e.value || "请选择"
|
|
535
542
|
})
|
|
536
543
|
}
|
|
537
544
|
);
|
|
538
545
|
}
|
|
539
|
-
function ie(
|
|
540
|
-
const { valueField:
|
|
546
|
+
function ie(e, d, c = {}, u) {
|
|
547
|
+
const { valueField: l = "value", onChange: r, ...v } = u;
|
|
541
548
|
return b(K, {
|
|
542
|
-
...
|
|
543
|
-
value:
|
|
544
|
-
options:
|
|
545
|
-
onUpdateValue: (
|
|
546
|
-
|
|
549
|
+
...v,
|
|
550
|
+
value: e.value,
|
|
551
|
+
options: d,
|
|
552
|
+
onUpdateValue: (o) => {
|
|
553
|
+
e.value = o, u?.onChange?.(o, u, d);
|
|
547
554
|
},
|
|
548
|
-
keyField:
|
|
549
|
-
...
|
|
555
|
+
keyField: l,
|
|
556
|
+
...c
|
|
550
557
|
});
|
|
551
558
|
}
|
|
552
|
-
function de(
|
|
559
|
+
function de(e, d, c = {}, u) {
|
|
560
|
+
const { onChange: l, ...r } = u;
|
|
553
561
|
return b(
|
|
554
|
-
|
|
562
|
+
O,
|
|
555
563
|
{
|
|
556
|
-
...
|
|
557
|
-
value:
|
|
558
|
-
onUpdateValue: (
|
|
559
|
-
|
|
564
|
+
...r,
|
|
565
|
+
value: e.value,
|
|
566
|
+
onUpdateValue: (v) => {
|
|
567
|
+
e.value = v, u?.onChange?.(v, u, d);
|
|
560
568
|
},
|
|
561
|
-
...
|
|
569
|
+
...c
|
|
562
570
|
},
|
|
563
571
|
{
|
|
564
|
-
default: () => (
|
|
565
|
-
const
|
|
572
|
+
default: () => (u?.options ?? d).map((o) => {
|
|
573
|
+
const f = u, t = o[f?.labelField ?? "label"], y = o[f?.valueField ?? "value"];
|
|
566
574
|
return b(
|
|
567
575
|
J,
|
|
568
576
|
{
|
|
569
|
-
...
|
|
570
|
-
label:
|
|
571
|
-
value:
|
|
577
|
+
...o,
|
|
578
|
+
label: t,
|
|
579
|
+
value: y
|
|
572
580
|
},
|
|
573
581
|
{
|
|
574
|
-
default: () =>
|
|
582
|
+
default: () => o.label
|
|
575
583
|
}
|
|
576
584
|
);
|
|
577
585
|
})
|
|
578
586
|
}
|
|
579
587
|
);
|
|
580
588
|
}
|
|
581
|
-
function ce(
|
|
582
|
-
|
|
583
|
-
|
|
589
|
+
function ce(e, d, c = {}, u) {
|
|
590
|
+
const { onChange: l, ...r } = u;
|
|
591
|
+
return s(
|
|
592
|
+
O,
|
|
584
593
|
{
|
|
585
|
-
...
|
|
586
|
-
value:
|
|
587
|
-
onUpdateValue: (
|
|
588
|
-
|
|
594
|
+
...r,
|
|
595
|
+
value: e.value,
|
|
596
|
+
onUpdateValue: (v) => {
|
|
597
|
+
e.value = v, u?.onChange?.(v, u, d);
|
|
589
598
|
},
|
|
590
|
-
...
|
|
599
|
+
...c
|
|
591
600
|
},
|
|
592
601
|
{
|
|
593
|
-
default: () => (
|
|
594
|
-
const
|
|
595
|
-
return
|
|
602
|
+
default: () => (u?.options ?? d).map((o) => {
|
|
603
|
+
const f = u, t = o[f?.labelField ?? "label"], y = o[f?.valueField ?? "value"];
|
|
604
|
+
return s(
|
|
596
605
|
Q,
|
|
597
606
|
{
|
|
598
|
-
...
|
|
599
|
-
label:
|
|
600
|
-
value:
|
|
607
|
+
...o,
|
|
608
|
+
label: t,
|
|
609
|
+
value: y
|
|
601
610
|
},
|
|
602
611
|
{
|
|
603
|
-
default: () =>
|
|
612
|
+
default: () => o.label
|
|
604
613
|
}
|
|
605
614
|
);
|
|
606
615
|
})
|
|
607
616
|
}
|
|
608
617
|
);
|
|
609
618
|
}
|
|
610
|
-
function
|
|
619
|
+
function ve(e, d, c = {}, u) {
|
|
620
|
+
const { onChange: l, ...r } = u;
|
|
611
621
|
return b(
|
|
612
622
|
W,
|
|
613
623
|
{
|
|
614
|
-
...
|
|
615
|
-
value:
|
|
616
|
-
onUpdateValue: (
|
|
617
|
-
|
|
624
|
+
...r,
|
|
625
|
+
value: e.value,
|
|
626
|
+
onUpdateValue: (v) => {
|
|
627
|
+
e.value = v, u?.onChange?.(v, u, d);
|
|
618
628
|
},
|
|
619
|
-
...
|
|
629
|
+
...c
|
|
620
630
|
},
|
|
621
631
|
{
|
|
622
632
|
default: () => b(
|
|
@@ -625,11 +635,11 @@ function ye(l, s, d = {}, n) {
|
|
|
625
635
|
itemStyle: "display: flex"
|
|
626
636
|
},
|
|
627
637
|
{
|
|
628
|
-
default: () => (
|
|
629
|
-
const
|
|
638
|
+
default: () => (u?.options ?? d).map((o) => {
|
|
639
|
+
const f = u, t = o[f?.labelField ?? "label"], y = o[f?.valueField ?? "value"];
|
|
630
640
|
return b(Y, {
|
|
631
|
-
value:
|
|
632
|
-
label:
|
|
641
|
+
value: y,
|
|
642
|
+
label: t
|
|
633
643
|
});
|
|
634
644
|
})
|
|
635
645
|
}
|
|
@@ -637,73 +647,76 @@ function ye(l, s, d = {}, n) {
|
|
|
637
647
|
}
|
|
638
648
|
);
|
|
639
649
|
}
|
|
640
|
-
function
|
|
650
|
+
function ye(e, d = {}, c) {
|
|
651
|
+
const { onChange: u, ...l } = c;
|
|
641
652
|
return b(Z, {
|
|
642
|
-
...
|
|
643
|
-
value:
|
|
644
|
-
onUpdateValue: (
|
|
645
|
-
|
|
653
|
+
...l,
|
|
654
|
+
value: e.value,
|
|
655
|
+
onUpdateValue: (r) => {
|
|
656
|
+
e.value = r, c?.onChange?.(r, c);
|
|
646
657
|
},
|
|
647
|
-
...
|
|
658
|
+
...d
|
|
648
659
|
});
|
|
649
660
|
}
|
|
650
|
-
function me(
|
|
661
|
+
function me(e, d = {}, c) {
|
|
662
|
+
const { onChange: u, ...l } = c;
|
|
651
663
|
return b(ee, {
|
|
652
|
-
...
|
|
653
|
-
value:
|
|
654
|
-
onUpdateValue: (
|
|
655
|
-
|
|
664
|
+
...l,
|
|
665
|
+
value: e.value,
|
|
666
|
+
onUpdateValue: (r) => {
|
|
667
|
+
e.value = r, c?.onChange?.(r, c);
|
|
656
668
|
},
|
|
657
|
-
...
|
|
669
|
+
...d
|
|
658
670
|
});
|
|
659
671
|
}
|
|
660
|
-
function fe(
|
|
672
|
+
function fe(e, d = {}, c) {
|
|
673
|
+
const { onChange: u, ...l } = c;
|
|
661
674
|
return b(le, {
|
|
662
|
-
...
|
|
663
|
-
value:
|
|
664
|
-
onUpdateValue: (
|
|
665
|
-
|
|
675
|
+
...l,
|
|
676
|
+
value: e.value,
|
|
677
|
+
onUpdateValue: (r) => {
|
|
678
|
+
e.value = r, c?.onChange?.(r, c);
|
|
666
679
|
},
|
|
667
|
-
...
|
|
680
|
+
...d
|
|
668
681
|
});
|
|
669
682
|
}
|
|
670
|
-
function Se(
|
|
671
|
-
const
|
|
672
|
-
renderInput: (
|
|
673
|
-
renderSelect: (
|
|
674
|
-
renderPopSelect: (
|
|
675
|
-
renderTreeSelect: (
|
|
676
|
-
renderRadioGroup: (
|
|
677
|
-
renderRadioButtonGroup: (
|
|
678
|
-
renderCheckboxGroup: (
|
|
679
|
-
renderSwitch: (
|
|
680
|
-
renderDatePicker: (
|
|
681
|
-
renderTimePicker: (
|
|
683
|
+
function Se(e, d = !0) {
|
|
684
|
+
const c = {
|
|
685
|
+
renderInput: (l) => ue(l.value, l.renderProps ?? {}, l),
|
|
686
|
+
renderSelect: (l) => oe(l.value, l.options ?? [], l.renderProps ?? {}, l),
|
|
687
|
+
renderPopSelect: (l) => se(l.value, l.options ?? [], l.renderProps ?? {}, l),
|
|
688
|
+
renderTreeSelect: (l) => ie(l.value, l.options ?? [], l.renderProps ?? {}, l),
|
|
689
|
+
renderRadioGroup: (l) => de(l.value, l.options ?? [], l.renderProps ?? {}, l),
|
|
690
|
+
renderRadioButtonGroup: (l) => ce(l.value, l.options ?? [], l.renderProps ?? {}, l),
|
|
691
|
+
renderCheckboxGroup: (l) => ve(l.value, l.options ?? [], l.renderProps ?? {}, l),
|
|
692
|
+
renderSwitch: (l) => ye(l.value, l.renderProps ?? {}, l),
|
|
693
|
+
renderDatePicker: (l) => me(l.value, l.renderProps ?? {}, l),
|
|
694
|
+
renderTimePicker: (l) => fe(l.value, l.renderProps ?? {}, l)
|
|
682
695
|
};
|
|
683
|
-
return
|
|
684
|
-
const
|
|
685
|
-
if (
|
|
686
|
-
|
|
687
|
-
else if (
|
|
688
|
-
const
|
|
689
|
-
|
|
696
|
+
return e.map((l) => {
|
|
697
|
+
const r = l;
|
|
698
|
+
if (r.value = re(l.value), typeof l.render2 == "function")
|
|
699
|
+
r.render2 = l.render2;
|
|
700
|
+
else if (l.renderType) {
|
|
701
|
+
const v = c[l.renderType];
|
|
702
|
+
v ? r.render2 = () => v(r) : console.warn(`[useDecorateForm] unknown renderType: ${l.renderType}`);
|
|
690
703
|
} else
|
|
691
|
-
|
|
692
|
-
return
|
|
704
|
+
r.render2 = () => c.renderInput(r);
|
|
705
|
+
return d ? M(r) : r;
|
|
693
706
|
});
|
|
694
707
|
}
|
|
695
708
|
export {
|
|
696
709
|
he as NaiDynamicCascadeInput,
|
|
697
710
|
ke as NaiDynamicForm,
|
|
698
711
|
Ce as NaiDynamicInput,
|
|
699
|
-
|
|
712
|
+
ve as renderCheckboxGroup,
|
|
700
713
|
me as renderDatePicker,
|
|
701
714
|
ue as renderInput,
|
|
702
715
|
se as renderPopSelect,
|
|
703
716
|
ce as renderRadioButtonGroup,
|
|
704
717
|
de as renderRadioGroup,
|
|
705
718
|
oe as renderSelect,
|
|
706
|
-
|
|
719
|
+
ye as renderSwitch,
|
|
707
720
|
fe as renderTimePicker,
|
|
708
721
|
ie as renderTreeSelect,
|
|
709
722
|
Se as useDecorateForm
|
package/dist/types/form.d.ts
CHANGED
|
@@ -20,9 +20,9 @@ export interface DyFormItem<K = any, RuleT = any> extends BaseDyFormItem<K> {
|
|
|
20
20
|
path?: string;
|
|
21
21
|
hidden?: boolean;
|
|
22
22
|
render2?: (formItem: DyFormItem) => VNode;
|
|
23
|
-
reset?: (formItem: DyFormItem) => void;
|
|
24
23
|
rule?: RuleT;
|
|
25
24
|
required?: boolean;
|
|
25
|
+
requiredHint?: (label: string) => string;
|
|
26
26
|
disabled?: Ref<boolean> | boolean;
|
|
27
27
|
clearable?: boolean;
|
|
28
28
|
type?: "text" | "textarea" | "password";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { DyFormItem } from './form.ts';
|
|
2
|
+
import { VNode } from 'vue';
|
|
3
|
+
export * from './form.ts';
|
|
2
4
|
export type DyCFormItem = {
|
|
3
5
|
rId: string;
|
|
4
6
|
key: string;
|
|
@@ -36,8 +38,13 @@ export type ExposeType = {
|
|
|
36
38
|
onSet?: (obj?: object) => void;
|
|
37
39
|
getResult?: (t?: 'res' | 'ori') => DyCFormItem[] | object;
|
|
38
40
|
};
|
|
41
|
+
export type PresetType = 'fullRow' | 'grid';
|
|
39
42
|
export type ExposeDyFType = {
|
|
40
43
|
reset?: (v?: any) => void;
|
|
41
44
|
validator: () => Promise<object>;
|
|
42
45
|
getResult?: (t?: 'res' | 'ori') => DyFormItem[] | object;
|
|
43
46
|
};
|
|
47
|
+
export interface DynamicFormSlots {
|
|
48
|
+
header?: () => VNode[];
|
|
49
|
+
footer?: () => VNode[];
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dynamicformdjx",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "xczcdjx",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
"import": "./dist/index.mjs",
|
|
23
23
|
"require": "./dist/index.cjs"
|
|
24
24
|
},
|
|
25
|
+
"./types/*": {
|
|
26
|
+
"types": "./dist/types/*.d.ts"
|
|
27
|
+
},
|
|
25
28
|
"./naiveUi": {
|
|
26
29
|
"types": "./dist/naiveUi/index.d.ts",
|
|
27
30
|
"import": "./dist/naiveUi/index.mjs",
|