@steedos/service-plugin-amis 2.3.5 → 2.3.6

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.
@@ -19,8 +19,8 @@
19
19
  };
20
20
  }
21
21
  // loadCss(Steedos.absoluteUrl("/unpkg.com/amis/sdk/sdk.css"))
22
- loadCss(Steedos.absoluteUrl("/unpkg.com/amis/sdk/helper.css"))
23
- loadCss(Steedos.absoluteUrl("/unpkg.com/amis/sdk/iconfont.css"))
22
+ // loadCss(Steedos.absoluteUrl("/unpkg.com/amis/sdk/helper.css"))
23
+ // loadCss(Steedos.absoluteUrl("/unpkg.com/amis/sdk/iconfont.css"))
24
24
  loadCss(Steedos.absoluteUrl("/amis/amis.css"))
25
25
 
26
26
  try {
@@ -48,9 +48,9 @@
48
48
  }
49
49
 
50
50
  // 加载Amis SDK: 如果直接放到body中会导致 meteor 编译后的 cordova.js 加载报错
51
- let amisSDKScript = document.createElement("script");
52
- amisSDKScript.setAttribute("src", Steedos.absoluteUrl('/unpkg.com/amis/sdk/sdk.js'));
53
- document.getElementsByTagName("head")[0].appendChild(amisSDKScript);
51
+ // let amisSDKScript = document.createElement("script");
52
+ // amisSDKScript.setAttribute("src", Steedos.absoluteUrl('/unpkg.com/amis/sdk/sdk.js'));
53
+ // document.getElementsByTagName("head")[0].appendChild(amisSDKScript);
54
54
  } catch (error) {
55
55
  console.error(error)
56
56
  };
@@ -73,9 +73,15 @@
73
73
  waitForThing(window, 'assetsLoaded'),
74
74
  waitForThing(window, 'amis'),
75
75
  ]).then(()=>{
76
- window.React = window.__React;
77
- window.ReactDOM = window.__ReactDOM;
76
+ // window.React = window.__React;
77
+ // window.ReactDOM = window.__ReactDOM;
78
78
  const AmisRenderers = [];
79
+ let amisLib = amisRequire('amis');
80
+ const registerMap = {
81
+ renderer: amisLib.Renderer,
82
+ formitem: amisLib.FormItem,
83
+ options: amisLib.OptionsControl,
84
+ };
79
85
 
80
86
  const amisComps = lodash.filter(Builder.registry['meta-components'], function(item){ return item.componentName && item.amis?.render});
81
87
 
@@ -88,7 +94,7 @@
88
94
  if(comp.componentType === 'amisSchema'){
89
95
  let amisReact = amisRequire('react');
90
96
  AmisWrapper = function(props){
91
- const { body, render } = props
97
+ const { $schema, body, render } = props
92
98
  const [schema, setSchema] = amisReact.useState(null);
93
99
  amisReact.useEffect(()=>{
94
100
  const result = Component.class(props);
@@ -99,17 +105,39 @@
99
105
  }else{
100
106
  setSchema(result)
101
107
  }
102
- }, [])
108
+ }, [JSON.stringify($schema)])
103
109
  return amisReact.createElement(amisReact.Fragment, null, amisReact.createElement(amisReact.Fragment, null, schema && render ? render('body', schema) : ''), amisReact.createElement(amisReact.Fragment, null, render ? render('body', body) : ''));
104
110
  }
105
111
  }
106
- amisRequire("amis").Renderer(
107
- {
108
- type: comp.amis?.render.type,
109
- weight: comp.amis?.render.weight,
110
- autoVar: true,
111
- }
112
- )(AmisWrapper);
112
+ // 注册amis渲染器
113
+ let asset = comp.amis.render;
114
+ if (!registerMap[asset.usage]) {
115
+ console.error(
116
+ `自定义组件注册失败,不存在${asset.usage}自定义组件类型。`, comp
117
+ );
118
+ } else {
119
+ registerMap[asset.usage]({
120
+ test: new RegExp(`(^|\/)${asset.type}`),
121
+ type: asset.type,
122
+ weight: asset.weight,
123
+ autoVar: true,
124
+ })(AmisWrapper);
125
+ // 记录当前创建的amis自定义组件
126
+ console.info('注册了一个自定义amis组件:', {
127
+ type: asset.type,
128
+ weight: asset.weight,
129
+ component: AmisWrapper,
130
+ framework: asset.framework,
131
+ usage: asset.usage,
132
+ });
133
+ }
134
+ // amisRequire("amis").Renderer(
135
+ // {
136
+ // type: comp.amis?.render.type,
137
+ // weight: comp.amis?.render.weight,
138
+ // autoVar: true,
139
+ // }
140
+ // )(AmisWrapper);
113
141
  } catch(e){console.error(e)}
