4.0.8 • Published 13 days ago

antdv-pro-layout v4.0.8

Weekly downloads
-
License
MIT
Repository
-
Last release
13 days ago

Ant Design Vue Pro Layout

Ant Design Pro布局Vue,易于使用专业脚手架。

Ant Design Pro Layout of Vue, easy to use pro scaffolding.

Vue Support NPM version NPM downloads License MIT

安装 Install

npm i antdv-pro-layout

简单使用 Simple Usage

首先,您应该将所需的 antdv-pro-layout 添加到库中。

First, you should add the antdv-pro-layout that you need into the library.

// main.[js|ts]
import 'antdv-pro-layout/dist/style.css';

import { createApp } from "vue";
import App from "./App.vue";
import Antd from "ant-design-vue";
import { ProLayout, PageContainer } from "antdv-pro-layout";

const app = createApp(App);

app.use(Antd).use(ProLayout).use(PageContainer).mount("#app");

之后,您可以在Vue组件中使用专业布局,如下所示:

After that, you can use pro-layout in your Vue components as simply as this:

<template>
  <pro-layout
    :locale="locale"
    v-bind="layoutConf"
    v-model:openKeys="state.openKeys"
    v-model:collapsed="state.collapsed"
    v-model:selectedKeys="state.selectedKeys"
  >
    <router-view />
  </pro-layout>
</template>

<script setup lang="ts">
import { reactive, useRouter } from "vue";
import { getMenuData, clearMenuItem, type MenuDataItem } from "antdv-pro-layout";

const locale = (menuData: MenuDataItem) => menuData.meta?.title;
const router = useRouter();

const { menuData } = getMenuData(clearMenuItem(router.getRoutes()));

const state = reactive({
  collapsed: false, // default value
  openKeys: ["/dashboard"],
  selectedKeys: ["/welcome"],
});
const layoutConf = reactive({
  navTheme: "dark",
  layout: "mix",
  splitMenus: false,
  menuData,
});
</script>

当前可用功能 API

ProLayout 布局

PropertyDescriptionTypeDefault Value
title布局LOGO右侧文本string'Ant Design Pro'
logo布局LOGO图链接stringhttps://gw.alipayobjects.com/zos/antfincdn/PmY%24TNNDBI/logo.svg
logoStyle布局LOGO图样式object-
loading布局内容区加载等待状态booleanfalse
layout菜单布局'side' | 'top' | 'mix''side'
breadcrumb布局内容左上角面包屑Object-
disableContentMargin布局内容禁用外边距booleanfalse
theme全局主题色'light' |'dark''light'
menuTheme菜单导航主题色'light' |'dark''light'
menuData菜单数据根据Vue-router routes 根路径'/'生成Object[{}]
collapsed菜单左侧时收起展开booleantrue
selectedKeys菜单选择高亮keysstring[][]
openKeys菜单选择打开展开keysstring[][]
menuHeaderRender渲染菜单头logo和标题区域v-slot | VNode | (props: BasicLayoutProps) => VNode | false-
menuHeaderExtraRender渲染菜单头拓展区域v-slot | VNode | (props: BasicLayoutProps) => VNode | false-
menuFooterRender渲染菜单底脚区域v-slot | VNode | (props: BasicLayoutProps) => VNode | false-
menuItemRender渲染菜单项 Menu.Itemv-slot#menuItemRender="menuItem"-
subMenuItemRender渲染菜单嵌套子项 Menu.SubItemv-slot#subMenuItemRender="menuItem"-
collapsedButtonRender渲染菜单收起按钮区域v-slot#collapsedButtonRender="collapsed"-
headerRender渲染顶部区域v-slot | VNode | (props: BasicLayoutProps) => VNode-
headerContentRenderheader content render method only layout sideslot | (props: BasicLayoutProps) => VNode-
rightContentRenderheader right content render methodslot | (props: BasicLayoutProps) => VNode-
footerRender渲染底部区域v-slot | ({ width, ...props }) => VNodefalse
tabRender渲染顶部标签页区域v-slot | ({ width, ...props }) => VNodefalse
breadcrumbRender渲染面包屑导航区域v-slot | ({ route, params, routes, paths, h }) => VNode[]-
locale菜单名国际化函数处理Function(menuDataItem?: MenuDataItem) => string | falsefalse
collapse菜单左侧收起展开触发函数处理Function(collapsed: boolean) => void-

Menu generation requires getMenuData and clearMenuItem function e.g. const { menuData } = getMenuData(clearMenuItem(routes))

自定义渲染 Custom Render

