hzerojs-plugin-yqcloud-jssdk 1.0.8 → 1.0.10

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.
Files changed (2) hide show
  1. package/lib/index.js +38 -22
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -44,6 +44,7 @@ var src_default = (props) => {
44
44
  var _a, _b;
45
45
  const { token, entryDetail, apiHost = YQ_API_HOST, tokenPath = "/iam/v1/zknow/encrypt/quick" } = props;
46
46
  const eleRef = import_react.default.useRef(null);
47
+ const tenantIdRef = import_react.default.useRef(null);
47
48
  const [appConfig, setAppConfig] = import_react.default.useState(false);
48
49
  const [isVisible, setIsVisble] = import_react.default.useState(false);
49
50
  import_react.default.useEffect(() => {
@@ -71,37 +72,52 @@ var src_default = (props) => {
71
72
  console.log("悬浮窗收起了");
72
73
  }
73
74
  }, [isVisible]);
75
+ async function yqRequest(url, method, data) {
76
+ return new Promise((resolve) => {
77
+ const xhr = new XMLHttpRequest();
78
+ xhr.withCredentials = false;
79
+ xhr.addEventListener("readystatechange", function() {
80
+ if (xhr.readyState === 4) {
81
+ try {
82
+ const res = JSON.parse(xhr.responseText);
83
+ resolve(res);
84
+ } catch (e) {
85
+ resolve(xhr.responseText);
86
+ }
87
+ }
88
+ });
89
+ xhr.open(
90
+ method,
91
+ url
92
+ );
93
+ xhr.setRequestHeader("Accept", "application/json, text/plain, */*");
94
+ if (tenantIdRef.current) {
95
+ xhr.setRequestHeader("x-tenant-id", tenantIdRef.current);
96
+ }
97
+ xhr.send(data);
98
+ });
99
+ }
74
100
  (0, import_react.useEffect)(() => {
75
101
  const url = `${apiHost}/iam/yqc/open_apps/quick/${token}`;
76
- const xhr = new XMLHttpRequest();
77
- xhr.withCredentials = false;
78
- xhr.addEventListener("readystatechange", function() {
79
- if (xhr.readyState === 4) {
80
- const jsonData = JSON.parse(xhr.responseText);
81
- try {
82
- if (jsonData && jsonData.failed) {
83
- console.log("【YQCloud】:", jsonData.message);
84
- } else {
85
- const appConfig2 = JSON.parse(jsonData.jsonConfig);
86
- setAppConfig(appConfig2);
87
- console.log("【YQCloud】解析配置成功:", appConfig2);
88
- }
89
- } catch (e) {
90
- console.log("【YQCloud】解析配置失败:", e);
102
+ yqRequest(url, "GET").then(function(jsonData) {
103
+ try {
104
+ if (jsonData && jsonData.failed) {
105
+ console.log("【YQCloud】:", jsonData.message);
106
+ } else {
107
+ const appConfig2 = JSON.parse(jsonData.jsonConfig);
108
+ tenantIdRef.current = jsonData.tenantId;
109
+ setAppConfig(appConfig2);
110
+ console.log("【YQCloud】解析配置成功:", appConfig2);
91
111
  }
112
+ } catch (e) {
113
+ console.log("【YQCloud】解析配置失败:", e);
92
114
  }
93
115
  });
94
- xhr.open(
95
- "GET",
96
- url
97
- );
98
- xhr.setRequestHeader("Accept", "application/json, text/plain, */*");
99
- xhr.send();
100
116
  }, [isVisible]);
101
117
  const openModal = async (openFunction) => {
102
118
  const secret = await import_axios.default.get(tokenPath || "/iam/v1/zknow/encrypt/quick");
103
119
  const authUrl = `${apiHost}/oauth/public/quick_authentication?token=${token}`;
104
- const res = await import_axios.default.post(authUrl, {
120
+ const res = await yqRequest(authUrl, "POST", {
105
121
  secret
106
122
  // code,
107
123
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hzerojs-plugin-yqcloud-jssdk",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "main": "lib/index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {