Parcourir la source

Merge branch 'master' of http://192.168.1.41:3000/outaozhen/cldV2react

outaozhen il y a 5 ans
Parent
commit
f0c0ab2395

+ 11 - 13
src/app.tsx

@@ -1,23 +1,21 @@
-import { apiGetRoles, getDataPerm } from './services/user'
-import { setAuthCache } from './utils/auth'
+import { apiGetRoles } from './services/user'
 import { setAuthority } from './utils/auth/authority'
-import { PERM_LIST_KEY } from './utils/cache/cacheEnum'
 
-const PermDataList = [
-  {
-    key: '/customer',
-    value: 2
-  }
-]
+// const PermDataList = [
+//   {
+//     key: '/customer',
+//     value: 2
+//   }
+// ]
 export function render(oldRender) {
   const path = window.location.pathname
   if (path !== '/user/login') {
     apiGetRoles().then(roles => {
       setAuthority(roles.data)
-      const permVal = PermDataList.find(item => path.startsWith(item.key))?.value
-      if (permVal) {
-        getDataPerm().then(prem => setAuthCache(PERM_LIST_KEY, prem?.data || []))
-      }
+      // const permVal = PermDataList.find(item => path.startsWith(item.key))?.value
+      // if (permVal) {
+      //   getDataPerm().then(prem => setAuthCache(PERM_LIST_KEY, prem?.data || []))
+      // }
     })
   }
   oldRender()

+ 4 - 1
src/layouts/SecurityLayout.jsx

@@ -6,7 +6,7 @@ import { stringify } from 'querystring'
 class SecurityLayout extends React.Component {
   state = {
     isReady: false
-  };
+  }
 
   componentDidMount() {
     this.setState({
@@ -18,6 +18,9 @@ class SecurityLayout extends React.Component {
       dispatch({
         type: 'user/fetchCurrent'
       })
+      dispatch({
+        type: 'global/fetchPermData'
+      })
     }
   }
 

+ 2 - 2
src/models/district.js

@@ -9,7 +9,7 @@ export default {
   effects: {
     *fetch({ payload }, { call, put }) {
       const response = yield call(queryDistrict, payload)
-      if (response && response.code === consts.RET_CODE.SUCCESS) {
+      if (response?.code === consts.RET_CODE.SUCCESS) {
         yield put({
           type: 'changeState',
           payload: {
@@ -31,7 +31,7 @@ export default {
         const { code = -1, data = [] } = yield call(queryDistrict, { parentId: provinceId })
         if (code === consts.RET_CODE.SUCCESS) {
           const response = yield call(queryDistrict, { parentId: cityId })
-          if (response && response.code === consts.RET_CODE.SUCCESS) {
+          if (response?.code === consts.RET_CODE.SUCCESS) {
             const newData = data.map(item => {
               const newItem = { ...item }
               if (item.id === cityId) {

+ 17 - 79
src/models/global.js

@@ -1,68 +1,25 @@
 // import { queryNotices } from '@/services/user'
 
+import consts from '@/basic/consts'
+import { getDataPerm } from '@/services/user'
+
 const GlobalModel = {
   namespace: 'global',
   state: {
     collapsed: false,
-    notices: []
+    notices: [],
+    premData: {}
   },
   effects: {
-    // *fetchNotices(_, { call, put, select }) {
-    //   const data = yield call(queryNotices)
-    //   yield put({
-    //     type: 'saveNotices',
-    //     payload: data
-    //   })
-    //   const unreadCount = yield select(
-    //     (state) => state.global.notices.filter((item) => !item.read).length
-    //   )
-    //   yield put({
-    //     type: 'user/changeNotifyCount',
-    //     payload: {
-    //       totalCount: data.length,
-    //       unreadCount
-    //     }
-    //   })
-    // },
-    // *clearNotices({ payload }, { put, select }) {
-    //   yield put({
-    //     type: 'saveClearedNotices',
-    //     payload
-    //   })
-    //   const count = yield select((state) => state.global.notices.length)
-    //   const unreadCount = yield select(
-    //     (state) => state.global.notices.filter((item) => !item.read).length
-    //   )
-    //   yield put({
-    //     type: 'user/changeNotifyCount',
-    //     payload: {
-    //       totalCount: count,
-    //       unreadCount
-    //     }
-    //   })
-    // },
-    // *changeNoticeReadState({ payload }, { put, select }) {
-    //   const notices = yield select((state) =>
-    //     state.global.notices.map((item) => {
-    //       const notice = { ...item }
-    //       if (notice.id === payload) {
-    //         notice.read = true
-    //       }
-    //       return notice
-    //     })
-    //   )
-    //   yield put({
-    //     type: 'saveNotices',
-    //     payload: notices
-    //   })
-    //   yield put({
-    //     type: 'user/changeNotifyCount',
-    //     payload: {
-    //       totalCount: notices.length,
-    //       unreadCount: notices.filter((item) => !item.read).length
-    //     }
-    //   })
-    // }
+    *fetchPermData(_, { put }) {
+      const response = yield getDataPerm()
+      if (response?.code === consts.RET_CODE.SUCCESS) {
+        yield put({
+          type: 'ChangePermData',
+          payload: response.data || {}
+        })
+      }
+    }
   },
   reducers: {
     changeLayoutCollapsed(
@@ -73,29 +30,10 @@ const GlobalModel = {
       { payload }
     ) {
       return { ...state, collapsed: payload }
+    },
+    ChangePermData(state, { payload }) {
+      return { ...state, premData: payload }
     }
-
-    // saveNotices(state, { payload }) {
-    //   return {
-    //     collapsed: false,
-    //     ...state,
-    //     notices: payload
-    //   }
-    // },
-
-    // saveClearedNotices(
-    //   state = {
-    //     notices: [],
-    //     collapsed: true
-    //   },
-    //   { payload }
-    // ) {
-    //   return {
-    //     ...state,
-    //     collapsed: false,
-    //     notices: state.notices.filter((item) => item.type !== payload)
-    //   }
-    // }
   }
 }
 export default GlobalModel

+ 7 - 6
src/pages/Customer/Client/index.jsx

@@ -20,9 +20,8 @@ import { useTableScroll } from '@/hooks/useAutoTable'
 import { apiAddClient, queryClient } from '@/services/customer'
 import { apiBatchLink } from '@/services/customer'
 import styles from './index.less'
-import { getPermDataList } from '@/utils/auth'
 
-const Contact = props => {
+const Client = props => {
   const { toggleDrawer, setDrawerProps } = useModal()
   const {
     personTagColorMap,
@@ -31,6 +30,7 @@ const Contact = props => {
     teamTags,
     dispatch,
     shouldUpdate,
+    permData,
     loading
   } = props
 
@@ -600,7 +600,7 @@ const Contact = props => {
             onChange={e => {
               setState({ ...state, params: { ...state.params, dataPermission: e } })
             }}
-            options={getPermDataList()?.customer || []}
+            options={permData?.customer || []}
           />
         }
         onLoadingChange={loadingStatus => {
@@ -614,11 +614,12 @@ const Contact = props => {
   )
 }
 
-export default connect(({ client, refresh, loading }) => ({
+export default connect(({ client, refresh, global, loading }) => ({
   personTagColorMap: client.personTagColorMap,
   personTags: client.personTags,
   teamTagColorMap: client.teamTagColorMap,
   teamTags: client.teamTags,
   loading: loading.models.client,
-  shouldUpdate: refresh.client
-}))(Contact)
+  shouldUpdate: refresh.client,
+  permData: global.premData
+}))(Client)

+ 4 - 3
src/pages/Customer/Company/index.jsx

@@ -14,7 +14,6 @@ import PersonLabel from './components/PersonLabel'
 import { TagTypeEnum, TagDataTypeEnum, LabelModeType } from './components/PersonLabel/const'
 import { Add, Down, Check } from '@icon-park/react'
 import { apiBatchLink } from '@/services/customer'
-import { getPermDataList } from '@/utils/auth'
 import styles from './index.less'
 
 const Company = props => {
@@ -25,6 +24,7 @@ const Company = props => {
     teamTags,
     dispatch,
     shouldUpdate,
+    permData,
     loading
   } = props
   const { toggleDrawer, setDrawerProps } = useModal()
@@ -471,7 +471,7 @@ const Company = props => {
             onChange={e => {
               setState({ ...state, params: { ...state.params, dataPermission: e } })
             }}
-            options={getPermDataList()?.customer || []}
+            options={permData?.customer || []}
           />
         }
         rowSelection={{
@@ -492,11 +492,12 @@ const Company = props => {
   )
 }
 
-export default connect(({ company, refresh, loading }) => ({
+export default connect(({ company, refresh, global, loading }) => ({
   personTagColorMap: company.personTagColorMap,
   personTags: company.personTags,
   teamTagColorMap: company.teamTagColorMap,
   teamTags: company.teamTags,
   loading: loading.models.company,
+  permData: global.premData,
   shouldUpdate: refresh.company
 }))(Company)

+ 109 - 0
src/pages/workbench/Dashboard/components/LeaderBoard.jsx

@@ -0,0 +1,109 @@
+import ProTable from '@ant-design/pro-table'
+import { Select } from 'antd'
+import React, { useState, useMemo } from 'react'
+
+const { Option } = Select
+
+const opMap = {
+  customer: '新增服务',
+  customerService: '客户服务',
+  client: '新增联系人',
+  clientService: '联系人服务',
+  business: '新增商机',
+  businessService: '商机服务'
+}
+const LeaderBoard = ({ dataList = [] }) => {
+  const [activeOp, setActiveOp] = useState('customer')
+
+  const columns = useMemo(() => {
+    const oColumns = [
+      {
+        title: '排名',
+        dataIndex: 'rank',
+        valueType: 'indexBorder',
+        width: '30%'
+      },
+      {
+        title: '姓名',
+        dataIndex: `${activeOp}Name`,
+        width: '40%'
+      },
+      {
+        title: '新增客户数',
+        dataIndex: 'customer',
+        width: '30%'
+      },
+      {
+        title: '客户服务',
+        dataIndex: 'customerService',
+        width: '30%'
+      },
+      {
+        title: '新增联系人',
+        dataIndex: 'client',
+        width: '30%'
+      },
+      {
+        title: '联系人服务',
+        dataIndex: 'clientService',
+        width: '30%'
+      },
+      {
+        title: '新增商机',
+        dataIndex: 'business',
+        width: '30%'
+      },
+      {
+        title: '商机服务',
+        dataIndex: 'businessService',
+        width: '30%'
+      }
+    ]
+
+    let stop = false
+    const bColumns = oColumns.reduce((prev, curr, idx) => {
+      if (idx < 2) {
+        prev.push(curr)
+        return prev
+      }
+
+      if (!stop && curr.dataIndex.startsWith(activeOp)) {
+        stop = true
+        prev.push(curr)
+        return prev
+      }
+      return prev
+    }, [])
+    return bColumns
+  }, [activeOp])
+
+  return (
+    <>
+      <div className="flex items-center justify-between">
+        <span>排行榜</span>
+        <Select defaultValue="customer" onChange={e => setActiveOp(e)}>
+          <Option value="customer">新增服务</Option>
+          <Option value="customerService">客户服务</Option>
+          <Option value="client">新增联系人</Option>
+          <Option value="clientService">联系人服务</Option>
+          <Option value="business">新增商机</Option>
+          <Option value="businessService">商机服务</Option>
+          {/* <Option value="开票金额">开票金额</Option>
+          <Option value="回款金额">回款金额</Option> */}
+        </Select>
+      </div>
+      <div className="text-center">{opMap[activeOp]}排行榜</div>
+      <ProTable
+        rowKey={record => record.rank}
+        columns={columns}
+        dataSource={dataList}
+        search={false}
+        size="small"
+        toolBarRender={false}
+        pagination={false}
+      />
+    </>
+  )
+}
+
+export default LeaderBoard

+ 4 - 40
src/pages/workbench/Dashboard/index.jsx

@@ -7,6 +7,7 @@ import consts from '@/consts'
 import { useModal } from '@/components/Modal'
 import { queryDashboard } from '@/services/dashboard'
 import ReminderList from './components/ReminderList'
+import LeaderBoard from './components/LeaderBoard'
 
 const Dashboard = () => {
   const { Option } = Select
@@ -138,21 +139,7 @@ const Dashboard = () => {
       )
     }
   ]
-  const columnsCustomer = [
-    {
-      title: '排名',
-      dataIndex: 'rank',
-      valueType: 'indexBorder'
-    },
-    {
-      title: '姓名',
-      dataIndex: 'clientStaffName'
-    },
-    {
-      title: '新增客户数',
-      dataIndex: 'clientCount'
-    }
-  ]
+
   const charData = state.char
   const threadData = state.thread
   // const uvBillData = [
@@ -399,31 +386,8 @@ const Dashboard = () => {
       <div className="mt-4">
         <Row gutter={16}>
           <Col className="gutter-row" span={12}>
-            <div className="p-4 bg-white border rounded-lg shadow-card">
-              <div className="relative">
-                <span>排行榜</span>
-                <div className="absolute right-1 top-0">
-                  <Select defaultValue="新增服务">
-                    <Option value="新增服务">新增服务</Option>
-                    <Option value="客户服务">客户服务</Option>
-                    <Option value="新增联系人">新增联系人</Option>
-                    <Option value="联系人服务">联系人服务</Option>
-                    <Option value="新增商机">新增商机</Option>
-                    <Option value="商机服务">商机服务</Option>
-                    <Option value="开票金额">开票金额</Option>
-                    <Option value="回款金额">回款金额</Option>
-                  </Select>
-                </div>
-              </div>
-              <div className="text-center">新增客户排行榜</div>
-              <ProTable
-                rowKey={record => record.rank}
-                columns={columnsCustomer}
-                dataSource={state.leaderboard}
-                search={false}
-                toolBarRender={false}
-                pagination={false}
-              />
+            <div className="p-4 pt-2 bg-white border rounded-lg shadow-card">
+              <LeaderBoard dataList={state.leaderboard} />
             </div>
           </Col>
         </Row>

+ 1 - 5
src/utils/auth/index.ts

@@ -2,7 +2,7 @@
 
 import { Persistent, BasicKeys } from '@/utils/cache/persistent'
 import projectSetting from '@/settings/projectSetting'
-import { TOKEN_KEY, CacheTypeEnum, PERM_LIST_KEY } from '@/utils/cache/cacheEnum'
+import { TOKEN_KEY, CacheTypeEnum } from '@/utils/cache/cacheEnum'
 
 const { permissionCacheType } = projectSetting
 const isLocal = permissionCacheType === CacheTypeEnum.LOCAL
@@ -11,10 +11,6 @@ export function getToken() {
   return getAuthCache(TOKEN_KEY)
 }
 
-export function getPermDataList() {
-  return getAuthCache(PERM_LIST_KEY)
-}
-
 export function getAuthCache<T>(key: BasicKeys) {
   const fn = isLocal ? Persistent.getLocal : Persistent.getSession
   return fn(key) as T

+ 0 - 2
src/utils/cache/cacheEnum.ts

@@ -5,8 +5,6 @@ export const TOKEN_KEY = 'TOKEN__'
 // role role key
 export const ROLES_KEY = 'ROLES__KEY__'
 
-export const PERM_LIST_KEY = 'PERM_LIST_KEY'
-
 // base global local key
 export const APP_LOCAL_CACHE_KEY = 'COMMON__LOCAL__KEY__'