@steedos/standard-object-database 2.6.8-beta.3 → 2.6.8-beta.30

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.
@@ -209,4 +209,43 @@ Steedos.ObjectFieldManager.getSummaryFiltersOperation = function(field_type) {
209
209
  operations.push(optionals.equal, optionals.unequal);
210
210
  }
211
211
  return operations;
212
- };
212
+ };
213
+
214
+ (function () {
215
+ try {
216
+ var styleCss = $(`<style>
217
+ .defaultValue_field div:first-child{
218
+ flex-grow: 1;
219
+ }
220
+ .defaultValue_field .defaultValue_field_formula{
221
+ // margin: 4px;
222
+ }
223
+ .defaultValue_field .defaultValue_field_formula .antd-Form-label{
224
+ visibility: visible;
225
+ }
226
+
227
+ .defaultValue_field .defaultValue_field_formula_visible{
228
+ flex-grow: 1;
229
+ }
230
+ .defaultValue_field .defaultValue_field_formula_visible .antd-Form-label .antd-TplField{
231
+ visibility: visible;
232
+ }
233
+ .defaultValue_field .defaultValue_field_hidden{
234
+ display: none;
235
+ }
236
+ .defaultValue_field .defaultValue_field_formula_hidden{
237
+ flex-grow: 0;
238
+ }
239
+ .defaultValue_field .defaultValue_field_formula_hidden .antd-Form-label{
240
+ display: none;
241
+ }
242
+ .defaultValue_field .defaultValue_field_formula_hidden .antd-FormulaPicker-input{
243
+ display: none;
244
+ }
245
+
246
+ </style>`);
247
+ $("head").append(styleCss);
248
+ } catch (error) {
249
+ console.log(error);
250
+ }
251
+ })();
@@ -313,7 +313,11 @@ fields:
313
313
  description:
314
314
  readonly:
315
315
  label: Readonly
316
- help:
316
+ help: It is read-only and does not appear on the form when you create or edit records.
317
+ description:
318
+ static:
319
+ label: Readonly and displayed while editing
320
+ help: Displays as read-only, but the field value can be set by default, autofill, or custom scripts when creating and editing records.
317
321
  description:
318
322
  hidden:
319
323
  label: Hidden
@@ -100,7 +100,7 @@ fields:
100
100
  help: 联动字段;例如:A是B依赖的字段,当A字段值发生改变,B字段选项值会随之改变。
101
101
  description:
102
102
  create:
103
- label: 是否显示新建按钮
103
+ label: 弹出选择时允许新建
104
104
  help:
105
105
  description:
106
106
  reference_to_field:
@@ -297,7 +297,11 @@ fields:
297
297
  description:
298
298
  readonly:
299
299
  label: 只读
300
- help:
300
+ help: 只读,且新建和编辑记录时不显示在表单上
301
+ description:
302
+ static:
303
+ label: 只读且编辑时显示
304
+ help: 显示为只读,但是在新建和编辑记录时可以通过默认值,自动填充或自定义脚本设置该字段值
301
305
  description:
302
306
  hidden:
303
307
  label: 隐藏
@@ -1,55 +1,55 @@
1
1
  /*
2
2
  * @Author: baozhoutao@steedos.com
3
3
  * @Date: 2022-08-05 14:17:44
4
- * @LastEditors: sunhaolin@hotoa.com
5
- * @LastEditTime: 2023-05-12 09:33:27
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2024-02-27 15:41:42
6
6
  * @Description:
7
7
  */
8
- const objectql = require("@steedos/objectql");
9
- const objectName = "object_fields";
10
- Meteor.startup(function () {
11
- var _change, _remove, inited = false;
12
- _change = function (document) {
13
- // 重置字段权限延迟10秒,防止对象服务未上线
14
- setTimeout(()=>{
15
- try {
16
- // console.log("====resetAllPermissionSetFieldPermissions====")
17
- objectql.getSteedosSchema().broker.call(`permission_fields.resetAllPermissionSetFieldPermissions`, {
18
- objectName: document.object
19
- }, {
20
- meta: {
21
- user: {
22
- userId: document.owner,
23
- spaceId: document.space,
24
- company_id: document.company_id,
25
- company_ids: document.company_ids,
26
- }
27
- }
28
- });
29
- } catch (error) {
30
- console.error(`resetAllPermissionSetFieldPermissions`, error)
31
- }
32
- }, 1000 * 10)
33
- };
34
- Creator.getCollection(objectName).find({}, {
35
- fields: {
36
- created: 0,
37
- created_by: 0,
38
- modified: 0,
39
- modified_by: 0
40
- }
41
- }).observe({
42
- added: function (newDocument) {
43
- if (inited) {
44
- return _change(newDocument);
45
- }
46
- },
47
- changed: function (newDocument, oldDocument) {
48
- return _change(newDocument);
49
- },
50
- removed: function (oldDocument) {
51
- return _change(oldDocument);
52
- }
53
- });
54
- inited = true;
55
- });
8
+ // const objectql = require("@steedos/objectql");
9
+ // const objectName = "object_fields";
10
+ // Meteor.startup(function () {
11
+ // var _change, _remove, inited = false;
12
+ // _change = function (document) {
13
+ // // 重置字段权限延迟10秒,防止对象服务未上线
14
+ // setTimeout(()=>{
15
+ // try {
16
+ // // console.log("====resetAllPermissionSetFieldPermissions====")
17
+ // objectql.getSteedosSchema().broker.call(`permission_fields.resetAllPermissionSetFieldPermissions`, {
18
+ // objectName: document.object
19
+ // }, {
20
+ // meta: {
21
+ // user: {
22
+ // userId: document.owner,
23
+ // spaceId: document.space,
24
+ // company_id: document.company_id,
25
+ // company_ids: document.company_ids,
26
+ // }
27
+ // }
28
+ // });
29
+ // } catch (error) {
30
+ // console.error(`resetAllPermissionSetFieldPermissions`, error)
31
+ // }
32
+ // }, 1000 * 10)
33
+ // };
34
+ // Creator.getCollection(objectName).find({}, {
35
+ // fields: {
36
+ // created: 0,
37
+ // created_by: 0,
38
+ // modified: 0,
39
+ // modified_by: 0
40
+ // }
41
+ // }).observe({
42
+ // added: function (newDocument) {
43
+ // if (inited) {
44
+ // return _change(newDocument);
45
+ // }
46
+ // },
47
+ // changed: function (newDocument, oldDocument) {
48
+ // return _change(newDocument);
49
+ // },
50
+ // removed: function (oldDocument) {
51
+ // return _change(oldDocument);
52
+ // }
53
+ // });
54
+ // inited = true;
55
+ // });
@@ -1,56 +1,56 @@
1
1
  /*
2
2
  * @Author: baozhoutao@steedos.com
3
3
  * @Date: 2022-08-05 14:17:44
4
- * @LastEditors: sunhaolin@hotoa.com
5
- * @LastEditTime: 2023-05-13 17:09:31
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2024-02-27 15:48:50
6
6
  * @Description:
7
7
  */
