@steedos-widgets/amis-object 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ export declare const AmisRecordService: (props: any) => Promise<{
2
+ type: string;
3
+ body: any[];
4
+ data: {
5
+ "_master.objectName": string;
6
+ "_master.recordId": string;
7
+ };
8
+ style: any;
9
+ onEvent: any;
10
+ }>;
@@ -5,6 +5,7 @@ export * from './AmisObjectTable';
5
5
  export * from './AmisObjectCalendar';
6
6
  export * from './AmisRecordDetailHeader';
7
7
  export * from './AmisRecordDetail';
8
+ export * from './AmisRecordService';
8
9
  export * from './AmisRecordDetailRelatedList';
9
10
  export * from './AmisRecordDetailRelatedLists';
10
11
  export * from './AmisSelectUser';
@@ -1750,8 +1750,8 @@ var config = {
1750
1750
  /*
1751
1751
  * @Author: baozhoutao@steedos.com
1752
1752
  * @Date: 2022-11-01 15:51:00
1753
- * @LastEditors: Please set LastEditors
1754
- * @LastEditTime: 2023-04-11 13:58:24
1753
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
1754
+ * @LastEditTime: 2023-04-16 17:04:16
1755
1755
  * @Description:
1756
1756
  */
1757
1757
 
@@ -1829,6 +1829,7 @@ const getSchema$4 = async (uiSchema, ctx) => {
1829
1829
  "context": "${context}",
1830
1830
  "global": "${global}",
1831
1831
  "listViewId": "${listViewId}",
1832
+ "displayAs": "${displayAs}",
1832
1833
  "uiSchema": "${uiSchema}",
1833
1834
  "isLookup": "${isLookup}",
1834
1835
  "listName": "${listName}"
@@ -4127,7 +4128,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4127
4128
  {
4128
4129
  "type": "button",
4129
4130
  "label": "重命名",
4130
- "visibleOn": "(global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && ['all', 'recent', 'my'].indexOf(listName) == -1",
4131
+ "disabledOn": "!((global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && !!uiSchema.list_views[listName].owner)",
4131
4132
  "onEvent": {
4132
4133
  "click": {
4133
4134
  "weight": 0,
@@ -4182,7 +4183,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4182
4183
  {
4183
4184
  "type": "button",
4184
4185
  "label": "共享设置",
4185
- "visibleOn": "global.user.is_space_admin && ['all', 'recent', 'my'].indexOf(listName) == -1",
4186
+ "disabledOn": "!(global.user.is_space_admin && !!uiSchema.list_views[listName].owner)",
4186
4187
  "onEvent": {
4187
4188
  "click": {
4188
4189
  "weight": 0,
@@ -4222,7 +4223,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4222
4223
  {
4223
4224
  "type": "button",
4224
4225
  "label": "过滤设置",
4225
- "visibleOn": "(global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && ['all', 'recent', 'my'].indexOf(listName) == -1",
4226
+ "disabledOn": "!((global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && !!uiSchema.list_views[listName].owner)",
4226
4227
  "onEvent": {
4227
4228
  "click": {
4228
4229
  "weight": 0,
@@ -4284,7 +4285,7 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4284
4285
  {
4285
4286
  "type": "button",
4286
4287
  "label": "显示的列",
4287
- "visibleOn": "(global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && ['all', 'recent', 'my'].indexOf(listName) == -1",
4288
+ "disabledOn": "!((global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && !!uiSchema.list_views[listName].owner)",
4288
4289
  "onEvent": {
4289
4290
  "click": {
4290
4291
  "weight": 0,
@@ -4343,10 +4344,74 @@ function getObjectHeaderToolbar(mainObject, formFactor, {showDisplayAs = false,
4343
4344
  }
4344
4345
  }
4345
4346
  },
4347
+ {
4348
+ "type": "button",
4349
+ "label": "默认排序规则",
4350
+ "disabledOn": "!((global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && !!uiSchema.list_views[listName].owner)",
4351
+ "onEvent": {
4352
+ "click": {
4353
+ "weight": 0,
4354
+ "actions": [
4355
+ {
4356
+ "dialog": {
4357
+ "type": "dialog",
4358
+ "title": "弹框标题",
4359
+ "data": {
4360
+ "&": "$$",
4361
+ "objectName": "${objectName}",
4362
+ "recordId": "${uiSchema.list_views[listName]._id}",
4363
+ "listName": "${listName}",
4364
+ "appId": "${appId}"
4365
+ },
4366
+ "body": [
4367
+ {
4368
+ "type": "steedos-object-form",
4369
+ "label": "对象表单",
4370
+ "objectApiName": "object_listviews",
4371
+ "recordId": "${recordId}",
4372
+ "className": "",
4373
+ "id": "u:061f158b4c5a",
4374
+ "mode": "edit",
4375
+ "fields": [
4376
+ "sort",
4377
+ "sort.$.field_name",
4378
+ "sort.$.order"
4379
+ ],
4380
+ "onEvent": {
4381
+ "submitSucc": {
4382
+ "weight": 0,
4383
+ "actions": [
4384
+ {
4385
+ "args": {
4386
+ "url": "${context.rootUrl}/app/${appId}/${objectName}/grid/${listName}",
4387
+ "blank": false
4388
+ },
4389
+ "actionType": "url"
4390
+ }
4391
+ ]
4392
+ }
4393
+ },
4394
+ "fieldsExtend": "{\n \"sort\": {\n \"amis\": {\n \"type\": \"tabs-transfer\",\n \"sortable\": true,\n \"searchable\": true,\n \"source\": {\n \"method\": \"get\",\n \"url\": \"${context.rootUrl}/service/api/amis-metadata-objects/objects/${objectName}/sortFields/options\",\n \"headers\": {\n \"Authorization\": \"Bearer ${context.tenantId},${context.authToken}\"\n }\n }\n }\n }\n}",
4395
+ "initApiAdaptor": "let sort;\nif (recordId) {\n sort = payload.data.initialValues.sort;\n //数据格式转换\n if (sort instanceof Array) {\n sort = lodash.map(sort, (item) => {\n return item.field_name + ':' + (item.order || 'asc')\n });\n }\n}\npayload.data.initialValues.sort = sort;\ndelete payload.extensions;",
4396
+ "apiRequestAdaptor": "const recordId = api.body.recordId;\n//数据格式转换\nif (typeof formData.sort == 'string') {\n formData.sort = formData.sort?.split(',');\n}\nformData.sort = lodash.map(formData.sort, (item) => {\n const arr = item.split(':');\n return { field_name: arr[0], order: arr[1] };\n});\nif (recordId) {\n query = 'mutation{record: ' + objectName + '__update(id: \"' + recordId + '\", doc: {__saveData}){_id}}';\n}\n__saveData = JSON.stringify(JSON.stringify(formData));\napi.data = { query: query.replace('{__saveData}', __saveData) };\n"
4397
+ }
4398
+ ],
4399
+ "showCloseButton": true,
4400
+ "showErrorMsg": true,
4401
+ "showLoading": true,
4402
+ "id": "u:d3f6947b6acf",
4403
+ "size": "lg"
4404
+ },
4405
+ "actionType": "dialog"
4406
+ }
4407
+ ]
4408
+ }
4409
+ }
4410
+ },
4346
4411
  {
4347
4412
  "type": "button",
4348
4413
  "label": "删除",
4349
- "visibleOn": "(global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && ['all', 'recent', 'my'].indexOf(listName) == -1",
4414
+ "disabledOn": "!((global.user.is_space_admin || global.userId == uiSchema.list_views[listName].owner) && !!uiSchema.list_views[listName].owner)",
4350
4415
  "confirmText": "如果您删除此列表视图,该视图将为所有具备访问权限的用户永久删除。是否确定要删除?",
4351
4416
  "onEvent": {
4352
4417
  "click": {
@@ -4707,7 +4772,6 @@ function getLookupSapceUserTreeSchema(){
4707
4772
  {
4708
4773
  "actionType": "custom",
4709
4774
  "script": `
4710
- debugger;
4711
4775
  const scope = event.context.scoped;
4712
4776
  //TODO: 将form中的value一同加入筛选内
4713
4777
  // var filterForm = scope.parent.parent.getComponents().find(function(n){
@@ -6191,7 +6255,7 @@ var index = /*#__PURE__*/Object.freeze({
6191
6255
 
6192
6256
  const API_CACHE = 100;
6193
6257
 
6194
- function getReadonlyFormAdaptor(fields){
6258
+ function getReadonlyFormAdaptor(object, fields){
6195
6259
  let scriptStr = '';
6196
6260
  const selectFields = ___default__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))});
6197
6261
  const gridAndObjectFieldsName = ___default__namespace.map(___default__namespace.filter(fields, function(field){return field.name.indexOf('.') < 0 && (field.type === 'object' || field.type === 'grid')}), 'name');
@@ -6250,6 +6314,7 @@ function getReadonlyFormAdaptor(fields){
6250
6314
  console.error(e)
6251
6315
  }
6252
6316
  payload.data = data;
6317
+ payload.data.__objectName = "${object.name}";
6253
6318
  payload.data.__record = record;
6254
6319
  window.postMessage(Object.assign({type: "record.loaded"}, {record: record}), "*")
6255
6320
  }
@@ -6267,7 +6332,7 @@ async function getReadonlyFormInitApi(object, recordId, fields, options){
6267
6332
  url: getApi$2()+"&recordId=${recordId}",
6268
6333
  cache: API_CACHE,
6269
6334
  // requestAdaptor: "console.log('getReadonlyFormInitApi requestAdaptor', api);return api;",
6270
- adaptor: getReadonlyFormAdaptor(fields),
6335
+ adaptor: getReadonlyFormAdaptor(object, fields),
6271
6336
  data: await getFindOneQuery$1(object, recordId, fields, options),
6272
6337
  headers: {
6273
6338
  Authorization: "Bearer ${context.tenantId},${context.authToken}"
@@ -6985,6 +7050,7 @@ async function getObjectDetail(objectSchema, recordId, ctx){
6985
7050
  eventName: "recordLoaded"
6986
7051
  },
6987
7052
  data: {
7053
+ objectName: "${event.data.__objectName}",
6988
7054
  record: "${event.data.__record}"
6989
7055
  }
6990
7056
  },
@@ -7421,7 +7487,7 @@ async function getTableApi(mainObject, fields, options){
7421
7487
  const api = await getApi(mainObject, null, fields, {count: options.queryCount, alias: 'rows', limit: top, queryOptions: `filters: {__filters}, top: {__top}, skip: {__skip}, sort: "{__sort}"`});
7422
7488
 
7423
7489
  if(options.isRelated){
7424
- api.url += "&recordId=${recordId}";
7490
+ api.url += "&recordId=${_master.recordId}";
7425
7491
  }
7426
7492
 
7427
7493
  api.data.$term = "$term";
@@ -8665,8 +8731,8 @@ async function getRelatedListSchema(
8665
8731
  /*
8666
8732
  * @Author: baozhoutao@steedos.com
8667
8733
  * @Date: 2022-07-05 15:55:39
8668
- * @LastEditors: baozhoutao@steedos.com
8669
- * @LastEditTime: 2023-04-12 14:24:09
8734
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
8735
+ * @LastEditTime: 2023-04-14 11:10:07
8670
8736
  * @Description:
8671
8737
  */
8672
8738
 
@@ -9152,6 +9218,41 @@ async function getRecordDetailSchema(objectName, appId, props = {}){
9152
9218
  }
9153
9219
  }
9154
9220
 
9221
+ async function getRecordServiceSchema(objectName, appId, props = {}) {
9222
+ const uiSchema = await getUISchema(objectName);
9223
+ return {
9224
+ uiSchema,
9225
+ amisSchema: {
9226
+ "type": "service",
9227
+ "body": [],
9228
+ data: {
9229
+ "_master.objectName": "${objectName}",
9230
+ "_master.recordId": "${recordId}"
9231
+ },
9232
+ "style": {
9233
+ "padding": "var(--Page-body-padding)",
9234
+ ...props.style
9235
+ },
9236
+ onEvent: {
9237
+ "recordLoaded": {
9238
+ "actions": [
9239
+ {
9240
+ "actionType": "reload",
9241
+ "data": {
9242
+ "name": `\${record.${uiSchema.NAME_FIELD_KEY || 'name'}}`,
9243
+ "_master.record": `\${record}`,
9244
+ // 不清楚reload 如何给对象下的某个key复制, 所以此处重复设置_master的objectName、recordId
9245
+ "_master.objectName": "${objectName}",
9246
+ "_master.recordId": "${recordId}"
9247
+ }
9248
+ }
9249
+ ]
9250
+ },
9251
+ ...props.onEvent
9252
+ }
9253
+ }
9254
+ }
9255
+ }
9155
9256
 
9156
9257
  // 获取单个相关表
9157
9258
  async function getObjectRelated(
@@ -12071,6 +12172,7 @@ var index_esm$1 = /*#__PURE__*/Object.freeze({
12071
12172
  getRecordDetailSchema: getRecordDetailSchema,
12072
12173
  getRecordPageInitSchema: getRecordPageInitSchema,
12073
12174
  getRecordPermissions: getRecordPermissions,
12175
+ getRecordServiceSchema: getRecordServiceSchema,
12074
12176
  getRelatedFieldValue: getRelatedFieldValue,
12075
12177
  getRelatedListSchema: getRelatedListSchema,
12076
12178
  getRelatedsCount: getRelatedsCount,
@@ -12550,6 +12652,8 @@ var AmisObjectForm = function (props) { return __awaiter(void 0, void 0, void 0,
12550
12652
  schema = _d.sent();
12551
12653
  amisSchema = schema.amisSchema;
12552
12654
  if (defaultData) {
12655
+ // 让ObjectForm支持props中的dafaultData属性与上层组件配置的defaultData混合
12656
+ // 为了解决相关表新建时如果是表单类型微页面,因为找不到ObjectForm在哪层而造成无法设置ObjectForm的defaultData的问题
12553
12657
  amisSchema.data.defaultData = __assign$2({ "&": "${defaultData}" }, defaultData);
12554
12658
  }
12555
12659
  uiSchema = schema.uiSchema;
@@ -12645,7 +12749,7 @@ var AmisObjectListView = function (props) { return __awaiter(void 0, void 0, voi
12645
12749
  },
12646
12750
  {
12647
12751
  "actionType": "reload",
12648
- "expression": "${(event.data.recordId || event.data.__deletedRecord === true) && event.data._isRelated != true}" //不是新建, 则刷新列表
12752
+ "expression": "${(event.data.recordId || event.data.__deletedRecord === true || event.data.displayAs === 'split') && event.data._isRelated != true}" //不是新建, 或分栏模式下新建主对象记录, 则刷新列表
12649
12753
  }
12650
12754
  ]
12651
12755
  };
@@ -12839,7 +12943,8 @@ var AmisRecordDetailHeader = function (props) { return __awaiter(void 0, void 0,
12839
12943
  "_id": "\${event.data.record._id}",
12840
12944
  "recordId": "\${event.data.record._id}",
12841
12945
  "recordLoaded": true,
12842
- }
12946
+ },
12947
+ "expression": "${event.data.objectName == '".concat(objectUiSchema === null || objectUiSchema === void 0 ? void 0 : objectUiSchema.name, "'}")
12843
12948
  }
12844
12949
  ]
12845
12950
  }
@@ -12886,6 +12991,36 @@ var AmisRecordDetail = function (props) { return __awaiter(void 0, void 0, void
12886
12991
  });
12887
12992
  }); };
12888
12993
 
12994
+ /*
12995
+ * @Author: baozhoutao@steedos.com
12996
+ * @Date: 2022-12-08 10:32:17
12997
+ * @LastEditors: 殷亮辉 yinlianghui@hotoa.com
12998
+ * @LastEditTime: 2023-04-14 11:30:21
12999
+ * @Description:
13000
+ */
13001
+ var AmisRecordService = function (props) { return __awaiter(void 0, void 0, void 0, function () {
13002
+ var className, _a, objectApiName, body, style, schema;
13003
+ return __generator(this, function (_b) {
13004
+ switch (_b.label) {
13005
+ case 0:
13006
+ className = props.className, props.$schema, props.appId, _a = props.objectApiName, objectApiName = _a === void 0 ? "space_users" : _a, props.recordId, props.fields, body = props.body, style = props.style;
13007
+ return [4 /*yield*/, getRecordServiceSchema(objectApiName)];
13008
+ case 1:
13009
+ schema = (_b.sent()).amisSchema;
13010
+ if (body) {
13011
+ schema.body = body;
13012
+ }
13013
+ if (className) {
13014
+ schema.className = className;
13015
+ }
13016
+ if (style) {
13017
+ Object.assign(schema.style, style);
13018
+ }
13019
+ return [2 /*return*/, schema];
13020
+ }
13021
+ });
13022
+ }); };
13023
+
12889
13024
  var AmisRecordDetailRelatedList = function (props) { return __awaiter(void 0, void 0, void 0, function () {
12890
13025
  var objectApiName, recordId, relatedObjectApiName, relatedKey, top, perPage, appId, relatedLabel, _a, className, columns, sort, filters, visible_on, formFactor, schema;
12891
13026
  return __generator(this, function (_b) {
@@ -14033,6 +14168,7 @@ exports.AmisRecordDetail = AmisRecordDetail;
14033
14168
  exports.AmisRecordDetailHeader = AmisRecordDetailHeader;
14034
14169
  exports.AmisRecordDetailRelatedList = AmisRecordDetailRelatedList;
14035
14170
  exports.AmisRecordDetailRelatedLists = AmisRecordDetailRelatedLists;
14171
+ exports.AmisRecordService = AmisRecordService;
14036
14172
  exports.AmisSelectFlow = AmisSelectFlow;
14037
14173
  exports.AmisSelectUser = AmisSelectUser;
14038
14174
  exports.AmisSteedosField = AmisSteedosField;