@steedos/service-pages 2.6.1-beta.6 → 2.6.2-beta.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.
Files changed (25) hide show
  1. package/main/default/applications/app_charts.app.yml +1 -1
  2. package/main/default/client/builder.client.js +3 -2
  3. package/main/default/client/page.render.client.js +97 -89
  4. package/main/default/objectTranslations/page_assignments.en/page_assignments.en.objectTranslation.yml +14 -14
  5. package/main/default/objectTranslations/pages.en/pages.en.objectTranslation.yml +9 -1
  6. package/main/default/objectTranslations/pages.zh-CN/pages.zh-CN.objectTranslation.yml +8 -0
  7. package/main/default/objects/page_versions/page_versions.object.yml +1 -1
  8. package/main/default/objects/pages/buttons/showDesign.button.js +1 -1
  9. package/main/default/objects/pages/buttons/viewPage.button.js +22 -0
  10. package/main/default/objects/pages/buttons/viewPage.button.yml +6 -0
  11. package/main/default/objects/pages/fields/allow_anonymous.field.yml +5 -0
  12. package/main/default/objects/pages/listviews/customize.listview.yml +18 -0
  13. package/main/default/objects/pages/listviews/system.listview.yml +18 -0
  14. package/main/default/routes/page_design.router.js +20 -5
  15. package/main/default/routes/page_view.ejs +198 -0
  16. package/main/default/routes/page_view.router.js +140 -0
  17. package/main/default/services/page.service.js +31 -3
  18. package/main/default/translations/en.translation.yml +11 -1
  19. package/main/default/translations/zh-CN.translation.yml +9 -0
  20. package/main/default/triggers/page_assignments_check.trigger.js +8 -8
  21. package/main/default/triggers/pages_api_name.trigger.js +2 -2
  22. package/main/default/triggers/pages_check.trigger.js +3 -3
  23. package/package.json +2 -2
  24. package/package.service.js +54 -5
  25. package/main/default/routes/design.html +0 -117
@@ -12,7 +12,7 @@ admin_menus:
12
12
  permission_sets:
13
13
  - admin
14
14
  - _id: pages
15
- name: Mini Pages
15
+ name: Micro Pages
16
16
  object_name: pages
17
17
  parent: user_interface
18
18
  sort: 300
@@ -51,10 +51,11 @@
51
51
  tenantId: Creator.USER_CONTEXT.spaceId,
52
52
  userId: Creator.USER_CONTEXT.userId,
53
53
  authToken: Creator.USER_CONTEXT.user.authToken
54
- }
54
+ },
55
+ locale: Creator.USER_CONTEXT.user.locale
55
56
  })
56
57
 
57
- window.postMessage({ type: "Builder.loaded" })
58
+ window.postMessage({ type: "Builder.loaded" }, "*")
58
59
  })
59
60
  })();
60
61
 
@@ -276,7 +276,7 @@
276
276
  $scopeId : schema.name || schema.id
277
277
  }
278
278
  });
279
- console.log(`defData`, defData)
279
+ // console.log(`defData`, defData)
280
280
 
281
281
  schema = lodash.defaultsDeep(defData , schema);
282
282
 
@@ -331,6 +331,10 @@
331
331
 
332
332
  const page = Steedos.Page.getPage('app', app_id, null, null, pageName);
