@steedos-widgets/amis-lib 3.6.2-beta.13 → 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
@@ -389,8 +389,8 @@ const Router = {
389
389
  /*
390
390
  * @Author: baozhoutao@steedos.com
391
391
  * @Date: 2022-07-20 16:29:22
392
- * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
393
- * @LastEditTime: 2023-12-28 14:59:08
392
+ * @LastEditors: liaodaxue
393
+ * @LastEditTime: 2024-01-25 14:44:17
394
394
  * @Description:
395
395
  */
396
396
 
@@ -462,6 +462,25 @@ function getComparableAmisVersion() {
462
462
  }
463
463
  }
464
464
 
465
+ /**
466
+ * 判断浏览器类型
467
+ * @returns 按需返回浏览器类型;
468
+ */
469
+ function getBowserType() {
470
+ const userAgent = navigator.userAgent;
471
+ if (userAgent.indexOf("Chrome")!== -1 && userAgent.indexOf("Safari") !== -1 && userAgent.indexOf("Edg") === -1) {
472
+ return "Chrome";
473
+ } else if (userAgent.indexOf("Firefox") !== -1) {
474
+ return "Firefox";
475
+ } else if (userAgent.indexOf("Safari") !== -1 && userAgent.indexOf("Chrome") === -1 && userAgent.indexOf("Edge") === -1) {
476
+ return "Safari";
477
+ } else if (userAgent.indexOf("Edg") !== -1) {
478
+ return "Edge";
479
+ } else {
480
+ return "Unknown browser"; // 其他浏览器...(可根据自己需要确定是否新增其他浏览器的判断)
481
+ }
482
+ }
483
+
465
484
  /*
466
485
  * @Author: baozhoutao@steedos.com
467
486
  * @Date: 2022-05-23 09:53:08
@@ -1865,7 +1884,8 @@ async function getQuickEditSchema(field, options){
1865
1884
  "failed": "失败了呢。。"
1866
1885
  }
1867
1886
  }
1868
- }
1887
+ },
1888
+ "expression": "${!recordPermissions.modifyAllRecords}"
1869
1889
  },
1870
1890
  {
1871
1891
  "actionType": "setValue",
@@ -1881,7 +1901,7 @@ async function getQuickEditSchema(field, options){
1881
1901
  "componentId": quickEditId,
1882
1902
  "args": {
1883
1903
  "value":{
1884
- "quickedit_record_permissions": "${event.data}"
1904
+ "quickedit_record_permissions": "${recordPermissions.modifyAllRecords ? {'allowEdit': true} : event.data}"
1885
1905
  }
1886
1906
  }
1887
1907
  }
@@ -1945,7 +1965,7 @@ async function getQuickEditSchema(field, options){
1945
1965
  `
1946
1966
  }
1947
1967
  },
1948
- "expression":"${event.data.value}"
1968
+ "expression":"${event.data.value && !recordPermissions.modifyAllRecords}"
1949
1969
  },
1950
1970
  {
1951
1971
  "actionType": "setValue",
@@ -1976,10 +1996,20 @@ async function getQuickEditSchema(field, options){
1976
1996
  "script": `
1977
1997
  const noPermission = event.data.noPermission;
1978
1998
  const crudComponent = event.context.scoped.getComponentById("${options.crudId}");
1979
- const selectedItems = crudComponent && crudComponent.props.store.selectedItems.concat();
1999
+ let selectedItems = crudComponent && crudComponent.props.store.selectedItems.concat();
1980
2000
  noPermission.forEach(function (item) {
1981
2001
  crudComponent && crudComponent.unSelectItem(_.find(selectedItems,{_id:item}));
2002
+ _.remove(selectedItems, (selected) => selected._id === item);
1982
2003
  })
2004
+ doAction({
2005
+ "componentId": "${quickEditId}",
2006
+ "actionType": "setValue",
2007
+ "args": {
2008
+ "value": {
2009
+ selectedItems
2010
+ }
2011
+ }
2012
+ });
1983
2013
  `
1984
2014
  },
1985
2015
  {
@@ -2070,7 +2100,8 @@ async function getTableColumns(fields, options){
2070
2100
  //增加quickEdit属性,实现快速编辑
2071
2101
  const quickEditSchema = allowEdit ? await getQuickEditSchema(field, options) : allowEdit;
2072
2102
  let className = "";
2073
- if(/Safari/.test(navigator.userAgent)){
2103
+ const bowserType = getBowserType();
2104
+ if(bowserType === "Safari"){
2074
2105
  className += " whitespace-nowrap ";
2075
2106
  }else {
2076
2107
  if(field.wrap != true){
@@ -2079,6 +2110,18 @@ async function getTableColumns(fields, options){
2079
2110
  className += " break-words ";
2080
2111
  }
2081
2112
  }
2113
+
2114
+ if (typeof field.amis?.className == "object") {
2115
+ className = {
2116
+ [className]: "true",
2117
+ ...field.amis.className
2118
+ };
2119
+ } else if (typeof field.amis?.className == "string") {
2120
+ className = `${className} ${field.amis.className} `;
2121
+ }
2122
+ let fieldAmis = _$1.clone(field.amis);
2123
+ delete fieldAmis?.className;
2124
+
2082
2125
  let columnItem;
2083
2126
  if((field.is_name || field.name === options.labelFieldName) && options.objectName === 'cms_files'){
2084
2127
  const previewFileScript = `
@@ -2129,7 +2172,7 @@ async function getTableColumns(fields, options){
2129
2172
  toggled: field.toggled,
2130
2173
  static: true,
2131
2174
  className,
2132
- }, field.amis, {name: field.name});
2175
+ }, fieldAmis, {name: field.name});
2133
2176
  }else if(field.type === 'avatar' || field.type === 'image' || field.type === 'file'){
2134
2177
  columnItem = Object.assign({}, {
2135
2178
  type: "switch",
@@ -2140,7 +2183,7 @@ async function getTableColumns(fields, options){
2140
2183
  static: true,
2141
2184
  className,
2142
2185
  ...getAmisFileReadonlySchema(field)
2143
- }, field.amis, {name: field.name});
2186
+ }, fieldAmis, {name: field.name});
2144
2187
  }
2145
2188
  else if(field.type === 'select'){
2146
2189
  const map = getSelectMap(field.options);
@@ -2155,7 +2198,7 @@ async function getTableColumns(fields, options){
2155
2198
  className,
2156
2199
  inputClassName: "inline",
2157
2200
  static: true,
2158
- }, field.amis, {name: field.name});
2201
+ }, fieldAmis, {name: field.name});
2159
2202
  }
2160
2203
  else {
2161
2204
  const tpl = await getFieldTpl(field, options);
@@ -2182,15 +2225,6 @@ async function getTableColumns(fields, options){
2182
2225
  // }
2183
2226
 
2184
2227
  //field上的amis属性里的clssname需要单独判断类型合并
2185
- if (typeof field.amis?.className == "object") {
2186
- className = {
2187
- [className]: "true",
2188
- ...field.amis.className
2189
- };
2190
- } else if (typeof field.amis?.className == "string") {
2191
- className = `${className} ${field.amis.className} `;
2192
- }
2193
- delete field.amis?.className;
2194
2228
 
2195
2229
  if(!field.hidden && !field.extra){
2196
2230
  columnItem = Object.assign({}, {
@@ -2207,7 +2241,7 @@ async function getTableColumns(fields, options){
2207
2241
  static: true,
2208
2242
  options: field.type === 'html' ? {html: true} : null
2209
2243
  // toggled: true
2210
- }, field.amis, {name: field.name});
2244
+ }, fieldAmis, {name: field.name});
2211
2245
 
2212
2246
  if(field.type === 'color'){
2213
2247
  columnItem.type = 'color';
@@ -8611,14 +8645,7 @@ async function getObjectCRUD(objectSchema, fields, options){
8611
8645
  headers: {
8612
8646
  Authorization: "Bearer ${context.tenantId},${context.authToken}",
8613
8647
  },
8614
- requestAdaptor: quickSaveApiRequestAdaptor,
8615
- adaptor: `
8616
- if(payload.errors){
8617
- payload.status = 2;
8618
- payload.msg = window.t ? window.t(payload.errors[0].message) : payload.errors[0].message;
8619
- }
8620
- return payload;
8621
- `
8648
+ requestAdaptor: quickSaveApiRequestAdaptor
8622
8649
  },
8623
8650
  // 外层data发生变化的时候, 不会重新渲染rowClassNameExpr, 所以先用css标记tr唯一标识
8624
8651
  // 使用表达式给tr添加初始选中状态
@@ -8635,6 +8662,21 @@ async function getObjectCRUD(objectSchema, fields, options){
8635
8662
  crudModeClassName = `steedos-crud-mode-${body.mode}`;
8636
8663
  }
8637
8664
 
8665
+ body.quickSaveApi.adaptor = `
8666
+ if(payload.errors){
8667
+ payload.status = 2;
8668
+ payload.msg = window.t ? window.t(payload.errors[0].message) : payload.errors[0].message;
8669
+ }
8670
+ debugger;
8671
+ var scope = SteedosUI.getRef(context.scopeId);
8672
+ var scopeParent = scope && scope.parent;
8673
+ var crudScoped = scopeParent.getComponentById('${body.id}');
8674
+ setTimeout(()=>{
8675
+ crudScoped && crudScoped.control.updateAutoFillHeight();
8676
+ }, 500);
8677
+ return payload;
8678
+ `;
8679
+
8638
8680
  if(body.columns && options.formFactor != 'SMALL'){
8639
8681
  //将_display放入crud的columns的倒数第二列中(最后一列会影响固定列),可以通过setvalue修改行内数据域的_display,而不影响上层items的_display,用于批量编辑
8640
8682
  body.columns.splice(body.columns.length -1 , 0, {name: '_display',type: 'static', width: 1, placeholder: "",id: objectSchema.name + "_display_${_index}", tpl: "${''}"});
@@ -12184,7 +12226,7 @@ async function convertSFieldToAmisField(field, readonly, ctx) {
12184
12226
  convertData = {
12185
12227
  type: getAmisStaticFieldType('datetime', readonly),
12186
12228
  inputFormat: 'YYYY-MM-DD HH:mm',
12187
- format: 'YYYY-MM-DDTHH:mm:ss.SSSZ',
12229
+ format: 'YYYY-MM-DDTHH:mm:00.000Z',
12188
12230
  tpl: readonly ? getDateTimeTpl(field) : null,
12189
12231
  utc: true,
12190
12232
  };
@@ -12956,8 +12998,56 @@ function uuidv4() {
12956
12998
  * @Author: 殷亮辉 yinlianghui@hotoa.com
12957
12999
  * @Date: 2023-11-15 09:50:22
12958
13000
  * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
12959
- * @LastEditTime: 2024-01-24 14:56:03
13001
+ * @LastEditTime: 2024-01-26 17:47:16
13002
+ */
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 转换后的子表组件字段值
12960
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
+ }
12961
13051
 
