@cpzxrobot/sdk 1.2.76 → 1.2.78

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 CHANGED
@@ -108,27 +108,31 @@ class Cpzxrobot {
108
108
  }
109
109
  return response;
110
110
  };
111
+ const processQueryParams = (url, config) => {
112
+ if (config && config.params) {
113
+ const flattenParams = (params, prefix = '') => {
114
+ const result = {};
115
+ Object.keys(params).forEach(key => {
116
+ const value = params[key];
117
+ const fullKey = prefix ? `${prefix}[${key}]` : key;
118
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
119
+ Object.assign(result, flattenParams(value, fullKey));
120
+ }
121
+ else if (value) {
122
+ result[fullKey] = value.toString();
123
+ }
124
+ });
125
+ return result;
126
+ };
127
+ const flattened = flattenParams(config.params);
128
+ url += "?" + new URLSearchParams(flattened).toString();
129
+ delete config.params;
130
+ }
131
+ return url;
132
+ };
111
133
  const instance = {
112
134
  get: async (url, config) => {
113
- if (config && config.params) {
114
- const flattenParams = (params, prefix = '') => {
115
- const result = {};
116
- Object.keys(params).forEach(key => {
117
- const value = params[key];
118
- const fullKey = prefix ? `${prefix}[${key}]` : key;
119
- if (value && typeof value === 'object' && !Array.isArray(value)) {
120
- Object.assign(result, flattenParams(value, fullKey));
121
- }
122
- else if (value) {
123
- result[fullKey] = value.toString();
124
- }
125
- });
126
- return result;
127
- };
128
- const flattened = flattenParams(config.params);
129
- url += "?" + new URLSearchParams(flattened).toString();
130
- delete config.params;
131
- }
135
+ url = processQueryParams(url, config);
132
136
  const response = await fetchWithAuth(url, {
133
137
  method: 'GET',
134
138
  headers: config === null || config === void 0 ? void 0 : config.headers
@@ -144,6 +148,7 @@ class Cpzxrobot {
144
148
  return { data: await response.json() };
145
149
  },
146
150
  getAndSave: async (url, config, fileName) => {
151
+ url = processQueryParams(url, config);
147
152
  const response = await fetchWithAuth(url, {
148
153
  method: 'GET',
149
154
  headers: config === null || config === void 0 ? void 0 : config.headers
@@ -153,6 +158,7 @@ class Cpzxrobot {
153
158
  return { data: blob };
154
159
  },
155
160
  getAndPreview: async (url, config, fileName) => {
161
+ url = processQueryParams(url, config);
156
162
  return instance.getAndSave(url, config, fileName);
157
163
  },
158
164
  upload: async (url, option) => {
@@ -160,13 +166,21 @@ class Cpzxrobot {
160
166
  const button = document.createElement("input");
161
167
  button.type = "file";
162
168
  button.style.display = "none";
169
+ button.multiple = (option === null || option === void 0 ? void 0 : option.multiple) || false;
163
170
  document.body.appendChild(button);
164
- button.onclick = async (e) => {
165
- var _a;
166
- const file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
167
- if (file) {
171
+ button.click(); // 手动触发点击
172
+ button.onchange = async (e) => {
173
+ const files = e.target.files;
174
+ if (files && files.length > 0) {
168
175
  const formData = new FormData();
169
- formData.append((option === null || option === void 0 ? void 0 : option["fileField"]) || "file", file);
176
+ if (option === null || option === void 0 ? void 0 : option.multiple) {
177
+ for (let i = 0; i < files.length; i++) {
178
+ formData.append("files[]", files[i]);
179
+ }
180
+ }
181
+ else {
182
+ formData.append((option === null || option === void 0 ? void 0 : option["fileField"]) || "file", files[0]);
183
+ }
170
184
  for (let key in option === null || option === void 0 ? void 0 : option["data"]) {
171
185
  formData.append(key, option["data"][key]);
172
186
  }
@@ -106,7 +106,7 @@ class ProjectGateway extends Object {
106
106
  // 上传项目文档
107
107
  upload: (args) => {
108
108
  return this.context.ready.then((axios) => {
109
- return axios.post(`/api/v2/coremde-sale/project/document/upload`, args);
109
+ return axios.upload(`/api/v2/coremde-sale/project/document/upload`, args);
110
110
  });
111
111
  },
112
112
  // 预览项目文档
@@ -13,7 +13,7 @@ class QuotationGateway extends Object {
13
13
  }
14
14
  add(args) {
15
15
  return this.context.ready.then((axios) => {
16
- return axios.upload(`/api/v2/coremde-sale/quotation/add`, args);
16
+ return axios.post(`/api/v2/coremde-sale/quotation/add`, args);
17
17
  });
18
18
  }
19
19
  get(id) {
@@ -126,6 +126,16 @@ class UserGateway extends Object {
126
126
  }
127
127
  async mypermission(params = undefined) {
128
128
  var axios = await this.context.ready;
129
+ var factory = await this.context.user.getSelectedFarm();
130
+ var args;
131
+ if (params) {
132
+ args = Object.assign(Object.assign({}, params), { factoryId: factory.id });
133
+ }
134
+ else {
135
+ args = {
136
+ factoryId: factory.id
137
+ };
138
+ }
129
139
  return axios.get("/api/v2/user/role/mypermission", {
130
140
  params
131
141
  });
package/index.ts CHANGED
@@ -127,27 +127,32 @@ export class Cpzxrobot {
127
127
  return response;
128
128
  };
129
129
 
130
+ const processQueryParams = (url: string, config?: any) => {
131
+ if (config && config.params) {
132
+ const flattenParams = (params: any, prefix = '') => {
133
+ const result: Record<string, string> = {};
134
+ Object.keys(params).forEach(key => {
135
+ const value = params[key];
136
+ const fullKey = prefix ? `${prefix}[${key}]` : key;
137
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
138
+ Object.assign(result, flattenParams(value, fullKey));
139
+ } else if (value) {
140
+ result[fullKey] = value.toString();
141
+ }
142
+ });
143
+ return result;
144
+ };
145
+ const flattened = flattenParams(config.params);
146
+ url += "?" + new URLSearchParams(flattened).toString();
147
+ delete config.params;
148
+ }
149
+ return url;
150
+ }
151
+
130
152
  const instance = {
131
- get: async (url: string, config?: any) => {
132
- if (config && config.params) {
133
- const flattenParams = (params: any, prefix = '') => {
134
- const result: Record<string, string> = {};
135
- Object.keys(params).forEach(key => {
136
- const value = params[key];
137
- const fullKey = prefix ? `${prefix}[${key}]` : key;
138
- if (value && typeof value === 'object' && !Array.isArray(value)) {
139
- Object.assign(result, flattenParams(value, fullKey));
140
- } else if(value){
141
- result[fullKey] = value.toString();
142
- }
143
- });
144
- return result;
145
- };
146
153
 
147
- const flattened = flattenParams(config.params);
148
- url += "?" + new URLSearchParams(flattened).toString();
149
- delete config.params;
150
- }
154
+ get: async (url: string, config?: any) => {
155
+ url = processQueryParams(url, config);
151
156
  const response = await fetchWithAuth(url, {
152
157
  method: 'GET',
153
158
  headers: config?.headers
@@ -166,6 +171,7 @@ export class Cpzxrobot {
166
171
  return { data: await response.json() };
167
172
  },
168
173
  getAndSave: async (url: string, config?: any, fileName?: string) => {
174
+ url = processQueryParams(url, config);
169
175
  const response = await fetchWithAuth(url, {
170
176
  method: 'GET',
171
177
  headers: config?.headers
@@ -175,6 +181,7 @@ export class Cpzxrobot {
175
181
  return { data: blob };
176
182
  },
177
183
  getAndPreview: async (url: string, config?: any, fileName?: string) => {
184
+ url = processQueryParams(url, config);
178
185
  return instance.getAndSave(url, config, fileName);
179
186
  },
180
187
  upload: async (url: string, option?: any) => {
@@ -182,12 +189,20 @@ export class Cpzxrobot {
182
189
  const button = document.createElement("input");
183
190
  button.type = "file";
184
191
  button.style.display = "none";
192
+ button.multiple = option?.multiple || false;
185
193
  document.body.appendChild(button);
186
- button.onclick = async (e: Event) => {
187
- const file = (e.target as HTMLInputElement).files?.[0];
188
- if (file) {
194
+ button.click(); // 手动触发点击
195
+ button.onchange = async (e: Event) => {
196
+ const files = (e.target as HTMLInputElement).files;
197
+ if (files && files.length > 0) {
189
198
  const formData = new FormData();
190
- formData.append(option?.["fileField"] || "file", file);
199
+ if (option?.multiple) {
200
+ for (let i = 0; i < files.length; i++) {
201
+ formData.append("files[]", files[i]);
202
+ }
203
+ } else {
204
+ formData.append(option?.["fileField"] || "file", files[0]);
205
+ }
191
206
  for (let key in option?.["data"]) {
192
207
  formData.append(key, option!["data"][key]);
193
208
  }
@@ -308,8 +323,8 @@ export class Cpzxrobot {
308
323
  this.vibrate = function (time?: number) {
309
324
  return platform.callHandler("app.vibrate", time);
310
325
  };
311
- this.showInDeviceManager = function (deviceId: number,type:string) {
312
- return platform.callHandler("app.showInDeviceManager", deviceId,type);
326
+ this.showInDeviceManager = function (deviceId: number, type: string) {
327
+ return platform.callHandler("app.showInDeviceManager", deviceId, type);
313
328
  };
314
329
  this.reloadGroup = function (group: string) {
315
330
  return platform.callHandler("app.reloadGroup", group);
@@ -437,7 +452,7 @@ export class Cpzxrobot {
437
452
  }
438
453
  });
439
454
  };
440
- this.showInDeviceManager = function (deviceId: number,type: string) {
455
+ this.showInDeviceManager = function (deviceId: number, type: string) {
441
456
  return this.axios.get(`/api/v1/${type}/share/` + deviceId);
442
457
  };
443
458
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.2.76",
3
+ "version": "1.2.78",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -146,7 +146,7 @@ export class ProjectGateway extends Object {
146
146
  fileType: "base-info" | "inquiry" | "contract";
147
147
  }) => {
148
148
  return this.context.ready.then((axios) => {
149
- return axios.post(`/api/v2/coremde-sale/project/document/upload`, args);
149
+ return axios.upload(`/api/v2/coremde-sale/project/document/upload`, args);
150
150
  });
151
151
  },
152
152
  // 预览项目文档
@@ -22,7 +22,7 @@ export class QuotationGateway extends Object {
22
22
 
23
23
  add(args: any) {
24
24
  return this.context.ready.then((axios) => {
25
- return axios.upload(`/api/v2/coremde-sale/quotation/add`, args);
25
+ return axios.post(`/api/v2/coremde-sale/quotation/add`, args);
26
26
  });
27
27
  }
28
28
 
package/user_gateway.ts CHANGED
@@ -139,6 +139,21 @@ export class UserGateway extends Object {
139
139
 
140
140
  async mypermission(params: any = undefined) {
141
141
  var axios = await this.context.ready;
142
+ var factory = await this.context.user.getSelectedFarm();
143
+ var args: {
144
+ factoryId: number;
145
+ [key: string]: any;
146
+ }
147
+ if (params) {
148
+ args = {
149
+ ...params,
150
+ factoryId: factory.id
151
+ }
152
+ }else{
153
+ args = {
154
+ factoryId: factory.id
155
+ };
156
+ }
142
157
  return axios.get("/api/v2/user/role/mypermission", {
143
158
  params
144
159
  });