Przeglądaj źródła

完善权限和登录页回跳

shaogen1995 1 miesiąc temu
rodzic
commit
f01313172d

+ 3 - 0
后台管理/src/assets/styles/base.css

@@ -43,6 +43,9 @@ textarea {
   opacity: 0;
   transition: opacity 0.5s;
 }
+.noFindPage .ant-result-title {
+  display: none;
+}
 /* 兼容360浏览器的下拉框 */
 .ant-select-selector {
   position: relative;

+ 3 - 0
后台管理/src/assets/styles/base.less

@@ -53,6 +53,9 @@ textarea {
 .noFindPage {
   opacity: 0;
   transition: opacity 0.5s;
+  .ant-result-title {
+    display: none;
+  }
 }
 
 /* 兼容360浏览器的下拉框 */

+ 9 - 1
后台管理/src/pages/B1ledger/index.tsx

@@ -11,6 +11,7 @@ import A0addGoods from '../A0addGoods'
 import { B1tableC } from '@/utils/tableData'
 import { B1devFu } from '@/utils/deriveFu'
 import { openLink } from '@/utils/history'
+import { authorityFu } from '@/utils/authority'
 
 function B1ledger() {
   // 待完善 表格/导出 入库时间 出库时间 当前位置相关
@@ -113,7 +114,14 @@ function B1ledger() {
           />
         </div>
         <div className='B1toprr'>
-          <Button type='primary' onClick={() => setOpenAdd(true)}>
+          <Button
+            type='primary'
+            onClick={() => {
+              authorityFu(400, '您没有藏品登记页面权限', () => {
+                setOpenAdd(true)
+              })
+            }}
+          >
             藏品登记
           </Button>
           &emsp;

+ 10 - 1
后台管理/src/pages/Layout/index.tsx

@@ -19,6 +19,7 @@ import MyPopconfirm from '@/components/MyPopconfirm'
 import { useDispatch } from 'react-redux'
 import { D1_APIgetlist } from '@/store/action/D1dict'
 import { D3_APIgetInfo } from '@/store/action/D3role'
+import store from '@/store'
 
 function Layout() {
   const [loding, setLoding] = useState(false)
@@ -63,10 +64,18 @@ function Layout() {
 
       const roleArr: any[] = res.data.permission
 
+      // 只拿后端返回的有权限的id,存到仓库
+      const authorityIds: number[] = []
+
       roleArr.forEach(v => {
-        if (v.authority) isOkIdArr.push(v.id)
+        if (v.authority) {
+          isOkIdArr.push(v.id)
+          authorityIds.push(v.id)
+        }
       })
 
+      store.dispatch({ type: 'layout/authorityIds', payload: authorityIds })
+
       // 详情页,也需要看下有没有页面权限
       setRouterSonRes(routerSon.filter(v => isOkIdArr.includes(v.id)))
 

+ 6 - 1
后台管理/src/pages/Login/index.tsx

@@ -62,7 +62,12 @@ export default function Login() {
 
       // 用户信息存到本地
       setTokenInfo({ ...res.data, token: res.data.satoken })
-      history.push('/')
+      const urlAll = window.location.href
+      if (urlAll.includes('?back=')) {
+        const url = urlAll.split('?back=')[1]
+        if (url) history.push(`/${url}`)
+        else history.push('/')
+      } else history.push('/')
     } else if (res.code === 3014) {
       MessageFu.warning('账号不存在或密码错误,请联系管理员!')
     } else if (res.code === -1 && res.msg === '验证码有误') {

+ 7 - 1
后台管理/src/store/reducer/layout.ts

@@ -24,7 +24,9 @@ const initState = {
   closeUpFile: {
     fu: () => {},
     state: false
-  }
+  },
+  // 页面权限id集合
+  authorityIds: [] as number[]
 }
 
 // 定义 action 类型
@@ -32,6 +34,7 @@ type LayoutActionType =
   | { type: 'layout/lookBigImg'; payload: { url: string; show: boolean } }
   | { type: 'layout/lookDom'; payload: LookDomType }
   | { type: 'layout/message'; payload: MessageType }
+  | { type: 'layout/authorityIds'; payload: number[] }
   | {
       type: 'layout/closeUpFile'
       payload: {
@@ -56,6 +59,9 @@ export default function layoutReducer(state = initState, action: LayoutActionTyp
     // 上传文件点击取消
     case 'layout/closeUpFile':
       return { ...state, closeUpFile: action.payload }
+    // 页面权限id集合
+    case 'layout/authorityIds':
+      return { ...state, authorityIds: action.payload }
 
     default:
       return state

+ 10 - 0
后台管理/src/utils/authority.ts

@@ -0,0 +1,10 @@
+import store from '@/store'
+import { MessageFu } from './message'
+
+// 看下有没有权限
+export const authorityFu = (id: number, txt: string, fu: () => void) => {
+  const authorityIds = store.getState().A0Layout.authorityIds
+
+  if (authorityIds.includes(id)) fu()
+  else MessageFu.warning(txt)
+}

+ 12 - 0
后台管理/src/utils/history.ts

@@ -4,6 +4,18 @@ import { getTokenInfo } from './storage'
 const history = createHashHistory()
 export default history
 
+// 权限失效,回登录页,带上回跳路径
+export const loginOutFu = () => {
+  const urlAll = window.location.href
+  const urlArr = urlAll.split('/#/')
+
+  if (!urlAll.includes('/login')) {
+    if (urlArr[1]) {
+      history.push(`/login?back=${urlArr[1]}`)
+    } else history.push('/login')
+  }
+}
+
 // 新窗口打开藏品详情页面
 export const openLink = (path: string) => {
   const urlAll = window.location.href

+ 4 - 4
后台管理/src/utils/http.ts

@@ -1,5 +1,5 @@
 import axios from 'axios'
-import history from './history'
+import { loginOutFu } from './history'
 import { getTokenInfo, removeTokenInfo } from './storage'
 import store from '@/store'
 import { MessageFu } from './message'
@@ -61,10 +61,10 @@ http.interceptors.response.use(
     }
     if (response.data.code === 401) {
       removeTokenInfo()
-      history.push('/login')
+      loginOutFu()
       clearTimeout(timeId)
       timeId = window.setTimeout(() => {
-        MessageFu.warning('登录失效!')
+        MessageFu.warning('登录超时!')
       }, 200)
     } else if (response.data.code === 0) {
       // MessageFu.success(response.data.msg);
@@ -92,7 +92,7 @@ http.interceptors.response.use(
           // 没有权限
           if (err.response.data.code === 401) {
             removeTokenInfo()
-            history.push('/login')
+            loginOutFu()
           }
         } else MessageFu.error('响应错误,请联系管理员!')
       }