8000 feat: add tabs layout by xiaohuoni · Pull Request #337 · alitajs/alita · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

feat: add tabs layout #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"updateInternalDependents": "always"
},
"ignore": ["@examples/boilerplate"]
"ignore": ["@examples/boilerplate", "@examples/tabs"]
}
6 changes: 6 additions & 0 deletions .changeset/friendly-cups-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'alita': patch
'@alita/plugins': patch
---

feat: add tabs layout
7 changes: 7 additions & 0 deletions examples/tabs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.env.local
/.umirc.local.ts
/.umirc.local.js
/config/config.local.ts
/config/config.local.js
/src/.umi
/.umi
12 changes: 12 additions & 0 deletions examples/tabs/.umirc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
appType: 'pc',
keepalive: [/users/, /foo/],
aconsole: {
console: {},
inspx: {},
},
mfsu: {},
antd: {},
hash: false,
tabsLayout: {},
};
5 changes: 5 additions & 0 deletions examples/tabs/mock/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
'/api/hello': {
text: 'Alita',
},
};
16 changes: 16 additions & 0 deletions examples/tabs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@examples/tabs",
"private": true,
"version": "1.0.0",
"scripts": {
"dev": "alita dev",
"build": "ANALYZE=1 alita build",
"plugin": "alita plugin list"
},
"dependencies": {
"@alita/flow": "workspace:*",
"@ant-design/icons": "^4.7.0",
"alita": "workspace:*",
"antd": "^4.21.2"
}
}
12 changes: 12 additions & 0 deletions examples/tabs/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IApi } from 'umi';

export default (api: IApi) => {
api.onDevCompileDone((opts) => {
opts;
// console.log('> onDevCompileDone', opts.isFirstCompile);
});
api.onBuildComplete((opts) => {
opts;
// console.log('> onBuildComplete', opts.isFirstCompile);
});
};
29 changes: 29 additions & 0 deletions examples/tabs/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export const request = {
prefix: '/api',
method: 'get',
errorHandler: (error) => {
// 集中处理错误
console.log(11111111);
console.log(error);
},
};

export const tabsLayout = {
local: {
'/': '首页',
'/users': '用户',
'/foo': '其他',
},
};

// async function delay(ms: number) {
// return new Promise((resolve) => setTimeout(resolve, ms));
// }
// export async function tabsLayout() {
// await delay(500);
// return {local:{
// '/':'首页',
// '/users':'用户',
// '/foo':'其他'
// }};
// }
Binary file added examples/tabs/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions examples/tabs/src/global.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.rumtime-keep-alive-layout > .ant-tabs-card .ant-tabs-tab-active {
background: #fff;
border-color: #fff;
}
81 changes: 81 additions & 0 deletions examples/tabs/src/layouts/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import {
DesktopOutlined,
PieChartOutlined,
UserOutlined,
} from '@ant-design/icons';
import { useKeepOutlets, useLocation, useNavigate } from 'alita';
import type { MenuProps } from 'antd';
import { Layout, Menu } from 'antd';
import React, { useState } from 'react';

const { Header, Content, Footer, Sider } = Layout;

type MenuItem = Required<MenuProps>['items'][number];

function getItem(
label: React.ReactNode,
key: React.Key,
icon?: React.ReactNode,
children?: MenuItem[],
): MenuItem {
return {
key,
icon,
children,
label,
} as MenuItem;
}

const items: MenuItem[] = [
getItem('首页', '/', <PieChartOutlined />),
getItem('用户', '/users', <UserOutlined />),
getItem('其他', '/foo', <DesktopOutlined />),
];