12962
13052
  function getTablePrimaryKey(props) {
12963
13053
  return props.primaryKey || "_id";
@@ -13037,6 +13127,7 @@ function getTableValueWithoutFieldPrefix(value, fieldPrefix) {
13037
13127
  * 子表组件字段值中每行数据的键值key补上指定前缀
13038
13128
  * @param {*} value 子表组件字段值,数组
13039
13129
  * @param {*} fieldPrefix 字段前缀
13130
+ * @param {*} primaryKey 主键字段名,主键不参与被键值key规则,需要排除,审批王amis表单也是这个规则
13040
13131
  * @returns 转换后的子表组件字段值
13041
13132
  */
13042
13133
  function getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey) {
@@ -13304,9 +13395,14 @@ function getFormPagination(props, mode) {
13304
13395
  "onEvent": {
13305
13396
  "click": {
13306
13397
  "actions": [
13398
+ {
13399
+ "actionType": "validate",
13400
+ "componentId": formId
13401
+ },
13307
13402
  {
13308
13403
  "actionType": "custom",
13309
- "script": onPageChangeScript
13404
+ "script": onPageChangeScript,
13405
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13310
13406
  }
13311
13407
  ]
13312
13408
  }
@@ -13331,9 +13427,14 @@ function getFormPagination(props, mode) {
13331
13427
  "onEvent": {
13332
13428
  "click": {
13333
13429
  "actions": [
13430
+ {
13431
+ "actionType": "validate",
13432
+ "componentId": formId
13433
+ },
13334
13434
  {
13335
13435
  "actionType": "custom",
13336
- "script": onPageChangeScript
13436
+ "script": onPageChangeScript,
13437
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13337
13438
  }
13338
13439
  ]
13339
13440
  }
@@ -13825,9 +13926,14 @@ async function getButtonActions(props, mode) {
13825
13926
  "onEvent": {
13826
13927
  "click": {
13827
13928
  "actions": [
13929
+ {
13930
+ "actionType": "validate",
13931
+ "componentId": formId
13932
+ },
13828
13933
  {
13829
13934
  "actionType": "custom",
13830
- "script": onSaveAndNewItemScript
13935
+ "script": onSaveAndNewItemScript,
13936
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13831
13937
  }
13832
13938
  ]
13833
13939
  }
@@ -13840,9 +13946,14 @@ async function getButtonActions(props, mode) {
13840
13946
  "onEvent": {
13841
13947
  "click": {
13842
13948
  "actions": [
13949
+ {
13950
+ "actionType": "validate",
13951
+ "componentId": formId
13952
+ },
13843
13953
  {
13844
13954
  "actionType": "custom",
13845
- "script": onSaveAndCopyItemScript
13955
+ "script": onSaveAndCopyItemScript,
13956
+ "expression": "${!!!event.data.validateResult.error}" //触发表单校验结果会存入validateResult,amis 3.2不支持,高版本比如 3.5.3支持
13846
13957
  }
13847
13958
  ]
13848
13959
  }
@@ -14108,18 +14219,51 @@ async function getButtonView(props) {
14108
14219
 
14109
14220
  async function getButtonDelete(props) {
14110
14221
  return {
14111
- "type": "button",
14112
- "label": "",
14113
- "icon": "fa fa-trash-alt",//不可以用fa-trash-o,因为设计字段布局界面中弹出的设置分组列表中显示不了这个图标
14222
+ "type": "dropdown-button",
14114
14223
  "level": "link",
14115
- "onEvent": {
14116
- "click": {
14117
- "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
+ ]
14118
14261
  }
14119
- }
14120
- };
14262
+ ]
14263
+ }
14121
14264
  }
14122
14265
 
14266
+
14123
14267
  const getAmisInputTableSchema = async (props) => {
14124
14268
  if (!props.id) {
14125
14269
  props.id = "steedos_input_table_" + props.name + "_" + Math.random().toString(36).substr(2, 9);
@@ -14192,6 +14336,7 @@ const getAmisInputTableSchema = async (props) => {
14192
14336
  if (fieldPrefix) {
14193
14337
  value = getTableValueWithoutFieldPrefix(value, fieldPrefix);
14194
14338
  }
14339
+ value = getTableValueWithEmptyValue(value, fields);
14195
14340
  if (primaryKey) {
14196
14341
  // 这里临时给每行数据补上primaryKey字段值,如果库里不需要保存这里补上的字段值,pipeOut中会识别autoGeneratePrimaryKeyValue属性选择最终移除这里补上的字段值
14197
14342
  // 这里始终自动生成primaryKey字段值,而不是只在pipeOut输出整个子表字段值时才生成,是因为要支持当数据库里保存的子表字段行数据没有primaryKey字段值时的行嵌套模式(即节点的children属性)功能
@@ -14213,6 +14358,7 @@ const getAmisInputTableSchema = async (props) => {
14213
14358
  if (fieldPrefix) {
14214
14359
  value = getTableValuePrependFieldPrefix(value, fieldPrefix, primaryKey);
14215
14360
  }
14361
+ value = getTableValueWithoutEmptyValue(value, fields);
14216
14362
  if (props.autoGeneratePrimaryKeyValue === true) {
14217
14363
  // 如果需要把自动生成的primaryKey值输出保存的库中,则补全所有行中的primaryKey值
14218
14364
  // 这里如果不全部补全的话,初始从库里返回的字段值中拿到的行没primaryKey值的话就不会自动补上
@@ -14241,6 +14387,10 @@ const getAmisInputTableSchema = async (props) => {
14241
14387
  "width": buttonsForColumnOperations.length > 1 ? "60px" : "20px"
14242
14388
  });
14243
14389
  }
14390
+ // if (showAsInlineEditMode) {
14391
+ // // 因为要支持不同的列上配置inlineEditMode属性,所有不可以把整个子表组件都设置为inlineEditMode
14392
+ // inputTableSchema.needConfirm = false;
14393
+ // }
14244
14394
  if (amis) {
14245
14395
  // 支持配置amis属性重写或添加最终生成的input-table中任何属性。
14246
14396
  delete amis.id;//如果steedos-input-table组件配置了amis.id属性,会造成新建编辑行功能不生效
@@ -14281,6 +14431,17 @@ const getAmisInputTableSchema = async (props) => {
14281
14431
  "body": headerToolbar
14282
14432
  });
14283
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
+
14284
14445
  let schema = {
14285
14446
  "type": "control",
14286
14447
  "body": {
@@ -14294,7 +14455,7 @@ const getAmisInputTableSchema = async (props) => {
14294
14455
  "labelAlign": props.labelAlign,
14295
14456
  //控制control的mode属性,https://aisuda.bce.baidu.com/amis/zh-CN/components/form/formitem#表单项展示
14296
14457
  "mode": props.mode || null,
14297
- "className": props.className
14458
+ className
14298
14459
  };
14299
14460
  // console.log("===schema===", schema);
14300
14461
  return schema;