@steedos-widgets/amis-lib 3.6.2-beta.14 → 3.6.2-beta.15

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.cjs.js CHANGED
@@ -12253,7 +12253,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
12253
12253
  convertData = {
12254
12254
  type: getAmisStaticFieldType('datetime', readonly),
12255
12255
  inputFormat: 'YYYY-MM-DD HH:mm',
12256
- format: 'YYYY-MM-DDTHH:mm:ss.SSSZ',
12256
+ format: 'YYYY-MM-DDTHH:mm:00.000Z',
12257
12257
  tpl: readonly ? getDateTimeTpl(field) : null,
12258
12258
  utc: true,
12259
12259
  };
@@ -13025,9 +13025,57 @@ function uuidv4() {
13025
13025
  * @Author: 殷亮辉 yinlianghui@hotoa.com
13026
13026
  * @Date: 2023-11-15 09:50:22
13027
13027
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
13028
- * @LastEditTime: 2024-01-25 14:11:50
13028
+ * @LastEditTime: 2024-01-26 17:47:16
13029
13029
  */
13030
13030
 
13031
+ /**
13032
+ * 子表组件字段值中每行数据补上字段值为空的的字段值,把值统一设置为空字符串,是为了解决amis amis 3.6/6.0 input-table组件bug:行中字段值为空时会显示为父作用域中的同名变量值,见:https://github.com/baidu/amis/issues/9520
13033
+ * amis #9520修正后此函数及相关代码可以移除
13034
+ * @param {*} value 子表组件字段值,数组
13035
+ * @param {*} fields 子表组件fields属性,数组
13036
+ * @returns 转换后的子表组件字段值
13037
+ */
13038
+ function getTableValueWithEmptyValue(value, fields) {
13039
+ return (value || []).map((itemValue) => {
13040
+ //这里不clone的话,会造成在pipeIn函数执行该函数后像pipeOut一样最终输出到表单项中,即库里字段值会被改了
13041
+ const newItemValue = _$1.clone(itemValue);
13042
+ (fields || []).forEach((itemField) => {
13043
+ if(itemField.name && (newItemValue[itemField.name] === undefined || newItemValue[itemField.name] === null)){
13044
+ // 这里newItemValue中不存在 itemField.name 属性,或者值为null时都会有“显示为父作用域中的同名变量值”的问题,所以null和undefined都要重置为空字符串
13045
+ // 实测数字、下拉框、多选lookup等字段类型重置为空字符串都不会有问题,而且实测amis from组件的清空表单字段值功能就是把表单中的各种字段类型设置为空字符串,所以看起来也符合amis规范
13046
+ newItemValue[itemField.name] = "";
13047
+ }
13048
+ if (newItemValue.children) {
13049
+ newItemValue.children = getTableValueWithEmptyValue(newItemValue.children, fields);
13050
+ }
13051
+ });
13052
+ return newItemValue;
13053
+ });
13054
+ }
13055
+
13056
+ /**
13057
+ * 把子表组件字段值中每行数据中经过上面getTableValueWithEmptyValue函数空字段值移除
13058
+ * amis #9520修正后此函数及相关代码可以移除
13059
+ * @param {*} value 子表组件字段值,数组
13060
+ * @param {*} fields 子表组件fields属性,数组
13061
+ * @returns 转换后的子表组件字段值
13062
+ */
13063
+ function getTableValueWithoutEmptyValue(value, fields) {
13064
+ return (value || []).map((itemValue) => {
13065
+ const newItemValue = _$1.clone(itemValue);
13066
+ (fields || []).forEach((itemField) => {
13067
+ if(itemField.name && (newItemValue[itemField.name] === "" || newItemValue[itemField.name] === undefined || newItemValue[itemField.name] === null)){
13068
+ // 这里额外把null和undefined值也删除掉纯粹是没必要输出保存它们
13069
+ delete newItemValue[itemField.name];
13070
+ }
13071
+ if (newItemValue.children) {
13072
+ newItemValue.children = getTableValueWithoutEmptyValue(newItemValue.children, fields);
13073
+ }
13074
+ });
13075
+ return newItemValue;
13076
+ });
13077
+ }
13078
+
13031
13079
  function getTablePrimaryKey(props) {
13032
13080
  return props.primaryKey || "_id";
13033
13081
  }
@@ -13106,6 +13154,7 @@ function getTableValueWithoutFieldPrefix(value, fieldPrefix) {
13106
13154
  * 子表组件字段值中每行数据的键值key补上指定前缀
13107
13155
  * @param {*} value 子表组件字段值,数组
13108
13156
  * @param {*} fieldPrefix 字段前缀
13157
+ * @param {*} primaryKey 主键字段名,主键不参与被键值key规则,需要排除,审批王amis表单也是这个规则
13109
13158
  * @returns 转换后的子表组件字段值
13110
13159
  */
13111
13160
  function getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey) {
@@ -13177,20 +13226,16 @@ function getInputTableCell(field, showAsInlineEditMode) {
13177
13226
  }
13178
13227
  }
13179
13228
  else {
13180
- // 这里加一层service是因为amis 3.6/6.0中有bug,不加的话,这里会显示为父作用域中中的同名变量值,见:https://github.com/baidu/amis/issues/9520
13181
13229
  return {
13182
- "type": "service",
13230
+ "type": "steedos-field",
13231
+ "config": Object.assign({}, field, {
13232
+ label: false
13233
+ }),
13234
+ inInputTable: true,
13235
+ "static": true,
13236
+ "readonly": true,
13183
13237
  label: field.label,
13184
- name: field.name,
13185
- "body":[{
13186
- "type": "steedos-field",
13187
- "config": Object.assign({}, field, {
13188
- label: false
13189
- }),
13190
- inInputTable: true,
13191
- "static": true,
13192
- "readonly": true
13193
- }]
13238
+ name: field.name
13194
13239
  }
13195
13240
  }
13196
13241
  }
