@blueking/bkui-form 0.0.40 → 0.0.41-beta.1

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.
@@ -1939,19 +1939,19 @@
1939
1939
  // 普通节点
1940
1940
  var parentId = Path.getParentPath(path);
1941
1941
  var parentNode = this.widgetMap[parentId];
1942
- if (!parentNode) {
1943
- console.warn('Unexpected parent id, add widget failed');
1944
- return;
1945
- }
1946
1942
  var _node = new WidgetNode({
1947
- id: instance.path,
1943
+ id: (instance === null || instance === void 0 ? void 0 : instance.path) || path,
1948
1944
  type: type,
1949
1945
  index: index,
1950
1946
  parent: parentNode,
1951
1947
  instance: instance,
1952
1948
  children: []
1953
1949
  });
1954
- parentNode.appendChild(_node);
1950
+ if (!parentNode) {
1951
+ console.warn('Unexpected parent id, please check widget node', _node);
1952
+ } else {
1953
+ parentNode.appendChild(_node);
1954
+ }
1955
1955
  this.widgetMap[path] = _node;
1956
1956
  }
1957
1957
  }
@@ -9821,13 +9821,14 @@
9821
9821
  var widgetPaths = path.split('.');
9822
9822
  var fieldTitleBreadcrumb = [];
9823
9823
  widgetPaths.forEach(function (thePath, thePathIndex) {
9824
+ var _theWidget$instance;
9824
9825
  var currentPaths = widgetPaths.slice(0, widgetPaths.length - thePathIndex);
9825
9826
  var widgetPath = currentPaths.join('.');
9826
9827
  var theWidget = widgetTree.widgetMap[widgetPath];
9827
9828
  // todo(判断path是否是数组索引)
9828
9829
  var isIndex = theWidget.instance.schema.type === 'array' || !theWidget.instance.schema.title;
9829
9830
  fieldTitleBreadcrumb.push(isIndex ? currentPaths.pop() : theWidget.instance.schema.title);
9830
- if (theWidget.instance.verifiable && theWidget.type === 'group') {
9831
+ if ((_theWidget$instance = theWidget.instance) !== null && _theWidget$instance !== void 0 && _theWidget$instance.verifiable && theWidget.type === 'group') {
9831
9832
  if (isError) {
9832
9833
  var groupErrors = "".concat(fieldTitleBreadcrumb.reverse().join('-'), ": ").concat(errorMsg);
9833
9834
  theWidget.instance.setGroupErrorTips(path, groupErrors);
@@ -9860,9 +9861,10 @@
9860
9861
  // 清空所在组错误信息
9861
9862
  var widgetPaths = path.split('.');
9862
9863
  widgetPaths.forEach(function (thePath, thePathIndex) {
9864
+ var _theWidget$instance2;
9863
9865
  var currentPaths = widgetPaths.slice(0, widgetPaths.length - thePathIndex).join('.');
9864
9866
  var theWidget = widgetTree.widgetMap[currentPaths];
9865
- if (theWidget.instance.verifiable && theWidget.type === 'group') {
9867
+ if ((_theWidget$instance2 = theWidget.instance) !== null && _theWidget$instance2 !== void 0 && _theWidget$instance2.verifiable && theWidget.type === 'group') {
9866
9868
  theWidget.instance.removeGroupErrorTips(path);
9867
9869
  }
9868
9870
  });
@@ -10088,16 +10090,25 @@
10088
10090
  readonly: this.readonly,
10089
10091
  error: this.error
10090
10092
  },
10091
- errorTips: ''
10093
+ errorTips: '',
10094
+ privateSchema: {},
10095
+ key: ''
10092
10096
  };
10093
10097
  },
10094
10098
  computed: {
10099
+ widgetMap: function widgetMap() {
10100
+ return widgetTree.widgetMap;
10101
+ },
10095
10102
  widgetNode: function widgetNode() {
10096
10103
  return widgetTree.widgetMap[this.path];
10097
10104
  },
10098
10105
  parent: function parent() {
10099
10106
  var _this$widgetNode;
10100
10107
  return (_this$widgetNode = this.widgetNode) === null || _this$widgetNode === void 0 ? void 0 : _this$widgetNode.parent;
10108
+ },
10109
+ // 当前widget schema数据
10110
+ widgetSchema: function widgetSchema() {
10111
+ return mergeDeep({}, this.schema, this.privateSchema);
10101
10112
  }
10102
10113
  },
10103
10114
  watch: {
@@ -10111,19 +10122,27 @@
10111
10122
  }, 0);
10112
10123
  }
10113
10124
  }
