@cpzxrobot/sdk 1.0.28 → 1.0.30
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/dist/index.js +41 -23
- package/index.ts +41 -26
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -148,8 +148,14 @@ class Cpzxrobot {
|
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
|
-
else
|
|
152
|
-
this.
|
|
151
|
+
else {
|
|
152
|
+
if (this.isLocalDomain(domain)) {
|
|
153
|
+
this.mode = "dev";
|
|
154
|
+
console.log("欢迎使用上海正诚物联网IOT系统,您当前是开发环境,请在平台获取开发用jwt key,并传入devAuth设置");
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
this.mode = "miniapp_in_web";
|
|
158
|
+
}
|
|
153
159
|
this.setTitle = function (title) {
|
|
154
160
|
document.title = title;
|
|
155
161
|
};
|
|
@@ -175,10 +181,6 @@ class Cpzxrobot {
|
|
|
175
181
|
URL.revokeObjectURL(url);
|
|
176
182
|
document.body.removeChild(a);
|
|
177
183
|
};
|
|
178
|
-
console.log("欢迎使用上海正诚物联网IOT系统,您当前是开发环境,请在平台获取开发用jwt key,并传入devAuth设置");
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
this.mode = "miniapp_in_web";
|
|
182
184
|
}
|
|
183
185
|
}
|
|
184
186
|
isIosMiniApp(location) {
|
|
@@ -211,26 +213,42 @@ class Cpzxrobot {
|
|
|
211
213
|
});
|
|
212
214
|
return;
|
|
213
215
|
}
|
|
214
|
-
this.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (res.data.Error) {
|
|
223
|
-
throw res.data.Error;
|
|
216
|
+
else if (this.mode === "miniapp_in_web") {
|
|
217
|
+
//if localstorage has token, use it
|
|
218
|
+
const token = localStorage.getItem("token");
|
|
219
|
+
if (token) {
|
|
220
|
+
this.token = token;
|
|
221
|
+
this.initAxios(baseURL);
|
|
222
|
+
this.resolveReady(this.axios);
|
|
223
|
+
return;
|
|
224
224
|
}
|
|
225
225
|
else {
|
|
226
|
-
|
|
226
|
+
//jump to miniapp login page
|
|
227
|
+
window.location.href = "https:///login.html";
|
|
227
228
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
.
|
|
231
|
-
|
|
232
|
-
this.
|
|
233
|
-
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
this.initAxios(baseURL);
|
|
232
|
+
this.auth = auth;
|
|
233
|
+
this.axios
|
|
234
|
+
.post("/api/v1/user/auth", {
|
|
235
|
+
appCode: this.appCode,
|
|
236
|
+
auth: auth,
|
|
237
|
+
})
|
|
238
|
+
.then((res) => {
|
|
239
|
+
if (res.data.Error) {
|
|
240
|
+
throw res.data.Error;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
this.token = "Bearer " + res.data.token;
|
|
244
|
+
}
|
|
245
|
+
this.resolveReady(this.axios);
|
|
246
|
+
})
|
|
247
|
+
.catch((err) => {
|
|
248
|
+
console.log("shzx ready caller reject", err);
|
|
249
|
+
this.rejectReady(err);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
234
252
|
}
|
|
235
253
|
isLocalDomain(domain) {
|
|
236
254
|
// 列出所有的本地开发域名
|
package/index.ts
CHANGED
|
@@ -179,8 +179,15 @@ export class Cpzxrobot {
|
|
|
179
179
|
}, 1500);
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
|
-
} else
|
|
183
|
-
this.
|
|
182
|
+
} else {
|
|
183
|
+
if (this.isLocalDomain(domain)) {
|
|
184
|
+
this.mode = "dev";
|
|
185
|
+
console.log(
|
|
186
|
+
"欢迎使用上海正诚物联网IOT系统,您当前是开发环境,请在平台获取开发用jwt key,并传入devAuth设置"
|
|
187
|
+
);
|
|
188
|
+
} else {
|
|
189
|
+
this.mode = "miniapp_in_web";
|
|
190
|
+
}
|
|
184
191
|
this.setTitle = function (title: string) {
|
|
185
192
|
document.title = title;
|
|
186
193
|
};
|
|
@@ -206,11 +213,6 @@ export class Cpzxrobot {
|
|
|
206
213
|
URL.revokeObjectURL(url);
|
|
207
214
|
document.body.removeChild(a);
|
|
208
215
|
};
|
|
209
|
-
console.log(
|
|
210
|
-
"欢迎使用上海正诚物联网IOT系统,您当前是开发环境,请在平台获取开发用jwt key,并传入devAuth设置"
|
|
211
|
-
);
|
|
212
|
-
} else {
|
|
213
|
-
this.mode = "miniapp_in_web";
|
|
214
216
|
}
|
|
215
217
|
}
|
|
216
218
|
isIosMiniApp(location: Location): boolean {
|
|
@@ -246,26 +248,39 @@ export class Cpzxrobot {
|
|
|
246
248
|
this.resolveReady(this.axios);
|
|
247
249
|
});
|
|
248
250
|
return;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
auth: auth,
|
|
256
|
-
})
|
|
257
|
-
.then((res) => {
|
|
258
|
-
if (res.data.Error) {
|
|
259
|
-
throw res.data.Error;
|
|
260
|
-
} else {
|
|
261
|
-
this.token = "Bearer " + res.data.token;
|
|
262
|
-
}
|
|
251
|
+
} else if (this.mode === "miniapp_in_web") {
|
|
252
|
+
//if localstorage has token, use it
|
|
253
|
+
const token = localStorage.getItem("token");
|
|
254
|
+
if (token) {
|
|
255
|
+
this.token = token;
|
|
256
|
+
this.initAxios(baseURL);
|
|
263
257
|
this.resolveReady(this.axios);
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
258
|
+
return;
|
|
259
|
+
} else {
|
|
260
|
+
//jump to miniapp login page
|
|
261
|
+
window.location.href = "https:///login.html";
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
this.initAxios(baseURL);
|
|
265
|
+
this.auth = auth;
|
|
266
|
+
this.axios
|
|
267
|
+
.post("/api/v1/user/auth", {
|
|
268
|
+
appCode: this.appCode,
|
|
269
|
+
auth: auth,
|
|
270
|
+
})
|
|
271
|
+
.then((res) => {
|
|
272
|
+
if (res.data.Error) {
|
|
273
|
+
throw res.data.Error;
|
|
274
|
+
} else {
|
|
275
|
+
this.token = "Bearer " + res.data.token;
|
|
276
|
+
}
|
|
277
|
+
this.resolveReady(this.axios);
|
|
278
|
+
})
|
|
279
|
+
.catch((err) => {
|
|
280
|
+
console.log("shzx ready caller reject", err);
|
|
281
|
+
this.rejectReady(err);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
269
284
|
}
|
|
270
285
|
|
|
271
286
|
isLocalDomain(domain: string): boolean {
|