@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.
@@ -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: 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;
@@ -10213,12 +10232,47 @@ var Widget = Vue.extend({
10213
10232
  val = item.label;
10214
10233
  }
10215
10234
  }
10216
- return val === '' ? '--' : String(val);
10235
+ var value = val === '' ? '--' : val;
10236
+ if (Object.prototype.toString.call(value) === '[Object Object]') {
10237
+ value = JSON.stringify(value);
10238
+ } else if (Array.isArray(value)) {
10239
+ var isTrue = value.some(function (item) {
10240
+ return item && _typeof(item) === 'object';
10241
+ });
10242
+ if (isTrue) {
10243
+ value = JSON.stringify(value);
10244
+ } else {
10245
+ value = value.join(',');
10246
+ }
10247
+ } else {
10248
+ value = String(value);
10249
+ }
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
+ }
10217
10271
  }
10218
10272
  },
10219
10273
  render: function render(h) {
10220
- var _events$callbacks, _this$$scopedSlots$de, _this$$scopedSlots$de2, _this$$scopedSlots, _this$schema$uiCompo2, _this$$scopedSlots$su, _this$$scopedSlots2;
10221
- 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),
10222
10276
  name = _Schema$getUiComponen.name,
10223
10277
  uiVnodeData = _objectWithoutProperties(_Schema$getUiComponen, _excluded2);
10224
10278
  // 注意顺序!!!
@@ -10227,13 +10281,15 @@ var Widget = Vue.extend({
10227
10281
  value: this.value
10228
10282
  });
10229
10283
  var self = this;
10230
- var widgetName = registry.getComponent(name) || name || Schema.getDefaultWidget(this.schema);
10284
+ var widgetName = registry.getComponent(name) || name || Schema.getDefaultWidget(this.widgetSchema);
10231
10285
  var widgetEvents = ((_events$callbacks = events.callbacks) === null || _events$callbacks === void 0 ? void 0 : _events$callbacks[this.path]) || {};
10232
10286
  // 当前state属性优先级最高
