hzerojs-plugin-yqcloud-jssdk 1.0.19 → 1.0.21

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.
package/lib/index.js CHANGED
@@ -41,7 +41,7 @@ var import_index = require("./index.css");
41
41
  var YQ_API_HOST = "https://api.test.yqcloud.com";
42
42
  var src_default = (props) => {
43
43
  var _a, _b;
44
- const { token, entryDetail, apiHost = YQ_API_HOST, tokenPath = "/iam/v1/zknow/encrypt/quick", modalBodyStyle, modalStyle } = props;
44
+ const { token, entryDetail, apiHost = YQ_API_HOST, tokenPath = "/iam/v1/zknow/encrypt/quick" } = props;
45
45
  const eleRef = import_react.default.useRef(null);
46
46
  const tenantIdRef = import_react.default.useRef(null);
47
47
  const [appConfig, setAppConfig] = import_react.default.useState(false);
@@ -130,13 +130,13 @@ var src_default = (props) => {
130
130
  const modal = import_modal.default.open({
131
131
  // title: '测试',
132
132
  maskClosable: true,
133
- bodyStyle: modalBodyStyle || {
133
+ bodyStyle: {
134
134
  width: (openFunction == null ? void 0 : openFunction.viewSize) || 800,
135
135
  padding: 0,
136
136
  height: "100%",
137
137
  overflow: "hidden"
138
138
  },
139
- style: modalStyle || {
139
+ style: {
140
140
  // top: 50,
141
141
  },
142
142
  contentStyle: {
@@ -158,7 +158,19 @@ var src_default = (props) => {
158
158
  function defaultIcon() {
159
159
  return /* @__PURE__ */ import_react.default.createElement("div", { type: "picture", style: { width: 18, height: 18, marginRight: 10, display: "inline-block" } });
160
160
  }
161
- const menu = /* @__PURE__ */ import_react.default.createElement(import_menu.default, null, (_a = appConfig == null ? void 0 : appConfig.openFunctions) == null ? void 0 : _a.map((openFunction) => /* @__PURE__ */ import_react.default.createElement(import_menu.default.Item, { onClick: () => openModal(openFunction) }, openFunction.icon ? /* @__PURE__ */ import_react.default.createElement("img", { style: { width: 18, height: 18, marginRight: 10 }, src: `${apiHost}/hfle/yqc/v1/0/files/download-by-key?fileKey=${openFunction.icon}`, alt: "" }) : defaultIcon(), openFunction.displayName)));
161
+ const menu = /* @__PURE__ */ import_react.default.createElement(import_menu.default, null, (_a = appConfig == null ? void 0 : appConfig.openFunctions) == null ? void 0 : _a.map((openFunction) => {
162
+ if (openFunction.enabledFlag) {
163
+ return /* @__PURE__ */ import_react.default.createElement(import_menu.default.Item, { onClick: () => openModal(openFunction), key: openFunction.id }, openFunction.icon ? /* @__PURE__ */ import_react.default.createElement(
164
+ "img",
165
+ {
166
+ style: { width: 18, height: 18, marginRight: 10 },
167
+ src: `${apiHost}/hfle/yqc/v1/0/files/download-by-key?fileKey=${openFunction.icon}`,
168
+ alt: ""
169
+ }
170
+ ) : defaultIcon(), openFunction.displayName);
171
+ }
172
+ return null;
173
+ }));
162
174
  const onlyOneButton = /* @__PURE__ */ import_react.default.createElement("div", { className: "yq-hzero-jssdk-btn", style: { padding: 0 }, onClick: () => openModal(appConfig == null ? void 0 : appConfig.openFunctions[0]) }, appConfig.icon ? /* @__PURE__ */ import_react.default.createElement("img", { style: { width: 18, height: 18, marginRight: 10 }, src: `${apiHost}/hfle/yqc/v1/0/files/download-by-key?fileKey=${appConfig.icon}`, alt: "" }) : /* @__PURE__ */ import_react.default.createElement("div", { type: "picture", style: { width: 18, height: 18, marginRight: 10, display: "inline-block" } }), (entryDetail == null ? void 0 : entryDetail.entryName) || (appConfig == null ? void 0 : appConfig.displayName) || (appConfig == null ? void 0 : appConfig.name));
163
175
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "yqcloud-hzero-jssdk", ref: eleRef }, ((_b = appConfig == null ? void 0 : appConfig.openFunctions) == null ? void 0 : _b.length) === 1 ? onlyOneButton : /* @__PURE__ */ import_react.default.createElement(import_popover.default, { overlayClassName: "yqcloud-hzero-jssdk-popover", overlayStyle: { padding: 0 }, openClassName: "yqcloud-hzero-jssdk-popover", content: menu, placement: "left" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "yq-hzero-jssdk-btn", style: { padding: 0 } }, appConfig.icon ? /* @__PURE__ */ import_react.default.createElement("img", { style: { width: 18, height: 18, marginRight: 10 }, src: `${apiHost}/hfle/yqc/v1/0/files/download-by-key?fileKey=${appConfig.icon}`, alt: "" }) : /* @__PURE__ */ import_react.default.createElement("div", { type: "picture", style: { width: 18, height: 18, marginRight: 10, display: "inline-block" } }), (entryDetail == null ? void 0 : entryDetail.entryName) || (appConfig == null ? void 0 : appConfig.displayName) || (appConfig == null ? void 0 : appConfig.name))));
164
176
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hzerojs-plugin-yqcloud-jssdk",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "main": "lib/index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -15,6 +15,7 @@
15
15
  },
16
16
  "files": [
17
17
  "lib",
18
- "browsers"
18
+ "browsers",
19
+ "src"
19
20
  ]
20
21
  }
package/src/index.css ADDED
@@ -0,0 +1,14 @@
1
+ .yqcloud-hzero-jssdk-popover .c7n-popover-inner-content{
2
+ padding: 0;
3
+ }
4
+ .yq-hzero-jssdk-btn:hover {
5
+ color: #0840f8;
6
+ }
7
+ .yq-hzero-jssdk-btn {
8
+ font-size: 13px;
9
+ color: #0f1358;
10
+ cursor: pointer;
11
+ }
12
+ .yqcloud-hzero-jssdk-popover.c7n-popover.c7n-popover .c7n-popover-content .c7n-popover-inner .c7n-popover-inner-content {
13
+ padding: 0;
14
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,184 @@
1
+ import React, {useEffect} from 'react';
2
+ import Modal from 'choerodon-ui/pro/es/modal';
3
+ import Menu from 'choerodon-ui/pro/es/menu';
4
+ import Popover from 'choerodon-ui/es/popover';
5
+ import axios from 'axios';
6
+ const YQ_API_HOST = 'https://api.test.yqcloud.com';
7
+ import './index.css';
8
+ // const TOKEN = '10ef346d-85fc-423a-9995-08731db60ba5';
9
+ export default (props) => {
10
+ const { token, entryDetail, apiHost = YQ_API_HOST, tokenPath = '/iam/v1/zknow/encrypt/quick' } = props;
11
+ const eleRef = React.useRef( null);
12
+ const tenantIdRef = React.useRef(null);
13
+ const [appConfig, setAppConfig] = React.useState(false);
14
+ const [isVisible, setIsVisble] = React.useState(false);
15
+ React.useEffect(() => {
16
+ let observer: any = null;
17
+ if (eleRef.current && 'IntersectionObserver' in window &&
18
+ 'IntersectionObserverEntry' in window &&
19
+ 'intersectionRatio' in window.IntersectionObserverEntry.prototype) {
20
+ observer = new IntersectionObserver(entries => {
21
+ if (entries[0].intersectionRatio === 1 ) {
22
+ setIsVisble(true);
23
+ // console.log('进入可视区域');
24
+ // do something
25
+ } else {
26
+ setIsVisble(false);
27
+ // console.log('移出可视区域');
28
+ // do something
29
+ }
30
+ });
31
+
32
+ observer.observe(eleRef.current);
33
+ }
34
+ return () => {
35
+ if(observer) {
36
+ observer.disconnect();
37
+ }
38
+ };
39
+ }, []);
40
+ React.useEffect(() => {
41
+ if(isVisible) {
42
+ console.log('悬浮窗展开了');
43
+ } else {
44
+ console.log('悬浮窗收起了');
45
+ }
46
+ }, [isVisible]);
47
+
48
+ async function yqRequest(url: string, method: string, data?: any) {
49
+ return new Promise<any>((resolve) => {
50
+ const xhr = new XMLHttpRequest();
51
+ xhr.withCredentials = false;
52
+
53
+ xhr.addEventListener('readystatechange', function () {
54
+ if (xhr.readyState === 4) {
55
+ try {
56
+ const res = JSON.parse(xhr.responseText);
57
+ resolve(res);
58
+ } catch (e) {
59
+ resolve(xhr.responseText);
60
+ // console.log('【YQCloud】xhr请求解析失败:', e, xhr.responseText);
61
+ }
62
+ }
63
+ });
64
+ xhr.open(
65
+ method,
66
+ url
67
+ );
68
+ xhr.setRequestHeader('Accept', 'application/json');
69
+ xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
70
+ if (tenantIdRef.current) {
71
+ xhr.setRequestHeader('x-tenant-id', tenantIdRef.current);
72
+ }
73
+ xhr.send(JSON.stringify(data));
74
+ });
75
+ }
76
+
77
+ useEffect(() => {
78
+ const url = `${apiHost}/iam/yqc/open_apps/quick/${token}`;
79
+
80
+ yqRequest(url, 'GET').then(function(jsonData) {
81
+ try {
82
+ if (jsonData && jsonData.failed) {
83
+ console.log('【YQCloud】:', jsonData.message);
84
+ } else {
85
+ const appConfig = JSON.parse(jsonData.jsonConfig);
86
+ tenantIdRef.current = jsonData.tenantId;
87
+ setAppConfig(appConfig);
88
+ console.log('【YQCloud】解析配置成功:', appConfig);
89
+ // document.body.appendChild(component(appConfig));
90
+ }
91
+ } catch (e) {
92
+ console.log('【YQCloud】解析配置失败:', e);
93
+ }
94
+ });
95
+ }, [isVisible]);
96
+ const openModal = async (openFunction) => {
97
+
98
+ const secret = await axios.get(tokenPath || '/iam/v1/zknow/encrypt/quick');
99
+ const authUrl = `${apiHost}/oauth/public/quick_authentication?token=${token}`;
100
+ const res = await yqRequest(authUrl, 'POST',{
101
+ secret,
102
+ // code,
103
+ });
104
+
105
+ const authParam = `&redirectFlag&access_token=${res.accessToken}&token_type=bearer&state=&expires_in=86399&scope=default`;
106
+ // fields default value, ex: '{userName:"yqcloud"}'
107
+ const fieldData = sessionStorage.getItem('YQ_FIELD_DATA');
108
+ let urlParam = authParam;
109
+ if (fieldData) {
110
+ urlParam = `&fieldData=${fieldData}${authParam}`;
111
+ }
112
+
113
+ const modal = Modal.open({
114
+ // title: '测试',
115
+ maskClosable: true,
116
+ bodyStyle: {
117
+ width: openFunction?.viewSize || 800,
118
+ padding: 0,
119
+ height: '100%',
120
+ overflow: 'hidden'
121
+ },
122
+ style: {
123
+ // top: 50,
124
+ },
125
+ contentStyle: {
126
+ width: openFunction?.viewSize || 800,
127
+ height: 'calc(100vh - 100px)'
128
+ },
129
+ header: null,
130
+ children: (
131
+ <iframe id="yq-sdk-frame" style={{ width: '100%', height: '100%'}} src={`${openFunction.link}${urlParam}`} frameBorder="0"></iframe>
132
+ ),
133
+ footer: null,
134
+ });
135
+ function closeModal(e) {
136
+ if (e.data === 'yq_close_modal') {
137
+ modal.close();
138
+ window.removeEventListener('message', closeModal);
139
+ }
140
+ }
141
+ window.addEventListener('message', closeModal);
142
+ };
143
+ function defaultIcon() {
144
+ return <div type="picture" style={{width: 18, height: 18, marginRight: 10, display: 'inline-block'}} />;
145
+ }
146
+ const menu = (
147
+ <Menu>
148
+ {appConfig?.openFunctions?.map((openFunction) => {
149
+ if (openFunction.enabledFlag) {
150
+ return (
151
+ <Menu.Item onClick={() => openModal(openFunction)} key={openFunction.id}>
152
+ {openFunction.icon ? <img
153
+ style={{width: 18, height: 18, marginRight: 10}}
154
+ src={`${apiHost}/hfle/yqc/v1/0/files/download-by-key?fileKey=${openFunction.icon}`}
155
+ alt=""/> : defaultIcon()}
156
+ {openFunction.displayName}
157
+ </Menu.Item>
158
+ );
159
+ }
160
+ return null;
161
+ })}
162
+ </Menu>
163
+ );
164
+
165
+ const onlyOneButton = (
166
+ <div className="yq-hzero-jssdk-btn" style={{ padding: 0 }} onClick={() => openModal(appConfig?.openFunctions[0])}>
167
+ {appConfig.icon ? <img style={{width: 18, height: 18, marginRight: 10}} src={`${apiHost}/hfle/yqc/v1/0/files/download-by-key?fileKey=${appConfig.icon}`} alt=""/> : <div type="picture" style={{width: 18, height: 18, marginRight: 10, display: 'inline-block'}} />}
168
+ {entryDetail?.entryName || appConfig?.displayName || appConfig?.name}
169
+ </div>
170
+ );
171
+
172
+ return (
173
+ <div className="yqcloud-hzero-jssdk" ref={eleRef}>
174
+ {appConfig?.openFunctions?.length === 1 ? onlyOneButton : (
175
+ <Popover overlayClassName="yqcloud-hzero-jssdk-popover" overlayStyle={{ padding: 0 }} openClassName="yqcloud-hzero-jssdk-popover" content={menu} placement="left">
176
+ <div className="yq-hzero-jssdk-btn" style={{ padding: 0 }}>
177
+ {appConfig.icon ? <img style={{width: 18, height: 18, marginRight: 10}} src={`${apiHost}/hfle/yqc/v1/0/files/download-by-key?fileKey=${appConfig.icon}`} alt=""/> : <div type="picture" style={{width: 18, height: 18, marginRight: 10, display: 'inline-block'}} />}
178
+ {entryDetail?.entryName || appConfig?.displayName || appConfig?.name}
179
+ </div>
180
+ </Popover>
181
+ )}
182
+ </div>
183
+ );
184
+ };
package/src/util.ts ADDED
@@ -0,0 +1,4 @@
1
+
2
+ export function sayHello() {
3
+ console.log('Hello World.')
4
+ }