@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,497 @@
|
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _async_to_generator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _define_property(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value: value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
function _object_spread(target) {
|
|
44
|
+
for(var i = 1; i < arguments.length; i++){
|
|
45
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
46
|
+
var ownKeys = Object.keys(source);
|
|
47
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
ownKeys.forEach(function(key) {
|
|
53
|
+
_define_property(target, key, source[key]);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
58
|
+
function ownKeys(object, enumerableOnly) {
|
|
59
|
+
var keys = Object.keys(object);
|
|
60
|
+
if (Object.getOwnPropertySymbols) {
|
|
61
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
62
|
+
if (enumerableOnly) {
|
|
63
|
+
symbols = symbols.filter(function(sym) {
|
|
64
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
keys.push.apply(keys, symbols);
|
|
68
|
+
}
|
|
69
|
+
return keys;
|
|
70
|
+
}
|
|
71
|
+
function _object_spread_props(target, source) {
|
|
72
|
+
source = source != null ? source : {};
|
|
73
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
74
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
75
|
+
} else {
|
|
76
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
77
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return target;
|
|
81
|
+
}
|
|
82
|
+
function _object_without_properties(source, excluded) {
|
|
83
|
+
if (source == null) return {};
|
|
84
|
+
var target = _object_without_properties_loose(source, excluded);
|
|
85
|
+
var key, i;
|
|
86
|
+
if (Object.getOwnPropertySymbols) {
|
|
87
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
88
|
+
for(i = 0; i < sourceSymbolKeys.length; i++){
|
|
89
|
+
key = sourceSymbolKeys[i];
|
|
90
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
91
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
92
|
+
target[key] = source[key];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return target;
|
|
96
|
+
}
|
|
97
|
+
function _object_without_properties_loose(source, excluded) {
|
|
98
|
+
if (source == null) return {};
|
|
99
|
+
var target = {};
|
|
100
|
+
var sourceKeys = Object.keys(source);
|
|
101
|
+
var key, i;
|
|
102
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
103
|
+
key = sourceKeys[i];
|
|
104
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
105
|
+
target[key] = source[key];
|
|
106
|
+
}
|
|
107
|
+
return target;
|
|
108
|
+
}
|
|
109
|
+
import Schema from '../../core/schema.ts.js';
|
|
110
|
+
import register from '../../core/register.ts.js';
|
|
111
|
+
import { defineComponent, h, withDirectives } from 'vue';
|
|
112
|
+
import { deepEquals, isObj, mergeDeep } from '../../util/index.ts.js';
|
|
113
|
+
import props from '../field/FieldProps.ts.js';
|
|
114
|
+
import Path from '../../core/path.ts.js';
|
|
115
|
+
import { reactionRegister, reactionDispatch, reactionUnRegister } from '../../core/reaction.ts.js';
|
|
116
|
+
import { executeExpression } from '../../core/expression.ts.js';
|
|
117
|
+
import { dispatchValidate } from '../../core/validator.ts.js';
|
|
118
|
+
import events from '../../core/events.ts.js';
|
|
119
|
+
import request from '../../util/fetch.ts.js';
|
|
120
|
+
import widgetTree from '../../core/widgetTree.ts.js';
|
|
121
|
+
import { capitalizeFirstLetter } from '../../util/index.ts.js';
|
|
122
|
+
import { bkTooltips } from 'bkui-vue';
|
|
123
|
+
export default defineComponent({
|
|
124
|
+
name: 'Widget',
|
|
125
|
+
inheritAttrs: false,
|
|
126
|
+
props,
|
|
127
|
+
data () {
|
|
128
|
+
return {
|
|
129
|
+
loading: false,
|
|
130
|
+
datasource: Schema.resolveDefaultDatasource(this.schema),
|
|
131
|
+
formItemProps: {
|
|
132
|
+
tips: '',
|
|
133
|
+
label: ''
|
|
134
|
+
},
|
|
135
|
+
state: {
|
|
136
|
+
visible: this.visible,
|
|
137
|
+
disabled: this.disabled,
|
|
138
|
+
readonly: this.readonly,
|
|
139
|
+
error: this.error
|
|
140
|
+
},
|
|
141
|
+
errorTips: '',
|
|
142
|
+
privateSchema: {},
|
|
143
|
+
key: ''
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
computed: {
|
|
147
|
+
widgetMap () {
|
|
148
|
+
return widgetTree.widgetMap;
|
|
149
|
+
},
|
|
150
|
+
widgetNode () {
|
|
151
|
+
return widgetTree.widgetMap[this.path];
|
|
152
|
+
},
|
|
153
|
+
parent () {
|
|
154
|
+
var _this_widgetNode;
|
|
155
|
+
return (_this_widgetNode = this.widgetNode) === null || _this_widgetNode === void 0 ? void 0 : _this_widgetNode.parent;
|
|
156
|
+
},
|
|
157
|
+
// 当前widget schema数据
|
|
158
|
+
widgetSchema () {
|
|
159
|
+
return mergeDeep({}, this.schema, this.privateSchema);
|
|
160
|
+
},
|
|
161
|
+
// 兼容以前数据结构
|
|
162
|
+
value () {
|
|
163
|
+
return this.modelValue;
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
watch: {
|
|
167
|
+
modelValue: {
|
|
168
|
+
handler (newValue, oldValue) {
|
|
169
|
+
if (!deepEquals(newValue, oldValue)) {
|
|
170
|
+
setTimeout(()=>{
|
|
171
|
+
reactionDispatch(this.path, 'valChange');
|
|
172
|
+
dispatchValidate(this.path);
|
|
173
|
+
}, 0);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
widgetSchema: {
|
|
178
|
+
deep: true,
|
|
179
|
+
handler (newValue, oldValue) {
|
|
180
|
+
if (deepEquals(newValue, oldValue)) return;
|
|
181
|
+
this.resetDatasource();
|
|
182
|
+
this.key = new Date().getTime().toString();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
created () {
|
|
187
|
+
// 表单项配置
|
|
188
|
+
const uiOptions = Schema.getUiOptions(this.widgetSchema);
|
|
189
|
+
this.formItemProps = _object_spread_props(_object_spread({}, uiOptions), {
|
|
190
|
+
// schema配置不存在title时默认用属性名作为title
|
|
191
|
+
label: uiOptions.showTitle ? uiOptions.label || Path.getPathLastProp(this.path) : '',
|
|
192
|
+
required: this.required
|
|
193
|
+
});
|
|
194
|
+
// 设置widget初始化状态 ui:component优先级 > ui:props优先级
|
|
195
|
+
const vNodeData = Schema.getUiComponent(this.widgetSchema);
|
|
196
|
+
const defaultProps = Object.assign({}, this.formItemProps, vNodeData || {});
|
|
197
|
+
Object.keys(defaultProps).forEach((key)=>{
|
|
198
|
+
if (Reflect.has(this.state, key)) {
|
|
199
|
+
this.setState(key, defaultProps[key]);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
// 注册widget TreeNode
|
|
203
|
+
widgetTree.addWidgetNode(this.path, this, 'node');
|
|
204
|
+
},
|
|
205
|
+
mounted () {
|
|
206
|
+
// 注册联动
|
|
207
|
+
reactionRegister(this.path, this.widgetSchema['ui:reactions']);
|
|
208
|
+
// 首次联动
|
|
209
|
+
reactionDispatch(this.path, 'valChange');
|
|
210
|
+
reactionDispatch(this.path, 'lifetime/init');
|
|
211
|
+
},
|
|
212
|
+
beforeUnmount () {
|
|
213
|
+
widgetTree.removeWidgetNode(this.path, this);
|
|
214
|
+
reactionUnRegister(this.path);
|
|
215
|
+
},
|
|
216
|
+
methods: {
|
|
217
|
+
setState (key, value) {
|
|
218
|
+
if (Reflect.has(this.state, key)) {
|
|
219
|
+
this.state[key] = value;
|
|
220
|
+
} else if (key === 'value') {
|
|
221
|
+
// 特殊处理value设置
|
|
222
|
+
this.$emit('update:modelValue', {
|
|
223
|
+
path: this.path,
|
|
224
|
+
value
|
|
225
|
+
});
|
|
226
|
+
} else {
|
|
227
|
+
console.warn(`Widget unsupported ${key} state, please check`);
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
loadDataSource () {
|
|
231
|
+
return _async_to_generator(function*() {
|
|
232
|
+
var _this_widgetSchema_uicomponent, _this_widgetSchema;
|
|
233
|
+
const xhrConfig = (_this_widgetSchema = this.widgetSchema) === null || _this_widgetSchema === void 0 ? void 0 : (_this_widgetSchema_uicomponent = _this_widgetSchema['ui:component']) === null || _this_widgetSchema_uicomponent === void 0 ? void 0 : _this_widgetSchema_uicomponent.remoteConfig;
|
|
234
|
+
if (xhrConfig) {
|
|
235
|
+
const { url, params } = xhrConfig, reset = _object_without_properties(xhrConfig, [
|
|
236
|
+
"url",
|
|
237
|
+
"params"
|
|
238
|
+
]);
|
|
239
|
+
const { request: http = request, responseParse } = this.httpAdapter;
|
|
240
|
+
try {
|
|
241
|
+
this.loading = true;
|
|
242
|
+
const remoteURL = executeExpression(url, this);
|
|
243
|
+
const requestParams = isObj(params) ? executeExpression(params, this) : params;
|
|
244
|
+
this.datasource = yield http(remoteURL, _object_spread_props(_object_spread({}, reset), {
|
|
245
|
+
params: requestParams,
|
|
246
|
+
responseParse
|
|
247
|
+
}));
|
|
248
|
+
this.loading = false;
|
|
249
|
+
} catch (e) {
|
|
250
|
+
this.loading = false;
|
|
251
|
+
console.error(e);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}).apply(this);
|
|
255
|
+
},
|
|
256
|
+
setErrorTips (tips) {
|
|
257
|
+
this.errorTips = tips;
|
|
258
|
+
},
|
|
259
|
+
getValue (path) {
|
|
260
|
+
return Path.getPathVal(this.rootData, path);
|
|
261
|
+
},
|
|
262
|
+
getReadonlyValue () {
|
|
263
|
+
var _this_widgetSchema_uicomponent;
|
|
264
|
+
let val = this.modelValue;
|
|
265
|
+
if (((_this_widgetSchema_uicomponent = this.widgetSchema['ui:component']) === null || _this_widgetSchema_uicomponent === void 0 ? void 0 : _this_widgetSchema_uicomponent.type) === 'password') {
|
|
266
|
+
val = '******';
|
|
267
|
+
} else if (this.datasource) {
|
|
268
|
+
var _this_datasource;
|
|
269
|
+
const item = (_this_datasource = this.datasource) === null || _this_datasource === void 0 ? void 0 : _this_datasource.find((item)=>item.value === this.modelValue);
|
|
270
|
+
if (item) {
|
|
271
|
+
val = item.label;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
let value = val === '' ? '--' : val;
|
|
275
|
+
if (Object.prototype.toString.call(value) === '[Object Object]') {
|
|
276
|
+
value = JSON.stringify(value);
|
|
277
|
+
} else if (Array.isArray(value)) {
|
|
278
|
+
const isTrue = value.some((item)=>item && typeof item === 'object');
|
|
279
|
+
if (isTrue) {
|
|
280
|
+
value = JSON.stringify(value);
|
|
281
|
+
} else {
|
|
282
|
+
value = value.join(',');
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
value = String(value);
|
|
286
|
+
}
|
|
287
|
+
return value;
|
|
288
|
+
},
|
|
289
|
+
getSchema () {
|
|
290
|
+
return this.widgetSchema;
|
|
291
|
+
},
|
|
292
|
+
setSchema (data) {
|
|
293
|
+
try {
|
|
294
|
+
this.privateSchema = JSON.parse(JSON.stringify(data));
|
|
295
|
+
} catch (err) {
|
|
296
|
+
console.warn(err);
|
|
297
|
+
}
|
|
298
|
+
return this.widgetSchema;
|
|
299
|
+
},
|
|
300
|
+
resetDatasource () {
|
|
301
|
+
var _this_widgetSchema_uicomponent, _this_widgetSchema;
|
|
302
|
+
const xhrConfig = (_this_widgetSchema = this.widgetSchema) === null || _this_widgetSchema === void 0 ? void 0 : (_this_widgetSchema_uicomponent = _this_widgetSchema['ui:component']) === null || _this_widgetSchema_uicomponent === void 0 ? void 0 : _this_widgetSchema_uicomponent.remoteConfig;
|
|
303
|
+
if (xhrConfig) {
|
|
304
|
+
this.loadDataSource();
|
|
305
|
+
} else {
|
|
306
|
+
this.datasource = Schema.resolveDefaultDatasource(this.widgetSchema);
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
// 获取 schema 中定义的默认值
|
|
310
|
+
getDefaultValue () {
|
|
311
|
+
return Schema.getSchemaDefaultValue(this.widgetSchema);
|
|
312
|
+
},
|
|
313
|
+
// 恢复默认值
|
|
314
|
+
resetToDefault () {
|
|
315
|
+
const defaultValue = this.getDefaultValue();
|
|
316
|
+
this.$emit('update:modelValue', {
|
|
317
|
+
path: this.path,
|
|
318
|
+
value: defaultValue
|
|
319
|
+
});
|
|
320
|
+
},
|
|
321
|
+
// 判断当前值是否与默认值相同
|
|
322
|
+
isDefaultValue () {
|
|
323
|
+
const defaultValue = this.getDefaultValue();
|
|
324
|
+
return deepEquals(this.modelValue, defaultValue);
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
render () {
|
|
328
|
+
var _events_callbacks, _this_$slots_default, _this_$slots;
|
|
329
|
+
const _Schema_getUiComponent = Schema.getUiComponent(this.widgetSchema), { name } = _Schema_getUiComponent, uiVnodeData = _object_without_properties(_Schema_getUiComponent, [
|
|
330
|
+
"name"
|
|
331
|
+
]);
|
|
332
|
+
// 注意顺序!!!
|
|
333
|
+
const widgetProps = _object_spread_props(_object_spread({}, this.$props), {
|
|
334
|
+
loading: this.loading,
|
|
335
|
+
modelValue: this.modelValue
|
|
336
|
+
});
|
|
337
|
+
const self = this;
|
|
338
|
+
const widgetName = register.getComponent(name) || name || Schema.getDefaultWidget(this.widgetSchema);
|
|
339
|
+
const widgetEvents = ((_events_callbacks = events.callbacks) === null || _events_callbacks === void 0 ? void 0 : _events_callbacks[this.path]) || {};
|
|
340
|
+
// 渲染表单项
|
|
341
|
+
const renderFormItem = ()=>{
|
|
342
|
+
var _this_widgetSchema_uicomponent;
|
|
343
|
+
return this.state.readonly && this.readonlyMode === 'value' && ((_this_widgetSchema_uicomponent = this.widgetSchema['ui:component']) === null || _this_widgetSchema_uicomponent === void 0 ? void 0 : _this_widgetSchema_uicomponent.name) !== 'table' ? renderReadonlyWidget : renderWidget;
|
|
344
|
+
};
|
|
345
|
+
var _this_$slots_default1;
|
|
346
|
+
// 渲染表单控件(当前state属性优先级最高)
|
|
347
|
+
const renderWidget = (_this_$slots_default1 = (_this_$slots_default = (_this_$slots = this.$slots).default) === null || _this_$slots_default === void 0 ? void 0 : _this_$slots_default.call(_this_$slots, {
|
|
348
|
+
path: this.path
|
|
349
|
+
})) !== null && _this_$slots_default1 !== void 0 ? _this_$slots_default1 : h(widgetName, mergeDeep(_object_spread_props(_object_spread({}, widgetProps, uiVnodeData || {}, Object.keys(widgetEvents).reduce((pre, key)=>{
|
|
350
|
+
pre[`on${capitalizeFirstLetter(key)}`] = widgetEvents[key];
|
|
351
|
+
return pre;
|
|
352
|
+
}, {})), {
|
|
353
|
+
schema: this.widgetSchema,
|
|
354
|
+
onClick () {
|
|
355
|
+
var _widgetEvents_click;
|
|
356
|
+
reactionDispatch(self.path, 'effect/click');
|
|
357
|
+
(_widgetEvents_click = widgetEvents.click) === null || _widgetEvents_click === void 0 ? void 0 : _widgetEvents_click.forEach((event)=>event());
|
|
358
|
+
},
|
|
359
|
+
'onUpdate:modelValue': (value)=>{
|
|
360
|
+
var _widgetEvents_updatemodelValue;
|
|
361
|
+
// 所有组件widget必须实现input事件,用于v-model时更新表单数据
|
|
362
|
+
self.$emit('update:modelValue', {
|
|
363
|
+
path: self.path,
|
|
364
|
+
value
|
|
365
|
+
});
|
|
366
|
+
(_widgetEvents_updatemodelValue = widgetEvents['update:modelValue']) === null || _widgetEvents_updatemodelValue === void 0 ? void 0 : _widgetEvents_updatemodelValue.forEach((event)=>event());
|
|
367
|
+
}
|
|
368
|
+
}), uiVnodeData, _object_spread_props(_object_spread({}, this.state), {
|
|
369
|
+
datasource: this.datasource,
|
|
370
|
+
readonly: this.readonly,
|
|
371
|
+
readonlyMode: this.readonlyMode
|
|
372
|
+
})));
|
|
373
|
+
const renderSuffix = ()=>{
|
|
374
|
+
var _this_$slots_suffix, _this_$slots;
|
|
375
|
+
return (_this_$slots_suffix = (_this_$slots = this.$slots).suffix) === null || _this_$slots_suffix === void 0 ? void 0 : _this_$slots_suffix.call(_this_$slots, {
|
|
376
|
+
path: this.path,
|
|
377
|
+
schema: this.widgetSchema
|
|
378
|
+
});
|
|
379
|
+
};
|
|
380
|
+
// 渲染默认readonly模式
|
|
381
|
+
const renderReadonlyWidget = h('div', {}, {
|
|
382
|
+
default: ()=>this.getReadonlyValue()
|
|
383
|
+
});
|
|
384
|
+
// 渲染删除按钮(用于数组类型widget删除)
|
|
385
|
+
const renderDelete = ()=>{
|
|
386
|
+
if (!this.removeable) return null;
|
|
387
|
+
return h('span', {
|
|
388
|
+
class: [
|
|
389
|
+
'bk-schema-form-group-delete'
|
|
390
|
+
],
|
|
391
|
+
onClick: ()=>{
|
|
392
|
+
self.$emit('remove', self.path);
|
|
393
|
+
}
|
|
394
|
+
}, [
|
|
395
|
+
h('i', {
|
|
396
|
+
class: [
|
|
397
|
+
'bk-form-icon icon-close3-shape'
|
|
398
|
+
]
|
|
399
|
+
})
|
|
400
|
+
]);
|
|
401
|
+
};
|
|
402
|
+
// 渲染恢复默认值按钮
|
|
403
|
+
const renderResetDefault = ()=>{
|
|
404
|
+
var _this_widgetSchema_uiprops;
|
|
405
|
+
// 优先使用 schema 中的配置,否则使用全局配置
|
|
406
|
+
const schemaShowResetDefault = (_this_widgetSchema_uiprops = this.widgetSchema['ui:props']) === null || _this_widgetSchema_uiprops === void 0 ? void 0 : _this_widgetSchema_uiprops.showResetDefault;
|
|
407
|
+
const showResetDefault = schemaShowResetDefault !== undefined ? schemaShowResetDefault : this.showResetDefault;
|
|
408
|
+
// 不显示恢复默认值按钮,或者当前值已经是默认值
|
|
409
|
+
if (!showResetDefault || this.isDefaultValue() || this.state.readonly || this.state.disabled) {
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
return withDirectives(h('span', {
|
|
413
|
+
class: [
|
|
414
|
+
'bk-schema-form-reset-default',
|
|
415
|
+
'bk-form-icon icon-reset'
|
|
416
|
+
],
|
|
417
|
+
onClick: ()=>{
|
|
418
|
+
self.resetToDefault();
|
|
419
|
+
}
|
|
420
|
+
}), [
|
|
421
|
+
[
|
|
422
|
+
bkTooltips,
|
|
423
|
+
{
|
|
424
|
+
content: '恢复默认值'
|
|
425
|
+
}
|
|
426
|
+
]
|
|
427
|
+
]);
|
|
428
|
+
};
|
|
429
|
+
// 渲染错误提示
|
|
430
|
+
const renderError = ()=>this.state.error ? h('p', {
|
|
431
|
+
class: 'bk-schema-form-item__error-tips'
|
|
432
|
+
}, {
|
|
433
|
+
default: ()=>this.errorTips
|
|
434
|
+
}) : null;
|
|
435
|
+
// 渲染表单提示
|
|
436
|
+
const renderFormTips = ()=>this.formItemProps.tips ? h('p', {
|
|
437
|
+
class: [
|
|
438
|
+
'mt5',
|
|
439
|
+
'mb0',
|
|
440
|
+
'f12'
|
|
441
|
+
],
|
|
442
|
+
style: {
|
|
443
|
+
color: '#5e6d82',
|
|
444
|
+
lineHeight: '1.5em'
|
|
445
|
+
}
|
|
446
|
+
}, {
|
|
447
|
+
default: ()=>this.formItemProps.tips
|
|
448
|
+
}) : null;
|
|
449
|
+
// 渲染 label 插槽内容(包含 label 文本和重置按钮)
|
|
450
|
+
const renderLabel = ()=>{
|
|
451
|
+
const labelText = this.formItemProps.label;
|
|
452
|
+
const { description } = this.widgetSchema;
|
|
453
|
+
if (description) {
|
|
454
|
+
return [
|
|
455
|
+
withDirectives(h('span', {
|
|
456
|
+
class: {
|
|
457
|
+
'bk-schema-form-label-description': description
|
|
458
|
+
}
|
|
459
|
+
}, labelText), [
|
|
460
|
+
[
|
|
461
|
+
bkTooltips,
|
|
462
|
+
{
|
|
463
|
+
content: description,
|
|
464
|
+
disabled: !description
|
|
465
|
+
}
|
|
466
|
+
]
|
|
467
|
+
]),
|
|
468
|
+
renderResetDefault()
|
|
469
|
+
];
|
|
470
|
+
}
|
|
471
|
+
return [
|
|
472
|
+
labelText,
|
|
473
|
+
renderResetDefault()
|
|
474
|
+
];
|
|
475
|
+
};
|
|
476
|
+
return h(register.getBaseWidget('form-item'), _object_spread_props(_object_spread({
|
|
477
|
+
key: this.key
|
|
478
|
+
}, this.formItemProps), {
|
|
479
|
+
style: _object_spread_props(_object_spread({}, this.layout.item || {}, this.layout.container || {}), {
|
|
480
|
+
// 表单项显示和隐藏状态
|
|
481
|
+
display: this.state.visible ? '' : 'none'
|
|
482
|
+
}),
|
|
483
|
+
class: {
|
|
484
|
+
'bk-schema-form-item--error': this.state.error
|
|
485
|
+
}
|
|
486
|
+
}), {
|
|
487
|
+
label: renderLabel,
|
|
488
|
+
default: ()=>[
|
|
489
|
+
renderFormItem(),
|
|
490
|
+
renderSuffix(),
|
|
491
|
+
renderDelete(),
|
|
492
|
+
renderError(),
|
|
493
|
+
renderFormTips()
|
|
494
|
+
]
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
});
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
@font-face {
|
|
2
|
+
font-family: "bk-form";
|
|
3
|
+
src: url("fonts/iconcool.svg#iconcool") format("svg"),
|
|
4
|
+
url("fonts/iconcool.ttf") format("truetype"),
|
|
5
|
+
url("fonts/iconcool.woff") format("woff"),
|
|
6
|
+
url("fonts/iconcool.eot?#iefix") format("embedded-opentype");
|
|
7
|
+
font-weight: normal;
|
|
8
|
+
font-style: normal;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.bk-form-icon {
|
|
12
|
+
/* use !important to prevent issues with browser extensions that change fonts */
|
|
13
|
+
font-family: 'bk-form' !important;
|
|
14
|
+
speak: none;
|
|
15
|
+
font-style: normal;
|
|
16
|
+
font-weight: normal;
|
|
17
|
+
font-variant: normal;
|
|
18
|
+
text-transform: none;
|
|
19
|
+
line-height: 1;
|
|
20
|
+
text-align: center;
|
|
21
|
+
/* Better Font Rendering =========== */
|
|
22
|
+
-webkit-font-smoothing: antialiased;
|
|
23
|
+
-moz-osx-font-smoothing: grayscale;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.icon-minus-line:before {
|
|
27
|
+
content: "\e102";
|
|
28
|
+
}
|
|
29
|
+
.icon-plus-line:before {
|
|
30
|
+
content: "\e104";
|
|
31
|
+
}
|
|
32
|
+
.icon-plus-circle-shape:before {
|
|
33
|
+
content: "\e105";
|
|
34
|
+
}
|
|
35
|
+
.icon-close3-shape:before {
|
|
36
|
+
content: "\e106";
|
|
37
|
+
}
|
|
38
|
+
.icon-down-shape:before {
|
|
39
|
+
content: "\e107";
|
|
40
|
+
}
|
|
41
|
+
.icon-reset:before {
|
|
42
|
+
content: "\e108";
|
|
43
|
+
}
|