Browse Source

feat: listDataTransform

touchitvoid 3 years ago
parent
commit
211d2356c5

+ 19 - 2
.idea/workspace.xml

@@ -3,8 +3,14 @@
   <component name="ChangeListManager">
     <list default="true" id="41f85978-32cc-4348-8909-ad50d32d8ad8" name="Default Changelist" comment="">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/layout/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/layout/index.tsx" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/router/config.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/router/config.tsx" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/router/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/router/index.tsx" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/services/api.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/services/api.ts" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/src/services/request.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/services/request.ts" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/views/User/Login.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/views/User/Login.tsx" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/views/Examine/company.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/views/Examine/company.tsx" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/views/Garden/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/views/Garden/index.tsx" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/views/Role/list.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/views/Role/list.tsx" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -38,11 +44,22 @@
       <option name="number" value="Default" />
       <option name="presentableId" value="Default" />
       <updated>1630475566284</updated>
-      <workItem from="1630475569580" duration="2565000" />
+      <workItem from="1630475569580" duration="7088000" />
     </task>
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
     <option name="version" value="3" />
   </component>
+  <component name="Vcs.Log.Tabs.Properties">
+    <option name="TAB_STATES">
+      <map>
+        <entry key="MAIN">
+          <value>
+            <State />
+          </value>
+        </entry>
+      </map>
+    </option>
+  </component>
 </project>

+ 11 - 13
src/layout/index.tsx

@@ -1,7 +1,7 @@
 import React, { useState, useEffect } from 'react'
-import { Layout, Menu, Breadcrumb } from 'antd'
+import { Layout, Menu } from 'antd'
 import { Route } from 'react-router-dom'
-import { MailOutlined, MehOutlined } from '@ant-design/icons'
+import { MehOutlined } from '@ant-design/icons'
 import './index.scss'
 import '@ant-design/pro-table/dist/table.css'
 import { routes } from  '../router/config'
