@steedos/service-plugin-amis 2.4.0-beta.9 → 2.4.1
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/main/default/client/amis.render.client.js +82 -33
- package/main/default/pages/action_field_updates.page.amis.json +266 -0
- package/main/default/pages/action_field_updates.page.yml +12 -0
- package/main/default/pages/apps_form.page.amis.json +28 -5
- package/main/default/pages/apps_form.page.yml +0 -2
- package/main/default/pages/generate_object_tabs.page.amis.json +3 -2
- package/main/default/pages/listview_form.page.amis.json +57 -7
- package/main/default/pages/object_layouts.page.amis.json +28 -10
- package/main/default/services/amis-design.service.js +57 -5
- package/main/default/services/amis.service.js +16 -26
- package/main/default/services/metadata/objects.service.js +41 -1
- package/main/default/services/utils/page-schema.js +174 -0
- package/package.json +5 -5
- package/public/amis/amis.css +0 -18
- package/public/tailwind/tailwind-steedos.css +138 -114
- package/tailwind.config.js +1 -1
- package/main/default/client/load.assets.client.js +0 -26
- package/main/default/client/style.client.js +0 -24
- package/main/default/client/tailwind.client.js +0 -35
- package/main/default/objects/pages/fields/render_engine.field.yml +0 -11
- package/main/default/objects/pages/pages.object.yml +0 -2
|
@@ -19,23 +19,24 @@
|
|
|
19
19
|
"modalName": "${modalName}"
|
|
20
20
|
},
|
|
21
21
|
"requestAdaptor": "const formData = api.data.$;\nconst objectName = api.data.objectName;\nconst fieldsName = Object.keys(formData);\ndelete formData.created;\ndelete formData.created_by;\ndelete formData.modified;\ndelete formData.modified_by;\ndelete formData._display;\n\n//数据格式转换\nformData.columns = lodash.map(formData.columns, (item) => {\n return { field: item };\n});\n\nformData.sort = lodash.map(formData.sort, (item) => {\n const arr = item.split(':');\n return { field_name: arr[0], order: arr[1]};\n});\n\nformData.mobile_columns = lodash.map(formData.mobile_columns, (item) => {\n return { field: item };\n});\n\nformData.searchable_fields = lodash.map(formData.searchable_fields, (item) => {\n return { field: item };\n});\n\n\nif (formData._filters_type_controller === 'conditions' && formData._filters_conditions) {\n formData.filters = window.amisConvert.conditionsToFilters(formData._filters_conditions);\n // formData.filters = JSON.stringify(window.amisConvert.conditionsToFilters(formData._filters_conditions), null, 4);\n} else {\n formData.filters = formData._filters_function || null;\n}\n\ndelete formData._filters_type_controller;\ndelete formData._filters_conditions;\ndelete formData._filters_function;\n\nlet query = `mutation{record: ${objectName}__insert(doc: {__saveData}){_id}}`;\nif (formData.recordId) {\n query = `mutation{record: ${objectName}__update(id: \"${formData.recordId}\", doc: {__saveData}){_id}}`;\n};\ndelete formData._id;\nlet __saveData = JSON.stringify(JSON.stringify(formData));\n\napi.data = { query: query.replace('{__saveData}', __saveData) };\nreturn api;",
|
|
22
|
+
"adaptor": "if (payload.errors) {\n payload.status = 2;\n payload.msg = window.t ? window.t(payload.errors[0].message) : payload.errors[0].message;\n}\nreturn payload;",
|
|
22
23
|
"responseData": {
|
|
23
24
|
"recordId": "${record._id}"
|
|
24
25
|
},
|
|
25
26
|
"headers": {
|
|
26
27
|
"Authorization": "Bearer ${context.tenantId},${context.authToken}"
|
|
27
|
-
}
|
|
28
|
-
"adaptor": "\nvar object_name = Session.get(\"object_name\");\nif (window.FlowRouter && window.FlowRouter.current().route.pathDef === '/app/:app_id/:object_name/grid/:list_view_id' && object_name != 'object_listviews') {\n var app_id = Session.get(\"app_id\");\n var list_view_id = payload.data.record._id;\n var url = \"/app/\" + app_id + \"/\" + object_name + \"/grid/\" + list_view_id;\n SteedosUI.router.go({ objectName: api.body.objectName, recordId: payload.data.record._id, type: api.body.recordId ? 'edit' : 'new' }, url);\n} else { \n SteedosUI.router.go({objectName: api.body.objectName, recordId: payload.data.record._id, type: api.body.recordId ? 'edit': 'new'});\n}\n\nreturn payload;\n "
|
|
28
|
+
}
|
|
29
29
|
},
|
|
30
30
|
"initApi": {
|
|
31
31
|
"method": "post",
|
|
32
32
|
"url": "${context.rootUrl}/graphql?rf=1653731141728",
|
|
33
33
|
"cache": 100,
|
|
34
|
-
"adaptor": "
|
|
34
|
+
"adaptor": "const recordId = api.body.recordId;\nvar data;\nif (recordId) {\n console.log('recordId==>', recordId)\n data = payload.data.data[0] || { _filters_type_controller: 'conditions' };\n //数据格式转换\n if (data) {\n data.columns = lodash.map(data.columns, 'field');\n data.sort = lodash.map(data.sort, (item) => {\n return `${item.field_name}:${item.order || 'asc'}`\n });\n data.mobile_columns = lodash.map(data.mobile_columns, 'field');\n data.searchable_fields = lodash.map(data.searchable_fields, 'field');\n\n if (data.filters && lodash.isString(data.filters)) {\n try {\n data.filters = JSON.parse(data.filters);\n } catch (e) { }\n }\n\n if (data.filters && lodash.isString(data.filters)) {\n data._filters_type_controller = 'function';\n } else {\n data._filters_type_controller = 'conditions'\n }\n\n if (data._filters_type_controller === 'conditions') {\n data._filters_conditions = window.amisConvert.filtersToConditions(data.filters || []);\n } else {\n data._filters_function = data.filters;\n }\n }\n} else {\n const defaultData = api.body.defaultData;\n let defaultValues = {};\n // TODO:字段默认值后期添加\n if(defaultData && _.isObject(defaultData) && !_.isArray(defaultData)){\n data = Object.assign({}, defaultValues, defaultData)\n }\n}\nfor (key in data) {\n if (data[key] === null) {\n delete data[key];\n }\n}\npayload.data = data;\ndelete payload.extensions;\nreturn payload;",
|
|
35
35
|
"data": {
|
|
36
|
-
"
|
|
36
|
+
"recordId": "${recordId}",
|
|
37
|
+
"defaultData": "${defaultData}",
|
|
38
|
+
"query": "{data:object_listviews(filters:[\"_id\", \"=\", \"${recordId}\"]){_id,label,name,object_name,requestAdaptor,adaptor,filter_scope,shared,show_count,columns,filter_fields,sort,filters,filter_logic,mobile_columns,searchable_fields,sort_no,created,created_by:created_by__expand{_id,name},modified,modified_by:modified_by__expand{_id,name},enable_amis_schema,amis_schema,_display{shared,show_count,created,modified}}}"
|
|
37
39
|
},
|
|
38
|
-
"sendOn": "!!this.recordId",
|
|
39
40
|
"replaceData": false,
|
|
40
41
|
"responseData": {
|
|
41
42
|
"&": "$$"
|
|
@@ -298,7 +299,7 @@
|
|
|
298
299
|
"label": "js脚本",
|
|
299
300
|
"name": "_filters_function",
|
|
300
301
|
"id": "u:84714ec9abba",
|
|
301
|
-
"visibleOn": "!!this.object_name && _filters_type_controller == 'function'",
|
|
302
|
+
"visibleOn": "!!this.object_name && !!this._filters_type_controller && _filters_type_controller== 'function'",
|
|
302
303
|
"className": "col-span-2 m-0",
|
|
303
304
|
"labelClassName": "hidden"
|
|
304
305
|
}
|
|
@@ -442,6 +443,39 @@
|
|
|
442
443
|
"title": "searchable"
|
|
443
444
|
}
|
|
444
445
|
},
|
|
446
|
+
{
|
|
447
|
+
"type": "fieldSet",
|
|
448
|
+
"title": "数据接口",
|
|
449
|
+
"description": "获取列表数据的 api",
|
|
450
|
+
"collapsable": true,
|
|
451
|
+
"body": [
|
|
452
|
+
{
|
|
453
|
+
"type": "editor",
|
|
454
|
+
"name": "requestAdaptor",
|
|
455
|
+
"label": "发送适配器",
|
|
456
|
+
"required": false,
|
|
457
|
+
"language": "javascript",
|
|
458
|
+
"description": "函数签名:(api) => api, 数据在 api.data 中,修改后返回 api 对象。",
|
|
459
|
+
"className": "col-span-2 m-1",
|
|
460
|
+
"labelClassName": "text-left"
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
"type": "editor",
|
|
464
|
+
"name": "adaptor",
|
|
465
|
+
"label": "接收适配器",
|
|
466
|
+
"required": false,
|
|
467
|
+
"language": "javascript",
|
|
468
|
+
"description": "函数签名: (payload, response, api) => payload",
|
|
469
|
+
"className": "col-span-2 m-1",
|
|
470
|
+
"labelClassName": "text-left"
|
|
471
|
+
}
|
|
472
|
+
],
|
|
473
|
+
"collapsed": true,
|
|
474
|
+
"visibleOn": "!!this.object_name",
|
|
475
|
+
"en-US": {
|
|
476
|
+
"title": "API"
|
|
477
|
+
}
|
|
478
|
+
},
|
|
445
479
|
{
|
|
446
480
|
"type": "fieldSet",
|
|
447
481
|
"title": "高级",
|
|
@@ -483,7 +517,23 @@
|
|
|
483
517
|
"actionsClassName": "p-sm b-t b-light text-center",
|
|
484
518
|
"className": "steedos-amis-form",
|
|
485
519
|
"language": "javascript",
|
|
486
|
-
"id": "listview_form"
|
|
520
|
+
"id": "listview_form",
|
|
521
|
+
"onEvent": {
|
|
522
|
+
"submitSucc": {
|
|
523
|
+
"weight": 0,
|
|
524
|
+
"actions": [
|
|
525
|
+
{
|
|
526
|
+
"actionType": "broadcast",
|
|
527
|
+
"args": {
|
|
528
|
+
"eventName": "@data.changed.object_listviews"
|
|
529
|
+
},
|
|
530
|
+
"data": {
|
|
531
|
+
"objectName": "object_listviews"
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
]
|
|
535
|
+
}
|
|
536
|
+
}
|
|
487
537
|
}
|
|
488
538
|
],
|
|
489
539
|
"regions": [
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
"recordId": "${recordId}",
|
|
18
18
|
"modalName": "${modalName}"
|
|
19
19
|
},
|
|
20
|
-
"requestAdaptor": "\n \n const formData = api.data.$;\n for (key in formData){\n // image、select等字段清空值后保存的空字符串转换为null。\n if(formData[key] === ''){\n formData[key] = null;\n }\n }\n const objectName = api.data.objectName;\n const fieldsName = Object.keys(formData);\n delete formData.created;\n delete formData.created_by;\n delete formData.modified;\n delete formData.modified_by;\n delete formData._display;\n delete formData.sort_order_options;\n delete formData.buttons_options;\n delete formData.fields_options;\n delete formData.field_groups_options;\n delete formData.related_lists_options;\n delete formData.related_object_fields_options;\n\n let query = `mutation{record: ${objectName}__insert(doc: {__saveData}){_id}}`;\n if(formData.recordId){\n query = `mutation{record: ${objectName}__update(id: \"${formData.recordId}\", doc: {__saveData}){_id}}`;\n };\n delete formData._id;\n let __saveData = JSON.stringify(JSON.stringify(formData));\n \n api.data = {query: query.replace('{__saveData}', __saveData)};\n return api;\n ",
|
|
20
|
+
"requestAdaptor": "\n \n const formData = api.data.$;\n for (key in formData){\n // image、select等字段清空值后保存的空字符串转换为null。\n if(formData[key] === ''){\n formData[key] = null;\n }\n }\n const objectName = api.data.objectName;\n const fieldsName = Object.keys(formData);\n delete formData.created;\n delete formData.created_by;\n delete formData.modified;\n delete formData.modified_by;\n delete formData._display;\n delete formData.sort_order_options;\n delete formData.buttons_options;\n delete formData.fields_options;\n delete formData.field_groups_options;\n delete formData.related_lists_options;\n delete formData.related_object_fields_options;\n delete formData.isLookup;\n\n let query = `mutation{record: ${objectName}__insert(doc: {__saveData}){_id}}`;\n if(formData.recordId){\n query = `mutation{record: ${objectName}__update(id: \"${formData.recordId}\", doc: {__saveData}){_id}}`;\n };\n delete formData._id;\n let __saveData = JSON.stringify(JSON.stringify(formData));\n \n api.data = {query: query.replace('{__saveData}', __saveData)};\n return api;\n ",
|
|
21
|
+
"adaptor": "if (payload.errors) {\n payload.status = 2;\n payload.msg = window.t ? window.t(payload.errors[0].message) : payload.errors[0].message;\n}\nreturn payload;",
|
|
21
22
|
"responseData": {
|
|
22
23
|
"recordId": "${record._id}"
|
|
23
24
|
},
|
|
24
|
-
"adaptor": "var modal = SteedosUI.getRef(api.body.modalName);\nmodal && modal.close();\n SteedosUI.router.go({objectName: api.body.objectName, recordId: payload.data.record._id, type: api.body.recordId ? 'edit': 'new'});\n return payload;\n ",
|
|
25
25
|
"headers": {
|
|
26
26
|
"Authorization": "Bearer ${context.tenantId},${context.authToken}"
|
|
27
27
|
}
|
|
@@ -29,10 +29,11 @@
|
|
|
29
29
|
"initApi": {
|
|
30
30
|
"method": "post",
|
|
31
31
|
"url": "${context.rootUrl}/graphql",
|
|
32
|
-
"sendOn": "!!this.recordId",
|
|
33
32
|
"cache": 100,
|
|
34
|
-
"adaptor": "
|
|
33
|
+
"adaptor": "const recordId = api.body.recordId;\nvar data;\nif (recordId) {\n data = payload.data.data[0];\n if (data) {\n data.object_name = data.object_name ? data.object_name.name : null;\n }\n}else{\n const defaultData = api.body.defaultData;\n let defaultValues = {};\n // TODO:字段默认值后期添加\n if (defaultData && _.isObject(defaultData) && !_.isArray(defaultData)) {\n data = Object.assign({}, defaultValues, defaultData)\n }\n}\n\n//初始化接口返回的字段移除字段值为null的字段\nfor (key in data){\n if(data[key] === null){\n delete data[key];\n }\n}\n\npayload.data = data;\ndelete payload.extensions;\nreturn payload;\n",
|
|
35
34
|
"data": {
|
|
35
|
+
"recordId": "${recordId}",
|
|
36
|
+
"defaultData": "${defaultData}",
|
|
36
37
|
"query": "{data:object_layouts(filters:[\"_id\", \"=\", \"${recordId}\"]){_id,name,label,object_name:object_name__expand{name,label},profiles,buttons,fields,related_lists,field_groups,created,created_by:created_by__expand{_id,name},modified,modified_by:modified_by__expand{_id,name},_display{created,modified}}}"
|
|
37
38
|
},
|
|
38
39
|
"headers": {
|
|
@@ -88,7 +89,7 @@
|
|
|
88
89
|
"id": "u:4e769995f638",
|
|
89
90
|
"source": {
|
|
90
91
|
"method": "get",
|
|
91
|
-
"url": "/service/api/amis-metadata-objects/objects/options",
|
|
92
|
+
"url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/options",
|
|
92
93
|
"headers": {
|
|
93
94
|
"Authorization": "Bearer ${context.tenantId},${context.authToken}"
|
|
94
95
|
}
|
|
@@ -228,7 +229,8 @@
|
|
|
228
229
|
"id": "u:a0027ac6f8c1",
|
|
229
230
|
"closeOnEsc": false,
|
|
230
231
|
"closeOnOutside": false,
|
|
231
|
-
"showCloseButton": true
|
|
232
|
+
"showCloseButton": true,
|
|
233
|
+
"size": "md"
|
|
232
234
|
},
|
|
233
235
|
"label": "设置按钮",
|
|
234
236
|
"id": "u:1ac8afc8a9bb"
|
|
@@ -241,7 +243,7 @@
|
|
|
241
243
|
"id": "u:bef2e378d96f",
|
|
242
244
|
"api": {
|
|
243
245
|
"method": "get",
|
|
244
|
-
"url": "/service/api/amis-metadata-objects/objects/${object_name}/actions/options",
|
|
246
|
+
"url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/actions/options",
|
|
245
247
|
"adaptor": "let data = payload.data;\ndata.buttons_options = data.options;\ndelete data.options\npayload.data = data;\nreturn payload;\n",
|
|
246
248
|
"sendOn": "!!this.object_name",
|
|
247
249
|
"headers": {
|
|
@@ -496,7 +498,7 @@
|
|
|
496
498
|
"affixFooter": false,
|
|
497
499
|
"api": {
|
|
498
500
|
"method": "get",
|
|
499
|
-
"url": "/service/api/amis-metadata-objects/objects/${object_name}/fields/layout_options",
|
|
501
|
+
"url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/fields/layout_options",
|
|
500
502
|
"adaptor": "let data = payload.data;\ndata.fields_options = data.options;\ndata.field_groups_options = lodash.uniq(lodash.compact(lodash.map(data.options, \"group\"))) || [];\ndelete data.options\npayload.data = data;\nreturn payload;\n",
|
|
501
503
|
"sendOn": "!!this.object_name",
|
|
502
504
|
"data": null,
|
|
@@ -536,7 +538,7 @@
|
|
|
536
538
|
"id": "u:dbadaff47153",
|
|
537
539
|
"api": {
|
|
538
540
|
"method": "get",
|
|
539
|
-
"url": "/service/api/amis-metadata-objects/objects/${object_name}/relatedLists/options",
|
|
541
|
+
"url": "${context.rootUrl}/service/api/amis-metadata-objects/objects/${object_name}/relatedLists/options",
|
|
540
542
|
"sendOn": "!!this.object_name",
|
|
541
543
|
"adaptor": "let data = payload.data;\ndata.related_lists_options = data.options;\ndelete data.options\npayload.data = data;\nreturn payload;\n",
|
|
542
544
|
"headers": {
|
|
@@ -700,7 +702,9 @@
|
|
|
700
702
|
"name": "filters",
|
|
701
703
|
"label": "过滤规则",
|
|
702
704
|
"quickEdit": {
|
|
703
|
-
"type": "
|
|
705
|
+
"type": "editor",
|
|
706
|
+
"language": "javascript",
|
|
707
|
+
"description": "函数签名:(filters, data) => 自定义过滤条件, 数据在 data 中,修改后返回 自定义过滤条件",
|
|
704
708
|
"tpl": "<b><%=data.filters%></b>",
|
|
705
709
|
"className": "col-span-2 m-0",
|
|
706
710
|
"labelClassName": "text-left",
|
|
@@ -859,6 +863,20 @@
|
|
|
859
863
|
"script": "// 新建页面布局时初始化related_lists默认值,字段值是CRUD表格控件渲染,新建页面布局时,不会自动填充到form中,需要手动填充\nconst initDefaultRelatedLists = function (input, rowValue, prop_name) {\n const superValues = input.__super.__super || {};\n if (superValues.recordId) {\n // 编辑记录本来就会初始化相关字段值,不需要再初始化\n return;\n }\n return {\n related_lists: superValues.related_lists,\n }\n}\n\nconst eventData = event.data;\ndoAction({\n actionType: 'setValue',\n componentId: \"object-layout-form\",\n args: {\n value: initDefaultRelatedLists(eventData)\n }\n});\n"
|
|
860
864
|
}
|
|
861
865
|
]
|
|
866
|
+
},
|
|
867
|
+
"submitSucc": {
|
|
868
|
+
"weight": 0,
|
|
869
|
+
"actions": [
|
|
870
|
+
{
|
|
871
|
+
"actionType": "broadcast",
|
|
872
|
+
"args": {
|
|
873
|
+
"eventName": "@data.changed.object_layouts"
|
|
874
|
+
},
|
|
875
|
+
"data": {
|
|
876
|
+
"objectName": "object_layouts"
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
]
|
|
862
880
|
}
|
|
863
881
|
},
|
|
864
882
|
"data": {
|
|
@@ -219,8 +219,63 @@ module.exports = {
|
|
|
219
219
|
const allMetadataObjects = await objectql.getSteedosSchema().getAllObject();
|
|
220
220
|
const allObjects = _.pluck(clone(allMetadataObjects), 'metadata');
|
|
221
221
|
|
|
222
|
+
const object = await objectql.getSteedosSchema().getObject(objectName);
|
|
223
|
+
const objectConfig = object.toConfig();
|
|
224
|
+
steedosI18n.translationObject(lng, objectConfig.name, objectConfig);
|
|
225
|
+
|
|
226
|
+
/*
|
|
227
|
+
object.details是一个字符串,形如:testb__c.testa__c
|
|
228
|
+
object.lookup_details是一个对象,格式如下:
|
|
229
|
+
{
|
|
230
|
+
key: "testd__c.testa__c",
|
|
231
|
+
objectName: "testa__c",
|
|
232
|
+
type: "detail",
|
|
233
|
+
}
|
|
234
|
+
*/
|
|
235
|
+
const relatedListObjects = [];
|
|
236
|
+
const relationsInfo = await object.getRelationsInfo();
|
|
237
|
+
const details = relationsInfo && relationsInfo.details;
|
|
238
|
+
// const lookupDetails = relationsInfo && relationsInfo.lookup_details;
|
|
239
|
+
// const relatedLists = _.union(details, lookupDetails);
|
|
240
|
+
|
|
241
|
+
_.each(details, function(related){
|
|
242
|
+
/*related可能是一个lookup_details,它是对象而不是字符串,从中取出key值*/
|
|
243
|
+
// if(typeof related !== "string"){
|
|
244
|
+
// relatedListObjects.push(related.objectName)
|
|
245
|
+
// }
|
|
246
|
+
let foo = related.split('.');
|
|
247
|
+
let rObjectName = foo[0];
|
|
248
|
+
relatedListObjects.push(rObjectName);
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
if(objectConfig.enable_files){
|
|
252
|
+
relatedListObjects.push("cms_files")
|
|
253
|
+
}
|
|
254
|
+
if(objectConfig.enable_tasks){
|
|
255
|
+
relatedListObjects.push("tasks")
|
|
256
|
+
}
|
|
257
|
+
if(objectConfig.enable_notes){
|
|
258
|
+
relatedListObjects.push("notes")
|
|
259
|
+
}
|
|
260
|
+
if(objectConfig.enable_events){
|
|
261
|
+
relatedListObjects.push("events")
|
|
262
|
+
}
|
|
263
|
+
if(objectConfig.enable_instances){
|
|
264
|
+
relatedListObjects.push("instances")
|
|
265
|
+
}
|
|
266
|
+
if(objectConfig.enable_approvals){
|
|
267
|
+
relatedListObjects.push("approvals")
|
|
268
|
+
}
|
|
269
|
+
if(objectConfig.enable_process){
|
|
270
|
+
relatedListObjects.push("process_instance_history")
|
|
271
|
+
}
|
|
272
|
+
if(objectConfig.enable_audit){
|
|
273
|
+
relatedListObjects.push("audit_records")
|
|
274
|
+
}
|
|
275
|
+
|
|
222
276
|
const query = {
|
|
223
|
-
filters: [ ['hidden', '!=', true] , ['name', '<>', ExcludeObjectNames]],
|
|
277
|
+
// filters: [ ['hidden', '!=', true] , ['name', '<>', ExcludeObjectNames]],
|
|
278
|
+
filters: [ ['hidden', '!=', true] ],
|
|
224
279
|
projection: {
|
|
225
280
|
name: 1,
|
|
226
281
|
label: 1,
|
|
@@ -231,10 +286,7 @@ module.exports = {
|
|
|
231
286
|
|
|
232
287
|
let objects = objectql.getSteedosSchema().metadataDriver.find(allObjects, query, spaceId);
|
|
233
288
|
objects = objects.filter(function(object){
|
|
234
|
-
|
|
235
|
-
return (field.type === "lookup" || field.type === "master_detail") && field.reference_to === objectName;
|
|
236
|
-
});
|
|
237
|
-
return !!relatedFieldKey;
|
|
289
|
+
return relatedListObjects.includes(object.name);
|
|
238
290
|
});
|
|
239
291
|
|
|
240
292
|
const dbListViews = await objectql.getObject('object_listviews').directFind({filters: [['shared', '!=', false]]})
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* @Author: baozhoutao@steedos.com
|
|
3
3
|
* @Date: 2022-05-19 11:38:30
|
|
4
|
-
* @LastEditors:
|
|
5
|
-
* @LastEditTime:
|
|
4
|
+
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
|
|
5
|
+
* @LastEditTime: 2023-03-15 17:37:05
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
9
|
-
const objectql = require("@steedos/objectql");
|
|
10
|
-
|
|
11
|
-
const callObjectServiceAction = async function(actionName, userSession, data){
|
|
12
|
-
const broker = objectql.getSteedosSchema().broker;
|
|
13
|
-
return broker.call(actionName, data || {}, { meta: { user: userSession}})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const getUISchema = async function(objectName, userSession){
|
|
17
|
-
return await callObjectServiceAction(`@${objectName}.getRecordView`, userSession);
|
|
18
|
-
}
|
|
8
|
+
const PageSchema = require('./utils/page-schema');
|
|
19
9
|
|
|
20
10
|
module.exports = {
|
|
21
11
|
name: "amis",
|
|
@@ -40,14 +30,14 @@ module.exports = {
|
|
|
40
30
|
async handler(ctx) {
|
|
41
31
|
const userSession = ctx.meta.user;
|
|
42
32
|
const { type, app, objectApiName, recordId, formFactor } = ctx.params;
|
|
43
|
-
return this.getDefaultSchema({type, app, objectApiName, recordId, formFactor, userSession});
|
|
33
|
+
return this.getDefaultSchema({ type, app, objectApiName, recordId, formFactor, userSession });
|
|
44
34
|
}
|
|
45
35
|
},
|
|
46
36
|
getInitSchema: {
|
|
47
37
|
async handler(ctx) {
|
|
48
38
|
const userSession = ctx.meta.user;
|
|
49
39
|
const { type, objectApiName, formFactor } = ctx.params;
|
|
50
|
-
return this.getInitSchema({type, objectApiName, formFactor, userSession}
|
|
40
|
+
return this.getInitSchema({ type, objectApiName, formFactor, userSession });
|
|
51
41
|
}
|
|
52
42
|
}
|
|
53
43
|
},
|
|
@@ -64,7 +54,7 @@ module.exports = {
|
|
|
64
54
|
*/
|
|
65
55
|
methods: {
|
|
66
56
|
getDefaultSchema: {
|
|
67
|
-
handler({type, app, objectApiName, recordId, formFactor, userSession}) {
|
|
57
|
+
handler({ type, app, objectApiName, recordId, formFactor, userSession }) {
|
|
68
58
|
// if(type === 'list'){
|
|
69
59
|
// return {
|
|
70
60
|
// type: 'page',
|
|
@@ -98,23 +88,23 @@ module.exports = {
|
|
|
98
88
|
}
|
|
99
89
|
},
|
|
100
90
|
getInitSchema: {
|
|
101
|
-
async handler({type, objectApiName, formFactor, userSession}) {
|
|
91
|
+
async handler({ type, objectApiName, formFactor, userSession }) {
|
|
102
92
|
|
|
103
|
-
const AmisLib = require('@steedos-widgets/amis-lib');
|
|
104
|
-
AmisLib.setUISchemaFunction(async function(objectName, force){
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
if(objectApiName){
|
|
93
|
+
// const AmisLib = require('@steedos-widgets/amis-lib');
|
|
94
|
+
// AmisLib.setUISchemaFunction(async function (objectName, force) {
|
|
95
|
+
// return await getUISchema(objectName, userSession);
|
|
96
|
+
// });
|
|
97
|
+
if (objectApiName) {
|
|
108
98
|
let schema;
|
|
109
|
-
switch(type){
|
|
99
|
+
switch (type) {
|
|
110
100
|
case "form":
|
|
111
|
-
schema =
|
|
101
|
+
schema = PageSchema.getFormPageInitSchema(objectApiName)
|
|
112
102
|
break;
|
|
113
103
|
case "list":
|
|
114
|
-
schema =
|
|
104
|
+
schema = PageSchema.getListPageInitSchema(objectApiName);
|
|
115
105
|
break;
|
|
116
106
|
case "record":
|
|
117
|
-
schema = await
|
|
107
|
+
schema = await PageSchema.getRecordPageInitSchema(objectApiName, userSession);
|
|
118
108
|
break;
|
|
119
109
|
}
|
|
120
110
|
return schema;
|
|
@@ -89,6 +89,16 @@ module.exports = {
|
|
|
89
89
|
return { status: 0, data: { options } }
|
|
90
90
|
}
|
|
91
91
|
},
|
|
92
|
+
getObjectDetailListsOptions: {
|
|
93
|
+
rest: {
|
|
94
|
+
method: "GET",
|
|
95
|
+
path: "/objects/:objectName/detailLists/options"
|
|
96
|
+
},
|
|
97
|
+
async handler(ctx) {
|
|
98
|
+
const options = await this.getObjectDetailListsOptions(ctx);
|
|
99
|
+
return { status: 0, data: { options } }
|
|
100
|
+
}
|
|
101
|
+
},
|
|
92
102
|
getObjectRelatedListsOptions: {
|
|
93
103
|
rest: {
|
|
94
104
|
method: "GET",
|
|
@@ -302,13 +312,43 @@ module.exports = {
|
|
|
302
312
|
actionsArr.push(action)
|
|
303
313
|
})
|
|
304
314
|
return _.uniq(_.compact(_.map(_.sortBy(actionsArr, "sort"), (action)=>{
|
|
315
|
+
const label = action.label || action.name
|
|
305
316
|
return {
|
|
306
317
|
value: action.name,
|
|
307
|
-
label:
|
|
318
|
+
label: `${label}(${action.name})`
|
|
308
319
|
}
|
|
309
320
|
})));
|
|
310
321
|
}
|
|
311
322
|
},
|
|
323
|
+
getObjectDetailListsOptions: {
|
|
324
|
+
async handler(ctx) {
|
|
325
|
+
const userSession = ctx.meta.user;
|
|
326
|
+
const lng = userSession.language || 'zh-CN';
|
|
327
|
+
const objectName = ctx.params.objectName;
|
|
328
|
+
const object = await objectql.getSteedosSchema().getObject(objectName);
|
|
329
|
+
const objectConfig = object.toConfig();
|
|
330
|
+
steedosI18n.translationObject(lng, objectConfig.name, objectConfig);
|
|
331
|
+
|
|
332
|
+
const options = [];
|
|
333
|
+
/*
|
|
334
|
+
object.details是一个字符串,形如:testb__c.testa__c
|
|
335
|
+
*/
|
|
336
|
+
const relationsInfo = await object.getRelationsInfo();
|
|
337
|
+
const details = relationsInfo && relationsInfo.details;
|
|
338
|
+
|
|
339
|
+
_.each(details, async function(related){
|
|
340
|
+
if (!related) return;
|
|
341
|
+
let foo = related.split('.');
|
|
342
|
+
let rObjectName = foo[0];
|
|
343
|
+
// let rFieldName = foo[1];
|
|
344
|
+
const rObjectConfig = await objectql.getSteedosSchema().getObject(rObjectName).toConfig();
|
|
345
|
+
steedosI18n.translationObject(lng, rObjectConfig.name, rObjectConfig);
|
|
346
|
+
let rObjectLable = rObjectConfig.label;
|
|
347
|
+
options.push({label: rObjectLable, value: rObjectName})
|
|
348
|
+
})
|
|
349
|
+
return options;
|
|
350
|
+
}
|
|
351
|
+
},
|
|
312
352
|
getObjectRelatedListsOptions: {
|
|
313
353
|
async handler(ctx) {
|
|
314
354
|
const userSession = ctx.meta.user;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
|
|
2
|
+
const objectql = require("@steedos/objectql");
|
|
3
|
+
|
|
4
|
+
const callObjectServiceAction = async function (actionName, userSession, data) {
|
|
5
|
+
const broker = objectql.getSteedosSchema().broker;
|
|
6
|
+
return broker.call(actionName, data || {}, { meta: { user: userSession } })
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const getUISchema = async function (objectName, userSession) {
|
|
10
|
+
return await callObjectServiceAction(`@${objectName}.getRecordView`, userSession);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const getScopeId = function (objectApiName, type) {
|
|
14
|
+
return `page_${objectApiName}_${type}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 获取对象表单初始化amisSchema
|
|
18
|
+
const getFormPageInitSchema = function (objectApiName) {
|
|
19
|
+
const amisSchema = {
|
|
20
|
+
"type": "steedos-object-form",
|
|
21
|
+
"label": "对象表单",
|
|
22
|
+
"objectApiName": objectApiName,
|
|
23
|
+
"recordId": "${recordId}",
|
|
24
|
+
"className": "sm:border sm:shadow sm:rounded sm:border-gray-300 bg-white p-4",
|
|
25
|
+
"id": "u:b3d626885b90",
|
|
26
|
+
"mode": "edit",
|
|
27
|
+
"layout": "normal"
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
type: 'page',
|
|
31
|
+
name: getScopeId(objectApiName, "form"),
|
|
32
|
+
bodyClassName: '',
|
|
33
|
+
regions: [
|
|
34
|
+
"body"
|
|
35
|
+
],
|
|
36
|
+
body: [
|
|
37
|
+
amisSchema
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 获取对象列表页面初始化amisSchema
|
|
43
|
+
const getListPageInitSchema = function (objectApiName) {
|
|
44
|
+
return {
|
|
45
|
+
type: 'page',
|
|
46
|
+
name: getScopeId(objectApiName, "list"),
|
|
47
|
+
bodyClassName: '',
|
|
48
|
+
regions: [
|
|
49
|
+
"body"
|
|
50
|
+
],
|
|
51
|
+
body: [{
|
|
52
|
+
"type": "steedos-object-listview",
|
|
53
|
+
"objectApiName": objectApiName,
|
|
54
|
+
"columnsTogglable": false,
|
|
55
|
+
"showHeader": true,
|
|
56
|
+
className: "sm:border bg-white sm:shadow sm:rounded border-slate-300 border-solid"
|
|
57
|
+
}]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 获取对象记录详细页面初始化amisSchema
|
|
62
|
+
const getRecordPageInitSchema = async function (objectApiName, userSession) {
|
|
63
|
+
var body = [];
|
|
64
|
+
const uiSchema = await getUISchema(objectApiName, userSession);
|
|
65
|
+
const hasRelatedLists = !!((uiSchema.related_lists || []).length || (uiSchema.details || []).length)
|
|
66
|
+
const detailed = {
|
|
67
|
+
"title": "详细",
|
|
68
|
+
"className": "px-0 py-4",
|
|
69
|
+
"body": [
|
|
70
|
+
{
|
|
71
|
+
"type": "steedos-object-form",
|
|
72
|
+
"label": "对象表单",
|
|
73
|
+
"objectApiName": "${objectName}",
|
|
74
|
+
"recordId": "${recordId}",
|
|
75
|
+
"appId": "${appId}"
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"id": "u:5d4e7e3f6ecc"
|
|
79
|
+
};
|
|
80
|
+
const related = {
|
|
81
|
+
"title": "相关",
|
|
82
|
+
"className": "px-0 pt-4",
|
|
83
|
+
"body": [
|
|
84
|
+
{
|
|
85
|
+
"type": "steedos-object-related-lists",
|
|
86
|
+
"label": "相关列表",
|
|
87
|
+
"objectApiName": "${objectName}",
|
|
88
|
+
"recordId": "${recordId}",
|
|
89
|
+
"appId": "${appId}"
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
const content = {
|
|
94
|
+
"type": "tabs",
|
|
95
|
+
"className": "sm:mt-3 bg-white sm:shadow sm:rounded sm:border border-slate-300 p-4",
|
|
96
|
+
"tabs": [
|
|
97
|
+
detailed
|
|
98
|
+
]
|
|
99
|
+
};
|
|
100
|
+
if (hasRelatedLists) {
|
|
101
|
+
content.tabs.push(related)
|
|
102
|
+
}
|
|
103
|
+
const amisSchema = {
|
|
104
|
+
"type": "service",
|
|
105
|
+
"body": [
|
|
106
|
+
{
|
|
107
|
+
"type": "steedos-record-detail-header",
|
|
108
|
+
"label": "标题面板",
|
|
109
|
+
"objectApiName": "${objectName}",
|
|
110
|
+
"recordId": "${recordId}",
|
|
111
|
+
onEvent: {
|
|
112
|
+
"recordLoaded": {
|
|
113
|
+
"actions": [
|
|
114
|
+
{
|
|
115
|
+
"actionType": "reload",
|
|
116
|
+
"data": {
|
|
117
|
+
"name": `\${event.data.record.${uiSchema?.NAME_FIELD_KEY || 'name'}}`,
|
|
118
|
+
"record": `\${event.data.record}`,
|
|
119
|
+
"recordLoaded": true,
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"actionType": "reload",
|
|
124
|
+
"componentId": `page_readonly_${objectApiName}_header`, //刷新标题, 详细页面header service 嵌套太多, 导致仅刷新第一层service无法更新recordName
|
|
125
|
+
"data": {
|
|
126
|
+
"name": `\${event.data.record.${uiSchema?.NAME_FIELD_KEY || 'name'}}`,
|
|
127
|
+
"record": `\${event.data.record}`,
|
|
128
|
+
"recordLoaded": true,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
content
|
|
136
|
+
],
|
|
137
|
+
data: {
|
|
138
|
+
"_master.objectName": "${objectName}",
|
|
139
|
+
"_master.recordId": "${recordId}"
|
|
140
|
+
},
|
|
141
|
+
onEvent: {
|
|
142
|
+
"recordLoaded": {
|
|
143
|
+
"actions": [
|
|
144
|
+
{
|
|
145
|
+
"actionType": "reload",
|
|
146
|
+
"data": {
|
|
147
|
+
"name": `\${record.${uiSchema?.NAME_FIELD_KEY || 'name'}}`,
|
|
148
|
+
"_master.record": `\${record}`,
|
|
149
|
+
// 不清楚reload 如何给对象下的某个key复制, 所以此处重复设置_master的objectName、recordId
|
|
150
|
+
"_master.objectName": "${objectName}",
|
|
151
|
+
"_master.recordId": "${recordId}"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
}
|
|
158
|
+
body.push(amisSchema);
|
|
159
|
+
return {
|
|
160
|
+
type: 'page',
|
|
161
|
+
id: `page_${objectApiName}_record_detail`,
|
|
162
|
+
name: getScopeId(objectApiName, "record_detail"),
|
|
163
|
+
bodyClassName: '',
|
|
164
|
+
regions: [
|
|
165
|
+
"body"
|
|
166
|
+
],
|
|
167
|
+
body
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
exports.getFormPageInitSchema = getFormPageInitSchema;
|
|
173
|
+
exports.getListPageInitSchema = getListPageInitSchema;
|
|
174
|
+
exports.getRecordPageInitSchema = getRecordPageInitSchema;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-plugin-amis",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "yarn build:tailwind-base && yarn build:tailwind",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
"gitHead": "ae77c1ed63399245141bf7237cd3966bfc4dc6b1",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"tailwindcss": "3.2.4"
|
|
19
|
+
}
|
|
20
20
|
}
|