@steedos/service-plugin-amis 2.4.0 → 2.4.2
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 +2 -2
- 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 +39 -0
- package/main/default/services/utils/page-schema.js +174 -0
- package/package.json +2 -5
|
@@ -101,11 +101,11 @@
|
|
|
101
101
|
})
|
|
102
102
|
|
|
103
103
|
if (props.env.enableAMISDebug && schema) {
|
|
104
|
-
console.groupCollapsed(
|
|
104
|
+
console.groupCollapsed(`[steedos render ${comp.amis?.render.type}]`);
|
|
105
105
|
console.trace('Component: ', props, 'Generated Amis Schema: ', schema);
|
|
106
106
|
console.groupEnd();
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
|
|
109
109
|
return amisReact.createElement(amisReact.Fragment, null, amisReact.createElement(amisReact.Fragment, null, schema && render ? render('body', schema) : ''), amisReact.createElement(amisReact.Fragment, null, render ? render('body', body) : ''));
|
|
110
110
|
}
|
|
111
111
|
}
|
|
@@ -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",
|
|
@@ -310,6 +320,35 @@ module.exports = {
|
|
|
310
320
|
})));
|
|
311
321
|
}
|
|
312
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
|
+
},
|
|
313
352
|
getObjectRelatedListsOptions: {
|
|
314
353
|
async handler(ctx) {
|
|
315
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.2",
|
|
4
4
|
"main": "package.service.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "yarn build:tailwind-base && yarn build:tailwind",
|
|
@@ -13,10 +13,7 @@
|
|
|
13
13
|
"publishConfig": {
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
|
-
"
|
|
17
|
-
"@steedos-widgets/amis-lib": "^1.0.22"
|
|
18
|
-
},
|
|
19
|
-
"gitHead": "70a4e7417d8d86c47cf5c7e3bbe0e89f2cee4222",
|
|
16
|
+
"gitHead": "0e880759058022827b737df329c254aff2bc94dc",
|
|
20
17
|
"devDependencies": {
|
|
21
18
|
"tailwindcss": "3.2.4"
|
|
22
19
|
}
|