@cpzxrobot/sdk 1.1.87 → 1.1.89

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
@@ -91,28 +91,32 @@ class Cpzxrobot {
91
91
  instance.getAndPreview = instance.getAndSave;
92
92
  // @ts-ignore
93
93
  instance.upload = (url, option) => {
94
- //add a file button to the body
95
- var button = document.createElement("input");
96
- button.type = "file";
97
- button.style.display = "none";
98
- document.body.appendChild(button);
99
- button.onclick = (e) => {
100
- var _a;
101
- var file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
102
- if (file) {
103
- const formData = new FormData();
104
- formData.append((option === null || option === void 0 ? void 0 : option["fileField"]) || "file", file);
105
- for (let key in option === null || option === void 0 ? void 0 : option["data"]) {
106
- formData.append(key, option["data"][key]);
94
+ return new Promise((resolve, reject) => {
95
+ //add a file button to the body
96
+ var button = document.createElement("input");
97
+ button.type = "file";
98
+ button.style.display = "none";
99
+ document.body.appendChild(button);
100
+ button.onclick = (e) => {
101
+ var _a;
102
+ var file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
103
+ if (file) {
104
+ const formData = new FormData();
105
+ formData.append((option === null || option === void 0 ? void 0 : option["fileField"]) || "file", file);
106
+ for (let key in option === null || option === void 0 ? void 0 : option["data"]) {
107
+ formData.append(key, option["data"][key]);
108
+ }
109
+ instance.post(url, formData).then((res) => {
110
+ button.remove();
111
+ resolve(res);
112
+ });
107
113
  }
108
- instance.post(url, formData).then((res) => {
114
+ else {
109
115
  button.remove();
110
- });
111
- }
112
- else {
113
- button.remove();
114
- }
115
- };
116
+ resolve({ data: { Error: "没有选择文件" } });
117
+ }
118
+ };
119
+ });
116
120
  };
117
121
  // @ts-ignore
118
122
  this.axios = instance;
@@ -76,10 +76,10 @@ class TransportGateway extends Object {
76
76
  });
77
77
  });
78
78
  },
79
- addImage: () => {
79
+ addImage: (args) => {
80
80
  return this.context.ready.then(() => {
81
81
  return this.context.axios
82
- .upload("/api/v2/pigfarm/feedTower/fodder/photo/add")
82
+ .upload("/api/v2/pigfarm/feedTower/fodder/photo/add", args)
83
83
  .then((res) => {
84
84
  if (res.data.code != 200) {
85
85
  throw res.data.message;
package/index.ts CHANGED
@@ -127,7 +127,8 @@ export class Cpzxrobot {
127
127
  instance.upload = (url: string, option?: {
128
128
  [key: string]: any;
129
129
  }) => {
130
- //add a file button to the body
130
+ return new Promise<any>((resolve, reject)=>{
131
+ //add a file button to the body
131
132
  var button = document.createElement("input");
132
133
  button.type = "file";
133
134
  button.style.display = "none";
@@ -142,11 +143,14 @@ export class Cpzxrobot {
142
143
  }
143
144
  instance.post(url, formData).then((res) => {
144
145
  button.remove();
146
+ resolve(res);
145
147
  });
146
148
  } else {
147
149
  button.remove();
150
+ resolve({data:{Error:"没有选择文件"}})
148
151
  }
149
152
  };
153
+ })
150
154
  }
151
155
  // @ts-ignore
152
156
  this.axios = instance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cpzxrobot/sdk",
3
- "version": "1.1.87",
3
+ "version": "1.1.89",
4
4
  "description": "提供给上海正芯数智APP第三方H5应用使用的SDK",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -87,10 +87,10 @@ export class TransportGateway extends Object {
87
87
  });
88
88
  });
89
89
  },
90
- addImage: () => {
90
+ addImage: (args: any) => {
91
91
  return this.context.ready.then(() => {
92
92
  return this.context.axios
93
- .upload("/api/v2/pigfarm/feedTower/fodder/photo/add")
93
+ .upload("/api/v2/pigfarm/feedTower/fodder/photo/add",args)
94
94
  .then((res) => {
95
95
  if (res.data.code != 200) {
96
96
  throw res.data.message;