@cqsjjb/jjb-cloud-component 0.0.1 → 0.0.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.
@@ -9,6 +9,10 @@ interface ComponentProps {
9
9
  interface CloudComponentProps extends ComponentProps {
10
10
  // 组件资源地址
11
11
  from: string;
12
+ // 缓存
13
+ cache?: string;
14
+ // 请求头
15
+ headers?: {};
12
16
  // 是否需要初始化更新settings和dataSource
13
17
  initialize?: boolean;
14
18
  // 组件唯一key
@@ -17,6 +17,8 @@ export default function CloudComponent(props) {
17
17
  const [ Component, setComponent ] = React.useState(null);
18
18
  const {
19
19
  from,
20
+ cache,
21
+ headers,
20
22
  initialize,
21
23
  componentKey,
22
24
  componentProps,
@@ -33,7 +35,11 @@ export default function CloudComponent(props) {
33
35
  const {
34
36
  module,
35
37
  styleId: _styleId
36
- } = await ImportCloudComponent({ from });
38
+ } = await ImportCloudComponent({
39
+ from,
40
+ cache,
41
+ headers
42
+ });
37
43
 
38
44
  styleId = _styleId;
39
45
 
@@ -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: {
@@ -82,7 +82,7 @@ function checkDependencies(lib, dependencies, isProxy) {
82
82
 
83
83
  /**
84
84
  * @description 手动加载模块
85
- * @param options {{ from: string, lib: string }}
85
+ * @param options {{ from: string, lib: string, cache: string, headers: {} }}
86
86
  * @example
87
87
  * Import({
88
88
  * from: 'https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js'
@@ -95,11 +95,17 @@ export default function ImportCloudComponent(options) {
95
95
  const lib = options.lib || '__coreLib';
96
96
  const from = options.from;
97
97
 
98
+ const cache = options.cache || 'force-cache';
99
+ const headers = tools.toObject(options.headers);
100
+
98
101
  if (!from) {
99
102
  throw Error(print('云组件资源访问地址不能为空!'));
100
103
  }
101
104
 
102
- return fetch(fromURL(from))
105
+ return fetch(from, {
106
+ cache,
107
+ headers
108
+ })
103
109
  .then(response => response.text())
104
110
  .then(response => {
105
111
  const {
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.2",
4
4
  "description": "前端-云组件",
5
5
  "main": "index.js",
6
6
  "scripts": {