Skip to content

Commit

Permalink
layout 布局开发
Browse files Browse the repository at this point in the history
  • Loading branch information
Winme committed Jan 6, 2020
1 parent 45f7681 commit d9d7b85
Show file tree
Hide file tree
Showing 47 changed files with 818 additions and 208 deletions.
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"typescript.updateImportsOnFileMove.enabled": "always",
"typescript.preferences.importModuleSpecifier": "auto",
"emmet.showAbbreviationSuggestions": false,
"emmet.showExpandedAbbreviation": "never",
// "emmet.showExpandedAbbreviation": "never",
"eslint.validate": ["typescript", "typescriptreact"],
"editor.formatOnSave": true
"editor.formatOnSave": true,
"prettier.printWidth": 120
}
33 changes: 13 additions & 20 deletions config-overrides.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
const {
override,
addLessLoader,
addWebpackAlias,
useEslintRc,
fixBabelImports
} = require('customize-cra')
var path = require('path')
var AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin')
const { override, addLessLoader, addWebpackAlias, useEslintRc, fixBabelImports } = require('customize-cra')
const path = require('path')
const darkTheme = require('@ant-design/dark-theme').default

const rewiredSourceMap = () => config => {
config.devtool =
config.mode === 'development' ? 'cheap-module-source-map' : false
return config
}
const resolve = dir => path.join(__dirname, '.', dir)

const rewiredDayJs = () => config => {
config.plugins = [...config.plugins, new AntdDayjsWebpackPlugin()]
const rewiredSourceMap = () => config => {
config.devtool = config.mode === 'development' ? 'cheap-module-source-map' : false
return config
}

module.exports = override(
useEslintRc(),
addLessLoader({
javascriptEnabled: true,
modifyVars: { '@primary-color': '#1DA57A' }
modifyVars: {
...darkTheme,
'@primary-color': '#13c2c2',
'@dark-color': '#141414'
}
}),
addWebpackAlias({
'~': path.resolve(__dirname, '..', 'src')
'~': resolve('src')
}),
fixBabelImports('import', {
libraryName: 'antd',
libraryDirectory: 'es',
style: true
}),
rewiredSourceMap(),
rewiredDayJs()
rewiredSourceMap()
)
27 changes: 19 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
{
"name": "react-admin",
"name": "react-antd-admin",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"@types/jest": "^24.0.0",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"antd": "^3.26.5",
"antd-dayjs-webpack-plugin": "^0.0.8",
"axios": "^0.19.0",
"babel-plugin-import": "^1.13.0",
"mockjs": "^1.1.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-redux": "^7.1.3",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"styled-components": "^4.4.1",
"typescript": "~3.7.2"
},
Expand All @@ -41,10 +40,22 @@
]
},
"devDependencies": {
"@ant-design/dark-theme": "^1.0.3",
"@types/http-proxy-middleware": "^0.19.3",
"@types/jest": "^24.0.0",
"@types/mockjs": "^1.0.2",
"@types/node": "^12.0.0",
"@types/react": "^16.9.0",
"@types/react-dom": "^16.9.0",
"@types/react-redux": "^7.1.5",
"@types/react-router-dom": "^5.1.3",
"@types/styled-components": "^4.4.1",
"babel-plugin-import": "^1.13.0",
"customize-cra": "^0.9.1",
"http-proxy-middleware": "^0.20.0",
"less": "^3.10.3",
"less-loader": "^5.0.0",
"react-app-rewired": "^2.1.5"
"react-app-rewired": "^2.1.5",
"redux-devtools-extension": "^2.13.8"
}
}
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>react-antd-admin</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
7 changes: 0 additions & 7 deletions src/App.less

This file was deleted.

14 changes: 7 additions & 7 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';
import React from 'react'
import { render } from '@testing-library/react'
import App from './App'

