@cpzxrobot/sdk 1.0.0 → 1.0.3
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 +8 -7
- package/index.ts +8 -6
- package/package.json +1 -1
- package/readme.md +92 -0
package/dist/index.js
CHANGED
|
@@ -48,10 +48,10 @@ class shzx {
|
|
|
48
48
|
inApp() {
|
|
49
49
|
return this.mode === "miniapp_in_app";
|
|
50
50
|
}
|
|
51
|
-
initAxios() {
|
|
51
|
+
initAxios(baseURL) {
|
|
52
52
|
if (this.mode !== "miniapp_in_app") {
|
|
53
53
|
const instance = axios_1.default.create({
|
|
54
|
-
baseURL
|
|
54
|
+
baseURL,
|
|
55
55
|
});
|
|
56
56
|
instance.interceptors.request.use((config) => {
|
|
57
57
|
// 在发送请求之前在头部添加token
|
|
@@ -126,7 +126,7 @@ class shzx {
|
|
|
126
126
|
this.setTitle = function (title) {
|
|
127
127
|
document.title = title;
|
|
128
128
|
};
|
|
129
|
-
console.log("
|
|
129
|
+
console.log("欢迎使用上海正诚物联网IOT系统,您当前是开发环境,请在平台获取开发用jwt key,并传入devAuth设置");
|
|
130
130
|
}
|
|
131
131
|
else {
|
|
132
132
|
this.mode = "miniapp_in_web";
|
|
@@ -149,16 +149,16 @@ class shzx {
|
|
|
149
149
|
openMiniApp(url) {
|
|
150
150
|
this._jumpToMiniApp(url);
|
|
151
151
|
}
|
|
152
|
-
setAuth(auth) {
|
|
152
|
+
setAuth(auth, baseURL) {
|
|
153
153
|
if (this.mode === "miniapp_in_app") {
|
|
154
154
|
this.platformReady.then(() => {
|
|
155
|
-
this.initAxios();
|
|
155
|
+
this.initAxios(baseURL);
|
|
156
156
|
console.log("shzx is ready");
|
|
157
157
|
this.resolveReady(this.axios);
|
|
158
158
|
});
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
|
-
this.initAxios();
|
|
161
|
+
this.initAxios(baseURL);
|
|
162
162
|
this.auth = auth;
|
|
163
163
|
this.axios
|
|
164
164
|
.post("/api/v1/user/auth", {
|
|
@@ -190,6 +190,7 @@ let _instance;
|
|
|
190
190
|
function default_1(args = {
|
|
191
191
|
devAuth: "",
|
|
192
192
|
appCode: "",
|
|
193
|
+
baseURL: "https://www.cpzxrobot.com/",
|
|
193
194
|
selectedFarm: {
|
|
194
195
|
id: 0,
|
|
195
196
|
code: "",
|
|
@@ -203,7 +204,7 @@ function default_1(args = {
|
|
|
203
204
|
}) {
|
|
204
205
|
if (!_instance) {
|
|
205
206
|
_instance = new shzx(args.appCode);
|
|
206
|
-
_instance.setAuth(args.devAuth);
|
|
207
|
+
_instance.setAuth(args.devAuth, args.baseURL);
|
|
207
208
|
if (args.selectedFarm) {
|
|
208
209
|
_instance.user.selectedFarm = args.selectedFarm;
|
|
209
210
|
}
|
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,95 @@
|
|
|
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
|
+
|
|
68
|
+
### 工厂信息接口
|
|
69
|
+
|
|
70
|
+
#### cpzxrobot().factory.workshops(factory_id)
|
|
71
|
+
|
|
72
|
+
获得工厂的所有车间
|
|
73
|
+
|
|
74
|
+
入参:
|
|
75
|
+
|
|
76
|
+
factory_id: 工厂id
|
|
77
|
+
|
|
78
|
+
#### cpzxrobot().factory.units(factory_id)
|
|
79
|
+
|
|
80
|
+
获得工厂的所有单元
|
|
81
|
+
|
|
82
|
+
入参:
|
|
83
|
+
|
|
84
|
+
factory_id: 工厂id
|
|
85
|
+
|
|
86
|
+
### 摄像头相关
|
|
87
|
+
|
|
88
|
+
cpzxrobot().camera.search(args)
|
|
89
|
+
|
|
90
|
+
搜索摄像头
|
|
91
|
+
|
|
92
|
+
入参:
|
|
93
|
+
|
|
94
|
+
入参为json object,可接受多种参数中的一个
|
|
95
|
+
|
|
96
|
+
如果入参为:{unit_id:xxx}则按单元搜索
|
|
97
|
+
|
|
98
|
+
如果入参为:{factory_id:xxx}则按工厂搜索
|