shaogen1995 1 неделя назад
Родитель
Сommit
4b1c85417f

+ 4 - 4
src/pages/Dmanage/D1register/D1edit/index.tsx

@@ -1,10 +1,10 @@
-import React, { useCallback, useEffect, useRef, useState } from 'react'
+import React, { useCallback, useEffect, useState } from 'react'
 import styles from './index.module.scss'
-import { D1_APIcreate, D1_APIgetInfo } from '@/store/action/Dmanage/D1register'
 import EditTop from '@/pages/Zother/EditTop'
 import EditBtn from '@/pages/Zother/EditBtn'
 import { rowArrTemp, TypeD1table } from '../data'
 import { useParams } from 'react-router-dom'
+import { D1API_obj } from '@/store/action/Dmanage/D1register'
 
 const rowArr = rowArrTemp('登记')
 
@@ -22,7 +22,7 @@ function D1edit() {
 
   // 创建订单
   const createFu = useCallback(async () => {
-    const res = await D1_APIcreate()
+    const res = await D1API_obj['创建订单']()
     if (res.code === 0) {
       setInfo(res.data)
       setBenPow(res.data)
@@ -31,7 +31,7 @@ function D1edit() {
 
   // 获取详情
   const getInfoFu = useCallback(async (id: number) => {
-    const res = await D1_APIgetInfo(id)
+    const res = await D1API_obj['获取详情'](id)
     if (res.code === 0) {
       setInfo(res.data)
       setBenPow(res.data)

+ 6 - 14
src/store/action/Dmanage/D1register.ts

@@ -1,5 +1,6 @@
 import { AppDispatch } from '@/store'
 import http from '@/utils/http'
+import { APIbase } from '../layout'
 
 /**
  * 藏品登记 -获取分页列表
@@ -18,23 +19,14 @@ export const D1_APIgetList = (data: any): any => {
   }
 }
 
+export const D1API_obj = {
+  创建订单: () => APIbase('get', 'cms/order/register/create'),
+  获取详情: (id: number) => APIbase('get', `cms/order/register/detail/${id}`)
+}
+
 /**
  * 藏品登记-删除
  */
 export const D1_APIdel = (id: number) => {
   return http.get(`cms/order/register/remove/${id}`)
 }
-
-/**
- * 藏品登记-创建订单
- */
-export const D1_APIcreate = () => {
-  return http.get(`cms/order/register/create`)
-}
-
-/**
- * 藏品登记-获取详情
- */
-export const D1_APIgetInfo = (id: number) => {
-  return http.get(`cms/order/register/detail/${id}`)
-}

+ 6 - 0
src/store/action/layout.ts

@@ -47,3 +47,9 @@ export const API_upFile = (data: any, url: string) => {
     })
   })
 }
+
+// 直接封装api通用方法
+export const APIbase = (fa: 'get' | 'post', url: string, can?: any) => {
+  if (fa === 'get') return http.get(url)
+  else return http.post(url, can)
+}