test('renders learn react link', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
const { getByText } = render(<App />)
const linkElement = getByText(/learn react/i)
expect(linkElement).toBeInTheDocument()
})
32 changes: 10 additions & 22 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import React from 'react'
import styled from 'styled-components'
import './App.less'
import { LayoutPage } from './pages/layout'
import LayoutPage from './pages/layout'
import { BrowserRouter, Switch, Route } from 'react-router-dom'
import LoginPage from './pages/login'

type Props = {
title?: string
content?: string
}

const Ap = styled.div`
justify-content: center;
display: block;
`
const P = styled(LayoutPage)`
color: inherit;
`

const App: React.FC<Props> = props => {
const App: React.FC = () => {
return (
<Ap className="App" style={{ height: '100%' }}>
<React.Suspense fallback={<div>1</div>}>
<P />
</React.Suspense>
</Ap>
<BrowserRouter>
<Switch>
<Route path="/login" component={LoginPage} />
<Route path="/" component={LayoutPage} />
</Switch>
</BrowserRouter>
)
}

Expand Down
34 changes: 34 additions & 0 deletions src/actions/global.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Action } from 'redux'

/** 用户设备 */
enum DeviceList {
/** 手机 */
MOBILE = 'MOBILE',
/** 电脑 */
DESKTOP = 'DESKTOP'
}

export type Device = keyof typeof DeviceList

export interface GlobalState {
/** 用户设备 */
device: Device

/** 菜单栏收起状态 */
collapsed: boolean
}

const SETGLOBALITEM = 'SETGLOBALITEM'

type SETGLOBALITEM = typeof SETGLOBALITEM

interface SetGloabalItem extends Action<SETGLOBALITEM> {
payload: Partial<GlobalState>
}

export const setGloabalItem = (payload: Partial<GlobalState>): SetGloabalItem => ({
type: 'SETGLOBALITEM',
payload
})

export type GlobalActions = SetGloabalItem
5 changes: 5 additions & 0 deletions src/api/layout.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { request } from './request'
import { MenuList } from '../interface/layout/menu.interface'

/** 获取菜单列表接口 */
export const getMenuList = () => request<MenuList>('get', '/user/menu')
61 changes: 61 additions & 0 deletions src/api/request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import axios from 'axios'
import { message as $message } from 'antd'

axios.defaults.timeout = 6000

axios.interceptors.request.use(
config => {
return config
},
error => {
Promise.reject(error)
}
)

axios.interceptors.response.use(
config => {
if (config?.data?.message) {
// $message.success(config.data.message)
}
return config?.data
},
error => {
const errorMessage = '系统异常'

$message.error(errorMessage)
return {
code: -1,
message: errorMessage,
result: null
}
}
)

export type Response<T = any> = {
status: boolean
message: string
result: T
}

type Method = 'get' | 'post'

export type MyResponse<T = any> = Promise<Response<T>>

/**
*
* @param method - request methods
* @param url - request url
* @param data - request data or params
*/
export const request = <T = any>(method: Method, url: string, data?: any): MyResponse<T> => {
// const prefix = '/api'
const prefix = ''
url = prefix + url
if (method === 'post') {
return axios.post(url, data)
} else {
return axios.get(url, {
params: data
})
}
}
5 changes: 5 additions & 0 deletions src/api/user.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { request } from './request'
import { LoginResult, LoginParams } from '../interface/user/login'

/** 登录接口 */
export const apiLogin = (data: LoginParams) => request<LoginResult>('get', '/user/login')
42 changes: 42 additions & 0 deletions src/assets/logo/antd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/logo/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/menu/dashboard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/menu/guide.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/menu/permission.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/hooks/useAsyncEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useEffect } from 'react'

type Callback = () => Promise<any>

type Deps = readonly any[]

/**
*
* @param callback callback
* @param deps dependences
*/
export default function useAsyncEffect(callback: Callback, deps: Deps = []) {
useEffect(() => {
callback().catch(e => console.log('useAsyncEffect error:', e))
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps)
}
20 changes: 0 additions & 20 deletions src/index.less

This file was deleted.

Loading

0 comments on commit d9d7b85

Please sign in to comment.