浏览代码

单页面返回按钮兼容

shaogen1995 2 月之前
父节点
当前提交
1cb1af9943

+ 2 - 2
public/index.html

@@ -12,8 +12,8 @@
 
     <script>
       // 域名地址
-      // const baseUrlTempOne = 'https://sit-yiwubwg.4dage.com'
-      const baseUrlTempOne = 'http://192.168.20.61:8096'
+      const baseUrlTempOne = 'https://sit-yiwubwg.4dage.com'
+      // const baseUrlTempOne = 'http://192.168.20.61:8096'
 
       // 钉钉模式
       const isDingTemp = false

+ 2 - 2
src/pages/B_enterTibet/B1collect/B1edit/index.tsx

@@ -8,7 +8,7 @@ import MyTable from '@/components/MyTable'
 import { B1TableC2, statusObj } from '@/utils/tableData'
 import MyPopconfirm from '@/components/MyPopconfirm'
 import ZflowTable from '../../../../components/ZflowTable'
-import history, { btnFlagFu2 } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu } from '@/utils/history'
 import {
   B1_APIcreate,
   B1_APIdel,
@@ -274,7 +274,7 @@ function B1edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/collect')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/collect')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 2 - 2
src/pages/B_enterTibet/B2identify/B2edit/index.tsx

@@ -14,7 +14,7 @@ import {
   B2_APIsaveDraft
 } from '@/store/action/B2identify'
 import { MessageFu } from '@/utils/message'
-import history, { btnFlagFu2 } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu } from '@/utils/history'
 import { EXbtnFu } from '@/utils/EXBtn'
 import { pageTitTxtObj } from '@/pages/D_storeManage/D4impStor/D4edit'
 import X3auditInfo from '@/pages/X_stock/X3auditInfo'
@@ -320,7 +320,7 @@ function B2edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/identify')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/identify')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 2 - 2
src/pages/B_enterTibet/B34typeIn/B34edit/index.tsx

@@ -17,7 +17,7 @@ import {
   FourAPI_saveDraft
 } from '@/store/action/FourAll'
 import { MessageFu } from '@/utils/message'
-import history, { btnFlagFu2, openGoodsInfoFu } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu, openGoodsInfoFu } from '@/utils/history'
 import { EXbtnFu } from '@/utils/EXBtn'
 import { pageTitTxtObj } from '@/pages/D_storeManage/D4impStor/D4edit'
 import X3auditInfo from '@/pages/X_stock/X3auditInfo'
@@ -371,7 +371,7 @@ function B34edit({ type }: Props) {
           />
         ) : null}
 
-        <Button onClick={() => history.push(`/${type === '入馆' ? 'entering' : 'enterTibet'}`)}>
+        <Button onClick={() => infoPageBackFu(`/${type === '入馆' ? 'entering' : 'enterTibet'}`)}>
           返回
         </Button>
       </>

+ 7 - 2
src/pages/C_goodsManage/C21wealth/C21edit/index.tsx

@@ -4,7 +4,12 @@ import { useParams } from 'react-router-dom'
 import { Button, Cascader, Checkbox, Input } from 'antd'
 import ZRichTexts from '@/components/ZRichTexts'
 import MyPopconfirm from '@/components/MyPopconfirm'
-import history, { btnFlagFu2, cascaderObjFu, openGoodsInfoFu } from '@/utils/history'
+import history, {
+  btnFlagFu2,
+  cascaderObjFu,
+  infoPageBackFu,
+  openGoodsInfoFu
+} from '@/utils/history'
 import { MessageFu } from '@/utils/message'
 import MyTable from '@/components/MyTable'
 import classNames from 'classnames'
@@ -336,7 +341,7 @@ function C21edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/wealth')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/wealth')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 2 - 2
src/pages/C_goodsManage/C22goodEdit/C22look/index.tsx

@@ -11,7 +11,7 @@ import {
 } from '@/store/action/C6edit'
 import { MessageFu } from '@/utils/message'
 import C22revamp, { OldNewType } from '../C22revamp'
-import history, { openGoodsInfoFu, textFu } from '@/utils/history'
+import history, { infoPageBackFu, openGoodsInfoFu, textFu } from '@/utils/history'
 import { pageTitTxtObj } from '@/pages/D_storeManage/D4impStor/D4edit'
 import { Button } from 'antd'
 import { statusObj } from '@/utils/tableData'
@@ -328,7 +328,7 @@ function C22look() {
               />
             ) : null}
 
-            <Button onClick={() => history.push('/goodEdit')}>返回</Button>
+            <Button onClick={() => infoPageBackFu('/goodEdit')}>返回</Button>
           </>
         )}
       </div>

+ 2 - 2
src/pages/D_storeManage/D3staff/D3edit/index.tsx

