@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.
@@ -1931,19 +1931,19 @@ var WidgetTree = /*#__PURE__*/function () {
1931
1931
  // 普通节点
1932
1932
  var parentId = Path.getParentPath(path);
1933
1933
  var parentNode = this.widgetMap[parentId];
1934
- if (!parentNode) {
1935
- console.warn('Unexpected parent id, add widget failed');
1936
- return;
1937
- }
1938
1934
  var _node = new WidgetNode({
1939
- id: instance.path,
1935
+ id: (instance === null || instance === void 0 ? void 0 : instance.path) || path,
1940
1936
  type: type,
1941
1937
  index: index,
1942
1938
  parent: parentNode,
1943
1939
  instance: instance,
1944
1940
  children: []
1945
1941
  });
1946
- parentNode.appendChild(_node);
1942
+ if (!parentNode) {
1943
+ console.warn('Unexpected parent id, please check widget node', _node);
1944
+ } else {
1945
+ parentNode.appendChild(_node);
1946
+ }
1947
1947
  this.widgetMap[path] = _node;
1948
1948
  }
1949
1949
  }
@@ -9813,13 +9813,14 @@ var setWidgetErrorTips = function setWidgetErrorTips(path, isError, errorMsg) {
9813
9813
  var widgetPaths = path.split('.');
9814
9814
  var fieldTitleBreadcrumb = [];
9815
9815
  widgetPaths.forEach(function (thePath, thePathIndex) {
9816
+ var _theWidget$instance;
9816
9817
  var currentPaths = widgetPaths.slice(0, widgetPaths.length - thePathIndex);
9817
9818
  var widgetPath = currentPaths.join('.');
9818
9819
  var theWidget = widgetTree.widgetMap[widgetPath];
9819
9820
  // todo(判断path是否是数组索引)
9820
9821
  var isIndex = theWidget.instance.schema.type === 'array' || !theWidget.instance.schema.title;
9821
9822
  fieldTitleBreadcrumb.push(isIndex ? currentPaths.pop() : theWidget.instance.schema.title);
9822
- if (theWidget.instance.verifiable && theWidget.type === 'group') {
9823
+ if ((_theWidget$instance = theWidget.instance) !== null && _theWidget$instance !== void 0 && _theWidget$instance.verifiable && theWidget.type === 'group') {
9823
9824
  if (isError) {
9824
9825
  var groupErrors = "".concat(fieldTitleBreadcrumb.reverse().join('-'), ": ").concat(errorMsg);
9825
9826
  theWidget.instance.setGroupErrorTips(path, groupErrors);
@@ -9852,9 +9853,10 @@ var validateFormItem = function validateFormItem(path) {
9852
9853
  // 清空所在组错误信息
9853
9854
  var widgetPaths = path.split('.');
9854
9855
  widgetPaths.forEach(function (thePath, thePathIndex) {
9856
+ var _theWidget$instance2;
9855
9857
  var currentPaths = widgetPaths.slice(0, widgetPaths.length - thePathIndex).join('.');
9856
9858
  var theWidget = widgetTree.widgetMap[currentPaths];
9857
- if (theWidget.instance.verifiable && theWidget.type === 'group') {
9859
+ if ((_theWidget$instance2 = theWidget.instance) !== null && _theWidget$instance2 !== void 0 && _theWidget$instance2.verifiable && theWidget.type === 'group') {
9858
9860
  theWidget.instance.removeGroupErrorTips(path);
9859
9861
  }
9860
9862
  });
@@ -10080,16 +10082,25 @@ var Widget = Vue.extend({
10080
10082
  readonly: this.readonly,
10081
10083
  error: this.error
10082
10084
  },
10083
- errorTips: ''
10085
+ errorTips: '',
10086
+ privateSchema: {},
10087
+ key: ''
10084
10088
  };
10085
10089
  },
10086
10090
  computed: {
10091
+ widgetMap: function widgetMap() {
10092
+ return widgetTree.widgetMap;
10093
+ },
10087
10094
  widgetNode: function widgetNode() {
10088
10095
  return widgetTree.widgetMap[this.path];
10089
10096
  },
10090
10097
  parent: function parent() {
10091
10098
  var _this$widgetNode;
10092
10099
  return (_this$widgetNode = this.widgetNode) === null || _this$widgetNode === void 0 ? void 0 : _this$widgetNode.parent;
10100
+ },
10101
+ // 当前widget schema数据
10102
+ widgetSchema: function widgetSchema() {
10103
+ return mergeDeep({}, this.schema, this.privateSchema);
10093
10104
  }
10094
10105
  },
10095
10106
  watch: {
@@ -10103,19 +10114,27 @@ var Widget = Vue.extend({
10103
10114
  }, 0);
10104
10115
  }
10105
10116
  }
10117
+ },
10118
+ widgetSchema: {
10119
+ deep: true,
10120
+ handler: function handler(newValue, oldValue) {
10121
+ if (deepEquals(newValue, oldValue)) return;
10122
+ this.resetDatasource();
10123
+ this.key = new Date().getTime();
10124
+ }
10106
10125
  }
10107
10126
  },
10108
10127
  created: function created() {
10109
10128
  var _this2 = this;
10110
10129
  // 表单项配置
10111
- var uiOptions = Schema.getUiOptions(this.schema);
10130
+ var uiOptions = Schema.getUiOptions(this.widgetSchema);
10112
10131
  this.formItemProps = _objectSpread2(_objectSpread2({}, uiOptions), {}, {
10113
10132
  // schema配置不存在title时默认用属性名作为title
10114
10133
  label: uiOptions.showTitle ? uiOptions.label || Path.getPathLastProp(this.path) : '',
10115
10134
  required: this.required
10116
10135
  });
10117
10136
  // 设置widget初始化状态 ui:component优先级 > ui:props优先级
10118
- var vNodeData = Schema.getUiComponent(this.schema);
10137
+ var vNodeData = Schema.getUiComponent(this.widgetSchema);
10119
10138
  var defaultProps = Object.assign({}, this.formItemProps, vNodeData.props || {});
10120
10139
  Object.keys(defaultProps).forEach(function (key) {
10121
10140
  if (Reflect.has(_this2.state, key)) {
@@ -10127,7 +10146,7 @@ var Widget = Vue.extend({
10127
10146
  },
10128
10147
  mounted: function mounted() {
10129
10148
  // 注册联动
10130
- reactionRegister(this.path, this.schema['ui:reactions']);
10149
+ reactionRegister(this.path, this.widgetSchema['ui:reactions']);
10131
10150
  // 首次联动
10132
10151
  reactionDispatch(this.path, 'valChange');
10133
10152
  reactionDispatch(this.path, 'lifetime/init');
@@ -10153,12 +10172,12 @@ var Widget = Vue.extend({
10153
10172
  loadDataSource: function loadDataSource() {
10154
10173
  var _this3 = this;
10155
10174
  return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
10156
- var _this3$schema, _this3$schema$uiComp, _this3$schema$uiComp$;
10175
+ var _this3$widgetSchema, _this3$widgetSchema$u, _this3$widgetSchema$u2;
10157
10176
  var xhrConfig, url, params, reset, _this3$httpAdapter, _this3$httpAdapter$re, http, responseParse, remoteURL, requestParams;
10158
10177
  return _regeneratorRuntime().wrap(function _callee$(_context) {
10159
10178
  while (1) switch (_context.prev = _context.next) {
10160
10179
  case 0:
10161
- 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;
10180
+ 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;
10162
10181
  if (!xhrConfig) {
10163
10182
  _context.next = 18;
10164
10183
  break;
@@ -10198,11 +10217,11 @@ var Widget = Vue.extend({
10198
10217
  return Path.getPathVal(this.rootData, path);
10199
10218
  },
10200
10219
  getReadonlyValue: function getReadonlyValue() {
10201
- var _this$schema$uiCompo,
10202
- _this$schema$uiCompo$,
10220
+ var _this$widgetSchema$ui,
10221
+ _this$widgetSchema$ui2,
10203
10222
  _this4 = this;
10204
10223
  var val = this.value;
10205
- 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') {
10224
+ 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') {
10206
10225
  val = '******';
10207
10226
  } else if (this.datasource) {
10208
10227
  var _this$datasource;
@@ -10214,7 +10233,7 @@ var Widget = Vue.extend({
10214
10233
  }
10215
10234
  }
10216
10235
  var value = val === '' ? '--' : val;
10217
- if (Object.prototype.call(value) === '[Object Object]') {
10236
+ if (Object.prototype.toString.call(value) === '[Object Object]') {
10218
10237
  value = JSON.stringify(value);
10219
10238
  } else if (Array.isArray(value)) {
10220
10239
  var isTrue = value.some(function (item) {
@@ -10229,11 +10248,31 @@ var Widget = Vue.extend({
10229
10248
  value = String(value);
10230
10249
  }
10231
10250
  return value;
10251
+ },
10252
+ getSchema: function getSchema() {
10253
+ return this.widgetSchema;
10254
+ },
10255
+ setSchema: function setSchema(data) {
10256
+ try {
10257
+ this.privateSchema = JSON.parse(JSON.stringify(data));
10258
+ } catch (err) {
10259
+ console.warn(err);
10260
+ }
10261
+ return this.widgetSchema;
10262
+ },
10263
+ resetDatasource: function resetDatasource() {
10264
+ var _this$widgetSchema, _this$widgetSchema$ui3, _this$widgetSchema$ui4;
10265
+ 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;
10266
+ if (xhrConfig) {
10267
+ this.loadDataSource();
10268
+ } else {
10269
+ this.datasource = Schema.resolveDefaultDatasource(this.widgetSchema);
10270
+ }
10232
10271
  }
10233
10272
  },
10234
10273
  render: function render(h) {
10235
- var _events$callbacks, _this$$scopedSlots$de, _this$$scopedSlots$de2, _this$$scopedSlots, _this$schema$uiCompo2, _this$$scopedSlots$su, _this$$scopedSlots2;
10236
- var _Schema$getUiComponen = Schema.getUiComponent(this.schema),
10274
+ var _events$callbacks, _this$$scopedSlots$de, _this$$scopedSlots$de2, _this$$scopedSlots, _this$widgetSchema$ui5, _this$$scopedSlots$su, _this$$scopedSlots2;
10275
+ var _Schema$getUiComponen = Schema.getUiComponent(this.widgetSchema),
10237
10276
  name = _Schema$getUiComponen.name,
10238
10277
  uiVnodeData = _objectWithoutProperties(_Schema$getUiComponen, _excluded2);
10239
10278
  // 注意顺序!!!
@@ -10242,13 +10281,15 @@ var Widget = Vue.extend({
10242
10281
  value: this.value
10243
10282
  });
10244
10283
  var self = this;
10245
- var widgetName = registry.getComponent(name) || name || Schema.getDefaultWidget(this.schema);
10284
+ var widgetName = registry.getComponent(name) || name || Schema.getDefaultWidget(this.widgetSchema);
10246
10285
  var widgetEvents = ((_events$callbacks = events.callbacks) === null || _events$callbacks === void 0 ? void 0 : _events$callbacks[this.path]) || {};
10247
10286
  // 当前state属性优先级最高
10248
10287
  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, {
10249
10288
  path: this.path
10250
10289
  })) !== null && _this$$scopedSlots$de !== void 0 ? _this$$scopedSlots$de : h(widgetName, mergeDeep({
10251
- props: _objectSpread2({}, widgetProps),
10290
+ props: _objectSpread2(_objectSpread2({}, widgetProps), {}, {
10291
+ schema: this.widgetSchema
10292
+ }),
10252
10293
  attrs: _objectSpread2({}, uiVnodeData.props || {}),
10253
10294
  class: {
10254
10295
  pr20: this.removeable
@@ -10294,6 +10335,7 @@ var Widget = Vue.extend({
10294
10335
  })]);
10295
10336
  };
10296
10337
  return h(registry.getBaseWidget('form-item'), {
10338
+ key: this.key,
10297
10339
  props: this.formItemProps,
10298
10340
  style: _objectSpread2(_objectSpread2(_objectSpread2({}, this.layout.item || {}), this.layout.container || {}), {}, {
10299
10341
  // 表单项显示和隐藏状态
@@ -10302,9 +10344,9 @@ var Widget = Vue.extend({
10302
10344
  class: {
10303
10345
  'bk-schema-form-item--error': this.state.error
10304
10346
  }
10305
- }, [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, {
10347
+ }, [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, {
10306
10348
  path: this.path,
10307
- schema: this.schema
10349
+ schema: this.widgetSchema
10308
10350
  }), this.removeable && renderDelete(), this.state.error ? h('p', {
10309
10351
  class: 'bk-schema-form-item__error-tips'
10310
10352
  }, this.errorTips) : null, this.formItemProps.tips ? h('p', {
@@ -10917,21 +10959,21 @@ var getRowDefaultData = function getRowDefaultData() {
10917
10959
  var TableWidget = Vue.extend({
10918
10960
  name: 'TableWidget',
10919
10961
  props: props,
10920
- mounted: function mounted() {
10921
- var _this = this;
10922
- this.$nextTick(function () {
10923
- var fieldMap = _this.schema.items.properties;
10924
- _this.value.forEach(function (item, index) {
10925
- Object.keys(fieldMap).forEach(function (key) {
10926
- var config = fieldMap[key];
10927
- if (config['ui:rules']) {
10928
- var instance = _this.$refs[key + index];
10929
- // 注册widget TreeNode
10930
- widgetTree.addWidgetNode("".concat(_this.path, ".").concat(key), instance, 'node');
10931
- }
10962
+ watch: {
10963
+ value: {
10964
+ immediate: true,
10965
+ handler: function handler() {
10966
+ var _this$value,
10967
+ _this = this;
10968
+ (_this$value = this.value) === null || _this$value === void 0 ? void 0 : _this$value.forEach(function (_, index) {
10969
+ var path = "".concat(_this.path, ".").concat(index);
10970
+ // 销毁上一次的缓存
10971
+ widgetTree.removeWidgetNode(path, null);
10972
+ // 重新当前行的父节点
10973
+ widgetTree.addWidgetNode(path, null, 'group');
10932
10974
  });
10933
- });
10934
- });
10975
+ }
10976
+ }
10935
10977
  },
10936
10978
  methods: {
10937
10979
  // 单元格表单编辑
@@ -10944,39 +10986,40 @@ var TableWidget = Vue.extend({
10944
10986
  },
10945
10987
  // 新增
10946
10988
  handleAddRow: function handleAddRow(index) {
10947
- var _this$$props$schema$i;
10948
- if (this.schema['ui:props'].disabled) return;
10989
+ var _this$schema$uiProps, _this$$props$schema$i;
10990
+ if ((_this$schema$uiProps = this.schema['ui:props']) !== null && _this$schema$uiProps !== void 0 && _this$schema$uiProps.disabled) return;
10949
10991
  var newValue = this.value.slice(0);
10950
10992
  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))));
10951
10993
  this.$emit('input', newValue);
10952
10994
  },
10953
10995
  // 删除
10954
10996
  handleDelRow: function handleDelRow(index) {
10955
- if (this.schema['ui:props'].disabled) return;
10997
+ var _this$schema$uiProps2;
10998
+ if ((_this$schema$uiProps2 = this.schema['ui:props']) !== null && _this$schema$uiProps2 !== void 0 && _this$schema$uiProps2.disabled) return;
10956
10999
  var newValue = this.value.slice(0);
10957
11000
  newValue.splice(index, 1);
10958
11001
  this.$emit('input', newValue);
10959
11002
  }
10960
11003
  },
10961
11004
  render: function render(h) {
10962
- var _schema$items,
10963
- _this2 = this;
11005
+ var _this2 = this;
10964
11006
  var self = this;
10965
- var _this$$props = this.$props,
10966
- schema = _this$$props.schema,
10967
- readonly = _this$$props.readonly,
10968
- readonlyMode = _this$$props.readonlyMode,
10969
- path = _this$$props.path,
10970
- context = _this$$props.context,
10971
- rootData = _this$$props.rootData,
10972
- value = _this$$props.value,
10973
- disabled = _this$$props.disabled;
10974
- var columnsKey = Object.keys(((_schema$items = schema.items) === null || _schema$items === void 0 ? void 0 : _schema$items.properties) || []);
11007
+ var schema = this.schema,
11008
+ path = this.path,
11009
+ value = this.value;
11010
+ var schemaItems = schema.items;
11011
+ var properties = {};
11012
+ if (schemaItems !== null && schemaItems !== void 0 && schemaItems.properties) {
11013
+ properties = schemaItems === null || schemaItems === void 0 ? void 0 : schemaItems.properties;
11014
+ } else {
11015
+ // table类型目前只支持items的类型为对象的schema
11016
+ console.warn('The current schema type is not supported table component', schemaItems);
11017
+ }
10975
11018
  var uiOptions = Schema.getUiOptions(schema);
10976
11019
  var getTableColumn = function getTableColumn() {
10977
- var VNodeList = columnsKey.map(function (key) {
11020
+ var VNodeList = Object.keys(properties).map(function (key) {
10978
11021
  var _colField$uiProps, _colField$uiProps2;
10979
- var colField = schema.items.properties[key];
11022
+ var colField = properties[key];
10980
11023
  // 仅支持基础数据类型的属性配置,render-header、sort-method、formatter等Function类型的属性不属于json支持的数据类型,配置将不会生效
10981
11024
  var colProps = ((_colField$uiProps = colField['ui:props']) === null || _colField$uiProps === void 0 ? void 0 : _colField$uiProps.tableColumnProps) || {};
10982
11025
  // 内置表头部分需要显示tooltips的场景, tableHeaderTips的属性将会透传给v-bk-tooltips指令
@@ -10998,20 +11041,12 @@ var TableWidget = Vue.extend({
10998
11041
  }
10999
11042
  return h(registry.getBaseWidget('table-column'), {
11000
11043
  props: _objectSpread2({
11001
- label: colField.title,
11002
- minWidth: colField.minWidth,
11003
- width: colField.width
11044
+ label: colField.title
11004
11045
  }, colProps),
11005
11046
  scopedSlots: {
11006
11047
  default: function _default(props) {
11007
11048
  return h(SchemaField, {
11008
- ref: key + props.$index,
11009
- props: {
11010
- context: context,
11011
- rootData: rootData,
11012
- readonly: readonly,
11013
- readonlyMode: readonlyMode,
11014
- disabled: disabled,
11049
+ props: _objectSpread2(_objectSpread2({}, _this2.$props), {}, {
11015
11050
  schema: mergeDeep(colField, {
11016
11051
  'ui:props': {
11017
11052
  // 默认不展示标题
@@ -11022,7 +11057,7 @@ var TableWidget = Vue.extend({
11022
11057
  }),
11023
11058
  path: Path.getCurPath(path, "".concat(props.$index, ".").concat(key)),
11024
11059
  value: props.row[key]
11025
- },
11060
+ }),
11026
11061
  on: {
11027
11062
  input: function input(data) {
11028
11063
  self.handleCellValChange(data);
@@ -11042,10 +11077,11 @@ var TableWidget = Vue.extend({
11042
11077
  },
11043
11078
  scopedSlots: {
11044
11079
  default: function _default(props) {
11080
+ var _schema$uiProps;
11045
11081
  return h('div', {
11046
11082
  class: {
11047
11083
  'table-widget-actions': true,
11048
- 'is-disabled': schema['ui:props'].disabled
11084
+ 'is-disabled': (_schema$uiProps = schema['ui:props']) === null || _schema$uiProps === void 0 ? void 0 : _schema$uiProps.disabled
11049
11085
  }
11050
11086
  }, [h('i', {
11051
11087
  class: 'bk-icon icon-plus-circle action-btn',