114
142
  }
115
143
  });
@@ -151,8 +179,31 @@
151
179
 
152
180
  return pathname + search + hash;
153
181
  };
154
-
155
- const AmisEnv = {
182
+ const isCurrentUrl = (to, ctx)=>{
183
+ try {
184
+ if (!to) {
185
+ return false;
186
+ }
187
+ const pathname = window.location.pathname;
188
+ const link = normalizeLink(to, {
189
+ ...location,
190
+ pathname,
191
+ hash: ''
192
+ });
193
+
194
+ if (!~link.indexOf('http') && ~link.indexOf(':')) {
195
+ let strict = ctx && ctx.strict;
196
+ return match(link, {
197
+ decode: decodeURIComponent,
198
+ strict: typeof strict !== 'undefined' ? strict : true
199
+ })(pathname);
200
+ }
201
+ return decodeURI(pathname) === link || decodeURI(pathname).startsWith(`${link}/`);
202
+ } catch (error) {
203
+ console.error(`error`, error)
204
+ }
205
+ }
206
+ AmisEnv = {
156
207
  // getModalContainer: (props)=>{
157
208
  // let div = document.querySelector("#amisModalContainer");
158
209
  // if(!div){
@@ -172,7 +223,7 @@
172
223
  to = normalizeLink(to);
173
224
 
174
225
  if (action && action.actionType === 'url') {
175
- action.blank === false ? (window.location.href = to) : window.open(to);
226
+ action.blank === true ? window.open(to): (window.location.href = to);
176
227
  return;
177
228
  }
178
229
 
@@ -189,6 +240,7 @@
189
240
  }
190
241
  },
191
242
  theme: 'antd',
243
+ isCurrentUrl: isCurrentUrl,
192
244
  };
193
245
 
