用户 / 订单 / 商品 管理

This commit is contained in:
zk
2026-07-10 15:27:16 +08:00
parent 20ab909329
commit bcdd1419e5
11 changed files with 462 additions and 19 deletions
+12 -6
View File
@@ -24,12 +24,18 @@ const request = (() => {
return Promise.reject('未登录');
}
const result = await response.json();
// 解析响应体
let result;
try { result = await response.json(); } catch (e) {
const msg = 'HTTP ' + response.status + ' 请求失败';
ElementPlus ? ElementPlus.ElMessage.error(msg) : alert(msg);
return Promise.reject(msg);
}
// 业务异常
if (result.status !== 200) {
const msg = result.message || '请求失败';
alert(msg);
// 业务异常code 不为 "0" 表示失败
if (result.code !== '0') {
const msg = result.msg || '请求失败';
ElementPlus ? ElementPlus.ElMessage.error(msg) : alert(msg);
return Promise.reject(msg);
}
@@ -42,7 +48,7 @@ const request = (() => {
return http(url + query, { method: 'GET' });
},
post(url, data) {
return http(url, { method: 'POST', body: JSON.stringify(data) });
return http(url, { method: 'POST', body: data != null ? JSON.stringify(data) : undefined });
},
put(url, data) {
return http(url, { method: 'PUT', body: JSON.stringify(data) });