12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- // Import the core alova instance
- import { BASE_URL } from "@/config";
- import alovaInstance from "./core/instance";
- // Export the global Apis object from the generated code
- import { createApis, withConfigType } from "./createApis";
- // Export the alova instance for direct use if needed
- export { alovaInstance };
- // Configure method options for specific APIs
- export const $$userConfigMap = withConfigType({});
- // Create the global Apis object
- const Apis = createApis(alovaInstance, $$userConfigMap);
- // Export both default and named export for AutoImport
- export default Apis;
- export { Apis };
- type Data<T> = {
- code: number;
- message: string;
- result: T;
- };
- export function uploadFile<T>(options: UniApp.UploadFileOption) {
- uni.showLoading({ title: "上传中...", mask: true });
- return new Promise<Data<T>>((resolve, reject) => {
- uni.uploadFile({
- url: BASE_URL + options.url,
- filePath: options.filePath,
- name: "file",
- method: "POST",
- header: {
- "Content-Type": "multipart/form-data",
- "X-Access-Token": useUserStore().token,
- },
- success(res) {
- uni.hideLoading();
- resolve(JSON.parse(res.data));
- },
- fail(err) {
- uni.hideLoading();
- reject(err);
- uni.showToast({ title: err.errMsg, icon: "none" });
- },
- });
- });
- }
|