hzerojs-plugin-yqcloud-jssdk 1.0.8 → 1.0.9

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