@steedos/service-pages 2.3.0-beta.8 → 2.3.0

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.
@@ -59,6 +59,8 @@
59
59
  window.define.amd = undefined;
60
60
 
61
61
  window.ReactDOM = ReactDom;
62
+ window.React17 = window.React;
63
+ window.ReactDOM17 = window.ReactDOM;
62
64
 
63
65
  // const BuilderSDK = BuilderReact;
64
66
 
@@ -71,18 +73,26 @@
71
73
 
72
74
  // window.builder = BuilderReact.builder;
73
75
 
74
- Builder.set({
75
- rootUrl: __meteor_runtime_config__.ROOT_URL,
76
- unpkgUrl: Steedos.absoluteUrl('/unpkg.com')
76
+ Promise.all([
77
+ waitForThing(Creator, 'USER_CONTEXT'),
78
+ ]).then(()=>{
79
+ Builder.set({
80
+ rootUrl: __meteor_runtime_config__.ROOT_URL,
81
+ unpkgUrl: Steedos.absoluteUrl('/unpkg.com'),
82
+ context: {
83
+ rootUrl: __meteor_runtime_config__.ROOT_URL,
84
+ tenantId: Creator.USER_CONTEXT.spaceId,
85
+ userId: Creator.USER_CONTEXT.userId,
86
+ authToken: Creator.USER_CONTEXT.user.authToken
87
+ }
88
+ })
89
+ // if(Meteor.settings.public.page && Meteor.settings.public.page.assetUrls){
90
+ // const defaultAssetsUrls = Meteor.settings.public.page.assetUrls.split(',')
91
+ // Builder.registerRemoteAssets(defaultAssetsUrls)
92
+ // }
93
+
94
+ window.postMessage({ type: "Builder.loaded" })
77
95
  })
78
-
79
- if(Meteor.settings.public.page && Meteor.settings.public.page.assetUrls){
80
- const defaultAssetsUrls = Meteor.settings.public.page.assetUrls.split(',')
81
- Builder.registerRemoteAssets(defaultAssetsUrls)
82
- }
83
-
84
- window.postMessage({ type: "Builder.loaded" })
85
-
86
96
  })();
87
97
 
88
98
 
@@ -179,7 +179,7 @@
179
179
  maskClosable: false,
180
180
  footer: null,
181
181
  bodyStyle: {padding: "0px", paddingTop: "12px"},
182
- children: React.createElement(BuilderComponent, {
182
+ children: React17.createElement(BuilderComponent, {
183
183
  model: "page", content: {
184
184
  "data": pageContentData
185
185
  }
@@ -195,7 +195,7 @@
195
195
  keyboard: false, // 禁止 esc 关闭
196
196
  footer: null,
197
197
  bodyStyle: {padding: "0px", paddingTop: "12px"},
198
- children: React.createElement(BuilderComponent, {
198
+ children: React17.createElement(BuilderComponent, {
199
199
  model: "page", content: {
200
200
  "data": pageContentData
201
201
  }
@@ -2,49 +2,198 @@
2
2
  * @Author: baozhoutao@steedos.com
3
3
  * @Date: 2022-06-02 17:45:15
4
4
  * @LastEditors: baozhoutao@steedos.com
5
- * @LastEditTime: 2022-07-13 10:59:56
5
+ * @LastEditTime: 2022-08-31 12:01:11
6
6
  * @Description:
7
7
  -->
8
8
  <html>
9
9
  <head>
10
10
  <script src="/unpkg.com/@steedos-builder/fiddle@0.0.5/dist/builder-fiddle.umd.js"></script>
11
+ <script src="/unpkg.com/axios@0.26.1/dist/axios.min.js"></script>
11
12
  </head>
12
13
 
13
14
  <body>
14
-
15
15
  <builder-fiddle host="<%=builderHost%>"></builder-fiddle>
16
-
17
16
  <script>
18
- let comp = document.querySelector( 'builder-fiddle' )
19
- const data = {
20
- AmisSchema: {
21
- "type": "page",
22
- "title": "Steedos Form Page",
23
- "body": [
24
- {
25
- "type": "form",
26
- "body": [
27
- {
28
- "type": "input-text",
29
- "name": "a",
30
- "label": "Name"
17
+ const settings = {
18
+ assetUrls: "<%=assetUrls%>",
19
+ rootUrl: "<%=rootUrl%>",
20
+ userId: "<%=userId%>",
21
+ tenantId: "<%=tenantId%>",
22
+ authToken: "<%=authToken%>",
23
+ pageId: "<%=pageId%>",
24
+ messageOnly: true,
25
+ };
26
+
27
+ let comp = document.querySelector("builder-fiddle");
28
+
29
+ const loadPage = async () => {
30
+ const { assetUrls, rootUrl, userId, tenantId, authToken, pageId } = settings;
31
+
32
+ // 如果传入 steedos rooturl
33
+ if (rootUrl && !authToken) return;
34
+
35
+ const initialContent = {
36
+ type: "page",
37
+ title: "Welcome to Steedos",
38
+ body: [],
39
+ regions: ["body"],
40
+ data: {
41
+ objectName: "space_users",
42
+ recordId: "",
43
+ initialValues: {},
44
+ appId: "builder",
45
+ title: "",
46
+ context: {
47
+ rootUrl,
48
+ userId,
49
+ tenantId,
50
+ authToken,
51
+ },
52
+ },
53
+ };
54
+
55
+ if (pageId) {
56
+ const result = await axios.get(
57
+ `${rootUrl}/service/api/page/pageVersion/${pageId}/latest/`,
58
+ {
59
+ withCredentials: true,
60
+ headers: { Authorization: `Bearer ${tenantId},${authToken}` },
61
+ }
62
+ );
63
+ if (result?.data) {
64
+ let schema = result.data.schema || initialContent;
65
+
66
+ let objectName = result.data.object_name;
67
+ let pageType = result.data.type;
68
+ if (typeof schema === "string") {
69
+ schema = JSON.parse(schema);
70
+ }
71
+
72
+ if (!schema.data) {
73
+ schema.data = {};
74
+ }
75
+
76
+ if (!schema.data.context) {
77
+ schema.data.context = {};
78
+ }
79
+
80
+ schema.data.objectName = objectName;
81
+
82
+ schema.data.context.rootUrl = rootUrl;
83
+ schema.data.context.tenantId = tenantId;
84
+ schema.data.context.userId = userId;
85
+ schema.data.context.authToken = authToken;
86
+
87
+ if (objectName && pageType === "record") {
88
+ const record = await axios.get(
89
+ `${rootUrl}/api/v4/${objectName}?$orderby=modified&$top=1`,
90
+ {
91
+ withCredentials: true,
92
+ headers: { Authorization: `Bearer ${tenantId},${authToken}` },
93
+ }
94
+ );
95
+ const value = record?.data?.value;
96
+ if (value?.length > 0) {
97
+ schema.data.recordId = value[0]._id;
31
98
  }
32
- ]
99
+ }
100
+
101
+ return schema || initialContent
102
+ }
103
+ } else {
104
+ return initialContent
105
+ }
106
+ };
107
+
108
+ const savePage = async (data) => {
109
+ const { rootUrl, userId, tenantId, authToken, pageId } = settings;
110
+
111
+ if (!pageId) {
112
+ return;
113
+ }
114
+
115
+ // 保存schema时,清理context下的认证信息
116
+ const schema = JSON.parse(
117
+ JSON.stringify(data.data.AmisSchema, null, 4)
118
+ );
119
+ if (schema.data && typeof schema.data.context === 'object' ) {
120
+ delete schema.data.context.userId;
121
+ delete schema.data.context.tenantId;
122
+ delete schema.data.context.authToken;
123
+ }
124
+ return await axios.put(
125
+ `${rootUrl}/service/api/page/pageVersion/${pageId}`,
126
+ {
127
+ withCredentials: true,
128
+ schema: JSON.stringify(schema, null, 4), //直接存储json格式会导致react form异常。
129
+ },
130
+ {
131
+ headers: { Authorization: `Bearer ${tenantId},${authToken}` },
132
+ }
133
+ )
134
+ .catch(function (error) {
135
+ // handle error
136
+ console.log(error);
137
+ });
138
+ };
139
+
140
+ const deployPageVersion = async () => {
141
+ const { rootUrl, tenantId, authToken, pageId } = settings;
142
+
143
+ if (!pageId) {
144
+ return;
145
+ }
146
+ return axios
147
+ .post(
148
+ `${rootUrl}/service/api/page/deploy`,
149
+ {
150
+ withCredentials: true,
151
+ pageId: pageId,
152
+ },
153
+ {
154
+ headers: { Authorization: `Bearer ${tenantId},${authToken}` },
155
+ }
156
+ )
157
+ .then(function (response) {
158
+ //保存时, 刷新父页面
159
+ if (window.opener) {
160
+ window.opener.postMessage(
161
+ Object.assign(
162
+ { type: "record.edited" },
163
+ { objectName: "pages" },
164
+ { record: {} }
165
+ ),
166
+ "*"
167
+ );
168
+ }
169
+ })
170
+ .catch(function (error) {
171
+ // handle error
172
+ console.log(error);
173
+ });
174
+ };
175
+ window.addEventListener('message', function (event) {
176
+ const { data } = event;
177
+ if (data) {
178
+ if (data.type === 'builder.loadContent') {
179
+ loadPage().then((content)=>{
180
+ comp.messageFrame('builder.contentChanged', { AmisSchema : content } )
181
+ })
182
+ }
183
+ if (data.type === 'builder.saveContent') {
184
+ savePage(data.data).then(()=>{
185
+ comp.messageFrame('builder.contentSaved')
186
+ })
187
+ }
188
+ if(data.type === "builder.deployContent"){
189
+ deployPageVersion().then(()=>{
190
+ comp.messageFrame('builder.contentDeployed')
191
+ })
33
192
  }
34
- ]
35
- }
36
- };
37
- // comp.data = data;
38
-
39
- const settings = {
40
- assetUrls: '<%=assetUrls%>',
41
- rootUrl: '<%=rootUrl%>',
42
- userId: '<%=userId%>',
43
- tenantId: '<%=tenantId%>',
44
- authToken: '<%=authToken%>',
45
- pageId: '<%=pageId%>',
46
- }
47
- comp.settings = settings
193
+ }
194
+ })
195
+
196
+ comp.settings = settings;
48
197
  </script>
49
198
  </body>
50
199
  </html>
@@ -10,6 +10,7 @@ const ejs = require('ejs');
10
10
  const fs = require('fs');
11
11
  const _ = require('lodash');
12
12
  const path = require('path');
13
+ const objectql = require('@steedos/objectql');
13
14
 
14
15
  router.get('/api/pageDesign', core.requireAuthentication, async function (req, res) {
15
16
  try {
@@ -35,10 +36,10 @@ router.get('/api/pageDesign', core.requireAuthentication, async function (req, r
35
36
  // userId: userSession.userId,
36
37
  // authToken: userSession.authToken
37
38
  // }
38
-
39
+ const page = await objectql.broker.call(`page.getLatestPageVersion`, {pageId: req.query.pageId});
39
40
  const retUrl = __meteor_runtime_config__.ROOT_URL + '/app/admin/pages/view/' + req.query.pageId
40
- const builderHost = `https://builder.steedos.cn/amis?${assetUrl}&retUrl=${retUrl}`;
41
- // const builderHost = `http://127.0.0.1:3000/amis?${assetUrl}&retUrl=${retUrl}`;
41
+ const steedosBuilderUrl = process.env.STEEDOS_BUILDER_URL || 'https://builder.steedos.cn';
42
+ const builderHost = `${steedosBuilderUrl}/amis?${assetUrl}&retUrl=${retUrl}&pageType=${page.type}`;
42
43
 
43
44
  // let data = fs.readFileSync(__dirname+'/design.html', 'utf8');
44
45
  // res.send(data.replace('SteedosBuilderHost',steedosBuilderHost).replace('DataContext', JSON.stringify(dataContext)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-pages",
3
- "version": "2.3.0-beta.8",
3
+ "version": "2.3.0",
4
4
  "main": "package.service.js",
5
5
  "scripts": {},
6
6
  "license": "MIT",
@@ -8,7 +8,7 @@
8
8
  "publishConfig": {
9
9
  "access": "public"
10
10
  },
11
- "gitHead": "d0bfd52568ee68e3af0f251c06bd8169e823851f",
11
+ "gitHead": "b00e79e6fb8549b2fabed7b6cd6d4847775ba5df",
12
12
  "dependencies": {
13
13
  "ejs": "^3.1.8"
14
14
  }