@cqsjjb/jjb-cloud-component 0.0.1 → 0.0.3

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.
@@ -1,5 +1,6 @@
1
1
  // @ts-ignore
2
2
  import * as React from 'react';
3
+ import type I_ImportCloudComponent from './import-cloud-component';
3
4
 
4
5
  interface ComponentProps {
5
6
  ref?: React.Ref<{ [ p: string ]: any }>;
@@ -9,6 +10,10 @@ interface ComponentProps {
9
10
  interface CloudComponentProps extends ComponentProps {
10
11
  // 组件资源地址
11
12
  from: string;
13
+ // 缓存
14
+ cache?: string;
15
+ // 请求头
16
+ headers?: {};
12
17
  // 是否需要初始化更新settings和dataSource
13
18
  initialize?: boolean;
14
19
  // 组件唯一key
@@ -39,4 +44,4 @@ interface CloudComponentFc extends React.FC<CloudComponentProps> {
39
44
  }
40
45
 
41
46
  declare const CloudComponent: CloudComponentFc;
42
- export default CloudComponent;
47
+ declare const ImportCloudComponent: typeof I_ImportCloudComponent;
@@ -16,7 +16,10 @@ export default function CloudComponent(props) {
16
16
  let styleId;
17
17
  const [ Component, setComponent ] = React.useState(null);
18
18
  const {
19
+ lib,
19
20
  from,
21
+ cache,
22
+ headers,
20
23
  initialize,
21
24
  componentKey,
22
25
  componentProps,
@@ -33,7 +36,12 @@ export default function CloudComponent(props) {
33
36
  const {
34
37
  module,
35
38
  styleId: _styleId
36
- } = await ImportCloudComponent({ from });
39
+ } = await ImportCloudComponent({
40
+ lib,
41
+ from,
42
+ cache,
43
+ headers
44
+ });
37
45
 
38
46
  styleId = _styleId;
39
47
 
@@ -63,3 +71,4 @@ export default function CloudComponent(props) {
63
71
  />
64
72
  );
65
73
  }
74
+
@@ -6,6 +6,10 @@ declare function ImportCloudComponent (options: {
6
6
  lib?: string;
7
7
  // 组件地址
8
8
  from: string;
9
+ // 缓存
10
+ cache?: string;
11
+ // 请求头
12
+ headers?: {}
9
13
  }): {
10
14
  styleId: string;
11
15
  module: {
@@ -61,7 +61,8 @@ function print(msg) {
61
61
  * @return {boolean}
62
62
  */
63
63
  function checkDependence(lib, name) {
64
- return tools.isUndefined(window[ lib ][ name ]);
64
+ const dependencies = new Function(`return window${ansLibField(lib)}`)();
65
+ return tools.isUndefined(dependencies[ name ]);
65
66
  }
66
67
 
67
68
  /**
@@ -82,7 +83,7 @@ function checkDependencies(lib, dependencies, isProxy) {
82
83
 
83
84
  /**
84
85
  * @description 手动加载模块
85
- * @param options {{ from: string, lib: string }}
86
+ * @param options {{ from: string, lib: string, cache: string, headers: {} }}
86
87
  * @example
87
88
  * Import({
88
89
  * from: 'https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js'
@@ -92,14 +93,20 @@ function checkDependencies(lib, dependencies, isProxy) {
92
93
  * @return {Promise<{ module: { info: {}, default:() => React.Component }, styleId: string }>}
93
94
  */
94
95
  export default function ImportCloudComponent(options) {
95
- const lib = options.lib || '__coreLib';
96
+ const lib = typeof window.proxy === 'undefined' ? `${options.lib || '__coreLib'}` : `.proxy.${options.lib || '__coreLib'}`;
96
97
  const from = options.from;
97
98
 
99
+ const cache = options.cache || 'force-cache';
100
+ const headers = tools.toObject(options.headers);
101
+
98
102
  if (!from) {
99
103
  throw Error(print('云组件资源访问地址不能为空!'));
100
104
  }
101
105
 
102
- return fetch(fromURL(from))
106
+ return fetch(from, {
107
+ cache,
108
+ headers
109
+ })
103
110
  .then(response => response.text())
104
111
  .then(response => {
105
112
  const {
@@ -141,3 +148,4 @@ export default function ImportCloudComponent(options) {
141
148
  };
142
149
  });
143
150
  }
151
+
package/index.js CHANGED
@@ -1,7 +1,2 @@
1
- import CloudComponent from './cloud-component';
2
- import ImportCloudComponent from './import-cloud-component';
3
-
4
- export {
5
- CloudComponent,
6
- ImportCloudComponent
7
- };
1
+ export CloudComponent from './cloud-component';
2
+ export ImportCloudComponent from './import-cloud-component';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cqsjjb/jjb-cloud-component",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "前端-云组件",
5
5
  "main": "index.js",
6
6
  "scripts": {