@@ -3,7 +3,7 @@ import styles from './index.module.scss'
 import { useParams } from 'react-router-dom'
 import { Button, DatePicker, Input, Select, Tabs } from 'antd'
 import MyPopconfirm from '@/components/MyPopconfirm'
-import history, { btnFlagFu2 } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu } from '@/utils/history'
 import { MessageFu } from '@/utils/message'
 import { statusObj } from '@/utils/tableData'
 import X3auditInfo from '@/pages/X_stock/X3auditInfo'
@@ -267,7 +267,7 @@ function C21edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/staff')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/staff')}>返回</Button>
       </>
     )
   }, [curTab, delFu, lookBtnFu, lookJumpFu, topInfo])

+ 7 - 2
src/pages/D_storeManage/D4impStor/D4edit/index.tsx

@@ -16,7 +16,12 @@ import {
 } from '@/store/action/D4impStor'
 import dayjs from 'dayjs'
 import { MessageFu } from '@/utils/message'
-import history, { btnFlagFu2, cascaderObjFu, openGoodsInfoFu } from '@/utils/history'
+import history, {
+  btnFlagFu2,
+  cascaderObjFu,
+  infoPageBackFu,
+  openGoodsInfoFu
+} from '@/utils/history'
 import classNames from 'classnames'
 import { Button, Cascader, DatePicker, Input, InputNumber, Select } from 'antd'
 import MyPopconfirm from '@/components/MyPopconfirm'
@@ -477,7 +482,7 @@ function D4edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/impStor')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/impStor')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 2 - 2
src/pages/D_storeManage/D5moveStor/D5edit/index.tsx

@@ -22,7 +22,7 @@ import { pageTitTxtObj } from '../../D4impStor/D4edit'
 import dayjs from 'dayjs'
 import { MessageFu } from '@/utils/message'
 import { findFirstDuplicate } from '../../D4impStor/data'
-import history, { btnFlagFu2, openGoodsInfoFu } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu, openGoodsInfoFu } from '@/utils/history'
 import classNames from 'classnames'
 import { Button, DatePicker, Input, InputNumber, Modal, Select } from 'antd'
 import TextArea from 'antd/es/input/TextArea'
@@ -488,7 +488,7 @@ function D5edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/moveStor')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/moveStor')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 2 - 2
src/pages/D_storeManage/D6putsStor/D6edit/index.tsx

@@ -17,7 +17,7 @@ import { API_goodsInfo } from '@/store/action/C1ledger'
 import { pageTitTxtObj } from '../../D4impStor/D4edit'
 import dayjs from 'dayjs'
 import { MessageFu } from '@/utils/message'
-import history, { btnFlagFu2, openGoodsInfoFu } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu, openGoodsInfoFu } from '@/utils/history'
 import classNames from 'classnames'
 import TextArea from 'antd/es/input/TextArea'
 import { Button, DatePicker, Input, Modal, Radio, Select } from 'antd'
@@ -534,7 +534,7 @@ function D6edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/putsStor')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/putsStor')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 2 - 2
src/pages/D_storeManage/D7check/D7edit/index.tsx

@@ -3,7 +3,7 @@ import styles from './index.module.scss'
 import { useParams } from 'react-router-dom'
 import { Button, DatePicker, Input, Modal, Select } from 'antd'
 import MyPopconfirm from '@/components/MyPopconfirm'
-import history, { btnFlagFu2 } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu } from '@/utils/history'
 import { MessageFu } from '@/utils/message'
 import { statusObj } from '@/utils/tableData'
 import X3auditInfo from '@/pages/X_stock/X3auditInfo'
@@ -315,7 +315,7 @@ function D7edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/check')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/check')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 2 - 2
src/pages/D_storeManage/D8cancel/D8edit/index.tsx

@@ -15,7 +15,7 @@ import {
 } from '@/store/action/D8cancel'
 import { pageTitTxtObj } from '../../D4impStor/D4edit'
 import { MessageFu } from '@/utils/message'
-import history, { btnFlagFu2, openGoodsInfoFu } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu, openGoodsInfoFu } from '@/utils/history'
 import TextArea from 'antd/es/input/TextArea'
 import { Button } from 'antd'
 import MyPopconfirm from '@/components/MyPopconfirm'
@@ -395,7 +395,7 @@ function D8edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/cancel')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/cancel')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 2 - 2
src/pages/E_goodsStorage/E1accident/E1edit/index.tsx

@@ -10,7 +10,7 @@ import { selectObj } from '@/utils/select'
 import Z3upFiles from '@/components/Z3upFiles'
 import ZRichTexts from '@/components/ZRichTexts'
 import MyPopconfirm from '@/components/MyPopconfirm'
-import history, { btnFlagFu2 } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu } from '@/utils/history'
 import { MessageFu } from '@/utils/message'
 import X3auditInfo from '@/pages/X_stock/X3auditInfo'
 import {
@@ -336,7 +336,7 @@ function E1edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/accident')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/accident')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 2 - 2
src/pages/E_goodsStorage/E3actuality/E3edit/index.tsx

