@cpzxrobot/sdk 1.0.0 → 1.0.1
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/index.ts +8 -6
- package/package.json +1 -1
- package/readme.md +61 -0
package/index.ts
CHANGED
|
@@ -65,10 +65,10 @@ class shzx {
|
|
|
65
65
|
return this.mode === "miniapp_in_app";
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
initAxios() {
|
|
68
|
+
initAxios(baseURL:string) {
|
|
69
69
|
if (this.mode !== "miniapp_in_app") {
|
|
70
70
|
const instance = axios.create({
|
|
71
|
-
baseURL
|
|
71
|
+
baseURL,
|
|
72
72
|
});
|
|
73
73
|
instance.interceptors.request.use(
|
|
74
74
|
(config) => {
|
|
@@ -181,16 +181,16 @@ class shzx {
|
|
|
181
181
|
this._jumpToMiniApp(url);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
setAuth(auth: string) {
|
|
184
|
+
setAuth(auth: string,baseURL:string) {
|
|
185
185
|
if (this.mode === "miniapp_in_app") {
|
|
186
186
|
this.platformReady.then(() => {
|
|
187
|
-
this.initAxios();
|
|
187
|
+
this.initAxios(baseURL);
|
|
188
188
|
console.log("shzx is ready");
|
|
189
189
|
this.resolveReady(this.axios);
|
|
190
190
|
});
|
|
191
191
|
return;
|
|
192
192
|
}
|
|
193
|
-
this.initAxios();
|
|
193
|
+
this.initAxios(baseURL);
|
|
194
194
|
this.auth = auth;
|
|
195
195
|
this.axios
|
|
196
196
|
.post("/api/v1/user/auth", {
|
|
@@ -225,12 +225,14 @@ let _instance!: shzx;
|
|
|
225
225
|
export default function (
|
|
226
226
|
args: {
|
|
227
227
|
devAuth: string;
|
|
228
|
+
baseURL: string;
|
|
228
229
|
appCode: string;
|
|
229
230
|
selectedFarm: Factory;
|
|
230
231
|
selectedUnit: Unit;
|
|
231
232
|
} = {
|
|
232
233
|
devAuth: "",
|
|
233
234
|
appCode: "",
|
|
235
|
+
baseURL: "https://www.cpzxrobot.com/",
|
|
234
236
|
selectedFarm: {
|
|
235
237
|
id: 0,
|
|
236
238
|
code: "",
|
|
@@ -245,7 +247,7 @@ export default function (
|
|
|
245
247
|
): shzx {
|
|
246
248
|
if (!_instance) {
|
|
247
249
|
_instance = new shzx(args.appCode);
|
|
248
|
-
_instance.setAuth(args.devAuth);
|
|
250
|
+
_instance.setAuth(args.devAuth,args.baseURL);
|
|
249
251
|
if (args.selectedFarm) {
|
|
250
252
|
_instance.user.selectedFarm = args.selectedFarm;
|
|
251
253
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -4,3 +4,64 @@
|
|
|
4
4
|
|
|
5
5
|
## 使用方式
|
|
6
6
|
|
|
7
|
+
```
|
|
8
|
+
npm i @cpzxrobot/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 开发指南
|
|
12
|
+
|
|
13
|
+
### 引入包
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
import cpzxrobot from "@cpzxrobot/sdk"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 配置开发信息
|
|
20
|
+
```
|
|
21
|
+
cpzxrobot({
|
|
22
|
+
devAuth: "从上海正芯获得的开发临时token",
|
|
23
|
+
appCode: "上海正芯分配的App Code",
|
|
24
|
+
selectedFarm: {
|
|
25
|
+
code: "xxxx",
|
|
26
|
+
company_code: "xxxx",
|
|
27
|
+
id: 123456,
|
|
28
|
+
name: "自定义用户测试的工厂,请从后台根据业务选择合适的工厂",
|
|
29
|
+
},
|
|
30
|
+
selectedUnit: {
|
|
31
|
+
id: 123456,
|
|
32
|
+
name: "自定义用户测试的单元,请从后台根据业务选择合适的单元",
|
|
33
|
+
workshopName: 'A栋'
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
使用上述模板进行sdk初始化
|
|
39
|
+
|
|
40
|
+
#### 开发时的CORS问题
|
|
41
|
+
|
|
42
|
+
如果上述配置后,出现调用接口CORS问题,请在初始化增加参数:
|
|
43
|
+
```
|
|
44
|
+
baseURL: "/"
|
|
45
|
+
```
|
|
46
|
+
并在vite.config.js等开发环境配置文件中配置:
|
|
47
|
+
```
|
|
48
|
+
server: {
|
|
49
|
+
proxy: {
|
|
50
|
+
"/api": {
|
|
51
|
+
target: "https://www.cpzxrobot.com/",
|
|
52
|
+
changeOrigin: true,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 调用接口
|
|
59
|
+
|
|
60
|
+
主要包入口:
|
|
61
|
+
|
|
62
|
+
| 调用入口 | 功能说明 |
|
|
63
|
+
| ----------------------- | -------------------- |
|
|
64
|
+
| cpzxrobot().factory.xxx | 获得工厂的相关信息 |
|
|
65
|
+
| cpzxrobot().device.xxx | 获得设备的相关信息 |
|
|
66
|
+
| cpzxrobot().camera.xxx | 获得摄像头的相关信息 |
|
|
67
|
+
|