chore: sync pending workspace updates
This commit is contained in:
@@ -157,8 +157,8 @@ function pickerText(options: Array<{ label?: string; name?: string }>, index: nu
|
||||
function validateForm() {
|
||||
const product = form.value.product_info;
|
||||
const address = form.value.return_address;
|
||||
if (!product.category_id || !product.brand_id || !product.product_name.trim()) {
|
||||
showInfoToast("请完整填写品类、品牌和商品名称");
|
||||
if (!product.category_id || !product.brand_id) {
|
||||
showInfoToast("请完整填写品类和品牌");
|
||||
return false;
|
||||
}
|
||||
if (!address.consignee.trim() || !address.mobile.trim() || !address.province.trim() || !address.city.trim() || !address.district.trim() || !address.detail_address.trim()) {
|
||||
@@ -251,7 +251,7 @@ onLoad(() => {
|
||||
<picker :range="brandOptions" range-key="name" :value="brandIndex" @change="onBrandChange">
|
||||
<view class="field picker-field">{{ pickerText(brandOptions, brandIndex, "选择品牌") }}</view>
|
||||
</picker>
|
||||
<input v-model="form.product_info.product_name" class="field" placeholder="商品名称" />
|
||||
<input v-model="form.product_info.product_name" class="field" placeholder="商品名称,可选" />
|
||||
<input v-model="form.product_info.color" class="field" placeholder="颜色,可选" />
|
||||
<input v-model="form.product_info.size_spec" class="field" placeholder="规格 / 尺寸,可选" />
|
||||
<input v-model="form.product_info.serial_no" class="field" placeholder="序列号,可选" />
|
||||
|
||||
@@ -2,6 +2,7 @@ import { buildAuthHeaders, clearAdminSession, redirectToLogin } from "./auth";
|
||||
import { resolveApiBaseUrl } from "./env";
|
||||
|
||||
const BASE_URL = resolveApiBaseUrl().replace(/\/$/, "");
|
||||
const REQUEST_TIMEOUT_MS = 15000;
|
||||
|
||||
type RequestMethod = "GET" | "POST" | "PUT" | "DELETE" | "OPTIONS" | "HEAD";
|
||||
|
||||
@@ -22,6 +23,25 @@ function buildUrl(url: string, params?: Record<string, string | number | undefin
|
||||
return search ? `${BASE_URL}${url}?${search}` : `${BASE_URL}${url}`;
|
||||
}
|
||||
|
||||
function buildNetworkError(error: UniApp.GeneralCallbackResult, fallback = "网络请求失败,请稍后重试") {
|
||||
const errMsg = String(error.errMsg || "");
|
||||
const normalized = errMsg.toLowerCase();
|
||||
|
||||
if (normalized.includes("timeout") || errMsg.includes("超时")) {
|
||||
return new Error("连接服务器超时,请检查网络,或联系管理员确认 API 服务是否正常");
|
||||
}
|
||||
|
||||
if (normalized.includes("abort")) {
|
||||
return new Error("请求已取消");
|
||||
}
|
||||
|
||||
if (normalized.includes("fail") || normalized.includes("network") || normalized.includes("request")) {
|
||||
return new Error("无法连接服务器,请检查网络,或联系管理员确认 API 服务是否正常");
|
||||
}
|
||||
|
||||
return new Error(errMsg || fallback);
|
||||
}
|
||||
|
||||
export function request<T>(
|
||||
url: string,
|
||||
options: {
|
||||
@@ -42,6 +62,7 @@ export function request<T>(
|
||||
method,
|
||||
data: options.data,
|
||||
header: headers,
|
||||
timeout: REQUEST_TIMEOUT_MS,
|
||||
success: (response: UniApp.RequestSuccessCallbackResult) => {
|
||||
const payload = response.data as ApiResponse<T>;
|
||||
if (payload?.code === 0) {
|
||||
@@ -56,7 +77,7 @@ export function request<T>(
|
||||
}
|
||||
reject(new Error(payload?.message || "请求失败"));
|
||||
},
|
||||
fail: (error: UniApp.GeneralCallbackResult) => reject(error),
|
||||
fail: (error: UniApp.GeneralCallbackResult) => reject(buildNetworkError(error)),
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -103,7 +124,7 @@ export function uploadFile<T>(url: string, filePath: string, formData: Record<st
|
||||
reject(error);
|
||||
}
|
||||
},
|
||||
fail: (error) => reject(error),
|
||||
fail: (error) => reject(buildNetworkError(error)),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user