@blueking/bkui-form 1.0.1-beta.1 → 1.0.1-beta.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/esm/adapter/common/FieldGroupWrap.tsx.js +199 -0
- package/esm/adapter/field/ArrayField.tsx.js +55 -0
- package/esm/adapter/field/BooleanField.tsx.js +41 -0
- package/esm/adapter/field/CompositionField.tsx.js +113 -0
- package/esm/adapter/field/FieldProps.ts.js +85 -0
- package/esm/adapter/field/NumberField.tsx.js +19 -0
- package/esm/adapter/field/ObjectField.tsx.js +58 -0
- package/esm/adapter/field/SchemaField.tsx.js +28 -0
- package/esm/adapter/field/StringField.tsx.js +4 -0
- package/esm/adapter/widget/ArrayWidget.ts.js +196 -0
- package/esm/adapter/widget/ButtonWidget.ts.js +76 -0
- package/esm/adapter/widget/CheckboxWidget.ts.js +101 -0
- package/esm/adapter/widget/CollapseGroupWidget.ts.js +140 -0
- package/esm/adapter/widget/ColorPickerWidget.ts.js +71 -0
- package/esm/adapter/widget/InputWidget.ts.js +79 -0
- package/esm/adapter/widget/KeyValueArrayWidget.tsx.js +156 -0
- package/esm/adapter/widget/RadioWidget.ts.js +98 -0
- package/esm/adapter/widget/SelectWidget.ts.js +98 -0
- package/esm/adapter/widget/SwitchWidget.ts.js +73 -0
- package/esm/adapter/widget/TabGroupWidget.ts.js +145 -0
- package/esm/adapter/widget/TableWidget.ts.js +205 -0
- package/esm/adapter/widget/Widget.ts.js +497 -0
- package/esm/assets/fonts/iconcool.eot +0 -0
- package/esm/assets/fonts/iconcool.ttf +0 -0
- package/esm/assets/fonts/iconcool.woff +0 -0
- package/esm/assets/style.css +43 -0
- package/esm/controller/form.css +164 -0
- package/esm/controller/form.tsx.js +159 -0
- package/esm/controller/props.ts.js +75 -0
- package/esm/core/events.ts.js +74 -0
- package/esm/core/expression.ts.js +67 -0
- package/esm/core/lang.ts.js +25 -0
- package/esm/core/layout.ts.js +149 -0
- package/esm/core/path.ts.js +60 -0
- package/esm/core/proxy.ts.js +10 -0
- package/esm/core/reaction.ts.js +116 -0
- package/esm/core/register.ts.js +74 -0
- package/esm/core/schema.ts.js +302 -0
- package/esm/core/validator.ts.js +248 -0
- package/esm/core/widgetTree.ts.js +163 -0
- package/esm/index.ts.js +6 -0
- package/esm/node_modules/@blueking/cli-service/dist/lib/path.js +35 -0
- package/esm/node_modules/@blueking/cli-service/dist/lib/util.js +233 -0
- package/esm/node_modules/@blueking/cli-service/dist/tools/rust/helper/path.js +172 -0
- package/esm/node_modules/ajv/dist/ajv.js +50 -0
- package/esm/node_modules/ajv/dist/compile/codegen/code.js +156 -0
- package/esm/node_modules/ajv/dist/compile/codegen/index.js +697 -0
- package/esm/node_modules/ajv/dist/compile/codegen/scope.js +143 -0
- package/esm/node_modules/ajv/dist/compile/errors.js +123 -0
- package/esm/node_modules/ajv/dist/compile/index.js +242 -0
- package/esm/node_modules/ajv/dist/compile/names.js +28 -0
- package/esm/node_modules/ajv/dist/compile/ref_error.js +12 -0
- package/esm/node_modules/ajv/dist/compile/resolve.js +155 -0
- package/esm/node_modules/ajv/dist/compile/rules.js +26 -0
- package/esm/node_modules/ajv/dist/compile/util.js +178 -0
- package/esm/node_modules/ajv/dist/compile/validate/applicability.js +19 -0
- package/esm/node_modules/ajv/dist/compile/validate/boolSchema.js +50 -0
- package/esm/node_modules/ajv/dist/compile/validate/dataType.js +203 -0
- package/esm/node_modules/ajv/dist/compile/validate/defaults.js +35 -0
- package/esm/node_modules/ajv/dist/compile/validate/index.js +520 -0
- package/esm/node_modules/ajv/dist/compile/validate/keyword.js +124 -0
- package/esm/node_modules/ajv/dist/compile/validate/subschema.js +81 -0
- package/esm/node_modules/ajv/dist/core.js +618 -0
- package/esm/node_modules/ajv/dist/refs/data.json +13 -0
- package/esm/node_modules/ajv/dist/refs/json-schema-draft-07.json +151 -0
- package/esm/node_modules/ajv/dist/runtime/equal.js +7 -0
- package/esm/node_modules/ajv/dist/runtime/ucs2length.js +24 -0
- package/esm/node_modules/ajv/dist/runtime/uri.js +6 -0
- package/esm/node_modules/ajv/dist/runtime/validation_error.js +11 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +49 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +106 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/allOf.js +23 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +12 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/contains.js +95 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +85 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/if.js +66 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +44 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/items.js +52 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/items2020.js +30 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/not.js +26 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +60 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +75 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +12 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/properties.js +54 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +38 -0
- package/esm/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +13 -0
- package/esm/node_modules/ajv/dist/vocabularies/code.js +131 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/id.js +10 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/index.js +16 -0
- package/esm/node_modules/ajv/dist/vocabularies/core/ref.js +122 -0
- package/esm/node_modules/ajv/dist/vocabularies/discriminator/index.js +104 -0
- package/esm/node_modules/ajv/dist/vocabularies/discriminator/types.js +9 -0
- package/esm/node_modules/ajv/dist/vocabularies/draft7.js +17 -0
- package/esm/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
- package/esm/node_modules/ajv/dist/vocabularies/format/index.js +6 -0
- package/esm/node_modules/ajv/dist/vocabularies/metadata.js +18 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/const.js +25 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/enum.js +48 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/index.js +33 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitItems.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitLength.js +27 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +27 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +26 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/pattern.js +24 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/required.js +79 -0
- package/esm/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +64 -0
- package/esm/node_modules/ajv-formats/dist/formats.js +173 -0
- package/esm/node_modules/ajv-formats/dist/index.js +37 -0
- package/esm/node_modules/ajv-formats/dist/limit.js +69 -0
- package/esm/node_modules/ajv-i18n/localize/zh/index.js +154 -0
- package/esm/node_modules/fast-deep-equal/index.js +46 -0
- package/esm/node_modules/fast-uri/index.js +303 -0
- package/esm/node_modules/fast-uri/lib/schemes.js +188 -0
- package/esm/node_modules/fast-uri/lib/scopedChars.js +30 -0
- package/esm/node_modules/fast-uri/lib/utils.js +244 -0
- package/esm/node_modules/json-schema-traverse/index.js +89 -0
- package/esm/node_modules/semver/classes/comparator.js +143 -0
- package/esm/node_modules/semver/classes/range.js +557 -0
- package/esm/node_modules/semver/classes/semver.js +333 -0
- package/esm/node_modules/semver/functions/clean.js +8 -0
- package/esm/node_modules/semver/functions/cmp.js +54 -0
- package/esm/node_modules/semver/functions/coerce.js +62 -0
- package/esm/node_modules/semver/functions/compare-build.js +9 -0
- package/esm/node_modules/semver/functions/compare-loose.js +5 -0
- package/esm/node_modules/semver/functions/compare.js +7 -0
- package/esm/node_modules/semver/functions/diff.js +60 -0
- package/esm/node_modules/semver/functions/eq.js +5 -0
- package/esm/node_modules/semver/functions/gt.js +5 -0
- package/esm/node_modules/semver/functions/gte.js +5 -0
- package/esm/node_modules/semver/functions/inc.js +21 -0
- package/esm/node_modules/semver/functions/lt.js +5 -0
- package/esm/node_modules/semver/functions/lte.js +5 -0
- package/esm/node_modules/semver/functions/major.js +5 -0
- package/esm/node_modules/semver/functions/minor.js +5 -0
- package/esm/node_modules/semver/functions/neq.js +5 -0
- package/esm/node_modules/semver/functions/parse.js +18 -0
- package/esm/node_modules/semver/functions/patch.js +5 -0
- package/esm/node_modules/semver/functions/prerelease.js +8 -0
- package/esm/node_modules/semver/functions/rcompare.js +5 -0
- package/esm/node_modules/semver/functions/rsort.js +5 -0
- package/esm/node_modules/semver/functions/satisfies.js +12 -0
- package/esm/node_modules/semver/functions/sort.js +5 -0
- package/esm/node_modules/semver/functions/valid.js +8 -0
- package/esm/node_modules/semver/index.js +91 -0
- package/esm/node_modules/semver/internal/constants.js +37 -0
- package/esm/node_modules/semver/internal/debug.js +11 -0
- package/esm/node_modules/semver/internal/identifiers.js +29 -0
- package/esm/node_modules/semver/internal/lrucache.js +42 -0
- package/esm/node_modules/semver/internal/parse-options.js +17 -0
- package/esm/node_modules/semver/internal/re.js +223 -0
- package/esm/node_modules/semver/ranges/gtr.js +6 -0
- package/esm/node_modules/semver/ranges/intersects.js +9 -0
- package/esm/node_modules/semver/ranges/ltr.js +6 -0
- package/esm/node_modules/semver/ranges/max-satisfying.js +27 -0
- package/esm/node_modules/semver/ranges/min-satisfying.js +26 -0
- package/esm/node_modules/semver/ranges/min-version.js +63 -0
- package/esm/node_modules/semver/ranges/outside.js +82 -0
- package/esm/node_modules/semver/ranges/simplify.js +49 -0
- package/esm/node_modules/semver/ranges/subset.js +249 -0
- package/esm/node_modules/semver/ranges/to-comparators.js +10 -0
- package/esm/node_modules/semver/ranges/valid.js +13 -0
- package/esm/util/fetch.ts.js +190 -0
- package/esm/util/index.ts.js +276 -0
- package/package.json +3 -4
- package/dist/main.css +0 -208
- package/dist/main.js +0 -17353
- /package/{dist/svg/iconcool.eb237688.svg → esm/assets/fonts/iconcool.svg} +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
.bk-schema-form {
|
|
2
|
+
font-size: 12px;
|
|
3
|
+
.mb10 {
|
|
4
|
+
margin-bottom: 10px;
|
|
5
|
+
}
|
|
6
|
+
.mb0 {
|
|
7
|
+
margin-bottom: 0px;
|
|
8
|
+
}
|
|
9
|
+
.mt5 {
|
|
10
|
+
margin-top: 5px;
|
|
11
|
+
}
|
|
12
|
+
.mr24 {
|
|
13
|
+
margin-right: 24px;
|
|
14
|
+
}
|
|
15
|
+
.mr5 {
|
|
16
|
+
margin-right: 5px;
|
|
17
|
+
}
|
|
18
|
+
.pr20 {
|
|
19
|
+
padding-right: 20px;
|
|
20
|
+
}
|
|
21
|
+
.bk-form-item {
|
|
22
|
+
margin-top: unset !important;
|
|
23
|
+
margin-bottom: unset !important;
|
|
24
|
+
}
|
|
25
|
+
.bk-schema-form-group.normal {
|
|
26
|
+
padding: 24px;
|
|
27
|
+
position: relative;
|
|
28
|
+
}
|
|
29
|
+
.bk-schema-form-group.card{
|
|
30
|
+
background: #fff;
|
|
31
|
+
padding: 0 24px 24px 24px;
|
|
32
|
+
border-radius: 2px;
|
|
33
|
+
}
|
|
34
|
+
.bk-schema-form-group.hide-empty-row .bk-schema-form-group-content {
|
|
35
|
+
row-gap: 0 !important;
|
|
36
|
+
}
|
|
37
|
+
.bk-schema-form-group.hide-empty-row .bk-schema-form-group-content .bk-form-item {
|
|
38
|
+
margin-bottom: 20px;
|
|
39
|
+
}
|
|
40
|
+
.bk-schema-form-group--error {
|
|
41
|
+
border-color: #f5222d !important;
|
|
42
|
+
}
|
|
43
|
+
.bk-schema-form-group__error-tips{
|
|
44
|
+
position: relative;
|
|
45
|
+
display: block;
|
|
46
|
+
width: 10px;
|
|
47
|
+
height: 10px;
|
|
48
|
+
}
|
|
49
|
+
.bk-schema-form-group__error-tips-popover {
|
|
50
|
+
position: absolute;
|
|
51
|
+
top: -5px;
|
|
52
|
+
left: 0;
|
|
53
|
+
z-index: 1;
|
|
54
|
+
background: #fff;
|
|
55
|
+
border: 1px solid #f5222d;
|
|
56
|
+
color: #f5222d;
|
|
57
|
+
font-size: 12px;
|
|
58
|
+
margin-left: 10px;
|
|
59
|
+
font-weight: normal;
|
|
60
|
+
padding: 5px 10px;
|
|
61
|
+
border-radius: 2px;
|
|
62
|
+
max-height: 50px;
|
|
63
|
+
overflow:hidden;
|
|
64
|
+
}
|
|
65
|
+
.bk-schema-form-group__error-tips-popover:hover {
|
|
66
|
+
max-height: unset;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.bk-schema-form-group__error-tips-popover > p {
|
|
70
|
+
padding: 0;
|
|
71
|
+
margin: 0;
|
|
72
|
+
white-space: nowrap;
|
|
73
|
+
}
|
|
74
|
+
.bk-schema-form-group .bk-schema-form-group-title {
|
|
75
|
+
font-size: 14px;
|
|
76
|
+
font-weight: 600;
|
|
77
|
+
color: #63656E;
|
|
78
|
+
}
|
|
79
|
+
.bk-schema-form-group .bk-schema-form-group-title.default {
|
|
80
|
+
display: inline-block;
|
|
81
|
+
margin-bottom: 10px;
|
|
82
|
+
}
|
|
83
|
+
.bk-schema-form-group .bk-schema-form-group-title.normal {
|
|
84
|
+
position: absolute;
|
|
85
|
+
top: -1em;
|
|
86
|
+
left: 10px;
|
|
87
|
+
line-height: 2em;
|
|
88
|
+
padding: 0 0.5em;
|
|
89
|
+
background: #fff;
|
|
90
|
+
}
|
|
91
|
+
.bk-schema-form-group .bk-schema-form-group-title.card{
|
|
92
|
+
display: flex;
|
|
93
|
+
height: 50px;
|
|
94
|
+
align-items: center;
|
|
95
|
+
padding: 0 24px;
|
|
96
|
+
margin: 0 -24px 8px -24px;
|
|
97
|
+
}
|
|
98
|
+
.bk-schema-form-group-add {
|
|
99
|
+
font-size: 14px;
|
|
100
|
+
color: #3a84ff;
|
|
101
|
+
cursor: pointer;
|
|
102
|
+
display: flex;
|
|
103
|
+
align-items: center;
|
|
104
|
+
}
|
|
105
|
+
.bk-schema-form-group-delete {
|
|
106
|
+
display: flex;
|
|
107
|
+
align-items: center;
|
|
108
|
+
justify-content: center;
|
|
109
|
+
position: absolute;
|
|
110
|
+
right: 8px;
|
|
111
|
+
top: 6px;
|
|
112
|
+
cursor: pointer;
|
|
113
|
+
color: #979bA5;
|
|
114
|
+
font-size: 14px;
|
|
115
|
+
}
|
|
116
|
+
.bk-schema-form-group-delete:hover {
|
|
117
|
+
color: #3a84ff;
|
|
118
|
+
}
|
|
119
|
+
.bk-schema-form-reset-default {
|
|
120
|
+
display: inline-flex;
|
|
121
|
+
align-items: center;
|
|
122
|
+
justify-content: center;
|
|
123
|
+
margin-left: 8px;
|
|
124
|
+
cursor: pointer;
|
|
125
|
+
color: #979bA5;
|
|
126
|
+
font-size: 14px;
|
|
127
|
+
}
|
|
128
|
+
.bk-schema-form-reset-default:hover {
|
|
129
|
+
color: #3a84ff;
|
|
130
|
+
}
|
|
131
|
+
.bk-schema-form-label-description {
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
border-bottom: 1px dashed #979ba5;
|
|
134
|
+
}
|
|
135
|
+
.bk-schema-form-item__error-tips {
|
|
136
|
+
color: #f5222d;
|
|
137
|
+
font-size: 12px;
|
|
138
|
+
margin-top: 5px;
|
|
139
|
+
margin: 0;
|
|
140
|
+
line-height: 1.5em;
|
|
141
|
+
}
|
|
142
|
+
.bk-schema-form-item--error .bk-input,
|
|
143
|
+
.bk-schema-form-item--error .bk-textarea-wrapper,
|
|
144
|
+
.bk-schema-form-item--error .bk-select {
|
|
145
|
+
border: 1px solid #f5222d;
|
|
146
|
+
box-shadow: none;
|
|
147
|
+
}
|
|
148
|
+
.bk-schema-form-item-auto-height .bk-form-content {
|
|
149
|
+
min-height: auto;
|
|
150
|
+
line-height: 1;
|
|
151
|
+
}
|
|
152
|
+
.table-widget-actions .action-btn {
|
|
153
|
+
margin-right: 8px;
|
|
154
|
+
font-size: 14px;
|
|
155
|
+
cursor: pointer;
|
|
156
|
+
}
|
|
157
|
+
.table-widget-actions .action-btn:hover {
|
|
158
|
+
color: #3a84ff;
|
|
159
|
+
}
|
|
160
|
+
.is-disabled .action-btn {
|
|
161
|
+
color: #dcdee5 !important;
|
|
162
|
+
cursor: not-allowed;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { defineComponent, h } from 'vue';
|
|
2
|
+
import { merge, deepEquals, mergeDeep, hasOwnProperty } from '../util/index.ts.js';
|
|
3
|
+
import registry, { Registry } from '../core/register.ts.js';
|
|
4
|
+
import Schema from '../core/schema.ts.js';
|
|
5
|
+
import Layout from '../core/layout.ts.js';
|
|
6
|
+
import createProxy from '../core/proxy.ts.js';
|
|
7
|
+
import Path from '../core/path.ts.js';
|
|
8
|
+
import props from './props.ts.js';
|
|
9
|
+
import SchemaField from '../adapter/field/SchemaField.tsx.js';
|
|
10
|
+
import ObjectField from '../adapter/field/ObjectField.tsx.js';
|
|
11
|
+
import NumberField from '../adapter/field/NumberField.tsx.js';
|
|
12
|
+
import StringField from '../adapter/field/StringField.tsx.js';
|
|
13
|
+
import ArrayField from '../adapter/field/ArrayField.tsx.js';
|
|
14
|
+
import BooleanField from '../adapter/field/BooleanField.tsx.js';
|
|
15
|
+
import CompositionField from '../adapter/field/CompositionField.tsx.js';
|
|
16
|
+
import CheckboxWidget from '../adapter/widget/CheckboxWidget.ts.js';
|
|
17
|
+
import SelectWidget from '../adapter/widget/SelectWidget.ts.js';
|
|
18
|
+
import RadioWidget from '../adapter/widget/RadioWidget.ts.js';
|
|
19
|
+
import ButtonWidget from '../adapter/widget/ButtonWidget.ts.js';
|
|
20
|
+
import TableWidget from '../adapter/widget/TableWidget.ts.js';
|
|
21
|
+
import FieldGroupWrap from '../adapter/common/FieldGroupWrap.tsx.js';
|
|
22
|
+
import KeyValueArrayWidget from '../adapter/widget/KeyValueArrayWidget.tsx.js';
|
|
23
|
+
import TabGroupWidget from '../adapter/widget/TabGroupWidget.ts.js';
|
|
24
|
+
import CollapseGroupWidget from '../adapter/widget/CollapseGroupWidget.ts.js';
|
|
25
|
+
import SwitcherWidget from '../adapter/widget/SwitchWidget.ts.js';
|
|
26
|
+
import ColorWidget from '../adapter/widget/ColorPickerWidget.ts.js';
|
|
27
|
+
import InputWidget from '../adapter/widget/InputWidget.ts.js';
|
|
28
|
+
import './form.css';
|
|
29
|
+
import { registryGlobalRules, validateForm, validateFormItem, validateFormWithResult, validateSchema, DEFAULT_RULES } from '../core/validator.ts.js';
|
|
30
|
+
const defaultOptions = {
|
|
31
|
+
namespace: 'bk',
|
|
32
|
+
// 包装组件库组件(添加一些属性方便配置)
|
|
33
|
+
components: {
|
|
34
|
+
button: ButtonWidget,
|
|
35
|
+
select: SelectWidget,
|
|
36
|
+
radio: RadioWidget,
|
|
37
|
+
checkbox: CheckboxWidget,
|
|
38
|
+
table: TableWidget,
|
|
39
|
+
group: FieldGroupWrap,
|
|
40
|
+
bfArray: KeyValueArrayWidget,
|
|
41
|
+
tab: TabGroupWidget,
|
|
42
|
+
collapse: CollapseGroupWidget,
|
|
43
|
+
switcher: SwitcherWidget,
|
|
44
|
+
color: ColorWidget,
|
|
45
|
+
bfInput: InputWidget
|
|
46
|
+
},
|
|
47
|
+
fields: {
|
|
48
|
+
object: ObjectField,
|
|
49
|
+
string: StringField,
|
|
50
|
+
any: '',
|
|
51
|
+
array: ArrayField,
|
|
52
|
+
boolean: BooleanField,
|
|
53
|
+
null: '',
|
|
54
|
+
integer: NumberField,
|
|
55
|
+
number: NumberField,
|
|
56
|
+
composition: CompositionField
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
export default function createForm(opts = {}) {
|
|
60
|
+
const options = mergeDeep(defaultOptions, opts);
|
|
61
|
+
const { namespace, components, fields, baseWidgets = {} } = options;
|
|
62
|
+
Registry.namespace = namespace;
|
|
63
|
+
registry.addComponentsMap(components);
|
|
64
|
+
registry.addFieldsMap(fields);
|
|
65
|
+
registry.addBaseWidgets(baseWidgets);
|
|
66
|
+
return defineComponent({
|
|
67
|
+
name: 'BkuiForm',
|
|
68
|
+
props,
|
|
69
|
+
data () {
|
|
70
|
+
return {
|
|
71
|
+
rootData: {},
|
|
72
|
+
formKey: 'bk-ui-form'
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
watch: {
|
|
76
|
+
schema (newSchema, oldSchema) {
|
|
77
|
+
if (JSON.stringify(newSchema) === JSON.stringify(oldSchema)) return;
|
|
78
|
+
this.validateSchema(this.schema);
|
|
79
|
+
this.initFormData();
|
|
80
|
+
this.formKey = `bk-ui-form-${new Date().getTime()}`;
|
|
81
|
+
},
|
|
82
|
+
context: {
|
|
83
|
+
handler (ctx) {
|
|
84
|
+
Registry.context = ctx;
|
|
85
|
+
if (hasOwnProperty(ctx, 'rules')) {
|
|
86
|
+
registryGlobalRules(ctx.rules);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
immediate: true
|
|
90
|
+
},
|
|
91
|
+
rules: {
|
|
92
|
+
immediate: true,
|
|
93
|
+
handler (value) {
|
|
94
|
+
registryGlobalRules(value);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
modelValue () {
|
|
98
|
+
this.initFormData();
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
beforeCreate () {
|
|
102
|
+
registryGlobalRules(DEFAULT_RULES);
|
|
103
|
+
},
|
|
104
|
+
created () {
|
|
105
|
+
this.validateSchema(this.schema);
|
|
106
|
+
this.initFormData();
|
|
107
|
+
},
|
|
108
|
+
methods: {
|
|
109
|
+
initFormData () {
|
|
110
|
+
this.rootData = merge(Schema.getSchemaDefaultValue(createProxy(this.schema, this)) || {}, this.modelValue);
|
|
111
|
+
this.emitFormValueChange(this.rootData, this.modelValue);
|
|
112
|
+
},
|
|
113
|
+
emitFormValueChange (newValue, oldValue) {
|
|
114
|
+
if (!deepEquals(newValue, oldValue)) {
|
|
115
|
+
this.rootData = newValue;
|
|
116
|
+
this.$emit('update:modelValue', newValue);
|
|
117
|
+
this.$emit('change', newValue, oldValue);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
validateForm,
|
|
121
|
+
validateFormItem,
|
|
122
|
+
validate: validateFormWithResult,
|
|
123
|
+
validateSchema
|
|
124
|
+
},
|
|
125
|
+
render () {
|
|
126
|
+
const self = this;
|
|
127
|
+
return h(registry.getBaseWidget('form'), {
|
|
128
|
+
ref: 'bkui-form',
|
|
129
|
+
key: this.formKey,
|
|
130
|
+
model: this.modelValue,
|
|
131
|
+
formType: this.formType,
|
|
132
|
+
labelWidth: this.labelWidth,
|
|
133
|
+
class: {
|
|
134
|
+
'bk-schema-form': true
|
|
135
|
+
},
|
|
136
|
+
style: {
|
|
137
|
+
width: typeof this.width === 'number' ? `${this.width}px` : this.width
|
|
138
|
+
}
|
|
139
|
+
}, {
|
|
140
|
+
default: ()=>h(SchemaField, Object.assign(Object.assign({}, this.$props), {
|
|
141
|
+
schema: createProxy(this.schema, this),
|
|
142
|
+
rootData: this.rootData,
|
|
143
|
+
modelValue: this.modelValue,
|
|
144
|
+
layout: new Layout(this.layout).layout,
|
|
145
|
+
'onUpdate:modelValue': ({ path = '', value })=>{
|
|
146
|
+
if (!path) {
|
|
147
|
+
// console.warn('set rootData');
|
|
148
|
+
self.emitFormValueChange(value, self.modelValue);
|
|
149
|
+
} else {
|
|
150
|
+
// 双向绑定逻辑
|
|
151
|
+
const newValue = Path.setPathValue(self.rootData, path, value);
|
|
152
|
+
self.emitFormValueChange(newValue, self.modelValue);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}), this.$slots)
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import request from '../util/fetch.ts.js';
|
|
2
|
+
export default {
|
|
3
|
+
// 表单值
|
|
4
|
+
modelValue: {
|
|
5
|
+
type: Object,
|
|
6
|
+
default: ()=>({})
|
|
7
|
+
},
|
|
8
|
+
rules: {
|
|
9
|
+
type: Object,
|
|
10
|
+
default: ()=>({})
|
|
11
|
+
},
|
|
12
|
+
schema: {
|
|
13
|
+
type: Object,
|
|
14
|
+
default: ()=>({})
|
|
15
|
+
},
|
|
16
|
+
width: {
|
|
17
|
+
type: [
|
|
18
|
+
String,
|
|
19
|
+
Number
|
|
20
|
+
],
|
|
21
|
+
default: '100%'
|
|
22
|
+
},
|
|
23
|
+
// 表单布局
|
|
24
|
+
layout: {
|
|
25
|
+
type: [
|
|
26
|
+
Array,
|
|
27
|
+
Object
|
|
28
|
+
],
|
|
29
|
+
default: ()=>[]
|
|
30
|
+
},
|
|
31
|
+
// 表单类型
|
|
32
|
+
formType: {
|
|
33
|
+
type: String,
|
|
34
|
+
default: 'default'
|
|
35
|
+
},
|
|
36
|
+
// 表单全局上下文
|
|
37
|
+
context: {
|
|
38
|
+
type: Object,
|
|
39
|
+
default: ()=>({})
|
|
40
|
+
},
|
|
41
|
+
// http请求适配器
|
|
42
|
+
httpAdapter: {
|
|
43
|
+
type: Object,
|
|
44
|
+
default: ()=>({
|
|
45
|
+
request,
|
|
46
|
+
responseParse: (res)=>res
|
|
47
|
+
})
|
|
48
|
+
},
|
|
49
|
+
readonly: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: false
|
|
52
|
+
},
|
|
53
|
+
// 透传 disabled 属性
|
|
54
|
+
disabled: {
|
|
55
|
+
type: Boolean,
|
|
56
|
+
default: false
|
|
57
|
+
},
|
|
58
|
+
readonlyMode: {
|
|
59
|
+
type: String,
|
|
60
|
+
default: 'value',
|
|
61
|
+
validator: (value)=>[
|
|
62
|
+
'value',
|
|
63
|
+
'custom'
|
|
64
|
+
].includes(value)
|
|
65
|
+
},
|
|
66
|
+
labelWidth: {
|
|
67
|
+
type: Number,
|
|
68
|
+
default: 150
|
|
69
|
+
},
|
|
70
|
+
// 全局配置:是否显示恢复默认值按钮
|
|
71
|
+
showResetDefault: {
|
|
72
|
+
type: Boolean,
|
|
73
|
+
default: false
|
|
74
|
+
}
|
|
75
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// 事件订阅器
|
|
2
|
+
function _define_property(obj, key, value) {
|
|
3
|
+
if (key in obj) {
|
|
4
|
+
Object.defineProperty(obj, key, {
|
|
5
|
+
value: value,
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true
|
|
9
|
+
});
|
|
10
|
+
} else {
|
|
11
|
+
obj[key] = value;
|
|
12
|
+
}
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
15
|
+
export class FormEvent {
|
|
16
|
+
on(path, type, cb) {
|
|
17
|
+
if (!(path in this.callbacks)) {
|
|
18
|
+
this.callbacks[path] = {};
|
|
19
|
+
}
|
|
20
|
+
if (!(type in this.callbacks[path])) {
|
|
21
|
+
this.callbacks[path][type] = [];
|
|
22
|
+
}
|
|
23
|
+
this.callbacks[path][type].push(cb);
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
off(path, type, cb) {
|
|
27
|
+
if (!(path && type)) {
|
|
28
|
+
// 参数全部为空,清空callbacks
|
|
29
|
+
this.callbacks = Object.create(null);
|
|
30
|
+
} else if (path && !type) {
|
|
31
|
+
// 清空当前path所有事件
|
|
32
|
+
delete this.callbacks[path];
|
|
33
|
+
} else if (path && type && !cb) {
|
|
34
|
+
// 清空当前type的所有事件
|
|
35
|
+
delete this.callbacks[path][type];
|
|
36
|
+
} else {
|
|
37
|
+
// 清空对应事件
|
|
38
|
+
const events = this.callbacks[path][type];
|
|
39
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
40
|
+
for(const index in events){
|
|
41
|
+
if (cb === events[index]) {
|
|
42
|
+
events.splice(Number(index), 1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
once(path, type, cb) {
|
|
49
|
+
const _this = this;
|
|
50
|
+
function innerOnce(...arg) {
|
|
51
|
+
cb(...arg);
|
|
52
|
+
_this.off(path, type, innerOnce);
|
|
53
|
+
}
|
|
54
|
+
innerOnce.fn = cb;
|
|
55
|
+
this.on(path, type, innerOnce);
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
emit(path, type, ...arg) {
|
|
59
|
+
if (!this.callbacks[path]) return;
|
|
60
|
+
if (type in this.callbacks[path]) {
|
|
61
|
+
const runs = [
|
|
62
|
+
...this.callbacks[path][type]
|
|
63
|
+
];
|
|
64
|
+
for (const cb of runs){
|
|
65
|
+
cb(...arg);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
constructor(){
|
|
70
|
+
_define_property(this, "callbacks", void 0);
|
|
71
|
+
this.callbacks = Object.create(null);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
export default new FormEvent();
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */ import { isObj } from '../util/index.ts.js';
|
|
2
|
+
import { Registry } from './register.ts.js';
|
|
3
|
+
// 组件对外暴露的上下文
|
|
4
|
+
export const getContext = (instance)=>{
|
|
5
|
+
const { context, loadDataSource, validate, schema, rootData, widgetNode } = instance;
|
|
6
|
+
return {
|
|
7
|
+
$self: instance,
|
|
8
|
+
$context: context,
|
|
9
|
+
$schema: schema,
|
|
10
|
+
$rules: schema.rules,
|
|
11
|
+
$loadDataSource: loadDataSource,
|
|
12
|
+
$validate: validate,
|
|
13
|
+
$rootData: rootData,
|
|
14
|
+
$widgetNode: widgetNode
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export const executeExpression = (expression, instance, $dep = [])=>{
|
|
18
|
+
const { $self, $context, $schema, $rules, $loadDataSource, $validate, $rootData, $widgetNode } = getContext(instance);
|
|
19
|
+
const context = {
|
|
20
|
+
$self,
|
|
21
|
+
$context,
|
|
22
|
+
$schema,
|
|
23
|
+
$rules,
|
|
24
|
+
$loadDataSource,
|
|
25
|
+
$validate,
|
|
26
|
+
$rootData,
|
|
27
|
+
$widgetNode,
|
|
28
|
+
$dep
|
|
29
|
+
};
|
|
30
|
+
if (typeof expression === 'string') {
|
|
31
|
+
if (!/^{{.+}}$/.test(expression.trim())) return expression; // 没有上下文时直接返回
|
|
32
|
+
const expStr = expression.trim().replace(/(^{{)|(}}$)/g, '') // 去掉{{ }}
|
|
33
|
+
.trim();
|
|
34
|
+
const innerFuncs = [
|
|
35
|
+
'$loadDataSource',
|
|
36
|
+
'$validate'
|
|
37
|
+
];
|
|
38
|
+
const func = function({ $self, $context, $schema, $rules, $loadDataSource, $validate, $rootData, $widgetNode, $dep }) {
|
|
39
|
+
try {
|
|
40
|
+
// eslint-disable-next-line no-eval
|
|
41
|
+
return innerFuncs.includes(expStr) ? eval(`${expStr}()`) : eval(expStr);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.error(`execute ${expStr} error, please check. \n`, err);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return func(context);
|
|
47
|
+
}
|
|
48
|
+
if (isObj(expression)) {
|
|
49
|
+
Object.keys(expression).forEach((key)=>{
|
|
50
|
+
expression[key] = executeExpression(expression[key], instance);
|
|
51
|
+
});
|
|
52
|
+
return expression;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
// 解析字符串模板(无上下文时使用,只能解析context内容)
|
|
56
|
+
export const parseStrTemplate = (expression)=>{
|
|
57
|
+
const $context = Registry.context;
|
|
58
|
+
const expStr = expression.trim().replace(/(^{{)|(}}$)/g, '').trim();
|
|
59
|
+
try {
|
|
60
|
+
// eslint-disable-next-line no-new-func
|
|
61
|
+
const func = new Function('$context', `return ${expStr}`);
|
|
62
|
+
return func($context);
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.error(`parse template ${expression} error`, err);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
export const isExpression = (expression)=>typeof expression === 'string' && /{{.*}}/.test(expression);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getCookie } from '../util/index.ts.js';
|
|
2
|
+
const messages = {
|
|
3
|
+
'zh-CN': {
|
|
4
|
+
add: '添加'
|
|
5
|
+
},
|
|
6
|
+
'en-US': {
|
|
7
|
+
add: 'Add'
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export default function locale(item) {
|
|
11
|
+
var _messages_curLang;
|
|
12
|
+
let curLang = getCookie('blueking_language') || 'zh-CN';
|
|
13
|
+
if ([
|
|
14
|
+
'en-US',
|
|
15
|
+
'enUS',
|
|
16
|
+
'enus',
|
|
17
|
+
'en-us',
|
|
18
|
+
'en'
|
|
19
|
+
].includes(curLang)) {
|
|
20
|
+
curLang = 'en-US';
|
|
21
|
+
} else {
|
|
22
|
+
curLang = 'zh-CN';
|
|
23
|
+
}
|
|
24
|
+
return ((_messages_curLang = messages[curLang]) === null || _messages_curLang === void 0 ? void 0 : _messages_curLang[item]) || '';
|
|
25
|
+
}
|