@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,199 @@
|
|
|
1
|
+
import { createVNode as _createVNode } from "vue";
|
|
2
|
+
import widgetTree from '../../core/widgetTree.ts.js';
|
|
3
|
+
import { h, defineComponent, withDirectives } from 'vue';
|
|
4
|
+
import props from '../field/FieldProps.ts.js';
|
|
5
|
+
import Schema from '../../core/schema.ts.js';
|
|
6
|
+
import { deepEquals } from '../../util/index.ts.js';
|
|
7
|
+
import { bkTooltips } from 'bkui-vue';
|
|
8
|
+
export default defineComponent({
|
|
9
|
+
name: 'FieldGroupWrap',
|
|
10
|
+
props: Object.assign(Object.assign({}, props), {
|
|
11
|
+
// 组类型
|
|
12
|
+
type: {
|
|
13
|
+
type: String,
|
|
14
|
+
default: 'default',
|
|
15
|
+
validator: (value)=>[
|
|
16
|
+
'default',
|
|
17
|
+
'normal',
|
|
18
|
+
'card'
|
|
19
|
+
].includes(value)
|
|
20
|
+
},
|
|
21
|
+
// 是否显示组title
|
|
22
|
+
showTitle: {
|
|
23
|
+
type: Boolean,
|
|
24
|
+
default: false
|
|
25
|
+
},
|
|
26
|
+
// 是否显示border
|
|
27
|
+
border: {
|
|
28
|
+
type: Boolean,
|
|
29
|
+
default: false
|
|
30
|
+
},
|
|
31
|
+
verifiable: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: false
|
|
34
|
+
},
|
|
35
|
+
hideEmptyRow: {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
default: false
|
|
38
|
+
},
|
|
39
|
+
showResetDefault: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
default: false
|
|
42
|
+
}
|
|
43
|
+
}),
|
|
44
|
+
data () {
|
|
45
|
+
return {
|
|
46
|
+
groupErrorTips: {},
|
|
47
|
+
state: {
|
|
48
|
+
// 组类型目前只支持visible
|
|
49
|
+
visible: true
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
computed: {
|
|
54
|
+
// 兼容以前数据结构
|
|
55
|
+
value () {
|
|
56
|
+
return this.modelValue;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
created () {
|
|
60
|
+
// 注册widget TreeNode
|
|
61
|
+
widgetTree.addWidgetNode(this.path, this, 'group');
|
|
62
|
+
},
|
|
63
|
+
mounted () {
|
|
64
|
+
// 更新样式
|
|
65
|
+
this.$forceUpdate();
|
|
66
|
+
},
|
|
67
|
+
beforeUnmount () {
|
|
68
|
+
widgetTree.removeWidgetNode(this.path, this);
|
|
69
|
+
},
|
|
70
|
+
methods: {
|
|
71
|
+
setState (key, value) {
|
|
72
|
+
if (Reflect.has(this.state, key)) {
|
|
73
|
+
this.state[key] = value;
|
|
74
|
+
} else {
|
|
75
|
+
console.warn(`Group unsupported ${key} state, please check`);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
setGroupErrorTips (widgetPath, errorTips) {
|
|
79
|
+
this.groupErrorTips[widgetPath] = errorTips;
|
|
80
|
+
},
|
|
81
|
+
removeGroupErrorTips (widgetPath) {
|
|
82
|
+
delete this.groupErrorTips[widgetPath];
|
|
83
|
+
},
|
|
84
|
+
clearGroupErrorTips () {
|
|
85
|
+
this.groupErrorTips = {};
|
|
86
|
+
},
|
|
87
|
+
// 获取 schema 中定义的默认值
|
|
88
|
+
getDefaultValue () {
|
|
89
|
+
return Schema.getSchemaDefaultValue(this.schema);
|
|
90
|
+
},
|
|
91
|
+
// 恢复默认值
|
|
92
|
+
resetToDefault () {
|
|
93
|
+
const defaultValue = this.getDefaultValue();
|
|
94
|
+
this.$emit('update:modelValue', {
|
|
95
|
+
path: this.path,
|
|
96
|
+
value: defaultValue
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
// 判断当前值是否与默认值相同
|
|
100
|
+
isDefaultValue () {
|
|
101
|
+
const defaultValue = this.getDefaultValue();
|
|
102
|
+
return deepEquals(this.modelValue, defaultValue);
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
render () {
|
|
106
|
+
var _a, _b, _c, _d, _e, _f;
|
|
107
|
+
const schemaFormStyle = Object.assign({
|
|
108
|
+
position: 'relative',
|
|
109
|
+
border: this.border ? '1px solid #dcdee5' : 'none',
|
|
110
|
+
display: !this.state.visible ? 'none' : ''
|
|
111
|
+
}, ((_a = this.layout) === null || _a === void 0 ? void 0 : _a.item) || {});
|
|
112
|
+
const groupContentStyle = Object.assign({}, ((_b = this.layout) === null || _b === void 0 ? void 0 : _b.container) || {
|
|
113
|
+
display: 'grid',
|
|
114
|
+
gridGap: '24px' // 未设置layout的布局组的默认样式
|
|
115
|
+
});
|
|
116
|
+
const self = this;
|
|
117
|
+
const renderDelete = ()=>h('span', {
|
|
118
|
+
class: [
|
|
119
|
+
'bk-schema-form-group-delete'
|
|
120
|
+
],
|
|
121
|
+
onClick () {
|
|
122
|
+
self.$emit('remove', self.path);
|
|
123
|
+
}
|
|
124
|
+
}, [
|
|
125
|
+
h('i', {
|
|
126
|
+
class: [
|
|
127
|
+
'bk-form-icon icon-close3-shape'
|
|
128
|
+
]
|
|
129
|
+
})
|
|
130
|
+
]);
|
|
131
|
+
const title = ((_c = this.schema) === null || _c === void 0 ? void 0 : _c.title) || ((_d = this.layout) === null || _d === void 0 ? void 0 : _d.prop);
|
|
132
|
+
const groupErrorTipsContent = Object.keys(this.groupErrorTips).map((widgetPath)=>_createVNode("p", null, [
|
|
133
|
+
this.groupErrorTips[widgetPath]
|
|
134
|
+
]));
|
|
135
|
+
const hasError = JSON.stringify(this.groupErrorTips) !== '{}';
|
|
136
|
+
// 渲染恢复默认值按钮
|
|
137
|
+
const renderResetDefault = ()=>{
|
|
138
|
+
// 不显示恢复默认值按钮,或者当前值已经是默认值
|
|
139
|
+
if (!this.showResetDefault || this.isDefaultValue() || this.readonly || this.disabled) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return withDirectives(h('span', {
|
|
143
|
+
class: [
|
|
144
|
+
'bk-schema-form-reset-default',
|
|
145
|
+
'bk-form-icon icon-reset'
|
|
146
|
+
],
|
|
147
|
+
onClick: ()=>{
|
|
148
|
+
self.resetToDefault();
|
|
149
|
+
}
|
|
150
|
+
}), [
|
|
151
|
+
[
|
|
152
|
+
bkTooltips,
|
|
153
|
+
{
|
|
154
|
+
content: '恢复默认值'
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
]);
|
|
158
|
+
};
|
|
159
|
+
return _createVNode("div", {
|
|
160
|
+
"class": [
|
|
161
|
+
'bk-schema-form-group',
|
|
162
|
+
this.type,
|
|
163
|
+
{
|
|
164
|
+
'hide-empty-row': this.hideEmptyRow
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
'bk-schema-form-group--error': hasError
|
|
168
|
+
}
|
|
169
|
+
],
|
|
170
|
+
"style": schemaFormStyle
|
|
171
|
+
}, [
|
|
172
|
+
title && this.showTitle ? _createVNode("span", {
|
|
173
|
+
"class": [
|
|
174
|
+
'bk-schema-form-group-title',
|
|
175
|
+
this.type
|
|
176
|
+
]
|
|
177
|
+
}, [
|
|
178
|
+
title,
|
|
179
|
+
renderResetDefault(),
|
|
180
|
+
hasError ? _createVNode("span", {
|
|
181
|
+
"class": "bk-schema-form-group__error-tips"
|
|
182
|
+
}, [
|
|
183
|
+
_createVNode("span", {
|
|
184
|
+
"class": "bk-schema-form-group__error-tips-popover"
|
|
185
|
+
}, [
|
|
186
|
+
groupErrorTipsContent
|
|
187
|
+
])
|
|
188
|
+
]) : null
|
|
189
|
+
]) : null,
|
|
190
|
+
_createVNode("div", {
|
|
191
|
+
"style": groupContentStyle,
|
|
192
|
+
"class": "bk-schema-form-group-content"
|
|
193
|
+
}, [
|
|
194
|
+
(_f = (_e = this.$slots) === null || _e === void 0 ? void 0 : _e.default) === null || _f === void 0 ? void 0 : _f.call(_e)
|
|
195
|
+
]),
|
|
196
|
+
this.removeable && renderDelete()
|
|
197
|
+
]);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __rest = this && this.__rest || function(s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
4
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for(var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++){
|
|
5
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
6
|
+
}
|
|
7
|
+
return t;
|
|
8
|
+
};
|
|
9
|
+
import Schema from '../../core/schema.ts.js';
|
|
10
|
+
import { defineComponent, h } from 'vue';
|
|
11
|
+
import props from './FieldProps.ts.js';
|
|
12
|
+
import Widget from '../widget/Widget.ts.js';
|
|
13
|
+
import SchemaField from './SchemaField.tsx.js';
|
|
14
|
+
import Path from '../../core/path.ts.js';
|
|
15
|
+
import { mergeDeep } from '../../util/index.ts.js';
|
|
16
|
+
import ArrayWidget from '../widget/ArrayWidget.ts.js';
|
|
17
|
+
export default defineComponent({
|
|
18
|
+
name: 'ArrayField',
|
|
19
|
+
props,
|
|
20
|
+
render () {
|
|
21
|
+
const { schema, path } = this.$props;
|
|
22
|
+
if (Schema.isMultiSelect(schema) || Schema.isCustomArrayWidget(schema)) {
|
|
23
|
+
// 多选类型 或 自定义数组类型(伪数组类型(只有一个FormItem,但是值为数组,值一般由自定义Widget控件决定))
|
|
24
|
+
return h(Widget, Object.assign(Object.assign(Object.assign({}, this.$props), this.$attrs), {
|
|
25
|
+
key: path,
|
|
26
|
+
schema: mergeDeep({
|
|
27
|
+
'ui:component': {
|
|
28
|
+
multiple: true
|
|
29
|
+
}
|
|
30
|
+
}, this.$props.schema)
|
|
31
|
+
}), this.$slots);
|
|
32
|
+
}
|
|
33
|
+
// 元组类型
|
|
34
|
+
if (Schema.isTupleArray(schema)) {
|
|
35
|
+
const _a = Schema.getGroupWrap(schema), { name } = _a, vnode = __rest(_a, [
|
|
36
|
+
"name"
|
|
37
|
+
]);
|
|
38
|
+
const tupleVnodeList = schema.items.map((item, index)=>h(SchemaField, Object.assign(Object.assign(Object.assign({}, this.$props), this.$attrs), {
|
|
39
|
+
key: Path.getCurPath(path, index),
|
|
40
|
+
schema: item,
|
|
41
|
+
path: Path.getCurPath(path, index)
|
|
42
|
+
}), this.$slots));
|
|
43
|
+
return h(name, mergeDeep(Object.assign(Object.assign({}, this.$props), {
|
|
44
|
+
path,
|
|
45
|
+
showTitle: true
|
|
46
|
+
}), vnode), {
|
|
47
|
+
default: ()=>[
|
|
48
|
+
...tupleVnodeList
|
|
49
|
+
]
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
// 一般数组类型
|
|
53
|
+
return h(ArrayWidget, Object.assign(Object.assign({}, this.$attrs), this.$props), this.$slots);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { defineComponent, h } from 'vue';
|
|
2
|
+
import props from './FieldProps.ts.js';
|
|
3
|
+
import Widget from '../widget/Widget.ts.js';
|
|
4
|
+
import { mergeDeep } from '../../util/index.ts.js';
|
|
5
|
+
export default defineComponent({
|
|
6
|
+
name: 'BooleanField',
|
|
7
|
+
props,
|
|
8
|
+
render () {
|
|
9
|
+
var _a;
|
|
10
|
+
const { name } = this.$props.schema['ui:component'] || {};
|
|
11
|
+
let widgetProps = {};
|
|
12
|
+
if ([
|
|
13
|
+
'radio',
|
|
14
|
+
'select'
|
|
15
|
+
].includes(name)) {
|
|
16
|
+
// radioGroup、select类型需要默认数据源
|
|
17
|
+
widgetProps = {
|
|
18
|
+
datasource: [
|
|
19
|
+
{
|
|
20
|
+
label: 'False',
|
|
21
|
+
value: false
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: 'True',
|
|
25
|
+
value: true
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
};
|
|
29
|
+
} else if (name === 'checkbox') {
|
|
30
|
+
// boolean 类型checkbox
|
|
31
|
+
widgetProps = {
|
|
32
|
+
label: (_a = this.$props.schema) === null || _a === void 0 ? void 0 : _a.title
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return h(Widget, Object.assign(Object.assign(Object.assign({}, this.$props), this.$attrs), {
|
|
36
|
+
schema: mergeDeep({
|
|
37
|
+
'ui:component': Object.assign({}, widgetProps)
|
|
38
|
+
}, this.$props.schema)
|
|
39
|
+
}), this.$slots);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var __rest = this && this.__rest || function(s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
4
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for(var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++){
|
|
5
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
6
|
+
}
|
|
7
|
+
return t;
|
|
8
|
+
};
|
|
9
|
+
import Path from '../../core/path.ts.js';
|
|
10
|
+
import register from '../../core/register.ts.js';
|
|
11
|
+
import Schema from '../../core/schema.ts.js';
|
|
12
|
+
import { isObj, mergeDeep } from '../../util/index.ts.js';
|
|
13
|
+
import { defineComponent, h } from 'vue';
|
|
14
|
+
import props from './FieldProps.ts.js';
|
|
15
|
+
import SchemaField from './SchemaField.tsx.js';
|
|
16
|
+
import Widget from '../widget/Widget.ts.js';
|
|
17
|
+
import { ajv } from '../../core/validator.ts.js';
|
|
18
|
+
export default defineComponent({
|
|
19
|
+
name: 'CompositionField',
|
|
20
|
+
props: Object.assign({}, props),
|
|
21
|
+
data () {
|
|
22
|
+
return {
|
|
23
|
+
activeIndex: -1
|
|
24
|
+
};
|
|
25
|
+
},
|
|
26
|
+
computed: {
|
|
27
|
+
composition () {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
if ((_a = this.schema.anyOf) === null || _a === void 0 ? void 0 : _a.length) {
|
|
30
|
+
return 'anyOf';
|
|
31
|
+
}
|
|
32
|
+
if ((_b = this.schema.oneOf) === null || _b === void 0 ? void 0 : _b.length) {
|
|
33
|
+
return 'oneOf';
|
|
34
|
+
}
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
created () {
|
|
39
|
+
// 初始化默认 composition 选项
|
|
40
|
+
const compositionList = this.schema[this.composition] || [];
|
|
41
|
+
// 没有required选项时回显不成功
|
|
42
|
+
const index = compositionList.findIndex((item)=>ajv.validate(item, this.modelValue));
|
|
43
|
+
this.activeIndex = index > -1 ? index : 0;
|
|
44
|
+
},
|
|
45
|
+
render () {
|
|
46
|
+
const compositionList = this.schema[this.composition] || [];
|
|
47
|
+
const schemaList = compositionList.map((item)=>{
|
|
48
|
+
const data = mergeDeep({}, this.schema, item);
|
|
49
|
+
delete data[this.composition];
|
|
50
|
+
return data;
|
|
51
|
+
});
|
|
52
|
+
const _a = Schema.getUiProps(`ui:${this.composition}`, this.schema), { name: com = 'radio' } = _a, // 默认用radio组件
|
|
53
|
+
vnodeData = __rest(_a, [
|
|
54
|
+
"name"
|
|
55
|
+
]);
|
|
56
|
+
const isConst = typeof this.schema.type !== 'object' && schemaList.every((item)=>item.const);
|
|
57
|
+
if (isConst) {
|
|
58
|
+
// 全是常量
|
|
59
|
+
return h(Widget, Object.assign(Object.assign({}, this.$props), this.$attrs), this.$slots);
|
|
60
|
+
}
|
|
61
|
+
const compositionVnodeData = __rest(Schema.getUiProps('ui:composition', this.schema), []);
|
|
62
|
+
return h(register.getComponent('group'), mergeDeep(Object.assign(Object.assign({}, this.$props), {
|
|
63
|
+
rootData: this.rootData,
|
|
64
|
+
schema: this.schema,
|
|
65
|
+
modelValue: Path.getPathVal(this.rootData, this.path),
|
|
66
|
+
path: this.path,
|
|
67
|
+
onRemove () {
|
|
68
|
+
this.$emit('remove', this.path);
|
|
69
|
+
}
|
|
70
|
+
}), compositionVnodeData), {
|
|
71
|
+
default: ()=>[
|
|
72
|
+
// anyOf component
|
|
73
|
+
h(register.getBaseWidget('form-item'), {
|
|
74
|
+
label: vnodeData === null || vnodeData === void 0 ? void 0 : vnodeData.title
|
|
75
|
+
}, {
|
|
76
|
+
default: ()=>h(register.getComponent(com), mergeDeep({
|
|
77
|
+
modelValue: this.activeIndex,
|
|
78
|
+
datasource: schemaList.map((item, index)=>({
|
|
79
|
+
label: item.title || '',
|
|
80
|
+
value: index
|
|
81
|
+
})),
|
|
82
|
+
clearable: false,
|
|
83
|
+
'onUpdate:modelValue': (index)=>{
|
|
84
|
+
this.activeIndex = index;
|
|
85
|
+
// 删除其他 composition 字段
|
|
86
|
+
if (isObj(this.modelValue)) {
|
|
87
|
+
const newValue = JSON.parse(JSON.stringify(this.modelValue));
|
|
88
|
+
const props = compositionList.filter((_, index)=>index !== this.activeIndex).reduce((pre, item)=>{
|
|
89
|
+
const { properties = {} } = item;
|
|
90
|
+
pre.push(...Object.keys(properties));
|
|
91
|
+
return pre;
|
|
92
|
+
}, []);
|
|
93
|
+
props.forEach((prop)=>{
|
|
94
|
+
delete newValue[prop];
|
|
95
|
+
});
|
|
96
|
+
this.$emit('update:modelValue', {
|
|
97
|
+
path: this.path,
|
|
98
|
+
value: newValue
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}, vnodeData || {}))
|
|
103
|
+
}),
|
|
104
|
+
// schema
|
|
105
|
+
h(SchemaField, Object.assign(Object.assign(Object.assign({}, this.$props), this.$attrs), {
|
|
106
|
+
key: this.activeIndex,
|
|
107
|
+
removeable: false,
|
|
108
|
+
schema: schemaList[this.activeIndex]
|
|
109
|
+
}), this.$slots)
|
|
110
|
+
]
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import request from '../../util/fetch.ts.js';
|
|
2
|
+
export default {
|
|
3
|
+
// 当前项shema
|
|
4
|
+
schema: {
|
|
5
|
+
type: Object,
|
|
6
|
+
default: ()=>({})
|
|
7
|
+
},
|
|
8
|
+
// 当前路径(唯一标识)
|
|
9
|
+
path: {
|
|
10
|
+
type: String,
|
|
11
|
+
default: ''
|
|
12
|
+
},
|
|
13
|
+
// 是否必须字段
|
|
14
|
+
required: {
|
|
15
|
+
type: Boolean,
|
|
16
|
+
default: false
|
|
17
|
+
},
|
|
18
|
+
// 全量数据(只读)
|
|
19
|
+
rootData: {
|
|
20
|
+
type: Object,
|
|
21
|
+
default: ()=>({})
|
|
22
|
+
},
|
|
23
|
+
// 当前值
|
|
24
|
+
modelValue: {
|
|
25
|
+
type: [
|
|
26
|
+
String,
|
|
27
|
+
Number,
|
|
28
|
+
Array,
|
|
29
|
+
Object,
|
|
30
|
+
Boolean
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
// 布局配置
|
|
34
|
+
layout: {
|
|
35
|
+
type: Object,
|
|
36
|
+
default: ()=>({})
|
|
37
|
+
},
|
|
38
|
+
// 当前全局变量上下文
|
|
39
|
+
context: {
|
|
40
|
+
type: Object,
|
|
41
|
+
default: ()=>({})
|
|
42
|
+
},
|
|
43
|
+
// 当前项是否可移除
|
|
44
|
+
removeable: {
|
|
45
|
+
type: Boolean,
|
|
46
|
+
default: false
|
|
47
|
+
},
|
|
48
|
+
// http请求适配器
|
|
49
|
+
httpAdapter: {
|
|
50
|
+
type: Object,
|
|
51
|
+
default: ()=>({
|
|
52
|
+
request,
|
|
53
|
+
responseParse: (res)=>res
|
|
54
|
+
})
|
|
55
|
+
},
|
|
56
|
+
visible: {
|
|
57
|
+
type: Boolean,
|
|
58
|
+
default: true
|
|
59
|
+
},
|
|
60
|
+
error: {
|
|
61
|
+
type: Boolean,
|
|
62
|
+
default: false
|
|
63
|
+
},
|
|
64
|
+
disabled: {
|
|
65
|
+
type: Boolean,
|
|
66
|
+
default: false
|
|
67
|
+
},
|
|
68
|
+
readonly: {
|
|
69
|
+
type: Boolean,
|
|
70
|
+
default: false
|
|
71
|
+
},
|
|
72
|
+
readonlyMode: {
|
|
73
|
+
type: String,
|
|
74
|
+
default: 'value',
|
|
75
|
+
validator: (value)=>[
|
|
76
|
+
'value',
|
|
77
|
+
'custom'
|
|
78
|
+
].includes(value)
|
|
79
|
+
},
|
|
80
|
+
// 全局配置:是否显示恢复默认值按钮
|
|
81
|
+
showResetDefault: {
|
|
82
|
+
type: Boolean,
|
|
83
|
+
default: false
|
|
84
|
+
}
|
|
85
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { mergeDeep } from '../../util/index.ts.js';
|
|
2
|
+
import { defineComponent, h } from 'vue';
|
|
3
|
+
import props from './FieldProps.ts.js';
|
|
4
|
+
import StringField from './StringField.tsx.js';
|
|
5
|
+
export default defineComponent({
|
|
6
|
+
name: 'NumberField',
|
|
7
|
+
props,
|
|
8
|
+
render () {
|
|
9
|
+
var _a;
|
|
10
|
+
return h(StringField, Object.assign(Object.assign(Object.assign({}, this.$props), this.$attrs), {
|
|
11
|
+
schema: mergeDeep({
|
|
12
|
+
'ui:component': {
|
|
13
|
+
type: 'number',
|
|
14
|
+
min: ((_a = this.$props.schema) === null || _a === void 0 ? void 0 : _a.type) === 'integer' ? 0 : -Infinity
|
|
15
|
+
}
|
|
16
|
+
}, this.$props.schema)
|
|
17
|
+
}), this.$slots);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __rest = this && this.__rest || function(s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
4
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for(var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++){
|
|
5
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
6
|
+
}
|
|
7
|
+
return t;
|
|
8
|
+
};
|
|
9
|
+
import { defineComponent, h } from 'vue';
|
|
10
|
+
import props from './FieldProps.ts.js';
|
|
11
|
+
import SchemaField from './SchemaField.tsx.js';
|
|
12
|
+
import Schema from '../../core/schema.ts.js';
|
|
13
|
+
import Path from '../../core/path.ts.js';
|
|
14
|
+
import Layout from '../../core/layout.ts.js';
|
|
15
|
+
import { mergeDeep, orderProperties } from '../../util/index.ts.js';
|
|
16
|
+
import Widget from '../widget/Widget.ts.js';
|
|
17
|
+
export default defineComponent({
|
|
18
|
+
name: 'ObjectField',
|
|
19
|
+
props,
|
|
20
|
+
render () {
|
|
21
|
+
const { schema, path, layout, rootData } = this.$props;
|
|
22
|
+
const properties = orderProperties(Object.keys(schema.properties || {}), schema['ui:order']);
|
|
23
|
+
let vNodeList = [];
|
|
24
|
+
if (properties.length) {
|
|
25
|
+
vNodeList = properties.map((name)=>{
|
|
26
|
+
var _a;
|
|
27
|
+
const curPath = Path.getCurPath(path, name);
|
|
28
|
+
const lastProp = curPath.split('.').pop();
|
|
29
|
+
const layoutConfig = Layout.findLayoutByProp(lastProp, layout.group || []) || {};
|
|
30
|
+
return h(SchemaField, Object.assign(Object.assign(Object.assign({}, this.$props), this.$attrs), {
|
|
31
|
+
key: curPath,
|
|
32
|
+
modelValue: Path.getPathVal(rootData, curPath),
|
|
33
|
+
schema: (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[name],
|
|
34
|
+
required: Schema.isRequired(schema, name),
|
|
35
|
+
path: curPath,
|
|
36
|
+
layout: layoutConfig,
|
|
37
|
+
removeable: false
|
|
38
|
+
}), this.$slots);
|
|
39
|
+
});
|
|
40
|
+
} else if (Schema.getUiComponent(schema)) {
|
|
41
|
+
// 如果object属性没有配置 Properties,但是有ui:component属性,那个直接渲染对应的组件
|
|
42
|
+
vNodeList = [
|
|
43
|
+
h(Widget, Object.assign(Object.assign({}, this.$props), this.$attrs), this.$slots)
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
const _a = Schema.getGroupWrap(schema), { name } = _a, vnodeData = __rest(_a, [
|
|
47
|
+
"name"
|
|
48
|
+
]);
|
|
49
|
+
return h(name, mergeDeep(Object.assign(Object.assign(Object.assign({}, this.$props), this.$attrs), {
|
|
50
|
+
modelValue: Path.getPathVal(rootData, path),
|
|
51
|
+
path
|
|
52
|
+
}), vnodeData), {
|
|
53
|
+
default: ()=>[
|
|
54
|
+
...vNodeList
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __rest = this && this.__rest || function(s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
4
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for(var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++){
|
|
5
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
6
|
+
}
|
|
7
|
+
return t;
|
|
8
|
+
};
|
|
9
|
+
import { h, defineComponent } from 'vue';
|
|
10
|
+
import Schema from '../../core/schema.ts.js';
|
|
11
|
+
import props from './FieldProps.ts.js';
|
|
12
|
+
import Path from '../../core/path.ts.js';
|
|
13
|
+
export default defineComponent({
|
|
14
|
+
name: 'SchemaField',
|
|
15
|
+
props,
|
|
16
|
+
render () {
|
|
17
|
+
const { schema, rootData, path } = this.$props;
|
|
18
|
+
const resolveSchema = Schema.resolveSchema(schema);
|
|
19
|
+
if (!Object.keys(schema).length) return null;
|
|
20
|
+
const _a = Schema.getSchemaField(resolveSchema), { name } = _a, fieldProps = __rest(_a, [
|
|
21
|
+
"name"
|
|
22
|
+
]);
|
|
23
|
+
return name ? h(name, Object.assign(Object.assign(Object.assign(Object.assign({}, this.$attrs), this.$props), fieldProps), {
|
|
24
|
+
modelValue: Path.getPathVal(rootData, path),
|
|
25
|
+
schema: resolveSchema
|
|
26
|
+
}), this.$slots) : null;
|
|
27
|
+
}
|
|
28
|
+
});
|