@steedos-widgets/amis-lib 3.6.4-beta.6 → 3.6.4-beta.7

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/dist/index.esm.js CHANGED
@@ -13436,9 +13436,11 @@ function uuidv4() {
13436
13436
  * @Author: 殷亮辉 yinlianghui@hotoa.com
13437
13437
  * @Date: 2023-11-15 09:50:22
13438
13438
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
13439
- * @LastEditTime: 2024-01-26 17:47:16
13439
+ * @LastEditTime: 2024-02-29 18:36:58
13440
13440
  */
13441
13441
 
13442
+ const fieldPrefixSplit = "__";
13443
+
13442
13444
  /**
13443
13445
  * 子表组件字段值中每行数据补上字段值为空的的字段值,把值统一设置为空字符串,是为了解决amis amis 3.6/6.0 input-table组件bug:行中字段值为空时会显示为父作用域中的同名变量值,见:https://github.com/baidu/amis/issues/9520
13444
13446
  * amis #9520修正后此函数及相关代码可以移除
@@ -13553,7 +13555,12 @@ function getTableValueWithoutFieldPrefix(value, fieldPrefix) {
13553
13555
  var newItemValue = {};
13554
13556
  for (let n in itemValue) {
13555
13557
  if (itemValue.hasOwnProperty(n)) {
13556
- newItemValue[n.replace(new RegExp(`^${fieldPrefix}`), "")] = itemValue[n];
13558
+ if(n === "children"){
13559
+ newItemValue.children = getTableValueWithoutFieldPrefix(itemValue.children, fieldPrefix);
13560
+ }
13561
+ else {
13562
+ newItemValue[n.replace(new RegExp(`^${fieldPrefix}`), "")] = itemValue[n];
13563
+ }
13557
13564
  }
13558
13565
  }
13559
13566
  convertedValue.push(newItemValue);
@@ -13574,7 +13581,12 @@ function getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey) {
13574
13581
  var newItemValue = {};
13575
13582
  for (let n in itemValue) {
13576
13583
  if (itemValue.hasOwnProperty(n) && typeof itemValue[n] !== undefined && n !== primaryKey) {
13577
- newItemValue[`${fieldPrefix}${n}`] = itemValue[n];
13584
+ if(n === "children"){
13585
+ newItemValue.children = getTableValuePrependFieldPrefix(itemValue.children, fieldPrefix, primaryKey);
13586
+ }
13587
+ else {
13588
+ newItemValue[`${fieldPrefix}${n}`] = itemValue[n];
13589
+ }
13578
13590
  }
13579
13591
  }
13580
13592
  if (primaryKey && itemValue[primaryKey]) {
@@ -13599,6 +13611,23 @@ function getTableFieldsWithoutFieldPrefix(fields, fieldPrefix) {
13599
13611
  });
13600
13612
  }
13601
13613
 
13614
+ /**
13615
+ * 子表组件字段集合属性中每个字段name补上指定前缀
13616
+ * 因amis存在bug:input-table内的字段在行编辑模式时会受到外层相同name的字段的影响 https://github.com/baidu/amis/issues/9653
13617
+ * 在渲染input table组件时统一调用此函数加上前缀来避开同名字段问题
13618
+ * @param {*} fields 子表组件字段集合,数组
13619
+ * @param {*} fieldPrefix 字段前缀
13620
+ * @returns 转换后的子表组件字段值
13621
+ */
13622
+ function getTableFieldsPrependFieldPrefix(fields, fieldPrefix) {
13623
+ return (fields || []).map((item) => {
13624
+ const newItem = clone(item);
13625
+ newItem.name = `${fieldPrefix}${item.name}`;
13626
+ newItem.__originalName = item.name;
13627
+ return newItem;
13628
+ });
13629
+ }
13630
+
13602
13631
  /**
13603
13632
  * @param {*} props
13604
13633
  * @param {*} mode edit/new/readonly
@@ -13609,6 +13638,9 @@ function getFormFields(props, mode = "edit") {
13609
13638
  if (fieldPrefix) {
13610
13639
  fields = getTableFieldsWithoutFieldPrefix(fields, fieldPrefix);
13611
13640
  }
13641
+ else {
13642
+ fields = getTableFieldsPrependFieldPrefix(fields, props.name + fieldPrefixSplit);
13643
+ }
13612
13644
  return (fields || []).map(function (item) {
13613
13645
  let formItem = {
13614
13646
  "type": "steedos-field",
@@ -13677,7 +13709,7 @@ function getComponentId(name, tag) {
13677
13709
  * @param {*} props
13678
13710
  * @param {*} mode edit/new/readonly
13679
13711
  */
13680
- async function getInputTableColumns(props) {
13712
+ async function getInputTableColumns(props, buttonsForColumnOperations) {
13681
13713
  let columns = props.columns || [];
13682
13714
  let inlineEditMode = props.inlineEditMode;
13683
13715
  let showAsInlineEditMode = inlineEditMode && props.editable;
@@ -13688,6 +13720,12 @@ async function getInputTableColumns(props) {
13688
13720
  if (fieldPrefix) {
13689
13721
  fields = getTableFieldsWithoutFieldPrefix(fields, fieldPrefix);
13690
13722
  }
13723
+ else {
13724
+ fields = getTableFieldsPrependFieldPrefix(fields, props.name + fieldPrefixSplit);
13725
+ columns = getTableFieldsPrependFieldPrefix(columns.map(function (item) {
13726
+ return typeof item == "string" ? { name: item } : item;
13727
+ }), props.name + fieldPrefixSplit);
13728
+ }
13691
13729
  if (inlineEditMode == true) {
13692
13730
  let popOverContainerSelector = "";
13693
13731
  let popOverContainer = props.popOverContainer && props.popOverContainer();
@@ -13711,7 +13749,7 @@ async function getInputTableColumns(props) {
13711
13749
  }
13712
13750
 
13713
13751
  if (columns && columns.length) {
13714
- return columns.map(function (column) {
13752
+ return columns.map(function (column, index) {
13715
13753
  let field, extendColumnProps = {};
13716
13754
  if (typeof column === "string") {
13717
13755
  // 如果字符串,则取出要显示的列配置
@@ -13737,9 +13775,13 @@ async function getInputTableColumns(props) {
13737
13775
  let className = "";
13738
13776
  //判断是否换行,目前规则默认换行
13739
13777
  if(extendColumnProps.wrap != true){
13740
- className += " whitespace-nowrap ";
13778
+ className += " whitespace-nowrap";
13741
13779
  }else {
13742
- className += " break-words ";
13780
+ className += " break-words";
13781
+ }
13782
+
13783
+ if(buttonsForColumnOperations.length == 0 && !props.showIndex && index == 0) {
13784
+ className += " antd-Table-primayCell";
13743
13785
  }
13744
13786
  //合并classname
13745
13787
  if (typeof extendColumnProps.className == "object") {
@@ -13758,9 +13800,12 @@ async function getInputTableColumns(props) {
13758
13800
  });
13759
13801
  }
13760
13802
  else {
13761
- return fields.map(function (field) {
13803
+ return fields.map(function (field, index) {
13762
13804
  let tableCell = getInputTableCell(field, showAsInlineEditMode);
13763
13805
  tableCell.className = " whitespace-nowrap ";
13806
+ if(buttonsForColumnOperations.length == 0 && !props.showIndex && index == 0) {
13807
+ tableCell.className += " antd-Table-primayCell";
13808
+ }
13764
13809
  return tableCell;
13765
13810
  }) || [];
13766
13811
  }
@@ -13978,6 +14023,10 @@ function getFormPaginationWrapper(props, form, mode) {
13978
14023
  let getTableValueWithoutFieldPrefix = new Function('v', 'f', "return (" + ${getTableValueWithoutFieldPrefix.toString()} + ")(v, f)");
13979
14024
  lastestFieldValue = getTableValueWithoutFieldPrefix(lastestFieldValue, fieldPrefix);
13980
14025
  }
14026
+ else{
14027
+ let getTableValuePrependFieldPrefix = new Function('v', 'f', "return (" + ${getTableValuePrependFieldPrefix.toString()} + ")(v, f)");
14028
+ lastestFieldValue = getTableValuePrependFieldPrefix(lastestFieldValue, "${props.name + fieldPrefixSplit}", "${primaryKey}");
14029
+ }
13981
14030
  //不可以直接像event.data.__tableItems = lastestFieldValue; 这样整个赋值,否则作用域会断
13982
14031
  let mode = "${mode || ''}";
13983
14032
  if(mode === "new"){
@@ -14784,6 +14833,9 @@ const getAmisInputTableSchema = async (props) => {
14784
14833
  if (fieldPrefix) {
14785
14834
  fields = getTableFieldsWithoutFieldPrefix(fields, fieldPrefix);
14786
14835
  }
14836
+ else {
14837
+ fields = getTableFieldsPrependFieldPrefix(fields, props.name + fieldPrefixSplit);
14838
+ }
14787
14839
  let serviceId = getComponentId("table_service", props.id);
14788
14840
  let buttonsForColumnOperations = [];
14789
14841
  let inlineEditMode = props.inlineEditMode;
@@ -14835,7 +14887,7 @@ const getAmisInputTableSchema = async (props) => {
14835
14887
  "showIndex": props.showIndex,
14836
14888
  "perPage": props.perPage,
14837
14889
  "id": props.id,
14838
- "columns": await getInputTableColumns(props),
14890
+ "columns": await getInputTableColumns(props, buttonsForColumnOperations),
14839
14891
  // "needConfirm": false, //不可以配置为false,否则,单元格都是可编辑状态,且很多static类型无法正常显示,比如static-mapping
14840
14892
  "strictMode": props.strictMode,
14841
14893
  "showTableAddBtn": false,
@@ -14845,6 +14897,9 @@ const getAmisInputTableSchema = async (props) => {
14845
14897
  if (fieldPrefix) {
14846
14898
  value = getTableValueWithoutFieldPrefix(value, fieldPrefix);
14847
14899
  }
14900
+ else {
14901
+ value = getTableValuePrependFieldPrefix(value, props.name + fieldPrefixSplit, primaryKey);
14902
+ }
14848
14903
  value = getTableValueWithEmptyValue(value, fields);
14849
14904
  if (primaryKey) {
14850
14905
  // 这里临时给每行数据补上primaryKey字段值,如果库里不需要保存这里补上的字段值,pipeOut中会识别autoGeneratePrimaryKeyValue属性选择最终移除这里补上的字段值
@@ -14867,6 +14922,9 @@ const getAmisInputTableSchema = async (props) => {
14867
14922
  if (fieldPrefix) {
14868
14923
  value = getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey);
14869
14924
  }
14925
+ else {
14926
+ value = getTableValueWithoutFieldPrefix(value, props.name + fieldPrefixSplit);
14927
+ }
14870
14928
  value = getTableValueWithoutEmptyValue(value, fields);
14871
14929
  if (props.autoGeneratePrimaryKeyValue === true) {
14872
14930
  // 如果需要把自动生成的primaryKey值输出保存的库中,则补全所有行中的primaryKey值