@ebiz/designer-components 0.1.97 → 0.1.98
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.mjs +19 -8
- package/package.json +1 -1
- package/src/apiService/simpleDataService.js +129 -116
package/dist/index.mjs
CHANGED
|
@@ -50159,10 +50159,15 @@ sx.interceptors.request.use(
|
|
|
50159
50159
|
sx.interceptors.response.use(
|
|
50160
50160
|
(e) => {
|
|
50161
50161
|
const { data: t } = e;
|
|
50162
|
-
|
|
50163
|
-
|
|
50164
|
-
|
|
50165
|
-
|
|
50162
|
+
if (t.code === void 0)
|
|
50163
|
+
return t;
|
|
50164
|
+
if (t.code === 0)
|
|
50165
|
+
return t.data;
|
|
50166
|
+
if (t.code < 0)
|
|
50167
|
+
return Promise.reject({
|
|
50168
|
+
code: t.code,
|
|
50169
|
+
message: t.message || t.msg || "请求失败"
|
|
50170
|
+
});
|
|
50166
50171
|
},
|
|
50167
50172
|
(e) => {
|
|
50168
50173
|
if (e.response) {
|
|
@@ -50182,7 +50187,7 @@ let hP = {
|
|
|
50182
50187
|
7: "/appdata/delData",
|
|
50183
50188
|
8: "/appdata/delDatas",
|
|
50184
50189
|
9: "/appdata/link/select",
|
|
50185
|
-
10: "/
|
|
50190
|
+
10: "/app/td-upload",
|
|
50186
50191
|
// 文件上传API
|
|
50187
50192
|
MULTIPLE_DATA_SEARCH: "/appdata/select",
|
|
50188
50193
|
DETAILS_DATA: "/appdata/detailData",
|
|
@@ -50194,7 +50199,7 @@ let hP = {
|
|
|
50194
50199
|
DEL_DATA: "/appdata/delData",
|
|
50195
50200
|
BATCH_DEL_DATA: "/appdata/delDatas",
|
|
50196
50201
|
MULTIPLE_DATA_LINK_SEARCH: "/appdata/link/select",
|
|
50197
|
-
FILE_UPLOAD: "/file/upload",
|
|
50202
|
+
FILE_UPLOAD: "/file/app/td-upload",
|
|
50198
50203
|
// 文件上传API
|
|
50199
50204
|
PROCESS: "/appdata/process"
|
|
50200
50205
|
};
|
|
@@ -50241,7 +50246,9 @@ const en = {
|
|
|
50241
50246
|
u instanceof File || u instanceof Blob ? (console.log(`Found file in field ${l}, adding as 'file'`), r.append("file", u), a = !0) : r.append(l, u);
|
|
50242
50247
|
}
|
|
50243
50248
|
else
|
|
50244
|
-
console.log(
|
|
50249
|
+
console.log(
|
|
50250
|
+
"FormData.entries() not supported, using original FormData"
|
|
50251
|
+
), r = t, a = !0;
|
|
50245
50252
|
} catch (i) {
|
|
50246
50253
|
console.error("Error processing FormData:", i), r = t;
|
|
50247
50254
|
}
|
|
@@ -50257,7 +50264,9 @@ const en = {
|
|
|
50257
50264
|
"Content-Type": void 0
|
|
50258
50265
|
},
|
|
50259
50266
|
onUploadProgress: (i) => {
|
|
50260
|
-
const l = Math.round(
|
|
50267
|
+
const l = Math.round(
|
|
50268
|
+
i.loaded * 100 / i.total
|
|
50269
|
+
);
|
|
50261
50270
|
n(l);
|
|
50262
50271
|
}
|
|
50263
50272
|
};
|
|
@@ -50267,6 +50276,8 @@ const en = {
|
|
|
50267
50276
|
return console.log("Converted file path to full URL:", s), s;
|
|
50268
50277
|
}
|
|
50269
50278
|
return i;
|
|
50279
|
+
}).catch((i) => {
|
|
50280
|
+
console.log("上传失败:", i);
|
|
50270
50281
|
});
|
|
50271
50282
|
}
|
|
50272
50283
|
}, A3e = {
|
package/package.json
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* 所有接口均使用POST方法提交
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import axios from
|
|
7
|
+
import axios from "axios";
|
|
8
8
|
// import { TinyNotify } from '@opentiny/vue'
|
|
9
9
|
// 从环境变量获取API基础URL
|
|
10
|
-
const API_BASE_URL = window.location.origin +
|
|
10
|
+
const API_BASE_URL = window.location.origin + "/api";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* 创建axios实例
|
|
@@ -16,56 +16,58 @@ const axiosInstance = axios.create({
|
|
|
16
16
|
baseURL: API_BASE_URL,
|
|
17
17
|
timeout: 30000,
|
|
18
18
|
headers: {
|
|
19
|
-
|
|
20
|
-
Accept:
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
Accept: "application/json"
|
|
21
21
|
}
|
|
22
|
-
})
|
|
22
|
+
});
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* 请求拦截器
|
|
26
26
|
*/
|
|
27
27
|
axiosInstance.interceptors.request.use(
|
|
28
|
-
|
|
28
|
+
config => {
|
|
29
29
|
// 添加认证信息
|
|
30
|
-
const token = localStorage.getItem(
|
|
30
|
+
const token = localStorage.getItem("token");
|
|
31
31
|
if (token) {
|
|
32
|
-
config.headers[
|
|
32
|
+
config.headers["AppDataAuthorization"] = `Bearer ${token}`;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// 如果是FormData格式,不设置Content-Type,让浏览器自动设置
|
|
36
36
|
if (config.data instanceof FormData) {
|
|
37
|
-
config.headers[
|
|
37
|
+
config.headers["Content-Type"] = undefined;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
return config
|
|
40
|
+
return config;
|
|
41
41
|
},
|
|
42
|
-
|
|
43
|
-
return Promise.reject(error)
|
|
42
|
+
error => {
|
|
43
|
+
return Promise.reject(error);
|
|
44
44
|
}
|
|
45
|
-
)
|
|
45
|
+
);
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* 响应拦截器
|
|
49
49
|
*/
|
|
50
50
|
axiosInstance.interceptors.response.use(
|
|
51
|
-
|
|
52
|
-
const { data } = response
|
|
51
|
+
response => {
|
|
52
|
+
const { data } = response;
|
|
53
53
|
|
|
54
54
|
// 根据后端API的响应格式进行调整
|
|
55
|
-
if (data.code ===
|
|
56
|
-
return data
|
|
57
|
-
} else {
|
|
55
|
+
if (data.code === undefined) {
|
|
56
|
+
return data;
|
|
57
|
+
} else if (data.code === 0) {
|
|
58
|
+
return data.data;
|
|
59
|
+
} else if (data.code < 0) {
|
|
58
60
|
// message.error(data.message || '请求失败');
|
|
59
61
|
return Promise.reject({
|
|
60
62
|
code: data.code,
|
|
61
|
-
message: data.message || data.msg ||
|
|
62
|
-
})
|
|
63
|
+
message: data.message || data.msg || "请求失败"
|
|
64
|
+
});
|
|
63
65
|
}
|
|
64
66
|
},
|
|
65
|
-
|
|
67
|
+
error => {
|
|
66
68
|
// 错误处理
|
|
67
69
|
if (error.response) {
|
|
68
|
-
const { status } = error.response
|
|
70
|
+
const { status } = error.response;
|
|
69
71
|
|
|
70
72
|
switch (status) {
|
|
71
73
|
case 401:
|
|
@@ -76,7 +78,7 @@ axiosInstance.interceptors.response.use(
|
|
|
76
78
|
// position: 'top-right',
|
|
77
79
|
// duration: 2000
|
|
78
80
|
// })
|
|
79
|
-
break
|
|
81
|
+
break;
|
|
80
82
|
case 403:
|
|
81
83
|
// TinyNotify({
|
|
82
84
|
// type: 'warning',
|
|
@@ -85,7 +87,7 @@ axiosInstance.interceptors.response.use(
|
|
|
85
87
|
// position: 'top-right',
|
|
86
88
|
// duration: 2000
|
|
87
89
|
// })
|
|
88
|
-
break
|
|
90
|
+
break;
|
|
89
91
|
case 404:
|
|
90
92
|
// TinyNotify({
|
|
91
93
|
// type: 'warning',
|
|
@@ -94,7 +96,7 @@ axiosInstance.interceptors.response.use(
|
|
|
94
96
|
// position: 'top-right',
|
|
95
97
|
// duration: 2000
|
|
96
98
|
// })
|
|
97
|
-
break
|
|
99
|
+
break;
|
|
98
100
|
case 500:
|
|
99
101
|
// TinyNotify({
|
|
100
102
|
// type: 'warning',
|
|
@@ -103,15 +105,15 @@ axiosInstance.interceptors.response.use(
|
|
|
103
105
|
// position: 'top-right',
|
|
104
106
|
// duration: 2000
|
|
105
107
|
// })
|
|
106
|
-
break
|
|
108
|
+
break;
|
|
107
109
|
default:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
// TinyNotify({
|
|
111
|
+
// type: 'warning',
|
|
112
|
+
// title: '请求失败',
|
|
113
|
+
// message: error.message,
|
|
114
|
+
// position: 'top-right',
|
|
115
|
+
// duration: 2000
|
|
116
|
+
// })
|
|
115
117
|
}
|
|
116
118
|
} else {
|
|
117
119
|
// TinyNotify({
|
|
@@ -124,36 +126,36 @@ axiosInstance.interceptors.response.use(
|
|
|
124
126
|
// message.error('网络错误,请检查您的网络连接');
|
|
125
127
|
}
|
|
126
128
|
|
|
127
|
-
return Promise.reject(error)
|
|
129
|
+
return Promise.reject(error);
|
|
128
130
|
}
|
|
129
|
-
)
|
|
131
|
+
);
|
|
130
132
|
|
|
131
133
|
let apiMap = {
|
|
132
|
-
"0":
|
|
133
|
-
"1":
|
|
134
|
-
"2":
|
|
135
|
-
"3":
|
|
136
|
-
"4":
|
|
137
|
-
"5":
|
|
138
|
-
"6":
|
|
139
|
-
"7":
|
|
140
|
-
"8":
|
|
141
|
-
"9":
|
|
142
|
-
"10":
|
|
134
|
+
"0": "/appdata/select",
|
|
135
|
+
"1": "/appdata/detailData",
|
|
136
|
+
"2": "/appdata/plugin",
|
|
137
|
+
"3": "/appdata/addData",
|
|
138
|
+
"4": "/appdata/addDatas",
|
|
139
|
+
"5": "/appdata/updateData",
|
|
140
|
+
"6": "/appdata/updateDatas",
|
|
141
|
+
"7": "/appdata/delData",
|
|
142
|
+
"8": "/appdata/delDatas",
|
|
143
|
+
"9": "/appdata/link/select",
|
|
144
|
+
"10": "/app/td-upload", // 文件上传API
|
|
143
145
|
|
|
144
|
-
MULTIPLE_DATA_SEARCH:
|
|
145
|
-
DETAILS_DATA:
|
|
146
|
-
INTERFACE_PLUGIN:
|
|
147
|
-
DATA_INSERT:
|
|
148
|
-
BATCH_DATA_INSERT:
|
|
149
|
-
DATA_MODIFY:
|
|
150
|
-
BATCH_DATA_MODIFY:
|
|
151
|
-
DEL_DATA:
|
|
152
|
-
BATCH_DEL_DATA:
|
|
153
|
-
MULTIPLE_DATA_LINK_SEARCH:
|
|
154
|
-
FILE_UPLOAD:
|
|
155
|
-
PROCESS:
|
|
156
|
-
}
|
|
146
|
+
MULTIPLE_DATA_SEARCH: "/appdata/select",
|
|
147
|
+
DETAILS_DATA: "/appdata/detailData",
|
|
148
|
+
INTERFACE_PLUGIN: "/appdata/plugin",
|
|
149
|
+
DATA_INSERT: "/appdata/addData",
|
|
150
|
+
BATCH_DATA_INSERT: "/appdata/addDatas",
|
|
151
|
+
DATA_MODIFY: "/appdata/updateData",
|
|
152
|
+
BATCH_DATA_MODIFY: "/appdata/updateDatas",
|
|
153
|
+
DEL_DATA: "/appdata/delData",
|
|
154
|
+
BATCH_DEL_DATA: "/appdata/delDatas",
|
|
155
|
+
MULTIPLE_DATA_LINK_SEARCH: "/appdata/link/select",
|
|
156
|
+
FILE_UPLOAD: "/file/app/td-upload", // 文件上传API
|
|
157
|
+
PROCESS: "/appdata/process"
|
|
158
|
+
};
|
|
157
159
|
|
|
158
160
|
/**
|
|
159
161
|
* 数据服务
|
|
@@ -169,36 +171,36 @@ const dataService = {
|
|
|
169
171
|
* @returns {Promise<any>} 响应数据
|
|
170
172
|
* @example
|
|
171
173
|
*/
|
|
172
|
-
fetch: (params = {}, apiConfig = {}, url =
|
|
174
|
+
fetch: (params = {}, apiConfig = {}, url = "") => {
|
|
173
175
|
if (!url) {
|
|
174
|
-
url = apiMap[apiConfig.apiType+
|
|
176
|
+
url = apiMap[apiConfig.apiType + ""];
|
|
175
177
|
if (!url) {
|
|
176
|
-
url = apiMap.PROCESS
|
|
178
|
+
url = apiMap.PROCESS;
|
|
177
179
|
}
|
|
178
|
-
url +=
|
|
180
|
+
url += "?key=" + apiConfig.key;
|
|
179
181
|
}
|
|
180
|
-
console.log(
|
|
182
|
+
console.log("apiConfig", apiConfig);
|
|
181
183
|
|
|
182
|
-
const { apiId =
|
|
184
|
+
const { apiId = "", ...restConfig } = apiConfig;
|
|
183
185
|
|
|
184
186
|
const defaultConfig = {
|
|
185
187
|
// 默认列表查询配置
|
|
186
188
|
headers: {
|
|
187
|
-
|
|
189
|
+
"X-List-Query": "true"
|
|
188
190
|
},
|
|
189
191
|
timeout: 20000
|
|
190
|
-
}
|
|
192
|
+
};
|
|
191
193
|
if (!params) {
|
|
192
|
-
params = {}
|
|
194
|
+
params = {};
|
|
193
195
|
}
|
|
194
|
-
params.apiId = apiConfig.apiId
|
|
196
|
+
params.apiId = apiConfig.apiId;
|
|
195
197
|
if (apiConfig.key) {
|
|
196
|
-
params.apiKey = apiConfig.key
|
|
198
|
+
params.apiKey = apiConfig.key;
|
|
197
199
|
}
|
|
198
|
-
console.log(
|
|
200
|
+
console.log("params", params);
|
|
199
201
|
|
|
200
|
-
const config = { ...defaultConfig, ...restConfig }
|
|
201
|
-
return axiosInstance.post(url, params, config)
|
|
202
|
+
const config = { ...defaultConfig, ...restConfig };
|
|
203
|
+
return axiosInstance.post(url, params, config);
|
|
202
204
|
},
|
|
203
205
|
|
|
204
206
|
/**
|
|
@@ -208,55 +210,57 @@ const dataService = {
|
|
|
208
210
|
* @param {Function} onProgress - 上传进度回调函数,参数为0-100的进度百分比
|
|
209
211
|
* @returns {Promise<any>} 上传响应数据
|
|
210
212
|
*/
|
|
211
|
-
upload: (url =
|
|
213
|
+
upload: (url = "", formData, onProgress = () => {}) => {
|
|
212
214
|
// 如果没有指定URL,使用默认的文件上传URL
|
|
213
215
|
if (!url) {
|
|
214
|
-
url = apiMap.FILE_UPLOAD
|
|
216
|
+
url = apiMap.FILE_UPLOAD;
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
// 确保FormData中的文件字段名是'file'
|
|
218
|
-
let fixedFormData = new FormData()
|
|
219
|
-
let fileFound = false
|
|
220
|
+
let fixedFormData = new FormData();
|
|
221
|
+
let fileFound = false;
|
|
220
222
|
|
|
221
223
|
// 检查并修复FormData
|
|
222
224
|
if (formData instanceof FormData) {
|
|
223
225
|
// 由于FormData不能直接检查内容,我们使用迭代器
|
|
224
226
|
try {
|
|
225
227
|
// 在某些旧浏览器中可能不支持entries()
|
|
226
|
-
if (typeof formData.entries ===
|
|
228
|
+
if (typeof formData.entries === "function") {
|
|
227
229
|
for (let pair of formData.entries()) {
|
|
228
|
-
const [key, value] = pair
|
|
230
|
+
const [key, value] = pair;
|
|
229
231
|
|
|
230
232
|
if (value instanceof File || value instanceof Blob) {
|
|
231
233
|
// 找到文件,使用正确的字段名
|
|
232
|
-
console.log(`Found file in field ${key}, adding as 'file'`)
|
|
233
|
-
fixedFormData.append(
|
|
234
|
-
fileFound = true
|
|
234
|
+
console.log(`Found file in field ${key}, adding as 'file'`);
|
|
235
|
+
fixedFormData.append("file", value);
|
|
236
|
+
fileFound = true;
|
|
235
237
|
} else {
|
|
236
238
|
// 保留其他字段
|
|
237
|
-
fixedFormData.append(key, value)
|
|
239
|
+
fixedFormData.append(key, value);
|
|
238
240
|
}
|
|
239
241
|
}
|
|
240
242
|
} else {
|
|
241
243
|
// 如果不支持entries(),假设formData已经是正确的,直接使用
|
|
242
|
-
console.log(
|
|
243
|
-
|
|
244
|
-
|
|
244
|
+
console.log(
|
|
245
|
+
"FormData.entries() not supported, using original FormData"
|
|
246
|
+
);
|
|
247
|
+
fixedFormData = formData;
|
|
248
|
+
fileFound = true;
|
|
245
249
|
}
|
|
246
250
|
} catch (e) {
|
|
247
|
-
console.error(
|
|
251
|
+
console.error("Error processing FormData:", e);
|
|
248
252
|
// 出错时使用原始FormData
|
|
249
|
-
fixedFormData = formData
|
|
253
|
+
fixedFormData = formData;
|
|
250
254
|
}
|
|
251
255
|
} else {
|
|
252
|
-
console.error(
|
|
253
|
-
return Promise.reject(new Error(
|
|
256
|
+
console.error("Invalid FormData:", formData);
|
|
257
|
+
return Promise.reject(new Error("FormData is required for file upload"));
|
|
254
258
|
}
|
|
255
259
|
|
|
256
260
|
// 如果没有找到文件,返回错误
|
|
257
|
-
if (!fileFound && typeof formData.entries ===
|
|
258
|
-
console.error(
|
|
259
|
-
return Promise.reject(new Error(
|
|
261
|
+
if (!fileFound && typeof formData.entries === "function") {
|
|
262
|
+
console.error("No file found in FormData");
|
|
263
|
+
return Promise.reject(new Error("No file found in FormData"));
|
|
260
264
|
}
|
|
261
265
|
|
|
262
266
|
// 上传配置
|
|
@@ -264,36 +268,45 @@ const dataService = {
|
|
|
264
268
|
timeout: 60000, // 上传超时时间加长
|
|
265
269
|
headers: {
|
|
266
270
|
// 让浏览器自动设置Content-Type和boundary
|
|
267
|
-
|
|
271
|
+
"Content-Type": undefined
|
|
268
272
|
},
|
|
269
|
-
onUploadProgress:
|
|
273
|
+
onUploadProgress: progressEvent => {
|
|
270
274
|
// 计算上传进度百分比
|
|
271
|
-
const percentCompleted = Math.round(
|
|
272
|
-
|
|
275
|
+
const percentCompleted = Math.round(
|
|
276
|
+
progressEvent.loaded * 100 / progressEvent.total
|
|
277
|
+
);
|
|
278
|
+
onProgress(percentCompleted);
|
|
273
279
|
}
|
|
274
|
-
}
|
|
280
|
+
};
|
|
275
281
|
|
|
276
282
|
// 发起上传请求
|
|
277
|
-
console.log(
|
|
278
|
-
return axiosInstance
|
|
279
|
-
|
|
283
|
+
console.log("Sending file upload request to:", url);
|
|
284
|
+
return axiosInstance
|
|
285
|
+
.post(url, fixedFormData, config)
|
|
286
|
+
.then(response => {
|
|
287
|
+
console.log("Upload server response:", response);
|
|
280
288
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
289
|
+
// 处理文件路径
|
|
290
|
+
// 如果返回的是相对路径,转换为完整URL
|
|
291
|
+
if (typeof response === "string" && !response.startsWith("http")) {
|
|
292
|
+
// 判断路径是否以斜杠开头
|
|
293
|
+
const baseUrl = API_BASE_URL.endsWith("/")
|
|
294
|
+
? API_BASE_URL.slice(0, -1)
|
|
295
|
+
: API_BASE_URL;
|
|
296
|
+
const filePath = response.startsWith("/") ? response : `/${response}`;
|
|
287
297
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
298
|
+
// 构建完整URL
|
|
299
|
+
const fullUrl = `${baseUrl}/files${filePath}`;
|
|
300
|
+
console.log("Converted file path to full URL:", fullUrl);
|
|
301
|
+
return fullUrl;
|
|
302
|
+
}
|
|
293
303
|
|
|
294
|
-
|
|
295
|
-
|
|
304
|
+
return response;
|
|
305
|
+
})
|
|
306
|
+
.catch(e => {
|
|
307
|
+
console.log("上传失败:", e);
|
|
308
|
+
});
|
|
296
309
|
}
|
|
297
|
-
}
|
|
310
|
+
};
|
|
298
311
|
|
|
299
|
-
export default dataService
|
|
312
|
+
export default dataService;
|