333
333
  if (page) {
334
+ Steedos.setDocumentTitle({
335
+ pageName: page.label,
336
+ tabName: null
337
+ })
334
338
  if (page.render_engine && page.render_engine != 'redash') {
335
339
  return Steedos.Page.render(container, page, Object.assign({}, options, {
336
340
  appId: app_id
@@ -354,93 +358,95 @@
354
358
  // console.log('autorun=====>computation:', computation)
355
359
  // Session.get("record_id");
356
360
  var container, e, lastData, ref, ref1, ref2, regions, schema, updateProps, updatePropsData;
357
- regions = self.data.regions();
358
- // console.log('regions====>', regions, this.lastRegions);
359
- updateProps = true;
360
- if (regions.objectName !== ((ref = this.lastRegions) != null ? ref.objectName : void 0)) {
361
- updateProps = false;
362
- }
363
- this.lastRegions = regions;
364
- if (updateProps && self.pageName) {
365
- try {
366
- if (SteedosUI.refs[self.pageName]) {
367
- let queryParams = FlowRouter.current().queryParams
368
-
369
- if(_.isArray(queryParams.side_object)){
370
- if(queryParams.side_object.length >= 1){
371
- queryParams.side_object = queryParams.side_object[0]
372
- }else{
373
- queryParams.side_object = ''
361
+ if(self.data.regions){
362
+ regions = self.data.regions();
363
+ // console.log('regions====>', regions, this.lastRegions);
364
+ updateProps = true;
365
+ if (regions.objectName !== ((ref = this.lastRegions) != null ? ref.objectName : void 0)) {
366
+ updateProps = false;
367
+ }
368
+ this.lastRegions = regions;
369
+ if (updateProps && self.pageName) {
370
+ try {
371
+ if (SteedosUI.refs[self.pageName]) {
372
+ let queryParams = FlowRouter.current().queryParams
373
+
374
+ if(_.isArray(queryParams.side_object)){
375
+ if(queryParams.side_object.length >= 1){
376
+ queryParams.side_object = queryParams.side_object[0]
377
+ }else{
378
+ queryParams.side_object = ''
379
+ }
374
380
  }
375
- }
376
-
377
- if(_.isArray(queryParams.side_listview_id)){
378
- if(queryParams.side_listview_id.length >= 1){
379
- queryParams.side_listview_id = queryParams.side_listview_id[0]
380
- }else{
381
- queryParams.side_listview_id = ''
381
+
382
+ if(_.isArray(queryParams.side_listview_id)){
383
+ if(queryParams.side_listview_id.length >= 1){
384
+ queryParams.side_listview_id = queryParams.side_listview_id[0]
385
+ }else{
386
+ queryParams.side_listview_id = ''
387
+ }
388
+ };
389
+
390
+ updatePropsData = {
391
+ objectName: objectName,
392
+ pageType: regions.pageType,
393
+ listViewId: regions.listViewId,
394
+ ...queryParams
395
+ };
396
+ if(queryParams.side_listview_id){
397
+ updatePropsData.listName=queryParams.side_listview_id
398
+ }else if(regions.listViewId){
399
+ updatePropsData.listName=regions.listViewId
382
400
  }
383
- };
384
-
385
- updatePropsData = {
386
- objectName: objectName,
387
- pageType: regions.pageType,
388
- listViewId: regions.listViewId,
389
- ...queryParams
390
- };
391
- if(queryParams.side_listview_id){
392
- updatePropsData.listName=queryParams.side_listview_id
393
- }else if(regions.listViewId){
394
- updatePropsData.listName=regions.listViewId
401
+
402
+ updatePropsData.display = Steedos.Page.getDisplay(objectName)
403
+
404
+ updatePropsData.recordId = Tracker.nonreactive(function() {
405
+ return Session.get("record_id");
406
+ });
407
+ lastData = ((ref1 = SteedosUI.refs[self.pageName]) != null ? (ref2 = ref1.__$schema) != null ? ref2.data : void 0 : void 0) || {};
408
+ // console.log("page_object Steedos.Page.Record.updateProps", {
409
+ // data: window._.defaultsDeep(updatePropsData, lastData)
410
+ // });
411
+ return SteedosUI.refs[self.pageName].updateProps({
412
+ data: window._.defaultsDeep(updatePropsData, lastData)
413
+ });
414
+ }
415
+ } catch (error) {
416
+ e = error;
417
+ console.error(self.pageName + ": " + e);
395
418
  }
396
-
397
- updatePropsData.display = Steedos.Page.getDisplay(objectName)
398
-
399
- updatePropsData.recordId = Tracker.nonreactive(function() {
400
- return Session.get("record_id");
401
- });
402
- lastData = ((ref1 = SteedosUI.refs[self.pageName]) != null ? (ref2 = ref1.__$schema) != null ? ref2.data : void 0 : void 0) || {};
403
- // console.log("page_object Steedos.Page.Record.updateProps", {
404
- // data: window._.defaultsDeep(updatePropsData, lastData)
405
- // });
406
- return SteedosUI.refs[self.pageName].updateProps({
407
- data: window._.defaultsDeep(updatePropsData, lastData)
408
- });
409
419
  }
410
- } catch (error) {
411
- e = error;
412
- console.error(self.pageName + ": " + e);
413
- }
414
- }
415
- if (!updateProps && self.pageName && SteedosUI.refs[self.pageName]) {
416
- try {
417
- SteedosUI.refs[self.pageName].unmount();
418
- } catch (error) {
419
- e = error;
420
- console.error(self.pageName + ": " + e);
421
- }
422
- }
423
- if (self.data.regions) {
424
- regions = Tracker.nonreactive(self.data.regions);
425
- this.lastRegions = regions;
426
- if (regions && regions.page && regions.page.schema) {
427
- schema = regions.page.schema;
428
- if (_.isString(schema)) {
429
- schema = JSON.parse(schema);
420
+ if (!updateProps && self.pageName && SteedosUI.refs[self.pageName]) {
421
+ try {
422
+ SteedosUI.refs[self.pageName].unmount();
423
+ } catch (error) {
424
+ e = error;
425
+ console.error(self.pageName + ": " + e);
426
+ }
427
+ }
428
+ if (self.data.regions) {
429
+ regions = Tracker.nonreactive(self.data.regions);
430
+ this.lastRegions = regions;
431
+ if (regions && regions.page && regions.page.schema) {
432
+ schema = regions.page.schema;
433
+ if (_.isString(schema)) {
434
+ schema = JSON.parse(schema);
435
+ }
436
+ self.pageName = schema.name;
437
+ }
438
+ }
439
+ objectName = Tracker.nonreactive(function() {
440
+ return Session.get("object_name");
441
+ });
442
+ recordId = Tracker.nonreactive(function() {
443
+ return Session.get("record_id");
444
+ });
445
+ container = Steedos.Page.Object.render(self, objectName, recordId);
446
+ // console.log("page_object Steedos.Page.Object.render");
447
+ if (container) {
448
+ return self.containerList.push(container);
430
449
  }
431
- self.pageName = schema.name;
432
- }
433
- }
434
- objectName = Tracker.nonreactive(function() {
435
- return Session.get("object_name");
436
- });
437
- recordId = Tracker.nonreactive(function() {
438
- return Session.get("record_id");
439
- });
440
- container = Steedos.Page.Object.render(self, objectName, recordId);
441
- // console.log("page_object Steedos.Page.Object.render");
442
- if (container) {
443
- return self.containerList.push(container);
444
450
  }
445
451
  });
446
452
  };
@@ -790,19 +796,19 @@
790
796
  const getSpaceLogo = function(){
791
797
  let logoSrc = '';
792
798
  const space = db.spaces.findOne(Steedos.getSpaceId())
793
- if(space?.avatar){
799
+ if(space && space.avatar){
794
800
  logoSrc = Steedos.absoluteUrl('api/files/avatars/'+space.avatar)
795
- }else if(space?.avatar_square){
801
+ }else if(space && space.avatar_square){
796
802
  logoSrc = Steedos.absoluteUrl('api/files/avatars/'+space.avatar_square)
797
803
  }else{
798
804
  var settings = Session.get("tenant_settings");
799
805
  var avatar_url = "";
800
806
  if(settings){
801
- avatar_url = settings?.logo_square_url;
807
+ avatar_url = settings.logo_square_url;
802
808
  }
803
809
  if(!avatar_url || !settings){
804
810
  avatar_url = "/images/logo_platform.png"
805
- if(Meteor.user()?.locale != 'zh-cn'){
811
+ if(Meteor.user() && Meteor.user().locale != 'zh-cn'){
806
812
  avatar_url = "/images/logo_platform.en-us.png"
807
813
  }
808
814
  }
@@ -839,7 +845,8 @@
839
845
  try {
840
846
  const data = {
841
847
  app,
842
- isMobile: window.innerWidth <= 768
848
+ isMobile: window.innerWidth <= 768,
849
+ tabId
843
850
  };
844
851
  const page = Steedos.Page.Header.getPage(appId, tabId);
845
852
  var rootId = "steedosGlobalHeaderRoot";
@@ -897,7 +904,8 @@
897
904
  try {
898
905
  const data = {
899
906
  app,
900
- isMobile: window.innerWidth <= 768
907
+ isMobile: window.innerWidth <= 768,
908
+ tabId
901
909
  };
902
910
  const page = Steedos.Page.Footer.getPage(appId, tabId);
903
911
  var rootId = "steedosGlobalFooterRoot";
@@ -1,48 +1,48 @@
1
1
  name: page_assignments
2
- label: 页面分配
2
+ label: Page Assignments
3
3
  description:
4
4
  fields:
5
5
  app:
6
- label: 应用
6
+ label: App
7
7
  help:
8
8
  description:
9
9
  desktop:
10
- label: 桌面端
10
+ label: Desktop
11
11
  help:
12
12
  description:
13
13
  is_system:
14
- label: 系统
14
+ label: System
15
15
  help:
16
16
  description:
17
17
  mobile:
18
- label: 移动端
18
+ label: Mobile
19
19
  help:
20
20
  description:
21
21
  page:
22
- label: 页面
22
+ label: Page
23
23
  help:
24
24
  description:
25
25
  profile:
26
- label: 简档
26
+ label: Profile
27
27
  help:
28
28
  description:
29
29
  record_type:
30
- label: 记录类型
30
+ label: Record Type
31
31
  help:
32
32
  description:
33
33
  type:
34
- label: 授权类型
34
+ label: Authorization Type
35
35
  help:
36
36
  options:
37
- - label: 组织默认设置
37
+ - label: Organization Default Settings
38
38
  value: orgDefault
39
- - label: 应用程序默认设置
39
+ - label: Application Default Settings
40
40
  value: appDefault
41
- - label: 应用程序和简档
41
+ - label: Applications and Profiles
42
42
  value: appRecordProfile
43
43
  description:
44
44
  listviews:
45
45
  all:
46
- label: 所有
46
+ label: All
47
47
  recent:
48
- label: 最近查看
48
+ label: Recently Viewed
@@ -1,5 +1,5 @@
1
1
  name: pages
2
- label: Mini Page
2
+ label: Micro Pages
3
3
  description:
4
4
  fields:
5
5
  dashboard_filters_enabled:
@@ -80,11 +80,17 @@ fields:
80
80
  label: Version Number
81
81
  help:
82
82
  description:
83
+ allow_anonymous:
84
+ label: Allow anonymous access
83
85
  listviews:
84
86
  all:
85
87
  label: All Pages
86
88
  recent:
87
89
  label: Recently Viewed
90
+ customize:
91
+ label: Customize
92
+ system:
93
+ label: System
88
94
  actions:
89
95
  customPage:
90
96
  label: Custom Page
@@ -98,3 +104,5 @@ actions:
98
104
  label: Reset Schema
99
105
  showDesign:
100
106
  label: Show Design
107
+ viewPage:
108
+ label: View
@@ -80,11 +80,17 @@ fields:
80
80
  label: 版本号
81
81
  help:
82
82
  description:
83
+ allow_anonymous:
84
+ label: 允许匿名访问
83
85
  listviews:
84
86
  all:
85
87
  label: 所有
86
88
  recent:
87
89
  label: 最近查看
90
+ customize:
91
+ label: 自定义
92
+ system:
93
+ label: 系统
88
94
  actions:
89
95
  customPage:
90
96
  label: 自定义
@@ -98,3 +104,5 @@ actions:
98
104
  label: 重置
99
105
  showDesign:
100
106
  label: 设计器
107
+ viewPage:
108
+ label: 查看
@@ -14,7 +14,7 @@ enable_search: false
14
14
  enable_share: false
15
15
  enable_tasks: false
16
16
  enable_workflow: false
17
- hidden: false
17
+ hidden: true
18
18
  icon: contract
19
19
  is_enable: true
20
20
  version: 2
@@ -1,7 +1,7 @@
1
1
  module.exports = {
2
2
  showDesign: function (object_name, record_id) {
3
3
  // Steedos.openWindow();
4
- document.location = Steedos.absoluteUrl(`/api/pageDesign?pageId=${record_id}&assetUrls=${Builder.settings.assetUrls}`);
4
+ document.location = Steedos.absoluteUrl(`/api/pageDesign?pageId=${record_id}&assetUrls=${Builder.settings.assetUrls}&locale=${Builder.settings.locale}`);
5
5
  },
6
6
  showDesignVisible: function (object_name, record_id, record_permissions) {
7
7
  var perms, record;
@@ -0,0 +1,22 @@
1
+ /*
2
+ * @Author: baozhoutaon@hotoa.com
3
+ * @Date: 2022-03-29 20:33:44
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2023-08-02 16:29:54
6
+ * @Description:
7
+ */
8
+ module.exports = {
9
+ viewPage: function (object_name, record_id) {
10
+ console.log(`viewPaga`, this)
11
+ const { record } = this.record;
12
+ if(record.allow_anonymous){
13
+ window.open(`/api/page/public/${record_id}`)
14
+ }else{
15
+ window.open(`/api/page/view/${record_id}`)
16
+ }
17
+ },
18
+ viewPageVisible: function (object_name, record_id, permission, data) {
19
+ var record = data && data.record;
20
+ return record && record.type === 'app';
21
+ }
22
+ }
@@ -0,0 +1,6 @@
1
+ name: viewPage
2
+ is_enable: true
3
+ label: 查看
4
+ 'on': record_only
5
+ visible: true
6
+ sort: 9999
@@ -0,0 +1,5 @@
1
+ name: allow_anonymous
2
+ label: Allow anonymous access
3
+ type: toggle
4
+ sort_no: 470
5
+ visible_on: "{{'app' == formData.type ? true: false}}"
@@ -0,0 +1,18 @@
1
+ name: customize
2
+ columns:
3
+ - field: label
4
+ - field: name
5
+ - field: render_engine
6
+ - field: type
7
+ - field: object_name
8
+ - field: is_active
9
+ - field: version
10
+ - field: is_system
11
+ wrap: false
12
+ filter_scope: space
13
+ filters: ["is_system","<>",true]
14
+ label: 自定义
15
+ scrolling_mode: standard
16
+ shared: true
17
+ sort_no: 110
18
+ type: grid
@@ -0,0 +1,18 @@
1
+ name: system
2
+ columns:
3
+ - field: label
4
+ - field: name
5
+ - field: render_engine
6
+ - field: type
7
+ - field: object_name
8
+ - field: is_active
9
+ - field: version
10
+ - field: is_system
11
+ wrap: false
12
+ filter_scope: space
13
+ filters: ["is_system","=",true]
14
+ label: 系统
15
+ scrolling_mode: standard
16
+ shared: true
17
+ sort_no: 110
18
+ type: grid
@@ -11,11 +11,23 @@ const fs = require('fs');
11
11
  const _ = require('lodash');
12
12
  const path = require('path');
13
13
  const objectql = require('@steedos/objectql');
14
+
15
+ const getPublicAssetUrls = function(assetUrls){
16
+ const values = _.map(_.split(assetUrls), (item)=>{
17
+ if(_.startsWith(item, '/')){
18
+ return Meteor.absoluteUrl(item) ;
19
+ }else{
20
+ return item;
21
+ }
22
+ })
23
+ return _.join(values, ',')
24
+ }
25
+
14
26
  router.get('/api/pageDesign', core.requireAuthentication, async function (req, res) {
15
27
  try {
16
28
  res.set('Content-Type', 'text/html');
17
29
  const userSession = req.user;
18
- let assetUrls = req.query.assetUrls;
30
+ let assetUrls = getPublicAssetUrls(req.query.assetUrls);
19
31
  const assetUrl = `assetUrl=${assetUrls.split(',').join("&assetUrl=")}&`;
20
32
 
21
33
  // const dataContext = {
@@ -24,13 +36,16 @@ router.get('/api/pageDesign', core.requireAuthentication, async function (req, r
24
36
  // userId: userSession.userId,
25
37
  // authToken: userSession.authToken
26
38
  // }
39
+ let locale = "zh-CN";
40
+ if (req.query.locale == "en-us") {
41
+ locale = "en-US";
42
+ } else if (req.query.locale == "zh-cn") {
43
+ locale = "zh-CN";
44
+ }
27
45
  const page = await objectql.broker.call(`page.getLatestPageVersion`, {pageId: req.query.pageId});
28
46
  const retUrl = __meteor_runtime_config__.ROOT_URL + '/app/admin/pages/view/' + req.query.pageId
29
47
  const steedosBuilderUrl = process.env.STEEDOS_BUILDER_URL || 'https://builder.steedos.cn';
30
- const builderHost = `${steedosBuilderUrl}/amis?${assetUrl}retUrl=${retUrl}&pageType=${page.type}`;
31
-
32
- // let data = fs.readFileSync(__dirname+'/design.html', 'utf8');
33
- // res.send(data.replace('SteedosBuilderHost',steedosBuilderHost).replace('DataContext', JSON.stringify(dataContext)));
48
+ const builderHost = `${steedosBuilderUrl}/amis?${assetUrl}retUrl=${retUrl}&locale=${locale}&pageType=${page.type}`;
34
49
 
35
50
  const filename = __dirname+'/page_design.ejs'
36
51
  const data = {
@@ -0,0 +1,198 @@
1
+ <!--
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2023-08-01 17:47:18
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2023-09-07 16:22:47
6
+ * @Description:
7
+ -->
8
+ <!DOCTYPE html>
9
+ <html>
10
+ <head>
11
+ <style>
12
+ body { background-color: #fff; }
13
+ html {
14
+ background-color: #fff;
15
+ background: #fff !important;
16
+ }
17
+ </style>
18
+ <meta charset="utf-8">
19
+ <title><%=Title%></title>
20
+
21
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
22
+ <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
23
+ <meta name="mobile-web-app-capable" content="yes">
24
+ <meta name="theme-color" content="#000">
25
+ <meta name="application-name">
26
+ <meta name="apple-mobile-web-app-capable" content="yes">
27
+ <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
28
+ <meta name="apple-mobile-web-app-title">
29
+
30
+ <link rel="stylesheet" href="/tailwind/tailwind-base.css" />
31
+
32
+ <script>
33
+ window.Creator = {};
34
+ window.Steedos = {
35
+ isMobile: ()=>{
36
+ return window.innerWidth <= 768;
37
+ }
38
+ };
39
+ window.__meteor_runtime_config__ = <%- JSON.stringify(__meteor_runtime_config__) %>
40
+ window.Meteor = {
41
+ isCordova: false
42
+ }
43
+ </script>
44
+
45
+
46
+ <script src="/lib/jquery/jquery-1.11.2.min.js"></script>
47
+
48
+ <!-- lodash,低代码编辑器的依赖 -->
49
+ <script src="<%=STEEDOS_UNPKG_URL%>/lodash@4.17.21/lodash.min.js"></script>
50
+ <script src="<%=STEEDOS_UNPKG_URL%>/marked@4.0.17/marked.min.js"></script>
51
+
52
+ <script src="<%=STEEDOS_UNPKG_URL%>/crypto-js@4.1.1/crypto-js.js"></script>
53
+
54
+ <!-- Steedos Builder -->
55
+ <script src="<%=STEEDOS_UNPKG_URL%>/@steedos-builder/sdk@0.2.38/dist/index.umd.js"></script>
56
+
57
+ <script src="<%=STEEDOS_AMIS_URL%>/sdk/sdk.js"></script>
58
+
59
+
60
+
61
+ <link rel="stylesheet" type="text/css" href="<%=STEEDOS_UNPKG_URL%>/@salesforce-ux/design-system@2.19.0/assets/styles/salesforce-lightning-design-system.min.css">
62
+ <link rel="stylesheet" href="<%=STEEDOS_AMIS_URL%>/lib/themes/antd.css" />
63
+ <link rel="stylesheet" href="<%=STEEDOS_AMIS_URL%>/lib/helper.css" />
64
+ <link rel="stylesheet" href="<%=STEEDOS_AMIS_URL%>/sdk/iconfont.css" />
65
+ <link rel="stylesheet" href="<%=STEEDOS_UNPKG_URL%>/@fortawesome/fontawesome-free@6.2.0/css/all.min.css" />
66
+
67
+ <link rel="stylesheet" href="<%=ROOT_URL%>/tailwind/tailwind-steedos.css" />
68
+ <link rel="stylesheet" href="<%=ROOT_URL%>/amis/amis.css" />
69
+ </head>
70
+
71
+ <body>
72
+
73
+ <div class="page-template-root"></div>
74
+
75
+ <script>
76
+ window.lodash = _;
77
+ window.MonacoEnvironment = {};
78
+ window.t = (k)=>{
79
+ console.log(`not support window.t`);
80
+ return k;
81
+ }
82
+
83
+ window.FlowRouter = {
84
+ current: ()=>{
85
+ return {
86
+ path: location.pathname,
87
+ queryParams: {}
88
+ }
89
+ }
90
+ }
91
+
92
+ </script>
93
+
94
+ <script src="/pages/js/builder.client.js"></script>
95
+ <script src="/pages/js/page.render.client.js"></script>
96
+ <script src="/pages/js/builder.client.js"></script>
97
+
98
+ <script src="/amis-pages/js/amis.render.client.js"></script>
99
+ <script src="/amis-pages/js/amis.util.client.js"></script>
100
+ <script src="/amis-pages/js/creator.function.client.js"></script>
101
+ <script src="/amis-pages/js/onWindowMessage.client.js"></script>
102
+
103
+
104
+ <script >
105
+ window.Creator.USER_CONTEXT = <%- JSON.stringify(USER_CONTEXT) %>
106
+ window.Builder = BuilderSDK.Builder;
107
+ window.builder = BuilderSDK.builder;
108
+ window.builder.init('steedos');
109
+
110
+ let searchParams = new URLSearchParams(location.search);
111
+ if (searchParams.get('assetUrls')) {
112
+ sessionStorage.setItem('assetUrls', searchParams.get('assetUrls'))
113
+ }
114
+
115
+ let assetUrls = "<%=STEEDOS_PUBLIC_PAGE_ASSETURLS%>"
116
+ if(_.isString(assetUrls)){
117
+ assetUrls = assetUrls.split(',');
118
+ }
119
+
120
+ const getBrowserLocale = function() {
121
+ var l, locale;
122
+ l = window.navigator.userLanguage || window.navigator.language || 'en';
123
+ if (l.indexOf("zh") >= 0) {
124
+ locale = "zh-cn";
125
+ } else {
126
+ locale = "en-us";
127
+ }
128
+ return locale;
129
+ };
130
+
131
+
132
+ Builder.set({
133
+ nodeEnv: "<%=NODE_ENV%>",
134
+ rootUrl: "<%=ROOT_URL%>",
135
+ unpkgUrl: "<%=STEEDOS_UNPKG_URL%>",
136
+ steedosVersion: "<%=STEEDOS_VERSION%>",
137
+ assetUrls: assetUrls,
138
+ steedosAmisVersion: "<%=STEEDOS_AMIS_VERSION%>",
139
+ locale: "<%=STEEDOS_LOCALE%>" || getBrowserLocale()
140
+ });
141
+
142
+ window.axios = amisRequire('axios');
143
+ window.moment = amisRequire('moment');
144
+ window.React = amisRequire('react');
145
+ window.ReactDOM = amisRequire('react-dom');
146
+
147
+ window.addEventListener('message', function (event) {
148
+ const { data } = event;
149
+ if (data.type === 'Builder.loaded') {
150
+ Builder.registerRemoteAssets(Builder.settings.assetUrls);
151
+ }
152
+ })
153
+
154
+ if ("<%=STEEDOS_PUBLIC_SCRIPT_VCONSOLE%>") {
155
+ let scriptTag = document.createElement("script");
156
+ scriptTag.setAttribute("src", "<%=STEEDOS_PUBLIC_SCRIPT_VCONSOLE%>");
157
+ document.getElementsByTagName("head")[0].appendChild(scriptTag);
158
+ scriptTag.onload = function(script){
159
+ window.vConsole = new window.VConsole();
160
+ }
161
+ }
162
+
163
+ if ("<%=STEEDOS_PUBLIC_SCRIPT_PLUGINS%>") {
164
+ "<%=STEEDOS_PUBLIC_SCRIPT_PLUGINS%>".split(',').forEach(function (src) {
165
+ let scriptTag = document.createElement("script");
166
+ scriptTag.setAttribute("src", src);
167
+ document.getElementsByTagName("head")[0].appendChild(scriptTag);
168
+ })
169
+ }
170
+
171
+ if ("<%=STEEDOS_PUBLIC_STYLE_PLUGINS%>") {
172
+ "<%=STEEDOS_PUBLIC_STYLE_PLUGINS%>".split(',').forEach(function (src) {
173
+ let styleTag = document.createElement("link");
174
+ styleTag.setAttribute("rel", "stylesheet");
175
+ styleTag.setAttribute("type", "text/css");
176
+ styleTag.setAttribute("href", src);
177
+ document.getElementsByTagName("head")[0].appendChild(styleTag);
178
+ })
179
+ }
180
+
181
+
182
+ const appId = 'admin';
183
+
184
+ const page = {
185
+ render_engine: 'amis',
186
+ name: "<%=pageApiName%>",
187
+ schema: <%- JSON.stringify(pageSchema) %>
188
+ }
189
+
190
+ const container = $(".page-template-root")[0];
191
+
192
+ Steedos.Page.render(container, page, Object.assign({}, {
193
+ appId: appId
194
+ }));
195
+
196
+ </script>
197
+ </body>
198
+ </html>
@@ -0,0 +1,140 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2022-04-04 16:34:28
4
+ * @Description:
5
+ */
6
+ const express = require('express');
7
+ const router = express.Router();
8
+ const auth = require('@steedos/auth');
9
+ const ejs = require('ejs');
10
+ const fs = require('fs');
11
+ const _ = require('lodash');
12
+ const path = require('path');
13
+ const objectql = require('@steedos/objectql');
14
+
15
+ router.get('/api/page/view/:pageId', auth.authentication, async function (req, res) {
16
+ try {
17
+ res.set('Content-Type', 'text/html');
18
+ const userSession = req.user;
19
+ const { pageId } = req.params;
20
+ const page = await objectql.getObject('pages').findOne(pageId)
21
+ const pageVersion = await objectql.broker.call(`page.getLatestPageVersion`, {pageId: pageId});
22
+ if(!pageVersion){
23
+ return res.status(404).send({ message: 'Page not found' });
24
+ }else if(page.type != 'app'){
25
+ // 如果不是app类型的page,则返回错误信息
26
+ return res.status(404).send({ message: 'Must be App page.' });
27
+ }
28
+
29
+ // 如果当前用户未登录,且页面不允许匿名访问,则跳转到登录页面
30
+ if(!userSession && !page.allow_anonymous){
31
+ return res.redirect(`/accounts/a/#/login?redirect_uri=${encodeURIComponent(`/api/page/view/${pageId}`)}`);
32
+ }
33
+
34
+ let assetUrls = req.query.assetUrls;
35
+
36
+ let locale = "zh-CN";
37
+ if (req.query.locale == "en-us") {
38
+ locale = "en-US";
39
+ } else if (req.query.locale == "zh-cn") {
40
+ locale = "zh-CN";
41
+ }
42
+
43
+ const filename = __dirname+'/page_view.ejs';
44
+ const data = {
45
+ Title: page.label,
46
+ pageApiName: page.name,
47
+ STEEDOS_UNPKG_URL: process.env.STEEDOS_UNPKG_URL,
48
+ STEEDOS_AMIS_URL: process.env.STEEDOS_AMIS_URL,
49
+ STEEDOS_PUBLIC_PAGE_ASSETURLS: assetUrls || process.env.STEEDOS_PUBLIC_PAGE_ASSETURLS,
50
+ NODE_ENV: process.env.NODE_ENV,
51
+ ROOT_URL: __meteor_runtime_config__.ROOT_URL,
52
+ STEEDOS_VERSION: process.env.STEEDOS_VERSION,
53
+ STEEDOS_AMIS_VERSION: process.env.STEEDOS_AMIS_VERSION,
54
+ STEEDOS_PUBLIC_SCRIPT_VCONSOLE: process.env.STEEDOS_PUBLIC_SCRIPT_VCONSOLE,
55
+ STEEDOS_PUBLIC_SCRIPT_PLUGINS: process.env.STEEDOS_PUBLIC_SCRIPT_PLUGINS,
56
+ STEEDOS_PUBLIC_STYLE_PLUGINS: process.env.STEEDOS_PUBLIC_STYLE_PLUGINS,
57
+ STEEDOS_LOCALE: locale,
58
+ USER_CONTEXT: {
59
+ user: userSession,
60
+ userId: userSession.userId,
61
+ spaceId: userSession.spaceId
62
+ },
63
+ pageSchema: _.isString(pageVersion.schema) ? JSON.parse(pageVersion.schema) : pageVersion.schema,
64
+ __meteor_runtime_config__: __meteor_runtime_config__
65
+ }
66
+ const options = {}
67
+ ejs.renderFile(filename, data, options, function(err, str){
68
+ // str => Rendered HTML string
69
+ if(err){
70
+ console.log(`err`, err)
71
+ }
72
+ res.send(str);
73
+ });
74
+
75
+ } catch (error) {
76
+ res.status(500).send({ message: error.message });
77
+ }
78
+
79
+ });
80
+
81
+ router.get('/api/page/public/:pageId', async function (req, res) {
82
+ try {
83
+ res.set('Content-Type', 'text/html');
84
+ const { pageId } = req.params;
85
+ const page = await objectql.getObject('pages').findOne(pageId)
86
+ const pageVersion = await objectql.broker.call(`page.getLatestPageVersion`, {pageId: pageId});
87
+ if(!pageVersion){
88
+ return res.status(404).send({ message: 'Page not found' });
89
+ }else if(page.type != 'app'){
90
+ // 如果不是app类型的page,则返回错误信息
91
+ return res.status(404).send({ message: 'Must be App page.' });
92
+ }
93
+
94
+ let assetUrls = req.query.assetUrls;
95
+
96
+ let locale = "zh-CN";
97
+ if (req.query.locale == "en-us") {
98
+ locale = "en-US";
99
+ } else if (req.query.locale == "zh-cn") {
100
+ locale = "zh-CN";
101
+ }
102
+
103
+ const filename = __dirname+'/page_view.ejs';
104
+ const data = {
105
+ Title: page.label,
106
+ pageApiName: page.name,
107
+ STEEDOS_UNPKG_URL: process.env.STEEDOS_UNPKG_URL,
108
+ STEEDOS_AMIS_URL: process.env.STEEDOS_AMIS_URL,
109
+ STEEDOS_PUBLIC_PAGE_ASSETURLS: assetUrls || process.env.STEEDOS_PUBLIC_PAGE_ASSETURLS,
110
+ NODE_ENV: process.env.NODE_ENV,
111
+ ROOT_URL: __meteor_runtime_config__.ROOT_URL,
112
+ STEEDOS_VERSION: process.env.STEEDOS_VERSION,
113
+ STEEDOS_AMIS_VERSION: process.env.STEEDOS_AMIS_VERSION,
114
+ STEEDOS_PUBLIC_SCRIPT_VCONSOLE: process.env.STEEDOS_PUBLIC_SCRIPT_VCONSOLE,
115
+ STEEDOS_PUBLIC_SCRIPT_PLUGINS: process.env.STEEDOS_PUBLIC_SCRIPT_PLUGINS,
116
+ STEEDOS_PUBLIC_STYLE_PLUGINS: process.env.STEEDOS_PUBLIC_STYLE_PLUGINS,
117
+ STEEDOS_LOCALE: locale,
118
+ USER_CONTEXT: {
119
+ user: {},
120
+ userId: "",
121
+ spaceId: ""
122
+ },
123
+ pageSchema: _.isString(pageVersion.schema) ? JSON.parse(pageVersion.schema) : pageVersion.schema,
124
+ __meteor_runtime_config__: __meteor_runtime_config__
125
+ }
126
+ const options = {}
127
+ ejs.renderFile(filename, data, options, function(err, str){
128
+ // str => Rendered HTML string
129
+ if(err){
130
+ console.log(`err`, err)
131
+ }
132
+ res.send(str);
133
+ });
134
+
135
+ } catch (error) {
136
+ res.status(500).send({ message: error.message });
137
+ }
138
+
139
+ });
140
+ exports.default = router;
@@ -1,7 +1,9 @@
1
1
  const objectql = require('@steedos/objectql');
2
2
  const metadataAPI = require('@steedos/metadata-api');
3
3
  const _ = require('lodash');
4
-
4
+ // 使用变量,存储所有资产
5
+ const ASSETS = {};
6
+ const ENV_ASSETS = process.env.STEEDOS_PUBLIC_PAGE_ASSETURLS.split(',')
5
7
  module.exports = {
6
8
  name: "page",
7
9
  mixins: [],
@@ -205,14 +207,40 @@ module.exports = {
205
207
  }
206
208
  return result;
207
209
  }
208
- }
210
+ },
211
+ addAssetUrl: {
212
+ handler: async function (ctx) {
213
+ const { name, url } = ctx.params;
214
+ // console.log(`addAssetUrl`, name, url)
215
+ return broker.broadcast("page.addAssetUrl", {
216
+ name, url
217
+ });
218
+ }
219
+ },
220
+ removeAssetUrl: {
221
+ handler: async function (ctx) {
222
+ const { name } = ctx.params;
223
+ return broker.broadcast("page.removeAssetUrl", {
224
+ name
225
+ });
226
+ }
227
+ }
209
228
  },
210
229
 
211
230
  /**
212
231
  * Events
213
232
  */
214
233
  events: {
215
-
234
+ 'page.addAssetUrl': function (ctx) {
235
+ const { name, url } = ctx.params;
236
+ ASSETS[name] = url;
237
+ process.env.STEEDOS_PUBLIC_PAGE_ASSETURLS = _.compact(_.uniq(_.concat(ENV_ASSETS, _.values(ASSETS)))).join(',');
238
+ },
239
+ 'page.removeAssetUrl': function (ctx) {
240
+ const { name } = ctx.params;
241
+ delete ASSETS[name]
242
+ process.env.STEEDOS_PUBLIC_PAGE_ASSETURLS = _.compact(_.uniq(_.concat(ENV_ASSETS, _.values(ASSETS)))).join(',');
243
+ },
216
244
  },
217
245
 
218
246
  /**
@@ -4,4 +4,14 @@ CustomApplications:
4
4
  description: null
5
5
  CustomLabels:
6
6
  menu_user_interface: User Interface
7
- menu_pages: Mini Page
7
+ menu_pages: Micro Pages
8
+ page_assignments_error_not_allowed_to_application_pages: Prohibit assigning permissions to application pages
9
+ page_assignments_error_organization_default_already_exists: Authorization for 'Organization Default Settings' already exists
10
+ page_assignments_error_application_default_already_exists: Authorization for 'Application Default Settings' already exists
11
+ page_assignments_error_application_and_profile_already_exists: Application and Profile authorization already exists
12
+ page_check_error_prohibit_modifying_page_types: Prohibit modifying page types
13
+ page_check_error_prohibit_modifying_page_renderer: Prohibit modifying the page renderer
14
+ page_check_error_prohibit_disabling_application_pages: Prohibit disabling application pages
15
+ page_pai_name_error_not_repeat: Api Name cannot be duplicate
16
+ page_versions_error_prohibit_modifying_non_latest_version: Prohibit modifying non latest version
17
+
@@ -5,3 +5,12 @@ CustomApplications:
5
5
  CustomLabels:
6
6
  menu_user_interface: 用户界面
7
7
  menu_pages: 微页面
8
+ page_assignments_error_not_allowed_to_application_pages: 禁止给应用程序页面分配权限
9
+ page_assignments_error_organization_default_settings_already_exists: 已存在「组织默认设置」授权
10
+ page_assignments_error_application_default_already_exists: 已存在「应用程序默认设置」授权
11
+ page_assignments_error_application_and_profile_already_exists: 已存在「应用程序和简档」授权
12
+ page_check_error_prohibit_modifying_page_types: 禁止修改页面类型
13
+ page_check_error_prohibit_modifying_page_renderer: 禁止修改页面渲染器
14
+ page_check_error_prohibit_disabling_application_pages: 禁止停用应用程序页面
15
+ page_pai_name_error_not_repeat: Api Name 不能重复
16
+ page_versions_error_prohibit_modifying_non_latest_version: 禁止修改非最新版
@@ -7,7 +7,7 @@ module.exports = {
7
7
  if(doc.page){
8
8
  const record = await objectql.getObject('pages').findOne(doc.page);
9
9
  if(record.type === 'app'){
10
- throw new Error('禁止给应用程序页面分配权限');
10
+ throw new Error('page_assignments_error_not_allowed_to_application_pages');
11
11
  }
12
12
  }
13
13
 
@@ -23,21 +23,21 @@ module.exports = {
23
23
  if(doc.type === 'orgDefault'){
24
24
  const count = await objectql.getObject('page_assignments').count({filters: [['page', '=', doc.page], ['type', '=', doc.type]]})
25
25
  if(count > 0){
26
- throw new Error("已存在「组织默认设置」授权")
26
+ throw new Error("page_assignments_error_organization_default_already_exists")
27
27
  }
28
28
  }
29
29
 
30
30
  if(doc.type === 'appDefault'){
31
31
  const count = await objectql.getObject('page_assignments').count({filters: [['page', '=', doc.page], ['type', '=', doc.type], ['app', '=', doc.app]]})
32
32
  if(count > 0){
33
- throw new Error("已存在「应用程序默认设置」授权")
33
+ throw new Error("page_assignments_error_application_default_already_exists")
34
34
  }
35
35
  }
36
36
 
37
37
  if(doc.type === 'appRecordProfile'){
38
38
  const count = await objectql.getObject('page_assignments').count({filters: [['page', '=', doc.page], ['type', '=', doc.type], ['app', '=', doc.app], ['profile', '=', doc.profile]]})
39
39
  if(count > 0){
40
- throw new Error("已存在「应用程序和简档」授权")
40
+ throw new Error("page_assignments_error_application_and_profile_already_exists")
41
41
  }
42
42
  }
43
43
 
@@ -47,7 +47,7 @@ module.exports = {
47
47
  if(doc.page){
48
48
  const record = await objectql.getObject('pages').findOne(doc.page);
49
49
  if(record.type === 'app'){
50
- throw new Error('禁止给应用程序页面分配权限');
50
+ throw new Error('page_assignments_error_not_allowed_to_application_pages');
51
51
  }
52
52
  }
53
53
 
@@ -63,21 +63,21 @@ module.exports = {
63
63
  if(doc.type === 'orgDefault'){
64
64
  const count = await objectql.getObject('page_assignments').count({filters: [['_id', '!=', id], ['page', '=', doc.page], ['type', '=', doc.type]]})
65
65
  if(count > 0){
66
- throw new Error("已存在「组织默认设置」授权")
66
+ throw new Error("page_assignments_error_organization_default_already_exists")
67
67
  }
68
68
  }
69
69
 
70
70
  if(doc.type === 'appDefault'){
71
71
  const count = await objectql.getObject('page_assignments').count({filters: [['_id', '!=', id], ['page', '=', doc.page], ['type', '=', doc.type], ['app', '=', doc.app]]})
72
72
  if(count > 0){
73
- throw new Error("已存在「应用程序默认设置」授权")
73
+ throw new Error("page_assignments_error_application_default_already_exists")
74
74
  }
75
75
  }
76
76
 
77
77
  if(doc.type === 'appRecordProfile'){
78
78
  const count = await objectql.getObject('page_assignments').count({filters: [['_id', '!=', id], ['page', '=', doc.page], ['type', '=', doc.type], ['app', '=', doc.app], ['profile', '=', doc.profile]]})
79
79
  if(count > 0){
80
- throw new Error("已存在「应用程序和简档」授权")
80
+ throw new Error("page_assignments_error_application_and_profile_already_exists")
81
81
  }
82
82
  }
83
83
  }
@@ -7,7 +7,7 @@ module.exports = {
7
7
  const {object_name, doc, spaceId} = this;
8
8
  const isUnique = await apiName.isSpaceUnique(spaceId, object_name, doc, doc.name)
9
9
  if(!isUnique){
10
- throw new Error('Api Name 不能重复');
10
+ throw new Error('page_pai_name_error_not_repeat');
11
11
  }
12
12
  },
13
13
 
@@ -16,7 +16,7 @@ module.exports = {
16
16
  if(_.has(doc, 'name')){
17
17
  const isUnique = await apiName.isSpaceUnique(spaceId, object_name, doc, doc.name, id)
18
18
  if(!isUnique){
19
- throw new Error('Api Name 不能重复');
19
+ throw new Error('page_pai_name_error_not_repeat');
20
20
  }
21
21
  }
22
22
  }
@@ -7,10 +7,10 @@ module.exports = {
7
7
  if(_.has(doc, 'type') || _.has(doc, 'render_engine')){
8
8
  const record = await objectql.getObject('pages').findOne(id);
9
9
  if(_.has(doc, 'type') && doc.type != record.type){
10
- throw new Error('禁止修改页面类型');
10
+ throw new Error('page_check_error_prohibit_modifying_page_types');
11
11
  }
12
12
  if(_.has(doc, 'render_engine') && doc.render_engine != record.render_engine){
13
- throw new Error('禁止修改页面渲染器');
13
+ throw new Error('page_check_error_prohibit_modifying_page_renderer');
14
14
  }
15
15
  }
16
16
 
@@ -23,7 +23,7 @@ module.exports = {
23
23
  type = record.type;
24
24
  }
25
25
  if(type === 'app'){
26
- throw new Error('禁止停用应用程序页面');
26
+ throw new Error('page_check_error_prohibit_disabling_application_pages');
27
27
  }
28
28
  }
29
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-pages",
3
- "version": "2.6.1-beta.6",
3
+ "version": "2.6.2-beta.2",
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": "d77961251196c5352622d977e554660796ed6208",
11
+ "gitHead": "ddef9fbc34afc7b57c59a31e9ed4f56818dc4c31",
12
12
  "dependencies": {
13
13
  "ejs": "^3.1.8"
14
14
  }
@@ -4,7 +4,8 @@ const packageName = project.name;
4
4
  const packageLoader = require('@steedos/service-package-loader');
5
5
  const objectql = require('@steedos/objectql');
6
6
  const _ = require(`lodash`);
7
-
7
+ const path = require('path');
8
+ const fs = require("fs");
8
9
  const getCharts = async(apiName)=>{
9
10
  const charts = await objectql.getObject('charts').find({ filters: [['name', '=', apiName]] });
10
11
  if(charts.length > 0){
@@ -35,7 +36,8 @@ module.exports = {
35
36
  path: __dirname,
36
37
  name: this.name,
37
38
  isPackage: false
38
- }
39
+ },
40
+ loadedPublicClientJS: false,
39
41
  },
40
42
 
41
43
  /**
@@ -144,14 +146,59 @@ module.exports = {
144
146
  * Events
145
147
  */
146
148
  events: {
147
-
149
+ "steedos-server.started": {
150
+ async handler() {
151
+ await this.publicClientJS();
152
+ }
153
+ },
154
+ "space.initialized": {
155
+ async handler() {
156
+ await this.publicClientJS();
157
+ }
158
+ }
148
159
  },
149
160
 
150
161
  /**
151
162
  * Methods
152
163
  */
153
164
  methods: {
154
-
165
+ publicClientJS: {
166
+ handler() {
167
+ let packageInfo = this.settings.packageInfo;
168
+ if (!packageInfo) {
169
+ return;
170
+ }
171
+ const { path : packagePath } = packageInfo;
172
+ let publicPath = path.join(packagePath, 'main', 'default', 'client');
173
+ try {
174
+ if (!fs.existsSync(publicPath) || this.settings.loadedPublicClientJS || typeof WebApp == 'undefined') {
175
+ return;
176
+ }
177
+ } catch (error) {
178
+ return
179
+ }
180
+
181
+ try {
182
+ const express = require('express');
183
+ this.settings.loadedPublicClientJS = true;
184
+ try {
185
+ const router = require('@steedos/router').staticRouter();
186
+ let routerPath = "";
187
+ if (__meteor_runtime_config__.ROOT_URL_PATH_PREFIX) {
188
+ routerPath = __meteor_runtime_config__.ROOT_URL_PATH_PREFIX;
189
+ }
190
+ const cacheTime = 86400000 * 1; // one day
191
+ router.use(`${routerPath}/pages/js`, express.static(publicPath, { maxAge: cacheTime }));
192
+ // WebApp.connectHandlers.use(router);
193
+ } catch (error) {
194
+ console.error(error)
195
+ this.settings.loadedPublicClientJS = false;
196
+ }
197
+ } catch (error) {
198
+
199
+ }
200
+ }
201
+ },
155
202
  },
156
203
 
157
204
  /**
@@ -165,7 +212,9 @@ module.exports = {
165
212
  * Service started lifecycle event handler
166
213
  */
167
214
  async started() {
168
-
215
+ this.broker.waitForServices("steedos-server").then(async () => {
216
+ await this.publicClientJS()
217
+ });
169
218
  },
170
219
 
171
220
  /**
@@ -1,117 +0,0 @@
1
- <html>
2
-
3
- <head>
4
- <script src="https://builder.steedos.cn/js/axios/axios.min.js"></script>
5
- <script src="https://builder.steedos.cn/js/builder-fiddle/builder-fiddle.umd.js"></script>
6
- </head>
7
-
8
- <body style="margin: 0;padding: 0;">
9
-
10
- <builder-fiddle host="SteedosBuilderHost"></builder-fiddle>
11
-
12
- <script>
13
- let comp = document.querySelector('builder-fiddle')
14
- var params = new URLSearchParams(location.search);
15
- var pageId = params.get("pageId");
16
- // /pageVersion/:pageId/latest
17
- const dataContext = DataContext;
18
- axios.get(`/service/api/page/pageVersion/${params.get("pageId")}/latest`).then(function (response) {
19
- let result = response.data;
20
-
21
- let schema = result?.schema;
22
- let objectName = result?.object_name;
23
- let pageType = result?.type;
24
- if (typeof schema === "string") {
25
- schema = JSON.parse(schema)
26
- }
27
- if(!schema){
28
- schema = {
29
- "type": "page",
30
- "body": [],
31
- "regions": [
32
- "body"
33
- ]
34
- };
35
- }
36
-
37
- if(!schema.data){
38
- schema.data = {}
39
- }
40
-
41
- if(!schema.data.context){
42
- schema.data.context = {}
43
- }
44
-
45
- schema.data.objectName = objectName;
46
-
47
- schema.data.context.rootUrl = dataContext.rootUrl;
48
- schema.data.context.tenantId = dataContext.tenantId;
49
- schema.data.context.userId = dataContext.userId;
50
- schema.data.context.authToken = dataContext.authToken;
51
-
52
- if(objectName && pageType === 'record'){
53
- axios.get(`/api/v4/${objectName}?$orderby=created desc&$top=1`).then(function (response) {
54
- const value = response.data?.value;
55
- if(value.length > 0){
56
- schema.data.recordId = value[0]._id;
57
- }
58
- const data = {
59
- AmisSchema: schema
60
- };
61
- console.log("record data", data)
62
- comp.data = data;
63
- });
64
- }else{
65
- const data = {
66
- AmisSchema: schema
67
- };
68
- console.log("record data", data)
69
- comp.data = data;
70
- }
71
-
72
-
73
- }).catch(function (error) {
74
- // handle error
75
- console.log(error);
76
- }).then(function () {
77
- // always executed
78
- });
79
-
80
- const onWindowMessage = function (event) {
81
- const { data } = event;
82
- if (data) {
83
- if (data.type === 'builder.saveContent') {
84
- axios.put(`/service/api/page/pageVersion/${params.get("pageId")}`, {
85
- schema: JSON.stringify(data.data.AmisSchema, null, 4) //直接存储json格式会导致react form异常。
86
- }).then(function (response) {
87
- window.postMessage(
88
- {
89
- type: 'builder.contentSaved',
90
- },
91
- '*'
92
- );
93
-
94
- try {
95
- //保存时, 刷新父页面
96
- if(window.opener){
97
- window.opener.postMessage(Object.assign({type: "record.edited"}, {objectName: 'pages'}, {record: {}}), "*")
98
- }
99
- } catch (error) {
100
- console.error(error)
101
- }
102
- }).catch(function (error) {
103
- // handle error
104
- console.log(error);
105
- }).then(function () {
106
- // always executed
107
- })
108
- }
109
- }
110
- }
111
-
112
- window.addEventListener('message', onWindowMessage);
113
-
114
- </script>
115
- </body>
116
-
117
- </html>