@blueking/bkui-form 0.0.39 → 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: 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;
@@ -10221,12 +10240,47 @@
10221
10240
  val = item.label;
10222
10241
  }
10223
10242
  }
10224
- return val === '' ? '--' : String(val);
10243
+ var value = val === '' ? '--' : val;
10244
+ if (Object.prototype.toString.call(value) === '[Object Object]') {
10245
+ value = JSON.stringify(value);
10246
+ } else if (Array.isArray(value)) {
10247
+ var isTrue = value.some(function (item) {
10248
+ return item && _typeof(item) === 'object';
10249
+ });
10250
+ if (isTrue) {
10251
+ value = JSON.stringify(value);
10252
+ } else {
10253
+ value = value.join(',');
10254
+ }
10255
+ } else {
10256
+ value = String(value);
10257
+ }
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
+ }
10225
10279
  }
10226
10280
  },
10227
10281
  render: function render(h) {
10228
- var _events$callbacks, _this$$scopedSlots$de, _this$$scopedSlots$de2, _this$$scopedSlots, _this$schema$uiCompo2, _this$$scopedSlots$su, _this$$scopedSlots2;
10229
- 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),
10230
10284
  name = _Schema$getUiComponen.name,
10231
10285
  uiVnodeData = _objectWithoutProperties(_Schema$getUiComponen, _excluded2);
10232
10286
  // 注意顺序!!!
@@ -10235,13 +10289,15 @@
10235
10289
  value: this.value
10236
10290
  });
10237
10291
  var self = this;
10238
- var widgetName = registry.getComponent(name) || name || Schema.getDefaultWidget(this.schema);
10292
+ var widgetName = registry.getComponent(name) || name || Schema.getDefaultWidget(this.widgetSchema);
10239
10293
  var widgetEvents = ((_events$callbacks = events.callbacks) === null || _events$callbacks === void 0 ? void 0 : _events$callbacks[this.path]) || {};
10240
10294
  // 当前state属性优先级最高
10241
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, {
10242
10296
  path: this.path
10243
10297
  })) !== null && _this$$scopedSlots$de !== void 0 ? _this$$scopedSlots$de : h(widgetName, mergeDeep({
10244
- props: _objectSpread2({}, widgetProps),
10298
+ props: _objectSpread2(_objectSpread2({}, widgetProps), {}, {
10299
+ schema: this.widgetSchema
10300
+ }),
10245
10301
  attrs: _objectSpread2({}, uiVnodeData.props || {}),
10246
10302
  class: {
10247
10303
  pr20: this.removeable
@@ -10287,6 +10343,7 @@
10287
10343
  })]);
10288
10344
  };
10289
10345
  return h(registry.getBaseWidget('form-item'), {
10346
+ key: this.key,
10290
10347
  props: this.formItemProps,
10291
10348
  style: _objectSpread2(_objectSpread2(_objectSpread2({}, this.layout.item || {}), this.layout.container || {}), {}, {
10292
10349
  // 表单项显示和隐藏状态
@@ -10295,9 +10352,9 @@
10295
10352
  class: {
10296
10353
  'bk-schema-form-item--error': this.state.error
10297
10354
  }
10298
- }, [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, {
10299
10356
  path: this.path,
10300
- schema: this.schema
10357
+ schema: this.widgetSchema
10301
10358
  }), this.removeable && renderDelete(), this.state.error ? h('p', {
10302
10359
  class: 'bk-schema-form-item__error-tips'
10303
10360
  }, this.errorTips) : null, this.formItemProps.tips ? h('p', {
@@ -10910,6 +10967,22 @@
10910
10967
  var TableWidget = Vue__default["default"].extend({
10911
10968
  name: 'TableWidget',
10912
10969
  props: props,
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');
10982
+ });
10983
+ }
10984
+ }
10985
+ },
10913
10986
  methods: {
10914
10987
  // 单元格表单编辑
10915
10988
  handleCellValChange: function handleCellValChange(_ref) {
@@ -10921,36 +10994,40 @@
10921
10994
  },
10922
10995
  // 新增
10923
10996
  handleAddRow: function handleAddRow(index) {
10924
- var _this$$props$schema$i;
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;
10925
10999
  var newValue = this.value.slice(0);
10926
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))));
10927
11001
  this.$emit('input', newValue);