const App: React.FC = () => {
const [collapsed, setCollapsed] = useState(false);
const element = useKeepOutlets();
const navigate = useNavigate();
const location = useLocation();
return (
<Layout style={{ minHeight: '100vh' }}>
<Sider
collapsible
collapsed={collapsed}
=> setCollapsed(value)}
>
<div
style={{
height: '32px',
margin: '16px',
color: '#fff',
textAlign: 'center',
fontSize: '16px',
}}
>
Umi 4
</div>
<Menu
=> {
navigate(e?.key);
}}
theme="dark"
defaultSelectedKeys={[location.pathname]}
mode="inline"
items={items}
/>
</Sider>
<Layout>
<Header style={{ padding: 0 }} />
<Content style={{ margin: '0 16px' }}>
<div style={{ padding: 24, minHeight: 360 }}>{element}</div>
</Content>
<Footer style={{ textAlign: 'center' }}>
Umi@4 实战小册 Created by xiaohuoni
</Footer>
</Layout>
</Layout>
);
};

export default App;
3 changes: 3 additions & 0 deletions examples/tabs/src/pages/foo/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import React from 'react';

export default () => <h2>user: Foo</h2>;
6 changes: 6 additions & 0 deletions examples/tabs/src/pages/index.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.title {
font-size: 30px;
}
.adm-button{
font-size: 30px
}
13 changes: 13 additions & 0 deletions examples/tabs/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { history } from 'alita';
import React from 'react';
import styles from './index.less';
export default () => (
<div
className={styles['adm-button']}
=> {
history.push('/users');
}}
>
Hello Alita
</div>
);
36 changes: 36 additions & 0 deletions examples/tabs/src/pages/users/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { KeepAliveContext } from '@@/plugin-keepalive';
import { history, Outlet, useLocation } from 'alita';
import { Button } from 'antd';
import React, { useState } from 'react';

export default () => {
const [count, setCount] = useState(0);
const location = useLocation();
const { dropByCacheKey } = React.useContext<any>(KeepAliveContext);
return (
<div>
<h2>users layout</h2>
<h3>当前页面状态被设置成自动保存</h3>
<h3>当前计数是:{count}</h3>
<Button
color="primary"
block
size="large"
=> setCount(count + 1)}
>
点我计数加1
</Button>
<h3
=> {
history.push('/');
}}
>
点我返回首页,记得回来看当前页面状态有没有被保存哦
</h3>
<Outlet />
<Button => dropByCacheKey(location.pathname)}>
清除当前页面缓存
</Button>
</div>
);
};
5 changes: 5 additions & 0 deletions examples/tabs/src/services/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { request } from '@@/plugin-request';

export async function query(): Promise<any> {
return request('/hello');
}
31 changes: 31 additions & 0 deletions examples/tabs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "dist",
"sourceMap": true,
"jsx": "react",
"declaration": false,
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2017",
"typeRoots": ["node_modules/@types"],
"lib": ["es2018", "dom"],
"allowSyntheticDefaultImports": true,
"rootDirs": ["/src", "/test", "/mock", "./typings"],
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"allowJs": true,
"strict": true,
"paths": {
"@/*": ["./src/*"],
"@@/*": ["./src/.umi/*"],
"alita": ["./src/.umi/*"]
}
}
}
13 changes: 13 additions & 0 deletions examples/tabs/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
declare module '*.css';
declare module '*.less';
declare module '*.scss';
declare module '*.sass';
declare module '*.svg';
declare module '*.png';
declare module '*.jpg';
declare module '*.jpeg';
declare module '*.gif';
declare module '*.bmp';
declare module '*.tiff';
declare module '*.json';

359 changes: 182 additions & 177 deletions packages/alita/assets/bundle-status.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/alita/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default (api: IApi) => {
require.resolve('./commands/generate/pages'),
require.resolve('@alita/plugins/dist/aconsole'),
require.resolve('@alita/plugins/dist/keepalive'),
require.resolve('@alita/plugins/dist/tabs-layout'),
require.resolve('@alita/plugins/dist/mainpath'),
require.resolve('@alita/plugins/dist/request'),
require.resolve('@alita/plugins/dist/dva'),
Expand Down
Loading
0