10125
+ },
10126
+ widgetSchema: {
10127
+ deep: true,
10128
+ handler: function handler(newValue, oldValue) {
10129
+ if (deepEquals(newValue, oldValue)) return;
10130
+ this.resetDatasource();
10131
+ this.key = new Date().getTime();
10132
+ }
10114
10133
  }
10115
10134
  },
10116
10135
  created: function created() {
10117
10136
  var _this2 = this;
10118
10137
  // 表单项配置
10119
- var uiOptions = Schema.getUiOptions(this.schema);
10138
+ var uiOptions = Schema.getUiOptions(this.widgetSchema);
10120
10139
  this.formItemProps = _objectSpread2(_objectSpread2({}, uiOptions), {}, {
10121
10140
  // schema配置不存在title时默认用属性名作为title
10122
10141
  label: uiOptions.showTitle ? uiOptions.label || Path.getPathLastProp(this.path) : '',
10123
10142
  required: this.required
10124
10143
  });
10125
10144
  // 设置widget初始化状态 ui:component优先级 > ui:props优先级
10126
- var vNodeData = Schema.getUiComponent(this.schema);
10145
+ var vNodeData = Schema.getUiComponent(this.widgetSchema);
10127
10146
  var defaultProps = Object.assign({}, this.formItemProps, vNodeData.props || {});
10128
10147
  Object.keys(defaultProps).forEach(function (key) {
10129
10148
  if (Reflect.has(_this2.state, key)) {
@@ -10135,7 +10154,7 @@
10135
10154
  },
10136
10155
  mounted: function mounted() {
10137
10156
  // 注册联动
10138
- reactionRegister(this.path, this.schema['ui:reactions']);
10157
+ reactionRegister(this.path, this.widgetSchema['ui:reactions']);
10139
10158
  // 首次联动
10140
10159
  reactionDispatch(this.path, 'valChange');
10141
10160
  reactionDispatch(this.path, 'lifetime/init');
@@ -10161,12 +10180,12 @@
10161
10180
  loadDataSource: function loadDataSource() {
10162
10181
  var _this3 = this;
10163
10182
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
10164
- var _this3$schema, _this3$schema$uiComp, _this3$schema$uiComp$;
10183
+ var _this3$widgetSchema, _this3$widgetSchema$u, _this3$widgetSchema$u2;
10165
10184
  var xhrConfig, url, params, reset, _this3$httpAdapter, _this3$httpAdapter$re, http, responseParse, remoteURL, requestParams;
10166
10185
  return _regeneratorRuntime().wrap(function _callee$(_context) {
10167
10186
  while (1) switch (_context.prev = _context.next) {
10168
10187
  case 0:
10169
- xhrConfig = (_this3$schema = _this3.schema) === null || _this3$schema === void 0 ? void 0 : (_this3$schema$uiComp = _this3$schema['ui:component']) === null || _this3$schema$uiComp === void 0 ? void 0 : (_this3$schema$uiComp$ = _this3$schema$uiComp.props) === null || _this3$schema$uiComp$ === void 0 ? void 0 : _this3$schema$uiComp$.remoteConfig;
10188
+ xhrConfig = (_this3$widgetSchema = _this3.widgetSchema) === null || _this3$widgetSchema === void 0 ? void 0 : (_this3$widgetSchema$u = _this3$widgetSchema['ui:component']) === null || _this3$widgetSchema$u === void 0 ? void 0 : (_this3$widgetSchema$u2 = _this3$widgetSchema$u.props) === null || _this3$widgetSchema$u2 === void 0 ? void 0 : _this3$widgetSchema$u2.remoteConfig;
10170
10189
  if (!xhrConfig) {
10171
10190
  _context.next = 18;
10172
10191
  break;
@@ -10206,11 +10225,11 @@
10206
10225
  return Path.getPathVal(this.rootData, path);
10207
10226
  },
10208
10227
  getReadonlyValue: function getReadonlyValue() {
10209
- var _this$schema$uiCompo,
10210
- _this$schema$uiCompo$,
10228
+ var _this$widgetSchema$ui,
10229
+ _this$widgetSchema$ui2,
10211
10230
  _this4 = this;
10212
10231
  var val = this.value;
10213
- if (((_this$schema$uiCompo = this.schema['ui:component']) === null || _this$schema$uiCompo === void 0 ? void 0 : (_this$schema$uiCompo$ = _this$schema$uiCompo.props) === null || _this$schema$uiCompo$ === void 0 ? void 0 : _this$schema$uiCompo$.type) === 'password') {
10232
+ if (((_this$widgetSchema$ui = this.widgetSchema['ui:component']) === null || _this$widgetSchema$ui === void 0 ? void 0 : (_this$widgetSchema$ui2 = _this$widgetSchema$ui.props) === null || _this$widgetSchema$ui2 === void 0 ? void 0 : _this$widgetSchema$ui2.type) === 'password') {
10214
10233
  val = '******';
10215
10234
  } else if (this.datasource) {
10216
10235
  var _this$datasource;
@@ -10222,7 +10241,7 @@
10222
10241
  }
10223
10242
  }
10224
10243
  var value = val === '' ? '--' : val;
10225
- if (Object.prototype.call(value) === '[Object Object]') {
10244
+ if (Object.prototype.toString.call(value) === '[Object Object]') {
10226
10245
  value = JSON.stringify(value);
10227
10246
  } else if (Array.isArray(value)) {
10228
10247
  var isTrue = value.some(function (item) {
@@ -10237,11 +10256,31 @@
10237
10256
  value = String(value);
10238
10257
  }
10239
10258
  return value;
10259
+ },
10260
+ getSchema: function getSchema() {
10261
+ return this.widgetSchema;
10262
+ },
10263
+ setSchema: function setSchema(data) {
10264
+ try {
10265
+ this.privateSchema = JSON.parse(JSON.stringify(data));
10266
+ } catch (err) {
10267
+ console.warn(err);
10268
+ }
10269
+ return this.widgetSchema;
10270
+ },
10271
+ resetDatasource: function resetDatasource() {
10272
+ var _this$widgetSchema, _this$widgetSchema$ui3, _this$widgetSchema$ui4;
10273
+ var xhrConfig = (_this$widgetSchema = this.widgetSchema) === null || _this$widgetSchema === void 0 ? void 0 : (_this$widgetSchema$ui3 = _this$widgetSchema['ui:component']) === null || _this$widgetSchema$ui3 === void 0 ? void 0 : (_this$widgetSchema$ui4 = _this$widgetSchema$ui3.props) === null || _this$widgetSchema$ui4 === void 0 ? void 0 : _this$widgetSchema$ui4.remoteConfig;
10274
+ if (xhrConfig) {
10275
+ this.loadDataSource();
10276
+ } else {
10277
+ this.datasource = Schema.resolveDefaultDatasource(this.widgetSchema);
10278
+ }
10240
10279
  }
10241
10280
  },
10242
10281
  render: function render(h) {
10243
- var _events$callbacks, _this$$scopedSlots$de, _this$$scopedSlots$de2, _this$$scopedSlots, _this$schema$uiCompo2, _this$$scopedSlots$su, _this$$scopedSlots2;
10244
- var _Schema$getUiComponen = Schema.getUiComponent(this.schema),
10282
+ var _events$callbacks, _this$$scopedSlots$de, _this$$scopedSlots$de2, _this$$scopedSlots, _this$widgetSchema$ui5, _this$$scopedSlots$su, _this$$scopedSlots2;
10283
+ var _Schema$getUiComponen = Schema.getUiComponent(this.widgetSchema),
10245
10284
  name = _Schema$getUiComponen.name,
10246
10285
  uiVnodeData = _objectWithoutProperties(_Schema$getUiComponen, _excluded2);
10247
10286
  // 注意顺序!!!
@@ -10250,13 +10289,15 @@
10250
10289
  value: this.value
10251
10290
  });
10252
10291
  var self = this;
10253
- var widgetName = registry.getComponent(name) || name || Schema.getDefaultWidget(this.schema);
10292
+ var widgetName = registry.getComponent(name) || name || Schema.getDefaultWidget(this.widgetSchema);
10254
10293
  var widgetEvents = ((_events$callbacks = events.callbacks) === null || _events$callbacks === void 0 ? void 0 : _events$callbacks[this.path]) || {};
10255
10294
  // 当前state属性优先级最高
10256
10295
  var renderWidget = (_this$$scopedSlots$de = (_this$$scopedSlots$de2 = (_this$$scopedSlots = this.$scopedSlots).default) === null || _this$$scopedSlots$de2 === void 0 ? void 0 : _this$$scopedSlots$de2.call(_this$$scopedSlots, {
10257
10296
  path: this.path
10258
10297
  })) !== null && _this$$scopedSlots$de !== void 0 ? _this$$scopedSlots$de : h(widgetName, mergeDeep({
10259
- props: _objectSpread2({}, widgetProps),
10298
+ props: _objectSpread2(_objectSpread2({}, widgetProps), {}, {
10299
+ schema: this.widgetSchema
10300
+ }),
10260
10301
  attrs: _objectSpread2({}, uiVnodeData.props || {}),
10261
10302
  class: {
10262
10303
  pr20: this.removeable
@@ -10302,6 +10343,7 @@
10302
10343
  })]);
10303
10344
  };
10304
10345
  return h(registry.getBaseWidget('form-item'), {
10346
+ key: this.key,
10305
10347
  props: this.formItemProps,
10306
10348
  style: _objectSpread2(_objectSpread2(_objectSpread2({}, this.layout.item || {}), this.layout.container || {}), {}, {
10307
10349
  // 表单项显示和隐藏状态
@@ -10310,9 +10352,9 @@
10310
10352
  class: {
10311
10353
  'bk-schema-form-item--error': this.state.error
10312
10354
  }
10313
- }, [this.state.readonly && this.readonlyMode === 'value' && ((_this$schema$uiCompo2 = this.schema['ui:component']) === null || _this$schema$uiCompo2 === void 0 ? void 0 : _this$schema$uiCompo2.name) !== 'table' ? renderReadonlyWidget : renderWidget, (_this$$scopedSlots$su = (_this$$scopedSlots2 = this.$scopedSlots).suffix) === null || _this$$scopedSlots$su === void 0 ? void 0 : _this$$scopedSlots$su.call(_this$$scopedSlots2, {
10355
+ }, [this.state.readonly && this.readonlyMode === 'value' && ((_this$widgetSchema$ui5 = this.widgetSchema['ui:component']) === null || _this$widgetSchema$ui5 === void 0 ? void 0 : _this$widgetSchema$ui5.name) !== 'table' ? renderReadonlyWidget : renderWidget, (_this$$scopedSlots$su = (_this$$scopedSlots2 = this.$scopedSlots).suffix) === null || _this$$scopedSlots$su === void 0 ? void 0 : _this$$scopedSlots$su.call(_this$$scopedSlots2, {
10314
10356
  path: this.path,
10315
- schema: this.schema
10357
+ schema: this.widgetSchema
10316
10358
  }), this.removeable && renderDelete(), this.state.error ? h('p', {
10317
10359
  class: 'bk-schema-form-item__error-tips'
10318
10360
  }, this.errorTips) : null, this.formItemProps.tips ? h('p', {
@@ -10925,21 +10967,21 @@
10925
10967
  var TableWidget = Vue__default["default"].extend({
10926
10968
  name: 'TableWidget',
10927
10969
  props: props,
10928
- mounted: function mounted() {
10929
- var _this = this;
10930
- this.$nextTick(function () {
10931
- var fieldMap = _this.schema.items.properties;
10932
- _this.value.forEach(function (item, index) {
10933
- Object.keys(fieldMap).forEach(function (key) {
10934
- var config = fieldMap[key];
10935
- if (config['ui:rules']) {
10936
- var instance = _this.$refs[key + index];
10937
- // 注册widget TreeNode
10938
- widgetTree.addWidgetNode("".concat(_this.path, ".").concat(key), instance, 'node');
10939
- }
10970
+ watch: {
10971
+ value: {
10972
+ immediate: true,
10973
+ handler: function handler() {
10974
+ var _this$value,
10975
+ _this = this;
10976
+ (_this$value = this.value) === null || _this$value === void 0 ? void 0 : _this$value.forEach(function (_, index) {
10977
+ var path = "".concat(_this.path, ".").concat(index);
10978
+ // 销毁上一次的缓存
10979
+ widgetTree.removeWidgetNode(path, null);
10980
+ // 重新当前行的父节点
10981
+ widgetTree.addWidgetNode(path, null, 'group');
10940
10982
  });
10941
- });
10942
- });
10983
+ }
10984
+ }
10943
10985
  },
10944
10986
  methods: {
10945
10987
  // 单元格表单编辑
@@ -10952,39 +10994,40 @@
10952
10994
  },
10953
10995
  // 新增
10954
10996
  handleAddRow: function handleAddRow(index) {
10955
- var _this$$props$schema$i;
10956
- if (this.schema['ui:props'].disabled) return;
10997
+ var _this$schema$uiProps, _this$$props$schema$i;
10998
+ if ((_this$schema$uiProps = this.schema['ui:props']) !== null && _this$schema$uiProps !== void 0 && _this$schema$uiProps.disabled) return;
10957
10999
  var newValue = this.value.slice(0);
10958
11000
  newValue.splice.apply(newValue, [index + 1, 0].concat(_toConsumableArray(getRowDefaultData((_this$$props$schema$i = this.$props.schema.items) === null || _this$$props$schema$i === void 0 ? void 0 : _this$$props$schema$i.properties))));
10959
11001
  this.$emit('input', newValue);
10960
11002
  },
10961
11003
  // 删除
10962
11004
  handleDelRow: function handleDelRow(index) {
10963
- if (this.schema['ui:props'].disabled) return;
11005
+ var _this$schema$uiProps2;
11006
+ if ((_this$schema$uiProps2 = this.schema['ui:props']) !== null && _this$schema$uiProps2 !== void 0 && _this$schema$uiProps2.disabled) return;
10964
11007
  var newValue = this.value.slice(0);
10965
11008
  newValue.splice(index, 1);
10966
11009
  this.$emit('input', newValue);
10967
11010
  }
10968
11011
  },
10969
11012
  render: function render(h) {
10970
- var _schema$items,
10971
- _this2 = this;
11013
+ var _this2 = this;
10972
11014
  var self = this;
10973
- var _this$$props = this.$props,
10974
- schema = _this$$props.schema,
10975
- readonly = _this$$props.readonly,
10976
- readonlyMode = _this$$props.readonlyMode,
10977
- path = _this$$props.path,
10978
- context = _this$$props.context,
10979
- rootData = _this$$props.rootData,
10980
- value = _this$$props.value,
10981
- disabled = _this$$props.disabled;
10982
- var columnsKey = Object.keys(((_schema$items = schema.items) === null || _schema$items === void 0 ? void 0 : _schema$items.properties) || []);
11015
+ var schema = this.schema,
11016
+ path = this.path,
11017
+ value = this.value;
11018
+ var schemaItems = schema.items;
11019
+ var properties = {};
11020
+ if (schemaItems !== null && schemaItems !== void 0 && schemaItems.properties) {
11021
+ properties = schemaItems === null || schemaItems === void 0 ? void 0 : schemaItems.properties;
11022
+ } else {
11023
+ // table类型目前只支持items的类型为对象的schema
11024
+ console.warn('The current schema type is not supported table component', schemaItems);
11025
+ }
10983
11026
  var uiOptions = Schema.getUiOptions(schema);
10984
11027
  var getTableColumn = function getTableColumn() {
10985
- var VNodeList = columnsKey.map(function (key) {
11028
+ var VNodeList = Object.keys(properties).map(function (key) {
10986
11029
  var _colField$uiProps, _colField$uiProps2;
10987
- var colField = schema.items.properties[key];
11030
+ var colField = properties[key];
10988
11031
  // 仅支持基础数据类型的属性配置,render-header、sort-method、formatter等Function类型的属性不属于json支持的数据类型,配置将不会生效
10989
11032
  var colProps = ((_colField$uiProps = colField['ui:props']) === null || _colField$uiProps === void 0 ? void 0 : _colField$uiProps.tableColumnProps) || {};
10990
11033
  // 内置表头部分需要显示tooltips的场景, tableHeaderTips的属性将会透传给v-bk-tooltips指令
@@ -11006,20 +11049,12 @@
11006
11049
  }
11007
11050
  return h(registry.getBaseWidget('table-column'), {
11008
11051
  props: _objectSpread2({
11009
- label: colField.title,
11010
- minWidth: colField.minWidth,
11011
- width: colField.width
11052
+ label: colField.title
11012
11053
  }, colProps),
11013
11054
  scopedSlots: {
11014
11055
  default: function _default(props) {
11015
11056
  return h(SchemaField, {
11016
- ref: key + props.$index,
11017
- props: {
11018
- context: context,
11019
- rootData: rootData,
11020
- readonly: readonly,
11021
- readonlyMode: readonlyMode,
11022
- disabled: disabled,
11057
+ props: _objectSpread2(_objectSpread2({}, _this2.$props), {}, {
11023
11058
  schema: mergeDeep(colField, {
11024
11059
  'ui:props': {
11025
11060
  // 默认不展示标题
@@ -11030,7 +11065,7 @@
11030
11065
  }),
11031
11066
  path: Path.getCurPath(path, "".concat(props.$index, ".").concat(key)),
11032
11067
  value: props.row[key]
11033
- },
11068
+ }),
11034
11069
  on: {
11035
11070
  input: function input(data) {
11036
11071
  self.handleCellValChange(data);
@@ -11050,10 +11085,11 @@
11050
11085
  },
11051
11086
  scopedSlots: {
11052
11087
  default: function _default(props) {
11088
+ var _schema$uiProps;
11053
11089
  return h('div', {
11054
11090
  class: {
11055
11091
  'table-widget-actions': true,
11056
- 'is-disabled': schema['ui:props'].disabled
11092
+ 'is-disabled': (_schema$uiProps = schema['ui:props']) === null || _schema$uiProps === void 0 ? void 0 : _schema$uiProps.disabled
11057
11093
  }
11058
11094
  }, [h('i', {
11059
11095
  class: 'bk-icon icon-plus-circle action-btn',