@@ -17,7 +17,7 @@ import { API_goodsInfo } from '@/store/action/C1ledger'
 import { pageTitTxtObj } from '@/pages/D_storeManage/D4impStor/D4edit'
 import dayjs from 'dayjs'
 import { MessageFu } from '@/utils/message'
-import history, { btnFlagFu2 } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu } from '@/utils/history'
 import { Button, DatePicker, Input, Select } from 'antd'
 import MyPopconfirm from '@/components/MyPopconfirm'
 import { EXbtnFu } from '@/utils/EXBtn'
@@ -333,7 +333,7 @@ function E3edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/actuality')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/actuality')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 2 - 2
src/pages/E_goodsStorage/E4repair/E4edit/index.tsx

@@ -15,7 +15,7 @@ import {
 import { pageTitTxtObj } from '@/pages/D_storeManage/D4impStor/D4edit'
 import dayjs from 'dayjs'
 import { MessageFu } from '@/utils/message'
-import history, { btnFlagFu2, openGoodsInfoFu } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu, openGoodsInfoFu } from '@/utils/history'
 import { C1GoodType } from '@/pages/A3_ledger/C1ledger/type'
 import classNames from 'classnames'
 import { Button, DatePicker, Input } from 'antd'
@@ -430,7 +430,7 @@ function E4edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/repair')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/repair')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 2 - 2
src/pages/F_exhibition/F1exhibition/F1edit/index.tsx

@@ -8,7 +8,7 @@ import MyTable, { MyTableMethods } from '@/components/MyTable'
 import { F1_GOOD_COLUMNS, F1_SON_TYPE_NAME_OPTS, F1_SON_TYPE_OPTS } from '../constants'
 import ZGaddNow from '@/components/ZGaddNow'
 import MyPopconfirm from '@/components/MyPopconfirm'
-import history, { btnFlagFu2, openGoodsInfoFu } from '@/utils/history'
+import history, { btnFlagFu2, infoPageBackFu, openGoodsInfoFu } from '@/utils/history'
 import {
   F1_APIcreate,
   F1_APIdel,
@@ -235,7 +235,7 @@ function F1edit() {
           />
         ) : null}
 
-        <Button onClick={() => history.push('/exhibition')}>返回</Button>
+        <Button onClick={() => infoPageBackFu('/exhibition')}>返回</Button>
       </>
     )
   }, [delFu, lookBtnFu, lookJumpFu, topInfo])

+ 8 - 1
src/store/reducer/layout.ts

@@ -54,7 +54,10 @@ const initState = {
   userRolePermissions: [] as RouterType,
 
   // 藏品详情页面tab和按钮权限
-  goodsInfoPower: [] as string[]
+  goodsInfoPower: [] as string[],
+
+  // 路由堆栈长度
+  routerLength: 0
 }
 
 // 定义 action 类型
@@ -75,6 +78,7 @@ type LayoutActionType =
   | { type: 'layout/exInfo'; payload: ExInfoType }
   | { type: 'layout/userRolePermissions'; payload: RouterType }
   | { type: 'layout/goodsInfoPower'; payload: string[] }
+  | { type: 'layout/routerLength'; payload: number }
 
 // 频道 reducer
 export default function layoutReducer(state = initState, action: LayoutActionType) {
@@ -112,6 +116,9 @@ export default function layoutReducer(state = initState, action: LayoutActionTyp
     // 藏品详情页面tab和按钮权限
     case 'layout/goodsInfoPower':
       return { ...state, goodsInfoPower: action.payload }
+    // 路由堆栈长度
+    case 'layout/routerLength':
+      return { ...state, routerLength: action.payload }
     default:
       return state
   }

+ 18 - 0
src/utils/history.ts

@@ -10,6 +10,24 @@ import { cascaderArr } from '@/pages/C_goodsManage/C1register/AddGoods/data'
 import { FourTableType } from '@/pages/B_enterTibet/B1collect/type'
 // import dd from 'gdt-jsapi'
 const history = createHashHistory()
+
+// 监听路由
+let routerLength = 0
+history.listen((_: any, listener: any) => {
+  if (listener === 'PUSH') {
+    routerLength += 1
+  } else if (listener === 'POP') {
+    if (routerLength >= 1) routerLength -= 1
+  }
+  store.dispatch({ type: 'layout/routerLength', payload: routerLength })
+})
+
+// 详情页的返回按钮 如果没有上一级 才push
+export const infoPageBackFu = (url: string) => {
+  const routerLength = store.getState().A0Layout.routerLength
+  routerLength ? history.go(-1) : history.push(url)
+}
+
 export default history
 
 // -------------------所有藏品详情 全部新页面打开-------------------