@steedos/service-pages 2.3.3 → 2.4.0-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.
@@ -18,6 +18,7 @@
18
18
  }else{
19
19
  thing = lodash.get(obj, path);
20
20
  }
21
+ // console.log(`_innerWaitForThing`, path)
21
22
  if (thing) {
22
23
  return resolve(thing);
23
24
  }
@@ -58,7 +59,7 @@
58
59
  if (window.define)
59
60
  window.define.amd = undefined;
60
61
 
61
- window.ReactDOM = ReactDom;
62
+ // window.ReactDOM = ReactDom;
62
63
  window.React17 = window.React;
63
64
  window.ReactDOM17 = window.ReactDOM;
64
65
 
@@ -4,10 +4,33 @@
4
4
  * @Description: 提供自定义page渲染能力, 供内部使用, 内容会迭代调整, 不对用户开放.
5
5
  */
6
6
  ;(function(){
7
+
8
+
9
+ const withModalWrap = (component, provideProps) => {
10
+ return (props) => {
11
+ const ModalComponent = component;
12
+ return React.createElement(ModalComponent, props);
13
+ }
14
+ }
15
+ const render = (component, componentProps, container, provideProps = {} ) => {
16
+ try {
17
+ const wrapComponent = withModalWrap(component, provideProps);
18
+ const contentEle = React.createElement(wrapComponent,{
19
+ ...componentProps
20
+ });
21
+ setTimeout(()=>{
22
+ ReactDOM.render(contentEle, container);
23
+ }, 100)
24
+ } catch (error) {
25
+ console.log(`error`, error)
26
+ }
27
+ }
28
+
7
29
  Steedos.Page = {
8
30
  App: {},
9
31
  Record: {},
10
32
  Listview: {},
33
+ Header: {},
11
34
  RelatedListview: {},
12
35
  Form: {
13
36
  StandardNew: {},
@@ -33,10 +56,10 @@
33
56
  return modalRoot;
34
57
  }
35
58
 
36
-
37
59
  Steedos.Page.getPage = function (type, appId, objectApiName, recordId, pageId) {
60
+ let objectInfo = null;
38
61
  if (type != 'list' && objectApiName) {
39
- const objectInfo = Creator.getObject(objectApiName);
62
+ objectInfo = Creator.getObject(objectApiName);
40
63
  if (objectInfo && objectInfo.version < 2) {
41
64
  return;
42
65
  }
@@ -55,6 +78,181 @@
55
78
  if (page && page.schema) {
56
79
  return page;
57
80
  }
81
+ else if(type === 'list'){
82
+ return {
83
+ render_engine: 'amis',
84
+ name: 'steedosListviewPage',
85
+ schema: {
86
+ "type": "page",
87
+ name: `amis-${appId}-${objectApiName}-listview`,
88
+ "title": "Welcome to Steedos",
89
+ bodyClassName: 'p-3',
90
+ "body": [
91
+ {
92
+ "type": "steedos-object-listview",
93
+ showHeader: true,
94
+ "label": "列表视图",
95
+ "objectApiName": "${objectName}",
96
+ "listName": "all",
97
+ "id": "u:be7c6341cd11"
98
+ }
99
+ ],
100
+ "regions": [
101
+ "body"
102
+ ],
103
+ "id": "u:7b47b6042b0d"
104
+ }
105
+ }
106
+ }else if(type === 'record'){
107
+ return {
108
+ render_engine: 'amis',
109
+ name: 'steedosRecordPage',
110
+ bodyClassName: 'p-3',
111
+ schema: {
112
+ "type": "page",
113
+ "name": `amis-${appId}-${objectApiName}-detail`,
114
+ "title": "Welcome to Steedos",
115
+ "body": [
116
+ {
117
+ "type": "steedos-record-detail",
118
+ "objectApiName": "${objectName}",
119
+ "recordId": "${recordId}",
120
+ appId: appId,
121
+ "id": "u:48d2c28eb755",
122
+ onEvent: {
123
+ "recordLoaded": {
124
+ "actions": [
125
+ {
126
+ "actionType": "reload",
127
+ "data": {
128
+ "name": `\${record.${objectInfo?.NAME_FIELD_KEY || 'name'}}`
129
+ }
130
+ }
131
+ ]
132
+ }
133
+ },
134
+ }
135
+ ],
136
+ "regions": [
137
+ "body"
138
+ ],
139
+ "id": "u:d138f5276481"
140
+ }
141
+ }
142
+
143
+ }else if(type === 'related_list'){
144
+ const relatedKey = FlowRouter._current.queryParams.related_field_name;
145
+ const masterObject = Creator.getObject(FlowRouter.getParam("object_name"))
146
+ const object = Creator.getObject(objectApiName)
147
+ const idFieldName = masterObject.idFieldName;
148
+ return {
149
+ render_engine: 'amis',
150
+ name: 'steedosRelatedListPage',
151
+ schema: {
152
+ type: 'service',
153
+ name: `amis-${appId}-${FlowRouter.getParam("object_name")}-related-${objectApiName}`,
154
+ api: {
155
+ method: "post",
156
+ url: `\${context.rootUrl}/graphql`,
157
+ requestAdaptor: `
158
+ api.data = {
159
+ query: \`{
160
+ data: ${masterObject.name}(filters:["${idFieldName}", "=", "${FlowRouter.getParam("record_id")}"]){
161
+ ${idFieldName}
162
+ ${masterObject.NAME_FIELD_KEY},
163
+ recordPermissions: _permissions{
164
+ allowCreate,
165
+ allowCreateFiles,
166
+ allowDelete,
167
+ allowDeleteFiles,
168
+ allowEdit,
169
+ allowEditFiles,
170
+ allowRead,
171
+ allowReadFiles,
172
+ disabled_actions,
173
+ disabled_list_views,
174
+ field_permissions,
175
+ modifyAllFiles,
176
+ modifyAllRecords,
177
+ modifyAssignCompanysRecords,
178
+ modifyCompanyRecords,
179
+ uneditable_fields,
180
+ unreadable_fields,
181
+ unrelated_objects,
182
+ viewAllFiles,
183
+ viewAllRecords,
184
+ viewAssignCompanysRecords,
185
+ viewCompanyRecords,
186
+ }
187
+ }
188
+ }\`
189
+ }
190
+ return api;
191
+ `,
192
+ adaptor: `
193
+ if(payload.data.data){
194
+ var data = payload.data.data[0];
195
+ payload.data = data;
196
+ }
197
+ payload.data.$breadcrumb = [
198
+ {
199
+ "label": "${masterObject.label}",
200
+ "href": "/app/${appId}/${masterObject.name}"
201
+ },
202
+ {
203
+ "label": payload.data.${masterObject.NAME_FIELD_KEY},
204
+ "href": "/app/${appId}/${masterObject.name}/view/${FlowRouter.getParam("record_id")}",
205
+ },
206
+ {
207
+ "label": "相关 ${object.label}"
208
+ },
209
+ ]
210
+ payload.data.$loaded = true;
211
+ return payload;
212
+ `,
213
+ headers: {
214
+ Authorization: "Bearer ${context.tenantId},${context.authToken}"
215
+ }
216
+ },
217
+ "data": {
218
+ "&": "$$",
219
+ "$breadcrumb": [], //先给一个空数组, 防止breadcrumb组件报错
220
+ },
221
+ body: [
222
+ {
223
+ "type": "panel",
224
+ "title": {
225
+ "type": "breadcrumb",
226
+ "source": "${$breadcrumb}"
227
+ },
228
+ "body": [
229
+ {
230
+ type: 'steedos-object-related-listview',
231
+ objectApiName: masterObject.name,
232
+ recordId: FlowRouter.getParam("record_id"),
233
+ relatedObjectApiName: objectApiName,
234
+ foreign_key: relatedKey,
235
+ relatedKey: relatedKey,
236
+ hiddenOn: "!!!this.$loaded"
237
+ // top: 5
238
+ }
239
+ ]
240
+ }
241
+ ,
242
+ // {
243
+ // type: 'steedos-object-related-listview',
244
+ // objectApiName: masterObject.name,
245
+ // recordId: FlowRouter.getParam("record_id"),
246
+ // relatedObjectApiName: objectApiName,
247
+ // foreign_key: relatedKey,
248
+ // relatedKey: relatedKey,
249
+ // hiddenOn: "!!!this.$loaded"
250
+ // // top: 5
251
+ // }
252
+ ]
253
+ }
254
+ }
255
+ }
58
256
  }
59
257
 
60
258
  Steedos.Page.render = function (root, page, data, options = {}) {
@@ -111,8 +309,11 @@
111
309
 
112
310
  let schema = typeof page.schema === 'string' ? JSON.parse(page.schema) : page.schema;
113
311
 
114
- const defData = lodash.defaultsDeep({}, data , {
312
+ const defData = lodash.defaultsDeep({}, data , {data: data} , {
115
313
  data: {
314
+ app_id: data.appId,
315
+ object_name: data.objectName,
316
+ record_id: data.recordId,
116
317
  context: {
117
318
  rootUrl: __meteor_runtime_config__.ROOT_URL,
118
319
  tenantId: Creator.USER_CONTEXT.spaceId,
@@ -126,7 +327,8 @@
126
327
  user: Creator.USER_CONTEXT.user,
127
328
  now: new Date(),
128
329
  // mode: mode //由表单提供
129
- }
330
+ },
331
+ scopeId: schema.name || schema.id
130
332
  }
131
333
  });
132
334
 
@@ -159,7 +361,7 @@
159
361
 
160
362
  if(!lodash.isFunction(root)){
161
363
  //渲染loading
162
- SteedosUI.render(BuilderComponent, {
364
+ render(BuilderComponent, {
163
365
  model: "page", content: {
164
366
  "data": loadingContentData
165
367
  }
@@ -172,7 +374,7 @@
172
374
  ]).then(()=>{
173
375
  //渲染page
174
376
  if(!lodash.isFunction(root)){
175
- SteedosUI.render(BuilderComponent, {
377
+ render(BuilderComponent, {
176
378
  model: "page", content: {
177
379
  "data": pageContentData
178
380
  }
@@ -274,6 +476,7 @@
274
476
  }
275
477
 
276
478
  if (page.render_engine && page.render_engine != 'redash') {
479
+ data.listName = data.listViewId;
277
480
  return Steedos.Page.render($("#" + rootId)[0], page, Object.assign({}, options, data));
278
481
  }
279
482
  } catch (error) {
@@ -393,20 +596,6 @@
393
596
  // data: initialValues,
394
597
  // }));
395
598
  }
396
-
397
- SteedosUI.showModal(stores.ComponentRegistry.components.ObjectForm, {
398
- name: `${objectApiName}_standard_new_form`,
399
- objectApiName: objectApiName,
400
- title: title,
401
- initialValues: initialValues,
402
- afterInsert: function (result) {
403
- if (result.length > 0) {
404
- var record = result[0];
405
- SteedosUI.router.go({objectName: objectApiName, recordId: record._id, type: 'new'});
406
- return true;
407
- }
408
- }
409
- }, null, { iconPath: '/assets/icons' });
410
599
  };
411
600
 
412
601
  Steedos.Page.Form.StandardEdit.render = function (appId, objectApiName, title, recordId, options) {
@@ -470,32 +659,6 @@
470
659
  // recordId: recordId
471
660
  // }));
472
661
  }
473
-
474
- return SteedosUI.showModal(stores.ComponentRegistry.components.ObjectForm, {
475
- name: `${objectApiName}_standard_edit_form`,
476
- objectApiName: objectApiName,
477
- recordId: recordId,
478
- title: title,
479
- afterUpdate: function () {
480
- setTimeout(function () {
481
- if(["/app/:app_id/:object_name/view/:record_id", "/app/:app_id/:object_name/:record_id/:related_object_name/grid"].indexOf(FlowRouter.current().route.pathDef) > -1){
482
- // 记录详细界面编辑子表记录,或相关子表列表界面编辑子表记录
483
- var params = FlowRouter.current().params;
484
- if(params.record_id !== recordId){
485
- // ObjectForm有缓存,修改子表记录可能会有主表记录的汇总字段变更,需要刷新主表记录
486
- SteedosUI.reloadRecord(params.object_name, params.record_id)
487
- }
488
- }
489
- if (FlowRouter.current().route.path.endsWith("/:record_id")) {
490
- FlowRouter.reload()
491
- } else {
492
- window.refreshDxSchedulerInstance()
493
- window.refreshGrid(options.gridName);
494
- }
495
- }, 1);
496
- return true;
497
- }
498
- }, null, { iconPath: '/assets/icons' })
499
662
  };
500
663
 
501
664
  // Steedos.Page.Form.StandardDelete.render = function(){
@@ -558,4 +721,205 @@
558
721
  graphqlFieldsQuery: getGraphqlFieldsQuery(objectApiName, selectFields, expandFields)
559
722
  })
560
723
  }
724
+
725
+ const getSpaceLogo = function(){
726
+ let logoSrc = '';
727
+ const space = db.spaces.findOne(Steedos.getSpaceId())
728
+ if(space?.avatar){
729
+ logoSrc = Steedos.absoluteUrl(space.avatar)
730
+ }else if(space?.avatar_square){
731
+ logoSrc = Steedos.absoluteUrl(space.avatar_square)
732
+ }else{
733
+ var settings = Session.get("tenant_settings");
734
+ if(settings){
735
+ avatar_url = settings?.logo_square_url;
736
+ }
737
+ if(!avatar_url || !settings){
738
+ avatar_url = "/images/logo_platform.png"
739
+ if(Meteor.user()?.locale != 'zh-cn'){
740
+ avatar_url = "/images/logo_platform.en-us.png"
741
+ }
742
+ }
743
+ logoSrc = Steedos.absoluteUrl(avatar_url)
744
+ }
745
+ return logoSrc
746
+ }
747
+
748
+ Steedos.Page.Header.render = function(appId, tabId){
749
+ const app = _.find(Session.get('app_menus'), {id: appId})
750
+ if (typeof app != 'undefined') {
751
+ if (app.id === 'admin' || (window.innerWidth < 768))
752
+ app.showSidebar = true;
753
+ if (app.showSidebar)
754
+ document.body.classList.add('sidebar')
755
+ else
756
+ document.body.classList.remove("sidebar")
757
+ }
758
+
759
+ try {
760
+ const data = {
761
+ app
762
+ };
763
+ const page = Steedos.Page.Header.getPage(appId, tabId);
764
+ var rootId = "steedosGlobalHeaderRoot";
765
+ var modalRoot = document.getElementById(rootId);
766
+ if (!modalRoot) {
767
+ modalRoot = document.createElement('div');
768
+ modalRoot.setAttribute('id', rootId);
769
+ $(".steedos-global-header-root")[0].appendChild(modalRoot);
770
+ }
771
+ if (page.render_engine && page.render_engine != 'redash') {
772
+ return Steedos.Page.render($("#" + rootId)[0], page, Object.assign({}, data));
773
+ }
774
+ } catch (error) {
775
+ console.error(`Steedos.Page.Header.render`, error)
776
+ }
777
+ }
778
+ Steedos.Page.Header.getPage = function(appId, tabId){
779
+ const logoSrc = getSpaceLogo()
780
+ return {
781
+ render_engine: 'amis',
782
+ name: 'steedosGlobalHeaderPage',
783
+ schema: {
784
+ "type": "service",
785
+ name: "globalHeader",
786
+ body: [
787
+ {
788
+ "type": "wrapper",
789
+ "className": 'p-0',
790
+ body: [
791
+ {
792
+ "type": "wrapper",
793
+ "className": "p-0 slds-global-header_container sticky top-0 z-40 w-full flex-none backdrop-blur transition-colors duration-500 lg:z-50 sm:shadow border-b-[3px] border-sky-500 border-solid",
794
+ body: [
795
+ {
796
+ "type": "wrapper",
797
+ "className": 'flex w-full px-4 h-[50px] p-0 justify-between items-center',
798
+ "body": [
799
+ {
800
+ type: "wrapper",
801
+ className: 'p-0 flex flex-1 items-center',
802
+ body: [
803
+ {
804
+ "type": "steedos-logo",
805
+ "src": "/logo.png",
806
+ "className": 'block h-7 w-auto mr-4',
807
+ "hiddenOn": "window.innerWidth < 768",
808
+ },
809
+ {
810
+ "type": "steedos-app-launcher",
811
+ hiddenOn: "${app.showSidebar != true}",
812
+ "showAppName": true
813
+ },
814
+ ],
815
+ },
816
+ {
817
+ "type": "steedos-global-header",
818
+ "label": "Global Header",
819
+ className: 'flex flex-nowrap gap-x-3 items-center',
820
+ logoutScript: "window.signOut();",
821
+ customButtons: [
822
+ {
823
+ "type": "button",
824
+ "className": "toggle-sidebar",
825
+ "hiddenOn": "${app.showSidebar != true}",
826
+ "onEvent": {
827
+ "click": {
828
+ "actions": [
829
+ {
830
+ "actionType": "custom",
831
+ "script": "document.body.classList.toggle('sidebar-open')",
832
+ }
833
+ ]
834
+ }
835
+ },
836
+ "body": [
837
+ {
838
+ "type": "steedos-icon",
839
+ "category": "utility",
840
+ "name": "rows",
841
+ "colorVariant": "default",
842
+ "id": "u:afc3a08e8cf3",
843
+ "className": "slds-button_icon slds-global-header__icon"
844
+ }
845
+ ],
846
+ },]
847
+ }
848
+ ],
849
+ },
850
+
851
+ {
852
+ "type": "grid",
853
+ hiddenOn: "${app.showSidebar === true}",
854
+ "className": 'steedos-context-bar hidden sm:flex h-10 leading-5 pl-4 mb-[-3px]',
855
+ "columns": [
856
+ {
857
+ "columnClassName": "items-center hidden sm:flex pb-0",
858
+ "body": [
859
+ {
860
+ "type": "steedos-app-launcher",
861
+ "showAppName": true,
862
+ "appId": "${app.id}",
863
+ }
864
+ ],
865
+ "md": "auto",
866
+ "valign": "middle"
867
+ },
868
+ {
869
+ "columnClassName": "flex ",
870
+ "body": [
871
+ {
872
+ "type": "steedos-app-menu",
873
+ "stacked": false,
874
+ showIcon: false,
875
+ "appId": "${app.id}",
876
+ overflow: {
877
+ enable: false,
878
+ itemWidth: 80,
879
+ },
880
+ "id": "u:77851eb4aa89",
881
+ }
882
+ ],
883
+ "id": "u:5367229505d8",
884
+ "md": "",
885
+ "valign": "middle",
886
+ }
887
+ ],
888
+ },
889
+ ],
890
+ },
891
+
892
+ {
893
+
894
+ "type": "button",
895
+ "className": 'p-0 absolute inset-0 mt-[50px]',
896
+ hiddenOn: "${app.showSidebar != true}",
897
+ body: [{
898
+ type: "wrapper",
899
+ className: 'sidebar-wrapper p-0 pt-2 fixed z-20 h-full ease-in-out duration-300 flex flex-col border-r overflow-y-auto bg-white border-slate-200 block -translate-x-0 sm:w-[220px] w-64',
900
+ body: [
901
+ {
902
+ "type": "steedos-app-menu",
903
+ "stacked": true,
904
+ "appId": "${app.id}",
905
+ },
906
+ ]
907
+ }],
908
+ "onEvent": {
909
+ "click": {
910
+ "actions": [
911
+ {
912
+ "actionType": "custom",
913
+ "script": "console.log(event.target); if(window.innerWidth < 768){ document.body.classList.remove('sidebar-open'); }",
914
+ }
915
+ ]
916
+ }
917
+ },
918
+ }
919
+ ],
920
+ },
921
+ ]
922
+ }
923
+ }
924
+ }
561
925
  })();
@@ -17,15 +17,4 @@ hidden: true
17
17
  icon: contract
18
18
  is_enable: true
19
19
  label: 微页面
20
- version: 2
21
- form:
22
- afterView: !!js/function |
23
- function(){
24
- if(this.doc.name && (this.doc.render_engine === 'redash' || !this.doc.render_engine)){
25
- return SteedosUI.render(stores.ComponentRegistry.components.Page, { pageId: this.doc.name }, $(".slds-template__container")[0])
26
- }
27
- if(this.doc.type === 'app'){
28
- $('[data-object-name="page_assignments"]').hide()
29
- }
30
- $('[data-object-name="page_versions"]').hide()
31
- }
20
+ version: 2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-pages",
3
- "version": "2.3.3",
3
+ "version": "2.4.0-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": "9d46ca700b9fc9586b66bcc8410684ff7343f5fb",
11
+ "gitHead": "4bbd9ee44a8cc1e75db2027c135b9e208b93964a",
12
12
  "dependencies": {
13
13
  "ejs": "^3.1.8"
14
14
  }
Binary file