8
- const objectql = require("@steedos/objectql");
9
- const objectName = "permission_objects";
10
- Meteor.startup(function () {
11
- var _change, _remove, inited = false;
12
- _change = function (document) {
13
- setTimeout(()=>{
14
- try {
15
- objectql.getSteedosSchema().broker.call(`permission_fields.resetFieldPermissions`, {
16
- permissionObjectId: document._id
17
- }, {
18
- meta: {
19
- user: {
20
- userId: document.owner,
21
- spaceId: document.space,
22
- company_id: document.company_id,
23
- company_ids: document.company_ids,
24
- }
25
- }
26
- });
27
- } catch (error) {
28
- console.error(`resetFieldPermissions`, error)
29
- }
30
- }, 1000 * 10)
31
- };
32
- Creator.getCollection(objectName).find({}, {
33
- fields: {
34
- created: 0,
35
- created_by: 0,
36
- modified: 0,
37
- modified_by: 0
38
- }
39
- }).observe({
40
- added: function (newDocument) {
41
- if (newDocument.copy_from) { // 通过复制简档创建的对象权限,不需要重置字段权限
42
- return;
43
- }
44
- if (inited) {
45
- return _change(newDocument);
46
- }
47
- },
48
- changed: function (newDocument, oldDocument) {
49
- return _change(newDocument);
50
- },
51
- // removed: function (oldDocument) {
52
- // return _change(oldDocument);
53
- // }
54
- });
55
- inited = true;
56
- });
8
+ // const objectql = require("@steedos/objectql");
9
+ // const objectName = "permission_objects";
10
+ // Meteor.startup(function () {
11
+ // var _change, _remove, inited = false;
12
+ // _change = function (document) {
13
+ // setTimeout(()=>{
14
+ // try {
15
+ // objectql.getSteedosSchema().broker.call(`permission_fields.resetFieldPermissions`, {
16
+ // permissionObjectId: document._id
17
+ // }, {
18
+ // meta: {
19
+ // user: {
20
+ // userId: document.owner,
21
+ // spaceId: document.space,
22
+ // company_id: document.company_id,
23
+ // company_ids: document.company_ids,
24
+ // }
25
+ // }
26
+ // });
27
+ // } catch (error) {
28
+ // console.error(`resetFieldPermissions`, error)
29
+ // }
30
+ // }, 1000 * 10)
31
+ // };
32
+ // Creator.getCollection(objectName).find({}, {
33
+ // fields: {
34
+ // created: 0,
35
+ // created_by: 0,
36
+ // modified: 0,
37
+ // modified_by: 0
38
+ // }
39
+ // }).observe({
40
+ // added: function (newDocument) {
41
+ // if (newDocument.copy_from) { // 通过复制简档创建的对象权限,不需要重置字段权限
42
+ // return;
43
+ // }
44
+ // if (inited) {
45
+ // return _change(newDocument);
46
+ // }
47
+ // },
48
+ // changed: function (newDocument, oldDocument) {
49
+ // return _change(newDocument);
50
+ // },
51
+ // // removed: function (oldDocument) {
52
+ // // return _change(oldDocument);
53
+ // // }
54
+ // });
55
+ // inited = true;
56
+ // });
@@ -1,5 +1,8 @@
1
1
  module.exports = {
2
2
  standard_newVisible: function (object_name, record_id, permission, data) {
3
+ if (!record_id) {
4
+ return false;
5
+ }
3
6
  if(!Creator.isSpaceAdmin()){
4
7
  return false
5
8
  }
@@ -199,9 +199,49 @@ fields:
199
199
  amis:
200
200
  disabledOn: "${is_system == true}"
201
201
  defaultValue:
202
- type: text
202
+ type: object
203
+ blackbox: true
203
204
  label: Default Value
204
205
  sort_no: 160
206
+ visible_on: "{{formData.type && ['autonumber','formula','summary','image','file'].indexOf(formData.type) < 0}}"
207
+ amis:
208
+ type: service
209
+ className:
210
+ antd-Form-item: true
211
+ antd-Form-item--normal: true
212
+ m-0: true
213
+ "md:border-b": global.mode === "read"
214
+ defaultValue_field: true
215
+ flex: true
216
+ schemaApi:
217
+ url: "${context.rootUrl}/service/api/object_fields/defaultValue/schema"
218
+ method: post
219
+ data:
220
+ object: ${object}
221
+ name: ${name}
222
+ options: ${options|filter:label:isTrue|filter:value:isTrue}
223
+ type: ${type}
224
+ reference_to: ${reference_to}
225
+ multiple: ${multiple}
226
+ filtersFunction: ${filtersFunction}
227
+ reference_to_field: ${reference_to_field}
228
+ mode: ${global.mode}
229
+ scale: ${scale}
230
+ _id: ${_id}
231
+ trackExpression: "${object},${options|filter:label:isTrue|filter:value:isTrue|pick:label,value|json},${type},${reference_to},${reference_to_field},${multiple},${filtersFunction},${_id},${scale}"
232
+ headers:
233
+ Authorization: "Bearer ${context.tenantId},${context.authToken}"
234
+ # sendOn: "!!this.type"
235
+ onEvent:
236
+ fetchSchemaInited:
237
+ weight: 0
238
+ actions:
239
+ - actionType: "setValue"
240
+ componentId: "service_detail_page"
241
+ args:
242
+ value:
243
+ defaultValue: "${event.data.body[0].value}"
244
+ expression: "global.mode ==='read' && event.data.body[0].value"
205
245
  group:
206
246
  type: text
207
247
  label: Group
@@ -249,7 +289,7 @@ fields:
249
289
  disabledOn: "${is_system == true}"
250
290
  create:
251
291
  type: boolean
252
- label: 是否显示新建按钮
292
+ label: 弹出选择时允许新建
253
293
  defaultValue: true
254
294
  visible_on: "{{['lookup'].indexOf(formData.type) > -1 ? true: false}}"
255
295
  sort_no: 185
@@ -448,7 +488,7 @@ fields:
448
488
  amis:
449
489
  showIndex: true
450
490
  disabledOn: "${is_system == true}"
451
- inlineEditMode: true
491
+ enableDialog: false
452
492
  columns:
453
493
  - label
454
494
  - value
@@ -481,9 +521,10 @@ fields:
481
521
  label: Auto Fill Mapping
482
522
  is_wide: true
483
523
  inlineHelpText: When the data is selected, the field values in the reference object are automatically filled into the current form field according to the following mapping.
484
- visible_on: "{{formData.type === 'lookup' || formData.type === 'master_detail'}}"
524
+ visible_on: "{{(formData.type === 'lookup' || formData.type === 'master_detail') && formData.reference_to && !!!formData.multiple}}"
485
525
  sort_no: 280
486
526
  amis:
527
+ enableDialog: false
487
528
  disabledOn: "${is_system == true}"
488
529
  auto_fill_mapping.$:
489
530
  label: Auto Fill Mapping
@@ -515,11 +556,42 @@ fields:
515
556
  - object
516
557
  filtersFunction: !<tag:yaml.org,2002:js/function> |-
517
558
  function (filters, values) {
518
- if(values && values.object){
519
- return ['object', '=', values.object]
520
- }else{
521
- return ['_id', '=', 'no']
559
+ //按照from字段类型给予不同的过滤限制,具体规则参考https://github.com/steedos/steedos-platform/issues/6496
560
+ var fieldFilters = {
561
+ "text": ["text", "textarea"],
562
+ "textarea": ["text", "textarea"],
563
+ "boolean": ["boolean", "toggle"],
564
+ "toggle": ["boolean", "toggle"],
565
+ "number": ["number", "currency"],
566
+ "currency": ["number", "currency"],
567
+ "lookup": ["lookup", "master_detail"],
568
+ "master_detail": ["lookup", "master_detail"],
569
+ "autonumber": ["autonumber", "text", "textarea"],
570
+ "email": ["email", "text", "textarea"]
571
+ };
572
+ var currentFilter = [];
573
+ var referenceObject = BuilderAmisObject && BuilderAmisObject.AmisLib && BuilderAmisObject.AmisLib.getUISchemaSync(values.reference_to);
574
+ var fromField = referenceObject && referenceObject.fields[values.auto_fill_mapping__from];
575
+
576
+ if (fromField && fromField.data_type) {
577
+ currentFilter.push(['type', 'in', fieldFilters[fromField.data_type] || fromField.data_type.split()]);
578
+ }else if (fromField) {
579
+ currentFilter.push(['type', 'in', fieldFilters[fromField.type] || fromField.type.split()]);
580
+ if (fromField.type == "lookup" || fromField.type == "master_detail") {
581
+ if (fromField.reference_to) {
582
+ currentFilter.push(['reference_to', '=', fromField.reference_to]);
583
+ }
584
+ if (fromField.reference_to_field) {
585
+ currentFilter.push(['reference_to_field', '=', fromField.reference_to_field]);
586
+ }
587
+ }
588
+ }
589
+ if (values && values.object) {
590
+ currentFilter.push(['object', '=', values.object]);
591
+ } else {
592
+ currentFilter.push(['_id', '=', 'no']);
522
593
  }
594
+ return currentFilter;
523
595
  }
524
596
  formula_blank_value:
525
597
  type: select
@@ -779,7 +851,13 @@ fields:
779
851
  readonly:
780
852
  type: boolean
781
853
  label: Readonly
854
+ inlineHelpText: It is read-only and does not appear on the form when you create or edit records.
855
+ group: ui
856
+ static:
857
+ type: boolean
858
+ label: Readonly and displayed while editing
782
859
  group: ui
860
+ inlineHelpText: Displays as read-only, but the field value can be set by default, autofill, or custom scripts when creating and editing records.
783
861
  hidden:
784
862
  type: boolean
785
863
  label: Hidden
@@ -62,11 +62,11 @@ module.exports = {
62
62
  var data = newRecord || { _filters_type_controller: 'conditions' };
63
63
  //数据格式转换
64
64
  if (data) {
65
- data.columns = lodash.map(data.columns, 'field');
66
65
  data.sort = lodash.map(data.sort, (item) => {
67
66
  return `${item.field_name}:${item.order || 'asc'}`
68
67
  });
69
- data.mobile_columns = lodash.map(data.mobile_columns, 'field');
68
+
69
+ data.searchable_fields = lodash.map(data.searchable_fields, 'field');
70
70
 
71
71
  if (data.filters && lodash.isString(data.filters)) {
72
72
  try {
@@ -2,7 +2,7 @@
2
2
  * @Author: baozhoutaon@hotoa.com
3
3
  * @Date: 2022-03-29 20:33:44
4
4
  * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2023-11-19 17:06:18
5
+ * @LastEditTime: 2024-02-23 13:37:49
6
6
  * @Description:
7
7
  */
8
8
  module.exports = {
@@ -23,7 +23,6 @@ module.exports = {
23
23
  query: `mutation{objects__upsert(id: "${obj.name}", doc: ${JSON.stringify(JSON.stringify(obj))}){_id,name}}`
24
24
  }),
25
25
  success: function (data) {
26
- console.log(`data====>`, data)
27
26
  SteedosUI.notification.success({
28
27
  message: '对象已自定义。'
29
28
  });
@@ -42,6 +41,9 @@ module.exports = {
42
41
  Steedos.authRequest(url, options);
43
42
  },
44
43
  customVisible: function (object_name, record_id, permission, data) {
44
+ if(Meteor.settings.public.enable_saas){
45
+ return false;
46
+ }
45
47
  var record = data && data.record;
46
48
  return record && record.is_system && !record.created;
47
49
  }
@@ -177,6 +177,9 @@ module.exports = {
177
177
  if(!record){
178
178
  record = Creator.odata.get("objects", record_id, "is_deleted");
179
179
  }
180
+ if(record.is_system){
181
+ return false;
182
+ }
180
183
  if(record && !record.is_deleted){
181
184
  return Creator.baseObject.actions.standard_delete.visible.apply(this, arguments);
182
185
  }
@@ -339,6 +339,7 @@ let objectTriggers = {
339
339
  object_name: doc.name,
340
340
  shared_to: "space",
341
341
  filter_scope: "space",
342
+ crud_mode: 'table',
342
343
  columns: [{field: 'name'}],
343
344
  "sort" : [
344
345
  {
@@ -355,6 +356,7 @@ let objectTriggers = {
355
356
  object_name: doc.name,
356
357
  shared_to: "space",
357
358
  filter_scope: "space",
359
+ crud_mode: 'table',
358
360
  columns: [{field: 'name'}]
359
361
  });
360
362
 
@@ -39,33 +39,43 @@
39
39
  "body": [
40
40
  {
41
41
  "type": "steedos-input-table",
42
- "inlineEditMode": true,
42
+ "enableDialog": false,
43
43
  "fields": [
44
44
  {
45
45
  "name": "group_name",
46
46
  "label": "名称",
47
47
  "type": "text",
48
+ "amis": {
49
+ "disabledOn": "${is_default || is_hidden}"
50
+ },
48
51
  "id": "u:31952daa443c"
49
52
  },
50
53
  {
51
54
  "name": "visible_on",
52
55
  "label": "显示条件",
53
56
  "type": "text",
57
+ "amis": {
58
+ "disabledOn": "${is_default || is_hidden}"
59
+ },
54
60
  "id": "u:8d7551abcd28",
55
61
  "value": null
56
62
  },
57
63
  {
58
64
  "name": "collapsed",
59
65
  "label": "默认折叠",
66
+ "amis": {
67
+ "disabledOn": "${is_default || is_hidden}"
68
+ },
60
69
  "type": "boolean"
61
70
  }
62
71
  ],
63
72
  "columns": [
64
73
  {
65
- "name": "group_name",
66
- "inlineEditMode": false
74
+ "name": "group_name"
75
+ },
76
+ {
77
+ "name": "visible_on"
67
78
  },
68
- "visible_on",
69
79
  {
70
80
  "name": "collapsed",
71
81
  "width": 50
@@ -76,7 +86,6 @@
76
86
  "editable": true,
77
87
  "removable": true,
78
88
  "draggable": false,
79
- "showIndex": false,
80
89
  "id": "u:776ec89804c0",
81
90
  "label": ""
82
91
  }
@@ -88,7 +97,7 @@
88
97
  "actions": [
89
98
  {
90
99
  "actionType": "custom",
91
- "script": "//整理分组数据\nlet setting_groups = _.cloneDeep(event.data.groups);\nif (!_.find(setting_groups, { is_default: true })) {\n setting_groups.unshift({\n \"id\": \"未分组\",\n \"group_name\": \"未分组\",\n \"visible_on\": \"\",\n \"is_default\": true\n })\n}\nif (!_.find(setting_groups, { is_hidden: true })) {\n setting_groups.push({\n id: \"隐藏\",\n group_name: \"隐藏\",\n visible_on: \"\",\n is_hidden: true\n });\n}\nsetting_groups.forEach(function (group) {\n if (group.is_hidden) {\n group.group_name = \"隐藏\";\n group.visible_on = \"\";\n }\n if (group.is_default) {\n group.group_name = \"未分组\";\n group.visible_on = \"\";\n }\n if (!group.id) {\n group.id = group.group_name;\n }\n if (!group.visible_on) {\n group.visible_on = \"\"\n }\n})\n\n//整理字段与分组关系的数据\nlet fieldForGroup = {};\nlet oldGroup = _.cloneDeep(event.data.fieldForGroup);\nsetting_groups.forEach(function (group) {\n if (_.has(oldGroup, group.id)) {\n fieldForGroup[group.id] = oldGroup[group.id];\n oldGroup = _.omit(oldGroup, group.id);\n } else {\n fieldForGroup[group.id] = [];\n }\n})\nif (oldGroup && !_.isEmpty(oldGroup)) {\n _.forEach(oldGroup, function (value, key) {\n fieldForGroup[\"未分组\"] = _.unionBy(fieldForGroup[\"未分组\"], value);\n });\n}\n\n//未分组 放在所有分组开头,隐藏 放在所有分组最后\nconst defaultGroup = fieldForGroup[\"未分组\"];\nconst hiddenGroup = fieldForGroup[\"隐藏\"];\ndelete fieldForGroup[\"未分组\"];\ndelete fieldForGroup[\"隐藏\"];\nfieldForGroup = _.merge({ \"未分组\": defaultGroup }, fieldForGroup, { \"隐藏\": hiddenGroup });\n\n//根据fieldForGroup调整groups顺序,设置分组与保存时需要groups按照顺序\nconst keys = _.keys(fieldForGroup);\nsetting_groups = _.sortBy(setting_groups, function (group) { return _.findIndex(keys, function (key) { return key == group.group_name }) });\n\ndoAction({\n actionType: 'setValue',\n componentId: 'service_field_design',\n args: {\n value: {\n groups: setting_groups\n }\n }\n});\n\ndoAction({\n actionType: 'setValue',\n componentId: \"form_field_design\",\n args: {\n value: { design_field: fieldForGroup }\n }\n});"
100
+ "script": "///整理分组数据\nconst defaultGroupName = \"未分组\";\nconst hiddenGroupName = \"隐藏\";\nlet setting_groups = _.cloneDeep(event.data.groups);\nif (!_.find(setting_groups, { is_default: true })) {\n setting_groups.unshift({\n \"id\": defaultGroupName,\n \"group_name\": defaultGroupName,\n \"visible_on\": \"\",\n \"is_default\": true\n })\n}\nif (!_.find(setting_groups, { is_hidden: true })) {\n setting_groups.push({\n id: hiddenGroupName,\n group_name: hiddenGroupName,\n visible_on: \"\",\n is_hidden: true\n });\n}\nsetting_groups.forEach(function (group) {\n if (group.is_hidden) {\n group.group_name = hiddenGroupName;\n group.visible_on = \"\";\n }\n if (group.is_default) {\n group.group_name = defaultGroupName;\n group.visible_on = \"\";\n }\n if (!group.id) {\n group.id = group.group_name;\n }\n if (!group.visible_on) {\n group.visible_on = \"\"\n }\n})\n\n//整理字段与分组关系的数据\nlet fieldForGroup = {};\nlet oldGroup = _.cloneDeep(event.data.fieldForGroup);\nsetting_groups.forEach(function (group) {\n if (_.has(oldGroup, group.id)) {\n fieldForGroup[group.id] = oldGroup[group.id];\n oldGroup = _.omit(oldGroup, group.id);\n } else {\n fieldForGroup[group.id] = [];\n }\n})\nif (oldGroup && !_.isEmpty(oldGroup)) {\n _.forEach(oldGroup, function (value, key) {\n fieldForGroup[defaultGroupName] = _.unionBy(fieldForGroup[defaultGroupName], value);\n });\n}\n\n//未分组 放在所有分组开头,隐藏 放在所有分组最后\nconst defaultGroup = fieldForGroup[defaultGroupName];\nconst hiddenGroup = fieldForGroup[hiddenGroupName];\ndelete fieldForGroup[defaultGroupName];\ndelete fieldForGroup[hiddenGroupName];\nfieldForGroup = _.merge({ [defaultGroupName]: defaultGroup }, fieldForGroup, { [hiddenGroupName]: hiddenGroup });\n\n//根据fieldForGroup调整groups顺序,设置分组与保存时需要groups按照顺序\nconst keys = _.keys(fieldForGroup);\nsetting_groups = _.sortBy(setting_groups, function (group) { return _.findIndex(keys, function (key) { return key == group.group_name }) });\n\ndoAction({\n actionType: 'setValue',\n componentId: 'service_field_design',\n args: {\n value: {\n groups: setting_groups\n }\n }\n});\n\ndoAction({\n actionType: 'setValue',\n componentId: \"form_field_design\",\n args: {\n value: { design_field: fieldForGroup }\n }\n});"
92
101
  }
93
102
  ]
94
103
  }
@@ -312,7 +321,7 @@
312
321
  "headers": {
313
322
  "Authorization": "Bearer ${context.tenantId},${context.authToken}"
314
323
  },
315
- "requestAdaptor": "var graphqlOrder = \"\";\n//先修改字段,使系统对象自行自定义\n//根据design_field,修改对象字段的sort_no与groups\nvar index = 1;\n_.forEach(api.data.design_field, function (items, key) {\n let group = key;\n if (key == \"未分组\" || key == \"隐藏\") {\n group = null;\n }\n _.forEach(items, function (item) {\n const field = _.find(api.data.fields, { 'id': item });\n //如果是在隐藏分组里的字段,就给visible_on属性赋予{{false}};如果不在隐藏分组里,就判断来自数据库内的visible_on属性是不是{{false}},是就清除,不是就保持不变\n const visible_on = key == \"隐藏\" ? \"{{false}}\" : (field.attr_visible_on == \"{{false}}\" ? \"{{true}}\" : field.attr_visible_on);\n let docJson = {\n sort_no: index * 10,\n group, visible_on\n }\n if (field.id == field._id && field.is_system) {\n docJson = {\n object: api.data.$self.designObjectName,\n type: field.type,\n _name: field._name,\n label: field.label,\n sort_no: index * 10,\n group,\n visible_on,\n is_system: field.is_system\n }\n }\n if (key != \"隐藏\") {\n docJson.hidden = false;\n }\n let itemOrder = 'upsert' + index + ':object_fields__upsert(id:\"' + item + '\" , doc:' + JSON.stringify(JSON.stringify(docJson)) + '){_id}\\n';\n graphqlOrder += itemOrder;\n index++;\n })\n})\n\n//根据groups,修改对象的字段分组field_groups\nvar field_groups = _.cloneDeep(api.data.groups);\n_.remove(field_groups, { is_default: true });\n_.remove(field_groups, { is_hidden: true });\nfield_groups = field_groups.map(function (group) {\n return _.omit(group, 'id');\n})\nconst keys = _.keys(api.data.design_field);\nfield_groups = _.sortBy(field_groups, function (group) { return _.findIndex(keys, function (key) { return key == group.group_name }) });\nconst groupOrder = 'upsert0:objects__upsert(id:\"' + api.data.$self.designObjectId + '\" , doc:' + JSON.stringify(JSON.stringify({ field_groups, name: api.data.$self.designObjectName })) + ') {_id}';\ngraphqlOrder += groupOrder;\n\n\ngraphqlOrder = 'mutation {' + graphqlOrder + '}';\nreturn {\n ...api,\n data: {\n query: graphqlOrder\n }\n}",
324
+ "requestAdaptor": "var graphqlOrder = \"\";\nvar field_groups = _.cloneDeep(api.data.groups);\n//先修改字段,使系统对象自行自定义\n//根据design_field,修改对象字段的sort_no与groups\nvar index = 1;\nconst defaultGroupName = _.find(field_groups, { 'is_default': true })?.name || \"未分组\";\nconst hiddenGroupName = _.find(field_groups, { 'is_hidden': true })?.name || \"隐藏\";\n_.forEach(api.data.design_field, function (items, key) {\n let group = key;\n if (key == defaultGroupName || key == hiddenGroupName) {\n group = null;\n }\n _.forEach(items, function (item) {\n const field = _.find(api.data.fields, { 'id': item });\n //如果是在隐藏分组里的字段,就给visible_on属性赋予{{false}};如果不在隐藏分组里,就判断来自数据库内的visible_on属性是不是{{false}},是就清除,不是就保持不变\n const visible_on = key == hiddenGroupName ? \"{{false}}\" : (field.attr_visible_on == \"{{false}}\" ? \"{{true}}\" : field.attr_visible_on);\n let docJson = {\n sort_no: index * 10,\n group, visible_on\n }\n if (field.id == field._id && field.is_system) {\n docJson = {\n object: api.data.$self.designObjectName,\n type: field.type,\n _name: field._name,\n label: field.label,\n sort_no: index * 10,\n group,\n visible_on,\n is_system: field.is_system\n }\n }\n if (key != hiddenGroupName) {\n docJson.hidden = false;\n }\n let itemOrder = 'upsert' + index + ':object_fields__upsert(id:\"' + item + '\" , doc:' + JSON.stringify(JSON.stringify(docJson)) + '){_id}\\n';\n graphqlOrder += itemOrder;\n index++;\n })\n})\n\n//根据groups,修改对象的字段分组field_groups\n_.remove(field_groups, { is_default: true });\n_.remove(field_groups, { is_hidden: true });\nfield_groups = field_groups.map(function (group) {\n return _.omit(group, 'id');\n})\nconst keys = _.keys(api.data.design_field);\nfield_groups = _.sortBy(field_groups, function (group) { return _.findIndex(keys, function (key) { return key == group.group_name }) });\nconst groupOrder = 'upsert0:objects__upsert(id:\"' + api.data.$self.designObjectId + '\" , doc:' + JSON.stringify(JSON.stringify({ field_groups, name: api.data.$self.designObjectName })) + ') {_id}';\ngraphqlOrder += groupOrder;\n\n\ngraphqlOrder = 'mutation {' + graphqlOrder + '}';\nreturn {\n ...api,\n data: {\n query: graphqlOrder\n }\n}",
316
325
  "adaptor": "if (payload.errors) {\n payload.status = 2;\n payload.msg = window.t ? window.t(payload.errors[\n 0\n ].message) : payload.errors[\n 0\n ].message;\n}\nreturn payload;",
317
326
  "messages": {},
318
327
  "data": {
@@ -358,7 +367,7 @@
358
367
  },
359
368
  "messages": {},
360
369
  "requestAdaptor": "",
361
- "adaptor": "//筛选出可编辑的字段\r\nvar oldFields = _.filter(payload.data.fields, function (obj) { return obj.recordPermissions.allowEdit; });\r\n//将group为空的字段分为未分组的组中,将系统字段的_id改为对象名.字段名\r\noldFields = _.map(oldFields, function (obj) {\r\n obj.originId = obj._id;\r\n if (obj.hidden || obj.visible_on == \"{{false}}\") {\r\n obj.group = \"隐藏\";\r\n }else if (obj.group === null) {\r\n obj.group = \"未分组\";\r\n }\r\n if (obj.is_system) {\r\n obj._id = api.data.designObjectName + \".\" + obj._name;\r\n }\r\n return obj;\r\n});\r\n\r\n//整合出字段的属性集合\r\nconst fields = oldFields.map((field) => {\r\n return {\r\n \"id\": field._id,//用与steedos-board组件的关系分辨\r\n \"_name\": field._name,\r\n \"label\": field.label,\r\n \"_id\": field.originId,//用于打开steedos-objectform\r\n \"columnSpan\": field.is_wide ? 2 : 1,\r\n \"is_system\": field.is_system,\r\n \"type\": field.type,\r\n \"attr_visible_on\": field.visible_on\r\n }\r\n})\r\n\r\n//从字段的group属性中,整合出字段分组的属性集合\r\nlet field_groups = _.map(_.uniqBy(oldFields, \"group\"), function (obj) {\r\n return {\r\n \"id\": obj.group,\r\n \"group_name\": obj.group,\r\n \"visible_on\": \"\"\r\n };\r\n});\r\n\r\n//合并对象上的field_groups与字段上的group\r\nlet groups = _.unionBy(api.data.field_groups, field_groups, 'id');\r\n\r\n//判断是否第一次调用接口,不是的话(说明是触发了datachange事件),返回fields与fieldUpdateData\r\nif (api.data.dataInitialed) {\r\n const eventData = api.data.eventData;\r\n let fieldUpdateData = \"\";\r\n const fieldForGroup = api.data.fieldForGroup;\r\n let fieldForGroupLength = 0;\r\n _.forIn(fieldForGroup, function (value, key) {\r\n fieldForGroupLength += value.length;\r\n });\r\n if (fieldForGroupLength < fields.length) {\r\n fieldUpdateData = {\r\n type: \"insert\",\r\n id: eventData.result.data.recordId\r\n }\r\n } else if (fieldForGroupLength > fields.length) {\r\n fieldUpdateData = {\r\n type: \"delete\",\r\n id: eventData._id\r\n }\r\n }\r\n return payload = {\r\n data: {\r\n fields,\r\n fieldUpdateData\r\n }\r\n }\r\n}\r\n\r\n//整合字段与分组的关系\r\nconst oldFieldsInGroups = _.groupBy(oldFields, \"group\");\r\nlet fieldForGroup = _.mapValues(_.groupBy(groups, \"id\"), function (group,key) {\r\n if (oldFieldsInGroups[key]) {\r\n return _.map(oldFieldsInGroups[key], function (obj) {\r\n return obj._id;\r\n });\r\n } else {\r\n return [];\r\n }\r\n});\r\n\r\n//未分组 放在所有分组开头,隐藏 放在所有分组最后\r\nconst defaultGroup = fieldForGroup[\"未分组\"];\r\nconst hiddenGroup = fieldForGroup[\"隐藏\"];\r\ndelete fieldForGroup[\"未分组\"];\r\ndelete fieldForGroup[\"隐藏\"];\r\nfieldForGroup = _.merge({ \"未分组\": defaultGroup }, fieldForGroup, { \"隐藏\": hiddenGroup });\r\n\r\n//根据fieldForGroup调整groups顺序,设置分组与保存时需要groups按照顺序\r\nconst keys = _.keys(fieldForGroup);\r\ngroups = _.sortBy(groups, function (group) { return _.findIndex(keys, function (key) { return key == group.group_name }) });\r\n\r\nreturn payload = {\r\n data: {\r\n fields,\r\n groups,\r\n fieldForGroup,\r\n dataInitialed: true\r\n }\r\n};",
370
+ "adaptor": "//筛选出可编辑的字段\nvar oldFields = _.filter(payload.data.fields, function (obj) { return obj.recordPermissions.allowEdit; });\n//将group为空的字段分为未分组的组中,将系统字段的_id改为对象名.字段名\noldFields = _.map(oldFields, function (obj) {\n obj.originId = obj._id;\n if (obj.hidden || obj.visible_on == \"{{false}}\") {\n obj.group = \"隐藏\";\n }else if (obj.group === null) {\n obj.group = \"未分组\";\n }\n if (obj.is_system) {\n obj._id = api.data.designObjectName + \".\" + obj._name;\n }\n return obj;\n});\n\n//整合出字段的属性集合\nconst fields = oldFields.map((field) => {\n return {\n \"id\": field._id,//用与steedos-board组件的关系分辨\n \"_name\": field._name,\n \"label\": field.label,\n \"_id\": field.originId,//用于打开steedos-objectform\n \"columnSpan\": field.is_wide ? 2 : 1,\n \"is_system\": field.is_system,\n \"type\": field.type,\n \"attr_visible_on\": field.visible_on\n }\n})\n\n//从字段的group属性中,整合出字段分组的属性集合\nlet field_groups = _.map(_.uniqBy(oldFields, \"group\"), function (obj) {\n return {\n \"id\": obj.group,\n \"group_name\": obj.group,\n \"visible_on\": \"\"\n };\n});\n\n//合并对象上的field_groups与字段上的group\nlet groups = _.unionBy(api.data.field_groups, field_groups, 'id');\n\n//判断是否第一次调用接口,不是的话(说明是触发了datachange事件),返回fields与fieldUpdateData;目前新增与删除都不支持\nif (api.data.dataInitialed) {\n const eventData = api.data.eventData;\n let fieldUpdateData = \"\";\n const fieldForGroup = api.data.fieldForGroup;\n let fieldForGroupLength = 0;\n _.forIn(fieldForGroup, function (value, key) {\n fieldForGroupLength += value.length;\n });\n if (fieldForGroupLength < fields.length) {\n fieldUpdateData = {\n type: \"insert\",\n id: eventData.result.data.recordId\n }\n } else if (fieldForGroupLength > fields.length) {\n fieldUpdateData = {\n type: \"delete\",\n id: eventData._id\n }\n }\n return payload = {\n data: {\n fields,\n fieldUpdateData,\n \n }\n }\n}\n\n//整合字段与分组的关系\nconst oldFieldsInGroups = _.groupBy(oldFields, \"group\");\nlet fieldForGroup = _.mapValues(_.groupBy(groups, \"id\"), function (group,key) {\n if (oldFieldsInGroups[key]) {\n return _.map(oldFieldsInGroups[key], function (obj) {\n return obj._id;\n });\n } else {\n return [];\n }\n});\n\n//未分组 放在所有分组开头,隐藏 放在所有分组最后\nconst defaultGroupName = _.find(groups, { 'is_default': true })?.name || \"未分组\";\nconst hiddenGroupName = _.find(groups, { 'is_hidden': true })?.name || \"隐藏\";\nconst defaultGroup = fieldForGroup[defaultGroupName];\nconst hiddenGroup = fieldForGroup[hiddenGroupName];\ndelete fieldForGroup[defaultGroupName];\ndelete fieldForGroup[hiddenGroupName];\nfieldForGroup = _.merge({ [defaultGroupName]: defaultGroup }, fieldForGroup, { [hiddenGroupName]: hiddenGroup });\n\n//根据fieldForGroup调整groups顺序,设置分组与保存时需要groups按照顺序\nconst keys = _.keys(fieldForGroup);\ngroups = _.sortBy(groups, function (group) { return _.findIndex(keys, function (key) { return key == group.group_name }) });\n\nreturn payload = {\n data: {\n fields,\n groups,\n fieldForGroup,\n dataInitialed: true\n }\n};",
362
371
  "sendOn": "!!this.designObjectId"
363
372
  },
364
373
  "messages": {},
@@ -367,7 +376,7 @@
367
376
  "actions": [
368
377
  {
369
378
  "actionType": "custom",
370
- "script": "\nconst fieldForGroup = context.props.data.fieldForGroup;\nconst fieldUpdateData = event.data.fieldUpdateData;\nif (fieldUpdateData && fieldUpdateData.type == \"delete\") {\n _.forIn(fieldForGroup, function (group, group_name) {\n _.remove(group, function (field) {\n return field === fieldUpdateData.id;\n })\n });\n} else if (fieldUpdateData && fieldUpdateData.type == \"insert\") {\n fieldForGroup[\"未分组\"].push(fieldUpdateData.id);\n}\n// doAction({\n// actionType: 'setValue',\n// componentId: \"service_field_design\",\n// args: {\n// value: { fieldForGroup }\n// }\n// });\n\ndoAction({\n actionType: 'setValue',\n componentId: \"form_field_design\",\n args: {\n value: { design_field:fieldForGroup }\n }\n});\n\n",
379
+ "script": "//新增或删除时才会触发,目前暂不支持\nconst fieldForGroup = context.props.data.fieldForGroup;\nconst fieldUpdateData = event.data.fieldUpdateData;\nif (fieldUpdateData && fieldUpdateData.type == \"delete\") {\n _.forIn(fieldForGroup, function (group, group_name) {\n _.remove(group, function (field) {\n return field === fieldUpdateData.id;\n })\n });\n} else if (fieldUpdateData && fieldUpdateData.type == \"insert\") {\n fieldForGroup[\"未分组\"].push(fieldUpdateData.id);\n}\n// doAction({\n// actionType: 'setValue',\n// componentId: \"service_field_design\",\n// args: {\n// value: { fieldForGroup }\n// }\n// });\n\ndoAction({\n actionType: 'setValue',\n componentId: \"form_field_design\",\n args: {\n value: { design_field:fieldForGroup }\n }\n});\n\n",
371
380
  "expression": "${event.data.fieldUpdateData}"
372
381
  }
373
382
  ]
@@ -391,7 +400,7 @@
391
400
  },
392
401
  "messages": {},
393
402
  "requestAdaptor": "",
394
- "adaptor": "const field_groups = payload.data.objects[0] && _.map(payload.data.objects[0].field_groups, function (obj) {\n return {\n \"id\": obj.group_name,\n \"group_name\": obj.group_name,\n \"visible_on\": obj.visible_on,\n \"default_folded\": obj.default_folded\n }\n});\nfield_groups.unshift({\n id: \"隐藏\",\n group_name: \"隐藏\",\n visible_on: \"\",\n is_hidden: true\n});\nfield_groups.unshift({\n id: \"未分组\",\n group_name: \"未分组\",\n visible_on: \"\",\n is_default: true\n});\n\n\n\nconst designObjectId = payload.data.objects[0] && payload.data.objects[0]._id;\nreturn payload = {\n data: {\n field_groups,\n designObjectId,\n designObjectLabel: payload.data.objects[0] && payload.data.objects[0].label,\n _master: {\n recordId: designObjectId\n }\n }\n}"
403
+ "adaptor": "const field_groups = payload.data.objects[0] && _.map(payload.data.objects[0].field_groups, function (obj) {\n return {\n \"id\": obj.group_name,\n \"group_name\": obj.group_name,\n \"visible_on\": obj.visible_on,\n \"collapsed\": obj.collapsed\n }\n});\nfield_groups.unshift({\n id: \"隐藏\",\n group_name: \"隐藏\",\n visible_on: \"\",\n is_hidden: true\n});\nfield_groups.unshift({\n id: \"未分组\",\n group_name: \"未分组\",\n visible_on: \"\",\n is_default: true\n});\n\n\n\nconst designObjectId = payload.data.objects[0] && payload.data.objects[0]._id;\nreturn payload = {\n data: {\n field_groups,\n designObjectId,\n designObjectLabel: payload.data.objects[0] && payload.data.objects[0].label,\n _master: {\n recordId: designObjectId\n }\n }\n}"
395
404
  },
396
405
  "messages": {},
397
406
  "onEvent": {
@@ -10,7 +10,23 @@
10
10
  "enableTabs": true,
11
11
  "mode": "edit",
12
12
  "layout": "horizontal",
13
- "apiRequestAdaptor": "api.data.query = api.data.query.replace('object_fields__update', 'object_fields__upsert')",
13
+ "onEvent": {
14
+ "change": {
15
+ "actions": [
16
+ {
17
+ "actionType": "setValue",
18
+ "args": {
19
+ "value": {
20
+ "defaultValue": ""
21
+ }
22
+ },
23
+ "expression": "${!!event.data.defaultValue_formula}"
24
+ }
25
+ ]
26
+ }
27
+ },
28
+ "initApiAdaptor": "const defaultValue_field_value = payload.data.defaultValue; if(defaultValue_field_value && _.isString(defaultValue_field_value) && defaultValue_field_value.indexOf('{')>-1 ){ payload.data.defaultValue_formula = defaultValue_field_value; delete payload.data.defaultValue; } return payload;",
29
+ "apiRequestAdaptor": "if(formData.defaultValue_formula){ formData.defaultValue = formData.defaultValue_formula } __saveData = JSON.stringify(JSON.stringify(formData)); api.data = {query: query.replace('{__saveData}', __saveData)}; api.data.query = api.data.query.replace('object_fields__update', 'object_fields__upsert')",
14
30
  "submitSuccActions": [
15
31
  {
16
32
  "actionType": "custom",
@@ -19,12 +35,120 @@
19
35
  {
20
36
  "actionType": "toast",
21
37
  "args": {
22
- "msgType": "success",
23
- "msg": "操作成功, 请刷新浏览器后查看效果",
24
- "position": "top-right"
38
+ "msgType": "success",
39
+ "msg": "操作成功, 请刷新浏览器后查看效果",
40
+ "position": "top-right"
41
+ }
42
+ }
43
+ ],
44
+ "fieldsExtend": {
45
+ "readonly": {
46
+ "amis": {
47
+ "onEvent": {
48
+ "change": {
49
+ "actions": [
50
+ {
51
+ "actionType": "setValue",
52
+ "componentId": "steedos_object_fields_form",
53
+ "args": {
54
+ "value": {
55
+ "static": false
56
+ }
57
+ },
58
+ "expression": "!!readonly"
59
+ }
60
+ ]
61
+ }
62
+ },
63
+ "id": "u:a32a4c461450"
64
+ }
65
+ },
66
+ "static": {
67
+ "amis": {
68
+ "onEvent": {
69
+ "change": {
70
+ "actions": [
71
+ {
72
+ "actionType": "setValue",
73
+ "componentId": "steedos_object_fields_form",
74
+ "args": {
75
+ "value": {
76
+ "readonly": false
77
+ }
78
+ },
79
+ "expression": "!!static"
80
+ }
81
+ ]
82
+ }
83
+ },
84
+ "id": "u:7affdbb0ef6d"
85
+ }
86
+ },
87
+ "required": {
88
+ "amis": {
89
+ "onEvent": {
90
+ "change": {
91
+ "actions": [
92
+ {
93
+ "actionType": "setValue",
94
+ "args": {
95
+ "value": {
96
+ "hidden": false
97
+ }
98
+ },
99
+ "componentId": "steedos_object_fields_form",
100
+ "expression": "${event.data.value}"
101
+ }
102
+ ]
103
+ }
104
+ },
105
+ "id": "u:adf4200a2170"
106
+ }
107
+ },
108
+ "hidden": {
109
+ "amis": {
110
+ "onEvent": {
111
+ "change": {
112
+ "actions": [
113
+ {
114
+ "actionType": "setValue",
115
+ "args": {
116
+ "value": {
117
+ "required": false
118
+ }
119
+ },
120
+ "componentId": "steedos_object_fields_form",
121
+ "expression": "${event.data.value}"
122
+ }
123
+ ]
124
+ }
125
+ },
126
+ "id": "u:adf4200a2170"
127
+ }
128
+ },
129
+ "type": {
130
+ "amis": {
131
+ "onEvent": {
132
+ "change": {
133
+ "actions": [
134
+ {
135
+ "actionType": "setValue",
136
+ "args": {
137
+ "value": {
138
+ "defaultValue": null
139
+ }
140
+ },
141
+ "componentId": "steedos_object_fields_form"
142
+ }
143
+ ]
144
+ }
145
+ }
25
146
  }
26
147
  }
27
- ]
148
+ },
149
+ "form": {
150
+ "id": "steedos_object_fields_form"
151
+ }
28
152
  }
29
153
  ],
30
154
  "data": {
@@ -2,7 +2,7 @@
2
2
  * @Author: baozhoutao@steedos.com
3
3
  * @Date: 2022-06-02 17:45:15
4
4
  * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2023-04-28 10:35:46
5
+ * @LastEditTime: 2024-02-29 13:28:53
6
6
  * @Description:
7
7
  -->
8
8
  <html>
@@ -101,6 +101,7 @@
101
101
  schema.data.context.tenantId = tenantId;
102
102
  schema.data.context.userId = userId;
103
103
  schema.data.context.authToken = authToken;
104
+ schema.data.context.user = <%- JSON.stringify(userSession) %>;
104
105
 
105
106
  return schema || initialContent
106
107
  }
@@ -56,6 +56,7 @@ router.get('/api/amisButtonDesign', core.requireAuthentication, async function (
56
56
  userId: userSession.userId,
57
57
  authToken: userSession.authToken,
58
58
  id: req.query.id,
59
+ userSession: userSession
59
60
  }
60
61
  const options = {}
61
62
  ejs.renderFile(filename, data, options, function(err, str){
@@ -0,0 +1,248 @@
1
+ /*
2
+ * @Description: 提供action_field_updates(字段更新对象)需要的数据接口
3
+ */
4
+
5
+ const register = require("@steedos/metadata-registrar");
6
+ const steedosI18n = require("@steedos/i18n");
7
+ const _ = require("lodash");
8
+ const clone = require("clone");
9
+
10
+ // 默认值字段代码:services/standard-object-database/main/default/services/object_fields.service.js
11
+
12
+ module.exports = {
13
+ name: "object_fields",
14
+ mixins: [],
15
+ /**
16
+ * Settings
17
+ */
18
+ settings: {
19
+
20
+ },
21
+
22
+ /**
23
+ * Dependencies
24
+ */
25
+ dependencies: [],
26
+
27
+ /**
28
+ * Actions
29
+ */
30
+ actions: {
31
+ getDefaultValueSchema: {
32
+ // 需要传 objectName, targetObject(非必填), field_name 参数进来。
33
+ rest: {
34
+ method: "POST",
35
+ path: "/defaultValue/schema"
36
+ },
37
+ async handler(ctx) {
38
+ const data = await this.getDefaultValueSchema(ctx);
39
+ return { status: 0, msg: "", data: data }
40
+ }
41
+ }
42
+ },
43
+
44
+ /**
45
+ * Events
46
+ */
47
+ events: {
48
+
49
+ },
50
+
51
+ /**
52
+ * Methods
53
+ */
54
+ methods: {
55
+ /* defaultValue 字段使用*/
56
+ getDefaultValueSchema: {
57
+ async handler(ctx) {
58
+ // console.log('ctx==>', ctx);
59
+ const userSession = ctx.meta.user;
60
+ const lng = userSession.language || 'zh-CN';
61
+ const type = ctx.params.type || 'text';
62
+ const objectName = ctx.params.object;
63
+ const fieldName = ctx.params.name;
64
+ const reference_to = ctx.params.reference_to;
65
+ const options = ctx.params.options;
66
+ const multiple = ctx.params.multiple;
67
+ const filtersFunction = ctx.params.filtersFunction;
68
+ const reference_to_field = ctx.params.reference_to_field || '_id';
69
+ const _id = ctx.params._id;
70
+ const mode = ctx.params.mode;
71
+ const scale = ctx.params.scale;
72
+ // const mode = global.mode;
73
+
74
+ const partialType = ['text','textarea','html','code','markdown','boolean','toggle','date','datetime','time','password','url','email','color','location'];
75
+ // const fieldType = partialType.indexOf(type) > -1 ? type : 'text';
76
+
77
+ let targetField = null;
78
+ let NAME_FIELD_KEY = null;
79
+ if (mode === 'read') {
80
+ const objectConfig = await register.getObjectConfig(objectName);
81
+ NAME_FIELD_KEY = objectConfig.NAME_FIELD_KEY || 'name';
82
+ targetField = objectConfig.fields[fieldName];
83
+ }
84
+ // console.log('targetField==>', targetField);
85
+ const value = (targetField && targetField.defaultValue) || '';
86
+ const translatedLabel = lng === 'zh-CN' ? "默认值" : 'DefaultValue';
87
+ let defaultValue_schema = {
88
+ "type": "text",
89
+ "name": "defaultValue",
90
+ "label": translatedLabel,
91
+ "labelClassName": "text-left"
92
+ }
93
+
94
+ if(partialType.indexOf(type) > -1){
95
+ defaultValue_schema.type = type;
96
+ }else if(type === 'select' && options){
97
+ defaultValue_schema.type = type;
98
+ defaultValue_schema.options = options;
99
+ defaultValue_schema.multiple = multiple;
100
+ }else if(['lookup','master_detail'].includes(type) && reference_to){
101
+ defaultValue_schema.type = type;
102
+ defaultValue_schema.reference_to = reference_to;
103
+ defaultValue_schema.multiple = multiple;
104
+ defaultValue_schema.filtersFunction = filtersFunction;
105
+ defaultValue_schema.reference_to_field = reference_to_field;
106
+ } else if(['number','currency','percent'].includes(type)){
107
+ defaultValue_schema.type = type;
108
+ defaultValue_schema.scale = scale;
109
+ }
110
+ let body = [];
111
+ let steedos_field = {
112
+ type:'steedos-field',
113
+ name:'defaultValue',
114
+ clearValueOnHidden: true,
115
+ fieldName: 'defaultValue',
116
+ field: defaultValue_schema,
117
+ value: value,
118
+ readonly: mode === 'read' ? true : false
119
+ };
120
+ if(mode === 'read'){
121
+ const baseFieldConfig = {
122
+ "name": "defaultValue",
123
+ "label": translatedLabel,
124
+ "labelClassName": "text-left",
125
+ "clearValueOnHidden": true,
126
+ "fieldName": "defaultValue"
127
+ }
128
+ if(_.isString(value) && value.indexOf('{')>-1){
129
+ // 只读时值是公式就显示公式
130
+ steedos_field = {
131
+ "type": "control",
132
+ "label": translatedLabel,
133
+ "body": {
134
+ "name": "defaultValue",
135
+ "label": translatedLabel,
136
+ "labelClassName": "text-left",
137
+ "type": "tpl",
138
+ "tpl": value.indexOf('$') > -1 ? "\\"+value : value
139
+ }
140
+ }
141
+ }else if(['number','currency','percent'].includes(type)){
142
+ steedos_field = {
143
+ ...baseFieldConfig,
144
+ "type": "static-tpl",
145
+ "tpl": `<div>${value}</div>`,
146
+ "className": "m-1 md:border-b steedos-static-tpl-readonly",
147
+ "quickEdit": false,
148
+ }
149
+ }else if(['date','datetime','time'].includes(type)){
150
+ let fieldTypeConfig ={};
151
+ if(type==='date'){
152
+ fieldTypeConfig = {
153
+ "type": "input-date",
154
+ "inputFormat": "YYYY-MM-DD",
155
+ "format": "YYYY-MM-DDT00:00:00.000[Z]",
156
+ "className": "m-1 steedos-input-date-edit",
157
+ }
158
+ }else if(type==='datetime'){
159
+ fieldTypeConfig = {
160
+ "type": "input-datetime",
161
+ "inputFormat": "YYYY-MM-DD HH:mm",
162
+ "format": "YYYY-MM-DDTHH:mm:ss.SSSZ",
163
+ "className": "m-1 steedos-input-datetime-edit",
164
+ }
165
+ }else if(type==='time'){
166
+ fieldTypeConfig = {
167
+ "type": "input-time",
168
+ "inputFormat": "HH:mm",
169
+ "format": "1970-01-01THH:mm:00.000[Z]",
170
+ "className": "m-1 steedos-input-time-edit",
171
+ }
172
+ }
173
+ steedos_field = {
174
+ ...baseFieldConfig,
175
+ ...fieldTypeConfig,
176
+ value: value,
177
+ static: true
178
+ }
179
+ }else if(['boolean'].includes(type)){
180
+ steedos_field = {
181
+ ...baseFieldConfig,
182
+ value: value,
183
+ "type": "static",
184
+ "tpl": `${value}`,
185
+ "className": "m-1 md:border-b steedos-static-readonly"
186
+ }
187
+ }else if(['lookup','master_detail'].includes(type)){
188
+ // console.log('t==>', type, reference_to, NAME_FIELD_KEY, targetField)
189
+ if(value && value.length && _.isString(reference_to)){
190
+ const query = {
191
+ fields: [NAME_FIELD_KEY],
192
+ filters: [reference_to_field, '=', value]
193
+ }
194
+ const res = await this.broker.call(
195
+ 'objectql.find',
196
+ {
197
+ objectName: reference_to,
198
+ query
199
+ }
200
+ );
201
+ // console.log('res==>', res, reference_to, NAME_FIELD_KEY, targetField);
202
+ const tpl = _.map(res, NAME_FIELD_KEY).join('、')
203
+ steedos_field = {
204
+ "type": "control",
205
+ "label": translatedLabel,
206
+ "body": {
207
+ "name": "defaultValue",
208
+ "label": translatedLabel,
209
+ "labelClassName": "text-left",
210
+ "type": "tpl",
211
+ "tpl": tpl
212
+ },
213
+ value: value
214
+ }
215
+ }
216
+ }
217
+ body = [steedos_field];
218
+ }else{
219
+ body = [steedos_field];
220
+ body[0].field.amis = {
221
+ // disabledOn: "!!this.defaultValue_formula",
222
+ "clearable": true,
223
+ "className": {
224
+ "defaultValue_field_hidden": "!this.defaultValue && (!this.defaultValue || '').toString() && !!this.defaultValue_formula"
225
+ }
226
+ }
227
+ body.push({
228
+ "name": "defaultValue_formula",
229
+ "label": translatedLabel,
230
+ "evalMode": false,
231
+ "type": "input-formula",
232
+ "placeholder": "公式",
233
+ // "disabledOn": "!!this.defaultValue && !!this.defaultValue.toString()",
234
+ "className": {
235
+ "defaultValue_field_formula": true,
236
+ "defaultValue_field_formula_visible": "!!this.defaultValue_formula",
237
+ "defaultValue_field_formula_hidden": "(!!this.defaultValue && !!this.defaultValue.toString()) || (!this.defaultValue && !this.defaultValue_formula)"
238
+ }
239
+ })
240
+ }
241
+ // console.log('body==>', body);
242
+ return {
243
+ body
244
+ }
245
+ }
246
+ }
247
+ }
248
+ };
@@ -125,14 +125,14 @@ async function checkMasterDetailTypeField(doc, oldReferenceTo) {
125
125
 
126
126
  const mastersCount = currentMasters.length;
127
127
  const detailsCount = currentDetails.length;
128
- if (mastersCount > 1) {
129
- throw new Meteor.Error(doc.name, "您无法创建此类型的字段,因为此对象已有两种主表子表关系。");
130
- }
131
- else if (mastersCount > 0) {
132
- if (detailsCount > 0) {
133
- throw new Meteor.Error(doc.name, "由于此对象上已经存在主表子表关系,同时是另一个主表子表关系的主对象,无法创建此类字段。");
134
- }
135
- }
128
+ if (mastersCount > 5) {
129
+ throw new Meteor.Error(doc.name, "您无法创建此类型的字段,因为此对象已有5种主表子表关系。");
130
+ }
131
+ // else if (mastersCount > 0) { // 当前对象已经有1个主子表字段
132
+ // if (detailsCount > 0) { // 当前对象已经作为了其他对象的主子表字段的关联对象
133
+ // throw new Meteor.Error(doc.name, "由于此对象上已经存在主表子表关系,同时是另一个主表子表关系的主对象,无法创建此类字段。");
134
+ // }
135
+ // }
136
136
 
137
137
  const detailPaths = await obj.getDetailPaths();
138
138
  const masterPaths = await refObj.getMasterPaths();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/standard-object-database",
3
- "version": "2.6.8-beta.3",
3
+ "version": "2.6.8-beta.30",
4
4
  "main": "package.service.js",
5
5
  "private": false,
6
6
  "publishConfig": {
@@ -12,10 +12,10 @@
12
12
  "description": "steedos package",
13
13
  "dependencies": {
14
14
  "@steedos-widgets/amis-lib": "^1.0.22",
15
- "@steedos/metadata-core": "2.6.8-beta.3",
16
- "@steedos/standard-objects": "2.6.8-beta.3"
15
+ "@steedos/metadata-core": "2.6.8-beta.30",
16
+ "@steedos/standard-objects": "2.6.8-beta.30"
17
17
  },
18
18
  "repository": {},
19
19
  "license": "MIT",
20
- "gitHead": "fc0c3488501254ec402e770673de858e8d76df5a"
20
+ "gitHead": "ab990190442cdaa29b8b862517f6273216cd8b3e"
21
21
  }
@@ -1,8 +1,8 @@
1
1
  /*
2
2
  * @Author: sunhaolin@hotoa.com
3
3
  * @Date: 1985-10-26 16:15:00
4
- * @LastEditors: 孙浩林 sunhaolin@steedos.com
5
- * @LastEditTime: 2023-11-30 10:13:13
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2024-02-29 10:24:41
6
6
  * @Description:
7
7
  */
8
8
  "use strict";
@@ -167,6 +167,9 @@ module.exports = {
167
167
  const dbRecord = await object.directFind({filters: ['_id','=',id]});
168
168
  if(dbRecord.length === 0){
169
169
  // const newId = await object._makeNewID();
170
+ const objectConfig = await object.toConfig();
171
+ let field_groups = objectConfig.field_groups || null;
172
+
170
173
  const now = new Date();
171
174
  await object.directInsert(Object.assign({}, data, {
172
175
  // _id: newId,
@@ -182,13 +185,14 @@ module.exports = {
182
185
  company_ids: userSession.company_ids,
183
186
  extend: name,
184
187
  custom: false,
185
- is_system: true
188
+ is_system: true,
189
+ field_groups: field_groups
186
190
  }));
187
191
  // id = newId;
188
192
  }
189
193
 
190
194
  if(data.is_system){
191
- data = _.pick(data, ['label', 'icon', 'enable_files', 'enable_tasks', 'enable_notes', 'enable_events', 'enable_workflow', 'enable_instances', 'enable_inline_edit', 'enable_tree', 'enable_enhanced_lookup', 'description', 'is_deleted'])
195
+ data = _.pick(data, ['label', 'icon', 'enable_files', 'enable_tasks', 'enable_notes', 'enable_events', 'enable_workflow', 'enable_instances', 'enable_inline_edit', 'enable_tree', 'enable_enhanced_lookup', 'description', 'is_deleted', 'field_groups'])
192
196
  }
193
197
 
194
198
  return object.update(id, data, userSession)