@steedos/service-plugin-amis 2.2.19 → 2.2.22

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.
@@ -15,54 +15,99 @@
15
15
  } catch (error) {
16
16
  console.error(error)
17
17
  };
18
-
19
- import('/amis/sdk/sdk.noreact.js').then(() => {
18
+
19
+ import('/unpkg.com/@steedos-ui/amis/dist/amis-sdk.umd.min.js').then(() => {
20
20
 
21
21
  Promise.all([
22
22
  waitForThing(window, 'assetsLoaded'),
23
- waitForThing(window, 'React'),
24
- waitForThing(window, 'Builder'),
25
- waitForThing(window, 'amisRequire'),
23
+ waitForThing(window, 'AmisSDK'),
26
24
  ]).then(()=>{
27
25
 
28
- window.SAmisReners = [];
26
+ const AmisRenderers = [];
29
27
 
30
28
  const amisComps = lodash.filter(Builder.registry['meta-components'], function(item){ return item.componentName && item.amis?.render});
31
29
 
32
- let amisLib = amisRequire('amis');
33
-
34
30
  lodash.each(amisComps,(comp)=>{
35
31
  const Component = Builder.components.find(item => item.name === comp.componentName);
36
- if (Component && !SAmisReners.includes(comp.amis?.render.type)){
32
+ if (Component && !AmisRenderers.includes(comp.amis?.render.type)){
37
33
  try {
38
- SAmisReners.push(comp.amis?.render.type);
39
- amisLib.Renderer(
34
+ AmisRenderers.push(comp.amis?.render.type);
35
+ AmisSDK.amis.Renderer(
40
36
  {
41
37
  type: comp.amis?.render.type,
42
- weight: comp.amis?.render.weight
38
+ weight: comp.amis?.render.weight,
39
+ autoVar: true,
43
40
  }
44
41
  )(Component.class);
45
- } catch(e){console.log(e)}
42
+ } catch(e){console.error(e)}
46
43
  }
47
- })
44
+ });
45
+
46
+ const AmisEnv = {
47
+ fetcher: ({url, method, data, config}) => {
48
+ console.log('fetcher. url', url);
49
+ if(url.startsWith("http") && url.indexOf("://") == -1){
50
+ url = decodeURIComponent(url)
51
+ }
52
+ config = config || {};
53
+ config.headers = config.headers || {};
54
+ config.withCredentials = true;
55
+
56
+ if (method !== 'post' && method !== 'put' && method !== 'patch') {
57
+ if (data) {
58
+ config.params = data;
59
+ }
60
+ return (axios)[method](url, config);
61
+ } else if (data && data instanceof FormData) {
62
+ // config.headers = config.headers || {};
63
+ // config.headers['Content-Type'] = 'multipart/form-data';
64
+ } else if (
65
+ data &&
66
+ typeof data !== 'string' &&
67
+ !(data instanceof Blob) &&
68
+ !(data instanceof ArrayBuffer)
69
+ ) {
70
+ data = JSON.stringify(data);
71
+ config.headers['Content-Type'] = 'application/json';
72
+ }
73
+
74
+ return (axios)[method](url, data, config);
75
+ },
76
+ isCancel: (e) => axios.isCancel(e),
77
+ updateLocation: ((location, replace) => {
78
+ console.debug('updateLocation==>', location, replace);
79
+ // const history = this.props.history;
80
+ // if (location === 'goBack') {
81
+ // return history.goBack();
82
+ // } else if (/^https?\:\/\//.test(location)) {
83
+ // return (window.location.href = location);
84
+ // }
85
+ // history[replace ? 'replace' : 'push'](normalizeLink(location, replace));
86
+ }),
87
+ notify: (type, msg) => {
88
+ AmisSDK.amis.toast[type]
89
+ ? AmisSDK.amis.toast[type](msg, type === 'error' ? '系统错误' : '系统消息')
90
+ : console.warn('[Notify]', type, msg);
91
+ console.log('[notify]', type, msg);
92
+ },
93
+ alert: AmisSDK.amis.alert,
94
+ confirm: AmisSDK.amis.confirm,
95
+ // copy: (contents, options = {}) => {
96
+ // const ret = copy(contents, options);
97
+ // ret && (!options || options.shutup !== true) && toast.info('内容已拷贝到剪切板');
98
+ // return ret;
99
+ // },
100
+ theme: 'cxd',
101
+ };
48
102
 
49
- // Register amis render
50
- var Amis = function (props) {
51
- var schema = props.schema, data = props.data;
52
- return React.createElement(React.Fragment, null,
53
- React.createElement("div", { id: "amis-root" }),
54
- // amisRequire('amis').render(schema, data, {theme: 'cxd'}))
55
- function () {
56
- setTimeout(function () {
57
- amisRequire('amis/embed').embed('#amis-root', schema, {
58
- data
59
- })
60
- }, 100)
61
- }()
62
- );
103
+ const AmisRender = function (props) {
104
+ const env = props.env;
105
+ const schema = props.schema;
106
+ const data = props.data;
107
+ return (React.createElement("div", { className: "amis-scope" }, AmisSDK.amis.render(schema, data, Object.assign({}, AmisEnv, env))));
63
108
  };
64
109
 
65
- Builder.registerComponent(Amis, {
110
+ Builder.registerComponent(AmisRender, {
66
111
  name: 'Amis',
67
112
  inputs: [
68
113
  { name: 'schema', type: 'object' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-plugin-amis",
3
- "version": "2.2.19",
3
+ "version": "2.2.22",
4
4
  "main": "package.service.js",
5
5
  "scripts": {},
6
6
  "license": "MIT",
@@ -8,5 +8,5 @@
8
8
  "publishConfig": {
9
9
  "access": "public"
10
10
  },
11
- "gitHead": "952067d4517fd07335b75c63fec4700f18db73ec"
11
+ "gitHead": "af4ea8ed034854c8de1ff8b9d5db241183524417"
12
12
  }
@@ -18,6 +18,7 @@ module.exports = {
18
18
  packageInfo: {
19
19
  path: __dirname,
20
20
  name: this.name,
21
+ isPackage: false
21
22
  }
22
23
  },
23
24