@@ -13377,9 +13422,14 @@ function getFormPagination(props, mode) {
13377
13422
  "onEvent": {
13378
13423
  "click": {
13379
13424
  "actions": [
13425
+ {
13426
+ "actionType": "validate",
13427
+ "componentId": formId
13428
+ },
13380
13429
  {
13381
13430
  "actionType": "custom",
13382
- "script": onPageChangeScript
13431
+ "script": onPageChangeScript,
13432
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13383
13433
  }
13384
13434
  ]
13385
13435
  }
@@ -13404,9 +13454,14 @@ function getFormPagination(props, mode) {
13404
13454
  "onEvent": {
13405
13455
  "click": {
13406
13456
  "actions": [
13457
+ {
13458
+ "actionType": "validate",
13459
+ "componentId": formId
13460
+ },
13407
13461
  {
13408
13462
  "actionType": "custom",
13409
- "script": onPageChangeScript
13463
+ "script": onPageChangeScript,
13464
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13410
13465
  }
13411
13466
  ]
13412
13467
  }
@@ -13898,9 +13953,14 @@ async function getButtonActions(props, mode) {
13898
13953
  "onEvent": {
13899
13954
  "click": {
13900
13955
  "actions": [
13956
+ {
13957
+ "actionType": "validate",
13958
+ "componentId": formId
13959
+ },
13901
13960
  {
13902
13961
  "actionType": "custom",
13903
- "script": onSaveAndNewItemScript
13962
+ "script": onSaveAndNewItemScript,
13963
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13904
13964
  }
13905
13965
  ]
13906
13966
  }
@@ -13913,9 +13973,14 @@ async function getButtonActions(props, mode) {
13913
13973
  "onEvent": {
13914
13974
  "click": {
13915
13975
  "actions": [
13976
+ {
13977
+ "actionType": "validate",
13978
+ "componentId": formId
13979
+ },
13916
13980
  {
13917
13981
  "actionType": "custom",
13918
- "script": onSaveAndCopyItemScript
13982
+ "script": onSaveAndCopyItemScript,
13983
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13919
13984
  }
13920
13985
  ]
13921
13986
  }
@@ -14181,18 +14246,51 @@ async function getButtonView(props) {
14181
14246
 
14182
14247
  async function getButtonDelete(props) {
14183
14248
  return {
14184
- "type": "button",
14185
- "label": "",
14186
- "icon": "fa fa-trash-alt",//不可以用fa-trash-o,因为设计字段布局界面中弹出的设置分组列表中显示不了这个图标
14249
+ "type": "dropdown-button",
14187
14250
  "level": "link",
14188
- "onEvent": {
14189
- "click": {
14190
- "actions": await getButtonActions(props, "delete")
14251
+ "icon": "fa fa-trash-alt",
14252
+ "size": "xs",
14253
+ "hideCaret": true,
14254
+ "closeOnClick": true,
14255
+ "body": [
14256
+ {
14257
+ "type": "wrapper",
14258
+ "size": "md",
14259
+ "className": "w-80",
14260
+ "body": [
14261
+ {
14262
+ "tpl": "确定要删除吗?",
14263
+ "type": "tpl"
14264
+ },
14265
+ {
14266
+ "type": "flex",
14267
+ "justify": "flex-end",
14268
+ "className": "mt-3",
14269
+ "items": [
14270
+ {
14271
+ "type": "button",
14272
+ "label": "取消",
14273
+ "className": "mr-2"
14274
+ },
14275
+ {
14276
+ "type": "button",
14277
+ "label": "删除",
14278
+ "level": "danger",
14279
+ "onEvent": {
14280
+ "click": {
14281
+ "actions": await getButtonActions(props, "delete")
14282
+ }
14283
+ }
14284
+ }
14285
+ ]
14286
+ }
14287
+ ]
14191
14288
  }
14192
- }
14193
- };
14289
+ ]
14290
+ }
14194
14291
  }
14195
14292
 
14293
+
14196
14294
  const getAmisInputTableSchema = async (props) => {
14197
14295
  if (!props.id) {
14198
14296
  props.id = "steedos_input_table_" + props.name + "_" + Math.random().toString(36).substr(2, 9);
@@ -14265,6 +14363,7 @@ const getAmisInputTableSchema = async (props) => {
14265
14363
  if (fieldPrefix) {
14266
14364
  value = getTableValueWithoutFieldPrefix(value, fieldPrefix);
14267
14365
  }
14366
+ value = getTableValueWithEmptyValue(value, fields);
14268
14367
  if (primaryKey) {
14269
14368
  // 这里临时给每行数据补上primaryKey字段值,如果库里不需要保存这里补上的字段值,pipeOut中会识别autoGeneratePrimaryKeyValue属性选择最终移除这里补上的字段值
14270
14369
  // 这里始终自动生成primaryKey字段值,而不是只在pipeOut输出整个子表字段值时才生成,是因为要支持当数据库里保存的子表字段行数据没有primaryKey字段值时的行嵌套模式(即节点的children属性)功能
@@ -14286,6 +14385,7 @@ const getAmisInputTableSchema = async (props) => {
14286
14385
  if (fieldPrefix) {
14287
14386
  value = getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey);
14288
14387
  }
14388
+ value = getTableValueWithoutEmptyValue(value, fields);
14289
14389
  if (props.autoGeneratePrimaryKeyValue === true) {
14290
14390
  // 如果需要把自动生成的primaryKey值输出保存的库中,则补全所有行中的primaryKey值
14291
14391
  // 这里如果不全部补全的话,初始从库里返回的字段值中拿到的行没primaryKey值的话就不会自动补上
@@ -14358,6 +14458,17 @@ const getAmisInputTableSchema = async (props) => {
14358
14458
  "body": headerToolbar
14359
14459
  });
14360
14460
  }
14461
+ let className = "steedos-input-table";
14462
+
14463
+ if (typeof props.className == "object") {
14464
+ className = {
14465
+ [className]: "true",
14466
+ ...props.className
14467
+ };
14468
+ } else if (typeof props.className == "string") {
14469
+ className = `${className} ${props.className} `;
14470
+ }
14471
+
14361
14472
  let schema = {
14362
14473
  "type": "control",
14363
14474
  "body": {
@@ -14371,7 +14482,7 @@ const getAmisInputTableSchema = async (props) => {
14371
14482
  "labelAlign": props.labelAlign,
14372
14483
  //控制control的mode属性,https://aisuda.bce.baidu.com/amis/zh-CN/components/form/formitem#表单项展示
14373
14484
  "mode": props.mode || null,
14374
- "className": props.className
14485
+ className
14375
14486
  };
14376
14487
  // console.log("===schema===", schema);
14377
14488
  return schema;