10928
11002
  },
10929
11003
  // 删除
10930
11004
  handleDelRow: function handleDelRow(index) {
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;
10931
11007
  var newValue = this.value.slice(0);
10932
11008
  newValue.splice(index, 1);
10933
11009
  this.$emit('input', newValue);
10934
11010
  }
10935
11011
  },
10936
11012
  render: function render(h) {
10937
- var _schema$items,
10938
- _this = this;
11013
+ var _this2 = this;
10939
11014
  var self = this;
10940
- var _this$$props = this.$props,
10941
- schema = _this$$props.schema,
10942
- readonly = _this$$props.readonly,
10943
- readonlyMode = _this$$props.readonlyMode,
10944
- path = _this$$props.path,
10945
- context = _this$$props.context,
10946
- rootData = _this$$props.rootData,
10947
- value = _this$$props.value;
10948
- 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
+ }
10949
11026
  var uiOptions = Schema.getUiOptions(schema);
10950
11027
  var getTableColumn = function getTableColumn() {
10951
- var VNodeList = columnsKey.map(function (key) {
11028
+ var VNodeList = Object.keys(properties).map(function (key) {
10952
11029
  var _colField$uiProps, _colField$uiProps2;
10953
- var colField = schema.items.properties[key];
11030
+ var colField = properties[key];
10954
11031
  // 仅支持基础数据类型的属性配置,render-header、sort-method、formatter等Function类型的属性不属于json支持的数据类型,配置将不会生效
10955
11032
  var colProps = ((_colField$uiProps = colField['ui:props']) === null || _colField$uiProps === void 0 ? void 0 : _colField$uiProps.tableColumnProps) || {};
10956
11033
  // 内置表头部分需要显示tooltips的场景, tableHeaderTips的属性将会透传给v-bk-tooltips指令
@@ -10977,11 +11054,7 @@
10977
11054
  scopedSlots: {
10978
11055
  default: function _default(props) {
10979
11056
  return h(SchemaField, {
10980
- props: {
10981
- context: context,
10982
- rootData: rootData,
10983
- readonly: readonly,
10984
- readonlyMode: readonlyMode,
11057
+ props: _objectSpread2(_objectSpread2({}, _this2.$props), {}, {
10985
11058
  schema: mergeDeep(colField, {
10986
11059
  'ui:props': {
10987
11060
  // 默认不展示标题
@@ -10992,7 +11065,7 @@
10992
11065
  }),
10993
11066
  path: Path.getCurPath(path, "".concat(props.$index, ".").concat(key)),
10994
11067
  value: props.row[key]
10995
- },
11068
+ }),
10996
11069
  on: {
10997
11070
  input: function input(data) {
10998
11071
  self.handleCellValChange(data);
@@ -11003,16 +11076,21 @@
11003
11076
  }
11004
11077
  });
11005
11078
  });
11006
- if (!_this.readonly && uiOptions.modifyRows !== false) {
11079
+ if (!_this2.readonly && uiOptions.modifyRows !== false) {
11007
11080
  VNodeList.push(h(registry.getBaseWidget('table-column'), {
11008
11081
  props: {
11009
11082
  label: '操作',
11010
- width: 100
11083
+ width: 100,
11084
+ fixed: 'right'
11011
11085
  },
11012
11086
  scopedSlots: {
11013
11087
  default: function _default(props) {
11088
+ var _schema$uiProps;
11014
11089
  return h('div', {
11015
- class: 'table-widget-actions'
11090
+ class: {
11091
+ 'table-widget-actions': true,
11092
+ 'is-disabled': (_schema$uiProps = schema['ui:props']) === null || _schema$uiProps === void 0 ? void 0 : _schema$uiProps.disabled
11093
+ }
11016
11094
  }, [h('i', {
11017
11095
  class: 'bk-icon icon-plus-circle action-btn',
11018
11096
  on: {
@@ -11050,7 +11128,7 @@
11050
11128
  },
11051
11129
  scopedSlots: {
11052
11130
  empty: function empty() {
11053
- return _this.readonly || uiOptions.modifyRows === false ? null : h('div', {
11131
+ return _this2.readonly || uiOptions.modifyRows === false ? null : h('div', {
11054
11132
  style: {
11055
11133
  color: '#3a84ff',
11056
11134
  cursor: 'pointer'