shaogen1995 3 hete
szülő
commit
619b623d7a

+ 11 - 8
src/pages/Dmanage/D1register/D1edit/index.tsx

@@ -5,6 +5,7 @@ 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'
+import { InfoProvider } from '@/pages/Zother/InfoContext'
 
 const rowArr = rowArrTemp('登记')
 
@@ -44,17 +45,19 @@ function D1edit() {
   }, [createFu, getInfoFu, id, key])
 
   return (
-    <div className={styles.D1edit}>
-      <div className='editMain'>
-        {/* 顶部 */}
-        <EditTop pageTxt='藏品登记' rowArr={rowArr} info={info} setInfo={setInfoFu} />
+    <InfoProvider>
+      <div className={styles.D1edit}>
+        <div className='editMain'>
+          {/* 顶部 */}
+          <EditTop pageTxt='藏品登记' rowArr={rowArr} info={info} setInfo={setInfoFu} />
 
-        {/* 藏品清单 */}
+          {/* 藏品清单 */}
 
-        {/* 底部按钮 */}
-        <EditBtn path='/register' btnPow={btnPow} info={info} />
+          {/* 底部按钮 */}
+          <EditBtn path='/register' btnPow={btnPow} info={info} />
+        </div>
       </div>
-    </div>
+    </InfoProvider>
   )
 }
 

+ 2 - 1
src/pages/Zother/EditBtn/index.tsx

@@ -30,9 +30,10 @@ function EditBtn({ path, info, btnPow }: Props) {
   const sonClick = useCallback(
     (val: string, flag?: string) => {
       // console.log('点击按钮', val, flag)
-
+      // 新增、编辑、审批、查看跳转
       if (flag) pageSkitFu(path, val, id, flag)
       else {
+        // 草稿、发起、审批、撤回、删除
         // 各种操作按钮逻辑待完善sg
       }
     },

+ 1 - 0
src/pages/Zother/EditTop/index.tsx

@@ -97,6 +97,7 @@ function EditTop({ rowArr, pageTxt, info, setInfo }: Props) {
                       allowClear={!item.must}
                       value={dayjs(info[item.key as 'date'])}
                       onChange={e => dataChangeFu(e, item)}
+                      disabledDate={current => current && current > dayjs().endOf('day')}
                     />
                   ) : item.type === 'Input' ? (
                     <Input

+ 34 - 0
src/pages/Zother/InfoContext.tsx

@@ -0,0 +1,34 @@
+import { createContext, ReactNode, useCallback, useContext, useMemo, useState } from 'react'
+import { TypeD1table } from '../Dmanage/D1register/data'
+
+type InfoContextValue = {
+  info: TypeD1table
+  setInfoFu: (info: TypeD1table) => void
+}
+
+type Props = {
+  children: ReactNode
+}
+
+const InfoContext = createContext<InfoContextValue | undefined>(undefined)
+
+export function InfoProvider({ children }: Props) {
+  const [info, setInfo] = useState({} as TypeD1table)
+
+  const setInfoFu = useCallback((newInfo: TypeD1table) => {
+    setInfo(newInfo)
+  }, [])
+
+  const value = useMemo(() => ({ info, setInfoFu }), [info, setInfoFu])
+
+  return <InfoContext.Provider value={value}>{children}</InfoContext.Provider>
+}
+
+// 自定义Hook,方便在子组件中使用
+export const useInfo = (): InfoContextValue => {
+  const context = useContext(InfoContext)
+  if (context === undefined) {
+    throw new Error('useInfo必须在InfoProvider内部使用')
+  }
+  return context
+}

+ 2 - 8
src/store/action/Dmanage/D1register.ts

@@ -21,12 +21,6 @@ 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}`)
+  获取详情: (id: number) => APIbase('get', `cms/order/register/detail/${id}`),
+  删除: (id: number) => APIbase('get', `cms/order/register/remove/${id}`)
 }