Skip to content

Commit

Permalink
添加记录数据组件 #387,设计器中不再提供记录详细组件
Browse files Browse the repository at this point in the history
  • Loading branch information
yinlianghui committed Apr 12, 2023
1 parent d8e60ef commit 9300d94
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 9 deletions.
35 changes: 33 additions & 2 deletions packages/@steedos-widgets/amis-lib/src/lib/objects.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author: [email protected]
* @Date: 2022-07-05 15:55:39
* @LastEditors: baozhoutao@steedos.com
* @LastEditTime: 2023-04-12 14:24:09
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
* @LastEditTime: 2023-04-12 23:24:23
* @Description:
*/
import { fetchAPI, getUserId } from "./steedos.client";
Expand Down Expand Up @@ -503,6 +503,37 @@ export async function getRecordDetailSchema(objectName, appId, props = {}){
}
}

export async function getRecordServiceSchema(objectName, appId, props = {}) {
const uiSchema = await getUISchema(objectName);
return {
uiSchema,
amisSchema: {
"type": "service",
"body": [],
data: {
"_master.objectName": "${objectName}",
"_master.recordId": "${recordId}"
},
onEvent: {
"recordLoaded": {
"actions": [
{
"actionType": "reload",
"data": {
"name": `\${record.${uiSchema.NAME_FIELD_KEY || 'name'}}`,
"_master.record": `\${record}`,
// 不清楚reload 如何给对象下的某个key复制, 所以此处重复设置_master的objectName、recordId
"_master.objectName": "${objectName}",
"_master.recordId": "${recordId}"
}
}
]
},
...props.onEvent
}
}
}
}

// 获取单个相关表
export async function getObjectRelated(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* @Author: [email protected]
* @Date: 2022-12-08 10:32:17
* @LastEditors: 殷亮辉 [email protected]
* @LastEditTime: 2023-04-12 23:59:26
* @Description:
*/

import { getRecordServiceSchema } from '@steedos-widgets/amis-lib'

export const AmisRecordService = async (props) => {
// console.log(`AmisRecordService======>`, props)
const { className, $schema, appId, objectApiName = "space_users", recordId, fields, body } = props;
const schema = (await getRecordServiceSchema(objectApiName, appId)).amisSchema;
schema.className = className;
if (body) {
schema.body = body;
}
return schema
}
5 changes: 3 additions & 2 deletions packages/@steedos-widgets/amis-object/src/amis/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author: [email protected]
* @Date: 2022-08-31 16:32:35
* @LastEditors: baozhoutao@steedos.com
* @LastEditTime: 2023-02-08 13:17:16
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
* @LastEditTime: 2023-04-12 23:45:54
* @Description:
*/
import './AmisObjectForm.less'
Expand All @@ -13,6 +13,7 @@ export * from './AmisObjectTable';
export * from './AmisObjectCalendar';
export * from './AmisRecordDetailHeader';
export * from './AmisRecordDetail';
export * from './AmisRecordService';
export * from './AmisRecordDetailRelatedList';
export * from './AmisRecordDetailRelatedLists';
export * from './AmisSelectUser';
Expand Down
8 changes: 5 additions & 3 deletions packages/@steedos-widgets/amis-object/src/meta.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* @Author: [email protected]
* @Date: 2022-08-31 16:32:35
* @LastEditors: baozhoutao@steedos.com
* @LastEditTime: 2023-04-07 18:23:05
* @LastEditors: 殷亮辉 yinlianghui@hotoa.com
* @LastEditTime: 2023-04-12 23:32:03
* @Description:
*/
// import Hello from "./metas/Hello";
Expand All @@ -12,6 +12,7 @@ import AmisObjectCalendar from "./metas/AmisObjectCalendar";
import AmisObjectTable from "./metas/AmisObjectTable";
import AmisRecordDetailHeader from "./metas/AmisRecordDetailHeader";
import AmisRecordDetail from "./metas/AmisRecordDetail";
import AmisRecordService from "./metas/AmisRecordService";
import AmisSelectUser from "./metas/AmisSelectUser";
import AmisRecordDetailRelatedList from "./metas/AmisRecordDetailRelatedList";
import AmisRecordDetailRelatedLists from "./metas/AmisRecordDetailRelatedLists";
Expand Down Expand Up @@ -59,7 +60,8 @@ const components = [
AmisObjectTable,
AmisRecordDetailRelatedList,
AmisRecordDetailRelatedLists,
AmisRecordDetail,
AmisRecordDetail,
AmisRecordService,
AmisObjectCalendar,
AmisObjectButton,
AmisObjectFieldLookup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: [email protected]
* @Date: 2022-08-31 16:32:35
* @LastEditors: 殷亮辉 [email protected]
* @LastEditTime: 2023-04-10 22:41:41
* @LastEditTime: 2023-04-12 23:29:24
* @Description:
*/
const config: any = {
Expand Down Expand Up @@ -62,7 +62,7 @@ export default {
weight: 1,
framework: "react"
},
plugin: {
plugin__disable: {
rendererName: config.amis.name,
$schema: '/schemas/UnkownSchema.json',
name: config.title,
Expand Down
116 changes: 116 additions & 0 deletions packages/@steedos-widgets/amis-object/src/metas/AmisRecordService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
const config: any = {
componentType: 'amisSchema', // amisSchema || react
group: "华炎魔方",
componentName: "AmisRecordService",
title: "记录数据",
docUrl: "",
screenshot: "",
npm: {
package: "@steedos-widgets/amis-object",
version: "{{version}}",
exportName: "AmisRecordService",
main: "",
destructuring: true,
subName: ""
},
props: [
{
name: "objectApiName",
propType: "string",
description: '对象名称',
},
{
name: "recordId",
propType: "string",
description: '记录Id',
}
],
preview: {
},
targets: ["steedos__RecordPage", "steedos__AppPage", "steedos__HomePage"],
engines: ["amis"],
// settings for amis.
amis: {
name: 'steedos-record-service',
icon: "fa-fw fa fa-list-alt"
}
};

export default {
...config,
snippets: [
{
title: config.title,
screenshot: "",
schema: {
componentName: config.componentName,
props: config.preview
}
}
],
amis: {
render: {
type: config.amis.name,
usage: "renderer",
weight: 1,
framework: "react"
},
plugin: {
rendererName: config.amis.name,
$schema: '/schemas/UnkownSchema.json',
name: config.title,
description: config.title,
tags: [config.group],
order: -9999,
icon: config.amis.icon,
scaffold: {
type: config.amis.name,
body: [],// 容器类字段
label: config.title,
objectApiName: "${objectName}",
recordId: "${recordId}"
},
regions: [
{
key: 'body',
label: '内容区'
}
],
previewSchema: {
type: config.amis.name,
objectApiName: 'space_users'
},
panelTitle: "设置",
panelControls: [
{
"type": "select",
"label": "对象",
"name": "objectApiName",
"searchable": true,
"multiple": false,
"source": {
"method": "get",
"url": "/service/api/amis-design/objects",
"requestAdaptor": "api.url = Builder.settings.rootUrl + api.url; if(!api.headers){api.headers = {}};api.headers.Authorization='Bearer ' + Builder.settings.tenantId + ',' + Builder.settings.authToken ;return api;",
"adaptor": `
let data = payload.data;
payload.unshift({
label: "当前对象",
name: "\${objectName}"
});
return payload;
`
},
"labelField": "label",
"valueField": "name",
"menuTpl": ""
},
{
type: "text",
name: "recordId",
label: "记录ID"
}
]
}
}
};

0 comments on commit 9300d94

Please sign in to comment.