@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.esm.js CHANGED
@@ -12226,7 +12226,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
12226
12226
  convertData = {
12227
12227
  type: getAmisStaticFieldType('datetime', readonly),
12228
12228
  inputFormat: 'YYYY-MM-DD HH:mm',
12229
- format: 'YYYY-MM-DDTHH:mm:ss.SSSZ',
12229
+ format: 'YYYY-MM-DDTHH:mm:00.000Z',
12230
12230
  tpl: readonly ? getDateTimeTpl(field) : null,
12231
12231
  utc: true,
12232
12232
  };
@@ -12998,9 +12998,57 @@ function uuidv4() {
12998
12998
  * @Author: 殷亮辉 yinlianghui@hotoa.com
12999
12999
  * @Date: 2023-11-15 09:50:22
13000
13000
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
13001
- * @LastEditTime: 2024-01-25 14:11:50
13001
+ * @LastEditTime: 2024-01-26 17:47:16
13002
13002
  */
13003
13003
 
13004
+ /**
13005
+ * 子表组件字段值中每行数据补上字段值为空的的字段值,把值统一设置为空字符串,是为了解决amis amis 3.6/6.0 input-table组件bug:行中字段值为空时会显示为父作用域中的同名变量值,见:https://github.com/baidu/amis/issues/9520
13006
+ * amis #9520修正后此函数及相关代码可以移除
13007
+ * @param {*} value 子表组件字段值,数组
13008
+ * @param {*} fields 子表组件fields属性,数组
13009
+ * @returns 转换后的子表组件字段值
13010
+ */
13011
+ function getTableValueWithEmptyValue(value, fields) {
13012
+ return (value || []).map((itemValue) => {
13013
+ //这里不clone的话,会造成在pipeIn函数执行该函数后像pipeOut一样最终输出到表单项中,即库里字段值会被改了
13014
+ const newItemValue = clone(itemValue);
13015
+ (fields || []).forEach((itemField) => {
13016
+ if(itemField.name && (newItemValue[itemField.name] === undefined || newItemValue[itemField.name] === null)){
13017
+ // 这里newItemValue中不存在 itemField.name 属性,或者值为null时都会有“显示为父作用域中的同名变量值”的问题,所以null和undefined都要重置为空字符串
13018
+ // 实测数字、下拉框、多选lookup等字段类型重置为空字符串都不会有问题,而且实测amis from组件的清空表单字段值功能就是把表单中的各种字段类型设置为空字符串,所以看起来也符合amis规范
13019
+ newItemValue[itemField.name] = "";
13020
+ }
13021
+ if (newItemValue.children) {
13022
+ newItemValue.children = getTableValueWithEmptyValue(newItemValue.children, fields);
13023
+ }
13024
+ });
13025
+ return newItemValue;
13026
+ });
13027
+ }
13028
+
13029
+ /**
13030
+ * 把子表组件字段值中每行数据中经过上面getTableValueWithEmptyValue函数空字段值移除
13031
+ * amis #9520修正后此函数及相关代码可以移除
13032
+ * @param {*} value 子表组件字段值,数组
13033
+ * @param {*} fields 子表组件fields属性,数组
13034
+ * @returns 转换后的子表组件字段值
13035
+ */
13036
+ function getTableValueWithoutEmptyValue(value, fields) {
13037
+ return (value || []).map((itemValue) => {
13038
+ const newItemValue = clone(itemValue);
13039
+ (fields || []).forEach((itemField) => {
13040
+ if(itemField.name && (newItemValue[itemField.name] === "" || newItemValue[itemField.name] === undefined || newItemValue[itemField.name] === null)){
13041
+ // 这里额外把null和undefined值也删除掉纯粹是没必要输出保存它们
13042
+ delete newItemValue[itemField.name];
13043
+ }
13044
+ if (newItemValue.children) {
13045
+ newItemValue.children = getTableValueWithoutEmptyValue(newItemValue.children, fields);
13046
+ }
13047
+ });
13048
+ return newItemValue;
13049
+ });
13050
+ }
13051
+
13004
13052
  function getTablePrimaryKey(props) {
13005
13053
  return props.primaryKey || "_id";
13006
13054
  }
@@ -13079,6 +13127,7 @@ function getTableValueWithoutFieldPrefix(value, fieldPrefix) {
13079
13127
  * 子表组件字段值中每行数据的键值key补上指定前缀
13080
13128
  * @param {*} value 子表组件字段值,数组
13081
13129
  * @param {*} fieldPrefix 字段前缀
13130
+ * @param {*} primaryKey 主键字段名,主键不参与被键值key规则,需要排除,审批王amis表单也是这个规则
13082
13131
  * @returns 转换后的子表组件字段值
13083
13132
  */
13084
13133
  function getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey) {
@@ -13150,20 +13199,16 @@ function getInputTableCell(field, showAsInlineEditMode) {
13150
13199
  }
13151
13200
  }
13152
13201
  else {
13153
- // 这里加一层service是因为amis 3.6/6.0中有bug,不加的话,这里会显示为父作用域中中的同名变量值,见:https://github.com/baidu/amis/issues/9520
13154
13202
  return {
13155
- "type": "service",
13203
+ "type": "steedos-field",
13204
+ "config": Object.assign({}, field, {
13205
+ label: false
13206
+ }),
13207
+ inInputTable: true,
13208
+ "static": true,
13209
+ "readonly": true,
13156
13210
  label: field.label,
13157
- name: field.name,
13158
- "body":[{
13159
- "type": "steedos-field",
13160
- "config": Object.assign({}, field, {
13161
- label: false
13162
- }),
13163
- inInputTable: true,
13164
- "static": true,
13165
- "readonly": true
13166
- }]
13211
+ name: field.name
13167
13212
  }
13168
13213
  }
13169
13214
  }
