Browse Source

🌷 UI: alway set theme (#9458)

* 🌷 UI: alway set theme

* 🌷 UI: support dynamic theme

* merge master
pull/9490/head 5.2.0
陈帅 4 years ago
committed by GitHub
parent
commit
645d6ed4fd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .github/workflows/deploy.yml
  2. 3
      config/config.ts
  3. 8
      package.json
  4. 28
      src/app.tsx
  5. 2
      src/components/HeaderDropdown/index.less
  6. 2
      src/components/HeaderSearch/index.less
  7. 2
      src/components/NoticeIcon/NoticeList.less
  8. 2
      src/components/NoticeIcon/index.less
  9. 2
      src/components/RightContent/index.less
  10. 2
      src/global.less
  11. 2
      src/pages/Welcome.less
  12. 1
      src/pages/Welcome.tsx
  13. 2
      src/pages/user/Login/index.less

2
.github/workflows/deploy.yml

@ -15,7 +15,7 @@ jobs:
run: yarn run: yarn
- name: plugins - name: plugins
run: yarn add umi-plugin-antd-theme umi-plugin-pro umi-plugin-setting-drawer run: yarn add umi-plugin-pro
- name: fetch-blocks - name: fetch-blocks
run: yarn run pro fetch-blocks run: yarn run pro fetch-blocks

3
config/config.ts

@ -38,8 +38,7 @@ export default defineConfig({
routes, routes,
// Theme for antd: https://ant.design/docs/react/customize-theme-cn // Theme for antd: https://ant.design/docs/react/customize-theme-cn
theme: { theme: {
'primary-color': defaultSettings.primaryColor, 'root-entry-name': 'variable',
'root-entry-name': 'default',
}, },
// esbuild is father build tools // esbuild is father build tools
// https://umijs.org/plugins/plugin-esbuild // https://umijs.org/plugins/plugin-esbuild

8
package.json

@ -1,6 +1,6 @@
{ {
"name": "ant-design-pro", "name": "ant-design-pro",
"version": "5.1.0", "version": "5.2.0",
"private": true, "private": true,
"description": "An out-of-box UI solution for enterprise applications", "description": "An out-of-box UI solution for enterprise applications",
"scripts": { "scripts": {
@ -57,10 +57,10 @@
"@ant-design/icons": "^4.5.0", "@ant-design/icons": "^4.5.0",
"@ant-design/pro-descriptions": "^1.9.0", "@ant-design/pro-descriptions": "^1.9.0",
"@ant-design/pro-form": "^1.43.0", "@ant-design/pro-form": "^1.43.0",
"@ant-design/pro-layout": "^6.26.0", "@ant-design/pro-layout": "^6.32.0-beta.4",
"@ant-design/pro-table": "^2.56.0", "@ant-design/pro-table": "^2.56.0",
"@umijs/route-utils": "^2.0.3", "@umijs/route-utils": "^2.0.4",
"antd": "4.16.13", "antd": "^4.17.0",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"lodash": "^4.17.11", "lodash": "^4.17.11",
"moment": "^2.25.3", "moment": "^2.25.3",

28
src/app.tsx

@ -1,4 +1,5 @@
import type { Settings as LayoutSettings } from '@ant-design/pro-layout'; import type { Settings as LayoutSettings } from '@ant-design/pro-layout';
import { SettingDrawer } from '@ant-design/pro-layout';
import { PageLoading } from '@ant-design/pro-layout'; import { PageLoading } from '@ant-design/pro-layout';
import type { RunTimeLayoutConfig } from 'umi'; import type { RunTimeLayoutConfig } from 'umi';
import { history, Link } from 'umi'; import { history, Link } from 'umi';
@ -21,6 +22,7 @@ export const initialStateConfig = {
export async function getInitialState(): Promise<{ export async function getInitialState(): Promise<{
settings?: Partial<LayoutSettings>; settings?: Partial<LayoutSettings>;
currentUser?: API.CurrentUser; currentUser?: API.CurrentUser;
loading?: boolean;
fetchUserInfo?: () => Promise<API.CurrentUser | undefined>; fetchUserInfo?: () => Promise<API.CurrentUser | undefined>;
}> { }> {
const fetchUserInfo = async () => { const fetchUserInfo = async () => {
@ -48,7 +50,7 @@ export async function getInitialState(): Promise<{
} }
// ProLayout 支持的api https://procomponents.ant.design/components/layout // ProLayout 支持的api https://procomponents.ant.design/components/layout
export const layout: RunTimeLayoutConfig = ({ initialState }) => { export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
return { return {
rightContentRender: () => <RightContent />, rightContentRender: () => <RightContent />,
disableContentMargin: false, disableContentMargin: false,
@ -79,10 +81,26 @@ export const layout: RunTimeLayoutConfig = ({ initialState }) => {
// 自定义 403 页面 // 自定义 403 页面
// unAccessible: <div>unAccessible</div>, // unAccessible: <div>unAccessible</div>,
// 增加一个 loading 的状态 // 增加一个 loading 的状态
// childrenRender: (children) => { childrenRender: (children, props) => {
// if (initialState.loading) return <PageLoading />; // if (initialState?.loading) return <PageLoading />;
// return children; return (
// }, <>
{children}
{!props.location?.pathname?.includes('/login') && (
<SettingDrawer
enableDarkTheme
settings={initialState?.settings}
onSettingChange={(settings) => {
setInitialState((preInitialState) => ({
...preInitialState,
settings,
}));
}}
/>
)}
</>
);
},
...initialState?.settings, ...initialState?.settings,
}; };
}; };

2
src/components/HeaderDropdown/index.less

@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less'; @import (reference) '~antd/es/style/themes/index';
.container > * { .container > * {
background-color: @popover-bg; background-color: @popover-bg;

2
src/components/HeaderSearch/index.less

@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less'; @import (reference) '~antd/es/style/themes/index';
.headerSearch { .headerSearch {
display: inline-flex; display: inline-flex;

2
src/components/NoticeIcon/NoticeList.less

@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less'; @import (reference) '~antd/es/style/themes/index';
.list { .list {
max-height: 400px; max-height: 400px;

2
src/components/NoticeIcon/index.less

@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less'; @import (reference) '~antd/es/style/themes/index';
.popover { .popover {
position: relative; position: relative;

2
src/components/RightContent/index.less

@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less'; @import (reference) '~antd/es/style/themes/index';
@pro-header-hover-bg: rgba(0, 0, 0, 0.025); @pro-header-hover-bg: rgba(0, 0, 0, 0.025);

2
src/global.less

@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less'; @import '~antd/es/style/variable.less';
html, html,
body, body,

2
src/pages/Welcome.less

@ -1,4 +1,4 @@
@import '~antd/lib/style/themes/default.less'; @import (reference) '~antd/es/style/themes/index';
.pre { .pre {
margin: 12px 0; margin: 12px 0;

1
src/pages/Welcome.tsx

@ -14,6 +14,7 @@ const CodePreview: React.FC = ({ children }) => (
const Welcome: React.FC = () => { const Welcome: React.FC = () => {
const intl = useIntl(); const intl = useIntl();
return ( return (
<PageContainer> <PageContainer>
<Card> <Card>

2
src/pages/user/Login/index.less

@ -1,4 +1,4 @@
@import '~antd/es/style/themes/default.less'; @import (reference) '~antd/es/style/themes/index';
.container { .container {
display: flex; display: flex;

Loading…
Cancel
Save