@steedos/service-plugin-amis 2.2.35 → 2.2.38
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 +81 -9
- package/main/default/client/amis.util.client.js +156 -0
- package/main/default/client/creator.function.client.js +153 -0
- package/main/default/pages/listview_form.page.amis.json +339 -0
- package/main/default/pages/listview_form.page.yml +12 -0
- package/main/default/services/amis.service.js +25 -2
- package/main/default/services/metadata/listviews.service.js +261 -52
- package/main/default/services/metadata/objects.service.js +166 -0
- package/main/default/services/utils/amis-schema.js +27 -0
- package/main/default/services/utils/fields/index.js +391 -0
- package/main/default/services/utils/fields/lookup.js +236 -0
- package/main/default/services/utils/fields/sections.js +86 -0
- package/main/default/services/utils/fields/table.js +140 -0
- package/main/default/services/utils/graphql.js +137 -0
- package/main/default/services/utils/object-list.js +72 -0
- package/main/default/services/utils/object-record.js +212 -0
- package/main/default/services/utils/tpl.js +94 -0
- package/main/default/services/utils/util.js +15 -0
- package/package.json +2 -2
- package/public/amis/amis.css +56 -4
- package/public/amis/sdk/sdk.css +0 -50980
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: baozhoutao@steedos.com
|
|
3
|
+
* @Date: 2022-05-26 16:02:08
|
|
4
|
+
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
+
* @LastEditTime: 2022-05-27 10:18:51
|
|
6
|
+
* @Description:
|
|
7
|
+
*/
|
|
8
|
+
const Fields = require('../fields');
|
|
9
|
+
const lodash = require('lodash');
|
|
10
|
+
|
|
11
|
+
const getFieldSchemaArray = (mergedSchema)=>{
|
|
12
|
+
let fieldSchemaArray = [];
|
|
13
|
+
fieldSchemaArray.length = 0
|
|
14
|
+
|
|
15
|
+
const fieldsArr = [];
|
|
16
|
+
lodash.forEach(mergedSchema.fields, (field, fieldName)=>{
|
|
17
|
+
if(!lodash.has(field, "name")){
|
|
18
|
+
field.name = fieldName
|
|
19
|
+
}
|
|
20
|
+
fieldsArr.push(field)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
lodash.forEach(lodash.sortBy(mergedSchema.fields, "sort_no"), (field) => {
|
|
24
|
+
if (!field.group || field.group == 'null' || field.group == '-')
|
|
25
|
+
field.group = '通用'
|
|
26
|
+
const fieldName = field.name;
|
|
27
|
+
let isObjectField = /\w+\.\w+/.test(fieldName)
|
|
28
|
+
if (field.type == 'grid' || field.type == 'object') {
|
|
29
|
+
// field.group = field.label
|
|
30
|
+
field.is_wide = true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!isObjectField){
|
|
34
|
+
if(!field.hidden){
|
|
35
|
+
fieldSchemaArray.push(Object.assign({name: fieldName}, field, {permission: {allowEdit: true}}))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
return fieldSchemaArray;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getSection = (permissionFields, fieldSchemaArray, sectionName) => {
|
|
43
|
+
const sectionFields = lodash.filter(fieldSchemaArray, { 'group': sectionName });
|
|
44
|
+
if(sectionFields.length == lodash.filter(sectionFields, ['hidden', true]).length){
|
|
45
|
+
return ;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const fieldSetBody = [];
|
|
49
|
+
|
|
50
|
+
_.each(sectionFields, (perField)=>{
|
|
51
|
+
let field = perField;
|
|
52
|
+
if(perField.type === 'grid'){
|
|
53
|
+
field = Fields.getGridFieldSubFields(perField, permissionFields);
|
|
54
|
+
}else if(perField.type === 'object'){
|
|
55
|
+
field = Fields.getObjectFieldSubFields(perField, permissionFields);
|
|
56
|
+
}
|
|
57
|
+
if(field.name.indexOf(".") < 0){
|
|
58
|
+
const amisField = Fields.convertSFieldToAmisField(field, false);
|
|
59
|
+
if(amisField){
|
|
60
|
+
fieldSetBody.push(amisField)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
"type": "fieldSet",
|
|
67
|
+
"title": sectionName,
|
|
68
|
+
"collapsable": true,
|
|
69
|
+
"body": fieldSetBody
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const getSections = (permissionFields, mergedSchema) => {
|
|
74
|
+
const fieldSchemaArray = getFieldSchemaArray(mergedSchema)
|
|
75
|
+
const _sections = lodash.groupBy(fieldSchemaArray, 'group');
|
|
76
|
+
const sections = [];
|
|
77
|
+
lodash.forEach(_sections, (value, key) => {
|
|
78
|
+
const section = getSection(permissionFields, fieldSchemaArray, key);
|
|
79
|
+
if(section.body.length > 0){
|
|
80
|
+
sections.push(section)
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
return sections;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
exports.getSections = getSections;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
const Tpl = require('../tpl');
|
|
2
|
+
const Fields = require('./index');
|
|
3
|
+
const _ = require('underscore');
|
|
4
|
+
const graphql = require('../graphql');
|
|
5
|
+
function getOperation(fields){
|
|
6
|
+
const controls = [];
|
|
7
|
+
_.each(fields, function(field){
|
|
8
|
+
controls.push(Fields.convertSFieldToAmisField(field, true));
|
|
9
|
+
})
|
|
10
|
+
return {
|
|
11
|
+
"type": "operation",
|
|
12
|
+
"label": "操作",
|
|
13
|
+
"width": 100,
|
|
14
|
+
fixed: "right",
|
|
15
|
+
"buttons": [
|
|
16
|
+
{
|
|
17
|
+
"type": "button",
|
|
18
|
+
"icon": "fa fa-eye",
|
|
19
|
+
"actionType": "dialog",
|
|
20
|
+
"tooltip": "查看",
|
|
21
|
+
"dialog": {
|
|
22
|
+
"title": "查看",
|
|
23
|
+
"body": {
|
|
24
|
+
"type": "form",
|
|
25
|
+
"controls": controls
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//获取name字段,如果没有,则_index字段添加链接
|
|
33
|
+
function getDetailColumn(){}
|
|
34
|
+
|
|
35
|
+
function getTableColumns(fields){
|
|
36
|
+
const columns = [{name: '_index',type: 'text', width: 32}];
|
|
37
|
+
_.each(fields, function(field){
|
|
38
|
+
|
|
39
|
+
const tpl = Tpl.getFieldTpl(field);
|
|
40
|
+
|
|
41
|
+
let type = 'text';
|
|
42
|
+
if(tpl){
|
|
43
|
+
type = 'tpl';
|
|
44
|
+
}
|
|
45
|
+
if(!field.hidden){
|
|
46
|
+
columns.push({
|
|
47
|
+
name: field.name,
|
|
48
|
+
label: field.label,
|
|
49
|
+
sortable: field.sortable,
|
|
50
|
+
searchable: field.searchable,
|
|
51
|
+
width: field.width,
|
|
52
|
+
type: type,
|
|
53
|
+
tpl: tpl,
|
|
54
|
+
toggled: field.toggled
|
|
55
|
+
// toggled: true
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// columns.push(getOperation(fields));
|
|
61
|
+
|
|
62
|
+
return columns;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function getDefaultParams(options){
|
|
66
|
+
return {
|
|
67
|
+
perPage: options.top || 10
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
exports.getTableSchema = function(fields, options){
|
|
72
|
+
if(!options){
|
|
73
|
+
options = {};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
mode: "table",
|
|
77
|
+
name: "thelist",
|
|
78
|
+
draggable: false,
|
|
79
|
+
headerToolbar: ['switch-per-page', 'pagination'],
|
|
80
|
+
defaultParams: getDefaultParams(options),
|
|
81
|
+
columns: getTableColumns(fields),
|
|
82
|
+
syncLocation: false,
|
|
83
|
+
keepItemSelectionOnPageChange: true
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
exports.getTableApi = function(mainObject, fields){
|
|
88
|
+
const searchableFields = [];
|
|
89
|
+
_.each(fields,function(field){
|
|
90
|
+
if(field.searchable){
|
|
91
|
+
searchableFields.push(field.name);
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
let valueField = mainObject.key_field || '_id';
|
|
95
|
+
const api = getApi(mainObject, null, fields, {alias: 'rows', queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"`});
|
|
96
|
+
api.data.$term = "$term";
|
|
97
|
+
api.data.$self = "$$";
|
|
98
|
+
api.requestAdaptor = `
|
|
99
|
+
const selfData = JSON.parse(JSON.stringify(api.data.$self));
|
|
100
|
+
var filters = [];
|
|
101
|
+
var pageSize = api.data.pageSize || 10;
|
|
102
|
+
var pageNo = api.data.pageNo || 1;
|
|
103
|
+
var skip = (pageNo - 1) * pageSize;
|
|
104
|
+
var orderBy = api.data.orderBy || '';
|
|
105
|
+
var orderDir = api.data.orderDir || '';
|
|
106
|
+
var sort = orderBy + ' ' + orderDir;
|
|
107
|
+
var allowSearchFields = ${JSON.stringify(searchableFields)};
|
|
108
|
+
if(api.data.$term){
|
|
109
|
+
filters = [["name", "contains", "'+ api.data.$term +'"]];
|
|
110
|
+
}else if(selfData.op === 'loadOptions' && selfData.value){
|
|
111
|
+
filters = [["${valueField}", "=", selfData.value]];
|
|
112
|
+
}
|
|
113
|
+
if(allowSearchFields){
|
|
114
|
+
allowSearchFields.forEach(function(key){
|
|
115
|
+
const keyValue = selfData[key];
|
|
116
|
+
if(keyValue){
|
|
117
|
+
filters.push([key, "contains", keyValue]);
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
api.data.query = api.data.query.replaceAll('{__filters}', JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim());
|
|
122
|
+
return api;
|
|
123
|
+
`
|
|
124
|
+
api.adaptor = `
|
|
125
|
+
_.each(payload.data.rows, function(item, index){
|
|
126
|
+
item._index = index + 1;
|
|
127
|
+
})
|
|
128
|
+
console.log('payload.data', payload.data);
|
|
129
|
+
return payload;
|
|
130
|
+
`;
|
|
131
|
+
return api;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function getApi(object, recordId, fields, options){
|
|
135
|
+
return {
|
|
136
|
+
method: "post",
|
|
137
|
+
url: graphql.getApi(),
|
|
138
|
+
data: graphql.getFindQuery(object, recordId, fields, options)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
const objectql = require('@steedos/objectql');
|
|
2
|
+
const _ = require('underscore');
|
|
3
|
+
function getFieldsTemplate(fields, expand){
|
|
4
|
+
if(expand != false){
|
|
5
|
+
expand = true;
|
|
6
|
+
}
|
|
7
|
+
let fieldsName = ['_id'];
|
|
8
|
+
let displayFields = [];
|
|
9
|
+
//TODO 此处需要考虑相关对象查询
|
|
10
|
+
_.each(fields, function(field){
|
|
11
|
+
if(field.name.indexOf('.') < 0){
|
|
12
|
+
if(expand && (field.type == 'lookup' || field.type == 'master_detail') && field.reference_to){
|
|
13
|
+
const NAME_FIELD_KEY = objectql.getObject(field.reference_to).NAME_FIELD_KEY;
|
|
14
|
+
fieldsName.push(`${field.name}:${field.name}__expand{_id,${NAME_FIELD_KEY}}`)
|
|
15
|
+
}else{
|
|
16
|
+
fieldsName.push(field.name)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if(field.type === 'date' || field.type == 'datetime' || field.type == 'boolean'){
|
|
20
|
+
fieldsName.push(`${field.name}`)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if(field.type === 'date' || field.type == 'datetime' || field.type == 'boolean' || field.type == 'select'){
|
|
24
|
+
displayFields.push(`${field.name}`)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
displayFields = _.uniq(displayFields);
|
|
30
|
+
fieldsName = _.uniq(fieldsName);
|
|
31
|
+
|
|
32
|
+
if(displayFields.length > 0){
|
|
33
|
+
return `${fieldsName.join(',')},_display{${displayFields.join(',')}}`;
|
|
34
|
+
}
|
|
35
|
+
return `${fieldsName.join(' ')}`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getFindOneQuery(object, recordId, fields, options){
|
|
39
|
+
let queryOptions = "";
|
|
40
|
+
if(recordId){
|
|
41
|
+
queryOptions = `(filters:["_id", "=", "${recordId}"])`;
|
|
42
|
+
}
|
|
43
|
+
let alias = "data";
|
|
44
|
+
if(options){
|
|
45
|
+
if(options.alias){
|
|
46
|
+
alias = options.alias;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if(options.filters){
|
|
50
|
+
queryOptions = `(filters:${options.filters})`;
|
|
51
|
+
}
|
|
52
|
+
if(options.queryOptions){
|
|
53
|
+
queryOptions = `(${options.queryOptions})`;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
query: `{${alias}:${object.name}${queryOptions}{${getFieldsTemplate(fields)}}}`
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getSaveQuery(object, recordId, fields, options){
|
|
62
|
+
return {
|
|
63
|
+
objectName: "${objectName}",
|
|
64
|
+
$: "$$",
|
|
65
|
+
recordId: "${recordId}",
|
|
66
|
+
modalName: "${modalName}"
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getSaveDataTpl(){
|
|
71
|
+
return `
|
|
72
|
+
const formData = api.data.$;
|
|
73
|
+
const objectName = api.data.objectName;
|
|
74
|
+
const fieldsName = Object.keys(formData);
|
|
75
|
+
delete formData.created;
|
|
76
|
+
delete formData.created_by;
|
|
77
|
+
delete formData.modified;
|
|
78
|
+
delete formData.modified_by;
|
|
79
|
+
|
|
80
|
+
let query = \`mutation{record: \${objectName}__insert(doc: {__saveData}){_id}}\`;
|
|
81
|
+
if(formData.recordId){
|
|
82
|
+
query = \`mutation{record: \${objectName}__update(id: "\${formData.recordId}", doc: {__saveData}){_id}}\`;
|
|
83
|
+
};
|
|
84
|
+
delete formData._id;
|
|
85
|
+
let __saveData = JSON.stringify(JSON.stringify(formData));
|
|
86
|
+
`
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getSaveRequestAdaptor(){
|
|
90
|
+
return `
|
|
91
|
+
${getSaveDataTpl()}
|
|
92
|
+
api.data = {query: query.replace('{__saveData}', __saveData)};
|
|
93
|
+
return api;
|
|
94
|
+
`
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function getFindQuery(object, recordId, fields, options){
|
|
98
|
+
let limit = options.limit || 10;
|
|
99
|
+
let queryOptions = `(top: ${limit})`;
|
|
100
|
+
if(recordId){
|
|
101
|
+
queryOptions = `(filters:["_id", "=", "${recordId}"], top: ${limit})`;
|
|
102
|
+
}
|
|
103
|
+
let alias = "data";
|
|
104
|
+
if(options){
|
|
105
|
+
if(options.alias){
|
|
106
|
+
alias = options.alias;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if(options.filters){
|
|
110
|
+
queryOptions = `(filters:${options.filters})`;
|
|
111
|
+
}
|
|
112
|
+
if(options.queryOptions){
|
|
113
|
+
queryOptions = `(${options.queryOptions})`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
orderBy: "${orderBy}",
|
|
118
|
+
orderDir: "${orderDir}",
|
|
119
|
+
pageNo: "${page}",
|
|
120
|
+
pageSize: "${perPage}",
|
|
121
|
+
query: `{${alias}:${object.name}${queryOptions}{${getFieldsTemplate(fields, options.expand)}},count:${object.name}__count(filters:{__filters})}`
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.getFindQuery = getFindQuery;
|
|
125
|
+
exports.getFindOneQuery = getFindOneQuery;
|
|
126
|
+
exports.getSaveQuery = getSaveQuery;
|
|
127
|
+
exports.getSaveRequestAdaptor = getSaveRequestAdaptor;
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
exports.getApi = function(isMobile){
|
|
131
|
+
if(isMobile){
|
|
132
|
+
//TODO 返回 绝对路径
|
|
133
|
+
}else{
|
|
134
|
+
// return __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + "/graphql"
|
|
135
|
+
return `\${context.rootUrl}/graphql`
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const Table = require('./fields/table');
|
|
2
|
+
const Util = require('./util');
|
|
3
|
+
function getBulkActions(){
|
|
4
|
+
return [
|
|
5
|
+
{
|
|
6
|
+
"label": "批量删除",
|
|
7
|
+
"actionType": "ajax",
|
|
8
|
+
"api": "delete:https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/${ids|raw}",
|
|
9
|
+
"confirmText": "确定要批量删除?"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"label": "批量修改",
|
|
13
|
+
"actionType": "dialog",
|
|
14
|
+
"dialog": {
|
|
15
|
+
"title": "批量编辑",
|
|
16
|
+
"name": "sample-bulk-edit",
|
|
17
|
+
"body": {
|
|
18
|
+
"type": "form",
|
|
19
|
+
"api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/bulkUpdate2",
|
|
20
|
+
"controls": [
|
|
21
|
+
{
|
|
22
|
+
"type": "hidden",
|
|
23
|
+
"name": "ids"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"type": "text",
|
|
27
|
+
"name": "engine",
|
|
28
|
+
"label": "Engine"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getHeaderToolbar(mainObject){
|
|
38
|
+
console.log('mainObject.icon', mainObject.icon);
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
"type": "tpl",
|
|
42
|
+
"tpl": `<span class="slds-icon_container slds-icon-standard-${mainObject.icon}"><svg class="extraSmall forceEntityIcon slds-icon slds-icon" aria-hidden="true"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="${Util.getSvgUrl("standard-sprite", mainObject.icon)}" /></svg></span> <span>${mainObject.label}</span><span> (\${count})</span>`,
|
|
43
|
+
"className": "v-middle font-semibold"
|
|
44
|
+
},
|
|
45
|
+
// "bulkActions",
|
|
46
|
+
{
|
|
47
|
+
"type": "columns-toggler",
|
|
48
|
+
"align": "right"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"type": "drag-toggler",
|
|
52
|
+
"align": "right"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"type": "pagination",
|
|
56
|
+
"align": "right"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.getObjectList = function(mainObject, fields, options){
|
|
62
|
+
const table = Table.getTableSchema(fields, options);
|
|
63
|
+
delete table.mode;
|
|
64
|
+
const bulkActions = getBulkActions()
|
|
65
|
+
return {
|
|
66
|
+
type: 'page',
|
|
67
|
+
bodyClassName: 'p-0',
|
|
68
|
+
name: `page_list_${mainObject.name}`,
|
|
69
|
+
body: Object.assign({}, table, {type: 'crud', keepItemSelectionOnPageChange: true, headerToolbar: getHeaderToolbar(mainObject),"bulkActions": bulkActions, api: Table.getTableApi(mainObject, fields)})
|
|
70
|
+
}
|
|
71
|
+
return
|
|
72
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
const _ = require('underscore');
|
|
2
|
+
const graphql = require('./graphql');
|
|
3
|
+
const Fields = require('./fields');
|
|
4
|
+
const Sections = require('./fields/sections');
|
|
5
|
+
|
|
6
|
+
const OMIT_FIELDS = ['created', 'created_by', 'modified', 'modified_by'];
|
|
7
|
+
const APICACHE = 100;
|
|
8
|
+
|
|
9
|
+
function getReadonlyFormAdaptor(fields){
|
|
10
|
+
let scriptStr = '';
|
|
11
|
+
const selectFields = _.filter(fields, function(field){return field.name.indexOf('.') < 0 && ((field.type == 'select' && field.options) || ((field.type == 'lookup' || field.type == 'master_detail') && !field.reference_to))});
|
|
12
|
+
_.each(selectFields, function(field){
|
|
13
|
+
if(!_.include(OMIT_FIELDS, field.name)){
|
|
14
|
+
const valueField = field.name;
|
|
15
|
+
if(field.options){
|
|
16
|
+
const options = JSON.stringify({options: field.options});
|
|
17
|
+
scriptStr = scriptStr + `var ${field.name}Options= (${options}).options;`;
|
|
18
|
+
}else if(field.optionsFunction){
|
|
19
|
+
scriptStr = scriptStr + `var ${field.name}Options = eval(${field.optionsFunction.toString()})(api.data);`
|
|
20
|
+
}
|
|
21
|
+
if(field.multiple){
|
|
22
|
+
scriptStr = scriptStr + `data.${field.name}__label = _.pluck(_.filter(${field.name}Options, function(option){return _.include(data.${field.name}, option.value)}), 'label');`
|
|
23
|
+
}else{
|
|
24
|
+
scriptStr = scriptStr + `var ${field.name}Selected = _.find(${field.name}Options, function(option){return data.${field.name} == option.value});`
|
|
25
|
+
scriptStr = scriptStr + `data.${field.name}__label = ${field.name}Selected ? ${field.name}Selected.label:null;`
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// const refFields = _.filter(fields, function(field){return field.name.indexOf('.') < 0 && (field.type == 'lookup' || field.type == 'master_detail') && !field.reference_to});
|
|
31
|
+
// _.each(refFields, function(field){
|
|
32
|
+
// if(!_.include(OMIT_FIELDS, field.name)){
|
|
33
|
+
// const valueField = field.reference_to_field || '_id';
|
|
34
|
+
// scriptStr = scriptStr + `var ${field.name}Options = eval(${field.optionsFunction.toString()})(api.data);`
|
|
35
|
+
// if(field.multiple){
|
|
36
|
+
// scriptStr = scriptStr + `data.${field.name}__label = _.pluck(_.filter(${field.name}Options, function(option){return _.include(data.${field.name}, option.value)}), 'label');`
|
|
37
|
+
// }else{
|
|
38
|
+
// scriptStr = scriptStr + `var ${field.name}Selected = _.find(${field.name}Options, function(option){return data.${field.name} == option.value});`
|
|
39
|
+
// scriptStr = scriptStr + `data.${field.name}__label = ${field.name}Selected ? ${field.name}Selected.label:null;`
|
|
40
|
+
// }
|
|
41
|
+
// }
|
|
42
|
+
// })
|
|
43
|
+
|
|
44
|
+
return `
|
|
45
|
+
var data = payload.data.data[0];
|
|
46
|
+
${scriptStr}
|
|
47
|
+
payload.data = data;
|
|
48
|
+
return payload;
|
|
49
|
+
`
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getReadonlyFormInitApi(object, recordId, fields){
|
|
53
|
+
return {
|
|
54
|
+
method: "post",
|
|
55
|
+
url: graphql.getApi()+"?rf="+ (new Date()).getTime(),
|
|
56
|
+
cache: APICACHE,
|
|
57
|
+
adaptor: getReadonlyFormAdaptor(fields),
|
|
58
|
+
data: graphql.getFindOneQuery(object, recordId, fields)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Global parameter: data、payload
|
|
64
|
+
* @param {*} fields
|
|
65
|
+
*/
|
|
66
|
+
function getConvertDataScriptStr(fields){
|
|
67
|
+
const refFields = _.filter(fields, function(field){return field.name.indexOf('.') < 0 && (field.type == 'lookup' || field.type == 'master_detail') && field.reference_to});
|
|
68
|
+
let scriptStr = '';
|
|
69
|
+
_.each(refFields, function(field){
|
|
70
|
+
if(!_.include(OMIT_FIELDS, field.name)){
|
|
71
|
+
const valueField = field.reference_to_field || '_id';
|
|
72
|
+
if(field.multiple){
|
|
73
|
+
scriptStr = scriptStr + `data.${field.name} = _.pluck(data.${field.name}, '${valueField}');`
|
|
74
|
+
}else{
|
|
75
|
+
scriptStr = scriptStr + `data.${field.name} = data.${field.name} ? data.${field.name}.${valueField}:null;`
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
return scriptStr;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getEditFormInitApi(object, recordId, fields){
|
|
83
|
+
return {
|
|
84
|
+
method: "post",
|
|
85
|
+
url: graphql.getApi(),
|
|
86
|
+
sendOn: "!!this.recordId",
|
|
87
|
+
cache: APICACHE,
|
|
88
|
+
adaptor: `
|
|
89
|
+
var data = payload.data.data[0];
|
|
90
|
+
if(data){
|
|
91
|
+
${getConvertDataScriptStr(fields)}
|
|
92
|
+
};
|
|
93
|
+
payload.data = data;
|
|
94
|
+
delete payload.extensions;
|
|
95
|
+
return payload;
|
|
96
|
+
`,
|
|
97
|
+
data: graphql.getFindOneQuery(object, recordId, fields)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getSaveApi(object, recordId, fields, options){
|
|
102
|
+
return {
|
|
103
|
+
method: 'post',
|
|
104
|
+
url: graphql.getApi(),
|
|
105
|
+
data: graphql.getSaveQuery(object, recordId, fields, options),
|
|
106
|
+
requestAdaptor: graphql.getSaveRequestAdaptor(),
|
|
107
|
+
responseData: {
|
|
108
|
+
"recordId": "${record._id}"
|
|
109
|
+
},
|
|
110
|
+
adaptor: `
|
|
111
|
+
SteedosUI.getRef(api.body.modalName).close();
|
|
112
|
+
SteedosUI.router.go({objectName: api.body.objectName, recordId: payload.data.record._id, type: api.body.recordId ? 'edit': 'new'});
|
|
113
|
+
return payload;
|
|
114
|
+
`
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function getInitApi(object, recordId, fields, readonly){
|
|
119
|
+
if(readonly){
|
|
120
|
+
return getReadonlyFormInitApi(object, recordId, fields);
|
|
121
|
+
}else{
|
|
122
|
+
return getEditFormInitApi(object, recordId, fields);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function getFormActions(redirect){
|
|
127
|
+
return [
|
|
128
|
+
{
|
|
129
|
+
"type": "button",
|
|
130
|
+
"label": "取消",
|
|
131
|
+
"actionType": "",
|
|
132
|
+
"level": "default",
|
|
133
|
+
"block": false,
|
|
134
|
+
"onClick": "SteedosUI.getRef(props.data.__super.modalName).close();"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"type": "button",
|
|
138
|
+
"label": "保存",
|
|
139
|
+
"actionType": "submit",
|
|
140
|
+
"level": "info"
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
function getFormBody(permissionFields, objectConfig){
|
|
147
|
+
return Sections.getSections(permissionFields, objectConfig);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
function convertSObjectToAmisSchema(objectConfig, recordId, readonly, userSession) {
|
|
152
|
+
// const fieldControls = [];
|
|
153
|
+
const permissionFields = Fields.getPermissionFields(objectConfig, userSession)
|
|
154
|
+
// _.each(permissionFields, function(perField){
|
|
155
|
+
// let field = perField;
|
|
156
|
+
// if(perField.type === 'grid'){
|
|
157
|
+
// field = Fields.getGridFieldSubFields(perField, permissionFields);
|
|
158
|
+
// }else if(perField.type === 'object'){
|
|
159
|
+
// field = Fields.getObjectFieldSubFields(perField, permissionFields);
|
|
160
|
+
// }
|
|
161
|
+
// if(field.name.indexOf(".") < 0){
|
|
162
|
+
// fieldControls.push(Fields.convertSFieldToAmisField(field, readonly))
|
|
163
|
+
// }
|
|
164
|
+
// })
|
|
165
|
+
|
|
166
|
+
// _.each(Fields.getBaseFields(readonly), function(field){
|
|
167
|
+
// fieldControls.push(field);
|
|
168
|
+
// })
|
|
169
|
+
|
|
170
|
+
let gapClassName = 'row-gap-1';
|
|
171
|
+
if(!readonly){
|
|
172
|
+
gapClassName = 'row-gap-4'
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const redirect = `/app/admin/${objectConfig.name}/view/${recordId}`
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
type: 'page',
|
|
179
|
+
bodyClassName: 'p-0',
|
|
180
|
+
regions: [
|
|
181
|
+
"body"
|
|
182
|
+
],
|
|
183
|
+
name: `page_${readonly ? 'readonly':'edit'}_${recordId}`,
|
|
184
|
+
initApi: readonly ? getInitApi(objectConfig, recordId, permissionFields, readonly) : null,
|
|
185
|
+
initFetch: readonly ? true : null,
|
|
186
|
+
body: [
|
|
187
|
+
{
|
|
188
|
+
type: "form",
|
|
189
|
+
mode: "normal",
|
|
190
|
+
// reload: `page_${readonly ? 'edit':'readonly'}_${recordId}`,
|
|
191
|
+
// redirect: redirect,
|
|
192
|
+
persistData: false,
|
|
193
|
+
promptPageLeave: readonly ? false : true,
|
|
194
|
+
name: `form_${readonly ? 'readonly':'edit'}_${recordId}`,
|
|
195
|
+
debug: false,
|
|
196
|
+
title: "",
|
|
197
|
+
api: readonly ? null : getSaveApi(objectConfig, recordId, permissionFields, {}),
|
|
198
|
+
initApi: readonly ? null : getInitApi(objectConfig, recordId, permissionFields, readonly),
|
|
199
|
+
initFetch: readonly ? null : true,
|
|
200
|
+
body: getFormBody(permissionFields, objectConfig),
|
|
201
|
+
panelClassName:'m-0',
|
|
202
|
+
bodyClassName: 'p-4',
|
|
203
|
+
actions: readonly ? null : getFormActions(redirect),
|
|
204
|
+
actionsClassName: readonly ? null : "p-sm b-t b-light text-center",
|
|
205
|
+
// className: `grid grid-cols-2 ${gapClassName} col-gap-6`
|
|
206
|
+
className: 'steedos-amis-form'
|
|
207
|
+
}
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
exports.convertSObjectToAmisSchema = convertSObjectToAmisSchema;
|