|
@@ -1,12 +1,12 @@
|
|
|
// 基础服务 - 对应 supermart-mini/service/base.js
|
|
// 基础服务 - 对应 supermart-mini/service/base.js
|
|
|
-import { get, post } from './http';
|
|
|
|
|
|
|
+import { get, post } from "./http";
|
|
|
|
|
|
|
|
const apis = {
|
|
const apis = {
|
|
|
- PAGE_CONFIG: '/api/app/page/getByPageId',
|
|
|
|
|
- MESSAGE: '/api/app/message',
|
|
|
|
|
- TRACK: '/api/track',
|
|
|
|
|
- FEEDBACK: '/api/app/feedback/submit',
|
|
|
|
|
- PARAM_CONFIG: '/param/paramConfig',
|
|
|
|
|
|
|
+ PAGE_CONFIG: "/api/app/page/getByPageId",
|
|
|
|
|
+ MESSAGE: "/api/app/message",
|
|
|
|
|
+ TRACK: "/api/track",
|
|
|
|
|
+ FEEDBACK: "/api/app/feedback/submit",
|
|
|
|
|
+ PARAM_CONFIG: "/param/paramConfig",
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
export interface BannerItem {
|
|
export interface BannerItem {
|
|
@@ -28,13 +28,19 @@ export interface PageConfig {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 获取页面配置
|
|
// 获取页面配置
|
|
|
-export const getPageConfig = async (pageId: string): Promise<PageConfig | null> => {
|
|
|
|
|
|
|
+export const getPageConfig = async (
|
|
|
|
|
+ pageId: string,
|
|
|
|
|
+): Promise<PageConfig | null> => {
|
|
|
const res = await get<PageConfig>(apis.PAGE_CONFIG, { pageId });
|
|
const res = await get<PageConfig>(apis.PAGE_CONFIG, { pageId });
|
|
|
return res.data;
|
|
return res.data;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 获取消息列表
|
|
// 获取消息列表
|
|
|
-export const getMessages = async (current: number, size: number, type?: string) => {
|
|
|
|
|
|
|
+export const getMessages = async (
|
|
|
|
|
+ current: number,
|
|
|
|
|
+ size: number,
|
|
|
|
|
+ type?: string,
|
|
|
|
|
+) => {
|
|
|
const params: any = { current, size };
|
|
const params: any = { current, size };
|
|
|
if (type) params.type = type;
|
|
if (type) params.type = type;
|
|
|
const res = await get(apis.MESSAGE, params);
|
|
const res = await get(apis.MESSAGE, params);
|
|
@@ -42,7 +48,11 @@ export const getMessages = async (current: number, size: number, type?: string)
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 获取消息列表(分页)
|
|
// 获取消息列表(分页)
|
|
|
-export const getMessageList = async (current: number, size: number, type?: string) => {
|
|
|
|
|
|
|
+export const getMessageList = async (
|
|
|
|
|
+ current: number,
|
|
|
|
|
+ size: number,
|
|
|
|
|
+ type?: string,
|
|
|
|
|
+) => {
|
|
|
const params: any = { current, size };
|
|
const params: any = { current, size };
|
|
|
if (type) params.type = type;
|
|
if (type) params.type = type;
|
|
|
const res = await get(apis.MESSAGE, params);
|
|
const res = await get(apis.MESSAGE, params);
|
|
@@ -67,6 +77,67 @@ export const track = async () => {
|
|
|
return res.data;
|
|
return res.data;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+// 上传文件
|
|
|
|
|
+export const uploadFile = async (
|
|
|
|
|
+ fileUri: string,
|
|
|
|
|
+ folder = "avatar",
|
|
|
|
|
+): Promise<string | null> => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
|
+
|
|
|
|
|
+ // 获取文件名
|
|
|
|
|
+ const fileName = fileUri.split("/").pop() || "image.jpg";
|
|
|
|
|
+
|
|
|
|
|
+ // 创建文件对象 (React Native 格式)
|
|
|
|
|
+ const fileObj = {
|
|
|
|
|
+ uri: fileUri,
|
|
|
|
|
+ type: "image/jpeg",
|
|
|
|
|
+ name: fileName,
|
|
|
|
|
+ } as any;
|
|
|
|
|
+
|
|
|
|
|
+ formData.append("file", fileObj);
|
|
|
|
|
+ formData.append("appId", "supermart-acetoys");
|
|
|
|
|
+ formData.append("folder", folder);
|
|
|
|
|
+
|
|
|
|
|
+ // 使用http.ts中的getToken获取token
|
|
|
|
|
+ const { getToken } = require("./http");
|
|
|
|
|
+ const token = getToken();
|
|
|
|
|
+
|
|
|
|
|
+ const response = await fetch("https://mm.acefig.com/api/oss/file/upload", {
|
|
|
|
|
+ method: "POST",
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ // 不设置 Content-Type,让 fetch 自动处理 multipart/form-data 边界
|
|
|
|
|
+ Authentication: token || "",
|
|
|
|
|
+ },
|
|
|
|
|
+ body: formData,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 检查响应状态
|
|
|
|
|
+ if (!response.ok) {
|
|
|
|
|
+ const errorText = await response.text();
|
|
|
|
|
+ console.error("上传响应状态:", response.status, "响应内容:", errorText);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const text = await response.text();
|
|
|
|
|
+ if (!text) {
|
|
|
|
|
+ console.error("上传响应为空");
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const result = JSON.parse(text);
|
|
|
|
|
+ // code 可能是数字或字符串
|
|
|
|
|
+ if ((result.code === 0 || result.code === "0") && result.data?.url) {
|
|
|
|
|
+ return result.data.url;
|
|
|
|
|
+ }
|
|
|
|
|
+ console.error("上传返回错误:", result);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error("上传文件失败:", error);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
export default {
|
|
export default {
|
|
|
getPageConfig,
|
|
getPageConfig,
|
|
|
getMessages,
|
|
getMessages,
|
|
@@ -74,4 +145,5 @@ export default {
|
|
|
getParamConfig,
|
|
getParamConfig,
|
|
|
submitFeedback,
|
|
submitFeedback,
|
|
|
track,
|
|
track,
|
|
|
|
|
+ uploadFile,
|
|
|
};
|
|
};
|