优化后,再次提交

This commit is contained in:
王利强
2026-05-03 09:08:56 +08:00
parent 721ef0ad54
commit 805747d1d9
1243 changed files with 46213 additions and 221 deletions

View File

@@ -5,6 +5,9 @@ import Request from './luch-request/index.js';
const baseUrl = 'https://yingji.hexieapi.com/prod-api';
// const baseUrl = 'http://192.168.1.168:5004';
// 图片/文件资源域名:去掉 /prod-api便于 <image> / previewImage / downloadFile 直接访问
const imageBaseUrl = baseUrl.replace(/\/prod-api\/?$/, '');
const http = new Request({
baseURL: baseUrl,
timeout: 10000
@@ -45,15 +48,17 @@ function showToast(title) {
// 请求
const requestAPI = (config) => {
// 支持对象参数或传统参数
let { url, method = 'GET', data = {}, noAuth = false } = typeof config === 'object' && config.url ? config : { url: config, method: arguments[1] || 'GET', data: arguments[2] || {} };
let { url, method = 'GET', data = {}, noAuth = false, loadingText } = typeof config === 'object' && config.url ? config : { url: config, method: arguments[1] || 'GET', data: arguments[2] || {} };
if (method == 'GET' && !isEmptyObject(data)) {
url += '?' + objectToQueryString(data);
}
// 显示加载状态
uni.showLoading({
title: '加载中...'
});
// 显示加载状态loadingText 为 false 时不显示)
if (loadingText !== false) {
uni.showLoading({
title: loadingText || '加载中...'
});
}
// 构建 header登录等接口不需要 Authorization
const header = {
@@ -130,4 +135,25 @@ const requestAPI = (config) => {
};
// 文件末尾应该导出
export { requestAPI, baseUrl, getToken };
export { requestAPI, baseUrl, getToken };
// 把附件 filePath 转成可用于图片预览/下载的 url
// filePath 可能是:
// 1) 绝对 http(s) 链接
// 2) 相对路径(以 / 开头)
// 3) 可能带 /prod-api 的拼接结果(兼容处理)
export const toImageUrl = (filePath) => {
if (!filePath) return '';
const p = String(filePath);
if (p.startsWith('http://') || p.startsWith('https://')) {
// 兼容:如果后端返回的是带 /prod-api 的资源地址,直接去掉
return p.replace(/\/prod-api(?=\/|$)/, '');
}
// 相对路径:统一拼到 imageBaseUrl 上
const normalized = p.startsWith('/') ? p : `/${p}`;
return imageBaseUrl + normalized;
};
export { imageBaseUrl };