Explorar el Código

📦 修改细节完成

imengyu hace 1 mes
padre
commit
7e82df0831

+ 3 - 0
nuxt.config.ts

@@ -23,6 +23,9 @@ export default defineNuxtConfig({
       extensions: ['.vue'],
     }
   ],
+  build: {
+    transpile: ['@imengyu/vue-scroll-rect'],
+  },
   routeRules: {
     '/': { swr: 1/* 1800 */ },
     '/about/': { swr: 86400 },

+ 1 - 0
src/common/request/core/RequestCore.ts

@@ -6,6 +6,7 @@ import { defaultResponseDataHandler, defaultResponseErrorHandler } from './Reque
 import type { HeaderType, QueryParams, TypeSaveable } from '../utils/AllType';
 import type { KeyValue } from '@imengyu/js-request-transform/dist/DataUtils';
 import type { RequestImplementer } from './RequestImplementer';
+import { FormDataImpl } from '../utils/FormDataImpl';
 
 /**
  * API 请求核心

+ 3 - 2
src/common/request/implementer/WebFetch.ts

@@ -1,5 +1,6 @@
 import type { RequestCacheStorage, RequestOptions } from "../core/RequestCore";
 import type { RequestImplementer } from "../core/RequestImplementer";
+import { FormDataImpl } from '../utils/FormDataImpl';
 
 const fetchImplementer : RequestImplementer = {
   getCache: async function (key: string) {
@@ -20,8 +21,8 @@ const fetchImplementer : RequestImplementer = {
     }, timeout);
 
     let body : string|FormData|undefined;
-    if (init?.data instanceof FormData)
-      body = init.data; 
+    if (init?.data instanceof FormData) 
+      body = (init.data as any).isImplType ? (init.data as any as FormDataImpl).getData() : init.data; 
     else if (typeof init?.data === 'object') {
       body = JSON.stringify(init.data); 
     }

+ 92 - 0
src/common/request/utils/FormDataImpl.ts

@@ -0,0 +1,92 @@
+export class FormDataImpl {
+  private _data: Map<string, string | string[]>;
+
+  constructor() {
+    this._data = new Map<string, string | string[]>();
+  }
+
+  isImplType = true;
+
+  append(key: string, value: string) {
+    if (this._data.has(key)) {
+      const currentValue = this._data.get(key);
+      if (Array.isArray(currentValue)) {
+        this._data.set(key, [...currentValue, value]);
+      } else {
+        this._data.set(key, [currentValue ?? '', value]);
+      }
+    } else {
+      this._data.set(key, value);
+    }
+  }
+
+  get(key: string) {
+    return this._data.get(key);
+  }
+
+  getAll(key: string) {
+    return Array.isArray(this._data.get(key)) ? this._data.get(key) || [] : [this._data.get(key) || ''];
+  }
+
+  has(key: string) {
+    return this._data.has(key);
+  }
+
+  delete(key: string) {
+    this._data.delete(key);
+  }
+
+  keys() {
+    return Array.from(this._data.keys());
+  }
+
+  values() {
+    return Array.from(this._data.values());
+  }
+
+  entries() {
+    return Array.from(this._data.entries());
+  }
+
+  forEach(callback: (value: string | string[], key: string, map: Map<string, string | string[]>) => void, thisArg?: any) {
+    this._data.forEach(callback, thisArg);
+  }
+
+  toString() {
+    const pairs: string[] = [];
+    this._data.forEach((value, key) => {
+      if (Array.isArray(value)) {
+        value.forEach((v) => pairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(v)}`));
+      } else {
+        pairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
+      }
+    });
+    return pairs.join('&');
+  }
+
+  toBrowserFormData() {
+    if (typeof window !== 'undefined' && window.FormData) {
+      const browserFormData = new window.FormData();
+      this._data.forEach((value, key) => {
+        if (Array.isArray(value)) {
+          value.forEach((v) => browserFormData.append(key, v));
+        } else {
+          browserFormData.append(key, value);
+        }
+      });
+      return browserFormData;
+    } else {
+      throw new Error('Browser environment is required to use toBrowserFormData');
+    }
+  }
+
+  getData() {
+    const json = {} as Record<string, string|string[]>;
+    this._data.forEach((value, key) => json[key] = value);
+    return JSON.stringify(json);
+  }
+}
+
+//兼容SSR情况下的 NodeJs
+if (typeof FormData === 'undefined')
+  global.FormData = FormDataImpl as any;

+ 1 - 3
src/pages/fusion/index.vue

@@ -84,9 +84,7 @@ import ImageTitleDescBlock from '@/components/parts/ImageTitleDescBlock.vue';
 import ThreeImageList from '@/components/parts/ThreeImageList.vue';
 import CalendarContent from '@/api/fusion/CalendarContent';
 import { GetContentListItem, GetContentListParams } from '@/api/CommonContent';
-import VueScrollRect from '@imengyu/vue-scroll-rect';
-
-const { ScrollRect } = VueScrollRect
+import { ScrollRect } from '@imengyu/vue-scroll-rect';
 
 const router = useRouter();
 const carouselConfig = {

+ 1 - 3
src/pages/index.vue

@@ -238,7 +238,7 @@ import { useRouter } from 'vue-router';
 import { useSSrSimpleDataLoader } from '@/composeable/SimpleDataLoader';
 import { NO_CONTENT_STRING } from '@/common/ConstStrings';
 import { DataDateUtils } from '@imengyu/js-request-transform';
-import VueScrollRect from '@imengyu/vue-scroll-rect';
+import { ScrollRect } from '@imengyu/vue-scroll-rect';
 import ImageTitleBlock from '@/components/parts/ImageTitleBlock.vue';
 import SimplePageContentLoader from '@/components/content/SimplePageContentLoader.vue';
 import IndexContent from '@/api/introduction/IndexContent';
@@ -252,8 +252,6 @@ import ProjectsContent from '@/api/inheritor/ProjectsContent';
 import SeminarContent from '@/api/inheritor/SeminarContent';
 import CommonContent, { GetColumListParams, GetContentListParams, type GetContentListItem } from '@/api/CommonContent';
 
-const { ScrollRect } = VueScrollRect
-
 const router = useRouter();
 
 const carouselConfig = {