10233
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, {
10234
10288
  path: this.path
10235
10289
  })) !== null && _this$$scopedSlots$de !== void 0 ? _this$$scopedSlots$de : h(widgetName, mergeDeep({
10236
- props: _objectSpread2({}, widgetProps),
10290
+ props: _objectSpread2(_objectSpread2({}, widgetProps), {}, {
10291
+ schema: this.widgetSchema
10292
+ }),
10237
10293
  attrs: _objectSpread2({}, uiVnodeData.props || {}),
10238
10294
  class: {
10239
10295
  pr20: this.removeable
@@ -10279,6 +10335,7 @@ var Widget = Vue.extend({
10279
10335
  })]);
10280
10336
  };
10281
10337
  return h(registry.getBaseWidget('form-item'), {
10338
+ key: this.key,
10282
10339
  props: this.formItemProps,
10283
10340
  style: _objectSpread2(_objectSpread2(_objectSpread2({}, this.layout.item || {}), this.layout.container || {}), {}, {
10284
10341
  // 表单项显示和隐藏状态
@@ -10287,9 +10344,9 @@ var Widget = Vue.extend({
10287
10344
  class: {
10288
10345
  'bk-schema-form-item--error': this.state.error
10289
10346
  }
10290
- }, [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, {
10291
10348
  path: this.path,
10292
- schema: this.schema
10349
+ schema: this.widgetSchema
10293
10350
  }), this.removeable && renderDelete(), this.state.error ? h('p', {
10294
10351
  class: 'bk-schema-form-item__error-tips'
10295
10352
  }, this.errorTips) : null, this.formItemProps.tips ? h('p', {
@@ -10902,6 +10959,22 @@ var getRowDefaultData = function getRowDefaultData() {
10902
10959
  var TableWidget = Vue.extend({
10903
10960
  name: 'TableWidget',
10904
10961
  props: props,
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');
10974
+ });
10975
+ }
10976
+ }
10977
+ },
10905
10978
  methods: {
10906
10979
  // 单元格表单编辑
10907
10980
  handleCellValChange: function handleCellValChange(_ref) {
@@ -10913,36 +10986,40 @@ var TableWidget = Vue.extend({
10913
10986
  },
10914
10987
  // 新增
10915
10988
  handleAddRow: function handleAddRow(index) {
10916
- var _this$$props$schema$i;
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;
10917
10991
  var newValue = this.value.slice(0);
10918
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))));
10919
10993
  this.$emit('input', newValue);
10920
10994
  },
10921
10995
  // 删除
10922
10996
  handleDelRow: function handleDelRow(index) {
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;
10923
10999
  var newValue = this.value.slice(0);
10924
11000
  newValue.splice(index, 1);
10925
11001
  this.$emit('input', newValue);
10926
11002
  }
10927
11003
  },
10928
11004
  render: function render(h) {
10929
- var _schema$items,
10930
- _this = this;
11005
+ var _this2 = this;
10931
11006
  var self = this;
10932
- var _this$$props = this.$props,
10933
- schema = _this$$props.schema,
10934
- readonly = _this$$props.readonly,
10935
- readonlyMode = _this$$props.readonlyMode,
10936
- path = _this$$props.path,
10937
- context = _this$$props.context,
10938
- rootData = _this$$props.rootData,
10939
- value = _this$$props.value;
10940
- 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
+ }
10941
11018
  var uiOptions = Schema.getUiOptions(schema);
10942
11019
  var getTableColumn = function getTableColumn() {
10943
- var VNodeList = columnsKey.map(function (key) {
11020
+ var VNodeList = Object.keys(properties).map(function (key) {
10944
11021
  var _colField$uiProps, _colField$uiProps2;
10945
- var colField = schema.items.properties[key];
11022
+ var colField = properties[key];
10946
11023
  // 仅支持基础数据类型的属性配置,render-header、sort-method、formatter等Function类型的属性不属于json支持的数据类型,配置将不会生效
10947
11024
  var colProps = ((_colField$uiProps = colField['ui:props']) === null || _colField$uiProps === void 0 ? void 0 : _colField$uiProps.tableColumnProps) || {};
10948
11025
  // 内置表头部分需要显示tooltips的场景, tableHeaderTips的属性将会透传给v-bk-tooltips指令
@@ -10969,11 +11046,7 @@ var TableWidget = Vue.extend({
10969
11046
  scopedSlots: {
10970
11047
  default: function _default(props) {
10971
11048
  return h(SchemaField, {
10972
- props: {
10973
- context: context,
10974
- rootData: rootData,
10975
- readonly: readonly,
10976
- readonlyMode: readonlyMode,
11049
+ props: _objectSpread2(_objectSpread2({}, _this2.$props), {}, {
10977
11050
  schema: mergeDeep(colField, {
10978
11051
  'ui:props': {
10979
11052
  // 默认不展示标题
@@ -10984,7 +11057,7 @@ var TableWidget = Vue.extend({
10984
11057
  }),
10985
11058
  path: Path.getCurPath(path, "".concat(props.$index, ".").concat(key)),
10986
11059
  value: props.row[key]
10987
- },
11060
+ }),
10988
11061
  on: {
10989
11062
  input: function input(data) {
10990
11063
  self.handleCellValChange(data);
@@ -10995,16 +11068,21 @@ var TableWidget = Vue.extend({
10995
11068
  }
10996
11069
  });
10997
11070
  });
10998
- if (!_this.readonly && uiOptions.modifyRows !== false) {
11071
+ if (!_this2.readonly && uiOptions.modifyRows !== false) {
10999
11072
  VNodeList.push(h(registry.getBaseWidget('table-column'), {
11000
11073
  props: {
11001
11074
  label: '操作',
11002
- width: 100
11075
+ width: 100,
11076
+ fixed: 'right'
11003
11077
  },
11004
11078
  scopedSlots: {
11005
11079
  default: function _default(props) {
11080
+ var _schema$uiProps;
11006
11081
  return h('div', {
11007
- class: 'table-widget-actions'
11082
+ class: {
11083
+ 'table-widget-actions': true,
11084
+ 'is-disabled': (_schema$uiProps = schema['ui:props']) === null || _schema$uiProps === void 0 ? void 0 : _schema$uiProps.disabled
11085
+ }
11008
11086
  }, [h('i', {
11009
11087
  class: 'bk-icon icon-plus-circle action-btn',
11010
11088
  on: {
@@ -11042,7 +11120,7 @@ var TableWidget = Vue.extend({
11042
11120
  },
11043
11121
  scopedSlots: {
11044
11122
  empty: function empty() {
11045
- return _this.readonly || uiOptions.modifyRows === false ? null : h('div', {
11123
+ return _this2.readonly || uiOptions.modifyRows === false ? null : h('div', {
11046
11124
  style: {
11047
11125
  color: '#3a84ff',
11048
11126
  cursor: 'pointer'