@@ -13350,9 +13395,14 @@ function getFormPagination(props, mode) {
13350
13395
  "onEvent": {
13351
13396
  "click": {
13352
13397
  "actions": [
13398
+ {
13399
+ "actionType": "validate",
13400
+ "componentId": formId
13401
+ },
13353
13402
  {
13354
13403
  "actionType": "custom",
13355
- "script": onPageChangeScript
13404
+ "script": onPageChangeScript,
13405
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13356
13406
  }
13357
13407
  ]
13358
13408
  }
@@ -13377,9 +13427,14 @@ function getFormPagination(props, mode) {
13377
13427
  "onEvent": {
13378
13428
  "click": {
13379
13429
  "actions": [
13430
+ {
13431
+ "actionType": "validate",
13432
+ "componentId": formId
13433
+ },
13380
13434
  {
13381
13435
  "actionType": "custom",
13382
- "script": onPageChangeScript
13436
+ "script": onPageChangeScript,
13437
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13383
13438
  }
13384
13439
  ]
13385
13440
  }
@@ -13871,9 +13926,14 @@ async function getButtonActions(props, mode) {
13871
13926
  "onEvent": {
13872
13927
  "click": {
13873
13928
  "actions": [
13929
+ {
13930
+ "actionType": "validate",
13931
+ "componentId": formId
13932
+ },
13874
13933
  {
13875
13934
  "actionType": "custom",
13876
- "script": onSaveAndNewItemScript
13935
+ "script": onSaveAndNewItemScript,
13936
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13877
13937
  }
13878
13938
  ]
13879
13939
  }
@@ -13886,9 +13946,14 @@ async function getButtonActions(props, mode) {
13886
13946
  "onEvent": {
13887
13947
  "click": {
13888
13948
  "actions": [
13949
+ {
13950
+ "actionType": "validate",
13951
+ "componentId": formId
13952
+ },
13889
13953
  {
13890
13954
  "actionType": "custom",
13891
- "script": onSaveAndCopyItemScript
13955
+ "script": onSaveAndCopyItemScript,
13956
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13892
13957
  }
13893
13958
  ]
13894
13959
  }
@@ -14154,18 +14219,51 @@ async function getButtonView(props) {
14154
14219
 
14155
14220
  async function getButtonDelete(props) {
14156
14221
  return {
14157
- "type": "button",
14158
- "label": "",
14159
- "icon": "fa fa-trash-alt",//不可以用fa-trash-o,因为设计字段布局界面中弹出的设置分组列表中显示不了这个图标
14222
+ "type": "dropdown-button",
14160
14223
  "level": "link",
14161
- "onEvent": {
14162
- "click": {
14163
- "actions": await getButtonActions(props, "delete")
14224
+ "icon": "fa fa-trash-alt",
14225
+ "size": "xs",
14226
+ "hideCaret": true,
14227
+ "closeOnClick": true,
14228
+ "body": [
14229
+ {
14230
+ "type": "wrapper",
14231
+ "size": "md",
14232
+ "className": "w-80",
14233
+ "body": [
14234
+ {
14235
+ "tpl": "确定要删除吗?",
14236
+ "type": "tpl"
14237
+ },
14238
+ {
14239
+ "type": "flex",
14240
+ "justify": "flex-end",
14241
+ "className": "mt-3",
14242
+ "items": [
14243
+ {
14244
+ "type": "button",
14245
+ "label": "取消",
14246
+ "className": "mr-2"
14247
+ },
14248
+ {
14249
+ "type": "button",
14250
+ "label": "删除",
14251
+ "level": "danger",
14252
+ "onEvent": {
14253
+ "click": {
14254
+ "actions": await getButtonActions(props, "delete")
14255
+ }
14256
+ }
14257
+ }
14258
+ ]
14259
+ }
14260
+ ]
14164
14261
  }
14165
- }
14166
- };
14262
+ ]
14263
+ }
14167
14264
  }
14168
14265
 
14266
+
14169
14267
  const getAmisInputTableSchema = async (props) => {
14170
14268
  if (!props.id) {
14171
14269
  props.id = "steedos_input_table_" + props.name + "_" + Math.random().toString(36).substr(2, 9);
@@ -14238,6 +14336,7 @@ const getAmisInputTableSchema = async (props) => {
14238
14336
  if (fieldPrefix) {
14239
14337
  value = getTableValueWithoutFieldPrefix(value, fieldPrefix);
14240
14338
  }
14339
+ value = getTableValueWithEmptyValue(value, fields);
14241
14340
  if (primaryKey) {
14242
14341
  // 这里临时给每行数据补上primaryKey字段值,如果库里不需要保存这里补上的字段值,pipeOut中会识别autoGeneratePrimaryKeyValue属性选择最终移除这里补上的字段值
14243
14342
  // 这里始终自动生成primaryKey字段值,而不是只在pipeOut输出整个子表字段值时才生成,是因为要支持当数据库里保存的子表字段行数据没有primaryKey字段值时的行嵌套模式(即节点的children属性)功能
@@ -14259,6 +14358,7 @@ const getAmisInputTableSchema = async (props) => {
14259
14358
  if (fieldPrefix) {
14260
14359
  value = getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey);
14261
14360
  }
14361
+ value = getTableValueWithoutEmptyValue(value, fields);
14262
14362
  if (props.autoGeneratePrimaryKeyValue === true) {
14263
14363
  // 如果需要把自动生成的primaryKey值输出保存的库中,则补全所有行中的primaryKey值
14264
14364
  // 这里如果不全部补全的话,初始从库里返回的字段值中拿到的行没primaryKey值的话就不会自动补上
@@ -14331,6 +14431,17 @@ const getAmisInputTableSchema = async (props) => {
14331
14431
  "body": headerToolbar
14332
14432
  });
14333
14433
  }
14434
+ let className = "steedos-input-table";
14435
+
14436
+ if (typeof props.className == "object") {
14437
+ className = {
14438
+ [className]: "true",
14439
+ ...props.className
14440
+ };
14441
+ } else if (typeof props.className == "string") {
14442
+ className = `${className} ${props.className} `;
14443
+ }
14444
+
14334
14445
  let schema = {
14335
14446
  "type": "control",
14336
14447
  "body": {
@@ -14344,7 +14455,7 @@ const getAmisInputTableSchema = async (props) => {
14344
14455
  "labelAlign": props.labelAlign,
14345
14456
  //控制control的mode属性,https://aisuda.bce.baidu.com/amis/zh-CN/components/form/formitem#表单项展示
14346
14457
  "mode": props.mode || null,
14347
- "className": props.className
14458
+ className
14348
14459
  };
14349
14460
  // console.log("===schema===", schema);
14350
14461
  return schema;