194
246
  const AmisRender = function (props) {
@@ -196,6 +248,18 @@
196
248
  const schema = props.schema;
197
249
  const data = props.data;
198
250
  const name = props.name;
251
+ const refName = schema.name || schema.id;
252
+ if(SteedosUI.refs[refName]){
253
+ if(SteedosUI.refs[refName].unmount){
254
+ try {
255
+ SteedosUI.refs[refName].unmount()
256
+ } catch (Exception) {
257
+ }
258
+ }else{
259
+ console.log(`not find amis scope unmount`)
260
+ }
261
+ }
262
+
199
263
  if(props.pageType === 'form'){
200
264
  env = Object.assign({
201
265
  getModalContainer: ()=>{
@@ -218,33 +282,84 @@
218
282
  return scoped = ref
219
283
  }
220
284
 
221
- React.useEffect(()=>{
222
- amisRequire('amis/embed').embed(`.steedos-amis-render-scope-${name}`,schema, {data, name, locale: getAmisLng()}, Object.assign({}, AmisEnv, env))
285
+
286
+ let amisReact = amisRequire('react');
287
+
288
+ amisReact.useEffect(()=>{
289
+ const amisScope = amisRequire('amis/embed').embed(`.steedos-amis-render-scope-${name}`,schema, {data, name, locale: getAmisLng()}, Object.assign({}, AmisEnv, env))
290
+ const refName = schema.name || schema.id;
291
+ if(window.SteedosUI && refName){
292
+ SteedosUI.refs[refName] = amisScope;
293
+ }
223
294
  }, [])
224
- return React.createElement("div", {
295
+ return amisReact.createElement("div", {
225
296
  className: "amis-scope"
226
- }, React.createElement("div", {
297
+ }, amisReact.createElement("div", {
227
298
  className: `steedos-amis-render-scope-${name}`
228
299
  }));
229
300
  };
230
301
 
302
+ window.renderAmis = function (root, schema, data, env) {
303
+ const refName = schema.name || schema.id;
304
+ if(SteedosUI.refs[refName]){
305
+ if(SteedosUI.refs[refName].unmount){
306
+ try {
307
+ SteedosUI.refs[refName].unmount()
308
+ } catch (Exception) {
309
+ }
310
+ }else{
311
+ console.log(`not find amis scope unmount`)
312
+ }
313
+ }
314
+
315
+ // if(props.pageType === 'form'){
316
+ // env = Object.assign({
317
+ // getModalContainer: ()=>{
318
+ // return document.querySelector('.amis-scope');
319
+ // }
320
+ // }, env);
321
+ // }
322
+ schema.scopeRef = (ref) => {
323
+ try {
324
+ if(!window.amisScopes){
325
+ window.amisScopes = {};
326
+ }
327
+ if(name){
328
+ window.amisScopes[name] = ref;
329
+ }
330
+ } catch (error) {
331
+ console.error('error', error)
332
+ }
333
+
334
+ return scoped = ref
335
+ }
336
+
337
+
338
+ const amisScope = amisRequire('amis/embed').embed(root, schema, {data, name, locale: getAmisLng()}, Object.assign({}, AmisEnv, env))
339
+ if(window.SteedosUI && refName){
340
+ SteedosUI.refs[refName] = amisScope;
341
+ }
342
+ };
343
+
231
344
  const initMonaco = ()=>{
232
345
 
233
- const { detect } = require('detect-browser');
346
+ // const { detect } = require('detect-browser');
234
347
 
235
- const browser = detect();
348
+ // const browser = detect();
236
349
 
237
- // 低于86版的chrome 不支持code类型字段及功能
238
- if (browser && browser.name === 'chrome' && Number(browser.version.split(".")[0]) < 86) {
239
- return Promise.resolve(true)
240
- }
350
+ // // 低于86版的chrome 不支持code类型字段及功能
351
+ // if (browser && browser.name === 'chrome' && Number(browser.version.split(".")[0]) < 86) {
352
+ // return Promise.resolve(true)
353
+ // }
241
354
 
242
- // 手机版暂不支持code类型字段.
243
- if(Meteor.isCordova){
244
- return Promise.resolve(true)
245
- }else{
246
- return Builder.initMonaco()
247
- }
355
+ // // 手机版暂不支持code类型字段.
356
+ // if(Meteor.isCordova){
357
+ // return Promise.resolve(true)
358
+ // }else{
359
+ // return Builder.initMonaco()
360
+ // }
361
+
362
+ return Promise.resolve(true)
248
363
  }
249
364
  //Amis SDK 中已清理了monaco, 所以这里需要提前注册,否则会导致amis code类型报错
250
365
  initMonaco().catch((err)=>{
@@ -1,3 +1,10 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2022-12-09 18:23:36
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2022-12-17 14:35:49
6
+ * @Description:
7
+ */
1
8
  // 解决多个react 问题. 注册组件时, 使用 amis 自带的 react , 运行 steedos 相关组件时, 使用 全局 react
2
9
  window.addEventListener('message', function (event) {
3
10
  const { data } = event;
@@ -7,8 +14,8 @@ window.addEventListener('message', function (event) {
7
14
  Promise.all([
8
15
  waitForThing(window, 'amis'),
9
16
  ]).then(()=>{
10
- window.__React = window.React;
11
- window.__ReactDOM = window.ReactDOM;
17
+ // window.__React = window.React;
18
+ // window.__ReactDOM = window.ReactDOM;
12
19
  window.React = amisRequire('react');
13
20
  window.ReactDOM = amisRequire('react-dom');
14
21
  window.ReactDom = window.ReactDOM;
@@ -1,16 +1,35 @@
1
1
  try {
2
2
  // 加载 tailwind
3
- if(typeof BigInt === 'undefined') {
4
- let tailwindStyle = document.createElement("link");
5
- tailwindStyle.setAttribute("rel", "stylesheet");
6
- tailwindStyle.setAttribute("type", "text/css");
7
- tailwindStyle.setAttribute("href", Steedos.absoluteUrl("/tailwind/tailwind.css"));
8
- document.getElementsByTagName("head")[0].appendChild(tailwindStyle);
9
- }else{
10
- let tailwindScript = document.createElement("script");
11
- tailwindScript.setAttribute("src", Steedos.absoluteUrl('/tailwind/tailwind.js'));
12
- document.getElementsByTagName("head")[0].appendChild(tailwindScript);
3
+ // if(typeof BigInt === 'undefined') {
4
+ // let tailwindStyle = document.createElement("link");
5
+ // tailwindStyle.setAttribute("rel", "stylesheet");
6
+ // tailwindStyle.setAttribute("type", "text/css");
7
+ // tailwindStyle.setAttribute("href", Steedos.absoluteUrl("/tailwind/tailwind.css"));
8
+ // document.getElementsByTagName("head")[0].appendChild(tailwindStyle);
9
+ // }else{
10
+ // let tailwindScript = document.createElement("script");
11
+ // tailwindScript.setAttribute("src", Steedos.absoluteUrl('/tailwind/tailwind.js'));
12
+ // document.getElementsByTagName("head")[0].appendChild(tailwindScript);
13
+ // }
14
+
15
+ const head = document.head || document.getElementsByTagName('head')[0]
16
+
17
+ let tailwindBase = document.createElement("link");
18
+ tailwindBase.setAttribute("rel", "stylesheet");
19
+ tailwindBase.setAttribute("type", "text/css");
20
+ tailwindBase.setAttribute("href", Steedos.absoluteUrl("/tailwind/tailwind-base.css"));
21
+
22
+ if (head.firstChild) {
23
+ head.insertBefore(tailwindBase, head.firstChild)
24
+ } else {
25
+ head.appendChild(tailwindBase)
13
26
  }
27
+
28
+ let tailwindStyle = document.createElement("link");
29
+ tailwindStyle.setAttribute("rel", "stylesheet");
30
+ tailwindStyle.setAttribute("type", "text/css");
31
+ tailwindStyle.setAttribute("href", Steedos.absoluteUrl("/tailwind/tailwind-steedos.css"));
32
+ head.appendChild(tailwindStyle)
14
33
  } catch (error) {
15
34
  console.error(error)
16
35
  };
@@ -0,0 +1,294 @@
1
+ {
2
+ "type": "page",
3
+ "body": [
4
+ {
5
+ "type": "service",
6
+ "className": "p-0",
7
+ "name": "page_edit_${recordId}",
8
+ "api": {
9
+ "method": "post",
10
+ "url": "${context.rootUrl}/graphql",
11
+ "adaptor": "\n if(payload.data.data){\n var data = payload.data.data[0];\n if(data){\n \n \n //初始化接口返回的字段移除字段值为null的字段\n for (key in data){\n if(data[key] === null){\n delete data[key];\n }\n }\n };\n payload.data = data;\n delete payload.extensions;\n }\n return payload;\n ",
12
+ "data": {
13
+ "query": "{data:action_field_updates(filters:[\"_id\", \"=\", \"${recordId}\"]){_id,name,label,object_name,target_object,field_name,operation,formula,literal_value,description,reevaluate_on_change,undirect,created,created_by,modified,modified_by,_display:_ui{object_name,target_object,field_name,operation,reevaluate_on_change,undirect,created,created_by,modified,modified_by}, \n recordPermissions: _permissions{\n allowCreate,\n allowCreateFiles,\n allowDelete,\n allowDeleteFiles,\n allowEdit,\n allowEditFiles,\n allowRead,\n allowReadFiles,\n disabled_actions,\n disabled_list_views,\n field_permissions,\n modifyAllFiles,\n modifyAllRecords,\n modifyAssignCompanysRecords,\n modifyCompanyRecords,\n uneditable_fields,\n unreadable_fields,\n unrelated_objects,\n viewAllFiles,\n viewAllRecords,\n viewAssignCompanysRecords,\n viewCompanyRecords,\n }\n }}"
14
+ },
15
+ "headers": {
16
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
17
+ },
18
+ "sendOn": "!!this.recordId",
19
+ "cache": 100
20
+ },
21
+ "initFetch": null,
22
+ "body": [
23
+ {
24
+ "type": "form",
25
+ "title": "",
26
+ "body": [
27
+ {
28
+ "type": "fieldSet",
29
+ "id": "u:3ce1d050bcac",
30
+ "title": "通用",
31
+ "collapsable": true,
32
+ "body": [
33
+ {
34
+ "name": "name",
35
+ "label": "API 名称",
36
+ "required": true,
37
+ "type": "input-text",
38
+ "className": "m-1",
39
+ "labelClassName": "text-left",
40
+ "clearValueOnHidden": true,
41
+ "fieldName": "name",
42
+ "id": "u:8ebca359c714"
43
+ },
44
+ {
45
+ "name": "label",
46
+ "label": "显示名称",
47
+ "required": true,
48
+ "type": "input-text",
49
+ "className": "m-1",
50
+ "labelClassName": "text-left",
51
+ "clearValueOnHidden": true,
52
+ "fieldName": "label",
53
+ "id": "u:124c34a09c5c"
54
+ },
55
+ {
56
+ "name": "object_name",
57
+ "label": "对象",
58
+ "required": false,
59
+ "type": "select",
60
+ "joinValues": false,
61
+ "extractValue": true,
62
+ "autoComplete": {
63
+ "method": "post",
64
+ "url": "${context.rootUrl}/graphql",
65
+ "data": {
66
+ "query": "{objects(filters: [\"_id\", \"=\", \"-1\"]){_id}}",
67
+ "$": "$$",
68
+ "$term": "$term",
69
+ "$value": "$object_name._id",
70
+ "rfield": "${object_name}"
71
+ },
72
+ "requestAdaptor": "\n var filters = '[]';\n var top = 10;\n if(api.data.$term){\n filters = '[\"name\", \"contains\", \"'+ api.data.$term +'\"]';\n }else if(api.data.$value){\n filters = '[\"_id\", \"=\", \"'+ api.data.$value +'\"]';\n }\n api.data.query = api.data.query.replace(/{__filters}/g, filters).replace('{__top}', top);\n return api;\n ",
73
+ "adaptor": "\n payload.data.options = eval(function anonymous(\n) {\n\n return Steedos.getObjectsOptions();\n\n})(api.data);\n return payload;\n "
74
+ },
75
+ "className": "m-1",
76
+ "labelClassName": "text-left",
77
+ "clearValueOnHidden": true,
78
+ "fieldName": "object_name",
79
+ "id": "u:0f2e40f882e2"
80
+ },
81
+ {
82
+ "name": "target_object",
83
+ "label": "要更新的对象",
84
+ "required": false,
85
+ "type": "select",
86
+ "joinValues": false,
87
+ "extractValue": true,
88
+ "autoComplete": {
89
+ "method": "post",
90
+ "url": "${context.rootUrl}/graphql",
91
+ "data": {
92
+ "query": "{objects(filters: [\"_id\", \"=\", \"-1\"]){_id}}",
93
+ "$": "$$",
94
+ "$term": "$term",
95
+ "$value": "$target_object._id",
96
+ "object_name": "$object_name",
97
+ "rfield": "${object_name}"
98
+ },
99
+ "requestAdaptor": "\n var filters = '[]';\n var top = 10;\n if(api.data.$term){\n filters = '[\"name\", \"contains\", \"'+ api.data.$term +'\"]';\n }else if(api.data.$value){\n filters = '[\"_id\", \"=\", \"'+ api.data.$value +'\"]';\n }\n api.data.query = api.data.query.replace(/{__filters}/g, filters).replace('{__top}', top);\n return api;\n ",
100
+ "adaptor": "\n payload.data.options = eval(function anonymous(doc\n) {\n\n var object = Creator.objectsByName[doc.object_name];\n if(object){\n var _options = [{label: object.label, value: object.name}];\n _.forEach(object.fields, function (field, fname) {\n if(field && field.type === 'master_detail' && _.isString(field.reference_to)){\n var referenceToObject = Creator.objectsByName[field.reference_to];\n if(referenceToObject){\n _options.push({\n label: referenceToObject.label,\n value: field.name,\n });\n }\n }\n });\n return _options;\n }\n return [];\n\n})(api.data);\n return payload;\n "
101
+ },
102
+ "className": "m-1",
103
+ "labelClassName": "text-left",
104
+ "clearValueOnHidden": true,
105
+ "fieldName": "target_object",
106
+ "id": "u:dd1c95753238"
107
+ },
108
+ {
109
+ "name": "field_name",
110
+ "label": "要更新的字段",
111
+ "required": false,
112
+ "type": "select",
113
+ "joinValues": false,
114
+ "extractValue": true,
115
+ "autoComplete": {
116
+ "method": "post",
117
+ "url": "${context.rootUrl}/graphql",
118
+ "data": {
119
+ "query": "{objects(filters: [\"_id\", \"=\", \"-1\"]){_id}}",
120
+ "$": "$$",
121
+ "$term": "$term",
122
+ "$value": "$field_name._id",
123
+ "object_name": "$object_name",
124
+ "target_object": "$target_object",
125
+ "rfield": "${object_name}"
126
+ },
127
+ "requestAdaptor": "\n var filters = '[]';\n var top = 10;\n if(api.data.$term){\n filters = '[\"name\", \"contains\", \"'+ api.data.$term +'\"]';\n }else if(api.data.$value){\n filters = '[\"_id\", \"=\", \"'+ api.data.$value +'\"]';\n }\n api.data.query = api.data.query.replace(/{__filters}/g, filters).replace('{__top}', top);\n return api;\n ",
128
+ "adaptor": "\n payload.data.options = eval(function anonymous(doc\n) {\n\n var mainObjectName = null;\n if(doc.target_object && doc.target_object != doc.object_name){\n mainObjectName = Creator.objectsByName[doc.object_name].fields[doc.target_object].reference_to;\n }else{\n mainObjectName = doc.object_name;\n }\n var object = Creator.objectsByName[mainObjectName];\n if(object){\n var _options = [];\n _.forEach(object.fields, function (field, fname) {\n if([\"formula\", \"summary\", \"autonumber\"].indexOf(field.type) < 0){\n /*公式、累计汇总、自动编号三种字段类型是只读的,不允许字段更新来变更其值*/\n _options.push({\n label: field.label,\n value: field.name,\n });\n }\n });\n return _options;\n }\n return [];\n\n})(api.data);\n return payload;\n "
129
+ },
130
+ "className": "m-1",
131
+ "labelClassName": "text-left",
132
+ "clearValueOnHidden": true,
133
+ "fieldName": "field_name",
134
+ "id": "u:204fadb7cef0"
135
+ },
136
+ {
137
+ "name": "operation",
138
+ "label": "新字段值类型",
139
+ "required": false,
140
+ "type": "select",
141
+ "joinValues": false,
142
+ "extractValue": true,
143
+ "autoComplete": {
144
+ "method": "post",
145
+ "url": "${context.rootUrl}/graphql",
146
+ "data": {
147
+ "query": "{objects(filters: [\"_id\", \"=\", \"-1\"]){_id}}",
148
+ "$": "$$",
149
+ "$term": "$term",
150
+ "$value": "$operation._id",
151
+ "field_name": "$field_name",
152
+ "target_object": "$target_object",
153
+ "object_name": "$object_name",
154
+ "rfield": "${object_name}"
155
+ },
156
+ "requestAdaptor": "\n var filters = '[]';\n var top = 10;\n if(api.data.$term){\n filters = '[\"name\", \"contains\", \"'+ api.data.$term +'\"]';\n }else if(api.data.$value){\n filters = '[\"_id\", \"=\", \"'+ api.data.$value +'\"]';\n }\n api.data.query = api.data.query.replace(/{__filters}/g, filters).replace('{__top}', top);\n return api;\n ",
157
+ "adaptor": "\n payload.data.options = eval(function anonymous(doc\n) {\n\n var mainObjectName = null;\n if(doc.target_object && doc.target_object != doc.object_name){\n mainObjectName = Creator.objectsByName[doc.object_name].fields[doc.target_object].reference_to;\n }else{\n mainObjectName = doc.object_name;\n }\n var object = Creator.objectsByName[mainObjectName];\n if(object && doc.field_name){\n var _options = [];\n var field = object.fields[doc.field_name];\n if(field && field.type != 'boolean'){\n _options.push({\n label: TAPi18n.__(\"action_field_updates_field_operation_options_null\"),\n value: 'null',\n }) \n }\n _options.push({\n label: TAPi18n.__(\"action_field_updates_field_operation_options_formula\"),\n value: 'formula',\n });\n _options.push({\n label: TAPi18n.__(\"action_field_updates_field_operation_options_literal\"),\n value: 'literal',\n })\n return _options;\n }\n return [];\n\n})(api.data);\n return payload;\n "
158
+ },
159
+ "className": "m-1",
160
+ "labelClassName": "text-left",
161
+ "clearValueOnHidden": true,
162
+ "fieldName": "operation",
163
+ "id": "u:627e520855b5",
164
+ "multiple": false
165
+ },
166
+ {
167
+ "name": "formula",
168
+ "label": "公式",
169
+ "required": false,
170
+ "type": "textarea",
171
+ "tpl": "<b><%=data.formula%></b>",
172
+ "className": "col-span-2 m-1",
173
+ "labelClassName": "text-left",
174
+ "clearValueOnHidden": true,
175
+ "fieldName": "formula",
176
+ "id": "u:20766a86a9f4",
177
+ "hiddenOn": "this.operation != 'formula'"
178
+ },
179
+ {
180
+ "type": "service",
181
+ "id": "u:d201a629c160",
182
+ "body": [],
183
+ "messages": {},
184
+ "schemaApi": {
185
+ "method": "get",
186
+ "url": "${context.rootUrl}/service/api/@${object_name}/uiSchema?field_name=${field_name}&operation=${operation}",
187
+ "adaptor": "const formData = api.body;\nconst target_field_name = formData.field_name;\nconst target_object_uiSchema = payload;\nconst target_fields = target_object_uiSchema && target_object_uiSchema.fields;\nconst target_field_type = target_fields && target_fields[target_field_name].type;\nlet literal_value_schema = {\n \"type\": \"text\",\n \"name\": \"literal_value\",\n \"label\": \"指定新字段值\",\n \"required\": false,\n \"is_wide\": true,\n \"labelClassName\": \"text-left\"\n}\nif (target_field_type) {\n literal_value_schema = Object.assign({}, target_object_uiSchema.fields[target_field_name], {\n name: \"literal_value\",\n label: \"指定新字段值\",\n disabled: false,\n readonly: false,\n is_wide: true\n });\n}\npayload = {\n \"status\": 0,\n \"msg\": \"\",\n \"data\": {\n \"body\": [\n {\n \"type\": \"steedos-field\",\n \"field\": literal_value_schema,\n \"name\": \"literal_value\",\n \"clearValueOnHidden\": true,\n \"fieldName\": \"literal_value\",\n \"visibleOn\": \"this.operation === 'literal'\"\n }\n ]\n }\n}\nreturn payload;",
188
+ "sendOn": "!!this.object_name && !!this.field_name && this.operation === 'literal'",
189
+ "headers": {
190
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
191
+ },
192
+ "data": {
193
+ "&": "$$"
194
+ }
195
+ }
196
+ },
197
+ {
198
+ "name": "description",
199
+ "label": "描述",
200
+ "required": false,
201
+ "type": "textarea",
202
+ "tpl": "<b><%=data.description%></b>",
203
+ "className": "col-span-2 m-1",
204
+ "labelClassName": "text-left",
205
+ "clearValueOnHidden": true,
206
+ "fieldName": "description",
207
+ "id": "u:16a7ebd835a6"
208
+ },
209
+ {
210
+ "name": "reevaluate_on_change",
211
+ "label": "字段更改后重新评估工作流规则",
212
+ "required": false,
213
+ "type": "checkbox",
214
+ "tpl": null,
215
+ "className": "m-1",
216
+ "labelClassName": "text-left",
217
+ "clearValueOnHidden": true,
218
+ "fieldName": "reevaluate_on_change",
219
+ "id": "u:b9baf683b6b0"
220
+ },
221
+ {
222
+ "name": "undirect",
223
+ "label": "触发对象触发器、工作流规则、字段验证规则",
224
+ "required": false,
225
+ "type": "checkbox",
226
+ "tpl": null,
227
+ "className": "m-1",
228
+ "labelClassName": "text-left",
229
+ "clearValueOnHidden": true,
230
+ "fieldName": "undirect",
231
+ "id": "u:b86f699bbe4f"
232
+ }
233
+ ]
234
+ }
235
+ ],
236
+ "id": "u:f57077c2a95f",
237
+ "mode": "horizontal",
238
+ "persistData": false,
239
+ "promptPageLeave": true,
240
+ "name": "form_edit_${recordId}",
241
+ "debug": false,
242
+ "submitText": "",
243
+ "api": {
244
+ "method": "post",
245
+ "url": "${context.rootUrl}/graphql",
246
+ "data": {
247
+ "objectName": "${objectName}",
248
+ "$": "$$",
249
+ "recordId": "${recordId}",
250
+ "modalName": "${modalName}"
251
+ },
252
+ "requestAdaptor": "\n \n const formData = api.data.$;\n for (key in formData){\n // image、select等字段清空值后保存的空字符串转换为null。\n if(formData[key] === ''){\n formData[key] = null;\n }\n }\n const objectName = api.data.objectName;\n const fieldsName = Object.keys(formData);\n delete formData.created;\n delete formData.created_by;\n delete formData.modified;\n delete formData.modified_by;\n delete formData._display;\n delete formData.created;\r\ndelete formData.created_by;\r\ndelete formData.modified;\r\ndelete formData.modified_by;\n \n \n let query = `mutation{record: ${objectName}__insert(doc: {__saveData}){_id}}`;\n if(formData.recordId && formData.recordId !='new'){\n query = `mutation{record: ${objectName}__update(id: \"${formData._id}\", doc: {__saveData}){_id}}`;\n };\n delete formData._id;\n let __saveData = JSON.stringify(JSON.stringify(formData));\n \n api.data = {query: query.replace('{__saveData}', __saveData)};\n return api;\n ",
253
+ "responseData": {
254
+ "recordId": "${record._id}"
255
+ },
256
+ "adaptor": "\n if(payload.errors){\n payload.status = 2;\n payload.msg = payload.errors[0].message;\n }\n return payload;\n ",
257
+ "headers": {
258
+ "Authorization": "Bearer ${context.tenantId},${context.authToken}"
259
+ }
260
+ },
261
+ "initFetch": true,
262
+ "panelClassName": "m-0 sm:rounded-lg shadow-none",
263
+ "bodyClassName": "p-0",
264
+ "className": "steedos-amis-form",
265
+ "onEvent": {
266
+ "submitSucc": {
267
+ "weight": 0,
268
+ "actions": [
269
+ {
270
+ "componentId": "listview_action_field_updates",
271
+ "actionType": "reload",
272
+ "expression": "!!listViewId"
273
+ },
274
+ {
275
+ "actionType": "custom",
276
+ "script": "\n const { recordId, listViewId } = context.props.data;\n const data = event.data;\n const appId = data.appId;\n const objectName = data.objectName;\n // 在记录详细界面时isRecordDetail为true\n // TODO: isRecordDetail这个判断需要优化\n const isRecordDetail = !!data.$master && data.$master.$master?.recordId;\n if(recordId){\n // 编辑记录时,刷新主表单\n doAction({\n componentId: `detail_${recordId}`,\n actionType: \"reload\",\n expression: `!${listViewId}`\n });\n }\n else if(!isRecordDetail){\n // 在列表视图界面新建记录时跳转到详细页面\n const jumpTo = event.context.env && event.context.env.jumpTo;\n if(jumpTo){\n const newRecordId = data.result.data?.recordId;\n jumpTo(\"/app/\" + appId + \"/\" + objectName + \"/view/\" + newRecordId);\n }\n }\n "
277
+ }
278
+ ]
279
+ }
280
+ }
281
+ }
282
+ ],
283
+ "initApi": null
284
+ }
285
+ ],
286
+ "data": {
287
+ "objectName": "action_field_updates",
288
+ "context": {}
289
+ },
290
+ "regions": [
291
+ "body"
292
+ ],
293
+ "bodyClassName": ""
294
+ }
@@ -0,0 +1,12 @@
1
+ name: action_field_updates
2
+ is_active: true
3
+ label: 字段更新表单
4
+ object_name: action_field_updates
5
+ pageAssignments:
6
+ - desktop: true
7
+ mobile: true
8
+ page: action_field_updates
9
+ type: orgDefault
10
+ render_engine: amis
11
+ type: form
12
+ widgets: []