Просмотр исходного кода

feat: 新增登录后获取项目名称对应逻辑

lanjianrong 4 лет назад
Родитель
Сommit
b2d441ff42

+ 11 - 0
src/assets/css/common.scss

@@ -23,6 +23,10 @@
   background-color: $pi-green;
 }
 
+.pi-bg-white {
+  background-color: $pi-white;
+}
+
 .pi-gray {
   color: $pi-gray;
 }
@@ -98,6 +102,13 @@
   flex: 3;
 }
 
+.pi-flex-quadruple {
+  flex: 4;
+}
+
+.pi-flex-quintuple {
+  flex: 5;
+}
 .pi-align-start {
   @extend .pi-flex;
 

+ 1 - 1
src/assets/css/variable.scss

@@ -6,7 +6,7 @@ $pi-light-gray: #bbbbbb !default;
 $pi-blue: #007bff !default;
 $pi-red: #dc3545 !default;
 $pi-yellow: #ffc170 !default;
-
+$pi-white: #ffffff !default;
 $pi-line-color: rgba(0,0,0,.125) !default;
 
 // 实现0.5px的效果

+ 0 - 3
src/pages/Contract/List/index.scss

@@ -1,3 +0,0 @@
-.list-content {
-  width: calc(100vw - 55px);
-}

+ 2 - 0
src/pages/Dashboard/index.module.scss

@@ -5,6 +5,8 @@
   & > :first-child {
     margin-bottom: 1rem;
   }
+
+
   .title {
     font-size: 1.75rem;
     font-weight: 500;

+ 12 - 6
src/pages/Dashboard/index.tsx

@@ -1,5 +1,5 @@
 import Header from '@/components/Header'
-import React from 'react'
+import React, { useEffect } from 'react'
 import styles from './index.module.scss'
 import SvgIcon from '@/components/SvgIcon'
 import './index.scss'
@@ -8,19 +8,25 @@ import { ZhButton } from '@/components/Button'
 import { dayjsFormat } from '@/utils/util'
 import { userStore } from '@/store/mobx'
 import { Tooltip } from 'antd'
+import { observer } from 'mobx-react'
 const Index = () => {
+  useEffect(() => {
+    if(!userStore.projectInfo.id) {
+      userStore.getProjectInfo()
+    }
+  }, [ userStore.projectInfo.id ])
   return (
     <div className="wrap-contaniner hide-menu">
       <Header title="待办事项"></Header>
       <div className={styles.content}>
         <span>系统消息</span>
-        <h5 className={styles.title}>项目名称</h5>
+        <h5 className={styles.title}>{userStore.projectName}</h5>
         <div className={styles.downtime}>
           <SvgIcon type="xxh-wrench" style={{ fontSize: '1.5rem' }}></SvgIcon>
           <p className={styles.downtimeText}>系统将于 2019年3月10日 14:09 开始停机维护,持续30分钟。造成不便敬请谅解。</p>
         </div>
         <div className="pi-justify-between">
-          <div className={[ styles.card, 'pi-flex-twice' ].join(' ')}>
+          <div className={[ styles.card, 'pi-flex-quintuple' ].join(' ')}>
             <div className={styles.cardHeader}>
               <span>需要你处理</span>
             </div>
@@ -46,7 +52,7 @@ const Index = () => {
               {/* <p className="pi-text-center pi-muted">暂时没有需要你处理的事项</p> */}
             </div>
           </div>
-          <div className={[ styles.card, 'pi-flex-twice', 'pi-mg-lr-30' ].join(' ')}>
+          <div className={[ styles.card, 'pi-flex-quintuple', 'pi-mg-lr-30' ].join(' ')}>
             <div className={styles.cardHeader}>
               <span>需要你关注</span>
             </div>
@@ -71,7 +77,7 @@ const Index = () => {
               </ul>
             </div>
           </div>
-          <div className="pi-flex-sub pi-flex-column">
+          <div className="pi-flex-twice pi-flex-column">
             <div className={styles.card}>
               <div className={styles.cardBody}>
                 <div className={styles.cardTitle}>
@@ -113,4 +119,4 @@ const Index = () => {
   )
 }
 
-export default Index
+export default observer(Index)

+ 15 - 1
src/store/mobx/user/index.ts

@@ -1,8 +1,9 @@
 import { apiLogout } from '@/components/Menu/api'
 import { apiLogin } from '@/pages/Login/api'
 import { iFromValues } from '@/types/login'
+import { ProjectInfo } from '@/types/project'
 import { iGroup, iUserInfo } from '@/types/setting'
-import { apiGetGroupList } from '@/utils/common/api'
+import { apiGetGroupList, apiProjectInfo } from '@/utils/common/api'
 import { delUserInfo, getUserInfo, saveUserInfo } from '@/utils/common/user'
 import consts from '@/utils/consts'
 import history from '@/utils/history'
@@ -33,6 +34,8 @@ class UserState {
 
   @observable groupList:iGroup[] = []
 
+  @observable projectInfo:ProjectInfo = { id: '', code: '', name: '' }
+
   @computed get isLogin() {
     return !!this.userInfo.id
   }
@@ -40,6 +43,9 @@ class UserState {
     return this.userInfo.isAdmin ? 'ADMIN' : 'USER'
   }
 
+  @computed get projectName() {
+    return this.projectInfo.name
+  }
 
   @action login(values: iFromValues) {
     apiLogin(values).then(({ code = -1, data }) => {
@@ -86,6 +92,14 @@ class UserState {
       }
     })
   }
+
+  @action getProjectInfo() {
+    apiProjectInfo().then(({ code = -1, data }) => {
+      if (code === consts.RET_CODE.SUCCESS) {
+        this.projectInfo = data
+      }
+    })
+  }
 }
 
 export default new UserState()

+ 5 - 0
src/types/project.d.ts

@@ -0,0 +1,5 @@
+export interface ProjectInfo{
+  id: string
+  code: string
+  name: string
+}

+ 6 - 0
src/utils/common/api.ts

@@ -54,3 +54,9 @@ export async function apiGetPermissionWithBid(bidsectionId: string) {
   const { data } = await request.get('', { bidsectionId })
   return data
 }
+
+/** 获取登录项目信息 */
+export async function apiProjectInfo() {
+  const { data } = await request.get('/api/project')
+  return data
+}