Commit 8fea1d73 authored by Sendya's avatar Sendya

fix: layout

parent b837158f
...@@ -2,19 +2,22 @@ const libDir = process.env.LIB_DIR; ...@@ -2,19 +2,22 @@ const libDir = process.env.LIB_DIR;
const transformIgnorePatterns = [ const transformIgnorePatterns = [
'/dist/', '/dist/',
'node_modules/[^/]+?/(?!(es|node_modules)/)', // Ignore modules without es dir 'node_modules/[^/]+?/(?!(node_modules)/)', // Ignore modules without es dir
]; ];
module.exports = { module.exports = {
testURL: 'http://localhost/', testURL: 'http://localhost/',
preset: 'ts-jest',
moduleFileExtensions: ['js', 'ts', 'tsx', 'json', 'vue'], moduleFileExtensions: ['js', 'ts', 'tsx', 'json', 'vue'],
modulePathIgnorePatterns: ['/_site/'], modulePathIgnorePatterns: ['/_site/'],
testPathIgnorePatterns: ['/node_modules/', 'node'], testPathIgnorePatterns: ['/node_modules/', 'node'],
transform: { transform: {
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest', '.*\\.(vue)$': '<rootDir>/node_modules/vue-jest',
'^.+\\.(ts|tsx)$': '<rootDir>/node_modules/babel-jest', '^.+\\.(ts|tsx)$': '<rootDir>/node_modules/babel-jest',
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
}, },
testRegex: libDir === 'dist' ? 'demo\\.test\\.ts$' : '.*\\.test\\.tsx$', testRegex: libDir === 'dist' ? 'demo\\.test\\.ts$' : '.*\\.test\\.tsx$',
testEnvironment: 'node',
moduleNameMapper: { moduleNameMapper: {
'^@/(.*)$': '<rootDir>/$1', '^@/(.*)$': '<rootDir>/$1',
}, },
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
"clean": "cross-env TS_NODE_PROJECT=scripts/tsconfig.json node -r ts-node/register ./scripts/cleanup.ts", "clean": "cross-env TS_NODE_PROJECT=scripts/tsconfig.json node -r ts-node/register ./scripts/cleanup.ts",
"start": "vc-tools run server", "start": "vc-tools run server",
"lint": "eslint src/ -c .eslintrc.js --ext .tsx,.ts", "lint": "eslint src/ -c .eslintrc.js --ext .tsx,.ts",
"lint-fix": "eslint --fix src/ -c .eslintrc.js --ext .tsx,.ts", "lint:fix": "eslint --fix src/ -c .eslintrc.js --ext .tsx,.ts",
"compile": "cross-env TS_NODE_PROJECT=scripts/tsconfig.json vc-tools run compile", "compile": "cross-env TS_NODE_PROJECT=scripts/tsconfig.json vc-tools run compile",
"test": "cross-env NODE_ENV=test jest --config .jest.js", "test": "cross-env NODE_ENV=test jest --config .jest.js",
"prepublishOnly": "npm run lint && npm run compile && npm run test", "prepublishOnly": "npm run lint && npm run compile && npm run test",
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
}, },
"devDependencies": { "devDependencies": {
"@ant-design-vue/tools": "^3.0.4", "@ant-design-vue/tools": "^3.0.4",
"@babel/runtime": "^7.11.2",
"@types/fs-extra": "^9.0.2", "@types/fs-extra": "^9.0.2",
"@types/jest": "^24.0.17", "@types/jest": "^24.0.17",
"@types/node": "^13.13.15", "@types/node": "^13.13.15",
...@@ -47,12 +46,13 @@ ...@@ -47,12 +46,13 @@
"@vue/test-utils": "^2.0.0-beta.2", "@vue/test-utils": "^2.0.0-beta.2",
"cross-env": "^5.2.0", "cross-env": "^5.2.0",
"eslint": "^6.7.2", "eslint": "^6.7.2",
"eslint-config-prettier": "^6.4.0", "eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.3", "eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-vue": "^7.0.0-0", "eslint-plugin-vue": "^7.0.0-0",
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"jest": "^25.4.0", "jest": "^25.4.0",
"jest-serializer-vue": "^2.0.2", "jest-serializer-vue": "^2.0.2",
"jest-transform-stub": "^2.0.0",
"prettier": "^1.19.1", "prettier": "^1.19.1",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"ts-node": "^8.10.2", "ts-node": "^8.10.2",
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
"vue-router": "^4.0.0-beta.13" "vue-router": "^4.0.0-beta.13"
}, },
"dependencies": { "dependencies": {
"@babel/runtime": "^7.10.4", "@babel/runtime": "^7.11.2",
"ant-design-vue": "^2.0.0-beta.10", "ant-design-vue": "^2.0.0-beta.10",
"lodash-es": "^4.17.15", "lodash-es": "^4.17.15",
"vue-types": "^3.0.1" "vue-types": "^3.0.1"
......
import { computed, App, FunctionalComponent, Plugin, CSSProperties } from 'vue'; import { computed, FunctionalComponent, CSSProperties } from 'vue';
import 'ant-design-vue/es/layout/style'; import 'ant-design-vue/es/layout/style';
import Layout from 'ant-design-vue/es/layout'; import Layout from 'ant-design-vue/es/layout';
import { withInstall } from 'ant-design-vue/es/_util/type';
import { default as ProProvider, ProProviderData } from './ProProvider'; import { default as ProProvider, ProProviderData } from './ProProvider';
import { default as GlobalFooter } from './GlobalFooter'; import { default as GlobalFooter } from './GlobalFooter';
import { default as SiderMenuWrapper, SiderMenuWrapperProps } from './SiderMenu'; import { default as SiderMenuWrapper, SiderMenuWrapperProps } from './SiderMenu';
...@@ -29,7 +30,7 @@ export interface BasicLayoutProps { ...@@ -29,7 +30,7 @@ export interface BasicLayoutProps {
headerRender?: WithFalse<(props: any /* HeaderProps */) => RenderVNodeType>; headerRender?: WithFalse<(props: any /* HeaderProps */) => RenderVNodeType>;
colSize?: string, colSize?: string;
/** /**
* 是否禁用移动端模式,有的管理系统不需要移动端模式,此属性设置为true即可 * 是否禁用移动端模式,有的管理系统不需要移动端模式,此属性设置为true即可
*/ */
...@@ -47,7 +48,7 @@ export interface BasicLayoutProps { ...@@ -47,7 +48,7 @@ export interface BasicLayoutProps {
export type ProLayoutProps = BasicLayoutProps & export type ProLayoutProps = BasicLayoutProps &
SiderMenuWrapperProps /* & HeaderProps & FooterProps */; SiderMenuWrapperProps /* & HeaderProps & FooterProps */;
const ProLayout: FunctionalComponent<ProLayoutProps> = (props, { emit, slots, attrs }) => { const ProLayout: FunctionalComponent<ProLayoutProps> = (props, { emit, slots }) => {
const handleCollapse = (collapsed: boolean) => { const handleCollapse = (collapsed: boolean) => {
emit('update:collapsed', collapsed); emit('update:collapsed', collapsed);
}; };
...@@ -80,8 +81,7 @@ const ProLayout: FunctionalComponent<ProLayoutProps> = (props, { emit, slots, at ...@@ -80,8 +81,7 @@ const ProLayout: FunctionalComponent<ProLayoutProps> = (props, { emit, slots, at
onCollapse={handleCollapse} onCollapse={handleCollapse}
/> />
<Layout> <Layout>
<Layout.Header style="background: #fff; padding: 0; height: 48px; line-height: 48px;"> <Layout.Header style="background: #fff; padding: 0; height: 48px; line-height: 48px;"></Layout.Header>
</Layout.Header>
<WrapContent <WrapContent
style={{ style={{
margin: '24px 16px', margin: '24px 16px',
...@@ -134,21 +134,15 @@ ProLayout.props = { ...@@ -134,21 +134,15 @@ ProLayout.props = {
type: String, type: String,
default: 'ant-pro', default: 'ant-pro',
}, },
'title': String, title: String,
'colSize': String, colSize: String,
'isChildrenLayout': Boolean, isChildrenLayout: Boolean,
'fixSiderbar': Boolean, fixSiderbar: Boolean,
'layout': String, layout: String,
'openKeys': Array, openKeys: Array,
'selectedKeys': Array, selectedKeys: Array,
'collapsed': Boolean, collapsed: Boolean,
'menuData': Array, menuData: Array,
} as any; } as any;
export default withInstall(ProLayout);
// @ts-ignore
ProLayout.install = function (app: App) {
app.component('pro-layout', ProLayout);
};
export default ProLayout as typeof ProLayout & Plugin;
import { computed, defineComponent, onBeforeUnmount, onMounted, PropType, VNodeChild } from 'vue'; import { computed, defineComponent, onBeforeUnmount, onMounted, PropType, VNodeChild } from 'vue';
import { useProProvider } from '../ProProvider'; import { useProProvider } from '../ProProvider';
import { RouteContextProps, useRouteContext } from '../RouteContext'; import { RouteContextProps, useRouteContext } from '../RouteContext';
import { getComponent } from '../utils';
import './index.less'; import './index.less';
export interface FooterToolbarProps { export interface FooterToolbarProps {
......
...@@ -3,16 +3,13 @@ import { useProProvider } from '../ProProvider'; ...@@ -3,16 +3,13 @@ import { useProProvider } from '../ProProvider';
import { PureSettings } from '../defaultSettings'; import { PureSettings } from '../defaultSettings';
import './GridContent.less'; import './GridContent.less';
interface GridContentProps { export interface GridContentProps {
contentWidth?: PureSettings['contentWidth']; contentWidth?: PureSettings['contentWidth'];
prefixCls?: string; prefixCls?: string;
style?: CSSProperties; style?: CSSProperties;
} }
const GridContent: FunctionalComponent<GridContentProps> = ( const GridContent: FunctionalComponent<GridContentProps> = (props, { slots }) => {
props,
{ slots },
) => {
const proConfig = useProProvider(); const proConfig = useProProvider();
const { contentWidth, getPrefixCls } = toRefs(proConfig); const { contentWidth, getPrefixCls } = toRefs(proConfig);
const customPrefixCls = props.prefixCls || getPrefixCls.value(); const customPrefixCls = props.prefixCls || getPrefixCls.value();
......
...@@ -140,7 +140,6 @@ const defaultPageHeaderRender = ( ...@@ -140,7 +140,6 @@ const defaultPageHeaderRender = (
pageHeaderRender, pageHeaderRender,
header, header,
extraContent, extraContent,
prefixCls,
...restProps ...restProps
} = props; } = props;
console.log('restProps', restProps); console.log('restProps', restProps);
......
...@@ -113,6 +113,8 @@ export const VueBaseMenuProps = { ...@@ -113,6 +113,8 @@ export const VueBaseMenuProps = {
}, },
}; };
const httpReg = /(http|https|ftp):\/\/([\w.]+\/?)\S*/;
const renderTitle = (title: string | undefined, i18nRender: FormatMessage) => { const renderTitle = (title: string | undefined, i18nRender: FormatMessage) => {
return <span>{(i18nRender && title && i18nRender(title)) || title}</span>; return <span>{(i18nRender && title && i18nRender(title)) || title}</span>;
}; };
...@@ -120,8 +122,10 @@ const renderTitle = (title: string | undefined, i18nRender: FormatMessage) => { ...@@ -120,8 +122,10 @@ const renderTitle = (title: string | undefined, i18nRender: FormatMessage) => {
const renderMenuItem = (item: RouteProps, i18nRender: FormatMessage) => { const renderMenuItem = (item: RouteProps, i18nRender: FormatMessage) => {
const meta = Object.assign({}, item.meta); const meta = Object.assign({}, item.meta);
const target = meta.target || null; const target = meta.target || null;
const CustomTag: any = (target && 'a') || 'router-link'; const hasRemoteUrl = httpReg.test(item.path)
const props = { to: { name: item.name }, href: item.path, target: target }; const CustomTag: any = resolveComponent((target && 'a') || 'router-link');
const props = { to: { name: item.name } };
const attrs = (hasRemoteUrl || target) ? { href: item.path, target: target } : {};
if (item.children && item.meta?.hideChildInMenu) { if (item.children && item.meta?.hideChildInMenu) {
// 把有子菜单的 并且 父菜单是要隐藏子菜单的 // 把有子菜单的 并且 父菜单是要隐藏子菜单的
// 都给子菜单增加一个 hidden 属性 // 都给子菜单增加一个 hidden 属性
...@@ -133,9 +137,9 @@ const renderMenuItem = (item: RouteProps, i18nRender: FormatMessage) => { ...@@ -133,9 +137,9 @@ const renderMenuItem = (item: RouteProps, i18nRender: FormatMessage) => {
// @ts-nocheck // @ts-nocheck
return ( return (
<Menu.Item key={item.path}> <Menu.Item key={item.path}>
<CustomTag {...props}> <CustomTag {...attrs} {...props}>
<LazyIcon icon={meta.icon} /> <LazyIcon icon={meta.icon} />
{renderTitle(meta.title!, i18nRender)} {renderTitle(meta.title, i18nRender)}
</CustomTag> </CustomTag>
</Menu.Item> </Menu.Item>
); );
...@@ -151,7 +155,7 @@ const renderSubMenu = (item: RouteProps, i18nRender: FormatMessage) => { ...@@ -151,7 +155,7 @@ const renderSubMenu = (item: RouteProps, i18nRender: FormatMessage) => {
return ( return (
<Menu.SubMenu key={item.path} title={renderMenuContent}> <Menu.SubMenu key={item.path} title={renderMenuContent}>
{/* eslint-disable-next-line @typescript-eslint/no-use-before-define */} {/* eslint-disable-next-line @typescript-eslint/no-use-before-define */}
{!item.meta?.hideChildInMenu && item.children!.map(cd => renderMenu(cd, i18nRender))} {!item.meta?.hideChildInMenu && item.children.map(cd => renderMenu(cd, i18nRender))}
</Menu.SubMenu> </Menu.SubMenu>
); );
}; };
......
import { mount } from '@vue/test-utils';
describe('index', () => {
it('shoul render GridContent', () => {
// empty
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment