ソースを参照

使用枚举定义类型

zhusiqing 4 年 前
コミット
65814d35f3
2 ファイル変更9 行追加9 行削除
  1. 4 3
      src/services/document.ts
  2. 5 6
      src/utils/mapping.ts

+ 4 - 3
src/services/document.ts

@@ -1,7 +1,7 @@
 import { Context } from 'koa';
 import { InterfaceResponseData } from '@utils/response';
 import { InterfaceDocument, InterfacePage, InterfaceTag, InterfaceDocumentList } from '@/controllers/document';
-import { CODE, decipher, cipher, mapDocMethod } from '@/utils';
+import { CODE, decipher, cipher, MapDocMethod } from '@/utils';
 
 const putDocument = async (ctx: Context, params: InterfaceDocument) :Promise<InterfaceResponseData> => {
   const reData: InterfaceResponseData = {
@@ -72,7 +72,7 @@ const getDocument = async (ctx: Context, id: string) :Promise<InterfaceResponseD
         return;
       };
       findDoc._id = id;
-      findDoc.method_des = mapDocMethod[findDoc.method];
+      findDoc.method_des = MapDocMethod[findDoc.method];
       reData.data = findDoc;
       reData.message = '成功';
       reData.success = true;
@@ -99,7 +99,8 @@ const getDocumentList = async (ctx: Context, params: InterfaceDocumentList) :Pro
         };
         docs.forEach(el => {
           el._id = cipher(el._id);
-          el.method_des = mapDocMethod[el.method];
+          el.method_des = MapDocMethod[el.method];
+          console.log(MapDocMethod[el.method]);
         });
         reData.data = docs;
         reData.message = '成功';

+ 5 - 6
src/utils/mapping.ts

@@ -1,7 +1,6 @@
-export const mapDocMethod = {
-  [1]: 'GET',
-  [2]: 'POST',
-  [3]: 'PUT',
-  [4]: 'DELETE'
+export enum MapDocMethod {
+  GET = 1,
+  POST,
+  PUT,
+  DELETE
 }
-