@steedos-widgets/amis-lib 1.2.13 → 1.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/index.cjs.js +2246 -2006
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +2247 -2007
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +2286 -2046
- package/dist/index.umd.js.map +1 -1
- package/dist/types/lib/converter/amis/fields/lookup.d.ts +1 -67
- package/dist/types/lib/converter/amis/fields/sections.d.ts +9 -0
- package/dist/types/lib/converter/amis/form.d.ts +9 -0
- package/dist/types/lib/converter/amis/index.d.ts +9 -0
- package/dist/types/lib/objects.d.ts +11 -0
- package/package.json +2 -2
package/dist/index.umd.js
CHANGED
|
@@ -1412,8 +1412,8 @@
|
|
|
1412
1412
|
/*
|
|
1413
1413
|
* @Author: baozhoutao@steedos.com
|
|
1414
1414
|
* @Date: 2022-11-01 15:51:00
|
|
1415
|
-
* @LastEditors:
|
|
1416
|
-
* @LastEditTime: 2023-
|
|
1415
|
+
* @LastEditors: liaodaxue
|
|
1416
|
+
* @LastEditTime: 2023-06-06 11:12:33
|
|
1417
1417
|
* @Description:
|
|
1418
1418
|
*/
|
|
1419
1419
|
|
|
@@ -1496,7 +1496,7 @@
|
|
|
1496
1496
|
"isLookup": "${isLookup}",
|
|
1497
1497
|
"listName": "${listName}"
|
|
1498
1498
|
},
|
|
1499
|
-
"title": "新建 ${uiSchema.label}",
|
|
1499
|
+
"title": "新建 ${uiSchema.label | raw}",
|
|
1500
1500
|
"body": [
|
|
1501
1501
|
{
|
|
1502
1502
|
"type": "service",
|
|
@@ -5469,6 +5469,7 @@ else{
|
|
|
5469
5469
|
pickerSchema = await getTableSchema$1(tableFields, {
|
|
5470
5470
|
labelFieldName: refObjectConfig.NAME_FIELD_KEY,
|
|
5471
5471
|
top: top,
|
|
5472
|
+
isLookup: true,
|
|
5472
5473
|
...ctx
|
|
5473
5474
|
});
|
|
5474
5475
|
|
|
@@ -5518,6 +5519,10 @@ else{
|
|
|
5518
5519
|
};
|
|
5519
5520
|
}
|
|
5520
5521
|
|
|
5522
|
+
if(field.pickerSchema){
|
|
5523
|
+
pickerSchema = Object.assign({}, pickerSchema, field.pickerSchema);
|
|
5524
|
+
}
|
|
5525
|
+
|
|
5521
5526
|
const data = {
|
|
5522
5527
|
type: getAmisStaticFieldType('picker', readonly),
|
|
5523
5528
|
labelField: referenceTo.labelField.name,
|
|
@@ -6044,7 +6049,7 @@ else{
|
|
|
6044
6049
|
return {
|
|
6045
6050
|
type: amisFieldType,
|
|
6046
6051
|
tpl: `
|
|
6047
|
-
<% let fileData = data.${steedosField.name}; if (fileData) { %>
|
|
6052
|
+
<% let fileData = data._display.${steedosField.name}; if (fileData) { %>
|
|
6048
6053
|
<% if(!Array.isArray(fileData)){ fileData = [fileData]} %>
|
|
6049
6054
|
<% fileData.forEach(function(item) { %>
|
|
6050
6055
|
<a href='<%= item.url %>' target='_self' class='block'><%= item.name %></a>
|
|
@@ -6085,7 +6090,6 @@ else{
|
|
|
6085
6090
|
}
|
|
6086
6091
|
}
|
|
6087
6092
|
};
|
|
6088
|
-
|
|
6089
6093
|
if(steedosField.multiple){
|
|
6090
6094
|
convertData.multiple = true;
|
|
6091
6095
|
convertData.joinValues = false;
|
|
@@ -6808,2204 +6812,2439 @@ else{
|
|
|
6808
6812
|
getAmisStaticFieldType: getAmisStaticFieldType
|
|
6809
6813
|
});
|
|
6810
6814
|
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
}else if(field.optionsFunction){
|
|
6824
|
-
scriptStr = scriptStr + `var ${field.name}Options = eval(${field.optionsFunction.toString()})(api.data);`;
|
|
6825
|
-
}else if(field._optionsFunction){
|
|
6826
|
-
scriptStr = scriptStr + `var ${field.name}Options = eval(${field._optionsFunction})(api.data);`;
|
|
6827
|
-
}
|
|
6828
|
-
if(field.multiple){
|
|
6829
|
-
scriptStr = scriptStr + `data.${field.name}__label = _.map(_.filter(${field.name}Options, function(option){return _.includes(data.${field.name}, option.value)}), 'label');`;
|
|
6830
|
-
}else {
|
|
6831
|
-
scriptStr = scriptStr + `var ${field.name}Selected = _.find(${field.name}Options, function(option){return data.${field.name} == option.value});`;
|
|
6832
|
-
scriptStr = scriptStr + `data.${field.name}__label = ${field.name}Selected ? ${field.name}Selected.label:null;`;
|
|
6833
|
-
}
|
|
6834
|
-
}
|
|
6835
|
-
});
|
|
6836
|
-
|
|
6837
|
-
// const refFields = _.filter(fields, function(field){return field.name.indexOf('.') < 0 && (field.type == 'lookup' || field.type == 'master_detail') && !field.reference_to});
|
|
6838
|
-
// _.each(refFields, function(field){
|
|
6839
|
-
// if(!_.includes(OMIT_FIELDS, field.name)){
|
|
6840
|
-
// const valueField = field.reference_to_field || '_id';
|
|
6841
|
-
// scriptStr = scriptStr + `var ${field.name}Options = eval(${field.optionsFunction.toString()})(api.data);`
|
|
6842
|
-
// if(field.multiple){
|
|
6843
|
-
// scriptStr = scriptStr + `data.${field.name}__label = _.map(_.filter(${field.name}Options, function(option){return _.includes(data.${field.name}, option.value)}), 'label');`
|
|
6844
|
-
// }else{
|
|
6845
|
-
// scriptStr = scriptStr + `var ${field.name}Selected = _.find(${field.name}Options, function(option){return data.${field.name} == option.value});`
|
|
6846
|
-
// scriptStr = scriptStr + `data.${field.name}__label = ${field.name}Selected ? ${field.name}Selected.label:null;`
|
|
6847
|
-
// }
|
|
6848
|
-
// }
|
|
6849
|
-
// })
|
|
6850
|
-
|
|
6851
|
-
return `
|
|
6852
|
-
if(payload.data.data.length === 0){
|
|
6853
|
-
return {
|
|
6854
|
-
status: 2,
|
|
6855
|
-
msg: "无法找到记录"
|
|
6856
|
-
}
|
|
6857
|
-
}
|
|
6858
|
-
if(payload.data.data){
|
|
6859
|
-
var data = payload.data.data[0];
|
|
6860
|
-
var gridAndObjectFieldsName = ${JSON.stringify(gridAndObjectFieldsName)};
|
|
6861
|
-
try{
|
|
6862
|
-
${scriptStr}
|
|
6863
|
-
${getScriptForAddUrlPrefixForImgFields(fields)}
|
|
6864
|
-
${getScriptForRewriteValueForFileFields(fields)}
|
|
6865
|
-
}catch(e){
|
|
6866
|
-
console.error(e)
|
|
6867
|
-
}
|
|
6868
|
-
// 原始记录
|
|
6869
|
-
var record = _.cloneDeep(data);
|
|
6870
|
-
try{
|
|
6871
|
-
_.each(gridAndObjectFieldsName, function(name){
|
|
6872
|
-
data[name] = data._display[name];
|
|
6873
|
-
})
|
|
6874
|
-
}catch(e){
|
|
6875
|
-
console.error(e)
|
|
6876
|
-
}
|
|
6877
|
-
payload.data = data;
|
|
6878
|
-
payload.data.__objectName = "${object.name}";
|
|
6879
|
-
payload.data.__record = record;
|
|
6880
|
-
window.postMessage(Object.assign({type: "record.loaded"}, {record: record}), "*")
|
|
6881
|
-
}
|
|
6882
|
-
if(payload.errors){
|
|
6883
|
-
payload.status = 2;
|
|
6884
|
-
payload.msg = payload.errors[0].message;
|
|
6885
|
-
}
|
|
6886
|
-
return payload;
|
|
6887
|
-
`
|
|
6888
|
-
}
|
|
6889
|
-
|
|
6890
|
-
async function getReadonlyFormInitApi(object, recordId, fields, options){
|
|
6891
|
-
return {
|
|
6892
|
-
method: "post",
|
|
6893
|
-
url: getApi$2()+"&recordId=${recordId}",
|
|
6894
|
-
cache: API_CACHE,
|
|
6895
|
-
// requestAdaptor: "console.log('getReadonlyFormInitApi requestAdaptor', api);return api;",
|
|
6896
|
-
adaptor: getReadonlyFormAdaptor(object, fields),
|
|
6897
|
-
data: await getFindOneQuery$1(object, recordId, fields, options),
|
|
6898
|
-
headers: {
|
|
6899
|
-
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
6900
|
-
}
|
|
6815
|
+
/*
|
|
6816
|
+
* @Author: baozhoutao@steedos.com
|
|
6817
|
+
* @Date: 2022-08-04 10:42:49
|
|
6818
|
+
* @LastEditors: baozhoutao@steedos.com
|
|
6819
|
+
* @LastEditTime: 2022-08-25 10:28:47
|
|
6820
|
+
* @Description:
|
|
6821
|
+
*/
|
|
6822
|
+
var config = {
|
|
6823
|
+
listView: {
|
|
6824
|
+
newRecordMode: 'modal',
|
|
6825
|
+
editRecordMode: 'modal',
|
|
6826
|
+
perPage: 20
|
|
6901
6827
|
}
|
|
6902
|
-
}
|
|
6828
|
+
};
|
|
6903
6829
|
|
|
6904
|
-
|
|
6905
|
-
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
|
|
6915
|
-
|
|
6916
|
-
|
|
6830
|
+
async function getQuickEditSchema(field, options){
|
|
6831
|
+
const quickEditId = options.objectName + "_" + field.name + "QuickEdit";//定义快速编辑的表单id,用于setvalue传值
|
|
6832
|
+
var quickEditSchema = { body: [], id: quickEditId };
|
|
6833
|
+
if (field.disabled) {
|
|
6834
|
+
quickEditSchema = false;
|
|
6835
|
+
} else {
|
|
6836
|
+
var fieldSchema = await convertSFieldToAmisField(field, false, ___namespace.omit(options, 'buttons'));
|
|
6837
|
+
//存在属性上可编辑,实际不可编辑的字段,convertSFieldToAmisField函数可能会返回undefined,如summary
|
|
6838
|
+
if (!!fieldSchema) {
|
|
6839
|
+
quickEditSchema.body.push(fieldSchema);
|
|
6840
|
+
//以下字段使用_display的数据,因此在触发change等事件时对数据_display进行修改,以实现保存前的回显
|
|
6841
|
+
var TempDisplayField = ``;
|
|
6842
|
+
quickEditSchema.body[0].onEvent = {};
|
|
6843
|
+
const quickEditOnEvent = function (displayField) {
|
|
6844
|
+
const EventType = {
|
|
6845
|
+
"actions": [
|
|
6846
|
+
{
|
|
6847
|
+
"actionType": "custom",
|
|
6848
|
+
"script": `
|
|
6849
|
+
var _display = event.data._display;
|
|
6850
|
+
${displayField}
|
|
6851
|
+
doAction({actionType: 'setValue', "args": {"value": {_display}},componentId: "${quickEditId}"});
|
|
6852
|
+
`
|
|
6853
|
+
}
|
|
6854
|
+
]
|
|
6855
|
+
};
|
|
6856
|
+
return EventType;
|
|
6917
6857
|
};
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6858
|
+
switch (field.type) {
|
|
6859
|
+
//TODO:amis的picker组件直接点击选项x时不会触发change事件,待处理
|
|
6860
|
+
case "lookup":
|
|
6861
|
+
case "master_detail":
|
|
6862
|
+
if (field.multiple) {
|
|
6863
|
+
TempDisplayField = `
|
|
6864
|
+
_display["${field.name}"] = [];
|
|
6865
|
+
event.data.value.forEach(function(item,index){
|
|
6866
|
+
_display["${field.name}"].push(
|
|
6867
|
+
{
|
|
6868
|
+
"label": event.data.option[index].${quickEditSchema.body[0].labelField},
|
|
6869
|
+
"value": event.data.option[index]._id,
|
|
6870
|
+
"objectName": "${field.reference_to}"
|
|
6871
|
+
}
|
|
6872
|
+
)
|
|
6873
|
+
})
|
|
6874
|
+
`;
|
|
6875
|
+
} else {
|
|
6876
|
+
TempDisplayField = `
|
|
6877
|
+
_display["${field.name}"] = {
|
|
6878
|
+
"label": event.data.option.${quickEditSchema.body[0].labelField},
|
|
6879
|
+
"value": event.data._id,
|
|
6880
|
+
"objectName": "${field.reference_to}"
|
|
6881
|
+
}
|
|
6882
|
+
`;
|
|
6883
|
+
}
|
|
6884
|
+
quickEditSchema.body[0].onEvent["change"] = quickEditOnEvent(TempDisplayField);
|
|
6885
|
+
break;
|
|
6886
|
+
case "select":
|
|
6887
|
+
TempDisplayField = `
|
|
6888
|
+
_display["${field.name}"] = event.data.selectedItems.label;
|
|
6889
|
+
`;
|
|
6890
|
+
quickEditSchema.body[0].onEvent["change"] = quickEditOnEvent(TempDisplayField);
|
|
6891
|
+
break;
|
|
6892
|
+
case "percent":
|
|
6893
|
+
TempDisplayField = `
|
|
6894
|
+
_display["${field.name}"] = (event.data.value * 100).toFixed(${field.scale}) + '%';
|
|
6895
|
+
`;
|
|
6896
|
+
quickEditSchema.body[0].onEvent["change"] = quickEditOnEvent(TempDisplayField);
|
|
6897
|
+
break;
|
|
6898
|
+
case "time":
|
|
6899
|
+
TempDisplayField = `
|
|
6900
|
+
_display["${field.name}"] = moment(event.data.value).utc().format('HH:mm');
|
|
6901
|
+
`;
|
|
6902
|
+
quickEditSchema.body[0].onEvent["change"] = quickEditOnEvent(TempDisplayField);
|
|
6903
|
+
break;
|
|
6904
|
+
case "date":
|
|
6905
|
+
TempDisplayField = `
|
|
6906
|
+
_display["${field.name}"] = moment(event.data.value).utc().format('YYYY-MM-DD');
|
|
6907
|
+
`;
|
|
6908
|
+
quickEditSchema.body[0].onEvent["change"] = quickEditOnEvent(TempDisplayField);
|
|
6909
|
+
break;
|
|
6910
|
+
case "datetime":
|
|
6911
|
+
TempDisplayField = `
|
|
6912
|
+
_display["${field.name}"] = moment(event.data.value).format('YYYY-MM-DD HH:mm');
|
|
6913
|
+
`;
|
|
6914
|
+
quickEditSchema.body[0].onEvent["change"] = quickEditOnEvent(TempDisplayField);
|
|
6915
|
+
break;
|
|
6916
|
+
case "boolean":
|
|
6917
|
+
TempDisplayField = `
|
|
6918
|
+
_display["${field.name}"] = event.data.value?"√":"";
|
|
6919
|
+
`;
|
|
6920
|
+
quickEditSchema.body[0].onEvent["change"] = quickEditOnEvent(TempDisplayField);
|
|
6921
|
+
break;
|
|
6922
|
+
case "number":
|
|
6923
|
+
case "currency":
|
|
6924
|
+
TempDisplayField = `
|
|
6925
|
+
_display["${field.name}"] = event.data.value?.toFixed(${field.scale});
|
|
6926
|
+
`;
|
|
6927
|
+
quickEditSchema.body[0].onEvent["change"] = quickEditOnEvent(TempDisplayField);
|
|
6928
|
+
|
|
6929
|
+
break;
|
|
6930
|
+
case "file":
|
|
6931
|
+
var removeDisplayField = ``;
|
|
6932
|
+
if (field.multiple) {
|
|
6933
|
+
TempDisplayField = `
|
|
6934
|
+
_display["${field.name}"].push({
|
|
6935
|
+
"name": event.data.result.name,
|
|
6936
|
+
"url": event.data.result.url,
|
|
6937
|
+
"type": event.data.item.type,
|
|
6938
|
+
"size": event.data.item.size
|
|
6939
|
+
});
|
|
6940
|
+
`;
|
|
6941
|
+
removeDisplayField = `
|
|
6942
|
+
_.remove(_display["${field.name}"], function(file){return file.url == event.data.item.url});
|
|
6943
|
+
`;
|
|
6944
|
+
} else {
|
|
6945
|
+
TempDisplayField = `
|
|
6946
|
+
_display["${field.name}"] = {
|
|
6947
|
+
"name": event.data.result.name,
|
|
6948
|
+
"url": event.data.result.url,
|
|
6949
|
+
"type": event.data.item.type,
|
|
6950
|
+
"size": event.data.item.size
|
|
6951
|
+
};
|
|
6952
|
+
`;
|
|
6953
|
+
removeDisplayField = `
|
|
6954
|
+
if(_display["${field.name}"].url == event.data.item.url){
|
|
6955
|
+
_display["${field.name}"] = {};
|
|
6956
|
+
}
|
|
6957
|
+
`;
|
|
6958
|
+
}
|
|
6959
|
+
quickEditSchema.body[0].onEvent["success"] = quickEditOnEvent(TempDisplayField);
|
|
6960
|
+
quickEditSchema.body[0].onEvent["remove"] = quickEditOnEvent(removeDisplayField);
|
|
6961
|
+
break;
|
|
6962
|
+
case "avatar":
|
|
6963
|
+
case "image":
|
|
6964
|
+
quickEditSchema.body[0].receiver.adaptor = `
|
|
6965
|
+
const { context } = api.body;
|
|
6966
|
+
var rootUrl = context.rootUrl + "/api/files/${field.type}s/";
|
|
6967
|
+
payload = {
|
|
6968
|
+
status: response.status == 200 ? 0 : response.status,
|
|
6969
|
+
msg: response.statusText,
|
|
6970
|
+
data: {
|
|
6971
|
+
value: rootUrl + payload._id,//为了实现图片crud的回显,需要将value从id改为url,当保存数据数据时,再在发送适配器内重新将id提取出来
|
|
6972
|
+
name: payload.original.name,
|
|
6973
|
+
url: rootUrl + payload._id,
|
|
6938
6974
|
}
|
|
6939
6975
|
}
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6976
|
+
return payload;
|
|
6977
|
+
`;
|
|
6978
|
+
break;
|
|
6979
|
+
}
|
|
6943
6980
|
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
fields.forEach((item)=>{
|
|
6951
|
-
if(item.type === 'file'){
|
|
6952
|
-
fileFieldsKeys.push(item.name);
|
|
6953
|
-
fileFields[item.name] = {
|
|
6954
|
-
name: item.name,
|
|
6955
|
-
multiple: item.multiple
|
|
6956
|
-
};
|
|
6981
|
+
} else {
|
|
6982
|
+
quickEditSchema = false;
|
|
6983
|
+
}
|
|
6984
|
+
//TODO:附件多选时会覆盖老数据,暂时禁用
|
|
6985
|
+
if(field.type == "file" && field.multiple){
|
|
6986
|
+
quickEditSchema = false;
|
|
6957
6987
|
}
|
|
6958
|
-
});
|
|
6959
|
-
if(!fileFieldsKeys.length){
|
|
6960
|
-
return '';
|
|
6961
6988
|
}
|
|
6962
|
-
return
|
|
6963
|
-
// file字段值重写以便编辑时正常显示附件名、点击附件名正常下载附件
|
|
6964
|
-
let fileFieldsKeys = ${JSON.stringify(fileFieldsKeys)};
|
|
6965
|
-
let fileFields = ${JSON.stringify(fileFields)};
|
|
6966
|
-
fileFieldsKeys.forEach((item)=>{
|
|
6967
|
-
let fileFieldValue = data[item];
|
|
6968
|
-
let fileFieldDisplayValue = data._display && data._display[item];
|
|
6969
|
-
if(fileFieldValue && fileFieldValue.length){
|
|
6970
|
-
if(fileFields[item].multiple){
|
|
6971
|
-
if(fileFieldDisplayValue instanceof Array){
|
|
6972
|
-
data[item] = fileFieldDisplayValue.map((item, index)=>{
|
|
6973
|
-
return {
|
|
6974
|
-
value: fileFieldValue[index],
|
|
6975
|
-
name: item.name,
|
|
6976
|
-
url: item.url + "?download=true",
|
|
6977
|
-
state: "uploaded"
|
|
6978
|
-
}
|
|
6979
|
-
});
|
|
6980
|
-
}
|
|
6981
|
-
}else{
|
|
6982
|
-
data[item] = [{
|
|
6983
|
-
value: fileFieldValue,
|
|
6984
|
-
name: fileFieldDisplayValue.name,
|
|
6985
|
-
url: fileFieldDisplayValue.url + "?download=true",
|
|
6986
|
-
state: "uploaded"
|
|
6987
|
-
}];
|
|
6988
|
-
}
|
|
6989
|
-
}
|
|
6990
|
-
})
|
|
6991
|
-
`
|
|
6989
|
+
return quickEditSchema;
|
|
6992
6990
|
}
|
|
6993
6991
|
|
|
6994
|
-
async function
|
|
6995
|
-
const
|
|
6996
|
-
|
|
6997
|
-
|
|
6998
|
-
|
|
6999
|
-
|
|
7000
|
-
|
|
7001
|
-
|
|
7002
|
-
|
|
7003
|
-
|
|
7004
|
-
|
|
7005
|
-
|
|
7006
|
-
|
|
7007
|
-
|
|
7008
|
-
|
|
7009
|
-
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
|
|
7019
|
-
|
|
7020
|
-
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
|
|
7027
|
-
|
|
7028
|
-
|
|
7029
|
-
|
|
7030
|
-
|
|
7031
|
-
|
|
7032
|
-
|
|
7033
|
-
|
|
7034
|
-
|
|
7035
|
-
|
|
7036
|
-
}
|
|
7037
|
-
})
|
|
7038
|
-
|
|
7039
|
-
//初始化接口返回的字段移除字段值为null的字段
|
|
7040
|
-
for (key in data){
|
|
7041
|
-
if(data[key] === null){
|
|
7042
|
-
delete data[key];
|
|
7043
|
-
}
|
|
7044
|
-
}
|
|
7045
|
-
};
|
|
7046
|
-
initialValues = data;
|
|
7047
|
-
}
|
|
7048
|
-
else{
|
|
7049
|
-
var uiSchema = api.body.uiSchema;
|
|
7050
|
-
var defaultData = api.body.defaultData;
|
|
7051
|
-
var defaultValues = {};
|
|
7052
|
-
_.each(uiSchema?.fields, function(field){
|
|
7053
|
-
var value = SteedosUI.getFieldDefaultValue(field, api.body.global);
|
|
7054
|
-
if(value){
|
|
7055
|
-
defaultValues[field.name] = value;
|
|
7056
|
-
}
|
|
7057
|
-
});
|
|
7058
|
-
if(defaultData && _.isObject(defaultData) && !_.isArray(defaultData)){
|
|
7059
|
-
defaultValues = Object.assign({}, defaultValues, defaultData)
|
|
7060
|
-
}
|
|
7061
|
-
if(uiSchema.form){
|
|
7062
|
-
try{
|
|
7063
|
-
var objectFormConfig = JSON.parse(uiSchema.form);
|
|
7064
|
-
var formInitialValuesFun = objectFormConfig.initialValues;
|
|
7065
|
-
if(formInitialValuesFun){
|
|
7066
|
-
formInitialValuesFun = new Function("return " + formInitialValuesFun)();
|
|
7067
|
-
}
|
|
7068
|
-
if(typeof formInitialValuesFun === "function"){
|
|
7069
|
-
initialValues = formInitialValuesFun.apply({doc: defaultValues || {} , global: api.body.global, master: api.body._master })
|
|
7070
|
-
}
|
|
7071
|
-
}
|
|
7072
|
-
catch(ex){
|
|
7073
|
-
console.warn(ex);
|
|
6992
|
+
async function getTableColumns(fields, options){
|
|
6993
|
+
const columns = [{name: '_index',type: 'text', width: 32, placeholder: ""}];
|
|
6994
|
+
const allowEdit = options.permissions?.allowEdit && options.permissions?.modifyAllRecords && !options.isLookup && options.enable_inline_edit != false;
|
|
6995
|
+
for (const field of fields) {
|
|
6996
|
+
//增加quickEdit属性,实现快速编辑
|
|
6997
|
+
const quickEditSchema = allowEdit ? await getQuickEditSchema(field, options) : allowEdit;
|
|
6998
|
+
if((field.is_name || field.name === options.labelFieldName) && options.objectName === 'cms_files'){
|
|
6999
|
+
const previewFileScript = `
|
|
7000
|
+
var data = event.data;
|
|
7001
|
+
var file_name = data.versions ? data.name : "${field.label}";
|
|
7002
|
+
var file_id = data._id;
|
|
7003
|
+
SteedosUI.previewFile && SteedosUI.previewFile({file_name, file_id});
|
|
7004
|
+
`;
|
|
7005
|
+
columns.push({
|
|
7006
|
+
"type": "button",
|
|
7007
|
+
"label": `<%=data.versions ? data.name : "${field.label}"%>`,
|
|
7008
|
+
"className": "whitespace-nowrap",
|
|
7009
|
+
"level": "link",
|
|
7010
|
+
"quickEdit": quickEditSchema,
|
|
7011
|
+
"onEvent": {
|
|
7012
|
+
"click": {
|
|
7013
|
+
"actions": [
|
|
7014
|
+
{
|
|
7015
|
+
"args": {
|
|
7016
|
+
"api": {
|
|
7017
|
+
"url": "${context.rootUrl}/api/files/files/${versions[0]}?download=true",
|
|
7018
|
+
"method": "get",
|
|
7019
|
+
"headers": {
|
|
7020
|
+
"Authorization": "Bearer ${context.tenantId},${context.authToken}"
|
|
7021
|
+
}
|
|
7022
|
+
}
|
|
7023
|
+
},
|
|
7024
|
+
"actionType": "download",
|
|
7025
|
+
"expression": "!!!window?.nw?.require"//浏览器上直接下载
|
|
7026
|
+
},
|
|
7027
|
+
{
|
|
7028
|
+
"args": {},
|
|
7029
|
+
"actionType": "custom",
|
|
7030
|
+
"script": previewFileScript,
|
|
7031
|
+
"expression": "!!window?.nw?.require" //PC客户端预览附件
|
|
7032
|
+
}
|
|
7033
|
+
]
|
|
7074
7034
|
}
|
|
7075
|
-
|
|
7076
|
-
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7087
|
-
|
|
7088
|
-
|
|
7089
|
-
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7093
|
-
|
|
7094
|
-
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
7035
|
+
}
|
|
7036
|
+
});
|
|
7037
|
+
}else if(field.type === 'toggle'){
|
|
7038
|
+
columns.push(Object.assign({}, {
|
|
7039
|
+
type: "switch",
|
|
7040
|
+
name: field.name,
|
|
7041
|
+
label: field.label,
|
|
7042
|
+
width: field.width,
|
|
7043
|
+
toggled: field.toggled,
|
|
7044
|
+
className:"whitespace-nowrap"
|
|
7045
|
+
}, field.amis, {name: field.name}));
|
|
7046
|
+
}else if(field.type === 'avatar' || field.type === 'image' || field.type === 'file'){
|
|
7047
|
+
columns.push(Object.assign({}, {
|
|
7048
|
+
type: "switch",
|
|
7049
|
+
name: field.name,
|
|
7050
|
+
label: field.label,
|
|
7051
|
+
width: field.width,
|
|
7052
|
+
toggled: field.toggled,
|
|
7053
|
+
quickEdit: quickEditSchema,
|
|
7054
|
+
className:"whitespace-nowrap",
|
|
7055
|
+
...getAmisFileReadonlySchema(field)
|
|
7056
|
+
}, field.amis, {name: field.name}));
|
|
7098
7057
|
}
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
adaptor: `
|
|
7113
|
-
if(payload.errors){
|
|
7114
|
-
payload.status = 2;
|
|
7115
|
-
payload.msg = window.t ? window.t(payload.errors[0].message) : payload.errors[0].message;
|
|
7116
|
-
}
|
|
7117
|
-
${options.apiAdaptor || ''}
|
|
7118
|
-
return payload;
|
|
7119
|
-
`,
|
|
7120
|
-
headers: {
|
|
7121
|
-
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
7058
|
+
else if(field.type === 'select'){
|
|
7059
|
+
const map = getSelectMap(field.options);
|
|
7060
|
+
columns.push(Object.assign({}, {
|
|
7061
|
+
type: "mapping",
|
|
7062
|
+
name: field.name,
|
|
7063
|
+
label: field.label,
|
|
7064
|
+
map: map,
|
|
7065
|
+
sortable: field.sortable,
|
|
7066
|
+
width: field.width,
|
|
7067
|
+
toggled: field.toggled,
|
|
7068
|
+
className:"whitespace-nowrap",
|
|
7069
|
+
quickEdit: quickEditSchema
|
|
7070
|
+
}, field.amis, {name: field.name}));
|
|
7122
7071
|
}
|
|
7123
|
-
|
|
7124
|
-
|
|
7125
|
-
|
|
7126
|
-
|
|
7127
|
-
|
|
7128
|
-
|
|
7129
|
-
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7137
|
-
|
|
7138
|
-
|
|
7139
|
-
|
|
7140
|
-
|
|
7141
|
-
|
|
7142
|
-
|
|
7143
|
-
|
|
7072
|
+
else {
|
|
7073
|
+
const tpl = await getFieldTpl(field, options);
|
|
7074
|
+
let type = 'text';
|
|
7075
|
+
if(tpl){
|
|
7076
|
+
type = 'tpl';
|
|
7077
|
+
}else if(field.type === 'html'){
|
|
7078
|
+
type = 'markdown';
|
|
7079
|
+
}else if(field.type === 'url' && field.show_as_qr){
|
|
7080
|
+
type = 'qr-code';
|
|
7081
|
+
}
|
|
7082
|
+
let className = "";
|
|
7083
|
+
if(field.type === 'textarea'){
|
|
7084
|
+
className = 'min-w-56';
|
|
7085
|
+
}
|
|
7086
|
+
if(field.wrap === false){
|
|
7087
|
+
className += " whitespace-nowrap";
|
|
7088
|
+
}
|
|
7089
|
+
if(!field.hidden && !field.extra){
|
|
7090
|
+
columns.push(Object.assign({}, {
|
|
7091
|
+
name: field.name,
|
|
7092
|
+
label: field.label,
|
|
7093
|
+
sortable: field.sortable,
|
|
7094
|
+
// searchable: field.searchable,
|
|
7095
|
+
width: field.width,
|
|
7096
|
+
type: type,
|
|
7097
|
+
tpl: tpl,
|
|
7098
|
+
toggled: field.toggled,
|
|
7099
|
+
className,
|
|
7100
|
+
quickEdit: quickEditSchema,
|
|
7101
|
+
options: field.type === 'html' ? {html: true} : null
|
|
7102
|
+
// toggled: true
|
|
7103
|
+
}, field.amis, {name: field.name}));
|
|
7104
|
+
}
|
|
7144
7105
|
}
|
|
7145
7106
|
}
|
|
7107
|
+
// columns.push(getOperation(fields));
|
|
7108
|
+
if(!___namespace.some(columns, { name: options.labelFieldName })){
|
|
7109
|
+
const href = Router.getObjectDetailPath({
|
|
7110
|
+
...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
|
|
7111
|
+
});
|
|
7112
|
+
columns[0].type = "tpl";
|
|
7113
|
+
columns[0].tpl = `<a href="${href}">\${${columns[0].name}}</a>`;
|
|
7114
|
+
}
|
|
7115
|
+
return columns;
|
|
7146
7116
|
}
|
|
7147
7117
|
|
|
7148
|
-
|
|
7149
|
-
*
|
|
7150
|
-
* @
|
|
7151
|
-
* @
|
|
7152
|
-
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
let isObjectField = /\w+\.\w+/.test(fieldName);
|
|
7165
|
-
if (field.type == 'grid' || field.type == 'object') {
|
|
7166
|
-
// field.group = field.label
|
|
7167
|
-
field.is_wide = true;
|
|
7168
|
-
}
|
|
7169
|
-
|
|
7170
|
-
if (!isObjectField){
|
|
7171
|
-
if(!field.hidden){
|
|
7172
|
-
fieldSchemaArray.push(Object.assign({name: fieldName}, field, {permission: {allowEdit: true}}));
|
|
7173
|
-
}
|
|
7118
|
+
/**
|
|
7119
|
+
* 生成移动端列表每行显示的amis行
|
|
7120
|
+
* @param {*} tpls 要显示的每个字段的tpl
|
|
7121
|
+
* @returns {
|
|
7122
|
+
"type": "wrapper",
|
|
7123
|
+
"body": [{
|
|
7124
|
+
"type": "tpl",
|
|
7125
|
+
"tpl": tpls[index].tpl,
|
|
7126
|
+
"className": "truncate"//左侧样式类
|
|
7127
|
+
},{
|
|
7128
|
+
"type": "tpl",
|
|
7129
|
+
"tpl": tpls[index + 1].tpl,
|
|
7130
|
+
"className": "truncate ml-2 flex flex-shrink-0"//右侧样式类
|
|
7131
|
+
}],
|
|
7132
|
+
"size": "none",
|
|
7133
|
+
"className": "flex items-center justify-between"//每行样式类
|
|
7174
7134
|
}
|
|
7175
|
-
|
|
7176
|
-
|
|
7177
|
-
|
|
7178
|
-
|
|
7179
|
-
|
|
7180
|
-
|
|
7181
|
-
|
|
7182
|
-
|
|
7183
|
-
|
|
7135
|
+
*/
|
|
7136
|
+
function getMobileLines(tpls){
|
|
7137
|
+
let lines = [];
|
|
7138
|
+
let maxLineCount = 2;
|
|
7139
|
+
let lineChildren = [];
|
|
7140
|
+
let isNewLine = false;
|
|
7141
|
+
let isLeft = true;
|
|
7142
|
+
let lineChildrenClassName = "";
|
|
7143
|
+
let lineClassName = "flex items-center justify-between h-[20px]";
|
|
7144
|
+
tpls.forEach(function(item){
|
|
7145
|
+
if(isNewLine && lines.length < maxLineCount){
|
|
7146
|
+
lines.push({
|
|
7147
|
+
"type": "wrapper",
|
|
7148
|
+
"body": lineChildren,
|
|
7149
|
+
"size": "none",
|
|
7150
|
+
"className": lineClassName
|
|
7151
|
+
});
|
|
7152
|
+
lineChildren = [];
|
|
7153
|
+
}
|
|
7154
|
+
if(isLeft){
|
|
7155
|
+
// 左侧半行
|
|
7156
|
+
lineChildrenClassName = "steedos-listview-item-left truncate";
|
|
7157
|
+
if(item.field.is_wide){
|
|
7158
|
+
// 左侧全行样式可以单独写
|
|
7159
|
+
lineChildrenClassName = "steedos-listview-item-wide truncate";
|
|
7160
|
+
}
|
|
7161
|
+
if(lines.length === 0){
|
|
7162
|
+
// 第一个字段加粗黑色显示
|
|
7163
|
+
lineChildrenClassName += " font-bold text-gray-800";
|
|
7164
|
+
}
|
|
7165
|
+
}
|
|
7166
|
+
else {
|
|
7167
|
+
// 右侧半行
|
|
7168
|
+
lineChildrenClassName = "steedos-listview-item-right truncate ml-2 flex flex-shrink-0";
|
|
7169
|
+
}
|
|
7170
|
+
lineChildren.push({
|
|
7171
|
+
"type": "tpl",
|
|
7172
|
+
"tpl": item.tpl,
|
|
7173
|
+
"className": lineChildrenClassName
|
|
7174
|
+
});
|
|
7184
7175
|
|
|
7185
|
-
|
|
7176
|
+
if(item.field.is_wide){
|
|
7177
|
+
// 宽字段占整行
|
|
7178
|
+
isLeft = true;
|
|
7179
|
+
isNewLine = true;
|
|
7180
|
+
}
|
|
7181
|
+
else {
|
|
7182
|
+
isLeft = !isLeft;
|
|
7183
|
+
isNewLine = isLeft;
|
|
7184
|
+
}
|
|
7185
|
+
});
|
|
7186
|
+
|
|
7187
|
+
if(lineChildren.length && lines.length < maxLineCount){
|
|
7188
|
+
lines.push({
|
|
7189
|
+
"type": "wrapper",
|
|
7190
|
+
"body": lineChildren,
|
|
7191
|
+
"size": "none",
|
|
7192
|
+
"className": lineClassName
|
|
7193
|
+
});
|
|
7194
|
+
}
|
|
7195
|
+
|
|
7196
|
+
return lines;
|
|
7197
|
+
}
|
|
7186
7198
|
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7199
|
+
async function getMobileTableColumns(fields, options){
|
|
7200
|
+
const columns = [];
|
|
7201
|
+
let nameField = {};
|
|
7202
|
+
let tpls = [];
|
|
7203
|
+
for (const field of fields) {
|
|
7204
|
+
let tpl = "";
|
|
7205
|
+
if(field.is_name || field.name === options.labelFieldName){
|
|
7206
|
+
nameField = field;
|
|
7207
|
+
options.onlyDisplayLabel = true;
|
|
7208
|
+
tpl = await getFieldTpl(field, options);
|
|
7209
|
+
}
|
|
7210
|
+
else if(field.type === 'avatar' || field.type === 'image' || field.type === 'file'){
|
|
7211
|
+
// 图片和附件类型字段暂时显示为附件名称,后续需要再优化
|
|
7212
|
+
tpl = `\${_display.${field.name}.name}`;
|
|
7213
|
+
}
|
|
7214
|
+
else {
|
|
7215
|
+
if(field.type === 'lookup' || field.type === 'master_detail'){
|
|
7216
|
+
options.onlyDisplayLabel = true;
|
|
7217
|
+
}
|
|
7218
|
+
tpl = await getFieldTpl(field, options);
|
|
7219
|
+
}
|
|
7220
|
+
if(!tpl){
|
|
7221
|
+
tpl = `\${${field.name}}`;
|
|
7222
|
+
}
|
|
7223
|
+
if(!field.hidden && !field.extra){
|
|
7224
|
+
tpls.push({ field, tpl });
|
|
7225
|
+
}
|
|
7226
|
+
}
|
|
7227
|
+
const url = getNameTplUrl(nameField, options);
|
|
7205
7228
|
|
|
7206
|
-
|
|
7207
|
-
const sectionFieldsVisibleOn = ___namespace.map(___namespace.compact(___namespace.map(fieldSetBody, 'visibleOn')) , (visibleOn)=>{
|
|
7208
|
-
return visibleOn;
|
|
7209
|
-
});
|
|
7210
|
-
const section = {
|
|
7211
|
-
"type": "fieldSet",
|
|
7212
|
-
"title": sectionName,
|
|
7213
|
-
"collapsable": true,
|
|
7214
|
-
"body": fieldSetBody,
|
|
7215
|
-
};
|
|
7216
|
-
if(sectionFieldsVisibleOn.length > 0 && fieldSetBody.length === sectionFieldsVisibleOn.length){
|
|
7217
|
-
section.visibleOn = `${sectionFieldsVisibleOn.join(" || ")}`;
|
|
7218
|
-
}
|
|
7219
|
-
return section
|
|
7220
|
-
};
|
|
7229
|
+
const columnLines = getMobileLines(tpls);
|
|
7221
7230
|
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
|
|
7232
|
-
|
|
7233
|
-
|
|
7231
|
+
|
|
7232
|
+
let column = {
|
|
7233
|
+
name: nameField.name,
|
|
7234
|
+
label: nameField.label,
|
|
7235
|
+
sortable: nameField.sortable,
|
|
7236
|
+
type: "button",
|
|
7237
|
+
level: "link",
|
|
7238
|
+
actionType: "link",
|
|
7239
|
+
link: url,
|
|
7240
|
+
innerClassName: "steedos-listview-item block text-gray-500",
|
|
7241
|
+
body: {
|
|
7242
|
+
"type": "wrapper",
|
|
7243
|
+
"body": columnLines,
|
|
7244
|
+
"size": "none",
|
|
7245
|
+
"className": "p-1"
|
|
7246
|
+
}
|
|
7247
|
+
};
|
|
7248
|
+
|
|
7249
|
+
if(options.objectName === 'cms_files'){
|
|
7250
|
+
if(window.Meteor?.isCordova){
|
|
7251
|
+
column = {
|
|
7252
|
+
...column,
|
|
7253
|
+
actionType: "",
|
|
7254
|
+
link: "",
|
|
7255
|
+
onEvent: {
|
|
7256
|
+
"click": {
|
|
7257
|
+
"actions": [
|
|
7258
|
+
{
|
|
7259
|
+
"script": `
|
|
7260
|
+
let cms_url = "/api/files/files/"+event.data.versions[0]+"?download=true"
|
|
7261
|
+
Steedos.cordovaDownload(encodeURI(Steedos.absoluteUrl(cms_url)), event.data.name);
|
|
7262
|
+
`,
|
|
7263
|
+
"actionType": "custom"
|
|
7264
|
+
}
|
|
7265
|
+
],
|
|
7266
|
+
"weight": 0
|
|
7267
|
+
}
|
|
7268
|
+
}
|
|
7269
|
+
};
|
|
7270
|
+
}else {
|
|
7271
|
+
column = {
|
|
7272
|
+
...column,
|
|
7273
|
+
actionType: "",
|
|
7274
|
+
link: "",
|
|
7275
|
+
onEvent: {
|
|
7276
|
+
"click": {
|
|
7277
|
+
"actions": [
|
|
7278
|
+
{
|
|
7279
|
+
"args": {
|
|
7280
|
+
"api": {
|
|
7281
|
+
"url": url,
|
|
7282
|
+
"method": "get",
|
|
7283
|
+
"headers": {
|
|
7284
|
+
"Authorization": "Bearer ${context.tenantId},${context.authToken}"
|
|
7285
|
+
}
|
|
7286
|
+
}
|
|
7287
|
+
},
|
|
7288
|
+
"actionType": "download"
|
|
7289
|
+
}
|
|
7290
|
+
],
|
|
7291
|
+
"weight": 0
|
|
7292
|
+
}
|
|
7293
|
+
}
|
|
7294
|
+
};
|
|
7295
|
+
}
|
|
7296
|
+
|
|
7234
7297
|
}
|
|
7235
|
-
}
|
|
7236
|
-
/*
|
|
7237
|
-
为了实现只有一个分组时隐藏该分组标题,需要分三种情况(分组如果没有visibleon属性就代表一定显示,有visibleon需要进行判断)
|
|
7238
|
-
1.所有分组中只有一个分组没有visibleon,还需要判断其他有visibleon的分组是否显示,只有其他都不显示时,才需要隐藏标题;反之,有任何一个显示,就不需要隐藏标题
|
|
7239
|
-
2.所有分组都有visibleon
|
|
7240
|
-
2.1 当前分组为隐藏时,标题就设置为隐藏
|
|
7241
|
-
2.2 当前分组为显示时,其他分组只要有一个是显示,就显示该分组标题
|
|
7242
|
-
2.3 当前分组为显示时,其他分组都隐藏,就隐藏该分组标题
|
|
7243
|
-
3.所有分组中有两个以上的分组没有visibleon(这种情况不用处理)
|
|
7244
|
-
*/
|
|
7245
|
-
if(ctx.mode == "edit"){
|
|
7246
|
-
if (sections.length - sectionHeaderVisibleOn.length == 1) {
|
|
7247
|
-
sections.forEach((section) => {
|
|
7248
|
-
section.headingClassName = {
|
|
7249
|
-
"hidden": `!(${sectionHeaderVisibleOn.join(" || ") || 'false'})`
|
|
7250
|
-
};
|
|
7251
|
-
});
|
|
7252
|
-
} else if (sections.length == sectionHeaderVisibleOn.length) {
|
|
7253
|
-
sections.forEach((section, index) => {
|
|
7254
|
-
var tempSectionHeaderVisibleOn = sectionHeaderVisibleOn.slice();
|
|
7255
|
-
tempSectionHeaderVisibleOn.splice(index, 1);
|
|
7256
|
-
section.headingClassName = {
|
|
7257
|
-
"hidden": `!((${tempSectionHeaderVisibleOn.join(" || ") || 'false'}) && ${sectionHeaderVisibleOn[index]})`
|
|
7258
|
-
};
|
|
7259
|
-
});
|
|
7260
|
-
}
|
|
7261
|
-
}
|
|
7262
|
-
|
|
7263
|
-
return sections;
|
|
7264
|
-
};
|
|
7265
7298
|
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
* @Date: 2022-07-07 11:02:29
|
|
7269
|
-
* @LastEditors: baozhoutao@steedos.com
|
|
7270
|
-
* @LastEditTime: 2023-03-07 17:19:34
|
|
7271
|
-
* @Description:
|
|
7272
|
-
*/
|
|
7299
|
+
columns.push(column);
|
|
7300
|
+
|
|
7273
7301
|
|
|
7274
|
-
|
|
7275
|
-
return await getSections(permissionFields, formFields, ctx);
|
|
7302
|
+
return columns;
|
|
7276
7303
|
}
|
|
7277
7304
|
|
|
7278
|
-
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
|
|
7282
|
-
_$1.toArray(args).reverse().forEach(item=> {
|
|
7283
|
-
_$1.mergeWith(output, item, (objectValue, sourceValue) => {
|
|
7284
|
-
return _$1.isArray(sourceValue) ? sourceValue : undefined;
|
|
7285
|
-
});
|
|
7286
|
-
});
|
|
7287
|
-
return output;
|
|
7288
|
-
};
|
|
7289
|
-
|
|
7290
|
-
function getBulkActions(objectSchema){
|
|
7291
|
-
return [
|
|
7292
|
-
{
|
|
7293
|
-
"type": "button",
|
|
7294
|
-
"level": "danger",
|
|
7295
|
-
"label": "批量删除",
|
|
7296
|
-
"actionType": "ajax",
|
|
7297
|
-
"confirmText": "确定要删除吗",
|
|
7298
|
-
"className": "hidden",
|
|
7299
|
-
"id": "batchDelete",
|
|
7300
|
-
"api": getBatchDelete(objectSchema.name),
|
|
7301
|
-
}
|
|
7302
|
-
// {
|
|
7303
|
-
// "label": "批量修改",
|
|
7304
|
-
// "actionType": "dialog",
|
|
7305
|
-
// "dialog": {
|
|
7306
|
-
// "title": "批量编辑",
|
|
7307
|
-
// "name": "sample-bulk-edit",
|
|
7308
|
-
// "body": {
|
|
7309
|
-
// "type": "form",
|
|
7310
|
-
// "api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/bulkUpdate2",
|
|
7311
|
-
// "controls": [
|
|
7312
|
-
// {
|
|
7313
|
-
// "type": "hidden",
|
|
7314
|
-
// "name": "ids"
|
|
7315
|
-
// },
|
|
7316
|
-
// {
|
|
7317
|
-
// "type": "text",
|
|
7318
|
-
// "name": "name",
|
|
7319
|
-
// "label": "Name"
|
|
7320
|
-
// }
|
|
7321
|
-
// ]
|
|
7322
|
-
// }
|
|
7323
|
-
// }
|
|
7324
|
-
// }
|
|
7325
|
-
]
|
|
7305
|
+
function getDefaultParams(options){
|
|
7306
|
+
return {
|
|
7307
|
+
perPage: options.top || options.perPage || config.listView.perPage
|
|
7308
|
+
}
|
|
7326
7309
|
}
|
|
7327
7310
|
|
|
7328
|
-
|
|
7329
|
-
|
|
7330
|
-
const { top, perPage, showDisplayAs = false, displayAs, crudClassName = "" } = options;
|
|
7331
|
-
const nonpaged = objectSchema.paging && objectSchema.paging.enabled === false;
|
|
7332
|
-
const isTreeObject = objectSchema.enable_tree;
|
|
7333
|
-
const bulkActions = getBulkActions(objectSchema);
|
|
7334
|
-
const bodyProps = {
|
|
7335
|
-
// toolbar: getToolbar(),
|
|
7336
|
-
// headerToolbar: getObjectHeaderToolbar(objectSchema, options.formFactor, {showDisplayAs}),
|
|
7337
|
-
headerToolbarClassName: "px-4 py-2 border-gray-300 bg-gray-100 border-solid border-b",
|
|
7338
|
-
footerToolbar: getObjectFooterToolbar(objectSchema, options.formFactor, {
|
|
7339
|
-
disableStatistics: options.queryCount === false
|
|
7340
|
-
}),
|
|
7341
|
-
filter: options.filterVisible !== false && await getObjectFilter(objectSchema, fields, options),
|
|
7342
|
-
};
|
|
7343
|
-
if(options.formFactor !== 'SMALL' || ["split"].indexOf(options.displayAs) == -1){
|
|
7344
|
-
Object.assign(bodyProps, {
|
|
7345
|
-
bulkActions: options.bulkActions != false ? bulkActions : false
|
|
7346
|
-
});
|
|
7347
|
-
}
|
|
7348
|
-
// yml里配置的 不分页和enable_tree:true 优先级最高,组件中输入的top次之。
|
|
7349
|
-
options.queryCount = true;
|
|
7350
|
-
if(nonpaged || isTreeObject){
|
|
7351
|
-
options.top = 50000;
|
|
7352
|
-
bodyProps.footerToolbar = [];
|
|
7353
|
-
options.queryCount = true; // 禁止翻页的时候, 需要查找总数
|
|
7354
|
-
}else if(top){
|
|
7355
|
-
bodyProps.footerToolbar = [];
|
|
7356
|
-
if(options.isRelated){
|
|
7357
|
-
options.queryCount = true;
|
|
7358
|
-
}else {
|
|
7359
|
-
options.queryCount = false;
|
|
7360
|
-
}
|
|
7361
|
-
}
|
|
7362
|
-
// console.log(`getObjectHeaderToolbar====2===>`, options.filterVisible)
|
|
7363
|
-
bodyProps.headerToolbar = getObjectHeaderToolbar(objectSchema, options.formFactor, {
|
|
7364
|
-
showDisplayAs,
|
|
7365
|
-
hiddenCount: options.queryCount === false,
|
|
7366
|
-
headerToolbarItems: options.headerToolbarItems,
|
|
7367
|
-
filterVisible: options.filterVisible
|
|
7368
|
-
});
|
|
7311
|
+
function getButtonVisibleOn(button){
|
|
7312
|
+
let visible= button.visible;
|
|
7369
7313
|
|
|
7314
|
+
if(button._visible){
|
|
7315
|
+
visible = button._visible;
|
|
7316
|
+
}
|
|
7370
7317
|
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
delete bodyProps.bulkActions;
|
|
7375
|
-
delete bodyProps.headerToolbar;
|
|
7376
|
-
delete bodyProps.footerToolbar;
|
|
7377
|
-
const card = await getCardSchema(fields, Object.assign({idFieldName: objectSchema.idFieldName, labelFieldName: objectSchema.NAME_FIELD_KEY || 'name'}, options, {actions: false}));
|
|
7378
|
-
body = Object.assign({}, card , {
|
|
7379
|
-
type: 'crud',
|
|
7380
|
-
primaryField: '_id',
|
|
7381
|
-
id: id,
|
|
7382
|
-
name: id,
|
|
7383
|
-
keepItemSelectionOnPageChange: false,
|
|
7384
|
-
api: await getTableApi(objectSchema, fields, options),
|
|
7385
|
-
hiddenOn: options.tableHiddenOn,
|
|
7386
|
-
},
|
|
7387
|
-
bodyProps
|
|
7388
|
-
);
|
|
7389
|
-
}else {
|
|
7390
|
-
let labelFieldName = objectSchema.NAME_FIELD_KEY || 'name';
|
|
7391
|
-
// organizations 对象的历史遗留问题, fullname 被标记为了 名称字段. 在此处特殊处理.
|
|
7392
|
-
if(objectSchema.name === 'organizations'){
|
|
7393
|
-
labelFieldName = 'name';
|
|
7394
|
-
}
|
|
7395
|
-
const table = await getTableSchema$1(fields, Object.assign({idFieldName: objectSchema.idFieldName, labelFieldName: labelFieldName}, options));
|
|
7396
|
-
delete table.mode;
|
|
7318
|
+
if(_$1.isBoolean(visible)){
|
|
7319
|
+
visible = visible.toString();
|
|
7320
|
+
}
|
|
7397
7321
|
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
|
|
7404
|
-
|
|
7405
|
-
|
|
7406
|
-
|
|
7407
|
-
autoFillHeight: options.isRelated ? false : true,
|
|
7408
|
-
className: `flex-auto ${crudClassName || ""}`,
|
|
7409
|
-
bodyClassName: "bg-white",
|
|
7410
|
-
crudClassName: crudClassName,
|
|
7411
|
-
},
|
|
7412
|
-
bodyProps,
|
|
7413
|
-
);
|
|
7322
|
+
if(visible){
|
|
7323
|
+
// if(visible.indexOf("Meteor.") > 0 || visible.indexOf("Creator.") > 0 || visible.indexOf("Session.") > 0){
|
|
7324
|
+
// console.warn('无效的visible', visible)
|
|
7325
|
+
// return 'false';
|
|
7326
|
+
// }
|
|
7327
|
+
if(visible.trim().startsWith('function')){
|
|
7328
|
+
return `${visible}(objectName, typeof _id === 'undefined' ? null: _id, typeof record === 'undefined' ? (typeof recordPermissions === 'undefined' ? {} : recordPermissions) : record.recordPermissions, data)`
|
|
7329
|
+
}
|
|
7330
|
+
return visible;
|
|
7414
7331
|
}
|
|
7415
7332
|
|
|
7416
|
-
|
|
7417
|
-
|
|
7418
|
-
|
|
7419
|
-
|
|
7420
|
-
|
|
7421
|
-
const footerSchema = defaults.footerSchema;
|
|
7422
|
-
if (headerSchema || footerSchema) {
|
|
7423
|
-
let wrappedBody = [body];
|
|
7424
|
-
if (headerSchema) {
|
|
7425
|
-
if(___default["default"].isArray(headerSchema)){
|
|
7426
|
-
wrappedBody = ___default["default"].union(headerSchema,wrappedBody);
|
|
7427
|
-
}
|
|
7428
|
-
else {
|
|
7429
|
-
wrappedBody.unshift(headerSchema);
|
|
7430
|
-
}
|
|
7333
|
+
if(button.type === 'amis_button'){
|
|
7334
|
+
const amisSchema = button.amis_schema;
|
|
7335
|
+
if(amisSchema && amisSchema.body && amisSchema.body.length > 0){
|
|
7336
|
+
const btn1 = amisSchema.body[0];
|
|
7337
|
+
return btn1.visibleOn
|
|
7431
7338
|
}
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
|
|
7437
|
-
|
|
7438
|
-
|
|
7339
|
+
}
|
|
7340
|
+
}
|
|
7341
|
+
|
|
7342
|
+
async function getTableOperation(ctx){
|
|
7343
|
+
const buttons = ctx.buttons;
|
|
7344
|
+
const operationButtons = [];
|
|
7345
|
+
_$1.each(buttons, (button)=>{
|
|
7346
|
+
if(_$1.isBoolean(button.visible)){
|
|
7347
|
+
button.visible = button.visible.toString();
|
|
7439
7348
|
}
|
|
7440
|
-
|
|
7441
|
-
|
|
7349
|
+
// operationButtons.push({
|
|
7350
|
+
// type: 'button',
|
|
7351
|
+
// label: button.label,
|
|
7352
|
+
// visibleOn: button.visible ? `${button.visible}` : (button._visible ? `${button._visible}` : null),
|
|
7353
|
+
// onEvent: {
|
|
7354
|
+
// click: {
|
|
7355
|
+
// actions: []
|
|
7356
|
+
// }
|
|
7357
|
+
// }
|
|
7358
|
+
// })
|
|
7359
|
+
|
|
7360
|
+
operationButtons.push({
|
|
7361
|
+
type: 'steedos-object-button',
|
|
7362
|
+
name: button.name,
|
|
7363
|
+
objectName: button.objectName,
|
|
7364
|
+
visibleOn: getButtonVisibleOn(button),
|
|
7365
|
+
className: 'antd-Button--default'
|
|
7366
|
+
});
|
|
7367
|
+
});
|
|
7368
|
+
if(operationButtons.length < 1){
|
|
7369
|
+
return ;
|
|
7442
7370
|
}
|
|
7443
|
-
// console.timeEnd('getObjectCRUD');
|
|
7444
|
-
// TODO: data应该只留loaded,其他属性都改为从上层传递下来
|
|
7445
7371
|
return {
|
|
7446
|
-
|
|
7447
|
-
|
|
7448
|
-
|
|
7449
|
-
|
|
7450
|
-
|
|
7451
|
-
|
|
7452
|
-
|
|
7453
|
-
|
|
7454
|
-
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7372
|
+
type: 'operation',
|
|
7373
|
+
label: '操作',
|
|
7374
|
+
fixed: 'right',
|
|
7375
|
+
labelClassName: 'text-center',
|
|
7376
|
+
className: 'text-center steedos-listview-operation w-20',
|
|
7377
|
+
buttons: [
|
|
7378
|
+
{
|
|
7379
|
+
"type": "steedos-dropdown-button",
|
|
7380
|
+
"label": "xxx",
|
|
7381
|
+
"buttons": operationButtons,
|
|
7382
|
+
"placement": "bottomRight",
|
|
7383
|
+
"overlayClassName": "shadow !min-w-[160px]",
|
|
7384
|
+
"trigger": ["click"],
|
|
7385
|
+
"id": "u:c2140a365019",
|
|
7386
|
+
onOpenApi: {
|
|
7387
|
+
url: `\${context.rootUrl}/service/api/@\${objectName}/recordPermissions/\${_id}`,
|
|
7388
|
+
method: "get",
|
|
7389
|
+
data: {
|
|
7390
|
+
$: "$$",
|
|
7391
|
+
objectName: "${objectName}",
|
|
7392
|
+
listViewId: "${listViewId}",
|
|
7393
|
+
appId: "${appId}",
|
|
7394
|
+
formFactor: "${formFactor}",
|
|
7395
|
+
context: `\${context}`
|
|
7396
|
+
},
|
|
7397
|
+
headers: {
|
|
7398
|
+
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
7399
|
+
},
|
|
7400
|
+
adaptor: `
|
|
7401
|
+
payload = {
|
|
7402
|
+
record: {
|
|
7403
|
+
recordPermissions: payload
|
|
7404
|
+
}
|
|
7405
|
+
};
|
|
7406
|
+
return payload;
|
|
7407
|
+
`,
|
|
7408
|
+
}
|
|
7409
|
+
}
|
|
7410
|
+
]
|
|
7458
7411
|
}
|
|
7459
7412
|
}
|
|
7460
7413
|
|
|
7461
|
-
|
|
7462
|
-
|
|
7463
|
-
|
|
7464
|
-
};
|
|
7465
|
-
|
|
7466
|
-
const getFormFields = (objectSchema, formProps)=>{
|
|
7467
|
-
/**
|
|
7468
|
-
* fieldsExtend: 重写字段定义
|
|
7469
|
-
* fields: 包含的字段
|
|
7470
|
-
* excludedFields: 排除的字段
|
|
7471
|
-
*/
|
|
7472
|
-
const { fieldsExtend, fields: includedFields, excludedFields } = formProps;
|
|
7473
|
-
|
|
7474
|
-
let fields = {};
|
|
7475
|
-
// 以uiSchema fields 为基础, 遍历字段, 并更新字段定义
|
|
7476
|
-
___default["default"].forEach(objectSchema.fields, (field, fieldName)=>{
|
|
7477
|
-
if(!lodash.has(field, "name")){
|
|
7478
|
-
field.name = fieldName;
|
|
7414
|
+
async function getTableSchema$1(fields, options){
|
|
7415
|
+
if(!options){
|
|
7416
|
+
options = {};
|
|
7479
7417
|
}
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
fields[field.name] = field;
|
|
7418
|
+
let columns = [];
|
|
7419
|
+
if(options.formFactor === 'SMALL' || ["split"].indexOf(options.displayAs) > -1){
|
|
7420
|
+
columns = await getMobileTableColumns(fields, options);
|
|
7484
7421
|
}
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
const includedFieldsMap = {};
|
|
7489
|
-
___default["default"].each(includedFields, (fName, index)=>{
|
|
7490
|
-
if(fields[fName]){
|
|
7491
|
-
includedFieldsMap[fName] = Object.assign({}, fields[fName], {sort_no: index});
|
|
7492
|
-
}
|
|
7493
|
-
});
|
|
7494
|
-
fields = includedFieldsMap;
|
|
7495
|
-
}
|
|
7496
|
-
|
|
7497
|
-
if(!___default["default"].isEmpty(excludedFields) && ___default["default"].isArray(excludedFields)){
|
|
7498
|
-
___default["default"].each(excludedFields, (fName)=>{
|
|
7499
|
-
delete fields[fName];
|
|
7500
|
-
});
|
|
7501
|
-
}
|
|
7502
|
-
|
|
7503
|
-
return lodash.sortBy(___default["default"].values(fields), "sort_no");
|
|
7504
|
-
};
|
|
7505
|
-
|
|
7506
|
-
async function getObjectForm(objectSchema, ctx){
|
|
7507
|
-
const { recordId, formFactor, layout = formFactor === 'SMALL' ? 'normal' : "normal", labelAlign, tabId, appId, defaults } = ctx;
|
|
7508
|
-
const fields = ___default["default"].values(objectSchema.fields);
|
|
7509
|
-
const formFields = getFormFields(objectSchema, ctx);
|
|
7510
|
-
const formSchema = defaults && defaults.formSchema || {};
|
|
7511
|
-
if(___default["default"].has(formSchema, 'className')){
|
|
7512
|
-
formSchema.className = 'steedos-amis-form';
|
|
7422
|
+
else {
|
|
7423
|
+
columns = await getTableColumns(fields, options);
|
|
7424
|
+
columns.push(await getTableOperation(options));
|
|
7513
7425
|
}
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
7518
|
-
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
data: {
|
|
7529
|
-
"&": "${initialValues}"
|
|
7530
|
-
},
|
|
7531
|
-
labelAlign,
|
|
7532
|
-
persistData: false,
|
|
7533
|
-
resetAfterSubmit: true,
|
|
7534
|
-
preventEnterSubmit: true,
|
|
7535
|
-
promptPageLeave: true,
|
|
7536
|
-
canAccessSuperData: false,
|
|
7537
|
-
name: `form_edit_${recordId}`,
|
|
7538
|
-
debug: false,
|
|
7539
|
-
title: "",
|
|
7540
|
-
submitText: "", // amis 表单不显示提交按钮, 表单提交由项目代码接管
|
|
7541
|
-
api: await getSaveApi(objectSchema, recordId, fields, ctx),
|
|
7542
|
-
initFetch: recordId != 'new',
|
|
7543
|
-
body: await getFormBody(fields, formFields, ctx),
|
|
7544
|
-
panelClassName:'m-0 sm:rounded-lg shadow-none border-none',
|
|
7545
|
-
bodyClassName: 'p-0',
|
|
7546
|
-
className: 'steedos-amis-form',
|
|
7547
|
-
hiddenOn: "${editFormInited != true}",
|
|
7548
|
-
onEvent: {
|
|
7549
|
-
"submitSucc": {
|
|
7550
|
-
"weight": 0,
|
|
7551
|
-
"actions": [
|
|
7552
|
-
{
|
|
7553
|
-
"actionType": "broadcast",
|
|
7554
|
-
"args": {
|
|
7555
|
-
"eventName": `@data.changed.${objectSchema.name}`
|
|
7556
|
-
},
|
|
7557
|
-
"data": {
|
|
7558
|
-
"objectName": `${objectSchema.name}`,
|
|
7559
|
-
"displayAs": "${displayAs}"
|
|
7560
|
-
}
|
|
7561
|
-
},
|
|
7562
|
-
{
|
|
7563
|
-
"actionType": "broadcast",
|
|
7564
|
-
"args": {
|
|
7565
|
-
"eventName": "@data.changed.${_master.objectName}"
|
|
7566
|
-
},
|
|
7567
|
-
"data": {
|
|
7568
|
-
"objectName": "${_master.objectName}",
|
|
7569
|
-
"_isRelated": "${_isRelated || _master._isRelated}"
|
|
7570
|
-
},
|
|
7571
|
-
"expression": `\${_master.objectName != '${objectSchema.name}' && _master.objectName}`
|
|
7572
|
-
},
|
|
7573
|
-
// {
|
|
7574
|
-
// "actionType": "custom",
|
|
7575
|
-
// "script": "debugger;"
|
|
7576
|
-
// },
|
|
7577
|
-
// {
|
|
7578
|
-
// "args": {},
|
|
7579
|
-
// "actionType": "closeDialog"
|
|
7580
|
-
// }
|
|
7581
|
-
]
|
|
7582
|
-
}
|
|
7583
|
-
}
|
|
7584
|
-
})]
|
|
7585
|
-
};
|
|
7586
|
-
if(formSchema.id){
|
|
7587
|
-
amisSchema.id = `service-${formSchema.id}`;
|
|
7426
|
+
return {
|
|
7427
|
+
mode: "table",
|
|
7428
|
+
name: "thelist",
|
|
7429
|
+
headerToolbarClassName: "py-2 px-2 border-gray-300 bg-gray-100 border-solid border-b",
|
|
7430
|
+
className: "",
|
|
7431
|
+
draggable: false,
|
|
7432
|
+
defaultParams: getDefaultParams(options),
|
|
7433
|
+
columns: columns,
|
|
7434
|
+
syncLocation: false,
|
|
7435
|
+
keepItemSelectionOnPageChange: true,
|
|
7436
|
+
checkOnItemClick: false,
|
|
7437
|
+
labelTpl: `\${${options.labelFieldName}}`,
|
|
7438
|
+
autoFillHeight: false, // 自动高度效果不理想,先关闭
|
|
7439
|
+
columnsTogglable: false,
|
|
7588
7440
|
}
|
|
7589
|
-
return amisSchema;
|
|
7590
7441
|
}
|
|
7591
7442
|
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
7600
|
-
|
|
7601
|
-
|
|
7602
|
-
|
|
7603
|
-
|
|
7604
|
-
|
|
7605
|
-
|
|
7606
|
-
|
|
7607
|
-
|
|
7608
|
-
|
|
7609
|
-
|
|
7610
|
-
|
|
7611
|
-
labelAlign,
|
|
7612
|
-
persistData: false,
|
|
7613
|
-
promptPageLeave: false,
|
|
7614
|
-
name: `form_readonly_${recordId}`,
|
|
7615
|
-
debug: false,
|
|
7616
|
-
title: "",
|
|
7617
|
-
data: {
|
|
7618
|
-
"formData": "$$"
|
|
7619
|
-
},
|
|
7620
|
-
wrapWithPanel: false,
|
|
7621
|
-
body: await getFormBody(_$1.map(fields, (field)=>{field.readonly = true; return field;}), _$1.map(formFields, (field)=>{field.readonly = true; return field;}), Object.assign({}, ctx, {showSystemFields: true})),
|
|
7622
|
-
className: 'steedos-amis-form bg-white',
|
|
7623
|
-
actions: [], // 不显示表单默认的提交按钮
|
|
7624
|
-
onEvent: {
|
|
7625
|
-
[`@data.changed.${objectSchema.name}`]: { // 由于amis service 组件的 onEvent 存在bug ,此处借助form来刷新 上层 service https://github.com/baidu/amis/issues/6294
|
|
7626
|
-
"actions": [
|
|
7627
|
-
{
|
|
7628
|
-
"actionType": "reload",
|
|
7629
|
-
"componentId": serviceId,
|
|
7630
|
-
"expression": "this.__deletedRecord != true"
|
|
7631
|
-
},
|
|
7632
|
-
{
|
|
7633
|
-
// "args": {
|
|
7634
|
-
// "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
|
|
7635
|
-
// "blank": false
|
|
7636
|
-
// },
|
|
7637
|
-
"actionType": "custom",
|
|
7638
|
-
"script": "Steedos.goBack()",
|
|
7639
|
-
"expression": "this.__deletedRecord === true"
|
|
7640
|
-
}
|
|
7641
|
-
]
|
|
7642
|
-
}
|
|
7643
|
-
}
|
|
7644
|
-
},
|
|
7645
|
-
}
|
|
7646
|
-
],
|
|
7647
|
-
onEvent: {
|
|
7648
|
-
"fetchInited": {
|
|
7649
|
-
"weight": 0,
|
|
7650
|
-
"actions": [
|
|
7651
|
-
{
|
|
7652
|
-
actionType: 'broadcast',
|
|
7653
|
-
eventName: "recordLoaded",
|
|
7654
|
-
args: {
|
|
7655
|
-
eventName: "recordLoaded"
|
|
7656
|
-
},
|
|
7657
|
-
data: {
|
|
7658
|
-
objectName: "${event.data.__objectName}",
|
|
7659
|
-
record: "${event.data.__record}"
|
|
7660
|
-
},
|
|
7661
|
-
expression: "${event.data.__response.error != true}"
|
|
7662
|
-
},
|
|
7663
|
-
{
|
|
7664
|
-
"actionType": "setValue",
|
|
7665
|
-
"args": {
|
|
7666
|
-
value: {
|
|
7667
|
-
"recordLoaded": true,
|
|
7668
|
-
}
|
|
7669
|
-
},
|
|
7670
|
-
expression: "${event.data.__response.error != true}"
|
|
7443
|
+
|
|
7444
|
+
|
|
7445
|
+
/**
|
|
7446
|
+
*
|
|
7447
|
+
* @param {*} mainObject
|
|
7448
|
+
* @param {*} fields
|
|
7449
|
+
* @param {*} options = {filter: listview 过滤条件, ...}
|
|
7450
|
+
* @returns
|
|
7451
|
+
*/
|
|
7452
|
+
async function getTableApi(mainObject, fields, options){
|
|
7453
|
+
const searchableFields = [];
|
|
7454
|
+
let { filter, filtersFunction, sort, top, setDataToComponentId = '' } = options;
|
|
7455
|
+
|
|
7456
|
+
if(___namespace.isArray(filter)){
|
|
7457
|
+
filter = ___namespace.map(filter, function(item){
|
|
7458
|
+
if(item.operation){
|
|
7459
|
+
return [item.field, item.operation, item.value];
|
|
7460
|
+
}else {
|
|
7461
|
+
return item
|
|
7671
7462
|
}
|
|
7672
|
-
|
|
7673
|
-
}
|
|
7674
|
-
}
|
|
7463
|
+
});
|
|
7675
7464
|
}
|
|
7676
|
-
|
|
7465
|
+
if(!filter){
|
|
7466
|
+
filter = [];
|
|
7467
|
+
}
|
|
7468
|
+
let baseFilters = null;
|
|
7469
|
+
if(filter){
|
|
7470
|
+
baseFilters = filter;
|
|
7471
|
+
}
|
|
7472
|
+
___namespace.each(fields,function(field){
|
|
7473
|
+
if(field.searchable){
|
|
7474
|
+
searchableFields.push(field.name);
|
|
7475
|
+
}
|
|
7476
|
+
});
|
|
7677
7477
|
|
|
7678
|
-
|
|
7679
|
-
|
|
7680
|
-
|
|
7681
|
-
|
|
7682
|
-
|
|
7683
|
-
|
|
7684
|
-
|
|
7685
|
-
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7478
|
+
const fileFields = {};
|
|
7479
|
+
const fileFieldsKeys = [];
|
|
7480
|
+
// 含有optionsFunction属性, 无reference_to属性的lookup字段
|
|
7481
|
+
const lookupFields = {};
|
|
7482
|
+
fields.forEach((item)=>{
|
|
7483
|
+
if(___namespace.includes(['image','avatar','file'], item.type)){
|
|
7484
|
+
fileFieldsKeys.push(item.name);
|
|
7485
|
+
fileFields[item.name] = {
|
|
7486
|
+
name: item.name,
|
|
7487
|
+
type: item.type,
|
|
7488
|
+
multiple: item.multiple
|
|
7489
|
+
};
|
|
7490
|
+
}
|
|
7491
|
+
if(___namespace.includes(['lookup'], item.type) && !item.reference_to ){
|
|
7492
|
+
lookupFields[item.name] = item;
|
|
7493
|
+
}
|
|
7494
|
+
});
|
|
7495
|
+
|
|
7496
|
+
let valueField = mainObject.key_field || '_id';
|
|
7497
|
+
const api = await getApi(mainObject, null, fields, {count: options.queryCount, alias: 'rows', limit: top, queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"`});
|
|
7498
|
+
|
|
7499
|
+
if(options.isRelated){
|
|
7500
|
+
api.url += "&recordId=${_master.recordId}";
|
|
7690
7501
|
}
|
|
7691
|
-
};
|
|
7692
7502
|
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
|
|
7697
|
-
|
|
7698
|
-
|
|
7699
|
-
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
|
|
7711
|
-
|
|
7712
|
-
|
|
7713
|
-
|
|
7714
|
-
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
|
|
7719
|
-
|
|
7720
|
-
|
|
7721
|
-
|
|
7722
|
-
|
|
7723
|
-
|
|
7724
|
-
|
|
7725
|
-
|
|
7726
|
-
|
|
7727
|
-
|
|
7728
|
-
|
|
7729
|
-
|
|
7730
|
-
|
|
7503
|
+
api.data.$term = "$term";
|
|
7504
|
+
api.data.term = "$term";
|
|
7505
|
+
api.data.$self = "$$";
|
|
7506
|
+
api.data.self = "$$";
|
|
7507
|
+
api.data.filter = "$filter";
|
|
7508
|
+
api.data.loaded = "${loaded}";
|
|
7509
|
+
api.data.listViewId = "${listViewId}";
|
|
7510
|
+
api.data.listName = "${listName}";
|
|
7511
|
+
api.requestAdaptor = `
|
|
7512
|
+
// selfData 中的数据由 CRUD 控制. selfData中,只能获取到 CRUD 给定的data. 无法从数据链中获取数据.
|
|
7513
|
+
let selfData = JSON.parse(JSON.stringify(api.data.$self));
|
|
7514
|
+
// 保留一份初始data,以供自定义发送适配器中获取原始数据。
|
|
7515
|
+
const data = _.cloneDeep(api.data);
|
|
7516
|
+
try{
|
|
7517
|
+
// TODO: 不应该直接在这里取localStorage,应该从外面传入
|
|
7518
|
+
const listViewId = api.data.listViewId;
|
|
7519
|
+
const listViewPropsStoreKey = location.pathname + "/crud/" + listViewId ;
|
|
7520
|
+
let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
|
|
7521
|
+
if(localListViewProps){
|
|
7522
|
+
localListViewProps = JSON.parse(localListViewProps);
|
|
7523
|
+
selfData = Object.assign({}, localListViewProps, selfData);
|
|
7524
|
+
if(!api.data.filter){
|
|
7525
|
+
api.data.filter = localListViewProps.filter;
|
|
7526
|
+
}
|
|
7527
|
+
if(!api.data.loaded){
|
|
7528
|
+
// 第一次加载组件,比如刷新浏览器时因为api.data.pageNo有默认值1
|
|
7529
|
+
// 所以会把localSearchableFilter中已经存过的页码覆盖
|
|
7530
|
+
// 如果是第一次加载组件始终让翻页页码从本地存储中取值
|
|
7531
|
+
let formFactor = "${options.formFactor}";
|
|
7532
|
+
// 移动端不识别本地存储中的翻页页码,否则点击加载更多按钮后无法刷新回第一页
|
|
7533
|
+
api.data.pageNo = formFactor === "SMALL" ? 1 : (localListViewProps.page || 1);
|
|
7534
|
+
}
|
|
7535
|
+
}
|
|
7536
|
+
}
|
|
7537
|
+
catch(ex){
|
|
7538
|
+
console.error("本地存储中crud参数解析异常:", ex);
|
|
7539
|
+
}
|
|
7540
|
+
${baseFilters ? `var systemFilters = ${JSON.stringify(baseFilters)};` : 'var systemFilters = [];'}
|
|
7541
|
+
var _ids = []
|
|
7542
|
+
const filtersFunction = ${filtersFunction};
|
|
7543
|
+
if(filtersFunction){
|
|
7544
|
+
const _filters = filtersFunction(systemFilters, api.data.$self);
|
|
7545
|
+
if(api.data.listName == "recent"){
|
|
7546
|
+
_ids = _filters[2]
|
|
7547
|
+
}
|
|
7548
|
+
if(_filters && _filters.length > 0){
|
|
7549
|
+
if(_.isEmpty(systemFilters)){
|
|
7550
|
+
systemFilters = _filters || [];
|
|
7551
|
+
}else{
|
|
7552
|
+
systemFilters = [systemFilters, 'and', _filters];
|
|
7553
|
+
}
|
|
7554
|
+
}
|
|
7555
|
+
}
|
|
7556
|
+
let userFilters =[];
|
|
7557
|
+
|
|
7558
|
+
if(_.isEmpty(systemFilters)){
|
|
7559
|
+
systemFilters = api.data.filter || [];
|
|
7560
|
+
}else{
|
|
7561
|
+
if(!_.isEmpty(api.data.filter)){
|
|
7562
|
+
systemFilters = [systemFilters, 'and', api.data.filter];
|
|
7563
|
+
}
|
|
7564
|
+
}
|
|
7565
|
+
var pageSize = api.data.pageSize || 10;
|
|
7566
|
+
var pageNo = api.data.pageNo || 1;
|
|
7567
|
+
var skip = (pageNo - 1) * pageSize;
|
|
7568
|
+
var orderBy = api.data.orderBy || '';
|
|
7569
|
+
var orderDir = api.data.orderDir || '';
|
|
7570
|
+
var sort = orderBy + ' ' + orderDir;
|
|
7571
|
+
sort = orderBy ? sort : "${sort || ''}";
|
|
7572
|
+
var allowSearchFields = ${JSON.stringify(searchableFields)};
|
|
7573
|
+
if(api.data.$term){
|
|
7574
|
+
userFilters = [["name", "contains", "'+ api.data.$term +'"]];
|
|
7575
|
+
}else if(selfData.op === 'loadOptions' && selfData.value){
|
|
7576
|
+
userFilters = [["${valueField.name}", "=", selfData.value]];
|
|
7577
|
+
}
|
|
7578
|
+
|
|
7579
|
+
var searchableFilter = SteedosUI.getSearchFilter(selfData) || [];
|
|
7580
|
+
|
|
7581
|
+
if(searchableFilter.length > 0){
|
|
7582
|
+
if(userFilters.length > 0 ){
|
|
7583
|
+
userFilters = [userFilters, 'and', searchableFilter];
|
|
7584
|
+
}else{
|
|
7585
|
+
userFilters = searchableFilter;
|
|
7586
|
+
}
|
|
7587
|
+
}
|
|
7588
|
+
|
|
7589
|
+
if(allowSearchFields){
|
|
7590
|
+
allowSearchFields.forEach(function(key){
|
|
7591
|
+
const keyValue = selfData[key];
|
|
7592
|
+
if(_.isString(keyValue)){
|
|
7593
|
+
userFilters.push([key, "contains", keyValue]);
|
|
7594
|
+
}else if(_.isArray(keyValue) || _.isBoolean(keyValue) || keyValue){
|
|
7595
|
+
userFilters.push([key, "=", keyValue]);
|
|
7596
|
+
}
|
|
7597
|
+
})
|
|
7598
|
+
}
|
|
7599
|
+
|
|
7600
|
+
if(selfData.__keywords && allowSearchFields){
|
|
7601
|
+
const keywordsFilters = [];
|
|
7602
|
+
allowSearchFields.forEach(function(key, index){
|
|
7603
|
+
const keyValue = selfData.__keywords;
|
|
7604
|
+
if(keyValue){
|
|
7605
|
+
keywordsFilters.push([key, "contains", keyValue]);
|
|
7606
|
+
if(index < allowSearchFields.length - 1){
|
|
7607
|
+
keywordsFilters.push('or');
|
|
7731
7608
|
}
|
|
7732
|
-
|
|
7733
|
-
|
|
7734
|
-
|
|
7735
|
-
|
|
7736
|
-
type: "switch",
|
|
7737
|
-
name: field.name,
|
|
7738
|
-
label: field.label,
|
|
7739
|
-
width: field.width,
|
|
7740
|
-
toggled: field.toggled,
|
|
7741
|
-
disabled: true,
|
|
7742
|
-
className:"whitespace-nowrap",
|
|
7743
|
-
}, field.amis, {name: field.name}));
|
|
7744
|
-
}else if(field.type === 'avatar' || field.type === 'image' || field.type === 'file'){
|
|
7745
|
-
columns.push(Object.assign({}, {
|
|
7746
|
-
type: "switch",
|
|
7747
|
-
name: field.name,
|
|
7748
|
-
label: field.label,
|
|
7749
|
-
width: field.width,
|
|
7750
|
-
toggled: field.toggled,
|
|
7751
|
-
disabled: true,
|
|
7752
|
-
className:"whitespace-nowrap",
|
|
7753
|
-
...getAmisFileReadonlySchema(field)
|
|
7754
|
-
}, field.amis, {name: field.name}));
|
|
7755
|
-
}
|
|
7756
|
-
else if(field.type === 'select'){
|
|
7757
|
-
const map = getSelectMap(field.options);
|
|
7758
|
-
columns.push(Object.assign({}, {
|
|
7759
|
-
type: "mapping",
|
|
7760
|
-
name: field.name,
|
|
7761
|
-
label: field.label,
|
|
7762
|
-
map: map,
|
|
7763
|
-
sortable: field.sortable,
|
|
7764
|
-
width: field.width,
|
|
7765
|
-
toggled: field.toggled,
|
|
7766
|
-
className:"whitespace-nowrap",
|
|
7767
|
-
}, field.amis, {name: field.name}));
|
|
7768
|
-
}
|
|
7769
|
-
else {
|
|
7770
|
-
const tpl = await getFieldTpl(field, options);
|
|
7609
|
+
}
|
|
7610
|
+
})
|
|
7611
|
+
userFilters.push(keywordsFilters);
|
|
7612
|
+
};
|
|
7771
7613
|
|
|
7772
|
-
|
|
7773
|
-
if(tpl){
|
|
7774
|
-
type = 'tpl';
|
|
7775
|
-
}else if(field.type === 'html'){
|
|
7776
|
-
type = 'markdown';
|
|
7777
|
-
}else if(field.type === 'url' && field.show_as_qr){
|
|
7778
|
-
type = 'qr-code';
|
|
7779
|
-
}
|
|
7780
|
-
let className = "";
|
|
7781
|
-
if(field.type === 'textarea'){
|
|
7782
|
-
className = 'min-w-56';
|
|
7783
|
-
}
|
|
7784
|
-
if(field.wrap === false){
|
|
7785
|
-
className += " whitespace-nowrap";
|
|
7786
|
-
}
|
|
7787
|
-
if(!field.hidden && !field.extra){
|
|
7788
|
-
columns.push(Object.assign({}, {
|
|
7789
|
-
name: field.name,
|
|
7790
|
-
label: field.label,
|
|
7791
|
-
sortable: field.sortable,
|
|
7792
|
-
// searchable: field.searchable,
|
|
7793
|
-
width: field.width,
|
|
7794
|
-
type: type,
|
|
7795
|
-
tpl: tpl,
|
|
7796
|
-
toggled: field.toggled,
|
|
7797
|
-
className,
|
|
7798
|
-
options: field.type === 'html' ? {html: true} : null
|
|
7799
|
-
// toggled: true
|
|
7800
|
-
}, field.amis, {name: field.name}));
|
|
7801
|
-
}
|
|
7802
|
-
}
|
|
7803
|
-
|
|
7804
|
-
}
|
|
7805
|
-
// columns.push(getOperation(fields));
|
|
7806
|
-
if(!___namespace.some(columns, { name: options.labelFieldName })){
|
|
7807
|
-
const href = Router.getObjectDetailPath({
|
|
7808
|
-
...options, formFactor: options.formFactor, appId: "${appId}", objectName: options.objectName || "${objectName}", recordId: `\${${options.idFieldName}}`
|
|
7809
|
-
});
|
|
7810
|
-
columns[0].type = "tpl";
|
|
7811
|
-
columns[0].tpl = `<a href="${href}">\${${columns[0].name}}</a>`;
|
|
7812
|
-
}
|
|
7813
|
-
return columns;
|
|
7814
|
-
}
|
|
7614
|
+
let filters = [];
|
|
7815
7615
|
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
"type": "tpl",
|
|
7827
|
-
"tpl": tpls[index + 1].tpl,
|
|
7828
|
-
"className": "truncate ml-2 flex flex-shrink-0"//右侧样式类
|
|
7829
|
-
}],
|
|
7830
|
-
"size": "none",
|
|
7831
|
-
"className": "flex items-center justify-between"//每行样式类
|
|
7832
|
-
}
|
|
7833
|
-
*/
|
|
7834
|
-
function getMobileLines(tpls){
|
|
7835
|
-
let lines = [];
|
|
7836
|
-
let maxLineCount = 2;
|
|
7837
|
-
let lineChildren = [];
|
|
7838
|
-
let isNewLine = false;
|
|
7839
|
-
let isLeft = true;
|
|
7840
|
-
let lineChildrenClassName = "";
|
|
7841
|
-
let lineClassName = "flex items-center justify-between h-[20px]";
|
|
7842
|
-
tpls.forEach(function(item){
|
|
7843
|
-
if(isNewLine && lines.length < maxLineCount){
|
|
7844
|
-
lines.push({
|
|
7845
|
-
"type": "wrapper",
|
|
7846
|
-
"body": lineChildren,
|
|
7847
|
-
"size": "none",
|
|
7848
|
-
"className": lineClassName
|
|
7849
|
-
});
|
|
7850
|
-
lineChildren = [];
|
|
7851
|
-
}
|
|
7852
|
-
if(isLeft){
|
|
7853
|
-
// 左侧半行
|
|
7854
|
-
lineChildrenClassName = "steedos-listview-item-left truncate";
|
|
7855
|
-
if(item.field.is_wide){
|
|
7856
|
-
// 左侧全行样式可以单独写
|
|
7857
|
-
lineChildrenClassName = "steedos-listview-item-wide truncate";
|
|
7858
|
-
}
|
|
7859
|
-
if(lines.length === 0){
|
|
7860
|
-
// 第一个字段加粗黑色显示
|
|
7861
|
-
lineChildrenClassName += " font-bold text-gray-800";
|
|
7862
|
-
}
|
|
7863
|
-
}
|
|
7864
|
-
else {
|
|
7865
|
-
// 右侧半行
|
|
7866
|
-
lineChildrenClassName = "steedos-listview-item-right truncate ml-2 flex flex-shrink-0";
|
|
7867
|
-
}
|
|
7868
|
-
lineChildren.push({
|
|
7869
|
-
"type": "tpl",
|
|
7870
|
-
"tpl": item.tpl,
|
|
7871
|
-
"className": lineChildrenClassName
|
|
7872
|
-
});
|
|
7616
|
+
if(!_.isEmpty(systemFilters)){
|
|
7617
|
+
filters = systemFilters;
|
|
7618
|
+
};
|
|
7619
|
+
if(api.data.$self.additionalFilters){
|
|
7620
|
+
if(_.isString(api.data.$self.additionalFilters)){
|
|
7621
|
+
userFilters.push(eval(api.data.$self.additionalFilters))
|
|
7622
|
+
}else{
|
|
7623
|
+
userFilters.push(api.data.$self.additionalFilters)
|
|
7624
|
+
}
|
|
7625
|
+
}
|
|
7873
7626
|
|
|
7874
|
-
|
|
7875
|
-
|
|
7876
|
-
|
|
7877
|
-
|
|
7878
|
-
|
|
7879
|
-
|
|
7880
|
-
|
|
7881
|
-
|
|
7882
|
-
|
|
7883
|
-
|
|
7884
|
-
|
|
7885
|
-
|
|
7886
|
-
|
|
7887
|
-
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7627
|
+
if(api.data.$self._isRelated){
|
|
7628
|
+
const self = api.data.$self;
|
|
7629
|
+
const relatedKey = self.relatedKey;
|
|
7630
|
+
const refField = self.uiSchema.fields[relatedKey];
|
|
7631
|
+
const masterRecord = self._master.record;
|
|
7632
|
+
const masterObjectName = self._master.objectName;
|
|
7633
|
+
let relatedValue = self._master.recordId;
|
|
7634
|
+
if(refField.reference_to_field && refField.reference_to_field != '_id'){
|
|
7635
|
+
relatedValue = masterRecord[refField.reference_to_field]
|
|
7636
|
+
}
|
|
7637
|
+
let relatedFilters;
|
|
7638
|
+
if (
|
|
7639
|
+
refField._reference_to ||
|
|
7640
|
+
(refField.reference_to && !_.isString(refField.reference_to))
|
|
7641
|
+
) {
|
|
7642
|
+
relatedFilters = [
|
|
7643
|
+
[relatedKey + "/o", "=", masterObjectName],
|
|
7644
|
+
[relatedKey + "/ids", "=", relatedValue],
|
|
7645
|
+
];
|
|
7646
|
+
} else {
|
|
7647
|
+
relatedFilters = [relatedKey, "=", relatedValue];
|
|
7648
|
+
}
|
|
7649
|
+
userFilters.push(relatedFilters)
|
|
7650
|
+
}
|
|
7651
|
+
|
|
7652
|
+
if(!_.isEmpty(userFilters)){
|
|
7653
|
+
if(_.isEmpty(filters)){
|
|
7654
|
+
filters = userFilters;
|
|
7655
|
+
}else{
|
|
7656
|
+
filters = [filters, 'and', userFilters]
|
|
7657
|
+
}
|
|
7658
|
+
}
|
|
7659
|
+
api.data._ids = _ids;
|
|
7660
|
+
api.data = {
|
|
7661
|
+
query: api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim())
|
|
7662
|
+
}
|
|
7663
|
+
${options.requestAdaptor || ''}
|
|
7664
|
+
return api;
|
|
7665
|
+
`;
|
|
7666
|
+
api.adaptor = `
|
|
7667
|
+
if(api.body.listName == "recent"){
|
|
7668
|
+
payload.data.rows = _.sortBy(payload.data.rows, function(item){
|
|
7669
|
+
return _.indexOf(api.body._ids, item._id)
|
|
7670
|
+
});
|
|
7671
|
+
}
|
|
7672
|
+
const enable_tree = ${mainObject.enable_tree};
|
|
7673
|
+
if(!enable_tree){
|
|
7674
|
+
_.each(payload.data.rows, function(item, index){
|
|
7675
|
+
const {pageNo, pageSize} = api.body;
|
|
7676
|
+
const skip = (pageNo - 1) * pageSize;
|
|
7677
|
+
item._index = skip + index + 1;
|
|
7678
|
+
})
|
|
7679
|
+
}
|
|
7680
|
+
window.postMessage(Object.assign({type: "listview.loaded"}), "*");
|
|
7681
|
+
let fileFields = ${JSON.stringify(fileFields)};
|
|
7682
|
+
let lookupFields = ${JSON.stringify(lookupFields)};
|
|
7683
|
+
_.each(payload.data.rows, function(item, index){
|
|
7684
|
+
_.each(fileFields , (field, key)=>{
|
|
7685
|
+
if(item[key] && item._display && item._display[key]){
|
|
7686
|
+
let value = item._display[key];
|
|
7687
|
+
if(!_.isArray(value)){
|
|
7688
|
+
value = [value]
|
|
7689
|
+
};
|
|
7690
|
+
if(field.type === 'file'){
|
|
7691
|
+
item[key] = value
|
|
7692
|
+
}else{
|
|
7693
|
+
item[key] = _.map(value, 'url')
|
|
7694
|
+
}
|
|
7695
|
+
}
|
|
7696
|
+
})
|
|
7697
|
+
_.each(lookupFields , (field, key)=>{
|
|
7698
|
+
if(item[key]){
|
|
7699
|
+
if(field._optionsFunction){
|
|
7700
|
+
const optionsFunction = eval("(" + field._optionsFunction+ ")")(item);
|
|
7701
|
+
item[key + '__label'] = _.map(_.filter(optionsFunction, function(option){return _.includes(item[key], option.value)}), 'label').join(' ');
|
|
7702
|
+
}
|
|
7703
|
+
}
|
|
7704
|
+
})
|
|
7705
|
+
})
|
|
7706
|
+
|
|
7707
|
+
if(enable_tree){
|
|
7708
|
+
const records = payload.data.rows || [];
|
|
7709
|
+
const getTreeOptions = SteedosUI.getTreeOptions
|
|
7710
|
+
payload.data.rows = getTreeOptions(records,{"valueField":"_id"});
|
|
7711
|
+
}
|
|
7712
|
+
|
|
7713
|
+
|
|
7714
|
+
try{
|
|
7715
|
+
// TODO: 不应该直接在这里取localStorage,应该从外面传入
|
|
7716
|
+
const listViewId = api.body.listViewId;
|
|
7717
|
+
const listViewPropsStoreKey = location.pathname + "/crud/" + listViewId ;
|
|
7718
|
+
/**
|
|
7719
|
+
* localListViewProps规范来自crud请求api中api.data.$self参数值的。
|
|
7720
|
+
* 比如:{"perPage":20,"page":1,"__searchable__name":"7","__searchable__between__n1__c":[null,null],"filter":[["name","contains","a"]]}
|
|
7721
|
+
* __searchable__...:顶部放大镜搜索条件
|
|
7722
|
+
* filter:右侧过滤器
|
|
7723
|
+
* perPage:每页条数
|
|
7724
|
+
* page:当前页码
|
|
7725
|
+
* orderBy:排序字段
|
|
7726
|
+
* orderDir:排序方向
|
|
7727
|
+
*/
|
|
7728
|
+
let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
|
|
7729
|
+
let selfData = JSON.parse(JSON.stringify(api.body.$self));
|
|
7730
|
+
if(localListViewProps){
|
|
7731
|
+
localListViewProps = JSON.parse(localListViewProps);
|
|
7732
|
+
selfData = Object.assign({}, localListViewProps, selfData, { filter: api.body.filter });
|
|
7733
|
+
if(!api.body.loaded){
|
|
7734
|
+
// 第一次加载组件,比如刷新浏览器时因为api.data.pageNo有默认值1
|
|
7735
|
+
// 所以会把localSearchableFilter中已经存过的页码覆盖
|
|
7736
|
+
// 如果是第一次加载组件始终让翻页页码从本地存储中取值
|
|
7737
|
+
let formFactor = "${options.formFactor}";
|
|
7738
|
+
// 移动端不识别本地存储中的翻页页码,否则点击加载更多按钮后无法刷新回第一页
|
|
7739
|
+
selfData.page = formFactor === "SMALL" ? 1 : (localListViewProps.page || 1);
|
|
7740
|
+
}
|
|
7741
|
+
}
|
|
7742
|
+
delete selfData.context;
|
|
7743
|
+
delete selfData.global;
|
|
7744
|
+
sessionStorage.setItem(listViewPropsStoreKey, JSON.stringify(selfData));
|
|
7745
|
+
// 返回页码到UI界面
|
|
7746
|
+
payload.data.page= selfData.page;
|
|
7747
|
+
}
|
|
7748
|
+
catch(ex){
|
|
7749
|
+
console.error("本地存储中crud参数解析异常:", ex);
|
|
7750
|
+
}
|
|
7751
|
+
// 标记加载过,后续优先从本地存储中加载相关参数
|
|
7752
|
+
payload.data.loaded= true;
|
|
7753
|
+
|
|
7754
|
+
const setDataToComponentId = "${setDataToComponentId}";
|
|
7755
|
+
if(setDataToComponentId){
|
|
7756
|
+
SteedosUI.getRef(api.body.$self.$scopeId)?.getComponentById(setDataToComponentId)?.setData({$count: payload.data.count})
|
|
7757
|
+
};
|
|
7758
|
+
${options.adaptor || ''}
|
|
7759
|
+
return payload;
|
|
7760
|
+
`;
|
|
7761
|
+
return api;
|
|
7762
|
+
}
|
|
7763
|
+
|
|
7764
|
+
async function getApi(object, recordId, fields, options){
|
|
7765
|
+
const data = await getFindQuery(object, recordId, fields, options);
|
|
7766
|
+
return {
|
|
7767
|
+
method: "post",
|
|
7768
|
+
url: getApi$2(), // + "&recordId=${recordId}"
|
|
7769
|
+
data: data,
|
|
7770
|
+
headers: {
|
|
7771
|
+
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
7772
|
+
}
|
|
7892
7773
|
}
|
|
7893
|
-
|
|
7894
|
-
return lines;
|
|
7895
7774
|
}
|
|
7896
7775
|
|
|
7897
|
-
|
|
7898
|
-
const
|
|
7899
|
-
|
|
7900
|
-
|
|
7901
|
-
|
|
7902
|
-
|
|
7903
|
-
|
|
7904
|
-
|
|
7905
|
-
options.onlyDisplayLabel = true;
|
|
7906
|
-
tpl = await getFieldTpl(field, options);
|
|
7907
|
-
}
|
|
7908
|
-
else if(field.type === 'avatar' || field.type === 'image' || field.type === 'file'){
|
|
7909
|
-
// 图片和附件类型字段暂时显示为附件名称,后续需要再优化
|
|
7910
|
-
tpl = `\${_display.${field.name}.name}`;
|
|
7776
|
+
function getRecordPermissionsApi(object, recordId, options){
|
|
7777
|
+
const data = getRecordPermissionsQuery(object, recordId, options);
|
|
7778
|
+
return {
|
|
7779
|
+
method: "post",
|
|
7780
|
+
url: getApi$2(),
|
|
7781
|
+
data: data,
|
|
7782
|
+
headers: {
|
|
7783
|
+
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
7911
7784
|
}
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7785
|
+
}
|
|
7786
|
+
}
|
|
7787
|
+
|
|
7788
|
+
const API_CACHE = 100;
|
|
7789
|
+
|
|
7790
|
+
function getReadonlyFormAdaptor(object, fields){
|
|
7791
|
+
let scriptStr = '';
|
|
7792
|
+
const selectFields = ___namespace.filter(fields, function(field){return field.name.indexOf('.') < 0 && ((field.type == 'select' && field.options) || ((field.type == 'lookup' || field.type == 'master_detail') && !field.reference_to))});
|
|
7793
|
+
const gridAndObjectFieldsName = ___namespace.map(___namespace.filter(fields, function(field){return field.name.indexOf('.') < 0 && (field.type === 'object' || field.type === 'grid')}), 'name');
|
|
7794
|
+
___namespace.each(selectFields, function(field){
|
|
7795
|
+
if(!___namespace.includes(OMIT_FIELDS, field.name)){
|
|
7796
|
+
field.name;
|
|
7797
|
+
if(field.options){
|
|
7798
|
+
const options = JSON.stringify({options: field.options});
|
|
7799
|
+
scriptStr = scriptStr + `var ${field.name}Options= (${options}).options;`;
|
|
7800
|
+
}else if(field.optionsFunction){
|
|
7801
|
+
scriptStr = scriptStr + `var ${field.name}Options = eval(${field.optionsFunction.toString()})(api.data);`;
|
|
7802
|
+
}else if(field._optionsFunction){
|
|
7803
|
+
scriptStr = scriptStr + `var ${field.name}Options = eval(${field._optionsFunction})(api.data);`;
|
|
7804
|
+
}
|
|
7805
|
+
if(field.multiple){
|
|
7806
|
+
scriptStr = scriptStr + `data.${field.name}__label = _.map(_.filter(${field.name}Options, function(option){return _.includes(data.${field.name}, option.value)}), 'label');`;
|
|
7807
|
+
}else {
|
|
7808
|
+
scriptStr = scriptStr + `var ${field.name}Selected = _.find(${field.name}Options, function(option){return data.${field.name} == option.value});`;
|
|
7809
|
+
scriptStr = scriptStr + `data.${field.name}__label = ${field.name}Selected ? ${field.name}Selected.label:null;`;
|
|
7915
7810
|
}
|
|
7916
|
-
tpl = await getFieldTpl(field, options);
|
|
7917
|
-
}
|
|
7918
|
-
if(!tpl){
|
|
7919
|
-
tpl = `\${${field.name}}`;
|
|
7920
|
-
}
|
|
7921
|
-
if(!field.hidden && !field.extra){
|
|
7922
|
-
tpls.push({ field, tpl });
|
|
7923
7811
|
}
|
|
7924
|
-
}
|
|
7925
|
-
const url = getNameTplUrl(nameField, options);
|
|
7812
|
+
});
|
|
7926
7813
|
|
|
7927
|
-
const
|
|
7814
|
+
// const refFields = _.filter(fields, function(field){return field.name.indexOf('.') < 0 && (field.type == 'lookup' || field.type == 'master_detail') && !field.reference_to});
|
|
7815
|
+
// _.each(refFields, function(field){
|
|
7816
|
+
// if(!_.includes(OMIT_FIELDS, field.name)){
|
|
7817
|
+
// const valueField = field.reference_to_field || '_id';
|
|
7818
|
+
// scriptStr = scriptStr + `var ${field.name}Options = eval(${field.optionsFunction.toString()})(api.data);`
|
|
7819
|
+
// if(field.multiple){
|
|
7820
|
+
// scriptStr = scriptStr + `data.${field.name}__label = _.map(_.filter(${field.name}Options, function(option){return _.includes(data.${field.name}, option.value)}), 'label');`
|
|
7821
|
+
// }else{
|
|
7822
|
+
// scriptStr = scriptStr + `var ${field.name}Selected = _.find(${field.name}Options, function(option){return data.${field.name} == option.value});`
|
|
7823
|
+
// scriptStr = scriptStr + `data.${field.name}__label = ${field.name}Selected ? ${field.name}Selected.label:null;`
|
|
7824
|
+
// }
|
|
7825
|
+
// }
|
|
7826
|
+
// })
|
|
7928
7827
|
|
|
7828
|
+
return `
|
|
7829
|
+
if(payload.data.data.length === 0){
|
|
7830
|
+
return {
|
|
7831
|
+
status: 2,
|
|
7832
|
+
msg: "无法找到记录"
|
|
7833
|
+
}
|
|
7834
|
+
}
|
|
7835
|
+
if(payload.data.data){
|
|
7836
|
+
var data = payload.data.data[0];
|
|
7837
|
+
var gridAndObjectFieldsName = ${JSON.stringify(gridAndObjectFieldsName)};
|
|
7838
|
+
try{
|
|
7839
|
+
${scriptStr}
|
|
7840
|
+
${getScriptForAddUrlPrefixForImgFields(fields)}
|
|
7841
|
+
${getScriptForRewriteValueForFileFields(fields)}
|
|
7842
|
+
}catch(e){
|
|
7843
|
+
console.error(e)
|
|
7844
|
+
}
|
|
7845
|
+
// 原始记录
|
|
7846
|
+
var record = _.cloneDeep(data);
|
|
7847
|
+
try{
|
|
7848
|
+
_.each(gridAndObjectFieldsName, function(name){
|
|
7849
|
+
data[name] = data._display[name];
|
|
7850
|
+
})
|
|
7851
|
+
}catch(e){
|
|
7852
|
+
console.error(e)
|
|
7853
|
+
}
|
|
7854
|
+
payload.data = data;
|
|
7855
|
+
payload.data.__objectName = "${object.name}";
|
|
7856
|
+
payload.data.__record = record;
|
|
7857
|
+
window.postMessage(Object.assign({type: "record.loaded"}, {record: record}), "*")
|
|
7858
|
+
}
|
|
7859
|
+
if(payload.errors){
|
|
7860
|
+
payload.status = 2;
|
|
7861
|
+
payload.msg = payload.errors[0].message;
|
|
7862
|
+
}
|
|
7863
|
+
return payload;
|
|
7864
|
+
`
|
|
7865
|
+
}
|
|
7929
7866
|
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
|
|
7934
|
-
|
|
7935
|
-
|
|
7936
|
-
|
|
7937
|
-
|
|
7938
|
-
|
|
7939
|
-
|
|
7940
|
-
"type": "wrapper",
|
|
7941
|
-
"body": columnLines,
|
|
7942
|
-
"size": "none",
|
|
7943
|
-
"className": "p-1"
|
|
7867
|
+
async function getReadonlyFormInitApi(object, recordId, fields, options){
|
|
7868
|
+
return {
|
|
7869
|
+
method: "post",
|
|
7870
|
+
url: getApi$2()+"&recordId=${recordId}",
|
|
7871
|
+
cache: API_CACHE,
|
|
7872
|
+
// requestAdaptor: "console.log('getReadonlyFormInitApi requestAdaptor', api);return api;",
|
|
7873
|
+
adaptor: getReadonlyFormAdaptor(object, fields),
|
|
7874
|
+
data: await getFindOneQuery$1(object, recordId, fields, options),
|
|
7875
|
+
headers: {
|
|
7876
|
+
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
7944
7877
|
}
|
|
7945
|
-
}
|
|
7946
|
-
|
|
7947
|
-
|
|
7948
|
-
|
|
7949
|
-
|
|
7950
|
-
|
|
7951
|
-
|
|
7952
|
-
|
|
7953
|
-
|
|
7954
|
-
|
|
7955
|
-
|
|
7956
|
-
|
|
7957
|
-
|
|
7958
|
-
|
|
7959
|
-
|
|
7960
|
-
|
|
7961
|
-
"actionType": "custom"
|
|
7962
|
-
}
|
|
7963
|
-
],
|
|
7964
|
-
"weight": 0
|
|
7965
|
-
}
|
|
7966
|
-
}
|
|
7967
|
-
};
|
|
7968
|
-
}else {
|
|
7969
|
-
column = {
|
|
7970
|
-
...column,
|
|
7971
|
-
actionType: "",
|
|
7972
|
-
link: "",
|
|
7973
|
-
onEvent: {
|
|
7974
|
-
"click": {
|
|
7975
|
-
"actions": [
|
|
7976
|
-
{
|
|
7977
|
-
"args": {
|
|
7978
|
-
"api": {
|
|
7979
|
-
"url": url,
|
|
7980
|
-
"method": "get",
|
|
7981
|
-
"headers": {
|
|
7982
|
-
"Authorization": "Bearer ${context.tenantId},${context.authToken}"
|
|
7983
|
-
}
|
|
7984
|
-
}
|
|
7985
|
-
},
|
|
7986
|
-
"actionType": "download"
|
|
7987
|
-
}
|
|
7988
|
-
],
|
|
7989
|
-
"weight": 0
|
|
7990
|
-
}
|
|
7991
|
-
}
|
|
7878
|
+
}
|
|
7879
|
+
}
|
|
7880
|
+
|
|
7881
|
+
/*
|
|
7882
|
+
img/avatar字段值添加URL前缀使其在amis中正常显示图片。
|
|
7883
|
+
*/
|
|
7884
|
+
function getScriptForAddUrlPrefixForImgFields(fields){
|
|
7885
|
+
let imgFieldsKeys = [];
|
|
7886
|
+
let imgFields = {};
|
|
7887
|
+
fields.forEach((item)=>{
|
|
7888
|
+
if(___namespace.includes(['image','avatar'], item.type)){
|
|
7889
|
+
imgFieldsKeys.push(item.name);
|
|
7890
|
+
imgFields[item.name] = {
|
|
7891
|
+
name: item.name,
|
|
7892
|
+
type: item.type,
|
|
7893
|
+
multiple: item.multiple
|
|
7992
7894
|
};
|
|
7993
7895
|
}
|
|
7994
|
-
|
|
7896
|
+
});
|
|
7897
|
+
if(!imgFieldsKeys.length){
|
|
7898
|
+
return '';
|
|
7995
7899
|
}
|
|
7900
|
+
return `
|
|
7901
|
+
// image字段值添加URL前缀
|
|
7902
|
+
let imgFieldsKeys = ${JSON.stringify(imgFieldsKeys)};
|
|
7903
|
+
let imgFields = ${JSON.stringify(imgFields)};
|
|
7904
|
+
imgFieldsKeys.forEach((item)=>{
|
|
7905
|
+
let imgFieldValue = data[item];
|
|
7906
|
+
let imgFieldDisplayValue = data._display && data._display[item];
|
|
7907
|
+
if(imgFieldValue && imgFieldValue.length){
|
|
7908
|
+
let fieldProps = imgFields[item];
|
|
7909
|
+
if(fieldProps.multiple){
|
|
7910
|
+
if(imgFieldDisplayValue instanceof Array){
|
|
7911
|
+
data[item] = imgFieldDisplayValue.map((i)=>{ return i.url });
|
|
7912
|
+
}
|
|
7913
|
+
}else{
|
|
7914
|
+
data[item] = imgFieldDisplayValue && imgFieldDisplayValue.url;
|
|
7915
|
+
}
|
|
7916
|
+
}
|
|
7917
|
+
})
|
|
7918
|
+
`
|
|
7919
|
+
}
|
|
7996
7920
|
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
|
|
7921
|
+
/*
|
|
7922
|
+
file字段值重写使其在amis中正常显示附件名、点击附件名下载文件。
|
|
7923
|
+
*/
|
|
7924
|
+
function getScriptForRewriteValueForFileFields(fields){
|
|
7925
|
+
let fileFieldsKeys = [];
|
|
7926
|
+
let fileFields = {};
|
|
7927
|
+
fields.forEach((item)=>{
|
|
7928
|
+
if(item.type === 'file'){
|
|
7929
|
+
fileFieldsKeys.push(item.name);
|
|
7930
|
+
fileFields[item.name] = {
|
|
7931
|
+
name: item.name,
|
|
7932
|
+
multiple: item.multiple
|
|
7933
|
+
};
|
|
7934
|
+
}
|
|
7935
|
+
});
|
|
7936
|
+
if(!fileFieldsKeys.length){
|
|
7937
|
+
return '';
|
|
7938
|
+
}
|
|
7939
|
+
return `
|
|
7940
|
+
// file字段值重写以便编辑时正常显示附件名、点击附件名正常下载附件
|
|
7941
|
+
let fileFieldsKeys = ${JSON.stringify(fileFieldsKeys)};
|
|
7942
|
+
let fileFields = ${JSON.stringify(fileFields)};
|
|
7943
|
+
fileFieldsKeys.forEach((item)=>{
|
|
7944
|
+
let fileFieldValue = data[item];
|
|
7945
|
+
let fileFieldDisplayValue = data._display && data._display[item];
|
|
7946
|
+
if(fileFieldValue && fileFieldValue.length){
|
|
7947
|
+
if(fileFields[item].multiple){
|
|
7948
|
+
if(fileFieldDisplayValue instanceof Array){
|
|
7949
|
+
data[item] = fileFieldDisplayValue.map((item, index)=>{
|
|
7950
|
+
return {
|
|
7951
|
+
value: fileFieldValue[index],
|
|
7952
|
+
name: item.name,
|
|
7953
|
+
url: item.url + "?download=true",
|
|
7954
|
+
state: "uploaded"
|
|
7955
|
+
}
|
|
7956
|
+
});
|
|
7957
|
+
}
|
|
7958
|
+
}else{
|
|
7959
|
+
data[item] = [{
|
|
7960
|
+
value: fileFieldValue,
|
|
7961
|
+
name: fileFieldDisplayValue.name,
|
|
7962
|
+
url: fileFieldDisplayValue.url + "?download=true",
|
|
7963
|
+
state: "uploaded"
|
|
7964
|
+
}];
|
|
7965
|
+
}
|
|
7966
|
+
}
|
|
7967
|
+
})
|
|
7968
|
+
`
|
|
8001
7969
|
}
|
|
8002
7970
|
|
|
8003
|
-
function
|
|
7971
|
+
async function getEditFormInitApi(object, recordId, fields, options){
|
|
7972
|
+
const data = await getFindOneQuery$1(object, recordId, fields);
|
|
7973
|
+
data.recordId = "${recordId}";
|
|
7974
|
+
data.objectName = "${objectName}";
|
|
7975
|
+
data.uiSchema = "${uiSchema}";
|
|
7976
|
+
data.global = "${global}";
|
|
7977
|
+
data.context = "${context}";
|
|
7978
|
+
data.defaultData = "${defaultData}";
|
|
7979
|
+
data._master = "${_master}";
|
|
7980
|
+
|
|
8004
7981
|
return {
|
|
8005
|
-
|
|
8006
|
-
|
|
8007
|
-
|
|
8008
|
-
|
|
8009
|
-
|
|
8010
|
-
|
|
8011
|
-
|
|
8012
|
-
|
|
8013
|
-
|
|
8014
|
-
|
|
7982
|
+
method: "post",
|
|
7983
|
+
url: getApi$2() + '&objectName=${objectName}' ,
|
|
7984
|
+
// sendOn: "!!this.recordId",
|
|
7985
|
+
cache: API_CACHE,
|
|
7986
|
+
requestAdaptor: `
|
|
7987
|
+
// 所有不想在network请求中发送的数据都应该从data中分离出来,data变量只需要留下query才需要发送出去
|
|
7988
|
+
var { recordId, objectName, uiSchema, global, context, ...data} = api.data;
|
|
7989
|
+
if(!recordId){
|
|
7990
|
+
// 新建则不请求任何数据
|
|
7991
|
+
data.query = "{data:" + objectName + "(filters: " + JSON.stringify(["_id", "=", null]) + ", top: 1){_id}}";
|
|
7992
|
+
}
|
|
7993
|
+
api.data = data;
|
|
7994
|
+
${options.initApiRequestAdaptor || ''}
|
|
7995
|
+
return api;
|
|
7996
|
+
`,
|
|
7997
|
+
adaptor: `
|
|
7998
|
+
const recordId = api.body.recordId;
|
|
7999
|
+
let initialValues={};
|
|
8000
|
+
if(recordId && payload.data.data){
|
|
8001
|
+
var data = payload.data.data[0];
|
|
8002
|
+
const dataKeys = _.keys(data);
|
|
8003
|
+
const uiSchema = api.body.uiSchema;
|
|
8004
|
+
const fieldKeys = uiSchema && _.keys(uiSchema.fields);
|
|
8015
8005
|
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
|
|
8006
|
+
if(data){
|
|
8007
|
+
${getScriptForAddUrlPrefixForImgFields(fields)}
|
|
8008
|
+
${getScriptForRewriteValueForFileFields(fields)}
|
|
8019
8009
|
|
|
8020
|
-
|
|
8021
|
-
|
|
8022
|
-
|
|
8023
|
-
|
|
8024
|
-
|
|
8025
|
-
|
|
8026
|
-
|
|
8010
|
+
_.each(dataKeys, function(key){
|
|
8011
|
+
if(fieldKeys.indexOf(key)<0){
|
|
8012
|
+
delete data[key];
|
|
8013
|
+
}
|
|
8014
|
+
})
|
|
8015
|
+
|
|
8016
|
+
//初始化接口返回的字段移除字段值为null的字段
|
|
8017
|
+
for (key in data){
|
|
8018
|
+
if(data[key] === null){
|
|
8019
|
+
delete data[key];
|
|
8020
|
+
}
|
|
8021
|
+
}
|
|
8022
|
+
};
|
|
8023
|
+
initialValues = data;
|
|
8024
|
+
}
|
|
8025
|
+
else{
|
|
8026
|
+
var uiSchema = api.body.uiSchema;
|
|
8027
|
+
var defaultData = api.body.defaultData;
|
|
8028
|
+
var defaultValues = {};
|
|
8029
|
+
_.each(uiSchema?.fields, function(field){
|
|
8030
|
+
var value = SteedosUI.getFieldDefaultValue(field, api.body.global);
|
|
8031
|
+
if(value){
|
|
8032
|
+
defaultValues[field.name] = value;
|
|
8033
|
+
}
|
|
8034
|
+
});
|
|
8035
|
+
if(defaultData && _.isObject(defaultData) && !_.isArray(defaultData)){
|
|
8036
|
+
defaultValues = Object.assign({}, defaultValues, defaultData)
|
|
8037
|
+
}
|
|
8038
|
+
if(uiSchema.form){
|
|
8039
|
+
try{
|
|
8040
|
+
var objectFormConfig = JSON.parse(uiSchema.form);
|
|
8041
|
+
var formInitialValuesFun = objectFormConfig.initialValues;
|
|
8042
|
+
if(formInitialValuesFun){
|
|
8043
|
+
formInitialValuesFun = new Function("return " + formInitialValuesFun)();
|
|
8044
|
+
}
|
|
8045
|
+
if(typeof formInitialValuesFun === "function"){
|
|
8046
|
+
initialValues = formInitialValuesFun.apply({doc: defaultValues || {} , global: api.body.global, master: api.body._master })
|
|
8047
|
+
}
|
|
8048
|
+
}
|
|
8049
|
+
catch(ex){
|
|
8050
|
+
console.warn(ex);
|
|
8051
|
+
}
|
|
8052
|
+
}
|
|
8053
|
+
if(_.isObject(initialValues)){
|
|
8054
|
+
// uiSchema.form.initialValues为函数且执行后为json,则优先取initialValues中的默认值
|
|
8055
|
+
initialValues = Object.assign({}, defaultValues, initialValues);
|
|
8056
|
+
}
|
|
8057
|
+
else{
|
|
8058
|
+
initialValues = defaultValues;
|
|
8059
|
+
}
|
|
8060
|
+
}
|
|
8061
|
+
// data下的变量需要在保存接口(getSaveApi)中被删除。
|
|
8062
|
+
payload.data = {
|
|
8063
|
+
...initialValues
|
|
8064
|
+
}
|
|
8065
|
+
${options.initApiAdaptor || ''}
|
|
8066
|
+
return payload;
|
|
8067
|
+
`,
|
|
8068
|
+
responseData: {
|
|
8069
|
+
initialValues: "$$",
|
|
8070
|
+
editFormInited: true
|
|
8071
|
+
},
|
|
8072
|
+
data: data,
|
|
8073
|
+
headers: {
|
|
8074
|
+
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
8027
8075
|
}
|
|
8028
|
-
return visible;
|
|
8029
8076
|
}
|
|
8077
|
+
}
|
|
8030
8078
|
|
|
8031
|
-
|
|
8032
|
-
|
|
8033
|
-
|
|
8034
|
-
|
|
8035
|
-
|
|
8079
|
+
|
|
8080
|
+
function getSaveApi(object, recordId, fields, options){
|
|
8081
|
+
return {
|
|
8082
|
+
method: 'post',
|
|
8083
|
+
url: getApi$2(),
|
|
8084
|
+
data: getSaveQuery(object, recordId),
|
|
8085
|
+
requestAdaptor: getSaveRequestAdaptor(fields, options),
|
|
8086
|
+
responseData: {
|
|
8087
|
+
"recordId": "${record._id}"
|
|
8088
|
+
},
|
|
8089
|
+
adaptor: `
|
|
8090
|
+
if(payload.errors){
|
|
8091
|
+
payload.status = 2;
|
|
8092
|
+
payload.msg = window.t ? window.t(payload.errors[0].message) : payload.errors[0].message;
|
|
8093
|
+
}
|
|
8094
|
+
${options.apiAdaptor || ''}
|
|
8095
|
+
return payload;
|
|
8096
|
+
`,
|
|
8097
|
+
headers: {
|
|
8098
|
+
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
8036
8099
|
}
|
|
8037
8100
|
}
|
|
8038
8101
|
}
|
|
8039
8102
|
|
|
8040
|
-
|
|
8041
|
-
const buttons = ctx.buttons;
|
|
8042
|
-
const operationButtons = [];
|
|
8043
|
-
_$1.each(buttons, (button)=>{
|
|
8044
|
-
if(_$1.isBoolean(button.visible)){
|
|
8045
|
-
button.visible = button.visible.toString();
|
|
8046
|
-
}
|
|
8047
|
-
// operationButtons.push({
|
|
8048
|
-
// type: 'button',
|
|
8049
|
-
// label: button.label,
|
|
8050
|
-
// visibleOn: button.visible ? `${button.visible}` : (button._visible ? `${button._visible}` : null),
|
|
8051
|
-
// onEvent: {
|
|
8052
|
-
// click: {
|
|
8053
|
-
// actions: []
|
|
8054
|
-
// }
|
|
8055
|
-
// }
|
|
8056
|
-
// })
|
|
8057
|
-
|
|
8058
|
-
operationButtons.push({
|
|
8059
|
-
type: 'steedos-object-button',
|
|
8060
|
-
name: button.name,
|
|
8061
|
-
objectName: button.objectName,
|
|
8062
|
-
visibleOn: getButtonVisibleOn(button),
|
|
8063
|
-
className: 'antd-Button--default'
|
|
8064
|
-
});
|
|
8065
|
-
});
|
|
8066
|
-
if(operationButtons.length < 1){
|
|
8067
|
-
return ;
|
|
8068
|
-
}
|
|
8103
|
+
function getBatchDelete(objectName){
|
|
8069
8104
|
return {
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
{
|
|
8077
|
-
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
data: {
|
|
8088
|
-
$: "$$",
|
|
8089
|
-
objectName: "${objectName}",
|
|
8090
|
-
listViewId: "${listViewId}",
|
|
8091
|
-
appId: "${appId}",
|
|
8092
|
-
formFactor: "${formFactor}",
|
|
8093
|
-
context: `\${context}`
|
|
8094
|
-
},
|
|
8095
|
-
headers: {
|
|
8096
|
-
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
8097
|
-
},
|
|
8098
|
-
adaptor: `
|
|
8099
|
-
payload = {
|
|
8100
|
-
record: {
|
|
8101
|
-
recordPermissions: payload
|
|
8102
|
-
}
|
|
8103
|
-
};
|
|
8104
|
-
return payload;
|
|
8105
|
-
`,
|
|
8106
|
-
}
|
|
8107
|
-
}
|
|
8108
|
-
]
|
|
8105
|
+
method: 'post',
|
|
8106
|
+
url: getApi$2(),
|
|
8107
|
+
requestAdaptor: `
|
|
8108
|
+
var ids = api.data.ids.split(",");
|
|
8109
|
+
var deleteArray = [];
|
|
8110
|
+
ids.forEach((id,index)=>{
|
|
8111
|
+
deleteArray.push(\`delete__\${index}:${objectName}__delete(id: "\${id}")\`);
|
|
8112
|
+
})
|
|
8113
|
+
api.data = {query: \`mutation{\${deleteArray.join(',')}}\`};
|
|
8114
|
+
return api;
|
|
8115
|
+
`,
|
|
8116
|
+
data: {
|
|
8117
|
+
ids: `\${ids}`
|
|
8118
|
+
},
|
|
8119
|
+
headers: {
|
|
8120
|
+
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
8121
|
+
}
|
|
8109
8122
|
}
|
|
8110
8123
|
}
|
|
8111
8124
|
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
columns = await getMobileTableColumns(fields, options);
|
|
8119
|
-
}
|
|
8120
|
-
else {
|
|
8121
|
-
columns = await getTableColumns(fields, options);
|
|
8122
|
-
columns.push(await getTableOperation(options));
|
|
8123
|
-
}
|
|
8124
|
-
return {
|
|
8125
|
-
mode: "table",
|
|
8126
|
-
name: "thelist",
|
|
8127
|
-
headerToolbarClassName: "py-2 px-2 border-gray-300 bg-gray-100 border-solid border-b",
|
|
8128
|
-
className: "",
|
|
8129
|
-
draggable: false,
|
|
8130
|
-
defaultParams: getDefaultParams(options),
|
|
8131
|
-
columns: columns,
|
|
8132
|
-
syncLocation: false,
|
|
8133
|
-
keepItemSelectionOnPageChange: true,
|
|
8134
|
-
checkOnItemClick: false,
|
|
8135
|
-
labelTpl: `\${${options.labelFieldName}}`,
|
|
8136
|
-
autoFillHeight: false, // 自动高度效果不理想,先关闭
|
|
8137
|
-
columnsTogglable: false,
|
|
8138
|
-
}
|
|
8139
|
-
}
|
|
8125
|
+
const DEFAULT_CALENDAR_OPTIONS = {
|
|
8126
|
+
startDateExpr: "start",
|
|
8127
|
+
endDateExpr: "end",
|
|
8128
|
+
allDayExpr: "is_all_day",
|
|
8129
|
+
textExpr: "name"
|
|
8130
|
+
};
|
|
8140
8131
|
|
|
8132
|
+
async function getCalendarApi(mainObject, fields, options) {
|
|
8133
|
+
if (!options) {
|
|
8134
|
+
options = {};
|
|
8135
|
+
}
|
|
8136
|
+
const calendarOptions = options.calendarOptions;
|
|
8137
|
+
const searchableFields = [];
|
|
8138
|
+
let { filter, sort, top, setDataToComponentId = '' } = options;
|
|
8141
8139
|
|
|
8140
|
+
if (!top) {
|
|
8141
|
+
// 日历请求不翻页
|
|
8142
|
+
top = 200;
|
|
8143
|
+
}
|
|
8142
8144
|
|
|
8143
|
-
|
|
8144
|
-
|
|
8145
|
-
|
|
8146
|
-
|
|
8147
|
-
|
|
8148
|
-
|
|
8149
|
-
|
|
8150
|
-
|
|
8151
|
-
|
|
8152
|
-
|
|
8145
|
+
if (___default["default"].isArray(filter)) {
|
|
8146
|
+
filter = ___default["default"].map(filter, function (item) {
|
|
8147
|
+
if (item.operation) {
|
|
8148
|
+
return [item.field, item.operation, item.value];
|
|
8149
|
+
} else {
|
|
8150
|
+
return item
|
|
8151
|
+
}
|
|
8152
|
+
});
|
|
8153
|
+
}
|
|
8154
|
+
if (!filter) {
|
|
8155
|
+
filter = [];
|
|
8156
|
+
}
|
|
8153
8157
|
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
return [item.field, item.operation, item.value];
|
|
8158
|
-
}else {
|
|
8159
|
-
return item
|
|
8160
|
-
}
|
|
8161
|
-
});
|
|
8162
|
-
}
|
|
8163
|
-
if(!filter){
|
|
8164
|
-
filter = [];
|
|
8158
|
+
___default["default"].each(fields, function (field) {
|
|
8159
|
+
if (field.searchable) {
|
|
8160
|
+
searchableFields.push(field.name);
|
|
8165
8161
|
}
|
|
8166
|
-
|
|
8167
|
-
|
|
8168
|
-
|
|
8162
|
+
});
|
|
8163
|
+
|
|
8164
|
+
const idFieldName = mainObject.idFieldName || "_id";
|
|
8165
|
+
let valueField = mainObject.key_field || '_id';
|
|
8166
|
+
const api = await getApi(mainObject, null, fields, { alias: 'rows', limit: top, queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"` });
|
|
8167
|
+
api.data.$term = "$term";
|
|
8168
|
+
api.data.$self = "$$";
|
|
8169
|
+
api.data.filter = "$filter";
|
|
8170
|
+
api.data.pageSize = top || 10;
|
|
8171
|
+
api.requestAdaptor = `
|
|
8172
|
+
let selfData = JSON.parse(JSON.stringify(api.data.$self));
|
|
8173
|
+
var filters = api.data.filter || ${JSON.stringify(filter)} || [];
|
|
8174
|
+
const eventFetchInfo = selfData.fetchInfo;
|
|
8175
|
+
const startDateExpr = "${calendarOptions.startDateExpr}";
|
|
8176
|
+
const endDateExpr = "${calendarOptions.endDateExpr}";
|
|
8177
|
+
const eventDurationFilters = [[endDateExpr, ">=", eventFetchInfo.start], [startDateExpr, "<=", eventFetchInfo.end]];
|
|
8178
|
+
if(_.isEmpty(filters)){
|
|
8179
|
+
filters = eventDurationFilters;
|
|
8180
|
+
}else{
|
|
8181
|
+
filters = [filters, 'and', eventDurationFilters]
|
|
8182
|
+
}
|
|
8183
|
+
|
|
8184
|
+
if(api.data.$self.additionalFilters){
|
|
8185
|
+
filters.push(api.data.$self.additionalFilters)
|
|
8186
|
+
}
|
|
8187
|
+
|
|
8188
|
+
var pageSize = api.data.pageSize || 10;
|
|
8189
|
+
var pageNo = api.data.pageNo || 1;
|
|
8190
|
+
var skip = (pageNo - 1) * pageSize;
|
|
8191
|
+
var orderBy = api.data.orderBy || '';
|
|
8192
|
+
var orderDir = api.data.orderDir || '';
|
|
8193
|
+
var sort = orderBy + ' ' + orderDir;
|
|
8194
|
+
sort = orderBy ? sort : "${sort}";
|
|
8195
|
+
var allowSearchFields = ${JSON.stringify(searchableFields)};
|
|
8196
|
+
if(api.data.$term){
|
|
8197
|
+
filters = [["name", "contains", "'+ api.data.$term +'"]];
|
|
8198
|
+
}else if(selfData.op === 'loadOptions' && selfData.value){
|
|
8199
|
+
filters = [["${valueField.name}", "=", selfData.value]];
|
|
8200
|
+
}
|
|
8201
|
+
var searchableFilter = SteedosUI.getSearchFilter(selfData) || [];
|
|
8202
|
+
|
|
8203
|
+
if(searchableFilter.length > 0){
|
|
8204
|
+
if(filters.length > 0 ){
|
|
8205
|
+
filters = [filters, 'and', searchableFilter];
|
|
8206
|
+
}else{
|
|
8207
|
+
filters = searchableFilter;
|
|
8208
|
+
}
|
|
8209
|
+
}
|
|
8210
|
+
|
|
8211
|
+
if(allowSearchFields){
|
|
8212
|
+
allowSearchFields.forEach(function(key){
|
|
8213
|
+
const keyValue = selfData[key];
|
|
8214
|
+
if(_.isString(keyValue)){
|
|
8215
|
+
filters.push([key, "contains", keyValue]);
|
|
8216
|
+
}else if(_.isArray(keyValue) || _.isBoolean(keyValue) || keyValue){
|
|
8217
|
+
filters.push([key, "=", keyValue]);
|
|
8218
|
+
}
|
|
8219
|
+
})
|
|
8220
|
+
}
|
|
8221
|
+
|
|
8222
|
+
if(selfData.__keywords && allowSearchFields){
|
|
8223
|
+
const keywordsFilters = [];
|
|
8224
|
+
allowSearchFields.forEach(function(key, index){
|
|
8225
|
+
const keyValue = selfData.__keywords;
|
|
8226
|
+
if(keyValue){
|
|
8227
|
+
keywordsFilters.push([key, "contains", keyValue]);
|
|
8228
|
+
if(index < allowSearchFields.length - 1){
|
|
8229
|
+
keywordsFilters.push('or');
|
|
8230
|
+
}
|
|
8231
|
+
}
|
|
8232
|
+
})
|
|
8233
|
+
filters.push(keywordsFilters);
|
|
8234
|
+
}
|
|
8235
|
+
api.data.query = api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim());
|
|
8236
|
+
delete api.data.$term;
|
|
8237
|
+
delete api.data.filter;
|
|
8238
|
+
delete api.data.pageSize;
|
|
8239
|
+
delete api.data.pageNo;
|
|
8240
|
+
delete api.data.orderBy;
|
|
8241
|
+
delete api.data.orderDir;
|
|
8242
|
+
return api;
|
|
8243
|
+
`;
|
|
8244
|
+
api.adaptor = `
|
|
8245
|
+
window.postMessage(Object.assign({type: "listview.loaded"}), "*");
|
|
8246
|
+
const setDataToComponentId = "${setDataToComponentId}";
|
|
8247
|
+
if(setDataToComponentId){
|
|
8248
|
+
SteedosUI.getRef(api.body.$self.scopeId)?.getComponentById(setDataToComponentId)?.setData({$count: payload.data.count})
|
|
8249
|
+
}
|
|
8250
|
+
const rows = payload.data.rows || [];
|
|
8251
|
+
const selfData = api.data.$self;
|
|
8252
|
+
const events = rows.map(function(n){
|
|
8253
|
+
return {
|
|
8254
|
+
id: n["${idFieldName}"],
|
|
8255
|
+
title: n["${calendarOptions.textExpr}"],
|
|
8256
|
+
start: n["${calendarOptions.startDateExpr}"],
|
|
8257
|
+
end: n["${calendarOptions.endDateExpr}"],
|
|
8258
|
+
allDay: n["${calendarOptions.allDayExpr}"],
|
|
8259
|
+
extendedProps: n
|
|
8169
8260
|
}
|
|
8170
|
-
|
|
8171
|
-
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
|
|
8261
|
+
});
|
|
8262
|
+
const successCallback = selfData.successCallback;
|
|
8263
|
+
const failureCallback = selfData.failureCallback;
|
|
8264
|
+
successCallback(events);
|
|
8265
|
+
return payload;
|
|
8266
|
+
`;
|
|
8267
|
+
return api;
|
|
8268
|
+
}
|
|
8175
8269
|
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8270
|
+
function getCalendarRecordPermissionsApi(mainObject, recordId) {
|
|
8271
|
+
const api = getRecordPermissionsApi(mainObject, recordId, { alias: 'rows', limit: 1, fields: ["allowEdit"] });
|
|
8272
|
+
api.data.$self = "$$";
|
|
8273
|
+
api.adaptor = `
|
|
8274
|
+
const rows = payload.data.rows || [];
|
|
8275
|
+
const selfData = api.data.$self;
|
|
8276
|
+
const revert = selfData.revert;
|
|
8277
|
+
const recordPermissions = rows[0] && rows[0].recordPermissions;
|
|
8278
|
+
const editable = !!(recordPermissions && recordPermissions.allowEdit);
|
|
8279
|
+
if(!editable){
|
|
8280
|
+
// 没有权限时还原
|
|
8281
|
+
revert && revert();
|
|
8282
|
+
}
|
|
8283
|
+
payload.data.editable = editable;
|
|
8284
|
+
return payload;
|
|
8285
|
+
`;
|
|
8286
|
+
return api;
|
|
8287
|
+
}
|
|
8193
8288
|
|
|
8194
|
-
|
|
8195
|
-
|
|
8289
|
+
function getCalendarRecordSaveApi(object, calendarOptions) {
|
|
8290
|
+
const formData = {};
|
|
8291
|
+
const idFieldName = object.idFieldName || "_id";
|
|
8292
|
+
formData[idFieldName] = "${event.data.event.id}";
|
|
8293
|
+
const nameFieldKey = object.NAME_FIELD_KEY || "name";
|
|
8294
|
+
formData[nameFieldKey] = "${event.data.event.title}";
|
|
8295
|
+
formData[calendarOptions.startDateExpr] = "${event.data.event.start}";
|
|
8296
|
+
formData[calendarOptions.endDateExpr] = "${event.data.event.end}";
|
|
8297
|
+
formData[calendarOptions.allDayExpr] = "${event.data.event.allDay}";
|
|
8298
|
+
// formData[calendarOptions.textExpr] = "${event.data.event.title}";
|
|
8299
|
+
const apiData = {
|
|
8300
|
+
objectName: "${objectName}",
|
|
8301
|
+
$: formData,
|
|
8302
|
+
$self: "$$"
|
|
8303
|
+
};
|
|
8304
|
+
const saveDataTpl = `
|
|
8305
|
+
const formData = api.data.$;
|
|
8306
|
+
const objectName = api.data.objectName;
|
|
8307
|
+
let query = \`mutation{record: \${objectName}__update(id: "\${formData.${idFieldName}}", doc: {__saveData}){${idFieldName}}}\`;
|
|
8308
|
+
delete formData.${idFieldName};
|
|
8309
|
+
let __saveData = JSON.stringify(JSON.stringify(formData));
|
|
8310
|
+
`;
|
|
8311
|
+
const requestAdaptor = `
|
|
8312
|
+
${saveDataTpl}
|
|
8313
|
+
api.data.query = query.replace('{__saveData}', __saveData);
|
|
8314
|
+
return api;
|
|
8315
|
+
`;
|
|
8196
8316
|
|
|
8197
|
-
|
|
8198
|
-
|
|
8317
|
+
return {
|
|
8318
|
+
method: 'post',
|
|
8319
|
+
url: getApi$2(),
|
|
8320
|
+
data: apiData,
|
|
8321
|
+
requestAdaptor: requestAdaptor,
|
|
8322
|
+
adaptor: `
|
|
8323
|
+
if(payload.errors){
|
|
8324
|
+
payload.status = 2;
|
|
8325
|
+
payload.msg = payload.errors[0].message;
|
|
8326
|
+
const revert = api.data.$self.event.data.revert;
|
|
8327
|
+
revert && revert();
|
|
8328
|
+
}
|
|
8329
|
+
return payload;
|
|
8330
|
+
`,
|
|
8331
|
+
headers: {
|
|
8332
|
+
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
8199
8333
|
}
|
|
8334
|
+
};
|
|
8335
|
+
}
|
|
8200
8336
|
|
|
8201
|
-
|
|
8202
|
-
|
|
8203
|
-
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
|
|
8211
|
-
let selfData = JSON.parse(JSON.stringify(api.data.$self));
|
|
8212
|
-
// 保留一份初始data,以供自定义发送适配器中获取原始数据。
|
|
8213
|
-
const data = _.cloneDeep(api.data);
|
|
8214
|
-
try{
|
|
8215
|
-
// TODO: 不应该直接在这里取localStorage,应该从外面传入
|
|
8216
|
-
const listViewId = api.data.listViewId;
|
|
8217
|
-
const listViewPropsStoreKey = location.pathname + "/crud/" + listViewId ;
|
|
8218
|
-
let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
|
|
8219
|
-
if(localListViewProps){
|
|
8220
|
-
localListViewProps = JSON.parse(localListViewProps);
|
|
8221
|
-
selfData = Object.assign({}, localListViewProps, selfData);
|
|
8222
|
-
if(!api.data.filter){
|
|
8223
|
-
api.data.filter = localListViewProps.filter;
|
|
8224
|
-
}
|
|
8225
|
-
if(!api.data.loaded){
|
|
8226
|
-
// 第一次加载组件,比如刷新浏览器时因为api.data.pageNo有默认值1
|
|
8227
|
-
// 所以会把localSearchableFilter中已经存过的页码覆盖
|
|
8228
|
-
// 如果是第一次加载组件始终让翻页页码从本地存储中取值
|
|
8229
|
-
let formFactor = "${options.formFactor}";
|
|
8230
|
-
// 移动端不识别本地存储中的翻页页码,否则点击加载更多按钮后无法刷新回第一页
|
|
8231
|
-
api.data.pageNo = formFactor === "SMALL" ? 1 : (localListViewProps.page || 1);
|
|
8232
|
-
}
|
|
8233
|
-
}
|
|
8234
|
-
}
|
|
8235
|
-
catch(ex){
|
|
8236
|
-
console.error("本地存储中crud参数解析异常:", ex);
|
|
8237
|
-
}
|
|
8238
|
-
${baseFilters ? `var systemFilters = ${JSON.stringify(baseFilters)};` : 'var systemFilters = [];'}
|
|
8239
|
-
var _ids = []
|
|
8240
|
-
const filtersFunction = ${filtersFunction};
|
|
8241
|
-
if(filtersFunction){
|
|
8242
|
-
const _filters = filtersFunction(systemFilters, api.data.$self);
|
|
8243
|
-
if(api.data.listName == "recent"){
|
|
8244
|
-
_ids = _filters[2]
|
|
8245
|
-
}
|
|
8246
|
-
if(_filters && _filters.length > 0){
|
|
8247
|
-
if(_.isEmpty(systemFilters)){
|
|
8248
|
-
systemFilters = _filters || [];
|
|
8249
|
-
}else{
|
|
8250
|
-
systemFilters = [systemFilters, 'and', _filters];
|
|
8251
|
-
}
|
|
8252
|
-
}
|
|
8253
|
-
}
|
|
8254
|
-
let userFilters =[];
|
|
8255
|
-
|
|
8256
|
-
if(_.isEmpty(systemFilters)){
|
|
8257
|
-
systemFilters = api.data.filter || [];
|
|
8258
|
-
}else{
|
|
8259
|
-
if(!_.isEmpty(api.data.filter)){
|
|
8260
|
-
systemFilters = [systemFilters, 'and', api.data.filter];
|
|
8261
|
-
}
|
|
8262
|
-
}
|
|
8263
|
-
var pageSize = api.data.pageSize || 10;
|
|
8264
|
-
var pageNo = api.data.pageNo || 1;
|
|
8265
|
-
var skip = (pageNo - 1) * pageSize;
|
|
8266
|
-
var orderBy = api.data.orderBy || '';
|
|
8267
|
-
var orderDir = api.data.orderDir || '';
|
|
8268
|
-
var sort = orderBy + ' ' + orderDir;
|
|
8269
|
-
sort = orderBy ? sort : "${sort || ''}";
|
|
8270
|
-
var allowSearchFields = ${JSON.stringify(searchableFields)};
|
|
8271
|
-
if(api.data.$term){
|
|
8272
|
-
userFilters = [["name", "contains", "'+ api.data.$term +'"]];
|
|
8273
|
-
}else if(selfData.op === 'loadOptions' && selfData.value){
|
|
8274
|
-
userFilters = [["${valueField.name}", "=", selfData.value]];
|
|
8275
|
-
}
|
|
8276
|
-
|
|
8277
|
-
var searchableFilter = SteedosUI.getSearchFilter(selfData) || [];
|
|
8337
|
+
/**
|
|
8338
|
+
* 列表视图Calendar amisSchema
|
|
8339
|
+
* @param {*} objectSchema 对象UISchema
|
|
8340
|
+
* @returns amisSchema
|
|
8341
|
+
*/
|
|
8342
|
+
async function getObjectCalendar(objectSchema, calendarOptions, options) {
|
|
8343
|
+
const permissions = objectSchema.permissions;
|
|
8344
|
+
if (!options) {
|
|
8345
|
+
options = {};
|
|
8346
|
+
}
|
|
8278
8347
|
|
|
8279
|
-
|
|
8280
|
-
if(userFilters.length > 0 ){
|
|
8281
|
-
userFilters = [userFilters, 'and', searchableFilter];
|
|
8282
|
-
}else{
|
|
8283
|
-
userFilters = searchableFilter;
|
|
8284
|
-
}
|
|
8285
|
-
}
|
|
8348
|
+
calendarOptions = Object.assign({}, DEFAULT_CALENDAR_OPTIONS, _$1.omitBy(calendarOptions, _$1.isNil));
|
|
8286
8349
|
|
|
8287
|
-
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8350
|
+
const titleFields = calendarOptions.title || [
|
|
8351
|
+
calendarOptions.startDateExpr,
|
|
8352
|
+
calendarOptions.endDateExpr,
|
|
8353
|
+
calendarOptions.allDayExpr,
|
|
8354
|
+
calendarOptions.textExpr
|
|
8355
|
+
];
|
|
8356
|
+
let fields = [];
|
|
8357
|
+
_$1.each(titleFields, function (n) {
|
|
8358
|
+
if (objectSchema.fields[n]) {
|
|
8359
|
+
fields.push(objectSchema.fields[n]);
|
|
8360
|
+
}
|
|
8361
|
+
});
|
|
8297
8362
|
|
|
8298
|
-
|
|
8299
|
-
|
|
8300
|
-
|
|
8301
|
-
const keyValue = selfData.__keywords;
|
|
8302
|
-
if(keyValue){
|
|
8303
|
-
keywordsFilters.push([key, "contains", keyValue]);
|
|
8304
|
-
if(index < allowSearchFields.length - 1){
|
|
8305
|
-
keywordsFilters.push('or');
|
|
8306
|
-
}
|
|
8307
|
-
}
|
|
8308
|
-
})
|
|
8309
|
-
userFilters.push(keywordsFilters);
|
|
8310
|
-
};
|
|
8363
|
+
if (objectSchema.fields[calendarOptions.allDayExpr]) {
|
|
8364
|
+
fields.push(objectSchema.fields[calendarOptions.allDayExpr]);
|
|
8365
|
+
}
|
|
8311
8366
|
|
|
8312
|
-
|
|
8367
|
+
let sort = options.sort;
|
|
8368
|
+
if (!sort) {
|
|
8369
|
+
const sortField = options.sortField;
|
|
8370
|
+
const sortOrder = options.sortOrder;
|
|
8371
|
+
if (sortField) {
|
|
8372
|
+
let sortStr = sortField + ' ' + sortOrder || 'asc';
|
|
8373
|
+
sort = sortStr;
|
|
8374
|
+
}
|
|
8375
|
+
}
|
|
8376
|
+
let initialView = calendarOptions.currentView;
|
|
8377
|
+
if (initialView) {
|
|
8378
|
+
// day, week, month, agenda
|
|
8379
|
+
switch (initialView) {
|
|
8380
|
+
case "day":
|
|
8381
|
+
initialView = "timeGridDay";
|
|
8382
|
+
break;
|
|
8383
|
+
case "week":
|
|
8384
|
+
initialView = "timeGridWeek";
|
|
8385
|
+
break;
|
|
8386
|
+
case "month":
|
|
8387
|
+
initialView = "dayGridMonth";
|
|
8388
|
+
break;
|
|
8389
|
+
case "agenda":
|
|
8390
|
+
initialView = "listWeek";
|
|
8391
|
+
break;
|
|
8392
|
+
}
|
|
8393
|
+
}
|
|
8394
|
+
else {
|
|
8395
|
+
initialView = "timeGridWeek";
|
|
8396
|
+
}
|
|
8313
8397
|
|
|
8314
|
-
|
|
8315
|
-
|
|
8316
|
-
};
|
|
8317
|
-
if(api.data.$self.additionalFilters){
|
|
8318
|
-
if(_.isString(api.data.$self.additionalFilters)){
|
|
8319
|
-
userFilters.push(eval(api.data.$self.additionalFilters))
|
|
8320
|
-
}else{
|
|
8321
|
-
userFilters.push(api.data.$self.additionalFilters)
|
|
8322
|
-
}
|
|
8323
|
-
}
|
|
8398
|
+
options.calendarOptions = calendarOptions;
|
|
8399
|
+
const api = await getCalendarApi(objectSchema, fields, options);
|
|
8324
8400
|
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
|
|
8328
|
-
|
|
8329
|
-
|
|
8330
|
-
|
|
8331
|
-
|
|
8332
|
-
|
|
8333
|
-
|
|
8334
|
-
|
|
8335
|
-
|
|
8336
|
-
|
|
8337
|
-
|
|
8338
|
-
|
|
8339
|
-
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
|
|
8343
|
-
|
|
8344
|
-
|
|
8345
|
-
|
|
8401
|
+
const onGetEventsScript = `
|
|
8402
|
+
const api = ${JSON.stringify(api)};
|
|
8403
|
+
event.data.calendarOptions = ${JSON.stringify(calendarOptions)};
|
|
8404
|
+
doAction({
|
|
8405
|
+
"actionType": 'ajax',
|
|
8406
|
+
"args": {
|
|
8407
|
+
"api": api
|
|
8408
|
+
},
|
|
8409
|
+
});
|
|
8410
|
+
`;
|
|
8411
|
+
|
|
8412
|
+
const onSelectScript = `
|
|
8413
|
+
const data = event.data;
|
|
8414
|
+
const doc = {};
|
|
8415
|
+
doc["${calendarOptions.startDateExpr}"] = data.start;
|
|
8416
|
+
doc["${calendarOptions.endDateExpr}"] = data.end;
|
|
8417
|
+
doc["${calendarOptions.allDayExpr}"] = data.allDay;
|
|
8418
|
+
doc["${calendarOptions.textExpr}"] = data.title;
|
|
8419
|
+
// ObjectForm会认作用域下的变量值
|
|
8420
|
+
// TODO: 待组件支持initValues属性后应该改掉,不应该通过data直接传值
|
|
8421
|
+
// TODO: 全天事件属性传入doc了但是没有生效,需要手动在ObjectForm中勾选全天事件
|
|
8422
|
+
const title = "新建 ${objectSchema.label}";
|
|
8423
|
+
doAction(
|
|
8424
|
+
{
|
|
8425
|
+
"actionType": "dialog",
|
|
8426
|
+
"dialog": {
|
|
8427
|
+
"type": "dialog",
|
|
8428
|
+
"title": title,
|
|
8429
|
+
"body": [
|
|
8430
|
+
{
|
|
8431
|
+
"type": "steedos-object-form",
|
|
8432
|
+
"objectApiName": "\${objectName}",
|
|
8433
|
+
"mode": "edit",
|
|
8434
|
+
"defaultData": doc,
|
|
8435
|
+
"onEvent": {
|
|
8436
|
+
"submitSucc": {
|
|
8437
|
+
"weight": 0,
|
|
8438
|
+
"actions": [
|
|
8439
|
+
{
|
|
8440
|
+
"actionType": "custom",
|
|
8441
|
+
"script": "event.data.view?.calendar.refetchEvents();"
|
|
8442
|
+
}
|
|
8443
|
+
]
|
|
8444
|
+
}
|
|
8445
|
+
}
|
|
8346
8446
|
}
|
|
8347
|
-
|
|
8447
|
+
],
|
|
8448
|
+
"closeOnEsc": false,
|
|
8449
|
+
"closeOnOutside": false,
|
|
8450
|
+
"showCloseButton": true,
|
|
8451
|
+
"size": "lg"
|
|
8348
8452
|
}
|
|
8453
|
+
});
|
|
8454
|
+
`;
|
|
8349
8455
|
|
|
8350
|
-
|
|
8351
|
-
|
|
8352
|
-
|
|
8353
|
-
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
|
|
8357
|
-
|
|
8358
|
-
|
|
8359
|
-
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
|
|
8364
|
-
|
|
8365
|
-
|
|
8366
|
-
|
|
8367
|
-
|
|
8368
|
-
|
|
8456
|
+
const onEventClickScript = `
|
|
8457
|
+
const data = event.data;
|
|
8458
|
+
const eventData = data.event;
|
|
8459
|
+
const appId = data.appId;
|
|
8460
|
+
const objectName = data.objectName;
|
|
8461
|
+
const eventId = data.event && data.event.id;
|
|
8462
|
+
doAction({
|
|
8463
|
+
"actionType": "dialog",
|
|
8464
|
+
"dialog": {
|
|
8465
|
+
"type": "dialog",
|
|
8466
|
+
"title": "",
|
|
8467
|
+
"body": [
|
|
8468
|
+
{
|
|
8469
|
+
"type": "steedos-record-detail",
|
|
8470
|
+
"objectApiName": "\${objectName}",
|
|
8471
|
+
"recordId": data.event && data.event.id
|
|
8472
|
+
}
|
|
8473
|
+
],
|
|
8474
|
+
"closeOnEsc": false,
|
|
8475
|
+
"closeOnOutside": false,
|
|
8476
|
+
"showCloseButton": true,
|
|
8477
|
+
"size": "lg",
|
|
8478
|
+
"actions": []
|
|
8479
|
+
}
|
|
8480
|
+
});
|
|
8481
|
+
`;
|
|
8482
|
+
|
|
8483
|
+
const recordId = "${event.id}";
|
|
8484
|
+
const recordPermissionsApi = getCalendarRecordPermissionsApi(objectSchema, recordId);
|
|
8485
|
+
const recordSaveApi = getCalendarRecordSaveApi(objectSchema, calendarOptions);
|
|
8486
|
+
|
|
8487
|
+
const businessHours = {
|
|
8488
|
+
daysOfWeek: [1, 2, 3, 4, 5],
|
|
8489
|
+
startTime: '08:00',
|
|
8490
|
+
endTime: '18:00',
|
|
8491
|
+
};
|
|
8492
|
+
if (!_$1.isEmpty(calendarOptions.startDayHour)) {
|
|
8493
|
+
businessHours.startTime = `${calendarOptions.startDayHour}:00`;
|
|
8369
8494
|
}
|
|
8370
|
-
|
|
8371
|
-
|
|
8372
|
-
_.each(payload.data.rows, function(item, index){
|
|
8373
|
-
const {pageNo, pageSize} = api.body;
|
|
8374
|
-
const skip = (pageNo - 1) * pageSize;
|
|
8375
|
-
item._index = skip + index + 1;
|
|
8376
|
-
})
|
|
8495
|
+
if (!_$1.isEmpty(calendarOptions.endDayHour)) {
|
|
8496
|
+
businessHours.endTime = `${calendarOptions.endDayHour}:00`;
|
|
8377
8497
|
}
|
|
8378
|
-
|
|
8379
|
-
|
|
8380
|
-
|
|
8381
|
-
|
|
8382
|
-
|
|
8383
|
-
|
|
8384
|
-
|
|
8385
|
-
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8389
|
-
|
|
8390
|
-
|
|
8391
|
-
|
|
8392
|
-
|
|
8498
|
+
|
|
8499
|
+
const onEvent = {
|
|
8500
|
+
"getEvents": {
|
|
8501
|
+
"weight": 0,
|
|
8502
|
+
"actions": [
|
|
8503
|
+
{
|
|
8504
|
+
"componentId": "",
|
|
8505
|
+
"args": {
|
|
8506
|
+
},
|
|
8507
|
+
"actionType": "custom",
|
|
8508
|
+
"script": onGetEventsScript
|
|
8509
|
+
}
|
|
8510
|
+
]
|
|
8511
|
+
},
|
|
8512
|
+
"select": {
|
|
8513
|
+
"weight": 0,
|
|
8514
|
+
"actions": [
|
|
8515
|
+
{
|
|
8516
|
+
"componentId": "",
|
|
8517
|
+
"args": {
|
|
8518
|
+
},
|
|
8519
|
+
"actionType": "custom",
|
|
8520
|
+
"script": onSelectScript
|
|
8521
|
+
}
|
|
8522
|
+
]
|
|
8523
|
+
},
|
|
8524
|
+
"eventClick": {
|
|
8525
|
+
"weight": 0,
|
|
8526
|
+
"actions": [
|
|
8527
|
+
{
|
|
8528
|
+
"componentId": "",
|
|
8529
|
+
"args": {
|
|
8530
|
+
},
|
|
8531
|
+
"actionType": "custom",
|
|
8532
|
+
"script": onEventClickScript
|
|
8533
|
+
}
|
|
8534
|
+
]
|
|
8535
|
+
},
|
|
8536
|
+
"eventAdd": {
|
|
8537
|
+
"weight": 0,
|
|
8538
|
+
"actions": [
|
|
8539
|
+
{
|
|
8540
|
+
"componentId": "",
|
|
8541
|
+
"args": {
|
|
8542
|
+
},
|
|
8543
|
+
"actionType": "custom",
|
|
8544
|
+
"script": "console.log('eventAdd'); console.log(event);"
|
|
8545
|
+
}
|
|
8546
|
+
]
|
|
8547
|
+
},
|
|
8548
|
+
"eventChange": {
|
|
8549
|
+
"weight": 0,
|
|
8550
|
+
"actions": [
|
|
8551
|
+
{
|
|
8552
|
+
"actionType": 'ajax',
|
|
8553
|
+
"args": {
|
|
8554
|
+
"api": recordPermissionsApi
|
|
8393
8555
|
}
|
|
8394
|
-
|
|
8395
|
-
|
|
8396
|
-
|
|
8397
|
-
|
|
8398
|
-
|
|
8399
|
-
|
|
8400
|
-
|
|
8556
|
+
},
|
|
8557
|
+
{
|
|
8558
|
+
"actionType": "toast",
|
|
8559
|
+
"expression": "!event.data.editable",
|
|
8560
|
+
"args": {
|
|
8561
|
+
"msgType": "error",
|
|
8562
|
+
"msg": "您没有编辑该记录的权限!",
|
|
8563
|
+
"position": "top-center"
|
|
8401
8564
|
}
|
|
8402
|
-
|
|
8403
|
-
|
|
8404
|
-
|
|
8405
|
-
|
|
8406
|
-
|
|
8407
|
-
|
|
8408
|
-
|
|
8409
|
-
|
|
8565
|
+
},
|
|
8566
|
+
{
|
|
8567
|
+
"actionType": 'ajax',
|
|
8568
|
+
"expression": "event.data.editable",
|
|
8569
|
+
"args": {
|
|
8570
|
+
"api": recordSaveApi,
|
|
8571
|
+
"messages": {
|
|
8572
|
+
"success": objectSchema.label + "修改成功",
|
|
8573
|
+
"failed": objectSchema.label + "修改失败!"
|
|
8574
|
+
}
|
|
8575
|
+
}
|
|
8576
|
+
}
|
|
8577
|
+
]
|
|
8578
|
+
},
|
|
8579
|
+
"eventRemove": {
|
|
8580
|
+
"weight": 0,
|
|
8581
|
+
"actions": [
|
|
8582
|
+
{
|
|
8583
|
+
"componentId": "",
|
|
8584
|
+
"args": {
|
|
8585
|
+
},
|
|
8586
|
+
"actionType": "custom",
|
|
8587
|
+
"script": "console.log('eventRemove'); console.log(event);"
|
|
8588
|
+
}
|
|
8589
|
+
]
|
|
8590
|
+
},
|
|
8591
|
+
"eventsSet": {
|
|
8592
|
+
"weight": 0,
|
|
8593
|
+
"actions": [
|
|
8594
|
+
{
|
|
8595
|
+
"componentId": "",
|
|
8596
|
+
"args": {
|
|
8597
|
+
},
|
|
8598
|
+
"actionType": "custom",
|
|
8599
|
+
"script": "console.log('eventsSet'); console.log(event);"
|
|
8600
|
+
}
|
|
8601
|
+
]
|
|
8602
|
+
}
|
|
8603
|
+
};
|
|
8410
8604
|
|
|
8605
|
+
Object.assign(onEvent, options.onEvent);
|
|
8411
8606
|
|
|
8412
|
-
|
|
8413
|
-
|
|
8414
|
-
|
|
8415
|
-
|
|
8416
|
-
|
|
8417
|
-
|
|
8418
|
-
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
* page:当前页码
|
|
8423
|
-
* orderBy:排序字段
|
|
8424
|
-
* orderDir:排序方向
|
|
8425
|
-
*/
|
|
8426
|
-
let localListViewProps = sessionStorage.getItem(listViewPropsStoreKey);
|
|
8427
|
-
let selfData = JSON.parse(JSON.stringify(api.body.$self));
|
|
8428
|
-
if(localListViewProps){
|
|
8429
|
-
localListViewProps = JSON.parse(localListViewProps);
|
|
8430
|
-
selfData = Object.assign({}, localListViewProps, selfData, { filter: api.body.filter });
|
|
8431
|
-
if(!api.body.loaded){
|
|
8432
|
-
// 第一次加载组件,比如刷新浏览器时因为api.data.pageNo有默认值1
|
|
8433
|
-
// 所以会把localSearchableFilter中已经存过的页码覆盖
|
|
8434
|
-
// 如果是第一次加载组件始终让翻页页码从本地存储中取值
|
|
8435
|
-
let formFactor = "${options.formFactor}";
|
|
8436
|
-
// 移动端不识别本地存储中的翻页页码,否则点击加载更多按钮后无法刷新回第一页
|
|
8437
|
-
selfData.page = formFactor === "SMALL" ? 1 : (localListViewProps.page || 1);
|
|
8438
|
-
}
|
|
8607
|
+
const config = options.config || {};
|
|
8608
|
+
if(config.eventContent && typeof config.eventContent === "string"){
|
|
8609
|
+
const hasReturn = /\breturn\b/.test(config.eventContent);
|
|
8610
|
+
if(hasReturn){
|
|
8611
|
+
try {
|
|
8612
|
+
// 如果是包括return语句的字符串,则按函数解析,见 https://fullcalendar.io/docs/content-injection
|
|
8613
|
+
let fn = new Function("arg", config.eventContent);
|
|
8614
|
+
config.eventContent = fn;
|
|
8615
|
+
} catch (e) {
|
|
8616
|
+
console.warn(e);
|
|
8439
8617
|
}
|
|
8440
|
-
|
|
8441
|
-
delete selfData.global;
|
|
8442
|
-
sessionStorage.setItem(listViewPropsStoreKey, JSON.stringify(selfData));
|
|
8443
|
-
// 返回页码到UI界面
|
|
8444
|
-
payload.data.page= selfData.page;
|
|
8618
|
+
}
|
|
8445
8619
|
}
|
|
8446
|
-
|
|
8447
|
-
|
|
8620
|
+
|
|
8621
|
+
if(config.noEventsContent && typeof config.noEventsContent === "string"){
|
|
8622
|
+
const hasReturn = /\breturn\b/.test(config.noEventsContent);
|
|
8623
|
+
if(hasReturn){
|
|
8624
|
+
try {
|
|
8625
|
+
// 如果是包括return语句的字符串,则按函数解析,见 https://fullcalendar.io/docs/content-injection
|
|
8626
|
+
let fn = new Function("arg", config.noEventsContent);
|
|
8627
|
+
config.noEventsContent = fn;
|
|
8628
|
+
} catch (e) {
|
|
8629
|
+
console.warn(e);
|
|
8630
|
+
}
|
|
8631
|
+
}
|
|
8448
8632
|
}
|
|
8449
|
-
// 标记加载过,后续优先从本地存储中加载相关参数
|
|
8450
|
-
payload.data.loaded= true;
|
|
8451
8633
|
|
|
8452
|
-
const
|
|
8453
|
-
|
|
8454
|
-
|
|
8634
|
+
const amisSchema = {
|
|
8635
|
+
"type": "steedos-fullcalendar",
|
|
8636
|
+
"label": "",
|
|
8637
|
+
"name": "fullcalendar",
|
|
8638
|
+
"placeholder":"${additionalFilters}",//用于触发reload
|
|
8639
|
+
"editable": permissions.allowEdit,
|
|
8640
|
+
"selectable": permissions.allowCreate,
|
|
8641
|
+
"selectMirror": permissions.allowCreate,
|
|
8642
|
+
"initialView": initialView,
|
|
8643
|
+
"businessHours": businessHours,
|
|
8644
|
+
...config,
|
|
8645
|
+
"onEvent": onEvent
|
|
8455
8646
|
};
|
|
8456
|
-
|
|
8457
|
-
return payload;
|
|
8458
|
-
`;
|
|
8459
|
-
return api;
|
|
8647
|
+
return amisSchema;
|
|
8460
8648
|
}
|
|
8461
8649
|
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
8465
|
-
|
|
8466
|
-
|
|
8467
|
-
|
|
8468
|
-
|
|
8469
|
-
|
|
8470
|
-
|
|
8650
|
+
/*
|
|
8651
|
+
* @Author: baozhoutao@steedos.com
|
|
8652
|
+
* @Date: 2022-05-26 16:02:08
|
|
8653
|
+
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
|
|
8654
|
+
* @LastEditTime: 2023-06-04 15:49:23
|
|
8655
|
+
* @Description:
|
|
8656
|
+
*/
|
|
8657
|
+
|
|
8658
|
+
const getFieldSchemaArray = (formFields) => {
|
|
8659
|
+
let fieldSchemaArray = [];
|
|
8660
|
+
fieldSchemaArray.length = 0;
|
|
8661
|
+
|
|
8662
|
+
___namespace.forEach(formFields, (field) => {
|
|
8663
|
+
if (!field.group || field.group == 'null' || field.group == '-')
|
|
8664
|
+
field.group = '通用';
|
|
8665
|
+
const fieldName = field.name;
|
|
8666
|
+
let isObjectField = /\w+\.\w+/.test(fieldName);
|
|
8667
|
+
if (field.type == 'grid' || field.type == 'object') {
|
|
8668
|
+
// field.group = field.label
|
|
8669
|
+
field.is_wide = true;
|
|
8471
8670
|
}
|
|
8472
|
-
}
|
|
8473
8671
|
|
|
8474
|
-
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
url: getApi$2(),
|
|
8479
|
-
data: data,
|
|
8480
|
-
headers: {
|
|
8481
|
-
Authorization: "Bearer ${context.tenantId},${context.authToken}"
|
|
8482
|
-
}
|
|
8672
|
+
if (!isObjectField) {
|
|
8673
|
+
if (!field.hidden) {
|
|
8674
|
+
fieldSchemaArray.push(Object.assign({ name: fieldName }, field, { permission: { allowEdit: true } }));
|
|
8675
|
+
}
|
|
8483
8676
|
}
|
|
8484
|
-
|
|
8677
|
+
});
|
|
8678
|
+
return fieldSchemaArray;
|
|
8679
|
+
};
|
|
8485
8680
|
|
|
8486
|
-
const
|
|
8487
|
-
|
|
8488
|
-
|
|
8489
|
-
|
|
8490
|
-
|
|
8681
|
+
const getSection = async (formFields, permissionFields, fieldSchemaArray, sectionName, ctx) => {
|
|
8682
|
+
if (!ctx) {
|
|
8683
|
+
ctx = {};
|
|
8684
|
+
}
|
|
8685
|
+
const sectionFields = ___namespace.filter(fieldSchemaArray, { 'group': sectionName });
|
|
8686
|
+
if (sectionFields.length == ___namespace.filter(sectionFields, ['hidden', true]).length) {
|
|
8687
|
+
return;
|
|
8688
|
+
}
|
|
8689
|
+
|
|
8690
|
+
const fieldSetBody = [];
|
|
8691
|
+
|
|
8692
|
+
for (const perField of sectionFields) {
|
|
8693
|
+
let field = perField;
|
|
8694
|
+
if (perField.type === 'grid') {
|
|
8695
|
+
field = await getGridFieldSubFields(perField, formFields);
|
|
8696
|
+
// console.log(`perField.type grid ===> field`, field)
|
|
8697
|
+
} else if (perField.type === 'object') {
|
|
8698
|
+
field = await getObjectFieldSubFields(perField, formFields);
|
|
8699
|
+
// console.log(`perField.type object ===> field`, field)
|
|
8700
|
+
}
|
|
8701
|
+
if (field.name.indexOf(".") < 0) {
|
|
8702
|
+
ctx.__formFields = formFields;
|
|
8703
|
+
const amisField = await convertSFieldToAmisField(field, field.readonly, ctx);
|
|
8704
|
+
// console.log(`${field.name} amisField`, field, amisField)
|
|
8705
|
+
if (amisField) {
|
|
8706
|
+
fieldSetBody.push(amisField);
|
|
8707
|
+
}
|
|
8708
|
+
}
|
|
8709
|
+
}
|
|
8710
|
+
|
|
8711
|
+
// fieldSet 已支持显隐控制
|
|
8712
|
+
const sectionFieldsVisibleOn = ___namespace.map(___namespace.compact(___namespace.map(fieldSetBody, 'visibleOn')), (visibleOn) => {
|
|
8713
|
+
return visibleOn;
|
|
8714
|
+
});
|
|
8715
|
+
|
|
8716
|
+
let section = {
|
|
8717
|
+
"type": "fieldSet",
|
|
8718
|
+
"title": sectionName,
|
|
8719
|
+
"collapsable": true,
|
|
8720
|
+
"body": fieldSetBody,
|
|
8721
|
+
};
|
|
8722
|
+
|
|
8723
|
+
if (ctx.enableTabs) {
|
|
8724
|
+
section = {
|
|
8725
|
+
"title": sectionName,
|
|
8726
|
+
"body": fieldSetBody,
|
|
8727
|
+
};
|
|
8728
|
+
}
|
|
8729
|
+
|
|
8730
|
+
if (sectionFieldsVisibleOn.length > 0 && fieldSetBody.length === sectionFieldsVisibleOn.length) {
|
|
8731
|
+
section.visibleOn = `${sectionFieldsVisibleOn.join(" || ")}`;
|
|
8732
|
+
}
|
|
8733
|
+
return section
|
|
8491
8734
|
};
|
|
8492
8735
|
|
|
8493
|
-
async
|
|
8494
|
-
if (!
|
|
8495
|
-
|
|
8736
|
+
const getSections = async (permissionFields, formFields, ctx) => {
|
|
8737
|
+
if (!ctx) {
|
|
8738
|
+
ctx = {};
|
|
8496
8739
|
}
|
|
8497
|
-
const
|
|
8498
|
-
const
|
|
8499
|
-
|
|
8740
|
+
const fieldSchemaArray = getFieldSchemaArray(formFields);
|
|
8741
|
+
const _sections = ___namespace.groupBy(fieldSchemaArray, 'group');
|
|
8742
|
+
const sections = [];
|
|
8743
|
+
var sectionVisibleOns = [];
|
|
8744
|
+
for (const key in _sections) {
|
|
8745
|
+
const section = await getSection(formFields, permissionFields, fieldSchemaArray, key, ctx);
|
|
8746
|
+
if (section.body.length > 0) {
|
|
8747
|
+
if (section.visibleOn) {
|
|
8748
|
+
sectionVisibleOns.push(section.visibleOn);
|
|
8749
|
+
}
|
|
8750
|
+
else {
|
|
8751
|
+
sectionVisibleOns.push("true");
|
|
8752
|
+
}
|
|
8753
|
+
sections.push(section);
|
|
8754
|
+
}
|
|
8755
|
+
}
|
|
8756
|
+
/*
|
|
8757
|
+
为了实现只有一个分组时隐藏该分组标题,需要分三种情况(分组如果没有visibleon属性就代表一定显示,有visibleon需要进行判断)
|
|
8758
|
+
1 当前分组为隐藏时,标题就设置为隐藏
|
|
8759
|
+
2 当前分组为显示时,其他分组只要有一个是显示,就显示该分组标题
|
|
8760
|
+
3 当前分组为显示时,其他分组都隐藏,就隐藏该分组标题
|
|
8761
|
+
*/
|
|
8762
|
+
sections.forEach((section, index) => {
|
|
8763
|
+
var tempSectionVisibleOns = sectionVisibleOns.slice();
|
|
8764
|
+
tempSectionVisibleOns.splice(index, 1);
|
|
8765
|
+
section.headingClassName = {
|
|
8766
|
+
"hidden": `!((${tempSectionVisibleOns.join(" || ") || 'false'}) && ${sectionVisibleOns[index]})`
|
|
8767
|
+
};
|
|
8768
|
+
});
|
|
8500
8769
|
|
|
8501
|
-
if (
|
|
8502
|
-
//
|
|
8503
|
-
|
|
8770
|
+
if (ctx.enableTabs) {
|
|
8771
|
+
// TODO: 以下sectionHeaderVisibleOn代码逻辑是为实现只有一个选项卡时给选项卡添加sectionHeaderVisibleOn样式类来把选项卡顶部卡头隐藏
|
|
8772
|
+
// 但是 amis filter过滤器有两个bug造成此功能不好实现:
|
|
8773
|
+
// 1.filter过滤器只支持对象数组,并不支持boolean或字符串数组,见: https://github.com/baidu/amis/issues/7078
|
|
8774
|
+
// 2.filter过滤器的返回结果无法进一步获取最终过滤后的数组长度,见:https://github.com/baidu/amis/issues/7077
|
|
8775
|
+
// let sectionHeaderVisibleOn = "false";
|
|
8776
|
+
// if(sectionVisibleOns.length){
|
|
8777
|
+
// sectionHeaderVisibleOn = "[" + sectionVisibleOns.join(",") + "]" + "|filter:equals:true.length > 1";
|
|
8778
|
+
// }
|
|
8779
|
+
// console.log("===sectionHeaderVisibleOn===", sectionHeaderVisibleOn);
|
|
8780
|
+
// sectionHeaderVisibleOn = "[true]|filter:equals:true.length > 1";
|
|
8781
|
+
// sectionHeaderVisibleOn = "false";
|
|
8782
|
+
// sectionHeaderVisibleOn = "[1,1,1]|filter:equals:1.length > 1";
|
|
8783
|
+
return [
|
|
8784
|
+
{
|
|
8785
|
+
"type": "tabs",
|
|
8786
|
+
// "className": {
|
|
8787
|
+
// "hiddenFormTabs": `!(${sectionHeaderVisibleOn})`
|
|
8788
|
+
// },
|
|
8789
|
+
"tabs": sections,
|
|
8790
|
+
"tabsMode": ctx.tabsMode
|
|
8791
|
+
}
|
|
8792
|
+
]
|
|
8504
8793
|
}
|
|
8505
8794
|
|
|
8506
|
-
|
|
8507
|
-
|
|
8508
|
-
|
|
8509
|
-
|
|
8510
|
-
|
|
8511
|
-
|
|
8795
|
+
return sections;
|
|
8796
|
+
};
|
|
8797
|
+
|
|
8798
|
+
/*
|
|
8799
|
+
* @Author: baozhoutao@steedos.com
|
|
8800
|
+
* @Date: 2022-07-07 11:02:29
|
|
8801
|
+
* @LastEditors: baozhoutao@steedos.com
|
|
8802
|
+
* @LastEditTime: 2023-03-07 17:19:34
|
|
8803
|
+
* @Description:
|
|
8804
|
+
*/
|
|
8805
|
+
|
|
8806
|
+
async function getFormBody(permissionFields, formFields, ctx){
|
|
8807
|
+
return await getSections(permissionFields, formFields, ctx);
|
|
8808
|
+
}
|
|
8809
|
+
|
|
8810
|
+
// lodash的defaultsDeep函数有bug,无法正确合并值为数值的节点,重写修正该函数
|
|
8811
|
+
// 源码出处:https://github.com/nodeutils/defaults-deep
|
|
8812
|
+
const defaultsDeep = (...args)=>{
|
|
8813
|
+
let output = {};
|
|
8814
|
+
_$1.toArray(args).reverse().forEach(item=> {
|
|
8815
|
+
_$1.mergeWith(output, item, (objectValue, sourceValue) => {
|
|
8816
|
+
return _$1.isArray(sourceValue) ? sourceValue : undefined;
|
|
8817
|
+
});
|
|
8818
|
+
});
|
|
8819
|
+
return output;
|
|
8820
|
+
};
|
|
8821
|
+
|
|
8822
|
+
function getBulkActions(objectSchema){
|
|
8823
|
+
return [
|
|
8824
|
+
{
|
|
8825
|
+
"type": "button",
|
|
8826
|
+
"level": "danger",
|
|
8827
|
+
"label": "批量删除",
|
|
8828
|
+
"actionType": "ajax",
|
|
8829
|
+
"confirmText": "确定要删除吗",
|
|
8830
|
+
"className": "hidden",
|
|
8831
|
+
"id": "batchDelete",
|
|
8832
|
+
"api": getBatchDelete(objectSchema.name),
|
|
8833
|
+
}
|
|
8834
|
+
// {
|
|
8835
|
+
// "label": "批量修改",
|
|
8836
|
+
// "actionType": "dialog",
|
|
8837
|
+
// "dialog": {
|
|
8838
|
+
// "title": "批量编辑",
|
|
8839
|
+
// "name": "sample-bulk-edit",
|
|
8840
|
+
// "body": {
|
|
8841
|
+
// "type": "form",
|
|
8842
|
+
// "api": "https://3xsw4ap8wah59.cfc-execute.bj.baidubce.com/api/amis-mock/sample/bulkUpdate2",
|
|
8843
|
+
// "controls": [
|
|
8844
|
+
// {
|
|
8845
|
+
// "type": "hidden",
|
|
8846
|
+
// "name": "ids"
|
|
8847
|
+
// },
|
|
8848
|
+
// {
|
|
8849
|
+
// "type": "text",
|
|
8850
|
+
// "name": "name",
|
|
8851
|
+
// "label": "Name"
|
|
8852
|
+
// }
|
|
8853
|
+
// ]
|
|
8854
|
+
// }
|
|
8855
|
+
// }
|
|
8856
|
+
// }
|
|
8857
|
+
]
|
|
8858
|
+
}
|
|
8859
|
+
|
|
8860
|
+
async function getObjectCRUD(objectSchema, fields, options){
|
|
8861
|
+
// console.time('getObjectCRUD');
|
|
8862
|
+
const { top, perPage, showDisplayAs = false, displayAs, crudClassName = "" } = options;
|
|
8863
|
+
const nonpaged = objectSchema.paging && objectSchema.paging.enabled === false;
|
|
8864
|
+
const isTreeObject = objectSchema.enable_tree;
|
|
8865
|
+
const bulkActions = getBulkActions(objectSchema);
|
|
8866
|
+
const bodyProps = {
|
|
8867
|
+
// toolbar: getToolbar(),
|
|
8868
|
+
// headerToolbar: getObjectHeaderToolbar(objectSchema, options.formFactor, {showDisplayAs}),
|
|
8869
|
+
headerToolbarClassName: "px-4 py-2 border-gray-300 bg-gray-100 border-solid border-b",
|
|
8870
|
+
footerToolbar: getObjectFooterToolbar(objectSchema, options.formFactor, {
|
|
8871
|
+
disableStatistics: options.queryCount === false
|
|
8872
|
+
}),
|
|
8873
|
+
filter: options.filterVisible !== false && await getObjectFilter(objectSchema, fields, options),
|
|
8874
|
+
};
|
|
8875
|
+
if(options.formFactor !== 'SMALL' || ["split"].indexOf(options.displayAs) == -1){
|
|
8876
|
+
Object.assign(bodyProps, {
|
|
8877
|
+
bulkActions: options.bulkActions != false ? bulkActions : false
|
|
8878
|
+
});
|
|
8879
|
+
}
|
|
8880
|
+
// yml里配置的 不分页和enable_tree:true 优先级最高,组件中输入的top次之。
|
|
8881
|
+
options.queryCount = true;
|
|
8882
|
+
if(nonpaged || isTreeObject){
|
|
8883
|
+
options.top = 5000;
|
|
8884
|
+
bodyProps.footerToolbar = [];
|
|
8885
|
+
options.queryCount = true; // 禁止翻页的时候, 需要查找总数
|
|
8886
|
+
}else if(top){
|
|
8887
|
+
bodyProps.footerToolbar = [];
|
|
8888
|
+
if(options.isRelated){
|
|
8889
|
+
options.queryCount = true;
|
|
8890
|
+
}else {
|
|
8891
|
+
options.queryCount = false;
|
|
8512
8892
|
}
|
|
8513
|
-
});
|
|
8514
|
-
}
|
|
8515
|
-
if (!filter) {
|
|
8516
|
-
filter = [];
|
|
8517
|
-
}
|
|
8518
|
-
|
|
8519
|
-
___default["default"].each(fields, function (field) {
|
|
8520
|
-
if (field.searchable) {
|
|
8521
|
-
searchableFields.push(field.name);
|
|
8522
8893
|
}
|
|
8523
|
-
|
|
8524
|
-
|
|
8525
|
-
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8529
|
-
|
|
8530
|
-
api.data.filter = "$filter";
|
|
8531
|
-
api.data.pageSize = top || 10;
|
|
8532
|
-
api.requestAdaptor = `
|
|
8533
|
-
let selfData = JSON.parse(JSON.stringify(api.data.$self));
|
|
8534
|
-
var filters = api.data.filter || ${JSON.stringify(filter)} || [];
|
|
8535
|
-
const eventFetchInfo = selfData.fetchInfo;
|
|
8536
|
-
const startDateExpr = "${calendarOptions.startDateExpr}";
|
|
8537
|
-
const endDateExpr = "${calendarOptions.endDateExpr}";
|
|
8538
|
-
const eventDurationFilters = [[endDateExpr, ">=", eventFetchInfo.start], [startDateExpr, "<=", eventFetchInfo.end]];
|
|
8539
|
-
if(_.isEmpty(filters)){
|
|
8540
|
-
filters = eventDurationFilters;
|
|
8541
|
-
}else{
|
|
8542
|
-
filters = [filters, 'and', eventDurationFilters]
|
|
8543
|
-
}
|
|
8544
|
-
|
|
8545
|
-
if(api.data.$self.additionalFilters){
|
|
8546
|
-
filters.push(api.data.$self.additionalFilters)
|
|
8547
|
-
}
|
|
8894
|
+
// console.log(`getObjectHeaderToolbar====2===>`, options.filterVisible)
|
|
8895
|
+
bodyProps.headerToolbar = getObjectHeaderToolbar(objectSchema, options.formFactor, {
|
|
8896
|
+
showDisplayAs,
|
|
8897
|
+
hiddenCount: options.queryCount === false,
|
|
8898
|
+
headerToolbarItems: options.headerToolbarItems,
|
|
8899
|
+
filterVisible: options.filterVisible
|
|
8900
|
+
});
|
|
8548
8901
|
|
|
8549
|
-
var pageSize = api.data.pageSize || 10;
|
|
8550
|
-
var pageNo = api.data.pageNo || 1;
|
|
8551
|
-
var skip = (pageNo - 1) * pageSize;
|
|
8552
|
-
var orderBy = api.data.orderBy || '';
|
|
8553
|
-
var orderDir = api.data.orderDir || '';
|
|
8554
|
-
var sort = orderBy + ' ' + orderDir;
|
|
8555
|
-
sort = orderBy ? sort : "${sort}";
|
|
8556
|
-
var allowSearchFields = ${JSON.stringify(searchableFields)};
|
|
8557
|
-
if(api.data.$term){
|
|
8558
|
-
filters = [["name", "contains", "'+ api.data.$term +'"]];
|
|
8559
|
-
}else if(selfData.op === 'loadOptions' && selfData.value){
|
|
8560
|
-
filters = [["${valueField.name}", "=", selfData.value]];
|
|
8561
|
-
}
|
|
8562
|
-
var searchableFilter = SteedosUI.getSearchFilter(selfData) || [];
|
|
8563
8902
|
|
|
8564
|
-
|
|
8565
|
-
|
|
8566
|
-
|
|
8567
|
-
|
|
8568
|
-
|
|
8903
|
+
let body = null;
|
|
8904
|
+
const id = `listview_${objectSchema.name}`;
|
|
8905
|
+
if(options.formFactor === 'SMALL' && false){
|
|
8906
|
+
delete bodyProps.bulkActions;
|
|
8907
|
+
delete bodyProps.headerToolbar;
|
|
8908
|
+
delete bodyProps.footerToolbar;
|
|
8909
|
+
const card = await getCardSchema(fields, Object.assign({idFieldName: objectSchema.idFieldName, labelFieldName: objectSchema.NAME_FIELD_KEY || 'name'}, options, {actions: false}));
|
|
8910
|
+
body = Object.assign({}, card , {
|
|
8911
|
+
type: 'crud',
|
|
8912
|
+
primaryField: '_id',
|
|
8913
|
+
id: id,
|
|
8914
|
+
name: id,
|
|
8915
|
+
keepItemSelectionOnPageChange: false,
|
|
8916
|
+
api: await getTableApi(objectSchema, fields, options),
|
|
8917
|
+
hiddenOn: options.tableHiddenOn,
|
|
8918
|
+
},
|
|
8919
|
+
bodyProps
|
|
8920
|
+
);
|
|
8921
|
+
}else {
|
|
8922
|
+
let labelFieldName = objectSchema.NAME_FIELD_KEY || 'name';
|
|
8923
|
+
// organizations 对象的历史遗留问题, fullname 被标记为了 名称字段. 在此处特殊处理.
|
|
8924
|
+
if(objectSchema.name === 'organizations'){
|
|
8925
|
+
labelFieldName = 'name';
|
|
8569
8926
|
}
|
|
8570
|
-
|
|
8571
|
-
|
|
8572
|
-
|
|
8573
|
-
|
|
8574
|
-
|
|
8575
|
-
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8927
|
+
const table = await getTableSchema$1(fields, Object.assign({idFieldName: objectSchema.idFieldName, labelFieldName: labelFieldName, permissions:objectSchema.permissions,enable_inline_edit:objectSchema.enable_inline_edit}, options));
|
|
8928
|
+
delete table.mode;
|
|
8929
|
+
//image与avatar需要在提交修改时特别处理
|
|
8930
|
+
const imageNames = ___default["default"].compact(___default["default"].map(___default["default"].filter(fields, (field) => ["image","avatar"].includes(field.type)), 'name'));
|
|
8931
|
+
const quickSaveApiRequestAdaptor = `
|
|
8932
|
+
var graphqlOrder = "";
|
|
8933
|
+
var imageNames = ${JSON.stringify(imageNames)};
|
|
8934
|
+
api.data.rowsDiff.forEach(function (item, index) {
|
|
8935
|
+
for(key in item){
|
|
8936
|
+
if(_.includes(imageNames, key)){
|
|
8937
|
+
if(typeof item[key] == "string"){
|
|
8938
|
+
const match = item[key].match(/\\/([^\\/]+)$/);
|
|
8939
|
+
item[key] = match && match.length > 1?match[1]:"";
|
|
8940
|
+
}else{
|
|
8941
|
+
item[key] = _.map(item[key], function(ele){
|
|
8942
|
+
const match = ele.match(/\\/([^\\/]+)$/);
|
|
8943
|
+
return match && match.length > 1?match[1]:"";
|
|
8944
|
+
})
|
|
8945
|
+
}
|
|
8579
8946
|
}
|
|
8947
|
+
}
|
|
8948
|
+
const itemOrder = 'update' + index + ':' + api.data.objectName + '__update(id:"' + item._id + '", doc:' + JSON.stringify(JSON.stringify(_.omit(item, '_id'))) + ') {_id}';
|
|
8949
|
+
graphqlOrder += itemOrder;
|
|
8580
8950
|
})
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8586
|
-
const keyValue = selfData.__keywords;
|
|
8587
|
-
if(keyValue){
|
|
8588
|
-
keywordsFilters.push([key, "contains", keyValue]);
|
|
8589
|
-
if(index < allowSearchFields.length - 1){
|
|
8590
|
-
keywordsFilters.push('or');
|
|
8591
|
-
}
|
|
8951
|
+
graphqlOrder = 'mutation {' + graphqlOrder + '}';
|
|
8952
|
+
return {
|
|
8953
|
+
...api,
|
|
8954
|
+
data: {
|
|
8955
|
+
query: graphqlOrder
|
|
8592
8956
|
}
|
|
8593
|
-
}
|
|
8594
|
-
|
|
8595
|
-
}
|
|
8596
|
-
api.data.query = api.data.query.replace(/{__filters}/g, JSON.stringify(filters)).replace('{__top}', pageSize).replace('{__skip}', skip).replace('{__sort}', sort.trim());
|
|
8597
|
-
delete api.data.$term;
|
|
8598
|
-
delete api.data.filter;
|
|
8599
|
-
delete api.data.pageSize;
|
|
8600
|
-
delete api.data.pageNo;
|
|
8601
|
-
delete api.data.orderBy;
|
|
8602
|
-
delete api.data.orderDir;
|
|
8603
|
-
return api;
|
|
8604
|
-
`;
|
|
8605
|
-
api.adaptor = `
|
|
8606
|
-
window.postMessage(Object.assign({type: "listview.loaded"}), "*");
|
|
8607
|
-
const setDataToComponentId = "${setDataToComponentId}";
|
|
8608
|
-
if(setDataToComponentId){
|
|
8609
|
-
SteedosUI.getRef(api.body.$self.scopeId)?.getComponentById(setDataToComponentId)?.setData({$count: payload.data.count})
|
|
8610
|
-
}
|
|
8611
|
-
const rows = payload.data.rows || [];
|
|
8612
|
-
const selfData = api.data.$self;
|
|
8613
|
-
const events = rows.map(function(n){
|
|
8614
|
-
return {
|
|
8615
|
-
id: n["${idFieldName}"],
|
|
8616
|
-
title: n["${calendarOptions.textExpr}"],
|
|
8617
|
-
start: n["${calendarOptions.startDateExpr}"],
|
|
8618
|
-
end: n["${calendarOptions.endDateExpr}"],
|
|
8619
|
-
allDay: n["${calendarOptions.allDayExpr}"],
|
|
8620
|
-
extendedProps: n
|
|
8621
|
-
}
|
|
8622
|
-
});
|
|
8623
|
-
const successCallback = selfData.successCallback;
|
|
8624
|
-
const failureCallback = selfData.failureCallback;
|
|
8625
|
-
successCallback(events);
|
|
8626
|
-
return payload;
|
|
8627
|
-
`;
|
|
8628
|
-
return api;
|
|
8629
|
-
}
|
|
8630
|
-
|
|
8631
|
-
function getCalendarRecordPermissionsApi(mainObject, recordId) {
|
|
8632
|
-
const api = getRecordPermissionsApi(mainObject, recordId, { alias: 'rows', limit: 1, fields: ["allowEdit"] });
|
|
8633
|
-
api.data.$self = "$$";
|
|
8634
|
-
api.adaptor = `
|
|
8635
|
-
const rows = payload.data.rows || [];
|
|
8636
|
-
const selfData = api.data.$self;
|
|
8637
|
-
const revert = selfData.revert;
|
|
8638
|
-
const recordPermissions = rows[0] && rows[0].recordPermissions;
|
|
8639
|
-
const editable = !!(recordPermissions && recordPermissions.allowEdit);
|
|
8640
|
-
if(!editable){
|
|
8641
|
-
// 没有权限时还原
|
|
8642
|
-
revert && revert();
|
|
8643
|
-
}
|
|
8644
|
-
payload.data.editable = editable;
|
|
8645
|
-
return payload;
|
|
8646
|
-
`;
|
|
8647
|
-
return api;
|
|
8648
|
-
}
|
|
8957
|
+
}
|
|
8958
|
+
`;
|
|
8649
8959
|
|
|
8650
|
-
|
|
8651
|
-
|
|
8652
|
-
|
|
8653
|
-
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8669
|
-
|
|
8670
|
-
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8675
|
-
|
|
8676
|
-
|
|
8960
|
+
body = Object.assign({}, table, {
|
|
8961
|
+
type: 'crud',
|
|
8962
|
+
primaryField: '_id',
|
|
8963
|
+
affixHeader: false,
|
|
8964
|
+
id: id,
|
|
8965
|
+
name: id,
|
|
8966
|
+
keepItemSelectionOnPageChange: true,
|
|
8967
|
+
api: await getTableApi(objectSchema, fields, options),
|
|
8968
|
+
hiddenOn: options.tableHiddenOn,
|
|
8969
|
+
autoFillHeight: options.isRelated ? false : true,
|
|
8970
|
+
className: `flex-auto ${crudClassName || ""}`,
|
|
8971
|
+
bodyClassName: "bg-white",
|
|
8972
|
+
crudClassName: crudClassName,
|
|
8973
|
+
quickSaveApi: {
|
|
8974
|
+
url: `\${context.rootUrl}/graphql`,
|
|
8975
|
+
method: "post",
|
|
8976
|
+
dataType: "json",
|
|
8977
|
+
headers: {
|
|
8978
|
+
Authorization: "Bearer ${context.tenantId},${context.authToken}",
|
|
8979
|
+
},
|
|
8980
|
+
requestAdaptor: quickSaveApiRequestAdaptor,
|
|
8981
|
+
},
|
|
8982
|
+
rowClassNameExpr: options.rowClassNameExpr
|
|
8983
|
+
},
|
|
8984
|
+
bodyProps,
|
|
8985
|
+
);
|
|
8986
|
+
}
|
|
8677
8987
|
|
|
8678
|
-
|
|
8679
|
-
|
|
8680
|
-
|
|
8681
|
-
|
|
8682
|
-
|
|
8683
|
-
|
|
8684
|
-
if(
|
|
8685
|
-
|
|
8686
|
-
|
|
8687
|
-
|
|
8688
|
-
|
|
8689
|
-
|
|
8690
|
-
|
|
8691
|
-
|
|
8692
|
-
|
|
8693
|
-
|
|
8988
|
+
const defaults = options.defaults;
|
|
8989
|
+
if (defaults) {
|
|
8990
|
+
const listSchema = defaults.listSchema || {};
|
|
8991
|
+
body = defaultsDeep({}, listSchema, body);
|
|
8992
|
+
const headerSchema = defaults.headerSchema;
|
|
8993
|
+
const footerSchema = defaults.footerSchema;
|
|
8994
|
+
if (headerSchema || footerSchema) {
|
|
8995
|
+
let wrappedBody = [body];
|
|
8996
|
+
if (headerSchema) {
|
|
8997
|
+
if(___default["default"].isArray(headerSchema)){
|
|
8998
|
+
wrappedBody = ___default["default"].union(headerSchema,wrappedBody);
|
|
8999
|
+
}
|
|
9000
|
+
else {
|
|
9001
|
+
wrappedBody.unshift(headerSchema);
|
|
9002
|
+
}
|
|
9003
|
+
}
|
|
9004
|
+
if (footerSchema) {
|
|
9005
|
+
if(___default["default"].isArray(footerSchema)){
|
|
9006
|
+
wrappedBody = ___default["default"].union(wrappedBody,footerSchema);
|
|
9007
|
+
}
|
|
9008
|
+
else {
|
|
9009
|
+
wrappedBody.push(footerSchema);
|
|
9010
|
+
}
|
|
9011
|
+
}
|
|
9012
|
+
body = wrappedBody;
|
|
9013
|
+
}
|
|
9014
|
+
}
|
|
9015
|
+
// console.timeEnd('getObjectCRUD');
|
|
9016
|
+
// TODO: data应该只留loaded,其他属性都改为从上层传递下来
|
|
9017
|
+
return {
|
|
9018
|
+
type: 'service',
|
|
9019
|
+
className: '',
|
|
9020
|
+
id: `service_${id}`,
|
|
9021
|
+
name: `page`,
|
|
9022
|
+
data: {
|
|
9023
|
+
objectName: objectSchema.name,
|
|
9024
|
+
// _id: null,
|
|
9025
|
+
recordPermissions: objectSchema.permissions,
|
|
9026
|
+
uiSchema: objectSchema,
|
|
9027
|
+
// loaded: false //crud接收适配器中设置为true,否则就是刷新浏览器第一次加载
|
|
9028
|
+
},
|
|
9029
|
+
body: body
|
|
8694
9030
|
}
|
|
8695
|
-
};
|
|
8696
9031
|
}
|
|
8697
9032
|
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
|
|
8702
|
-
*/
|
|
8703
|
-
async function getObjectCalendar(objectSchema, calendarOptions, options) {
|
|
8704
|
-
const permissions = objectSchema.permissions;
|
|
8705
|
-
if (!options) {
|
|
8706
|
-
options = {};
|
|
8707
|
-
}
|
|
8708
|
-
|
|
8709
|
-
calendarOptions = Object.assign({}, DEFAULT_CALENDAR_OPTIONS, _$1.omitBy(calendarOptions, _$1.isNil));
|
|
9033
|
+
const getGlobalData = (mode)=>{
|
|
9034
|
+
const user = getSteedosAuth();
|
|
9035
|
+
return {mode: mode, user: user, spaceId: user.spaceId, userId: user.userId}
|
|
9036
|
+
};
|
|
8710
9037
|
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
|
|
8720
|
-
|
|
9038
|
+
const getFormFields = (objectSchema, formProps)=>{
|
|
9039
|
+
/**
|
|
9040
|
+
* fieldsExtend: 重写字段定义
|
|
9041
|
+
* fields: 包含的字段
|
|
9042
|
+
* excludedFields: 排除的字段
|
|
9043
|
+
*/
|
|
9044
|
+
const { fieldsExtend, fields: includedFields, excludedFields } = formProps;
|
|
9045
|
+
|
|
9046
|
+
let fields = {};
|
|
9047
|
+
// 以uiSchema fields 为基础, 遍历字段, 并更新字段定义
|
|
9048
|
+
___default["default"].forEach(objectSchema.fields, (field, fieldName)=>{
|
|
9049
|
+
if(!lodash.has(field, "name")){
|
|
9050
|
+
field.name = fieldName;
|
|
9051
|
+
}
|
|
9052
|
+
if(fieldsExtend && fieldsExtend[fieldName]){
|
|
9053
|
+
fields[field.name] = Object.assign({}, field, fieldsExtend[fieldName], {name: field.name});
|
|
9054
|
+
}else {
|
|
9055
|
+
fields[field.name] = field;
|
|
8721
9056
|
}
|
|
8722
9057
|
});
|
|
8723
9058
|
|
|
8724
|
-
if
|
|
8725
|
-
|
|
9059
|
+
if(!___default["default"].isEmpty(includedFields) && ___default["default"].isArray(includedFields)){
|
|
9060
|
+
const includedFieldsMap = {};
|
|
9061
|
+
___default["default"].each(includedFields, (fName, index)=>{
|
|
9062
|
+
if(fields[fName]){
|
|
9063
|
+
includedFieldsMap[fName] = Object.assign({}, fields[fName], {sort_no: index});
|
|
9064
|
+
}
|
|
9065
|
+
});
|
|
9066
|
+
fields = includedFieldsMap;
|
|
8726
9067
|
}
|
|
8727
9068
|
|
|
8728
|
-
|
|
8729
|
-
|
|
8730
|
-
|
|
8731
|
-
|
|
8732
|
-
if (sortField) {
|
|
8733
|
-
let sortStr = sortField + ' ' + sortOrder || 'asc';
|
|
8734
|
-
sort = sortStr;
|
|
8735
|
-
}
|
|
8736
|
-
}
|
|
8737
|
-
let initialView = calendarOptions.currentView;
|
|
8738
|
-
if (initialView) {
|
|
8739
|
-
// day, week, month, agenda
|
|
8740
|
-
switch (initialView) {
|
|
8741
|
-
case "day":
|
|
8742
|
-
initialView = "timeGridDay";
|
|
8743
|
-
break;
|
|
8744
|
-
case "week":
|
|
8745
|
-
initialView = "timeGridWeek";
|
|
8746
|
-
break;
|
|
8747
|
-
case "month":
|
|
8748
|
-
initialView = "dayGridMonth";
|
|
8749
|
-
break;
|
|
8750
|
-
case "agenda":
|
|
8751
|
-
initialView = "listWeek";
|
|
8752
|
-
break;
|
|
8753
|
-
}
|
|
8754
|
-
}
|
|
8755
|
-
else {
|
|
8756
|
-
initialView = "timeGridWeek";
|
|
9069
|
+
if(!___default["default"].isEmpty(excludedFields) && ___default["default"].isArray(excludedFields)){
|
|
9070
|
+
___default["default"].each(excludedFields, (fName)=>{
|
|
9071
|
+
delete fields[fName];
|
|
9072
|
+
});
|
|
8757
9073
|
}
|
|
8758
9074
|
|
|
8759
|
-
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
const onGetEventsScript = `
|
|
8763
|
-
const api = ${JSON.stringify(api)};
|
|
8764
|
-
event.data.calendarOptions = ${JSON.stringify(calendarOptions)};
|
|
8765
|
-
doAction({
|
|
8766
|
-
"actionType": 'ajax',
|
|
8767
|
-
"args": {
|
|
8768
|
-
"api": api
|
|
8769
|
-
},
|
|
8770
|
-
});
|
|
8771
|
-
`;
|
|
8772
|
-
|
|
8773
|
-
const onSelectScript = `
|
|
8774
|
-
const data = event.data;
|
|
8775
|
-
const doc = {};
|
|
8776
|
-
doc["${calendarOptions.startDateExpr}"] = data.start;
|
|
8777
|
-
doc["${calendarOptions.endDateExpr}"] = data.end;
|
|
8778
|
-
doc["${calendarOptions.allDayExpr}"] = data.allDay;
|
|
8779
|
-
doc["${calendarOptions.textExpr}"] = data.title;
|
|
8780
|
-
// ObjectForm会认作用域下的变量值
|
|
8781
|
-
// TODO: 待组件支持initValues属性后应该改掉,不应该通过data直接传值
|
|
8782
|
-
// TODO: 全天事件属性传入doc了但是没有生效,需要手动在ObjectForm中勾选全天事件
|
|
8783
|
-
const title = "新建 ${objectSchema.label}";
|
|
8784
|
-
doAction(
|
|
8785
|
-
{
|
|
8786
|
-
"actionType": "dialog",
|
|
8787
|
-
"dialog": {
|
|
8788
|
-
"type": "dialog",
|
|
8789
|
-
"title": title,
|
|
8790
|
-
"body": [
|
|
8791
|
-
{
|
|
8792
|
-
"type": "steedos-object-form",
|
|
8793
|
-
"objectApiName": "\${objectName}",
|
|
8794
|
-
"mode": "edit",
|
|
8795
|
-
"defaultData": doc,
|
|
8796
|
-
"onEvent": {
|
|
8797
|
-
"submitSucc": {
|
|
8798
|
-
"weight": 0,
|
|
8799
|
-
"actions": [
|
|
8800
|
-
{
|
|
8801
|
-
"actionType": "custom",
|
|
8802
|
-
"script": "event.data.view?.calendar.refetchEvents();"
|
|
8803
|
-
}
|
|
8804
|
-
]
|
|
8805
|
-
}
|
|
8806
|
-
}
|
|
8807
|
-
}
|
|
8808
|
-
],
|
|
8809
|
-
"closeOnEsc": false,
|
|
8810
|
-
"closeOnOutside": false,
|
|
8811
|
-
"showCloseButton": true,
|
|
8812
|
-
"size": "lg"
|
|
8813
|
-
}
|
|
8814
|
-
});
|
|
8815
|
-
`;
|
|
9075
|
+
return lodash.sortBy(___default["default"].values(fields), "sort_no");
|
|
9076
|
+
};
|
|
8816
9077
|
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8832
|
-
|
|
9078
|
+
async function getObjectForm(objectSchema, ctx){
|
|
9079
|
+
const { recordId, formFactor, layout = formFactor === 'SMALL' ? 'normal' : "normal", labelAlign, tabId, appId, defaults } = ctx;
|
|
9080
|
+
const fields = ___default["default"].values(objectSchema.fields);
|
|
9081
|
+
const formFields = getFormFields(objectSchema, ctx);
|
|
9082
|
+
const formSchema = defaults && defaults.formSchema || {};
|
|
9083
|
+
if(___default["default"].has(formSchema, 'className')){
|
|
9084
|
+
formSchema.className = 'steedos-amis-form';
|
|
9085
|
+
}
|
|
9086
|
+
const amisSchema = {
|
|
9087
|
+
type: 'service',
|
|
9088
|
+
className: 'p-0',
|
|
9089
|
+
name: `page_edit_${recordId}`,
|
|
9090
|
+
api: await getEditFormInitApi(objectSchema, recordId, fields, ctx),
|
|
9091
|
+
data:{
|
|
9092
|
+
editFormInited: false
|
|
9093
|
+
},
|
|
9094
|
+
// data: {global: getGlobalData('edit'), recordId: recordId, objectName: objectSchema.name, context: {rootUrl: getRootUrl(), tenantId: getTenantId(), authToken: getAuthToken()}},
|
|
9095
|
+
initApi: null,
|
|
9096
|
+
initFetch: null ,
|
|
9097
|
+
body: [defaultsDeep({}, formSchema, {
|
|
9098
|
+
type: "form",
|
|
9099
|
+
mode: layout,
|
|
9100
|
+
data: {
|
|
9101
|
+
"&": "${initialValues}"
|
|
9102
|
+
},
|
|
9103
|
+
labelAlign,
|
|
9104
|
+
persistData: false,
|
|
9105
|
+
resetAfterSubmit: true,
|
|
9106
|
+
preventEnterSubmit: true,
|
|
9107
|
+
promptPageLeave: true,
|
|
9108
|
+
canAccessSuperData: false,
|
|
9109
|
+
name: `form_edit_${recordId}`,
|
|
9110
|
+
debug: false,
|
|
9111
|
+
title: "",
|
|
9112
|
+
submitText: "", // amis 表单不显示提交按钮, 表单提交由项目代码接管
|
|
9113
|
+
api: await getSaveApi(objectSchema, recordId, fields, ctx),
|
|
9114
|
+
initFetch: recordId != 'new',
|
|
9115
|
+
body: await getFormBody(fields, formFields, ctx),
|
|
9116
|
+
panelClassName:'m-0 sm:rounded-lg shadow-none border-none',
|
|
9117
|
+
bodyClassName: 'p-0',
|
|
9118
|
+
className: 'steedos-amis-form',
|
|
9119
|
+
hiddenOn: "${editFormInited != true}",
|
|
9120
|
+
onEvent: {
|
|
9121
|
+
"submitSucc": {
|
|
9122
|
+
"weight": 0,
|
|
9123
|
+
"actions": [
|
|
9124
|
+
{
|
|
9125
|
+
"actionType": "broadcast",
|
|
9126
|
+
"args": {
|
|
9127
|
+
"eventName": `@data.changed.${objectSchema.name}`
|
|
9128
|
+
},
|
|
9129
|
+
"data": {
|
|
9130
|
+
"objectName": `${objectSchema.name}`,
|
|
9131
|
+
"displayAs": "${displayAs}"
|
|
9132
|
+
}
|
|
9133
|
+
},
|
|
9134
|
+
{
|
|
9135
|
+
"actionType": "broadcast",
|
|
9136
|
+
"args": {
|
|
9137
|
+
"eventName": "@data.changed.${_master.objectName}"
|
|
9138
|
+
},
|
|
9139
|
+
"data": {
|
|
9140
|
+
"objectName": "${_master.objectName}",
|
|
9141
|
+
"_isRelated": "${_isRelated || _master._isRelated}"
|
|
9142
|
+
},
|
|
9143
|
+
"expression": `\${_master.objectName != '${objectSchema.name}' && _master.objectName}`
|
|
9144
|
+
},
|
|
9145
|
+
// {
|
|
9146
|
+
// "actionType": "custom",
|
|
9147
|
+
// "script": "debugger;"
|
|
9148
|
+
// },
|
|
9149
|
+
// {
|
|
9150
|
+
// "args": {},
|
|
9151
|
+
// "actionType": "closeDialog"
|
|
9152
|
+
// }
|
|
9153
|
+
]
|
|
9154
|
+
}
|
|
8833
9155
|
}
|
|
8834
|
-
]
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
"size": "lg",
|
|
8839
|
-
"actions": []
|
|
9156
|
+
})]
|
|
9157
|
+
};
|
|
9158
|
+
if(formSchema.id){
|
|
9159
|
+
amisSchema.id = `service-${formSchema.id}`;
|
|
8840
9160
|
}
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
|
|
8844
|
-
const recordId = "${event.id}";
|
|
8845
|
-
const recordPermissionsApi = getCalendarRecordPermissionsApi(objectSchema, recordId);
|
|
8846
|
-
const recordSaveApi = getCalendarRecordSaveApi(objectSchema, calendarOptions);
|
|
8847
|
-
|
|
8848
|
-
const businessHours = {
|
|
8849
|
-
daysOfWeek: [1, 2, 3, 4, 5],
|
|
8850
|
-
startTime: '08:00',
|
|
8851
|
-
endTime: '18:00',
|
|
8852
|
-
};
|
|
8853
|
-
if (!_$1.isEmpty(calendarOptions.startDayHour)) {
|
|
8854
|
-
businessHours.startTime = `${calendarOptions.startDayHour}:00`;
|
|
8855
|
-
}
|
|
8856
|
-
if (!_$1.isEmpty(calendarOptions.endDayHour)) {
|
|
8857
|
-
businessHours.endTime = `${calendarOptions.endDayHour}:00`;
|
|
8858
|
-
}
|
|
9161
|
+
return amisSchema;
|
|
9162
|
+
}
|
|
8859
9163
|
|
|
8860
|
-
|
|
8861
|
-
"
|
|
8862
|
-
|
|
8863
|
-
|
|
8864
|
-
|
|
8865
|
-
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
8876
|
-
|
|
8877
|
-
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
|
|
8890
|
-
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
|
|
8899
|
-
|
|
8900
|
-
|
|
8901
|
-
|
|
8902
|
-
|
|
9164
|
+
async function getObjectDetail(objectSchema, recordId, ctx){
|
|
9165
|
+
const { formFactor, layout = formFactor === 'SMALL' ? 'normal' : "normal", labelAlign, formInitProps } = ctx;
|
|
9166
|
+
const fields = ___default["default"].values(objectSchema.fields);
|
|
9167
|
+
const formFields = getFormFields(objectSchema, ctx);
|
|
9168
|
+
const serviceId = `service_detail_page`;
|
|
9169
|
+
return {
|
|
9170
|
+
type: 'service',
|
|
9171
|
+
name: `page_readonly_${recordId}`,
|
|
9172
|
+
id: serviceId,
|
|
9173
|
+
data: {global: getGlobalData('read'), context: {rootUrl: getRootUrl(), tenantId: getTenantId(), authToken: getAuthToken()}},
|
|
9174
|
+
api: await getReadonlyFormInitApi(objectSchema, recordId, fields, formInitProps),
|
|
9175
|
+
body: [
|
|
9176
|
+
{
|
|
9177
|
+
"type": "wrapper", //form 的 hiddenOn 会导致 form onEvent 异常, 使用wrapper包裹一次form,并在wrapper上控制显隐
|
|
9178
|
+
hiddenOn: "${recordLoaded != true}",
|
|
9179
|
+
"className": "p-0 m-0",
|
|
9180
|
+
"body": {
|
|
9181
|
+
type: "form",
|
|
9182
|
+
mode: layout,
|
|
9183
|
+
labelAlign,
|
|
9184
|
+
persistData: false,
|
|
9185
|
+
promptPageLeave: false,
|
|
9186
|
+
name: `form_readonly_${recordId}`,
|
|
9187
|
+
debug: false,
|
|
9188
|
+
title: "",
|
|
9189
|
+
data: {
|
|
9190
|
+
"formData": "$$"
|
|
9191
|
+
},
|
|
9192
|
+
wrapWithPanel: false,
|
|
9193
|
+
body: await getFormBody(_$1.map(fields, (field)=>{field.readonly = true; return field;}), _$1.map(formFields, (field)=>{field.readonly = true; return field;}), Object.assign({}, ctx, {showSystemFields: true})),
|
|
9194
|
+
className: 'steedos-amis-form bg-white',
|
|
9195
|
+
actions: [], // 不显示表单默认的提交按钮
|
|
9196
|
+
onEvent: {
|
|
9197
|
+
[`@data.changed.${objectSchema.name}`]: { // 由于amis service 组件的 onEvent 存在bug ,此处借助form来刷新 上层 service https://github.com/baidu/amis/issues/6294
|
|
9198
|
+
"actions": [
|
|
9199
|
+
{
|
|
9200
|
+
"actionType": "reload",
|
|
9201
|
+
"componentId": serviceId,
|
|
9202
|
+
"expression": "this.__deletedRecord != true"
|
|
9203
|
+
},
|
|
9204
|
+
{
|
|
9205
|
+
// "args": {
|
|
9206
|
+
// "url": "/app/${appId}/${objectName}/grid/${side_listview_id}",
|
|
9207
|
+
// "blank": false
|
|
9208
|
+
// },
|
|
9209
|
+
"actionType": "custom",
|
|
9210
|
+
"script": "Steedos.goBack()",
|
|
9211
|
+
"expression": "this.__deletedRecord === true"
|
|
9212
|
+
}
|
|
9213
|
+
]
|
|
9214
|
+
}
|
|
9215
|
+
}
|
|
8903
9216
|
},
|
|
8904
|
-
"actionType": "custom",
|
|
8905
|
-
"script": "console.log('eventAdd'); console.log(event);"
|
|
8906
|
-
}
|
|
8907
|
-
]
|
|
8908
|
-
},
|
|
8909
|
-
"eventChange": {
|
|
8910
|
-
"weight": 0,
|
|
8911
|
-
"actions": [
|
|
8912
|
-
{
|
|
8913
|
-
"actionType": 'ajax',
|
|
8914
|
-
"args": {
|
|
8915
|
-
"api": recordPermissionsApi
|
|
8916
|
-
}
|
|
8917
|
-
},
|
|
8918
|
-
{
|
|
8919
|
-
"actionType": "toast",
|
|
8920
|
-
"expression": "!event.data.editable",
|
|
8921
|
-
"args": {
|
|
8922
|
-
"msgType": "error",
|
|
8923
|
-
"msg": "您没有编辑该记录的权限!",
|
|
8924
|
-
"position": "top-center"
|
|
8925
9217
|
}
|
|
8926
|
-
|
|
8927
|
-
{
|
|
8928
|
-
"
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
|
|
9218
|
+
],
|
|
9219
|
+
onEvent: {
|
|
9220
|
+
"fetchInited": {
|
|
9221
|
+
"weight": 0,
|
|
9222
|
+
"actions": [
|
|
9223
|
+
{
|
|
9224
|
+
actionType: 'broadcast',
|
|
9225
|
+
eventName: "recordLoaded",
|
|
9226
|
+
args: {
|
|
9227
|
+
eventName: "recordLoaded"
|
|
9228
|
+
},
|
|
9229
|
+
data: {
|
|
9230
|
+
objectName: "${event.data.__objectName}",
|
|
9231
|
+
record: "${event.data.__record}"
|
|
9232
|
+
},
|
|
9233
|
+
expression: "${event.data.__response.error != true}"
|
|
9234
|
+
},
|
|
9235
|
+
{
|
|
9236
|
+
"actionType": "setValue",
|
|
9237
|
+
"args": {
|
|
9238
|
+
value: {
|
|
9239
|
+
"recordLoaded": true,
|
|
9240
|
+
}
|
|
9241
|
+
},
|
|
9242
|
+
expression: "${event.data.__response.error != true}"
|
|
8935
9243
|
}
|
|
9244
|
+
]
|
|
8936
9245
|
}
|
|
8937
9246
|
}
|
|
8938
|
-
]
|
|
8939
|
-
},
|
|
8940
|
-
"eventRemove": {
|
|
8941
|
-
"weight": 0,
|
|
8942
|
-
"actions": [
|
|
8943
|
-
{
|
|
8944
|
-
"componentId": "",
|
|
8945
|
-
"args": {
|
|
8946
|
-
},
|
|
8947
|
-
"actionType": "custom",
|
|
8948
|
-
"script": "console.log('eventRemove'); console.log(event);"
|
|
8949
|
-
}
|
|
8950
|
-
]
|
|
8951
|
-
},
|
|
8952
|
-
"eventsSet": {
|
|
8953
|
-
"weight": 0,
|
|
8954
|
-
"actions": [
|
|
8955
|
-
{
|
|
8956
|
-
"componentId": "",
|
|
8957
|
-
"args": {
|
|
8958
|
-
},
|
|
8959
|
-
"actionType": "custom",
|
|
8960
|
-
"script": "console.log('eventsSet'); console.log(event);"
|
|
8961
|
-
}
|
|
8962
|
-
]
|
|
8963
|
-
}
|
|
8964
|
-
};
|
|
8965
|
-
|
|
8966
|
-
Object.assign(onEvent, options.onEvent);
|
|
8967
|
-
|
|
8968
|
-
const config = options.config || {};
|
|
8969
|
-
if(config.eventContent && typeof config.eventContent === "string"){
|
|
8970
|
-
const hasReturn = /\breturn\b/.test(config.eventContent);
|
|
8971
|
-
if(hasReturn){
|
|
8972
|
-
try {
|
|
8973
|
-
// 如果是包括return语句的字符串,则按函数解析,见 https://fullcalendar.io/docs/content-injection
|
|
8974
|
-
let fn = new Function("arg", config.eventContent);
|
|
8975
|
-
config.eventContent = fn;
|
|
8976
|
-
} catch (e) {
|
|
8977
|
-
console.warn(e);
|
|
8978
|
-
}
|
|
8979
|
-
}
|
|
8980
|
-
}
|
|
8981
|
-
|
|
8982
|
-
if(config.noEventsContent && typeof config.noEventsContent === "string"){
|
|
8983
|
-
const hasReturn = /\breturn\b/.test(config.noEventsContent);
|
|
8984
|
-
if(hasReturn){
|
|
8985
|
-
try {
|
|
8986
|
-
// 如果是包括return语句的字符串,则按函数解析,见 https://fullcalendar.io/docs/content-injection
|
|
8987
|
-
let fn = new Function("arg", config.noEventsContent);
|
|
8988
|
-
config.noEventsContent = fn;
|
|
8989
|
-
} catch (e) {
|
|
8990
|
-
console.warn(e);
|
|
8991
|
-
}
|
|
8992
9247
|
}
|
|
8993
|
-
}
|
|
8994
|
-
|
|
8995
|
-
const amisSchema = {
|
|
8996
|
-
"type": "steedos-fullcalendar",
|
|
8997
|
-
"label": "",
|
|
8998
|
-
"name": "fullcalendar",
|
|
8999
|
-
"placeholder":"${additionalFilters}",//用于触发reload
|
|
9000
|
-
"editable": permissions.allowEdit,
|
|
9001
|
-
"selectable": permissions.allowCreate,
|
|
9002
|
-
"selectMirror": permissions.allowCreate,
|
|
9003
|
-
"initialView": initialView,
|
|
9004
|
-
"businessHours": businessHours,
|
|
9005
|
-
...config,
|
|
9006
|
-
"onEvent": onEvent
|
|
9007
|
-
};
|
|
9008
|
-
return amisSchema;
|
|
9009
9248
|
}
|
|
9010
9249
|
|
|
9011
9250
|
/*
|
|
@@ -9427,8 +9666,8 @@ else{
|
|
|
9427
9666
|
/*
|
|
9428
9667
|
* @Author: baozhoutao@steedos.com
|
|
9429
9668
|
* @Date: 2022-07-05 15:55:39
|
|
9430
|
-
* @LastEditors:
|
|
9431
|
-
* @LastEditTime: 2023-04
|
|
9669
|
+
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
|
|
9670
|
+
* @LastEditTime: 2023-06-04 17:36:49
|
|
9432
9671
|
* @Description:
|
|
9433
9672
|
*/
|
|
9434
9673
|
|
|
@@ -9759,7 +9998,8 @@ else{
|
|
|
9759
9998
|
"requestAdaptor": listView.requestAdaptor,
|
|
9760
9999
|
"adaptor": listView.adaptor,
|
|
9761
10000
|
"headerToolbarItems": ctx.headerToolbarItems,
|
|
9762
|
-
"filterVisible": ctx.filterVisible
|
|
10001
|
+
"filterVisible": ctx.filterVisible,
|
|
10002
|
+
"rowClassNameExpr": ctx.rowClassNameExpr
|
|
9763
10003
|
};
|
|
9764
10004
|
return {
|
|
9765
10005
|
uiSchema,
|