Custom rightContentRender
<template #rightContentRender>
  <div style="margin-right: 12px">
    <a-avatar shape="square" size="small">
      <template #icon>
        <UserOutlined />
      </template>
    </a-avatar>
  </div>
</template>
Custom menu.item
<template #menuItemRender="{ item, icon }">
  <a-menu-item
    :key="item.path"
    :disabled="item.meta?.disabled"
    :danger="item.meta?.danger"
    :icon="icon"
  >
    <router-link :to="{ path: item.path }">
      <span class="ant-pro-menu-item">
        <a-badge count="5" dot>
          <span class="ant-pro-menu-item-title">{{ item.meta.title }}</span>
        </a-badge>
      </span>
    </router-link>
  </a-menu-item>
</template>
Custom breadcrumbRender
<template #breadcrumbRender="{ route, params, routes }">
  <span v-if="routes.indexOf(route) === routes.length - 1">
    {{ route.breadcrumbName }}
  </span>
  <router-link v-else :to="{ path: route.path, params }">
    {{ route.breadcrumbName }}
  </router-link>
</template>
Custom tabRender
<template #tabRender="{ width, fixedHeader }">
  <div>
    <header
      class="ant-layout-header"
      style="height: 36px; line-height: 36px; background: transparent"
      v-if="fixedHeader"
    ></header>
    <div
      :style="{
        margin: '0',
        height: '36px',
        lineHeight: '36px',
        right: '0px',
        top: '48px',
        position: fixedHeader ? 'fixed' : 'unset',
        zIndex: 14,
        padding: '4px 16px',
        width: width,
        background: '#fff',
        boxShadow: '0 1px 4px #0015291f',
        transition: 'background 0.3s, width 0.2s',
      }"
    >
      tabRender fixedHeader:{{fixedHeader}} width:{{ width }} 
    </div>
  </div>
</template>
Custom footer with slot
<template #footerRender="{ width, headerTheme }">
  <div>
    <footer class="ant-layout-footer" style="height: 36px; line-height: 36px; background: transparent"></footer>
    <div
      :style="{
        margin: '0',
        height: '36px',
        lineHeight: '36px',
        right: '0px',
        bottom: '0px',
        position: headerTheme == 'dark' ? 'fixed' : 'unset',
        zIndex: 14,
        padding: '4px 16px',
        width: width,
        background: '#fff',
        boxShadow: '0 1px 4px #0015291f',
        transition: 'background 0.3s, width 0.2s'
      }"
    >
      footerRender headerTheme:{{ headerTheme }} width:{{ width }}
    </div>
  </div>
</template>
Custom footer with props
<GlobalFooter
  :links="[
    { title: 'Link 1', href: '#' },
    { title: 'Link 2', href: '#' },
  ]"
  copyright="Pro Layout &copy; 2021 Sendya."
></GlobalFooter>

PageContainer 内容页

包含antdv组件API属性: PageHeader 页头Affix 固钉

参数说明类型默认值
loading加载状态booleanfalse
flex内容布局充满,默认固定宽度1200pxbooleanfalse
fixed-header固定 PageHeader 到顶部booleanfalse
affixProps固钉的配置affix-
pageFooter渲染页脚插槽VNode | v-slot-
pageHeader渲染页头替换PageHeader组件插槽VNode | v-slot-
...PageHeader 页头API--
breadcrumbPageHeader面包屑的配置,{}配置不显示breadcrumb-
contentPageHeader默认插槽VNode | v-slot-
contentExtraPageHeader默认插槽右侧空间VNode | v-slot-
tab-listPageHeader插槽footer无时,显示标签列表Array<{key: string, tab: any}>-
tab-active-key标签列表当前激活keystring-
tab-change标签列表tab被点击的回调(key) => void-
tab-props标签列表标签页属性tabs-

基本使用示例 Basic Usage

项目目录下 Playground or Use Template

Recommend look Examples or Use Template

源项目仓库分支 Branch

来自 @ant-design-vue/pro-layout

  • next : Vue3 + ant-design-vue@3.x (latest)
  • v3.1 : Vue3 + ant-design-vue@2.2.x (release LTS)
  • v2 : Vue2 + ant-design-vue@1.7.x

当前分支v4版本,还在持续更新

持续维护 Continuous Maintenance

# 安装所需依赖
npm install

# 打包生成dist目录含d.ts文件
npm run build
4.0.8

13 days ago

4.0.5

1 month ago

4.0.4

2 months ago

4.0.3

2 months ago

4.0.1

2 months ago

4.0.0

2 months ago

3.2.6

6 months ago

3.2.5

6 months ago