@@ -12,29 +12,28 @@ const { Header, Content, Sider } = Layout
 const reallyRoutes = routes.map(item => item.children ? item.children : item).flat()
 
 const AdminLayout: any = (props) => {
-
-  useEffect(() => {
-    setCurrentKeys([props.history.location.pathname])
-  }, [])
-  const [currnetKeys, setCurrentKeys]: any = useState(["/admin/role"])
+  const [currentKeys, setCurrentKeys]: any = useState(["/admin/role"])
 
   const switchRoute = route => {
     props.history.push(route.path)
     setCurrentKeys([route.path])
   }
+  useEffect(() => {
+    setCurrentKeys([props.history.location.pathname])
+  }, [props.history.location.pathname])
 
   return (
     <Layout style={{ minHeight: '100vh' }}>
       <Sider style={{ backgroundColor: 'white' }}>
-        <Menu mode="inline" selectedKeys={currnetKeys}>
+        <Menu mode="inline" selectedKeys={currentKeys}>
         {
-          routes.map((route, index) => {
+          routes.map((route) => {
             return (
               route.children
                 ?
-                <Menu.SubMenu title={route.title}>
+                <Menu.SubMenu key={route.path} title={route.title}>
                   {
-                    route.children.filter(item => !item.hideInMenu).map((child, childIndex) =>
+                    route.children.filter(item => !item.hideInMenu).map(child =>
                       <Menu.Item
                         key={child.path}
                         onClick={() => switchRoute(child)}
@@ -64,8 +63,7 @@ const AdminLayout: any = (props) => {
         </Header>
         <Content className='layout-content'>
           {
-            reallyRoutes.
-              map(route =>
+            reallyRoutes.map(route =>
                 <Route
                   exact
                   path={route.path}

+ 2 - 3
src/router/config.tsx

@@ -2,8 +2,7 @@ import RoleList from '../views/Role/list'
 import HomePage from '../views/Home/index'
 import Login2 from '../views/User/Login'
 import ExamineCompany from '../views/Examine/company'
-import AddCompnay from '../views/Examine/add-company'
-import ExamineStore from '../views/Examine/store'
+import AddCompany from '../views/Examine/add-company'
 
 import React, { lazy, Suspense } from 'react'
 const GardenList = lazy(() => import('../views/Garden/index'))
@@ -34,7 +33,7 @@ export const routes: any = [
       {
         title: '添加物业公司',
         path: '/admin/company/add',
-        component: AddCompnay,
+        component: AddCompany,
         hideInMenu: true
       },
       {

+ 2 - 3
src/router/index.tsx

@@ -1,8 +1,7 @@
 import * as React from 'react'
 import { BrowserRouter, Switch, Route } from 'react-router-dom'
 import AdminLayout from '../layout/index'
-import Login2 from '../views/User/Login'
-import { routes, staticRoutes } from  '../router/config'
+import { staticRoutes } from './config'
 
 const router: React.FC = () => {
   return (
@@ -12,7 +11,7 @@ const router: React.FC = () => {
         {
           staticRoutes.map(route => {
             return (
-              <Route path={route.path} component={route.component} />
+              <Route path={route.path} component={route.component} key={route.path} />
             )
           })
         }

+ 27 - 3
src/services/api.ts

@@ -1,8 +1,32 @@
-import request from "./request";
+import request from "./request"
+
+const ListDataTransform = (AsyncMethod) => {
+  return new Promise(resolve => {
+    AsyncMethod.then(({ data, code }) => resolve({
+      total: data.total || data.list.length,
+      data: data.list.map((item, index) => {
+        if (item.childs) {
+          item.children = item.childs
+        }
+        item.key = `${item.name}-${index}`
+        return item
+      }),
+      success: !code
+    }))
+  })
+}
 
 // Post Login
-export const PostLogin = (params: any) => request({
-  url: '/v1/user/login',
+export const PostLogin = params => request({
+  url: '/user/login',
   method: 'post',
   data: params
 })
+
+// 权限列表
+export const GetRoleList: any = params => ListDataTransform(request({
+  url: '/system_permission',
+  method: 'get',
+  params
+}))
+

+ 2 - 3
src/services/request.ts

@@ -1,7 +1,7 @@
 import axios from 'axios'
 import { message } from 'antd'
 
-const prefix = '/api'
+const prefix = '/api/v1'
 
 export const request = axios.create({
   baseURL: `${prefix}`,
@@ -10,7 +10,7 @@ export const request = axios.create({
 
 request.interceptors.request.use(config => {
   if (localStorage.getItem('area-token')) {
-    config.headers['Authorization'] = localStorage.getItem('area-token')
+    config.headers['token'] = localStorage.getItem('area-token')
   }
   return config
 })
@@ -20,7 +20,6 @@ request.interceptors.response.use(response => {
     const error = response.data.message
     message.error(error)
     throw error
-    return
   }
   return response.data
 })

+ 2 - 2
src/views/Examine/company.tsx

@@ -1,7 +1,7 @@
 import * as React from 'react'
-import type { ProColumns, ActionType } from '@ant-design/pro-table'
+import type { ActionType } from '@ant-design/pro-table'
 import ProTable from '@ant-design/pro-table'
-import { Button, message, Input, Drawer, Modal, Form, InputNumber, Row } from 'antd'
+import { Button, Modal, Form, InputNumber, Row } from 'antd'
 import { PlusOutlined } from '@ant-design/icons'
 import { BasicInfoForm, ProveForm } from './map'
 

+ 2 - 3
src/views/Garden/index.tsx

@@ -1,8 +1,7 @@
 import * as React from 'react'
-import type { ProColumns, ActionType } from '@ant-design/pro-table'
+import type { ActionType } from '@ant-design/pro-table'
 import ProTable from '@ant-design/pro-table'
-import { Button, message, Input, Drawer, Modal, Form, InputNumber, Row, Select } from 'antd'
-import { PlusOutlined } from '@ant-design/icons'
+import { Button, Modal, Form, Select } from 'antd'
 
 const GardenList: React.FC = (props: any) => {
   // @ts-ignore

+ 4 - 11
src/views/Role/list.tsx

@@ -1,14 +1,16 @@
 import * as React from 'react'
 import type { ActionType } from '@ant-design/pro-table'
 import ProTable from '@ant-design/pro-table'
-import { Button, message, Input, Drawer } from 'antd'
+import { Button } from 'antd'
 import { PlusOutlined } from '@ant-design/icons'
+import { GetRoleList } from '../../services/api'
 
 // @ts-ignore
 const columns: any = [
   {
     title: '权限名称',
     dataIndex: 'name',
+    key: 'name'
   },
   {
     title: '所属上级code',
@@ -36,7 +38,6 @@ const columns: any = [
 ]
 const RoleList: React.FC = () => {
   const actionRef = React.useRef<ActionType>();
-
   return (
     <ProTable
       headerTitle="权限列表"
@@ -45,15 +46,7 @@ const RoleList: React.FC = () => {
       search={{
         labelWidth: 120,
       }}
-      request={() => {
-        return Promise.resolve({
-          total: 200,
-          data: [{
-            children: [{}, {}]
-          }],
-          success: true,
-        });
-      }}
+      request={GetRoleList}
       toolBarRender={() => [
         <Button
           type="primary"